Skip to content

Commit

Permalink
ORC-3547 Support updating workflow template spec
Browse files Browse the repository at this point in the history
  • Loading branch information
louisnow committed Jul 4, 2022
1 parent 63e13ee commit e4672ba
Show file tree
Hide file tree
Showing 4 changed files with 1,560 additions and 3,061 deletions.
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

0 comments on commit e4672ba

Please sign in to comment.