Skip to content

Commit d41520b

Browse files
committed
fix: Refactoring to follow smilar patterns as other components
fix: PR comment resolution
1 parent 09b4650 commit d41520b

File tree

8 files changed

+119
-263
lines changed

8 files changed

+119
-263
lines changed
Lines changed: 7 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,18 @@
1-
# Default values for multus.
2-
# This is a YAML-formatted file.
3-
# Declare variables to be passed into your templates.
4-
5-
# Image configuration
6-
image:
7-
repository: ghcr.io/k8snetworkplumbingwg/multus-cni
8-
tag: "" # If empty, will use Chart.AppVersion + suffix
9-
suffix: "-thick" # Default suffix (can be overridden)
10-
pullPolicy: IfNotPresent
11-
12-
# Image pull secrets
13-
imagePullSecrets: []
14-
15-
# Service account configuration
16-
serviceAccount:
17-
create: true
18-
name: multus
19-
annotations: {}
20-
21-
# Pod security context
22-
podSecurityContext:
23-
privileged: true
24-
25-
# Container security context
26-
securityContext:
27-
privileged: true
28-
capabilities:
29-
add:
30-
- NET_ADMIN
31-
- SYS_ADMIN
32-
33-
# Priority class
34-
priorityClassName: system-node-critical
35-
36-
# Pod network configuration
37-
hostNetwork: true
38-
hostPID: true
39-
40-
# Pod lifecycle configuration
41-
terminationGracePeriodSeconds: 10
42-
43-
# Update strategy
44-
updateStrategy:
45-
type: RollingUpdate
46-
rollingUpdate:
47-
maxUnavailable: 1
48-
49-
# Tolerations
50-
tolerations:
51-
- operator: Exists
52-
effect: NoSchedule
53-
- operator: Exists
54-
effect: NoExecute
55-
56-
# Node selector
57-
nodeSelector: {}
58-
59-
# Affinity
60-
affinity: {}
61-
62-
# Pod annotations
63-
podAnnotations: {}
64-
65-
# Pod labels
66-
podLabels: {}
67-
68-
# Resource limits and requests
69-
resources:
70-
limits:
71-
cpu: 100m
72-
memory: 128Mi
73-
requests:
74-
cpu: 100m
75-
memory: 128Mi
76-
77-
# Multus daemon configuration
1+
# Multus daemon configuration overrides
782
daemonConfig:
79-
chrootDir: "/hostroot"
80-
cniVersion: "0.3.1"
81-
logLevel: "verbose"
82-
logToStderr: true
83-
readinessIndicatorFile: "{{ .ReadinessSocketPath }}"
84-
cniConfigDir: "/host/etc/cni/net.d"
85-
multusAutoconfigDir: "/host/etc/cni/net.d"
86-
multusConfigFile: "auto"
87-
socketDir: "/host/run/multus/"
3+
readinessIndicatorFile: "{{ .SocketPath }}"
884

89-
{{- if .ReadinessSocketPath }}
5+
{{- if .SocketPath }}
906
# Volumes for CNI readiness socket
917
volumes:
92-
- name: {{ .SocketVolumeName }}
8+
- name: cni-readiness-sock
939
hostPath:
94-
path: "{{ .ReadinessSocketPath }}"
10+
path: "{{ .SocketPath }}"
9511
type: Socket
9612

9713
# Volume mounts for CNI readiness socket
9814
volumeMounts:
99-
- name: {{ .SocketVolumeName }}
100-
mountPath: "{{ .ReadinessSocketPath }}"
15+
- name: cni-readiness-sock
16+
mountPath: "{{ .SocketPath }}"
10117
readOnly: true
10218
{{- end }}

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/deployer.go

Lines changed: 0 additions & 104 deletions
This file was deleted.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
// MultusHandler implements the cluster lifecycle hooks and:
1010
// - Detects the cloud provider from the cluster infrastructure
1111
// - Reads CNI configuration from cluster variables
12-
// - Gets the readiness socket path for the configured CNI (via cni.ReadinessSocketPath)
12+
// - Gets the socket path for the configured CNI (via cni.SocketPath)
1313
// - Automatically deploys Multus with socket-based configuration
1414
//
15-
// MultusDeployer is the internal deployer that handles:
16-
// - Templating Helm values with the CNI readiness socket path
15+
// helmAddonStrategy is the internal strategy that handles:
16+
// - Templating Helm values with the CNI socket path
1717
// - Deploying Multus using HelmAddon strategy with Go template-based values
1818
//
1919
// 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.
20+
// to be ready, eliminating the need for explicit wait logic in the strategy.
2121
//
2222
// This package does NOT expose Multus in the API - it's an internal addon
2323
// that deploys automatically based on cloud provider and CNI selection.

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

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99

1010
"github.com/spf13/pflag"
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1112
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1213
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1314
ctrl "sigs.k8s.io/controller-runtime"
@@ -17,30 +18,43 @@ import (
1718
commonhandlers "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
1819
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/lifecycle"
1920
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
21+
capiutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/utils"
22+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/lifecycle/addons"
2023
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/lifecycle/cni"
2124
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/lifecycle/config"
2225
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
2326
)
2427

28+
const (
29+
defaultMultusReleaseName = "multus"
30+
defaultMultusNamespace = metav1.NamespaceSystem
31+
)
32+
2533
type MultusConfig struct {
2634
*options.GlobalOptions
35+
36+
helmAddonConfig *addons.HelmAddonConfig
2737
}
2838

2939
func NewMultusConfig(globalOptions *options.GlobalOptions) *MultusConfig {
3040
return &MultusConfig{
3141
GlobalOptions: globalOptions,
42+
helmAddonConfig: addons.NewHelmAddonConfig(
43+
"default-multus-values-template",
44+
defaultMultusNamespace,
45+
defaultMultusReleaseName,
46+
),
3247
}
3348
}
3449

3550
func (m *MultusConfig) AddFlags(prefix string, flags *pflag.FlagSet) {
36-
// No flags needed for Multus - it's auto-deployed
51+
m.helmAddonConfig.AddFlags(prefix+".helm-addon", flags)
3752
}
3853

3954
type MultusHandler struct {
4055
client ctrlclient.Client
4156
config *MultusConfig
4257
helmChartInfoGetter *config.HelmChartGetter
43-
deployer *MultusDeployer
4458
}
4559

4660
var (
@@ -58,7 +72,6 @@ func New(
5872
client: c,
5973
config: cfg,
6074
helmChartInfoGetter: helmChartInfoGetter,
61-
deployer: NewMultusDeployer(c, helmChartInfoGetter),
6275
}
6376
}
6477

@@ -101,16 +114,15 @@ func (m *MultusHandler) apply(
101114
)
102115

103116
// Check if Multus is supported for this cloud provider
104-
isSupported, providerName := m.deployer.isCloudProviderSupported(cluster)
105-
106-
if !isSupported {
117+
provider := capiutils.GetProvider(cluster)
118+
if provider != "eks" && provider != "nutanix" {
107119
log.V(5).Info(
108120
"Multus is not supported for this cloud provider. Skipping Multus deployment.",
109121
)
110122
return
111123
}
112124

113-
log.Info(fmt.Sprintf("Cluster is %s. Checking CNI configuration for Multus deployment.", providerName))
125+
log.Info(fmt.Sprintf("Cluster is %s. Checking CNI configuration for Multus deployment.", provider))
114126

115127
// Read CNI configuration to detect which CNI is deployed
116128
varMap := variables.ClusterVariablesToVariablesMap(cluster.Spec.Topology.Variables)
@@ -130,19 +142,37 @@ func (m *MultusHandler) apply(
130142
return
131143
}
132144

133-
// Get readiness socket path for the CNI provider
134-
readinessSocketPath, err := cni.ReadinessSocketPath(cniVar.Provider)
145+
// Get socket path for the CNI provider
146+
socketPath, err := cni.SocketPath(cniVar.Provider)
135147
if err != nil {
136148
log.V(5).
137149
Info(fmt.Sprintf("Multus does not support CNI provider: %s. Skipping Multus deployment.", cniVar.Provider))
138150
return
139151
}
140152

141-
log.Info(fmt.Sprintf("Auto-deploying Multus for %s cluster with %s CNI", providerName, cniVar.Provider))
153+
log.Info(fmt.Sprintf("Auto-deploying Multus for %s cluster with %s CNI", provider, cniVar.Provider))
154+
155+
// Get helm chart configuration
156+
helmChart, err := m.helmChartInfoGetter.For(ctx, log, config.Multus)
157+
if err != nil {
158+
log.Error(
159+
err,
160+
"failed to get configmap with helm settings",
161+
)
162+
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
163+
resp.SetMessage(
164+
fmt.Sprintf("failed to get configuration to create helm addon: %v",
165+
err,
166+
),
167+
)
168+
return
169+
}
142170

143-
// Deploy Multus using the deployer
171+
// Create and apply helm addon strategy
144172
targetNamespace := m.config.DefaultsNamespace()
145-
if err := m.deployer.Deploy(ctx, cluster, readinessSocketPath, targetNamespace, log); err != nil {
173+
strategy := newHelmAddonStrategy(m.client, helmChart, m.config.helmAddonConfig)
174+
175+
if err := strategy.apply(ctx, cluster, socketPath, targetNamespace, log); err != nil {
146176
log.Error(err, "failed to deploy Multus")
147177
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
148178
resp.SetMessage(fmt.Sprintf("failed to deploy Multus: %v", err))

0 commit comments

Comments
 (0)