Skip to content

Helm upgrade doesn't wait for Job to complete #5948

Closed

Description

@wieslaw-decent

Output of helm version:

Client: &version.Version{SemVer:"v2.14.1", GitCommit:"5270352a09c7e8b6e8c9593002a73535276507c0", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.14.1", GitCommit:"5270352a09c7e8b6e8c9593002a73535276507c0", GitTreeState:"clean"}

Output of kubectl version:

Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.6", GitCommit:"abdda3f9fefa29172298a2e42f5102e777a8ec25", GitTreeState:"clean", BuildDate:"2019-05-08T13:53:53Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.6-gke.13", GitCommit:"fcbc1d20b6bca1936c0317743055ac75aef608ce", GitTreeState:"clean", BuildDate:"2019-06-19T20:50:07Z", GoVersion:"go1.11.5b4", Compiler:"gc", Platform:"linux/amd64"}

Cloud Provider/Platform (AKS, GKE, Minikube etc.): GKE

I'm installing a chart that consists of a single Kubernetes Job. Since I want it to run on every upgrade, I've given it a name that changes each time:
name: keycloak-migrations-{{ now | date "20060102150405" }}

The problem is that Helm doesn't seem to wait for the Job to finish properly:

% helm upgrade --wait -i keycloak-post-install .                                                         Release "keycloak-post-install" has been upgraded.
LAST DEPLOYED: Wed Jun 26 20:08:22 2019
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1/ConfigMap
NAME                 DATA  AGE
keycloak-migrations  1     95s

==> v1/Job
NAME                                COMPLETIONS  DURATION  AGE
keycloak-migrations-20190626180822  0/1          7s        7s

==> v1/Pod(related)
NAME                                      READY  STATUS   RESTARTS  AGE
keycloak-migrations-20190626180822-bc7zl  1/1    Running  0         7s

I guess this is a bug, since Helm waited for all of the other Jobs I've run using it.
Additional question: is there a simple way to run a Job on each upgrade?

Activity

  1. mfilotto commented on Jun 27, 2019

    @mfilotto

    I'm afraid Jobs are not managed by helm

  2. mfilotto commented on Jun 27, 2019

    @mfilotto

    I tried to set the Job as a hook but then I have the error "failed: no objects visited"
    #4670

  3. hickeyma commented on Jun 27, 2019

    @hickeyma
    Contributor

    @mfilotto Jobs are managed by Helm. The discussion in #4670 mentions the use of hooks which are "un-managed" and if you have a chart which has everything marked as a hook then there is nothing to install (#4670 (comment)).

  4. hickeyma commented on Jun 27, 2019

    @hickeyma
    Contributor

    @wieslaw-decent Can you show the job so I can get a better understanding of the situation?

  5. wieslaw-decent commented on Jun 27, 2019

    @wieslaw-decent
    Author

    @hickeyma sure! here you go:

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: keycloak-migrations-{{ now | date "20060102150405" }}
    spec:
      backoffLimit: 1
      activeDeadlineSeconds: 1800
      template:
        metadata:
          labels:
            app: keycloak
        spec:
          containers:
          - image: us.gcr.io/XXX/keycloak:latest
            name: migrations
            command: ["/bin/bash", "-x", "/usr/src/migrate.sh"]
            env:
            - name: KEYCLOAK_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: keycloak-admin
                  key: password
            resources:
              limits:
                cpu: 1
                memory: 2Gi
              requests:
                cpu: 50m
                memory: 1Gi
            volumeMounts:
            - name: config-volume
              mountPath: /usr/src
          securityContext:
            fsGroup: 1000
            runAsNonRoot: true
            runAsUser: 1000
          volumes:
            - name: config-volume
              configMap:
                name: keycloak-migrations
          restartPolicy: Never
    

    No annotations are present, so it shouldn't be treated as a hook.

  6. NandoTheessen commented on Jul 5, 2019

    @NandoTheessen

    I believe this does not only apply to hooks but also secrets, jobs and a few others! You can read more about it in the issue #4670 where there is a full list.

  7. hickeyma commented on Jul 8, 2019

    @hickeyma
    Contributor

    @thomastaylor312 You have been looking into the --wait capability lately. You might be best placed to comment on this?

  8. thomastaylor312 commented on Jul 8, 2019

    @thomastaylor312
    Contributor

    Ok, so the behavior here is correct. Helm only waits for Jobs that are hooks. However, the --wait flag does not support waiting for jobs, so I think this would correctly be classified as a feature request. Is that fair @wieslaw-decent?

  9. wieslaw-decent commented on Jul 17, 2019

    @wieslaw-decent
    Author

    Thanks for looking into it, @thomastaylor312 sounds fair enough to me!

  10. jasondamour commented on Mar 4, 2020

    @jasondamour

    @thomastaylor312 @wieslaw-decent With helm 3 out now, is there any change to this? Can helm 3 return the exit code of jobs, or is it still a feature request

  11. desaintmartin commented on Jun 17, 2020

    @desaintmartin

    This issue is interesting.

    Let's say we have:
    1/ A Statefulset with a database to deploy
    2/ a Job containing a script that initializes the database, waiting for the database to be started as initContainer
    3/ a Deployment containing the application server, waiting for the database to be started as initContainer, and simply raising exceptions if access while the database is not initialized yet

    As there is no order, everything is ran in parallel, which is not an issue and works well... Unless the job fails. In this case, the deployment is successful in theory (every resource is Running, so Helm considers this a success), but a failure in practice.

    Should we have an "expected state" annotation, like finished, so that we can state that we want this Job to be completed, not simply running? Or are we expected to use another architecture?

  12. zh168654 commented on Jul 1, 2020

    @zh168654
    Contributor

    @thomastaylor312 @hickeyma I've submitted a PR to implement this, could you please take a look. Thanks

  13. github-actions commented on Nov 22, 2020

    @github-actions

    This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

  14. saada commented on Nov 22, 2020

    @saada

    unstale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions