Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 3f9425f

Browse files
committed
feat: add helm chart field
1 parent e885c96 commit 3f9425f

File tree

9 files changed

+55
-12
lines changed

9 files changed

+55
-12
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/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/openapi/patterns"
1213
"github.com/d2iq-labs/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: 6 additions & 1 deletion
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
@@ -26,9 +31,10 @@ const (
2631
)
2732

2833
type HelmChartGetter struct {
29-
cl ctrlclient.Reader
30-
cmName string
31-
cmNamespace string
34+
cl ctrlclient.Reader
35+
cmName string
36+
cmNamespace string
37+
variablePath []string
3238
}
3339

3440
type HelmChart struct {
@@ -45,6 +51,7 @@ func NewHelmChartGetterFromConfigMap(
4551
cl,
4652
cmName,
4753
cmNamespace,
54+
[]string{"addons", v1alpha1.HelmChartRepository},
4855
}
4956
}
5057

@@ -71,6 +78,7 @@ func (h *HelmChartGetter) get(
7178

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

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)