Skip to content

Commit ffe5636

Browse files
committed
fix: Refactoring to follow smilar patterns as other components
1 parent 09b4650 commit ffe5636

File tree

4 files changed

+38
-44
lines changed

4 files changed

+38
-44
lines changed

hack/addons/helm-chart-bundler/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG MINDTHEGAP_VERSION=v1.17.0
1+
ARG MINDTHEGAP_VERSION=v1.24.0
22

33
FROM --platform=${BUILDPLATFORM} ghcr.io/mesosphere/mindthegap:${MINDTHEGAP_VERSION} as bundle_builder
44
# This gets called by goreleaser so the copy source has to be the path relative to the repo root.

pkg/handlers/lifecycle/cni/multus/doc.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
// - Gets the readiness socket path for the configured CNI (via cni.ReadinessSocketPath)
1313
// - Automatically deploys Multus with socket-based configuration
1414
//
15-
// MultusDeployer is the internal deployer that handles:
15+
// helmAddonStrategy is the internal strategy that handles:
16+
// - Cloud provider support detection (EKS and Nutanix)
1617
// - Templating Helm values with the CNI readiness socket path
1718
// - Deploying Multus using HelmAddon strategy with Go template-based values
1819
//
1920
// Multus relies on the readinessIndicatorFile configuration to wait for the primary CNI
20-
// to be ready, eliminating the need for explicit wait logic in the deployer.
21+
// to be ready, eliminating the need for explicit wait logic in the strategy.
2122
//
2223
// This package does NOT expose Multus in the API - it's an internal addon
2324
// that deploys automatically based on cloud provider and CNI selection.

pkg/handlers/lifecycle/cni/multus/handler.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type MultusHandler struct {
4040
client ctrlclient.Client
4141
config *MultusConfig
4242
helmChartInfoGetter *config.HelmChartGetter
43-
deployer *MultusDeployer
4443
}
4544

4645
var (
@@ -58,7 +57,6 @@ func New(
5857
client: c,
5958
config: cfg,
6059
helmChartInfoGetter: helmChartInfoGetter,
61-
deployer: NewMultusDeployer(c, helmChartInfoGetter),
6260
}
6361
}
6462

@@ -101,7 +99,7 @@ func (m *MultusHandler) apply(
10199
)
102100

103101
// Check if Multus is supported for this cloud provider
104-
isSupported, providerName := m.deployer.isCloudProviderSupported(cluster)
102+
isSupported, providerName := isCloudProviderSupported(cluster)
105103

106104
if !isSupported {
107105
log.V(5).Info(
@@ -140,9 +138,27 @@ func (m *MultusHandler) apply(
140138

141139
log.Info(fmt.Sprintf("Auto-deploying Multus for %s cluster with %s CNI", providerName, cniVar.Provider))
142140

143-
// Deploy Multus using the deployer
141+
// Get helm chart configuration
142+
helmChart, err := m.helmChartInfoGetter.For(ctx, log, config.Multus)
143+
if err != nil {
144+
log.Error(
145+
err,
146+
"failed to get configmap with helm settings",
147+
)
148+
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
149+
resp.SetMessage(
150+
fmt.Sprintf("failed to get configuration to create helm addon: %v",
151+
err,
152+
),
153+
)
154+
return
155+
}
156+
157+
// Create and apply helm addon strategy
144158
targetNamespace := m.config.DefaultsNamespace()
145-
if err := m.deployer.Deploy(ctx, cluster, readinessSocketPath, targetNamespace, log); err != nil {
159+
strategy := newHelmAddonStrategy(m.client, helmChart)
160+
161+
if err := strategy.apply(ctx, cluster, readinessSocketPath, targetNamespace, log); err != nil {
146162
log.Error(err, "failed to deploy Multus")
147163
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
148164
resp.SetMessage(fmt.Sprintf("failed to deploy Multus: %v", err))

pkg/handlers/lifecycle/cni/multus/deployer.go renamed to pkg/handlers/lifecycle/cni/multus/strategy_helmaddon.go

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,61 +21,38 @@ const (
2121
defaultMultusNamespace = metav1.NamespaceSystem
2222
)
2323

24-
type MultusDeployer struct {
25-
client ctrlclient.Client
26-
helmChartInfoGetter *config.HelmChartGetter
24+
type helmAddonStrategy struct {
25+
client ctrlclient.Client
26+
helmChart *config.HelmChart
2727
}
2828

29-
func NewMultusDeployer(client ctrlclient.Client, helmChartInfoGetter *config.HelmChartGetter) *MultusDeployer {
30-
return &MultusDeployer{
31-
client: client,
32-
helmChartInfoGetter: helmChartInfoGetter,
29+
func newHelmAddonStrategy(client ctrlclient.Client, helmChart *config.HelmChart) helmAddonStrategy {
30+
return helmAddonStrategy{
31+
client: client,
32+
helmChart: helmChart,
3333
}
3434
}
3535

36-
func (m *MultusDeployer) Deploy(
36+
func (s helmAddonStrategy) apply(
3737
ctx context.Context,
3838
cluster *clusterv1.Cluster,
3939
readinessSocketPath string,
40-
targetNamespace string,
40+
defaultsNamespace string,
4141
log logr.Logger,
4242
) error {
43-
// Check if Multus deployment is supported for this cloud provider
44-
isSupported, providerName := m.isCloudProviderSupported(cluster)
45-
46-
// Currently, Multus is only supported for EKS and Nutanix clusters
47-
if !isSupported {
48-
log.Info("Multus deployment is only supported for EKS and Nutanix clusters. Skipping deployment.")
49-
return nil
50-
}
51-
52-
log.Info(fmt.Sprintf("Cluster is %s. Proceeding with Multus deployment.", providerName))
53-
54-
// Get Multus Helm chart info
55-
helmChart, err := m.helmChartInfoGetter.For(ctx, log, config.Multus)
56-
if err != nil {
57-
// For local testing, provide a placeholder chart info
58-
log.Info("Multus not found in helm-config.yaml, using placeholder chart info for local development")
59-
helmChart = &config.HelmChart{
60-
Name: "multus",
61-
Version: "dev",
62-
Repository: "",
63-
}
64-
}
65-
6643
// Deploy Multus using HelmAddonApplier with template function
6744
strategy := addons.NewHelmAddonApplier(
6845
addons.NewHelmAddonConfig(
6946
"default-multus-values-template",
7047
defaultMultusNamespace,
7148
defaultMultusReleaseName,
7249
),
73-
m.client,
74-
helmChart,
50+
s.client,
51+
s.helmChart,
7552
).WithValueTemplater(templateValuesFunc(readinessSocketPath)).
7653
WithDefaultWaiter()
7754

78-
if err := strategy.Apply(ctx, cluster, targetNamespace, log); err != nil {
55+
if err := strategy.Apply(ctx, cluster, defaultsNamespace, log); err != nil {
7956
return fmt.Errorf("failed to apply Multus deployment: %w", err)
8057
}
8158

@@ -85,7 +62,7 @@ func (m *MultusDeployer) Deploy(
8562

8663
// isCloudProviderSupported checks if the cluster is a supported cloud provider
8764
// by inspecting the infrastructure reference.
88-
func (m *MultusDeployer) isCloudProviderSupported(cluster *clusterv1.Cluster) (
65+
func isCloudProviderSupported(cluster *clusterv1.Cluster) (
8966
isSupported bool,
9067
providerName string,
9168
) {

0 commit comments

Comments
 (0)