Skip to content

Commit fc1e937

Browse files
feat: removing addon strategy
1 parent f13740b commit fc1e937

11 files changed

+62
-234
lines changed

api/v1alpha1/addon_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ type NutanixKonnectorAgent struct {
379379
// A reference to the Secret for credential information for the target Prism Central instance
380380
// +kubebuilder:validation:Optional
381381
Credentials *NutanixKonnectorAgentCredentials `json:"credentials,omitempty"`
382-
383382
}
384383

385384
type NutanixKonnectorAgentCredentials struct {

api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,6 @@ spec:
256256
required:
257257
- secretRef
258258
type: object
259-
strategy:
260-
default: HelmAddon
261-
description: Addon strategy used to deploy the Nutanix konnector-agent to the k8s cluster.
262-
enum:
263-
- HelmAddon
264-
type: string
265259
type: object
266260
nfd:
267261
description: NFD tells us to enable or disable the node feature discovery addon.

examples/capi-quick-start/nutanix-cluster-calico-crs.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ spec:
9494
credentials:
9595
secretRef:
9696
name: ${CLUSTER_NAME}-pc-creds-for-konnector-agent
97-
strategy: HelmAddon
9897
nfd:
9998
strategy: ClusterResourceSet
10099
serviceLoadBalancer:

examples/capi-quick-start/nutanix-cluster-calico-helm-addon.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ spec:
9292
credentials:
9393
secretRef:
9494
name: ${CLUSTER_NAME}-pc-creds-for-konnector-agent
95-
strategy: HelmAddon
9695
nfd: {}
9796
serviceLoadBalancer:
9897
configuration:

examples/capi-quick-start/nutanix-cluster-cilium-crs.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ spec:
9494
credentials:
9595
secretRef:
9696
name: ${CLUSTER_NAME}-pc-creds-for-konnector-agent
97-
strategy: HelmAddon
9897
nfd:
9998
strategy: ClusterResourceSet
10099
serviceLoadBalancer:

examples/capi-quick-start/nutanix-cluster-cilium-helm-addon.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ spec:
9292
credentials:
9393
secretRef:
9494
name: ${CLUSTER_NAME}-pc-creds-for-konnector-agent
95-
strategy: HelmAddon
9695
nfd: {}
9796
serviceLoadBalancer:
9897
configuration:

examples/capi-quick-start/nutanix-cluster-with-failuredomains-cilium-crs.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ spec:
130130
credentials:
131131
secretRef:
132132
name: ${CLUSTER_NAME}-pc-creds-for-konnector-agent
133-
strategy: HelmAddon
134133
nfd:
135134
strategy: ClusterResourceSet
136135
serviceLoadBalancer:

examples/capi-quick-start/nutanix-cluster-with-failuredomains-cilium-helm-addon.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ spec:
128128
credentials:
129129
secretRef:
130130
name: ${CLUSTER_NAME}-pc-creds-for-konnector-agent
131-
strategy: HelmAddon
132131
nfd: {}
133132
serviceLoadBalancer:
134133
configuration:

hack/examples/patches/nutanix/konnector-agent.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
credentials:
88
secretRef:
99
name: ${CLUSTER_NAME}-pc-creds-for-konnector-agent
10-
strategy: HelmAddon

pkg/handlers/lifecycle/konnectoragent/handler.go

Lines changed: 61 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -210,55 +210,42 @@ func (n *DefaultKonnectorAgent) apply(
210210
}
211211

212212
var strategy addons.Applier
213-
switch k8sAgentVar.Strategy {
214-
case v1alpha1.AddonStrategyHelmAddon:
215-
helmChart, err := n.helmChartInfoGetter.For(ctx, log, config.KonnectorAgent)
216-
if err != nil {
217-
log.Error(
218-
err,
219-
"failed to get configmap with helm settings",
220-
)
221-
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
222-
resp.SetMessage(
223-
fmt.Sprintf("failed to get configuration to create helm addon: %v",
224-
err,
225-
),
226-
)
227-
return
228-
}
229-
clusterConfigVar, err := variables.Get[apivariables.ClusterConfigSpec](
230-
varMap,
231-
v1alpha1.ClusterConfigVariableName,
213+
helmChart, err := n.helmChartInfoGetter.For(ctx, log, config.KonnectorAgent)
214+
if err != nil {
215+
log.Error(
216+
err,
217+
"failed to get configmap with helm settings",
232218
)
233-
if err != nil {
234-
log.Error(
235-
err,
236-
"failed to read clusterConfig variable from cluster definition",
237-
)
238-
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
239-
resp.SetMessage(
240-
fmt.Sprintf("failed to read clusterConfig variable from cluster definition: %v",
241-
err,
242-
),
243-
)
244-
return
245-
}
246-
strategy = addons.NewHelmAddonApplier(
247-
n.config.helmAddonConfig,
248-
n.client,
249-
helmChart,
250-
).WithValueTemplater(templateValuesFunc(clusterConfigVar.Nutanix, cluster))
251-
case "":
252219
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
253-
resp.SetMessage("strategy not provided for Konnector Agent")
220+
resp.SetMessage(
221+
fmt.Sprintf("failed to get configuration to create helm addon: %v",
222+
err,
223+
),
224+
)
254225
return
255-
default:
226+
}
227+
clusterConfigVar, err := variables.Get[apivariables.ClusterConfigSpec](
228+
varMap,
229+
v1alpha1.ClusterConfigVariableName,
230+
)
231+
if err != nil {
232+
log.Error(
233+
err,
234+
"failed to read clusterConfig variable from cluster definition",
235+
)
256236
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
257237
resp.SetMessage(
258-
fmt.Sprintf("unknown Konnector Agent addon deployment strategy %q", k8sAgentVar.Strategy),
238+
fmt.Sprintf("failed to read clusterConfig variable from cluster definition: %v",
239+
err,
240+
),
259241
)
260242
return
261243
}
244+
strategy = addons.NewHelmAddonApplier(
245+
n.config.helmAddonConfig,
246+
n.client,
247+
helmChart,
248+
).WithValueTemplater(templateValuesFunc(clusterConfigVar.Nutanix, cluster))
262249

263250
if err := strategy.Apply(ctx, cluster, n.config.DefaultsNamespace(), log); err != nil {
264251
log.Error(err, "Helm strategy Apply failed")
@@ -333,7 +320,7 @@ func (n *DefaultKonnectorAgent) BeforeClusterDelete(
333320
)
334321

335322
varMap := variables.ClusterVariablesToVariablesMap(cluster.Spec.Topology.Variables)
336-
k8sAgentVar, err := variables.Get[apivariables.NutanixKonnectorAgent](
323+
_, err := variables.Get[apivariables.NutanixKonnectorAgent](
337324
varMap,
338325
n.variableName,
339326
n.variablePath...)
@@ -358,56 +345,42 @@ func (n *DefaultKonnectorAgent) BeforeClusterDelete(
358345
return
359346
}
360347

361-
// Only handle HelmAddon strategy for cleanup
362-
switch k8sAgentVar.Strategy {
363-
case v1alpha1.AddonStrategyHelmAddon:
364-
// Check if cleanup is already in progress or completed
365-
cleanupStatus, err := n.checkCleanupStatus(ctx, cluster, log)
366-
if err != nil {
367-
log.Error(err, "Failed to check cleanup status")
368-
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
369-
resp.SetMessage(err.Error())
370-
return
371-
}
372-
373-
switch cleanupStatus {
374-
case cleanupStatusCompleted:
375-
log.Info("Konnector Agent cleanup already completed")
376-
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess)
377-
return
378-
case cleanupStatusInProgress:
379-
log.Info("Konnector Agent cleanup in progress, requesting retry")
380-
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess)
381-
resp.SetRetryAfterSeconds(5) // Retry after 5 seconds
382-
return
383-
case cleanupStatusNotStarted:
384-
log.Info("Starting Konnector Agent cleanup")
385-
// Proceed with cleanup below
386-
}
387-
388-
err = n.deleteHelmChartProxy(ctx, cluster, log)
389-
if err != nil {
390-
log.Error(err, "Failed to delete helm chart")
391-
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
392-
resp.SetMessage(err.Error())
393-
return
394-
}
395-
396-
// After initiating cleanup, request a retry to monitor completion
397-
log.Info("Konnector Agent cleanup initiated, will monitor progress")
398-
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess)
399-
resp.SetRetryAfterSeconds(5) // Quick retry to start monitoring
348+
// Check if cleanup is already in progress or completed
349+
cleanupStatus, err := n.checkCleanupStatus(ctx, cluster, log)
350+
if err != nil {
351+
log.Error(err, "Failed to check cleanup status")
352+
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
353+
resp.SetMessage(err.Error())
354+
return
355+
}
400356

401-
case "":
402-
log.Info("No strategy specified, skipping cleanup")
357+
switch cleanupStatus {
358+
case cleanupStatusCompleted:
359+
log.Info("Konnector Agent cleanup already completed")
403360
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess)
404-
default:
405-
log.Info(
406-
"Unknown Konnector Agent strategy, skipping cleanup",
407-
"strategy", k8sAgentVar.Strategy,
408-
)
361+
return
362+
case cleanupStatusInProgress:
363+
log.Info("Konnector Agent cleanup in progress, requesting retry")
409364
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess)
365+
resp.SetRetryAfterSeconds(5) // Retry after 5 seconds
366+
return
367+
case cleanupStatusNotStarted:
368+
log.Info("Starting Konnector Agent cleanup")
369+
// Proceed with cleanup below
410370
}
371+
372+
err = n.deleteHelmChartProxy(ctx, cluster, log)
373+
if err != nil {
374+
log.Error(err, "Failed to delete helm chart")
375+
resp.SetStatus(runtimehooksv1.ResponseStatusFailure)
376+
resp.SetMessage(err.Error())
377+
return
378+
}
379+
380+
// After initiating cleanup, request a retry to monitor completion
381+
log.Info("Konnector Agent cleanup initiated, will monitor progress")
382+
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess)
383+
resp.SetRetryAfterSeconds(5) // Quick retry to start monitoring
411384
}
412385

413386
func (n *DefaultKonnectorAgent) deleteHelmChartProxy(

0 commit comments

Comments
 (0)