diff --git a/main.go b/main.go index 9c44da3bb2..10cbf5188c 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" utilruntime "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/client-go/kubernetes" clientgoscheme "k8s.io/client-go/kubernetes/scheme" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" "k8s.io/client-go/rest" @@ -99,6 +100,11 @@ func main() { os.Exit(1) } + if err := initNicIdMap(); err != nil { + setupLog.Error(err, "unable to init NicIdMap") + os.Exit(1) + } + if err = (&controllers.SriovNetworkReconciler{ Client: mgrGlobal.GetClient(), Scheme: mgrGlobal.GetScheme(), @@ -174,6 +180,16 @@ func main() { } } +func initNicIdMap() error { + namespace := os.Getenv("NAMESPACE") + kubeclient := kubernetes.NewForConfigOrDie(ctrl.GetConfigOrDie()) + if err := sriovnetworkv1.InitNicIdMap(kubeclient, namespace); err != nil { + return err + } + + return nil +} + func createDefaultPolicy(cfg *rest.Config) error { logger := setupLog.WithName("createDefaultPolicy") c, err := client.New(cfg, client.Options{Scheme: scheme})