Skip to content

Commit

Permalink
feat: add helm chart field
Browse files Browse the repository at this point in the history
  • Loading branch information
faiq committed Apr 11, 2024
1 parent c444bc7 commit dd8f1a3
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 11 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha1/addon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/openapi/patterns"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables"
)

Expand All @@ -24,6 +25,7 @@ const (
)

type Addons struct {
HelmChartRepository *string `json:"helmChartRepository,omitempty"`
// +optional
CNI *CNI `json:"cni,omitempty"`

Expand All @@ -46,6 +48,10 @@ func (Addons) VariableSchema() clusterv1.VariableSchema {
Description: "Cluster configuration",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"helmChartRepository": {
Pattern: patterns.DNS1123Label,
Description: "Optional OCI registry used to pull helm charts for adons",
},
"cni": CNI{}.VariableSchema().OpenAPIV3Schema,
"nfd": NFD{}.VariableSchema().OpenAPIV3Schema,
"clusterAutoscaler": ClusterAutoscaler{}.VariableSchema().OpenAPIV3Schema,
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ const (
AWSVariableName = "aws"
// NutanixVariableName is the Nutanix config patch variable name.
NutanixVariableName = "nutanix"
// HelmChartRepository is the variable name for the OCI registry for addons.
HelmChartRepository = "HelmChartRepository"
)
5 changes: 5 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.

Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (n *DefaultClusterAutoscaler) AfterControlPlaneInitialized(
case v1alpha1.AddonStrategyHelmAddon:
helmChart, err := n.helmChartInfoGetter.For(
ctx,
&req.Cluster,
log,
config.Autoscaler,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/generic/lifecycle/cni/calico/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (c *CalicoCNI) AfterControlPlaneInitialized(
case v1alpha1.AddonStrategyHelmAddon:
// this is tigera and not calico because we deploy calico via operataor
log.Info("fetching settings for tigera-operator-config")
helmChart, err := c.helmChartInfoGetter.For(ctx, log, config.Tigera)
helmChart, err := c.helmChartInfoGetter.For(ctx, &req.Cluster, log, config.Tigera)
if err != nil {
log.Error(
err,
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/generic/lifecycle/cni/cilium/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *CiliumCNI) AfterControlPlaneInitialized(
client: c.client,
}
case v1alpha1.AddonStrategyHelmAddon:
helmChart, err := c.helmChartInfoGetter.For(ctx, log, config.Cilium)
helmChart, err := c.helmChartInfoGetter.For(ctx, &req.Cluster, log, config.Cilium)
if err != nil {
log.Error(
err,
Expand Down
36 changes: 30 additions & 6 deletions pkg/handlers/generic/lifecycle/config/cm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import (
"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
)

type Component string
Expand All @@ -27,9 +32,10 @@ const (
)

type HelmChartGetter struct {
cl ctrlclient.Reader
cmName string
cmNamespace string
cl ctrlclient.Reader
cmName string
cmNamespace string
variablePath []string
}

type HelmChart struct {
Expand All @@ -46,6 +52,7 @@ func NewHelmChartGetterFromConfigMap(
cl,
cmName,
cmNamespace,
[]string{"addons", v1alpha1.HelmChartRepository},
}
}

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

func (h *HelmChartGetter) For(
ctx context.Context,
cluster *clusterv1.Cluster,
log logr.Logger,
name Component,
) (*HelmChart, error) {
Expand All @@ -81,6 +89,19 @@ func (h *HelmChartGetter) For(
h.cmName,
h.cmNamespace),
)
varMap := variables.ClusterVariablesToVariablesMap(cluster.Spec.Topology.Variables)

helmChartRepo, found, err := variables.Get[string](
varMap,
clusterconfig.MetaVariableName,
h.variablePath...)
if err != nil {
return nil, fmt.Errorf(
"failed to get helmChartRepo variable from %s: %w",
clusterconfig.MetaVariableName,
err,
)
}
cm, err := h.get(ctx)
if err != nil {
return nil, err
Expand All @@ -89,7 +110,10 @@ func (h *HelmChartGetter) For(
if !ok {
return nil, fmt.Errorf("did not find key %s in %v", name, cm.Data)
}
var settings HelmChart
err = yaml.Unmarshal([]byte(d), &settings)
return &settings, err
var chart HelmChart
err = yaml.Unmarshal([]byte(d), &chart)
if found {
chart.Repository = helmChartRepo
}
return &chart, err
}
9 changes: 7 additions & 2 deletions pkg/handlers/generic/lifecycle/csi/nutanix-csi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (n *NutanixCSI) handleHelmAddonApply(
"cluster",
ctrlclient.ObjectKeyFromObject(&req.Cluster),
)
helmChart, err := n.helmChartInfoGetter.For(ctx, log, config.NutanixStorageCSI)
helmChart, err := n.helmChartInfoGetter.For(ctx, &req.Cluster, log, config.NutanixStorageCSI)
if err != nil {
return fmt.Errorf("failed to get values for nutanix-csi-config %w", err)
}
Expand Down Expand Up @@ -186,7 +186,12 @@ func (n *NutanixCSI) handleHelmAddonApply(
return fmt.Errorf("failed to apply nutanix-csi installation HelmChartProxy: %w", err)
}

snapshotHelmChart, err := n.helmChartInfoGetter.For(ctx, log, config.NutanixSnapshotCSI)
snapshotHelmChart, err := n.helmChartInfoGetter.For(
ctx,
&req.Cluster,
log,
config.NutanixSnapshotCSI,
)
if err != nil {
return fmt.Errorf("failed to get values for nutanix-csi-config %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/generic/lifecycle/nfd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (n *DefaultNFD) AfterControlPlaneInitialized(
client: n.client,
}
case v1alpha1.AddonStrategyHelmAddon:
helmChart, err := n.helmChartInfoGetter.For(ctx, log, config.NFD)
helmChart, err := n.helmChartInfoGetter.For(ctx, &req.Cluster, log, config.NFD)
if err != nil {
log.Error(
err,
Expand Down

0 comments on commit dd8f1a3

Please sign in to comment.