Skip to content

Commit

Permalink
Add helm version to capabilities
Browse files Browse the repository at this point in the history
Some charts, like cert-manager check the helm version, since fleet uses
the SDK we need to set it.
  • Loading branch information
Mario Manno committed Aug 24, 2023
1 parent eba02a4 commit ac5dc35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 8 additions & 2 deletions integrationtests/agent/helm_capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func capabilityBundleResources() map[string][]v1alpha1.BundleResource {
Name: "config-chart/Chart.yaml",
},
{
Content: "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: test-simple-chart-config\ndata:\n test: \"value123\"\n name: {{ .Values.name }}\n",
Content: "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: test-simple-chart-config\ndata:\n test: \"value123\"\n name: {{ .Values.name }}\n kubeVersion: {{ .Capabilities.KubeVersion.Version }}\n apiVersions: {{ join \", \" .Capabilities.APIVersions | }}\n helmVersion: {{ .Capabilities.HelmVersion.Version }}\n",
Name: "config-chart/templates/configmap.yaml",
},
{
Expand Down Expand Up @@ -89,12 +89,18 @@ var _ = Describe("Helm Chart uses Capabilities", Ordered, func() {
})
})

It("config map from chart is deployed", func() {
It("config map from chart is deployed with capabilities", func() {
cm := corev1.ConfigMap{}
Eventually(func() bool {
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: env.namespace, Name: "test-simple-chart-config"}, &cm)
return err == nil
}).Should(BeTrue())

Expect(cm.Data["name"]).To(Equal("example-value"))
Expect(cm.Data["kubeVersion"]).ToNot(BeEmpty())
Expect(cm.Data["apiVersions"]).ToNot(BeEmpty())
Expect(cm.Data["apiVersions"]).To(ContainSubstring("apps/v1"))
Expect(cm.Data["helmVersion"]).ToNot(BeEmpty())
})
})

Expand Down
14 changes: 7 additions & 7 deletions internal/helmdeployer/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chartutil"

"k8s.io/client-go/discovery"
)

Expand Down Expand Up @@ -53,13 +54,12 @@ func getCapabilities(c action.Configuration) (*chartutil.Capabilities, error) {
}
}

c.Capabilities = &chartutil.Capabilities{
APIVersions: apiVersions,
KubeVersion: chartutil.KubeVersion{
Version: kubeVersion.GitVersion,
Major: kubeVersion.Major,
Minor: kubeVersion.Minor,
},
c.Capabilities = chartutil.DefaultCapabilities
c.Capabilities.APIVersions = apiVersions
c.Capabilities.KubeVersion = chartutil.KubeVersion{
Version: kubeVersion.GitVersion,
Major: kubeVersion.Major,
Minor: kubeVersion.Minor,
}
return c.Capabilities, nil
}
Expand Down

0 comments on commit ac5dc35

Please sign in to comment.