@@ -31,8 +31,9 @@ import (
3131 "github.com/Azure/azure-container-networking/cns/hnsclient"
3232 "github.com/Azure/azure-container-networking/cns/ipampool"
3333 cssctrl "github.com/Azure/azure-container-networking/cns/kubecontroller/clustersubnetstate"
34+ mtpncctrl "github.com/Azure/azure-container-networking/cns/kubecontroller/multitenantpodnetworkconfig"
3435 nncctrl "github.com/Azure/azure-container-networking/cns/kubecontroller/nodenetworkconfig"
35- "github.com/Azure/azure-container-networking/cns/kubecontroller/podwatcher "
36+ podctrl "github.com/Azure/azure-container-networking/cns/kubecontroller/pod "
3637 "github.com/Azure/azure-container-networking/cns/logger"
3738 "github.com/Azure/azure-container-networking/cns/multitenantcontroller"
3839 "github.com/Azure/azure-container-networking/cns/multitenantcontroller/multitenantoperator"
@@ -41,7 +42,8 @@ import (
4142 "github.com/Azure/azure-container-networking/cns/wireserver"
4243 acn "github.com/Azure/azure-container-networking/common"
4344 "github.com/Azure/azure-container-networking/crd"
44- "github.com/Azure/azure-container-networking/crd/clustersubnetstate/api/v1alpha1"
45+ cssv1alpha1 "github.com/Azure/azure-container-networking/crd/clustersubnetstate/api/v1alpha1"
46+ mtv1alpha1 "github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
4547 "github.com/Azure/azure-container-networking/crd/nodenetworkconfig"
4648 "github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
4749 acnfs "github.com/Azure/azure-container-networking/internal/fs"
@@ -1123,6 +1125,19 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
11231125 return errors .Wrap (err , "failed to get NodeName" )
11241126 }
11251127
1128+ node , err := clientset .CoreV1 ().Nodes ().Get (ctx , nodeName , metav1.GetOptions {})
1129+ if err != nil {
1130+ return errors .Wrapf (err , "failed to get node %s" , nodeName )
1131+ }
1132+
1133+ // check the Node labels for Swift V2
1134+ if _ , ok := node .Labels [configuration .LabelSwiftV2 ]; ok {
1135+ cnsconfig .EnableSwiftV2 = true
1136+ cnsconfig .WatchPods = true
1137+ // TODO(rbtr): create the NodeInfo for Swift V2
1138+ // register the noop mtpnc reconciler to populate the cache
1139+ }
1140+
11261141 var podInfoByIPProvider cns.PodInfoByIPProvider
11271142 switch {
11281143 case cnsconfig .ManageEndpointState :
@@ -1195,9 +1210,12 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
11951210 if err = v1alpha .AddToScheme (scheme ); err != nil {
11961211 return errors .Wrap (err , "failed to add nodenetworkconfig/v1alpha to scheme" )
11971212 }
1198- if err = v1alpha1 .AddToScheme (scheme ); err != nil {
1213+ if err = cssv1alpha1 .AddToScheme (scheme ); err != nil {
11991214 return errors .Wrap (err , "failed to add clustersubnetstate/v1alpha1 to scheme" )
12001215 }
1216+ if err = mtv1alpha1 .AddToScheme (scheme ); err != nil {
1217+ return errors .Wrap (err , "failed to add multitenantpodnetworkconfig/v1alpha1 to scheme" )
1218+ }
12011219
12021220 // Set Selector options on the Manager cache which are used
12031221 // to perform *server-side* filtering of the cached objects. This is very important
@@ -1211,12 +1229,15 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
12111229 "kube-system" : {FieldSelector : fields .SelectorFromSet (fields.Set {"metadata.name" : nodeName })},
12121230 },
12131231 },
1214- & corev1.Pod {}: {
1215- Field : fields .SelectorFromSet (fields.Set {"spec.nodeName" : nodeName }),
1216- },
12171232 },
12181233 }
12191234
1235+ if cnsconfig .WatchPods {
1236+ cacheOpts .ByObject [& corev1.Pod {}] = cache.ByObject {
1237+ Field : fields .SelectorFromSet (fields.Set {"spec.nodeName" : nodeName }),
1238+ }
1239+ }
1240+
12201241 managerOpts := ctrlmgr.Options {
12211242 Scheme : scheme ,
12221243 Metrics : ctrlmetrics.Options {BindAddress : "0" },
@@ -1230,7 +1251,7 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
12301251 }
12311252
12321253 // Build the IPAM Pool monitor
1233- clusterSubnetStateChan := make (chan v1alpha1 .ClusterSubnetState )
1254+ clusterSubnetStateChan := make (chan cssv1alpha1 .ClusterSubnetState )
12341255
12351256 // this cachedscopedclient is built using the Manager's cached client, which is
12361257 // NOT SAFE TO USE UNTIL THE MANAGER IS STARTED!
@@ -1248,19 +1269,6 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
12481269
12491270 // Start building the NNC Reconciler
12501271
1251- // get our Node so that we can xref it against the NodeNetworkConfig's to make sure that the
1252- // NNC is not stale and represents the Node we're running on.
1253- node , err := clientset .CoreV1 ().Nodes ().Get (ctx , nodeName , metav1.GetOptions {})
1254- if err != nil {
1255- return errors .Wrapf (err , "failed to get node %s" , nodeName )
1256- }
1257-
1258- // check the Node labels for Swift V2
1259- if _ , ok := node .Labels [configuration .LabelSwiftV2 ]; ok {
1260- cnsconfig .EnableSwiftV2 = true
1261- // TODO(rbtr): create the NodeInfo for Swift V2
1262- }
1263-
12641272 // get CNS Node IP to compare NC Node IP with this Node IP to ensure NCs were created for this node
12651273 nodeIP := configuration .NodeIP ()
12661274
@@ -1281,12 +1289,18 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
12811289
12821290 // TODO: add pod listeners based on Swift V1 vs MT/V2 configuration
12831291 if cnsconfig .WatchPods {
1284- pw := podwatcher .New (nodeName )
1292+ pw := podctrl .New (nodeName )
12851293 if err := pw .SetupWithManager (manager ); err != nil {
12861294 return errors .Wrapf (err , "failed to setup pod watcher with manager" )
12871295 }
12881296 }
12891297
1298+ if cnsconfig .EnableSwiftV2 {
1299+ if err := mtpncctrl .SetupWithManager (manager ); err != nil {
1300+ return errors .Wrapf (err , "failed to setup mtpnc reconciler with manager" )
1301+ }
1302+ }
1303+
12901304 // adding some routes to the root service mux
12911305 mux := httpRestServiceImplementation .Listener .GetMux ()
12921306 mux .Handle ("/readyz" , http .StripPrefix ("/readyz" , & healthz.Handler {}))
0 commit comments