Skip to content

Commit

Permalink
Merge pull request #168 from Jont828/depointer-helm-options
Browse files Browse the repository at this point in the history
🌱 Convert pointer types in Helm options to regular fields
  • Loading branch information
k8s-ci-robot authored Feb 7, 2024
2 parents 78b193b + fa594f1 commit c3a07aa
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 254 deletions.
15 changes: 9 additions & 6 deletions api/v1alpha1/helmchartproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type HelmChartProxySpec struct {
// Options represents CLI flags passed to Helm operations (i.e. install, upgrade, delete) and
// include options such as wait, skipCRDs, timeout, waitForJobs, etc.
// +optional
Options *HelmOptions `json:"options,omitempty"`
Options HelmOptions `json:"options,omitempty"`

// Credentials is a reference to an object containing the OCI credentials. If it is not specified, no credentials will be used.
// +optional
Expand Down Expand Up @@ -119,30 +119,32 @@ type HelmOptions struct {
// Install represents CLI flags passed to Helm install operation which can be used to control
// behaviour of helm Install operations via options like wait, skipCrds, timeout, waitForJobs, etc.
// +optional
Install *HelmInstallOptions `json:"install,omitempty"`
Install HelmInstallOptions `json:"install,omitempty"`

// Upgrade represents CLI flags passed to Helm upgrade operation which can be used to control
// behaviour of helm Upgrade operations via options like wait, skipCrds, timeout, waitForJobs, etc.
// +optional
Upgrade *HelmUpgradeOptions `json:"upgrade,omitempty"`
Upgrade HelmUpgradeOptions `json:"upgrade,omitempty"`

// Uninstall represents CLI flags passed to Helm uninstall operation which can be used to control
// behaviour of helm Uninstall operation via options like wait, timeout, etc.
// +optional
Uninstall *HelmUninstallOptions `json:"uninstall,omitempty"`

// EnableClientCache is a flag to enable Helm client cache. If it is not specified, it will be set to true.
// +kubebuilder:default=false
// +optional
EnableClientCache *bool `json:"enableClientCache,omitempty"`
EnableClientCache bool `json:"enableClientCache,omitempty"`
}

type HelmInstallOptions struct {
// CreateNamespace indicates the Helm install/upgrade action to create the
// HelmChartProxySpec.ReleaseNamespace if it does not exist yet.
// On uninstall, the namespace will not be garbage collected.
// If it is not specified by user, will be set to default 'true'.
// +kubebuilder:default=true
// +optional
CreateNamespace *bool `json:"createNamespace,omitempty"`
CreateNamespace bool `json:"createNamespace,omitempty"`

// IncludeCRDs determines whether CRDs stored as a part of helm templates directory should be installed.
// +optional
Expand All @@ -167,7 +169,8 @@ type HelmUpgradeOptions struct {
// +optional
Recreate bool `json:"recreate,omitempty"`

// MaxHistory limits the maximum number of revisions saved per release
// MaxHistory limits the maximum number of revisions saved per release (default is 10).
// +kubebuilder:default=10
// +optional
MaxHistory int `json:"maxHistory,omitempty"`

Expand Down
18 changes: 6 additions & 12 deletions api/v1alpha1/helmchartproxy_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
Expand All @@ -45,7 +44,7 @@ func (r *HelmChartProxy) SetupWebhookWithManager(mgr ctrl.Manager) error {

var _ webhook.Defaulter = &HelmChartProxy{}

const helmTimeout = time.Second * 600
const helmTimeout = 10 * time.Minute

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (p *HelmChartProxy) Default() {
Expand All @@ -55,18 +54,13 @@ func (p *HelmChartProxy) Default() {
p.Spec.ReleaseNamespace = "default"
}

// If 'Wait' is set, we need to set default 'Timeout' to make install successful.
if p.Spec.Options != nil && p.Spec.Options.Wait && p.Spec.Options.Timeout == nil {
p.Spec.Options.Timeout = &metav1.Duration{Duration: helmTimeout}
if p.Spec.Options.Atomic {
p.Spec.Options.Wait = true
}

// If 'CreateNamespace' is not specified by user, set default value to 'true'
if p.Spec.Options != nil {
if p.Spec.Options.Install == nil {
p.Spec.Options.Install = &HelmInstallOptions{CreateNamespace: ptr.To(true)}
} else if p.Spec.Options.Install.CreateNamespace == nil {
p.Spec.Options.Install.CreateNamespace = ptr.To(true)
}
// Note: timeout is also needed to ensure that Spec.Options.Wait works.
if p.Spec.Options.Timeout == nil {
p.Spec.Options.Timeout = &metav1.Duration{Duration: helmTimeout}
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/helmreleaseproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type HelmReleaseProxySpec struct {
// Options represents the helm setting options which can be used to control behaviour of helm operations(Install, Upgrade, Delete, etc)
// via options like wait, skipCrds, timeout, waitForJobs, etc.
// +optional
Options *HelmOptions `json:"options,omitempty"`
Options HelmOptions `json:"options,omitempty"`

// Credentials is a reference to an object containing the OCI credentials. If it is not specified, no credentials will be used.
// +optional
Expand Down
34 changes: 4 additions & 30 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ spec:
validation is enforced.
type: boolean
enableClientCache:
default: false
description: EnableClientCache is a flag to enable Helm client
cache. If it is not specified, it will be set to true.
type: boolean
Expand All @@ -166,6 +167,7 @@ spec:
behaviour of helm Install operations via options like wait, skipCrds, timeout, waitForJobs, etc.
properties:
createNamespace:
default: true
description: |-
CreateNamespace indicates the Helm install/upgrade action to create the
HelmChartProxySpec.ReleaseNamespace if it does not exist yet.
Expand Down Expand Up @@ -224,8 +226,9 @@ spec:
This should be used with caution.
type: boolean
maxHistory:
default: 10
description: MaxHistory limits the maximum number of revisions
saved per release
saved per release (default is 10).
type: integer
recreate:
description: Recreate will (if true) recreate pods after a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ spec:
validation is enforced.
type: boolean
enableClientCache:
default: false
description: EnableClientCache is a flag to enable Helm client
cache. If it is not specified, it will be set to true.
type: boolean
Expand All @@ -175,6 +176,7 @@ spec:
behaviour of helm Install operations via options like wait, skipCrds, timeout, waitForJobs, etc.
properties:
createNamespace:
default: true
description: |-
CreateNamespace indicates the Helm install/upgrade action to create the
HelmChartProxySpec.ReleaseNamespace if it does not exist yet.
Expand Down Expand Up @@ -233,8 +235,9 @@ spec:
This should be used with caution.
type: boolean
maxHistory:
default: 10
description: MaxHistory limits the maximum number of revisions
saved per release
saved per release (default is 10).
type: integer
recreate:
description: Recreate will (if true) recreate pods after a
Expand Down
11 changes: 0 additions & 11 deletions controllers/helmchartproxy/helmchartproxy_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

var defaultEnableClientCache = true

// deleteOrphanedHelmReleaseProxies deletes any HelmReleaseProxy resources that belong to a Cluster that is not selected by its parent HelmChartProxy.
func (r *HelmChartProxyReconciler) deleteOrphanedHelmReleaseProxies(ctx context.Context, helmChartProxy *addonsv1alpha1.HelmChartProxy, clusters []clusterv1.Cluster, helmReleaseProxies []addonsv1alpha1.HelmReleaseProxy) error {
log := ctrl.LoggerFrom(ctx)
Expand Down Expand Up @@ -229,15 +227,6 @@ func constructHelmReleaseProxy(existing *addonsv1alpha1.HelmReleaseProxy, helmCh
}
}

// Set the default value for EnableClientCache if it is not set
if helmReleaseProxy.Spec.Options == nil {
helmReleaseProxy.Spec.Options = &addonsv1alpha1.HelmOptions{}
}

if helmReleaseProxy.Spec.Options.EnableClientCache == nil {
helmReleaseProxy.Spec.Options.EnableClientCache = &defaultEnableClientCache
}

return helmReleaseProxy
}

Expand Down
Loading

0 comments on commit c3a07aa

Please sign in to comment.