Skip to content

Commit

Permalink
feat: remove HelmChart struct, split it between new HelmConfig struct…
Browse files Browse the repository at this point in the history
… and existing HelmRelease struct
  • Loading branch information
ahmad-ibra committed Jul 30, 2024
1 parent 4c85249 commit 36874a6
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 37 deletions.
11 changes: 10 additions & 1 deletion api/v1alpha1/validatorconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (

// ValidatorConfigSpec defines the desired state of ValidatorConfig.
type ValidatorConfigSpec struct {
// HelmConfig defines the configuration for the Helm repository.
HelmConfig HelmConfig `json:"helmConfig" yaml:"helmConfig"`

// Plugins defines the configuration for the validator plugins.
Plugins []HelmRelease `json:"plugins,omitempty" yaml:"plugins,omitempty"`

Expand Down Expand Up @@ -54,11 +57,17 @@ type HelmChart struct {
// Name of the Helm chart.
Name string `json:"name" yaml:"name"`

// Repository URL of the Helm chart.
// Repository of the Helm chart.
Repository string `json:"repository" yaml:"repository"`

// Version of the Helm chart.
Version string `json:"version" yaml:"version"`
}

// HelmConfig defines the configuration for the Helm registry.
type HelmConfig struct {
// Registry is the URL of the Helm registry.
Registry string `json:"registry" yaml:"registry"`

// CAFile is the path to the CA certificate for the Helm repository.
CAFile string `json:"caFile,omitempty" yaml:"caFile,omitempty"`
Expand Down
16 changes: 16 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

3 changes: 2 additions & 1 deletion chart/validator/README.md

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion chart/validator/templates/validator-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ kind: ValidatorConfig
metadata:
name: validator-config
spec:
helmConfig:
registry: {{ required ".Values.helmConfig.registry is required!" .Values.helmConfig.registry }}
{{- if .Values.helmConfig.caFile }}
caFile: {{ .Values.helmConfig.caFile }}
{{- end }}
{{- if .Values.helmConfig.insecureSkipVerify }}
insecureSkipVerify: {{ .Values.helmConfig.insecureSkipVerify }}
{{- end }}
{{- if .Values.helmConfig.authSecretName }}
authSecretName: {{ .Values.helmConfig.authSecretName }}
{{- end }}
plugins:
{{- range .Values.plugins }}
-
Expand All @@ -22,4 +33,4 @@ spec:
sink:
type: {{ required ".Values.sink.type is required!" .Values.sink.type }}
secretName: {{ required ".Values.sink.secretName is required!" .Values.sink.secretName }}
{{- end }}
{{- end }}
17 changes: 10 additions & 7 deletions chart/validator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,14 @@ pluginSecrets:
# <your public key content here>
# -----END PUBLIC KEY-----

helmConfig:
registry: "https://validator-labs.github.io"

# Validation plugin charts
plugins:
- chart:
name: validator-plugin-azure
repository: "https://validator-labs.github.io/validator-plugin-azure"
repository: validator-plugin-azure
version: v0.0.14
values: |-
controllerManager:
Expand Down Expand Up @@ -264,7 +267,7 @@ plugins:
serviceAccountName: ""
- chart:
name: validator-plugin-oci
repository: "https://validator-labs.github.io/validator-plugin-oci"
repository: validator-plugin-oci
version: v0.0.12
values: |-
controllerManager:
Expand Down Expand Up @@ -321,7 +324,7 @@ plugins:
type: ClusterIP
- chart:
name: validator-plugin-kubescape
repository: "https://validator-labs.github.io/validator-plugin-kubescape"
repository: validator-plugin-kubescape
version: v0.0.4
values: |-
controllerManager:
Expand Down Expand Up @@ -386,7 +389,7 @@ plugins:
type: ClusterIP
- chart:
name: validator-plugin-aws
repository: "https://validator-labs.github.io/validator-plugin-aws"
repository: validator-plugin-aws
version: v0.1.2
values: |-
controllerManager:
Expand Down Expand Up @@ -453,7 +456,7 @@ plugins:
serviceAccountName: ""
- chart:
name: validator-plugin-network
repository: "https://validator-labs.github.io/validator-plugin-network"
repository: validator-plugin-network
version: v0.0.20
values: |-
controllerManager:
Expand Down Expand Up @@ -512,7 +515,7 @@ plugins:
type: ClusterIP
- chart:
name: validator-plugin-maas
repository: "https://validator-labs.github.io/validator-plugin-maas"
repository: validator-plugin-maas
version: v0.0.5
values: |-
controllerManager:
Expand Down Expand Up @@ -569,7 +572,7 @@ plugins:
type: ClusterIP
- chart:
name: validator-plugin-vsphere
repository: "https://validator-labs.github.io/validator-plugin-vsphere"
repository: validator-plugin-vsphere
version: v0.0.28
values: |-
controllerManager:
Expand Down
37 changes: 24 additions & 13 deletions config/crd/bases/validation.spectrocloud.labs_validatorconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ spec:
spec:
description: ValidatorConfigSpec defines the desired state of ValidatorConfig.
properties:
helmConfig:
description: HelmConfig defines the configuration for the Helm repository.
properties:
authSecretName:
description: AuthSecretName is the name of the K8s secret containing
the authentication details for the Helm repository.
type: string
caFile:
description: CAFile is the path to the CA certificate for the
Helm repository.
type: string
insecureSkipVerify:
description: InsecureSkipTLSVerify skips the verification of the
server's certificate chain and host name.
type: boolean
registry:
description: Registry is the URL of the Helm registry.
type: string
required:
- registry
type: object
plugins:
description: Plugins defines the configuration for the validator plugins.
items:
Expand All @@ -48,23 +69,11 @@ spec:
chart:
description: Chart defines the Helm chart to be installed.
properties:
authSecretName:
description: AuthSecretName is the name of the K8s secret
containing the authentication details for the Helm repository.
type: string
caFile:
description: CAFile is the path to the CA certificate for
the Helm repository.
type: string
insecureSkipVerify:
description: InsecureSkipTLSVerify skips the verification
of the server's certificate chain and host name.
type: boolean
name:
description: Name of the Helm chart.
type: string
repository:
description: Repository URL of the Helm chart.
description: Repository of the Helm chart.
type: string
version:
description: Version of the Helm chart.
Expand Down Expand Up @@ -100,6 +109,8 @@ spec:
- secretName
- type
type: object
required:
- helmConfig
type: object
status:
description: ValidatorConfigStatus defines the observed state of ValidatorConfig
Expand Down
3 changes: 3 additions & 0 deletions hack/chart/values-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,8 @@ pluginSecrets:
# <your public key content here>
# -----END PUBLIC KEY-----

helmConfig:
registry: "https://validator-labs.github.io"

# Validation plugin charts
plugins:
4 changes: 2 additions & 2 deletions hack/update-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function addChartValues {
cat <<EOF >> chart/validator/values.yaml
- chart:
name: $1
repository: "https://validator-labs.github.io/$1"
repository: $1
version: v$2
values: |-
$indentedValues
Expand Down Expand Up @@ -65,4 +65,4 @@ versions["oci"]=$OCI_VERSION
versions["vsphere"]=$VSPHERE_VERSION

updateHaulerManifest
updateValues
updateValues
2 changes: 1 addition & 1 deletion hauler-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ metadata:
spec:
files:
- name: validatorctl
path: https://github.com/validator-labs/validatorctl/releases/download/v0.0.5/validator-linux-amd64
path: https://github.com/validator-labs/validatorctl/releases/download/v0.0.6/validator-linux-amd64
6 changes: 4 additions & 2 deletions internal/controller/testdata/vc-network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ metadata:
name: validator-config-test
namespace: validator
spec:
helmConfig:
registry: https://validator-labs.github.io
authSecretName: validator-plugin-network-chart-secret
plugins:
- chart:
name: validator-plugin-network
repository: https://validator-labs.github.io/validator-plugin-network
authSecretName: validator-plugin-network-chart-secret
repository: validator-plugin-network
version: v0.0.15
values: |-
controllerManager:
Expand Down
11 changes: 6 additions & 5 deletions internal/controller/validatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (r *ValidatorConfigReconciler) redeployIfNeeded(ctx context.Context, vc *v1
specPlugins := make(map[string]bool)
conditions := make([]v1alpha1.ValidatorPluginCondition, len(vc.Spec.Plugins))

helmConfig := vc.Spec.HelmConfig
for i, p := range vc.Spec.Plugins {
specPlugins[p.Chart.Name] = true

Expand All @@ -166,14 +167,14 @@ func (r *ValidatorConfigReconciler) redeployIfNeeded(ctx context.Context, vc *v1

opts := &helm.Options{
Chart: p.Chart.Name,
Repo: p.Chart.Repository,
Repo: fmt.Sprintf("%s/%s", helmConfig.Registry, p.Chart.Repository),
Version: p.Chart.Version,
Values: p.Values,
InsecureSkipTLSVerify: p.Chart.InsecureSkipTLSVerify,
InsecureSkipTLSVerify: helmConfig.InsecureSkipTLSVerify,
}

if p.Chart.AuthSecretName != "" {
nn := types.NamespacedName{Name: p.Chart.AuthSecretName, Namespace: vc.Namespace}
if helmConfig.AuthSecretName != "" {
nn := types.NamespacedName{Name: helmConfig.AuthSecretName, Namespace: vc.Namespace}
if err := r.configureHelmOpts(ctx, nn, opts); err != nil {
r.Log.V(0).Error(err, "failed to configure basic auth for Helm upgrade")
conditions[i] = r.buildHelmChartCondition(p.Chart.Name, err)
Expand All @@ -182,7 +183,7 @@ func (r *ValidatorConfigReconciler) redeployIfNeeded(ctx context.Context, vc *v1
}

var cleanupLocalChart bool
if strings.HasPrefix(p.Chart.Repository, oci.Scheme) {
if strings.HasPrefix(helmConfig.Registry, oci.Scheme) {
r.Log.V(0).Info("Pulling plugin Helm chart", "name", p.Chart.Name)

opts.Path = fmt.Sprintf("/charts/%s", opts.Chart)
Expand Down
11 changes: 7 additions & 4 deletions internal/controller/validatorconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,15 @@ var _ = Describe("ValidatorConfig controller", Ordered, func() {
Namespace: validatorNamespace,
},
Spec: v1alpha1.ValidatorConfigSpec{
HelmConfig: v1alpha1.HelmConfig{
Registry: "foo",
AuthSecretName: "chart-secret",
},
Plugins: []v1alpha1.HelmRelease{
{
Chart: v1alpha1.HelmChart{
Name: "foo",
Repository: "bar",
AuthSecretName: "chart-secret",
Repository: "bar",
Name: "bar",
},
},
},
Expand All @@ -167,7 +170,7 @@ var _ = Describe("ValidatorConfig controller", Ordered, func() {
if err := k8sClient.Get(ctx, vcKey, vc); err != nil {
return false
}
condition, ok := isConditionTrue(vc, "foo", v1alpha1.HelmChartDeployedCondition)
condition, ok := isConditionTrue(vc, "bar", v1alpha1.HelmChartDeployedCondition)
return condition.Status == corev1.ConditionFalse && !ok
}, timeout, interval).Should(BeTrue(), "failed to deploy validator-plugin-network")
})
Expand Down

0 comments on commit 36874a6

Please sign in to comment.