Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Provide optional rollback support for HelmReleases #2006

Merged
merged 7 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions chart/flux/templates/helm-operator-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ spec:
type: boolean
forceUpgrade:
type: boolean
rollback:
type: object
properties:
enable:
type: boolean
force:
type: boolean
recreate:
type: boolean
disableHooks:
type: boolean
timeout:
type: int64
wait:
type: boolean
valueFileSecrets:
type: array
items:
Expand Down
4 changes: 2 additions & 2 deletions cmd/helm-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ func main() {

// the status updater, to keep track of the release status for
// every HelmRelease
statusUpdater := status.New(ifClient, kubeClient, helmClient, *namespace)
go statusUpdater.Loop(shutdown, log.With(logger, "component", "annotator"))
statusUpdater := status.New(ifClient, fhrInformer.Lister(), helmClient)
go statusUpdater.Loop(shutdown, log.With(logger, "component", "statusupdater"))

// start HTTP server
go daemonhttp.ListenAndServe(*listenAddr, chartSync, log.With(logger, "component", "daemonhttp"), shutdown)
Expand Down
15 changes: 15 additions & 0 deletions deploy-helm/flux-helm-release-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ spec:
type: boolean
forceUpgrade:
type: boolean
rollback:
type: object
properties:
enable:
type: boolean
force:
type: boolean
recreate:
type: boolean
disableHooks:
type: boolean
timeout:
type: int64
wait:
type: boolean
valueFileSecrets:
type: array
items:
Expand Down
53 changes: 51 additions & 2 deletions integrations/apis/flux.weave.works/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/ghodss/yaml"
v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/helm/pkg/chartutil"

Expand Down Expand Up @@ -94,7 +94,8 @@ type GitChartSource struct {
SkipDepUpdate bool `json:"skipDepUpdate,omitempty"`
}

// DefaultGitRef is the ref assumed if the Ref field is not given in a GitChartSource
// DefaultGitRef is the ref assumed if the Ref field is not given in
// a GitChartSource
const DefaultGitRef = "master"

func (s GitChartSource) RefOrDefault() string {
Expand All @@ -119,6 +120,22 @@ func (s RepoChartSource) CleanRepoURL() string {
return cleanURL + "/"
}

type Rollback struct {
Enable bool `json:"enable,omitempty"`
Force bool `json:"force,omitempty"`
Recreate bool `json:"recreate,omitempty"`
DisableHooks bool `json:"disableHooks,omitempty"`
Timeout *int64 `json:"timeout,omitempty"`
Wait bool `json:"wait,omitempty"`
}

func (r Rollback) GetTimeout() int64 {
if r.Timeout == nil {
return 300
}
return *r.Timeout
}

// HelmReleaseSpec is the spec for a HelmRelease resource
type HelmReleaseSpec struct {
ChartSource `json:"chart"`
Expand All @@ -135,6 +152,9 @@ type HelmReleaseSpec struct {
// Force resource update through delete/recreate, allows recovery from a failed state
// +optional
ForceUpgrade bool `json:"forceUpgrade,omitempty"`
// Enable rollback and configure options
// +optional
Rollback Rollback `json:"rollback,omitempty"`
}

// GetTimeout returns the install or upgrade timeout (defaults to 300s)
Expand All @@ -145,6 +165,22 @@ func (r HelmRelease) GetTimeout() int64 {
return *r.Spec.Timeout
}

// GetValuesFromSources maintains backwards compatibility with
// ValueFileSecrets by merging them into the ValuesFrom array.
func (r HelmRelease) GetValuesFromSources() []ValuesFromSource {
valuesFrom := r.Spec.ValuesFrom
// Maintain backwards compatibility with ValueFileSecrets
if r.Spec.ValueFileSecrets != nil {
var secretKeyRefs []ValuesFromSource
for _, ref := range r.Spec.ValueFileSecrets {
s := &v1.SecretKeySelector{LocalObjectReference: ref}
secretKeyRefs = append(secretKeyRefs, ValuesFromSource{SecretKeyRef: s})
}
valuesFrom = append(secretKeyRefs, valuesFrom...)
}
return valuesFrom
}

type HelmReleaseStatus struct {
// ReleaseName is the name as either supplied or generated.
// +optional
Expand All @@ -154,6 +190,14 @@ type HelmReleaseStatus struct {
// managed by this resource.
ReleaseStatus string `json:"releaseStatus"`

// ObservedGeneration is the most recent generation observed by
// the controller.
ObservedGeneration int64 `json:"observedGeneration"`

// ValuesChecksum holds the SHA256 checksum of the last applied
// values.
ValuesChecksum string `json:"valuesChecksum"`

// Revision would define what Git hash or Chart version has currently
// been deployed.
// +optional
Expand All @@ -171,6 +215,8 @@ type HelmReleaseCondition struct {
Type HelmReleaseConditionType `json:"type"`
Status v1.ConditionStatus `json:"status"`
// +optional
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// +optional
Reason string `json:"reason,omitempty"`
Expand All @@ -187,6 +233,9 @@ const (
// Released means the chart release, as specified in this
// HelmRelease, has been processed by Helm.
HelmReleaseReleased HelmReleaseConditionType = "Released"
// RolledBack means the chart to which the HelmRelease refers
// has been rolled back
HelmReleaseRolledBack HelmReleaseConditionType = "RolledBack"
)

// FluxHelmValues embeds chartutil.Values so we can implement deepcopy on map[string]interface{}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading