From 52d19ec28cb0c15ae02df1119e328d38fd8fad21 Mon Sep 17 00:00:00 2001 From: Ivan Kolodyazhny Date: Sun, 1 Aug 2021 09:33:34 +0300 Subject: [PATCH] Init sriovnetworkv1.NicIdMap on operator startup (#171) After moving sriovnetworkv1.NicIdMap into ConfigMap we need to initialize it's data on operator startup. Signed-off-by: Ivan Kolodyazhny --- main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.go b/main.go index 9c44da3bb..f28587538 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})