Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): ClusterProfile HelmCharts can be expressed as a template #800

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

gianlucam76
Copy link
Member

For instance

apiVersion: config.projectsveltos.io/v1beta1
kind: ClusterProfile
metadata:
  name: deploy-kyverno
spec:
  clusterSelector:
    matchLabels:
      env: fv
  syncMode: Continuous
  helmCharts:
  - repositoryURL:    https://kyverno.github.io/kyverno/
    repositoryName:   kyverno
    chartName:        kyverno/kyverno
    chartVersion:     |-
      {{$version := index .Cluster.metadata.labels "k8s-version" }}{{if eq $version "v1.29.0"}}v3.2.5
      {{else}}v3.2.6
      {{end}}
    releaseName:      kyverno-latest
    releaseNamespace: kyverno
    helmChartAction:  Install

Sveltos will fetch Cluster and use it to instantiate this template before deploying it.

Issue: if Cluster.Labels changes, Sveltos won't redeploy as hash is not changing.

Fixes #794

mgianluc added 2 commits December 5, 2024 08:06
For instance

```yaml
apiVersion: config.projectsveltos.io/v1beta1
kind: ClusterProfile
metadata:
  name: deploy-kyverno
spec:
  clusterSelector:
    matchLabels:
      env: fv
  syncMode: Continuous
  helmCharts:
  - repositoryURL:    https://kyverno.github.io/kyverno/
    repositoryName:   kyverno
    chartName:        kyverno/kyverno
    chartVersion:     |-
      {{$version := index .Cluster.metadata.labels "k8s-version" }}{{if eq $version "v1.29.0"}}v3.2.5
      {{else}}v3.2.6
      {{end}}
    releaseName:      kyverno-latest
    releaseNamespace: kyverno
    helmChartAction:  Install
```

Sveltos will fetch Cluster and use it to instantiate this template before deploying it.

Issue: if Cluster.Labels changes, Sveltos won't redeploy as hash is not changing.
For instance

```yaml
apiVersion: config.projectsveltos.io/v1beta1
kind: ClusterProfile
metadata:
  name: deploy-kyverno
spec:
  clusterSelector:
    matchLabels:
      env: fv
  syncMode: Continuous
  helmCharts:
  - repositoryURL:    https://kyverno.github.io/kyverno/
    repositoryName:   kyverno
    chartName:        kyverno/kyverno
    chartVersion:     |-
      {{$version := index .Cluster.metadata.labels "k8s-version" }}{{if eq $version "v1.29.0"}}v3.2.5
      {{else}}v3.2.6
      {{end}}
    releaseName:      kyverno-latest
    releaseNamespace: kyverno
    helmChartAction:  Install
```

Sveltos will fetch Cluster and use it to instantiate this template before deploying it.

Issue: if Cluster.Labels changes, Sveltos won't redeploy as hash is not changing.
@gianlucam76 gianlucam76 removed the DO_NOT_MERGE Do not merge PR yet label Dec 5, 2024
@gianlucam76
Copy link
Member Author

By default, Sveltos does not react to all Cluster changes but only to some (like Spec.Paused or labels changes).

When the helmChart is expressed as a template and relies on Cluster fields to be instantiated, Cluster needs to be fetched in the templateResoruceRefs section. Doing so Sveltos will react to any change and re-instantiate the ClusterProfile.

apiVersion: config.projectsveltos.io/v1beta1
kind: ClusterProfile
metadata:
  name: deploy-kyverno
spec:
  clusterSelector:
    matchLabels:
      env: fv
  syncMode: Continuous
  templateResourceRefs:
  - resource:
      apiVersion: cluster.x-k8s.io/v1beta1
      kind: Cluster
      name: "{{ .Cluster.metadata.name }}"
    identifier: Cluster
  helmCharts:
  - repositoryURL:    https://kyverno.github.io/kyverno/
    repositoryName:   kyverno
    chartName:        kyverno/kyverno
    chartVersion:     |-
      {{$version := index .Cluster.metadata.labels "k8s-version" }}{{if eq $version "v1.29.0"}}v3.2.5
      {{else}}v3.2.6
      {{end}}
    releaseName:      kyverno-latest
    releaseNamespace: kyverno
    helmChartAction:  Install

If we started with Cluster having label k8s-version: v1.29.0, Sveltos will first deploy Kyverno v3.2.5

Later on if the label is removed or modified, Sveltos reacts to it by upgrading Kyverno to version v3.2.6

@gianlucam76 gianlucam76 merged commit d0a0cae into projectsveltos:main Dec 5, 2024
5 checks passed
@gianlucam76 gianlucam76 deleted the helm-template branch December 5, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Template-Based Helm Chart Versioning in ClusterProfile Using Labels
1 participant