Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

Commit

Permalink
use ReleaseHistory Tiller GRPC call to check state
Browse files Browse the repository at this point in the history
Switches to using the ReleaseHistory GRPC call to see if the chart
release exists or not. If it doesn't exist, install the chart, otherwise
upgrade it.
  • Loading branch information
Adnan Abdulhussein committed Dec 6, 2017
1 parent fe21f9d commit 4da569b
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func releaseName(ns, name string) string {
func isNotFound(err error) bool {
// Ideally this would be `grpc.Code(err) == codes.NotFound`,
// but it seems helm doesn't return grpc codes
return strings.Contains(grpc.ErrorDesc(err), "has no deployed releases")
return strings.Contains(grpc.ErrorDesc(err), "not found")
}

func (c *Controller) updateRelease(key string) error {
Expand Down Expand Up @@ -230,19 +230,12 @@ func (c *Controller) updateRelease(key string) error {

var rel *release.Release

log.Printf("Updating release %s", rlsName)
res, err := c.helmClient.UpdateReleaseFromChart(
rlsName,
chartRequested,
helm.UpdateValueOverrides([]byte(helmObj.Spec.Values)),
//helm.UpgradeForce(true), ?
)
_, err = c.helmClient.ReleaseHistory(rlsName, helm.WithMaxHistory(1))
if err != nil {
if !isNotFound(err) {
return err
}

log.Printf("Existing release %s not found -> installing into namespace %s", rlsName, helmObj.Namespace)
log.Printf("Installing release %s into namespace %s", rlsName, helmObj.Namespace)
res, err := c.helmClient.InstallReleaseFromChart(
chartRequested,
helmObj.Namespace,
Expand All @@ -254,6 +247,16 @@ func (c *Controller) updateRelease(key string) error {
}
rel = res.GetRelease()
} else {
log.Printf("Updating release %s", rlsName)
res, err := c.helmClient.UpdateReleaseFromChart(
rlsName,
chartRequested,
helm.UpdateValueOverrides([]byte(helmObj.Spec.Values)),
//helm.UpgradeForce(true), ?
)
if err != nil {
return err
}
rel = res.GetRelease()
}

Expand Down

0 comments on commit 4da569b

Please sign in to comment.