Skip to content

Commit dc56d5b

Browse files
author
Ashish Nair
committed
fix: Updated the code to delete and the create the NNC with the HomeAz value
1 parent c053ba5 commit dc56d5b

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

cns/service/main.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,36 +1306,46 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
13061306
// Create the base NNC CRD if HomeAz is enabled
13071307
if cnsconfig.EnableHomeAz {
13081308
homeAzResponse := httpRestServiceImplementation.GetHomeAz(ctx)
1309-
availabilityZone := strconv.FormatUint(uint64(homeAzResponse.HomeAzResponse.HomeAz), 10)
1310-
logger.Printf("[Azure CNS] HomeAz: %s", availabilityZone)
1309+
logger.Printf("[Azure CNS] HomeAz: %s", strconv.FormatUint(uint64(homeAzResponse.HomeAzResponse.HomeAz), 10))
13111310
// Create Node Network Config CRD and update the Home Az field with the cache value from the HomeAz Monitor
13121311
var nnc *v1alpha.NodeNetworkConfig
13131312
if nnc, err = directnnccli.Get(ctx, types.NamespacedName{Namespace: "kube-system", Name: nodeName}); err != nil {
13141313
logger.Errorf("[Azure CNS] failed to get existing NNC: %v", err)
13151314
}
13161315

1316+
newNNC := createBaseNNC(node)
13171317
if nnc == nil {
13181318
logger.Printf("[Azure CNS] Creating new base NNC")
1319-
newNNC := createBaseNNC(node)
1320-
newNNC.Spec.AvailabilityZone = availabilityZone
1319+
newNNC.Spec.AvailabilityZone = strconv.FormatUint(uint64(homeAzResponse.HomeAzResponse.HomeAz), 10)
13211320
if err = directcli.Create(ctx, newNNC); err != nil {
13221321
return errors.Wrap(err, "failed to create base NNC")
13231322
}
13241323
} else {
1325-
// nnc.Spec.AvailabilityZone = availabilityZone
1326-
// if err = directcli.Update(ctx, nnc); err != nil {
1327-
// return errors.Wrap(err, "failed to update base NNC")
1328-
// }
13291324
logger.Printf("[Azure CNS] Patching existing NNC with new Spec with HomeAz")
1330-
newSpec := v1alpha.NodeNetworkConfigSpec{}
1331-
newSpec.AvailabilityZone = availabilityZone
1332-
newSpec.RequestedIPCount = nnc.Spec.RequestedIPCount
1333-
newSpec.IPsNotInUse = nnc.Spec.IPsNotInUse
1334-
if _, err := directnnccli.PatchSpec(ctx, types.NamespacedName{Namespace: "kube-system", Name: nodeName}, &newSpec, "azure-cns"); err != nil {
1335-
return errors.Wrap(err, "failed to update base NNC")
1325+
newNNC.Spec.AvailabilityZone = strconv.FormatUint(uint64(homeAzResponse.HomeAzResponse.HomeAz), 10)
1326+
newNNC.Spec.RequestedIPCount = nnc.Spec.RequestedIPCount
1327+
newNNC.Spec.IPsNotInUse = nnc.Spec.IPsNotInUse
1328+
newNNC.Status = nnc.Status
1329+
newNNC.UID = nnc.UID
1330+
newNNC.Name = nnc.Name
1331+
newNNC.Namespace = nnc.Namespace
1332+
newNNC.Annotations = nnc.Annotations
1333+
newNNC.Labels = nnc.Labels
1334+
newNNC.Finalizers = nnc.Finalizers
1335+
newNNC.OwnerReferences = nnc.OwnerReferences
1336+
newNNC.CreationTimestamp = nnc.CreationTimestamp
1337+
newNNC.DeletionTimestamp = nnc.DeletionTimestamp
1338+
1339+
// Delete existing NNC and create new one with updated HomeAz
1340+
if err = directcli.Delete(ctx, nnc); err != nil {
1341+
return errors.Wrap(err, "[Azure CNS]: failed to delete existing NNC")
1342+
}
1343+
1344+
if err = directcli.Create(ctx, newNNC); err != nil {
1345+
return errors.Wrap(err, "[Azure CNS]: failed to create new NNC")
13361346
}
13371347
}
1338-
logger.Printf("[Azure CNS] Updated HomeAz in NNC")
1348+
logger.Printf("[Azure CNS] Updated HomeAz in NNC %v", newNNC)
13391349
}
13401350

13411351
logger.Printf("Reconciling initial CNS state")

0 commit comments

Comments
 (0)