Skip to content

Commit 9f48fec

Browse files
committed
fix: PR comment resolution
1 parent ffe5636 commit 9f48fec

File tree

6 files changed

+48
-179
lines changed

6 files changed

+48
-179
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 }}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
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
//
1515
// helmAddonStrategy is the internal strategy that handles:
16-
// - Cloud provider support detection (EKS and Nutanix)
17-
// - Templating Helm values with the CNI readiness socket path
16+
// - Templating Helm values with the CNI socket path
1817
// - Deploying Multus using HelmAddon strategy with Go template-based values
1918
//
2019
// Multus relies on the readinessIndicatorFile configuration to wait for the primary CNI

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,26 @@ import (
2020
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/lifecycle/cni"
2121
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/lifecycle/config"
2222
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
23+
capiutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/utils"
2324
)
2425

26+
type helmAddonConfig struct {
27+
defaultValuesTemplateConfigMapName string
28+
}
29+
30+
func (c *helmAddonConfig) AddFlags(prefix string, flags *pflag.FlagSet) {
31+
flags.StringVar(
32+
&c.defaultValuesTemplateConfigMapName,
33+
prefix+".default-values-template-configmap-name",
34+
"default-multus-values-template",
35+
"default values ConfigMap name",
36+
)
37+
}
38+
2539
type MultusConfig struct {
2640
*options.GlobalOptions
41+
42+
helmAddonConfig helmAddonConfig
2743
}
2844

2945
func NewMultusConfig(globalOptions *options.GlobalOptions) *MultusConfig {
@@ -33,7 +49,7 @@ func NewMultusConfig(globalOptions *options.GlobalOptions) *MultusConfig {
3349
}
3450

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

3955
type MultusHandler struct {
@@ -99,16 +115,15 @@ func (m *MultusHandler) apply(
99115
)
100116

101117
// Check if Multus is supported for this cloud provider
102-
isSupported, providerName := isCloudProviderSupported(cluster)
103-
104-
if !isSupported {
118+
provider := capiutils.GetProvider(cluster)
119+
if provider != "eks" && provider != "nutanix" {
105120
log.V(5).Info(
106121
"Multus is not supported for this cloud provider. Skipping Multus deployment.",
107122
)
108123
return
109124
}
110125

111-
log.Info(fmt.Sprintf("Cluster is %s. Checking CNI configuration for Multus deployment.", providerName))
126+
log.Info(fmt.Sprintf("Cluster is %s. Checking CNI configuration for Multus deployment.", provider))
112127

113128
// Read CNI configuration to detect which CNI is deployed
114129
varMap := variables.ClusterVariablesToVariablesMap(cluster.Spec.Topology.Variables)
@@ -128,15 +143,15 @@ func (m *MultusHandler) apply(
128143
return
129144
}
130145

131-
// Get readiness socket path for the CNI provider
132-
readinessSocketPath, err := cni.ReadinessSocketPath(cniVar.Provider)
146+
// Get socket path for the CNI provider
147+
socketPath, err := cni.SocketPath(cniVar.Provider)
133148
if err != nil {
134149
log.V(5).
135150
Info(fmt.Sprintf("Multus does not support CNI provider: %s. Skipping Multus deployment.", cniVar.Provider))
136151
return
137152
}
138153

139-
log.Info(fmt.Sprintf("Auto-deploying Multus for %s cluster with %s CNI", providerName, cniVar.Provider))
154+
log.Info(fmt.Sprintf("Auto-deploying Multus for %s cluster with %s CNI", provider, cniVar.Provider))
140155

141156
// Get helm chart configuration
142157
helmChart, err := m.helmChartInfoGetter.For(ctx, log, config.Multus)
@@ -156,9 +171,9 @@ func (m *MultusHandler) apply(
156171

157172
// Create and apply helm addon strategy
158173
targetNamespace := m.config.DefaultsNamespace()
159-
strategy := newHelmAddonStrategy(m.client, helmChart)
174+
strategy := newHelmAddonStrategy(m.client, helmChart, m.config.helmAddonConfig)
160175

161-
if err := strategy.apply(ctx, cluster, readinessSocketPath, targetNamespace, log); err != nil {
176+
if err := strategy.apply(ctx, cluster, socketPath, targetNamespace, log); err != nil {
162177
log.Error(err, "failed to deploy Multus")
163178
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
164179
resp.SetMessage(fmt.Sprintf("failed to deploy Multus: %v", err))

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

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ const (
2222
)
2323

2424
type helmAddonStrategy struct {
25+
config helmAddonConfig
2526
client ctrlclient.Client
2627
helmChart *config.HelmChart
2728
}
2829

29-
func newHelmAddonStrategy(client ctrlclient.Client, helmChart *config.HelmChart) helmAddonStrategy {
30+
func newHelmAddonStrategy(client ctrlclient.Client, helmChart *config.HelmChart, config helmAddonConfig) helmAddonStrategy {
3031
return helmAddonStrategy{
32+
config: config,
3133
client: client,
3234
helmChart: helmChart,
3335
}
@@ -36,20 +38,20 @@ func newHelmAddonStrategy(client ctrlclient.Client, helmChart *config.HelmChart)
3638
func (s helmAddonStrategy) apply(
3739
ctx context.Context,
3840
cluster *clusterv1.Cluster,
39-
readinessSocketPath string,
41+
socketPath string,
4042
defaultsNamespace string,
4143
log logr.Logger,
4244
) error {
4345
// Deploy Multus using HelmAddonApplier with template function
4446
strategy := addons.NewHelmAddonApplier(
4547
addons.NewHelmAddonConfig(
46-
"default-multus-values-template",
48+
s.config.defaultValuesTemplateConfigMapName,
4749
defaultMultusNamespace,
4850
defaultMultusReleaseName,
4951
),
5052
s.client,
5153
s.helmChart,
52-
).WithValueTemplater(templateValuesFunc(readinessSocketPath)).
54+
).WithValueTemplater(templateValuesFunc(socketPath)).
5355
WithDefaultWaiter()
5456

5557
if err := strategy.Apply(ctx, cluster, defaultsNamespace, log); err != nil {
@@ -59,23 +61,3 @@ func (s helmAddonStrategy) apply(
5961
log.Info("Successfully deployed Multus")
6062
return nil
6163
}
62-
63-
// isCloudProviderSupported checks if the cluster is a supported cloud provider
64-
// by inspecting the infrastructure reference.
65-
func isCloudProviderSupported(cluster *clusterv1.Cluster) (
66-
isSupported bool,
67-
providerName string,
68-
) {
69-
if cluster.Spec.InfrastructureRef == nil {
70-
return false, ""
71-
}
72-
73-
switch cluster.Spec.InfrastructureRef.Kind {
74-
case "AWSManagedCluster":
75-
return true, "EKS"
76-
case "NutanixCluster":
77-
return true, "Nutanix"
78-
default:
79-
return false, ""
80-
}
81-
}

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

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,26 @@ package multus
66
import (
77
"bytes"
88
"fmt"
9-
"path/filepath"
10-
"strings"
119
"text/template"
1210

1311
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1412
)
1513

1614
// templateValuesFunc returns a template function that parses the Multus values template
17-
// and replaces socket-related placeholders with the provided readiness socket path.
18-
func templateValuesFunc(readinessSocketPath string) func(*clusterv1.Cluster, string) (string, error) {
15+
// and replaces socket-related placeholders with the provided socket path.
16+
func templateValuesFunc(socketPath string) func(*clusterv1.Cluster, string) (string, error) {
1917
return func(_ *clusterv1.Cluster, valuesTemplate string) (string, error) {
2018
t, err := template.New("").Parse(valuesTemplate)
2119
if err != nil {
2220
return "", fmt.Errorf("failed to parse Multus values template: %w", err)
2321
}
2422

2523
type input struct {
26-
ReadinessSocketPath string
27-
SocketVolumeName string
24+
SocketPath string
2825
}
2926

30-
// Extract volume name from socket path
31-
// e.g., "/run/cilium/cilium.sock" -> "cilium-sock"
32-
// or "/var/run/calico/cni-server.sock" -> "calico-sock"
33-
socketVolumeName := extractVolumeName(readinessSocketPath)
34-
3527
templateInput := input{
36-
ReadinessSocketPath: readinessSocketPath,
37-
SocketVolumeName: socketVolumeName,
28+
SocketPath: socketPath,
3829
}
3930

4031
var b bytes.Buffer
@@ -46,37 +37,3 @@ func templateValuesFunc(readinessSocketPath string) func(*clusterv1.Cluster, str
4637
return b.String(), nil
4738
}
4839
}
49-
50-
// extractVolumeName derives a volume name from the socket path.
51-
// Examples:
52-
// - "/run/cilium/cilium.sock" -> "cilium-sock"
53-
// - "/var/run/calico/cni-server.sock" -> "calico-sock"
54-
func extractVolumeName(socketPath string) string {
55-
if socketPath == "" {
56-
return ""
57-
}
58-
59-
// Get the directory part and extract the CNI name
60-
dir := filepath.Dir(socketPath)
61-
// Remove leading/trailing slashes and get the last component
62-
dir = strings.Trim(dir, "/")
63-
parts := strings.Split(dir, "/")
64-
65-
var name string
66-
// Look for "cilium" or "calico" in the path
67-
for _, part := range parts {
68-
if part == "cilium" || part == "calico" {
69-
name = part
70-
break
71-
}
72-
}
73-
74-
if name == "" {
75-
// Fallback: use the last directory component before the socket
76-
if len(parts) > 0 {
77-
name = parts[len(parts)-1]
78-
}
79-
}
80-
81-
return name + "-sock"
82-
}

pkg/handlers/lifecycle/cni/socket.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
1010
)
1111

12-
// ReadinessSocketPath returns the readiness socket path for the given CNI provider.
12+
// SocketPath returns the socket path for the given CNI provider.
1313
// The socket path is used by Multus to wait for the primary CNI to be ready.
1414
// Returns an empty string and error for unsupported providers.
15-
func ReadinessSocketPath(cniProvider string) (string, error) {
16-
switch cniProvider {
15+
func SocketPath(provider string) (string, error) {
16+
switch provider {
1717
case v1alpha1.CNIProviderCilium:
1818
return "/run/cilium/cilium.sock", nil
1919
case v1alpha1.CNIProviderCalico:
2020
return "/var/run/calico/cni-server.sock", nil
2121
default:
22-
return "", fmt.Errorf("unsupported CNI provider for Multus: %s", cniProvider)
22+
return "", fmt.Errorf("unsupported CNI provider for Multus: %s", provider)
2323
}
2424
}

0 commit comments

Comments
 (0)