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+
2533type MultusConfig struct {
2634 * options.GlobalOptions
35+
36+ helmAddonConfig * addons.HelmAddonConfig
2737}
2838
2939func 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
3550func (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
3954type MultusHandler struct {
4055 client ctrlclient.Client
4156 config * MultusConfig
4257 helmChartInfoGetter * config.HelmChartGetter
43- deployer * MultusDeployer
4458}
4559
4660var (
@@ -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