Skip to content

Commit c053ba5

Browse files
author
Ashish Nair
committed
fix:Updating the NNC to Patch or create a new NNC and update the HomeAz accordingly
1 parent 85eb1ad commit c053ba5

File tree

7 files changed

+40
-16
lines changed

7 files changed

+40
-16
lines changed

.pipelines/mdnc/azure-cns-cni-1.4.39.1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ metadata:
1212
rules:
1313
- apiGroups: ["acn.azure.com"]
1414
resources: ["nodenetworkconfigs"]
15-
verbs: ["get", "list", "watch", "patch", "update"]
15+
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
1616
---
1717
apiVersion: rbac.authorization.k8s.io/v1
1818
kind: ClusterRole

.pipelines/mdnc/azure-cns-cni-1.5.28.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ metadata:
1212
rules:
1313
- apiGroups: ["acn.azure.com"]
1414
resources: ["nodenetworkconfigs"]
15-
verbs: ["get", "list", "watch", "patch", "update"]
15+
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
1616
---
1717
apiVersion: rbac.authorization.k8s.io/v1
1818
kind: ClusterRole

.pipelines/mdnc/azure-cns-cni-1.5.4.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ metadata:
1212
rules:
1313
- apiGroups: ["acn.azure.com"]
1414
resources: ["nodenetworkconfigs"]
15-
verbs: ["get", "list", "watch", "patch", "update"]
15+
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
1616
---
1717
apiVersion: rbac.authorization.k8s.io/v1
1818
kind: ClusterRole

.pipelines/mdnc/azure-cns-cni.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ metadata:
1212
rules:
1313
- apiGroups: ["acn.azure.com"]
1414
resources: ["nodenetworkconfigs"]
15-
verbs: ["get", "list", "watch", "patch", "update"]
15+
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
1616
---
1717
apiVersion: rbac.authorization.k8s.io/v1
1818
kind: ClusterRole

cns/azure-cns.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ metadata:
1212
rules:
1313
- apiGroups: ["acn.azure.com"]
1414
resources: ["nodenetworkconfigs"]
15-
verbs: ["get", "list", "watch", "patch", "update"]
15+
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
1616
---
1717
apiVersion: rbac.authorization.k8s.io/v1
1818
kind: ClusterRole

cns/service/main.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,16 +1303,39 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
13031303
// TODO(rbtr): nodename and namespace should be in the cns config
13041304
directscopedcli := nncctrl.NewScopedClient(directnnccli, types.NamespacedName{Namespace: "kube-system", Name: nodeName})
13051305

1306-
nnc := v1alpha.NodeNetworkConfig{}
1306+
// Create the base NNC CRD if HomeAz is enabled
13071307
if cnsconfig.EnableHomeAz {
1308-
// Create Node Network Config CRD and update the Home Az field with the cache value from the HomeAz Monitor
1309-
nnc = createBaseNNC(node)
13101308
homeAzResponse := httpRestServiceImplementation.GetHomeAz(ctx)
1311-
nnc.Spec.AvailabilityZone = strconv.FormatUint(uint64(homeAzResponse.HomeAzResponse.HomeAz), 10)
1312-
}
1309+
availabilityZone := strconv.FormatUint(uint64(homeAzResponse.HomeAzResponse.HomeAz), 10)
1310+
logger.Printf("[Azure CNS] HomeAz: %s", availabilityZone)
1311+
// Create Node Network Config CRD and update the Home Az field with the cache value from the HomeAz Monitor
1312+
var nnc *v1alpha.NodeNetworkConfig
1313+
if nnc, err = directnnccli.Get(ctx, types.NamespacedName{Namespace: "kube-system", Name: nodeName}); err != nil {
1314+
logger.Errorf("[Azure CNS] failed to get existing NNC: %v", err)
1315+
}
13131316

1314-
if err = directcli.Create(ctx, &nnc); err != nil {
1315-
return errors.Wrap(err, "failed to create base NNC")
1317+
if nnc == nil {
1318+
logger.Printf("[Azure CNS] Creating new base NNC")
1319+
newNNC := createBaseNNC(node)
1320+
newNNC.Spec.AvailabilityZone = availabilityZone
1321+
if err = directcli.Create(ctx, newNNC); err != nil {
1322+
return errors.Wrap(err, "failed to create base NNC")
1323+
}
1324+
} 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+
// }
1329+
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")
1336+
}
1337+
}
1338+
logger.Printf("[Azure CNS] Updated HomeAz in NNC")
13161339
}
13171340

13181341
logger.Printf("Reconciling initial CNS state")
@@ -1525,14 +1548,15 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
15251548
return nil
15261549
}
15271550

1528-
func createBaseNNC(node *corev1.Node) v1alpha.NodeNetworkConfig {
1529-
return v1alpha.NodeNetworkConfig{ObjectMeta: metav1.ObjectMeta{
1551+
func createBaseNNC(node *corev1.Node) *v1alpha.NodeNetworkConfig {
1552+
return &v1alpha.NodeNetworkConfig{ObjectMeta: metav1.ObjectMeta{
15301553
Annotations: make(map[string]string),
15311554
Labels: map[string]string{
15321555
"managed": "true",
15331556
"owner": node.Name,
15341557
},
1535-
Name: node.Name,
1558+
Name: node.Name,
1559+
Namespace: "kube-system",
15361560
}}
15371561
}
15381562

test/integration/manifests/cilium/cns-write-ovly.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ metadata:
1212
rules:
1313
- apiGroups: ["acn.azure.com"]
1414
resources: ["nodenetworkconfigs"]
15-
verbs: ["get", "list", "watch", "patch", "update"]
15+
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
1616
---
1717
apiVersion: rbac.authorization.k8s.io/v1
1818
kind: ClusterRole

0 commit comments

Comments
 (0)