diff --git a/cmd/argoexec/commands/artifact/delete.go b/cmd/argoexec/commands/artifact/delete.go index 39ee4fd7decd..5a155ca38081 100644 --- a/cmd/argoexec/commands/artifact/delete.go +++ b/cmd/argoexec/commands/artifact/delete.go @@ -29,7 +29,7 @@ func NewArtifactDeleteCommand() *cobra.Command { namespace := client.Namespace() clientConfig := client.GetConfig() - if podName, ok := os.LookupEnv(common.EnvVarArtifactPodName); ok { + if podName, ok := os.LookupEnv(common.EnvVarArtifactGCPodHash); ok { config, err := clientConfig.ClientConfig() workflowInterface := workflow.NewForConfigOrDie(config) @@ -38,7 +38,7 @@ func NewArtifactDeleteCommand() *cobra.Command { } artifactGCTaskInterface := workflowInterface.ArgoprojV1alpha1().WorkflowArtifactGCTasks(namespace) - labelSelector := fmt.Sprintf("%s = %s", common.LabelKeyArtifactGCPodName, podName) + labelSelector := fmt.Sprintf("%s = %s", common.LabelKeyArtifactGCPodHash, podName) err = deleteArtifacts(labelSelector, cmd.Context(), artifactGCTaskInterface) if err != nil { diff --git a/test/e2e/testdata/artifactgc/artgc-multi-strategy-multi-anno.yaml b/test/e2e/testdata/artifactgc/artgc-multi-strategy-multi-anno.yaml index f4673bbf9669..b1d652df40bb 100644 --- a/test/e2e/testdata/artifactgc/artgc-multi-strategy-multi-anno.yaml +++ b/test/e2e/testdata/artifactgc/artgc-multi-strategy-multi-anno.yaml @@ -1,9 +1,7 @@ apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: - generateName: two-artgc- - #finalizers: - # - "blah" + generateName: testing-on-completion-and-on-deletion-strategies- spec: entrypoint: entrypoint artifactGC: diff --git a/workflow/common/common.go b/workflow/common/common.go index 4ec5a9a63cdd..9647e162e2a2 100644 --- a/workflow/common/common.go +++ b/workflow/common/common.go @@ -87,8 +87,8 @@ const ( LabelKeyClusterWorkflowTemplate = workflow.WorkflowFullName + "/cluster-workflow-template" // LabelKeyOnExit is a label applied to Pods that are run from onExit nodes, so that they are not shut down when stopping a Workflow LabelKeyOnExit = workflow.WorkflowFullName + "/on-exit" - // LabelKeyArtifactGCPodName is a label applied to WorkflowTaskSets used by the Artifact Garbage Collection Pod - LabelKeyArtifactGCPodName = workflow.WorkflowFullName + "/artifact-gc-pod" + // LabelKeyArtifactGCPodHash is a label applied to WorkflowTaskSets used by the Artifact Garbage Collection Pod + LabelKeyArtifactGCPodHash = workflow.WorkflowFullName + "/artifact-gc-pod" // ExecutorArtifactBaseDir is the base directory in the init container in which artifacts will be copied to. // Each artifact will be named according to its input name (e.g: /argo/inputs/artifacts/CODE) @@ -109,8 +109,8 @@ const ( // Various environment variables containing pod information exposed to the executor container(s) - // EnvVarArtifactPodName is applied as a Label on the WorkflowTaskSets read by the Artifact GC Pod, so that the Pod can find them - EnvVarArtifactPodName = "ARGO_ARTIFACT_POD_NAME" + // EnvVarArtifactGCPodHash is applied as a Label on the WorkflowTaskSets read by the Artifact GC Pod, so that the Pod can find them + EnvVarArtifactGCPodHash = "ARGO_ARTIFACT_POD_NAME" // EnvVarPodName contains the name of the pod (currently unused) EnvVarPodName = "ARGO_POD_NAME" // EnvVarPodUID is the workflow's UID diff --git a/workflow/controller/artifact_gc.go b/workflow/controller/artifact_gc.go index d0961b7d4aae..b92ef1f9dfd1 100644 --- a/workflow/controller/artifact_gc.go +++ b/workflow/controller/artifact_gc.go @@ -85,18 +85,6 @@ func (woc *wfOperationCtx) artifactGCStrategiesReady() map[wfv1.ArtifactGCStrate strategies[wfv1.ArtifactGCOnWorkflowDeletion] = struct{}{} } } - // todo: look at implementing "OnWorkflowSuccessOrDeletion" and "OnWorkflowFailureOrDeletion" instead of these: - /* - if woc.wf.Status.Successful() { - if !woc.wf.Status.ArtifactGCStatus.IsArtifactGCStrategyProcessed(wfv1.ArtifactGCOnWorkflowSuccess) { - strategies[wfv1.ArtifactGCOnWorkflowSuccess] = struct{}{} - } - } - if woc.wf.Status.Failed() { - if !woc.wf.Status.ArtifactGCStatus.IsArtifactGCStrategyProcessed(wfv1.ArtifactGCOnWorkflowFailure) { - strategies[wfv1.ArtifactGCOnWorkflowFailure] = struct{}{} - } - }*/ return strategies } @@ -262,10 +250,17 @@ func (woc *wfOperationCtx) artGCTaskName(podName string, taskIndex int) string { return fmt.Sprintf("%s-%d", podName, taskIndex) } +func (woc *wfOperationCtx) artifactGCPodLabel(podName string) string { + hashedPod := fnv.New32a() + _, _ = hashedPod.Write([]byte(podName)) + return fmt.Sprintf("%d", hashedPod.Sum32()) +} + func (woc *wfOperationCtx) addTemplateArtifactsToTasks(podName string, tasks *[]*wfv1.WorkflowArtifactGCTask, template *wfv1.Template, artifactSearchResults wfv1.ArtifactSearchResults) { if len(artifactSearchResults) == 0 { return } + if tasks == nil { ts := make([]*wfv1.WorkflowArtifactGCTask, 0) tasks = &ts @@ -282,7 +277,7 @@ func (woc *wfOperationCtx) addTemplateArtifactsToTasks(podName string, tasks *[] ObjectMeta: metav1.ObjectMeta{ Namespace: woc.wf.Namespace, Name: woc.artGCTaskName(podName, 0), - Labels: map[string]string{common.LabelKeyArtifactGCPodName: podName}, + Labels: map[string]string{common.LabelKeyArtifactGCPodHash: woc.artifactGCPodLabel(podName)}, OwnerReferences: []metav1.OwnerReference{ // make sure we get deleted with the workflow *metav1.NewControllerRef(woc.wf, wfv1.SchemeGroupVersion.WithKind(workflow.WorkflowKind)), }, @@ -416,7 +411,7 @@ func (woc *wfOperationCtx) createArtifactGCPod(ctx context.Context, strategy wfv ImagePullPolicy: woc.controller.executorImagePullPolicy(), Args: []string{"artifact", "delete", "--loglevel", getExecutorLogLevel()}, Env: []corev1.EnvVar{ - {Name: common.EnvVarArtifactPodName, Value: podName}, + {Name: common.EnvVarArtifactGCPodHash, Value: woc.artifactGCPodLabel(podName)}, }, // if this pod is breached by an attacker we: // * prevent installation of any new packages @@ -547,7 +542,7 @@ func (woc *wfOperationCtx) processCompletedArtifactGCPod(ctx context.Context, po woc.log.Infof("processing completed Artifact GC Pod '%s'", pod.Name) // get associated WorkflowArtifactGCTasks - labelSelector := fmt.Sprintf("%s = %s", common.LabelKeyArtifactGCPodName, pod.Name) + labelSelector := fmt.Sprintf("%s = %s", common.LabelKeyArtifactGCPodHash, woc.artifactGCPodLabel(pod.Name)) taskList, err := woc.controller.wfclientset.ArgoprojV1alpha1().WorkflowArtifactGCTasks(woc.wf.Namespace).List(ctx, metav1.ListOptions{LabelSelector: labelSelector}) if err != nil { return fmt.Errorf("failed to List WorkflowArtifactGCTasks: %w", err)