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

clean-jobs workflow step doesn't clean jobs created with WorkflowRun #178

Closed
oanasc opened this issue Nov 22, 2023 · 2 comments · Fixed by kubevela/catalog#738
Closed

clean-jobs workflow step doesn't clean jobs created with WorkflowRun #178

oanasc opened this issue Nov 22, 2023 · 2 comments · Fixed by kubevela/catalog#738

Comments

@oanasc
Copy link

oanasc commented Nov 22, 2023

Describe the bug
WorkflowRun creates a job that is labeled with workflowrun.oam.dev/name and the underlying pod is labeled with workflow.oam.dev/name this difference means clean-jobs is not deleting the jobs when there aren't any matchingLabels provided.

To Reproduce
Steps to reproduce the behavior:

  1. Apply an WorkflowRun, in this example is an addon but should behave the same way with any
apiVersion: core.oam.dev/v1alpha1
kind: WorkflowRun
metadata:
  name: enable-addons-test
  namespace: vela-system
spec:
  mode: 
  workflowSpec:
    steps:
      - name: Enable chartmuseum
        type: addon-operation
        properties:
          addonName: chartmuseum
          operation: enable
          args:
          - --override-definitions

      - name: Clean
        type: clean-jobs
        if: always
        properties:
          namespace: "vela-system"
  1. The first step creates a job and a pod, notice the difference in the labels between the pod using workflow.* and the job using workflowrun.*
apiVersion: v1
kind: Pod
metadata:
  name: enable-addons-test-qealctrkbx-gx2dr
  generateName: enable-addons-test-qealctrkbx-
  namespace: vela-system
  labels:
    workflow.oam.dev/name: enable-addons-test
    workflow.oam.dev/session: qealctrkbx
   ...
--
apiVersion: batch/v1
kind: Job
metadata:
  name: enable-addons-test-qealctrkbx
  namespace: vela-system
  labels:
    enable-addon.oam.dev: enable-addons-test
    workflowrun.oam.dev/name: enable-addons-test
    workflowrun.oam.dev/namespace: vela-system
    ...
  1. Then the clean-jobs runs and that tries for filter both the job and the pod a single parameter for matchingLabels which results in only the pods being cleaned up
if parameter.labelselector == _|_ {
    matchingLabels: "workflow.oam.dev/name": context.name
}

Expected behavior
It should cleanup both pods and jobs

Additional context
A couple of options when it comes to the fix:

  • should the pod have the workflowrun annotation?
  • or should the clean-jobs delete if is workflow or workflowrun which is a trivial fix
@FogDong
Copy link
Member

FogDong commented Nov 24, 2023

The workflowrun.oam.dev/name label is added by the workflowrun controller.
So I think the problem here is because we forget to add workflow.oam.dev/name in job: https://github.com/kubevela/catalog/blob/master/addons/vela-workflow/definitions/addon-operation.cue#L25

I can update this definition or you can also add another clean-jobs step. By default clean-jobs will clean the job and pod with "workflow.oam.dev/name", you can add another step like:

     - name: Clean2
        type: clean-jobs
        if: always
        properties:
          namespace: "vela-system"
          matchingLabels: 
		workflowrun.oam.dev/name: enable-addons-test
				

@oanasc
Copy link
Author

oanasc commented Nov 24, 2023

Appreciated the fix, I personally worked around it by creating my own definition that has a delete for both labels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants