Skip to content

Commit

Permalink
fix: enable custom key for a secret
Browse files Browse the repository at this point in the history
  • Loading branch information
sebltm committed Dec 27, 2023
1 parent a47edf2 commit 6af05fc
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 23 deletions.
16 changes: 15 additions & 1 deletion api/v1alpha1/helmchartproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const (
// HelmChartProxyFinalizer is the finalizer used by the HelmChartProxy controller to cleanup add-on resources when
// a HelmChartProxy is being deleted.
HelmChartProxyFinalizer = "helmchartproxy.addons.cluster.x-k8s.io"

// Default OCI secret key
DefaultOCIKey = "config.json"
)

// HelmChartProxySpec defines the desired state of HelmChartProxy.
Expand Down Expand Up @@ -68,7 +71,7 @@ type HelmChartProxySpec struct {

// CredentialsSecretRef is a reference to a Secret containing the OCI credentials. If it is not specified, no Secret will be used.
// +optional
CredentialsSecretRef *corev1.SecretReference `json:"credentialsSecretRef,omitempty"`
CredentialsSecretRef *SecretKeyRef `json:"credentialsSecretRef,omitempty"`
}

type HelmOptions struct {
Expand Down Expand Up @@ -185,6 +188,17 @@ type HelmUninstallOptions struct {
Description string `json:"description,omitempty"`
}

type SecretKeyRef struct {
// Name is the name of the Secret containing the OCI credentials.
Name string `json:"name"`

// Namespace is the namespace of the Secret containing the OCI credentials.
Namespace string `json:"namespace"`

// Key is the key in the Secret containing the OCI credentials.
Key string `json:"key"`
}

// HelmChartProxyStatus defines the observed state of HelmChartProxy.
type HelmChartProxyStatus struct {
// Conditions defines current state of the HelmChartProxy.
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 @@ -73,7 +73,7 @@ type HelmReleaseProxySpec struct {

// CredentialsSecretRef is a reference to a Secret containing the OCI credentials. If it is not specified, no Secret will be used.
// +optional
CredentialsSecretRef *corev1.SecretReference `json:"credentialsSecretRef,omitempty"`
CredentialsSecretRef *SecretKeyRef `json:"credentialsSecretRef,omitempty"`
}

// HelmReleaseProxyStatus defines the observed state of HelmReleaseProxy.
Expand Down
27 changes: 21 additions & 6 deletions api/v1alpha1/zz_generated.deepcopy.go

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

16 changes: 11 additions & 5 deletions config/crd/bases/addons.cluster.x-k8s.io_helmchartproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,22 @@ spec:
description: CredentialsSecretRef is a reference to a Secret containing
the OCI credentials. If it is not specified, no Secret will be used.
properties:
key:
description: Key is the key in the Secret containing the OCI credentials.
type: string
name:
description: name is unique within a namespace to reference a
secret resource.
description: Name is the name of the Secret containing the OCI
credentials.
type: string
namespace:
description: namespace defines the space within which the secret
name must be unique.
description: Namespace is the namespace of the Secret containing
the OCI credentials.
type: string
required:
- key
- name
- namespace
type: object
x-kubernetes-map-type: atomic
namespace:
description: ReleaseNamespace is the namespace the Helm release will
be installed on each selected Cluster. If it is not specified, it
Expand Down
16 changes: 11 additions & 5 deletions config/crd/bases/addons.cluster.x-k8s.io_helmreleaseproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,22 @@ spec:
description: CredentialsSecretRef is a reference to a Secret containing
the OCI credentials. If it is not specified, no Secret will be used.
properties:
key:
description: Key is the key in the Secret containing the OCI credentials.
type: string
name:
description: name is unique within a namespace to reference a
secret resource.
description: Name is the name of the Secret containing the OCI
credentials.
type: string
namespace:
description: namespace defines the space within which the secret
name must be unique.
description: Namespace is the namespace of the Secret containing
the OCI credentials.
type: string
required:
- key
- name
- namespace
type: object
x-kubernetes-map-type: atomic
namespace:
description: ReleaseNamespace is the namespace the Helm release will
be installed on the referenced Cluster. If it is not specified,
Expand Down
12 changes: 12 additions & 0 deletions controllers/helmchartproxy/helmchartproxy_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ func constructHelmReleaseProxy(existing *addonsv1alpha1.HelmReleaseProxy, helmCh
helmReleaseProxy.Spec.Options = helmChartProxy.Spec.Options
helmReleaseProxy.Spec.CredentialsSecretRef = helmChartProxy.Spec.CredentialsSecretRef

if helmReleaseProxy.Spec.CredentialsSecretRef != nil {
// If the namespace is not set, set it to the namespace of the HelmChartProxy
if helmReleaseProxy.Spec.CredentialsSecretRef.Namespace == "" {
helmReleaseProxy.Spec.CredentialsSecretRef.Namespace = helmChartProxy.Namespace
}

// If the key is not set, set it to the default key
if helmReleaseProxy.Spec.CredentialsSecretRef.Key == "" {
helmReleaseProxy.Spec.CredentialsSecretRef.Key = addonsv1alpha1.DefaultOCIKey
}
}

// Set the default value for EnableClientCache if it is not set
if helmReleaseProxy.Spec.Options.EnableClientCache == nil {
helmReleaseProxy.Spec.Options.EnableClientCache = &defaultEnableClientCache
Expand Down
Loading

0 comments on commit 6af05fc

Please sign in to comment.