@@ -19,11 +19,13 @@ package controllers
1919import (
2020 "context"
2121 "fmt"
22+ "time"
23+
2224 "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2325 "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
2426 "k8s.io/apimachinery/pkg/types"
25- "time"
2627
28+ networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
2729 "github.com/openstack-k8s-operators/lib-common/modules/common/env"
2830 "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
2931 nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
@@ -53,8 +55,9 @@ func ensureNAD(
5355 var err error
5456 // Iterate over the []networkattachment, get the corresponding NAD and create
5557 // the required annotation
58+ nadList := []networkv1.NetworkAttachmentDefinition {}
5659 for _ , netAtt := range nAttach {
57- _ , err = nad .GetNADWithName (ctx , helper , netAtt , helper .GetBeforeObject ().GetNamespace ())
60+ nad , err : = nad .GetNADWithName (ctx , helper , netAtt , helper .GetBeforeObject ().GetNamespace ())
5861 if err != nil {
5962 if k8s_errors .IsNotFound (err ) {
6063 log .FromContext (ctx ).Info (fmt .Sprintf ("network-attachment-definition %s not found" , netAtt ))
@@ -74,9 +77,13 @@ func ensureNAD(
7477 err .Error ()))
7578 return serviceAnnotations , manila .ResultRequeue , nil
7679 }
80+
81+ if nad != nil {
82+ nadList = append (nadList , * nad )
83+ }
7784 }
7885 // Create NetworkAnnotations
79- serviceAnnotations , err = nad .CreateNetworksAnnotation ( helper . GetBeforeObject (). GetNamespace (), nAttach )
86+ serviceAnnotations , err = nad .EnsureNetworksAnnotation ( nadList )
8087 if err != nil {
8188 err := fmt .Errorf ("failed create network annotation from %s: %w" , nAttach , err )
8289 conditionUpdater .Set (condition .FalseCondition (
0 commit comments