Skip to content

helm rollback with service modification results in inconsistent state #3675

Closed

Description

@ritazh

helm version:

Client: &version.Version{SemVer:“v2.8.2”, GitCommit:“a80231648a1473929271764b920a8e346f6de844", GitTreeState:“clean”}
Server: &version.Version{SemVer:“v2.8.2", GitCommit:“a80231648a1473929271764b920a8e346f6de844”, GitTreeState:“clean”}

After helm rollback (see repro steps below) failed with

Error: Service "" is invalid: spec.ports[0].nodePort: Invalid value: 30849: may not be used when `type` is 'ClusterIP'

Then another helm rollback --force results in

Error: "[release name]" has no deployed releases

The release resulted in a limbo such that helm upgrade cannot find the release and helm install results in

Error: a release named [release name] already exist

Repro steps:

$ helm create chart01
$ helm install --name chart01rel ./chart01
$ # change service.type from ClusterIP to LoadBalancer
$ helm upgrade chart01rel ./chart01
$ # wait for load balancer to get provisioned
$ helm rollback chart01rel 1 --dry-run
Rollback was a success! Happy Helming!
$ helm rollback chart01rel 1
Error: Service "[release name]" is invalid: spec.ports[0].nodePort: Invalid value: 30849: may not be used when `type` is 'ClusterIP'

cc @trstringer

Activity

  1. technosophos commented on Mar 14, 2018

    @technosophos
    Member

    It appears to be the case that Kubernetes is assigning a nodePort to the Service when you change the type from ClusterIP to LoadBalancer. But this is not a valid value for a ClusterIP. So when you roll back, it generates an error when Kubernetes merges the rollback manifest into the running service.

    Note that it is Kubernetes, not Helm, that is automatically adding the nodePort value. It looks like a chart would have to expose nodePort on the service as a configurable parameter so that it could be overridden in cases like this.

  2. koalalorenzo commented on Mar 14, 2018

    @koalalorenzo

    The problem is that helm gets stuck with the pending update. If you run a helm rollback with ‘—force’, it works, but if you don’t the rollback is stuck and the deployment disappears from ‘helm ls’.

  3. koalalorenzo commented on Mar 15, 2018

    @koalalorenzo

    I forgot to say: It is NOT a question, this is a bug, because we are expecting helm to handle the rollback. It may cause outages due to the fact that we can't rollback again.

    So if we deploy something with ClusterIP, then we switch to LoadBalancer by mistake and we want to rollback, we will meet this error (if we don't use --force)... then helm is stuck! If we trigger a second rollback, maybe with --force this time to "fix" the ClusterIP nodePort, all the rollbacks will be "pending", but if we run helm ls the deployment will not be there. We can't do anymore a helm install and we can't do a helm delete

  4. koalalorenzo commented on Mar 15, 2018

    @koalalorenzo

    @bacongobbler Could you label this issue as a Bug or/and give more information?

  5. stuartleeks commented on Mar 15, 2018

    @stuartleeks
    Contributor

    I've just run through the repro steps above and captured a few extra outputs...

    (The chart below is just the output of helm create test)

    Install with ClusterIP
    ~/go/src/k8s.io/helm/bin/helm install --name test ./test --set service.type=ClusterIP

    Upgrade to use LoadBalancer
    ~/go/src/k8s.io/helm/bin/helm upgrade test ./test --set service.type=LoadBalancer

    History:

    $ ~/go/src/k8s.io/helm/bin/helm history test
    REVISION	UPDATED                 	STATUS    	CHART     	DESCRIPTION     
    1       	Thu Mar 15 10:21:51 2018	SUPERSEDED	test-0.1.0	Install complete
    2       	Thu Mar 15 10:23:52 2018	DEPLOYED  	test-0.1.0	Upgrade complete
    

    Rollback to version 1 (ClusterIP)
    ~/go/src/k8s.io/helm/bin/helm rollback test 1

    Error: rpc error: code = Unknown desc = Service "test" is invalid: spec.ports[0].nodePort: Invalid value: 32644: may not be used when `type` is 'ClusterIP'
    
    $ ~/go/src/k8s.io/helm/bin/helm history test
    REVISION	UPDATED                 	STATUS          	CHART     	DESCRIPTION     
    1       	Thu Mar 15 10:21:51 2018	SUPERSEDED      	test-0.1.0	Install complete
    2       	Thu Mar 15 10:23:52 2018	SUPERSEDED      	test-0.1.0	Upgrade complete
    3       	Thu Mar 15 10:25:14 2018	PENDING_ROLLBACK	test-0.1.0	Rollback to 1   
    

    Note that the history shows PENDING_ROLLBACK for the failed rollback. In the tiller logs:

    [tiller] 2018/03/15 10:25:15 warning: Failed to record release test: release: "test.v3" already exists
    

    At this point helm ls returns no entries

    helm install returns

    Error: rpc error: code = Unknown desc = a release named test already exists.
    Run: helm ls --all test; to check the status of the release
    Or run: helm del --purge test; to delete it
    

    helm rollback --force

    Error: rpc error: code = Unknown desc = "test" has no deployed releases
    

    helm upgrade

    Error: UPGRADE FAILED: rpc error: code = Unknown desc = "test" has no deployed releases
    
  6. stuartleeks commented on Mar 15, 2018

    @stuartleeks
    Contributor

    After looking into the tiller error, I noticed that this line has s.recordRelease(targetRelease, false). The false tells recordRelease to try to create the release record but it has already been created by prepareRollback with the PENDING_ROLLBACK status. I changed this line to s.recordRelease(targetRelease, true) and re-tested, and the tiller failed to record release error no longer occurred.

    With this change in place, the history after the failed rollback becomes

    REVISION	UPDATED                 	STATUS    	CHART     	DESCRIPTION                                                 
    1       	Thu Mar 15 11:11:10 2018	SUPERSEDED	test-0.1.0	Install complete                                            
    2       	Thu Mar 15 11:11:16 2018	SUPERSEDED	test-0.1.0	Upgrade complete                                            
    3       	Thu Mar 15 11:11:21 2018	FAILED    	test-0.1.0	Rollback "test" failed: Service "test" is invalid: spec.p...
    
    

    However, helm install and helm upgrade both still fail as before.

  7. bacongobbler commented on Mar 15, 2018

    @bacongobbler
    Member

    Yes, I'll change this to a bug. I was just asleep :)

  8. zaa commented on Mar 31, 2018

    @zaa

    I've tried to reproduce the issue using kubectl apply and got the same issue. So I think the analysis from @technosophos is right here, you should expose nodePort in the helm chart explicitly and set it to 0 for the service of type ClusterIP.

    I0331 16:56:29.063604   31838 request.go:873] Request Body: {"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"name\":\"pgsql\",\"namespace\":\"default\"},\"spec\":{\"ports\":[{\"name\":\"postgres\",\"port\":5432,\"protocol\":\"TCP\",\"targetPort\":5432}],\"selector\":{\"app\":\"pm-postgres\"},\"type\":\"ClusterIP\"}}\n"}},"spec":{"type":"ClusterIP"}}
    I0331 16:56:29.063655   31838 round_trippers.go:417] curl -k -v -XPATCH  -H "Accept: application/json" -H "Content-Type: application/strategic-merge-patch+json" -H "User-Agent: kubectl/v1.9.4 (darwin/amd64) kubernetes/bee2d15" https://192.168.99.100:8443/api/v1/namespaces/default/services/pgsql
    I0331 16:56:29.065930   31838 round_trippers.go:436] PATCH https://192.168.99.100:8443/api/v1/namespaces/default/services/pgsql 422 Unprocessable Entity in 2 milliseconds
    I0331 16:56:29.065958   31838 round_trippers.go:442] Response Headers:
    I0331 16:56:29.065965   31838 round_trippers.go:445]     Content-Type: application/json
    I0331 16:56:29.065972   31838 round_trippers.go:445]     Content-Length: 426
    I0331 16:56:29.065978   31838 round_trippers.go:445]     Date: Sat, 31 Mar 2018 12:56:29 GMT
    I0331 16:56:29.066011   31838 request.go:873] Response Body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Service \"pgsql\" is invalid: spec.ports[0].nodePort: Invalid value: 32535: may not be used when `type` is 'ClusterIP'","reason":"Invalid","details":{"name":"pgsql","kind":"Service","causes":[{"reason":"FieldValueInvalid","message":"Invalid value: 32535: may not be used when `type` is 'ClusterIP'","field":"spec.ports[0].nodePort"}]},"code":422}
    F0331 16:56:29.066306   31838 helpers.go:119] The Service "pgsql" is invalid: spec.ports[0].nodePort: Invalid value: 32535: may not be used when `type` is 'ClusterIP'
    

    Second attempt where the port definition has nodePort set to 0:

    I0331 16:59:19.686756   31843 request.go:873] Request Body: {"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"name\":\"pgsql\",\"namespace\":\"default\"},\"spec\":{\"ports\":[{\"name\":\"postgres\",\"nodePort\":0,\"port\":5432,\"protocol\":\"TCP\",\"targetPort\":5432}],\"selector\":{\"app\":\"pm-postgres\"},\"type\":\"ClusterIP\"}}\n"}},"spec":{"$setElementOrder/ports":[{"port":5432}],"ports":[{"nodePort":0,"port":5432}],"type":"ClusterIP"}}
    I0331 16:59:19.686807   31843 round_trippers.go:417] curl -k -v -XPATCH  -H "Content-Type: application/strategic-merge-patch+json" -H "Accept: application/json" -H "User-Agent: kubectl/v1.9.4 (darwin/amd64) kubernetes/bee2d15" https://192.168.99.100:8443/api/v1/namespaces/default/services/pgsql
    I0331 16:59:19.696914   31843 round_trippers.go:436] PATCH https://192.168.99.100:8443/api/v1/namespaces/default/services/pgsql 200 OK in 10 milliseconds
    I0331 16:59:19.696944   31843 round_trippers.go:442] Response Headers:
    I0331 16:59:19.696951   31843 round_trippers.go:445]     Content-Type: application/json
    I0331 16:59:19.696958   31843 round_trippers.go:445]     Content-Length: 851
    I0331 16:59:19.696964   31843 round_trippers.go:445]     Date: Sat, 31 Mar 2018 12:59:19 GMT
    I0331 16:59:19.697006   31843 request.go:873] Response Body: {"kind":"Service","apiVersion":"v1","metadata":{"name":"pgsql","namespace":"default","selfLink":"/api/v1/namespaces/default/services/pgsql","uid":"2b7540cf-34e2-11e8-ab23-0800274f8495","resourceVersion":"309124","creationTimestamp":"2018-03-31T12:51:03Z","annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"name\":\"pgsql\",\"namespace\":\"default\"},\"spec\":{\"ports\":[{\"name\":\"postgres\",\"nodePort\":0,\"port\":5432,\"protocol\":\"TCP\",\"targetPort\":5432}],\"selector\":{\"app\":\"pm-postgres\"},\"type\":\"ClusterIP\"}}\n"}},"spec":{"ports":[{"name":"postgres","protocol":"TCP","port":5432,"targetPort":5432}],"selector":{"app":"pm-postgres"},"clusterIP":"10.105.94.171","type":"ClusterIP","sessionAffinity":"None"},"status":{"loadBalancer":{}}}```
    
  9. stuartleeks commented on May 10, 2018

    @stuartleeks
    Contributor

    The underlying issue here is that we tried to transition from ClusterIP -> LoadBalancer -> ClusterIP, and the second transition failed because nodePort was configured by LoadBalancer and is invalid for ClusterIP. The comment from @zaa is useful thinking about this going forwards for this particular case.

    However, in terms of the state of the release in helm I believe that there is an underlying issue with helm: we got to a situation that we could only recover from with helm delete and starting over.

    I recently spent some time digging into this with @technosophos and have done some more research since that I'd like to add to the thread for discussion.

    In the case of this issue, we arrived at the "no way forward" situation by doing the LoadBalancer -> ClusterIP transition as a rollback. I figured that it should be possible to do that transition as an upgrade and expected to reach the same "no way forward" situation with helm.... but I didn't!

    Doing this as a rollback I ended up with:

    REVISION    UPDATED                     STATUS              CHART              DESCRIPTION                                                  
    
    1           Thu May  3 15:57:13 2018    SUPERSEDED          helm-test-0.1.0    Install complete                                             
    
    2           Thu May  3 15:57:16 2018    SUPERSEDED          helm-test-0.1.0    Upgrade complete                                             
    
    3           Thu May  3 15:57:18 2018    FAILED              helm-test-0.1.0    Rollback "failed-rollback" failed: Service "failed-rollba... 
    

    And at this point neither upgrade nor rollback will allow you to proceed.

    However, with upgrade I ended up with:

    REVISION    UPDATED                     STATUS        CHART              DESCRIPTION                                                  
    
    1           Thu May  3 15:59:25 2018    SUPERSEDED    helm-test-0.1.0    Install complete                                             
    
    2           Thu May  3 15:59:27 2018    DEPLOYED      helm-test-0.1.0    Upgrade complete                                             
    
    3           Thu May  3 15:59:29 2018    FAILED        helm-test-0.1.0    Upgrade "failed-upgrade" failed: Service "failed-upgrade-... 
    

    The key difference here is that we still have a revision marked as deployed.

    So for a failed upgrade the previous release is left as DEPLOYED whereas for a failed rollback the previous release is marked as SUPERSEDED.

    Looking back in history, I first found #1137 that discusses this behaviour and seems to suggest that the current rollback behaviour is expected. There are two PRs referenced from the issue that add in the SUPERSEDED behaviour (tagging @michelleN as the contributor of those PRs :-)). Looking back in the code logs, I then found this change that reversed the behaviour as part of fixing #2437

    At this point I'm confused as to what the behaviour should be!

    What should be the behaviour for rollback/upgrade in terms of whether they leave the previously revision as DEPLOYED vs SUPERSEDED on failure?

  10. technosophos commented on May 11, 2018

    @technosophos
    Member
  11. adamreese commented on May 15, 2018

    @adamreese
    Member

    I paired with @technosophos on this and found two issues beings discussed in this thread.

    The first one is a bug that was introduced in the refactor on kubernetes v1.10 that no longer validated objects against a schema. Fixed now in #4042. This should capture all the examples listed in the issue.

    The second issue is how we handle releases in a failed state. When a failure occurs during a release some resources could be deployed/patched/deleted/created and in a broken state. To calculate a patch to rollback is difficult because we don't know the full state of the cluster anymore. We make assumptions that try to get it close. For helm 3 I am looking at ways we can implement a proper reconcile against cluster resources.

  12. SlickNik commented on May 16, 2018

    @SlickNik
    Member

    @adamreese Thanks for the update and the fix!

    Given that we have the fix for this in #4042 and are planning to further address this reconciliation with our Helm 3 design, should we go ahead and close out this issue? Or would you prefer to keep it open to validate the Helm 3 design against?

  13. ritazh commented on May 18, 2018

    @ritazh
    Author

    Thanks everyone for chiming in and fixing this bug!!! 👏 If it's ok with everyone, let's keep this issue open so we can validate how we handle releases in a failed state against Helm 3.

  14. added
    bug
    and removed on Jun 5, 2018
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions