From 8d4029f79cb1fbd4acf35927a54749c04b948ca2 Mon Sep 17 00:00:00 2001 From: PoAn Yang Date: Thu, 4 Jul 2024 10:02:44 +0800 Subject: [PATCH 1/2] feat: add log about watching namespace and skip vmi Signed-off-by: PoAn Yang --- pkg/controller/virtualmachineinstance/controller.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/controller/virtualmachineinstance/controller.go b/pkg/controller/virtualmachineinstance/controller.go index 9bad99b9..0d952db3 100644 --- a/pkg/controller/virtualmachineinstance/controller.go +++ b/pkg/controller/virtualmachineinstance/controller.go @@ -42,6 +42,10 @@ func Register( nodeToVMName: nodeToVMName, namespace: namespace, } + logrus.WithFields(logrus.Fields{ + "controller": vmiControllerName, + "namespace": namespace, + }).Info("start watching virtual machine instance") vmis.OnChange(ctx, vmiControllerName, handler.OnVmiChanged) } @@ -63,10 +67,18 @@ func (h *Handler) OnVmiChanged(_ string, vmi *kubevirtv1.VirtualMachineInstance) // only handle the migration completed vmi if vmi == nil || vmi.DeletionTimestamp != nil || vmi.Annotations == nil || vmi.Namespace != h.namespace || !isMigrationCompleted(vmi) { + logrus.WithFields(logrus.Fields{ + "namespace": vmi.Namespace, + "name": vmi.Name, + }).Info("skip processing virtual machine instance") return vmi, nil } if creator := vmi.Labels[builder.LabelKeyVirtualMachineCreator]; creator != virtualmachine.VirtualMachineCreatorNodeDriver { + logrus.WithFields(logrus.Fields{ + "namespace": vmi.Namespace, + "name": vmi.Name, + }).Info("skip processing virtual machine instance") return vmi, nil } From 4e1e2347b4d5ca97a1801a134ac0f4e1e73d8a1f Mon Sep 17 00:00:00 2001 From: PoAn Yang Date: Thu, 4 Jul 2024 10:56:25 +0800 Subject: [PATCH 2/2] fix: add default namespace if namespace is empty Signed-off-by: PoAn Yang --- pkg/cloud-controller-manager/ccm.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/cloud-controller-manager/ccm.go b/pkg/cloud-controller-manager/ccm.go index 263f0955..e4978a93 100644 --- a/pkg/cloud-controller-manager/ccm.go +++ b/pkg/cloud-controller-manager/ccm.go @@ -12,6 +12,7 @@ import ( "github.com/rancher/wrangler/pkg/kubeconfig" "github.com/rancher/wrangler/pkg/signals" "github.com/rancher/wrangler/pkg/start" + corev1 "k8s.io/api/core/v1" "k8s.io/client-go/tools/clientcmd" cloudprovider "k8s.io/cloud-provider" "k8s.io/klog/v2" @@ -67,6 +68,9 @@ func newCloudProvider(reader io.Reader) (cloudprovider.Interface, error) { } namespace := rawConfig.Contexts[rawConfig.CurrentContext].Namespace + if namespace == "" { + namespace = corev1.NamespaceDefault + } localCfg, err := kubeconfig.GetNonInteractiveClientConfig(os.Getenv("KUBECONFIG")).ClientConfig() if err != nil {