Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORC-3547 Support updating workflow template spec #42

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const constants = {
// atlan-defaults configmap details
ATLAN_DEFAULTS_CONFIGMAP_NAME: "atlan-defaults",
ATLAN_DEFAULTS_CONFIGMAP_NAMESPACE: "default",

ARGO_WORKFLOW_NON_SPEC_KEYS: ["templates", "entrypoint"],
};

exports.constants = constants;
63 changes: 63 additions & 0 deletions lib/k8s.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,73 @@ K8sInstaller.upsertTemplate = function (packageName, namespace, kind, group, yam
clusterInstall,
group,
forceUpdate
).then((upsertedResponse) => {
if (upsertedResponse === null) return Promise.resolve(null);
return K8sInstaller.handleTemplateSpecUpdates(yamlObject, namespace, group);
});
});
};
/**
*
* @param {Object} yamlObject
* @param {string} namespace
* @param {string} group
* @returns {Promise<Object | null>}
*/
K8sInstaller.handleTemplateSpecUpdates = function (yamlObject, namespace, group) {
return customK8sApi
.listNamespacedCustomObject(
group,
constants.ARGO_K8S_API_VERSION,
namespace,
constants.ARGO_WORKFLOW_TEMPLATES_PLURAL,
null,
null,
null,
null,
`${constants.ARGOPM_LIBRARY_NAME_LABEL}=${yamlObject.metadata.labels[constants.ARGOPM_LIBRARY_NAME_LABEL]}`
)
.then((response) => {
const metadataSpec = getWorkflowSpecFromTemplate(yamlObject);
const workflowTemplates = response.body.items.filter(
(item) => item.metadata.name !== yamlObject.metadata.name
);
for (const workflowTemplate of workflowTemplates) {
Object.assign(workflowTemplate.spec, metadataSpec);
Object.assign(workflowTemplate.metadata.labels, yamlObject.metadata.labels);
Object.assign(workflowTemplate.metadata.annotations, yamlObject.metadata.annotations);
constants.ARGO_WORKFLOW_NON_SPEC_KEYS.forEach((k) => delete workflowTemplate.spec[k]);
}

return Promise.all(
workflowTemplates.map((workflowTemplate) =>
K8sInstaller.patchCustomResource(
workflowTemplate.metadata.name,
namespace,
constants.ARGO_WORKFLOW_TEMPLATES_PLURAL,
workflowTemplate,
false,
group
)
)
);
});
};

/**
*
* @param {Object} yamlObject
* @returns {Object}
*/
function getWorkflowSpecFromTemplate(yamlObject) {
const specObject = {};
for (const key in yamlObject.spec) {
if (constants.ARGO_WORKFLOW_NON_SPEC_KEYS.includes(key)) continue;
specObject[key] = yamlObject.spec[key];
}
return specObject;
}

/**
*
* @param {Object} response
Expand Down
Loading