Skip to content

Commit dd8f1a3

Browse files
committed
feat: add helm chart field
1 parent c444bc7 commit dd8f1a3

File tree

9 files changed

+54
-11
lines changed

9 files changed

+54
-11
lines changed

api/v1alpha1/addon_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"k8s.io/utils/ptr"
1010
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1111

12+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/openapi/patterns"
1213
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables"
1314
)
1415

@@ -24,6 +25,7 @@ const (
2425
)
2526

2627
type Addons struct {
28+
HelmChartRepository *string `json:"helmChartRepository,omitempty"`
2729
// +optional
2830
CNI *CNI `json:"cni,omitempty"`
2931

@@ -46,6 +48,10 @@ func (Addons) VariableSchema() clusterv1.VariableSchema {
4648
Description: "Cluster configuration",
4749
Type: "object",
4850
Properties: map[string]clusterv1.JSONSchemaProps{
51+
"helmChartRepository": {
52+
Pattern: patterns.DNS1123Label,
53+
Description: "Optional OCI registry used to pull helm charts for adons",
54+
},
4955
"cni": CNI{}.VariableSchema().OpenAPIV3Schema,
5056
"nfd": NFD{}.VariableSchema().OpenAPIV3Schema,
5157
"clusterAutoscaler": ClusterAutoscaler{}.VariableSchema().OpenAPIV3Schema,

api/v1alpha1/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ const (
1414
AWSVariableName = "aws"
1515
// NutanixVariableName is the Nutanix config patch variable name.
1616
NutanixVariableName = "nutanix"
17+
// HelmChartRepository is the variable name for the OCI registry for addons.
18+
HelmChartRepository = "HelmChartRepository"
1719
)

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/handlers/generic/lifecycle/clusterautoscaler/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func (n *DefaultClusterAutoscaler) AfterControlPlaneInitialized(
123123
case v1alpha1.AddonStrategyHelmAddon:
124124
helmChart, err := n.helmChartInfoGetter.For(
125125
ctx,
126+
&req.Cluster,
126127
log,
127128
config.Autoscaler,
128129
)

pkg/handlers/generic/lifecycle/cni/calico/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (c *CalicoCNI) AfterControlPlaneInitialized(
130130
case v1alpha1.AddonStrategyHelmAddon:
131131
// this is tigera and not calico because we deploy calico via operataor
132132
log.Info("fetching settings for tigera-operator-config")
133-
helmChart, err := c.helmChartInfoGetter.For(ctx, log, config.Tigera)
133+
helmChart, err := c.helmChartInfoGetter.For(ctx, &req.Cluster, log, config.Tigera)
134134
if err != nil {
135135
log.Error(
136136
err,

pkg/handlers/generic/lifecycle/cni/cilium/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (c *CiliumCNI) AfterControlPlaneInitialized(
128128
client: c.client,
129129
}
130130
case v1alpha1.AddonStrategyHelmAddon:
131-
helmChart, err := c.helmChartInfoGetter.For(ctx, log, config.Cilium)
131+
helmChart, err := c.helmChartInfoGetter.For(ctx, &req.Cluster, log, config.Cilium)
132132
if err != nil {
133133
log.Error(
134134
err,

pkg/handlers/generic/lifecycle/config/cm.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import (
1111
"gopkg.in/yaml.v2"
1212
corev1 "k8s.io/api/core/v1"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1415
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
16+
17+
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
18+
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
19+
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
1520
)
1621

1722
type Component string
@@ -27,9 +32,10 @@ const (
2732
)
2833

2934
type HelmChartGetter struct {
30-
cl ctrlclient.Reader
31-
cmName string
32-
cmNamespace string
35+
cl ctrlclient.Reader
36+
cmName string
37+
cmNamespace string
38+
variablePath []string
3339
}
3440

3541
type HelmChart struct {
@@ -46,6 +52,7 @@ func NewHelmChartGetterFromConfigMap(
4652
cl,
4753
cmName,
4854
cmNamespace,
55+
[]string{"addons", v1alpha1.HelmChartRepository},
4956
}
5057
}
5158

@@ -72,6 +79,7 @@ func (h *HelmChartGetter) get(
7279

7380
func (h *HelmChartGetter) For(
7481
ctx context.Context,
82+
cluster *clusterv1.Cluster,
7583
log logr.Logger,
7684
name Component,
7785
) (*HelmChart, error) {
@@ -81,6 +89,19 @@ func (h *HelmChartGetter) For(
8189
h.cmName,
8290
h.cmNamespace),
8391
)
92+
varMap := variables.ClusterVariablesToVariablesMap(cluster.Spec.Topology.Variables)
93+
94+
helmChartRepo, found, err := variables.Get[string](
95+
varMap,
96+
clusterconfig.MetaVariableName,
97+
h.variablePath...)
98+
if err != nil {
99+
return nil, fmt.Errorf(
100+
"failed to get helmChartRepo variable from %s: %w",
101+
clusterconfig.MetaVariableName,
102+
err,
103+
)
104+
}
84105
cm, err := h.get(ctx)
85106
if err != nil {
86107
return nil, err
@@ -89,7 +110,10 @@ func (h *HelmChartGetter) For(
89110
if !ok {
90111
return nil, fmt.Errorf("did not find key %s in %v", name, cm.Data)
91112
}
92-
var settings HelmChart
93-
err = yaml.Unmarshal([]byte(d), &settings)
94-
return &settings, err
113+
var chart HelmChart
114+
err = yaml.Unmarshal([]byte(d), &chart)
115+
if found {
116+
chart.Repository = helmChartRepo
117+
}
118+
return &chart, err
95119
}

pkg/handlers/generic/lifecycle/csi/nutanix-csi/handler.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (n *NutanixCSI) handleHelmAddonApply(
148148
"cluster",
149149
ctrlclient.ObjectKeyFromObject(&req.Cluster),
150150
)
151-
helmChart, err := n.helmChartInfoGetter.For(ctx, log, config.NutanixStorageCSI)
151+
helmChart, err := n.helmChartInfoGetter.For(ctx, &req.Cluster, log, config.NutanixStorageCSI)
152152
if err != nil {
153153
return fmt.Errorf("failed to get values for nutanix-csi-config %w", err)
154154
}
@@ -186,7 +186,12 @@ func (n *NutanixCSI) handleHelmAddonApply(
186186
return fmt.Errorf("failed to apply nutanix-csi installation HelmChartProxy: %w", err)
187187
}
188188

189-
snapshotHelmChart, err := n.helmChartInfoGetter.For(ctx, log, config.NutanixSnapshotCSI)
189+
snapshotHelmChart, err := n.helmChartInfoGetter.For(
190+
ctx,
191+
&req.Cluster,
192+
log,
193+
config.NutanixSnapshotCSI,
194+
)
190195
if err != nil {
191196
return fmt.Errorf("failed to get values for nutanix-csi-config %w", err)
192197
}

pkg/handlers/generic/lifecycle/nfd/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (n *DefaultNFD) AfterControlPlaneInitialized(
116116
client: n.client,
117117
}
118118
case v1alpha1.AddonStrategyHelmAddon:
119-
helmChart, err := n.helmChartInfoGetter.For(ctx, log, config.NFD)
119+
helmChart, err := n.helmChartInfoGetter.For(ctx, &req.Cluster, log, config.NFD)
120120
if err != nil {
121121
log.Error(
122122
err,

0 commit comments

Comments
 (0)