private String checkNamespace(KubernetesCloud kubernetesCloud, @CheckForNull NamespaceAction namespaceAction) { String namespace = null; if (!Strings.isNullOrEmpty(step.getNamespace())) { namespace = step.getNamespace(); } else if ((namespaceAction != null) && (!Strings.isNullOrEmpty(namespaceAction.getNamespace()))) { namespace = namespaceAction.getNamespace(); } else { namespace = kubernetesCloud.getNamespace(); } return namespace; }
/** * Generates a namespace id/name if one has not been explicitly specified. * If no name or prefix is specified, it will try to determine a namespace based on the enclosing elements. * Finally it will fallback to generating one using the default prefix. * * @param name A fixed namespace name. * @param prefix The prefix to use. * @param sessionId The id of the session. * @return The name if not null or empty, else prefix-sessionId. */ protected String generateNamespaceId(String name, String prefix, String sessionId) { if (Utils.isNotNullOrEmpty(name)) { return name; } else if (Utils.isNotNullOrEmpty(prefix)) { return String.format(NAME_FORMAT, prefix, sessionId); } NamespaceAction namespaceAction = getNamespaceAction(); if (namespaceAction != null && Utils.isNotNullOrEmpty(namespaceAction.getNamespace())) { return namespaceAction.getNamespace(); } return String.format(NAME_FORMAT, DEFAULT_PREFIX, sessionId); }
/** * Generates a namespace id/name if one has not been explicitly specified. * If no name or prefix is specified, it will try to determine a namespace based on the enclosing elements. * Finally it will fallback to generating one using the default prefix. * * @param name A fixed namespace name. * @param prefix The prefix to use. * @param sessionId The id of the session. * @return The name if not null or empty, else prefix-sessionId. */ protected String generateNamespaceId(String name, String prefix, String sessionId) { if (Utils.isNotNullOrEmpty(name)) { return name; } else if (Utils.isNotNullOrEmpty(prefix)) { return String.format(NAME_FORMAT, prefix, sessionId); } NamespaceAction namespaceAction = getNamespaceAction(); if (namespaceAction != null && Utils.isNotNullOrEmpty(namespaceAction.getNamespace())) { return namespaceAction.getNamespace(); } return String.format(NAME_FORMAT, DEFAULT_PREFIX, sessionId); }
protected boolean isNamespaceProvided() { if (Utils.isNotNullOrEmpty(getStep().getName())) { return true; } NamespaceAction namespaceAction = getNamespaceAction(); if (namespaceAction != null && Utils.isNotNullOrEmpty(namespaceAction.getNamespace())) { return true; } return false; }
protected boolean isNamespaceProvided() { if (Utils.isNotNullOrEmpty(getStep().getName())) { return true; } NamespaceAction namespaceAction = getNamespaceAction(); if (namespaceAction != null && Utils.isNotNullOrEmpty(namespaceAction.getNamespace())) { return true; } return false; }
@Override protected String run() throws Exception { String namespace = null; try { FilePath workspace = getContext().get(FilePath.class); namespace = workspace.child(Config.KUBERNETES_NAMESPACE_PATH).readToString(); if (Utils.isNotNullOrEmpty(namespace)) { return namespace; } } catch (Throwable t) { //it might be executed outside of a `node` block in which case, we want to ignore. } NamespaceAction namespaceAction = new NamespaceAction(getContext().get(Run.class)); namespace = namespaceAction.getNamespace(); if (Utils.isNotNullOrEmpty(namespace)) { return namespace; } return step.getFallbackNamespace(); } }
@Override protected String run() throws Exception { String namespace = null; try { FilePath workspace = getContext().get(FilePath.class); namespace = workspace.child(Config.KUBERNETES_NAMESPACE_PATH).readToString(); if (Utils.isNotNullOrEmpty(namespace)) { return namespace; } } catch (Throwable t) { //it might be executed outside of a `node` block in which case, we want to ignore. } NamespaceAction namespaceAction = new NamespaceAction(getContext().get(Run.class)); namespace = namespaceAction.getNamespace(); if (Utils.isNotNullOrEmpty(namespace)) { return namespace; } return step.getFallbackNamespace(); } }