From 3c87c43ceff6122637c8d8070601f7271026360e Mon Sep 17 00:00:00 2001 From: Shivanshu Raj Shrivastava Date: Wed, 27 Oct 2021 01:51:22 +0530 Subject: [PATCH] Migrated `scheduler` files server.go, node_label.go, csi.go, non_csi.go to structured logging (#105855) * migrated server.go * fixed migration * resolving review comments * added storageClass * review comments * review comments --- cmd/kube-scheduler/app/server.go | 5 +++-- .../framework/plugins/nodelabel/node_label.go | 2 +- .../framework/plugins/nodevolumelimits/csi.go | 14 ++++++-------- .../framework/plugins/nodevolumelimits/non_csi.go | 14 +++++++------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/cmd/kube-scheduler/app/server.go b/cmd/kube-scheduler/app/server.go index 373da9ce456..a313e242dec 100644 --- a/cmd/kube-scheduler/app/server.go +++ b/cmd/kube-scheduler/app/server.go @@ -65,7 +65,8 @@ type Option func(runtime.Registry) error func NewSchedulerCommand(registryOptions ...Option) *cobra.Command { opts, err := options.NewOptions() if err != nil { - klog.Fatalf("unable to initialize command options: %v", err) + klog.ErrorS(err, "Unable to initialize command options") + os.Exit(1) } cmd := &cobra.Command{ @@ -196,7 +197,7 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched * select { case <-ctx.Done(): // We were asked to terminate. Exit 0. - klog.Info("Requested to terminate. Exiting.") + klog.InfoS("Requested to terminate, exiting") os.Exit(0) default: // We lost the lock. diff --git a/pkg/scheduler/framework/plugins/nodelabel/node_label.go b/pkg/scheduler/framework/plugins/nodelabel/node_label.go index 5bdd1686110..4d1b928649e 100644 --- a/pkg/scheduler/framework/plugins/nodelabel/node_label.go +++ b/pkg/scheduler/framework/plugins/nodelabel/node_label.go @@ -51,7 +51,7 @@ func New(plArgs runtime.Object, handle framework.Handle) (framework.Plugin, erro return nil, err } - klog.Warning("NodeLabel plugin is deprecated and will be removed in a future version; use NodeAffinity instead") + klog.InfoS("NodeLabel plugin is deprecated and will be removed in a future version, use NodeAffinity instead") return &NodeLabel{ handle: handle, args: args, diff --git a/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go b/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go index def28682f0b..df5d0a54f61 100644 --- a/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go +++ b/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go @@ -96,7 +96,7 @@ func (pl *CSILimits) Filter(ctx context.Context, _ *framework.CycleState, pod *v csiNode, err := pl.csiNodeLister.Get(node.Name) if err != nil { // TODO: return the error once CSINode is created by default (2 releases) - klog.V(5).InfoS("Could not get a CSINode object for the node", "node", node.Name, "err", err) + klog.V(5).InfoS("Could not get a CSINode object for the node", "node", klog.KObj(node), "err", err) } newVolumes := make(map[string]string) @@ -188,7 +188,7 @@ func (pl *CSILimits) filterAttachableVolumes( } // If the PVC is invalid, we don't count the volume because // there's no guarantee that it belongs to the running predicate. - klog.V(5).InfoS("Unable to look up PVC info", "PVC", fmt.Sprintf("%s/%s", pod.Namespace, pvcName)) + klog.V(5).InfoS("Unable to look up PVC info", "pod", klog.KObj(pod), "PVC", klog.KRef(pod.Namespace, pvcName)) continue } @@ -215,17 +215,15 @@ func (pl *CSILimits) filterAttachableVolumes( // the information of the CSI driver that the plugin has been migrated to. func (pl *CSILimits) getCSIDriverInfo(csiNode *storagev1.CSINode, pvc *v1.PersistentVolumeClaim) (string, string) { pvName := pvc.Spec.VolumeName - namespace := pvc.Namespace - pvcName := pvc.Name if pvName == "" { - klog.V(5).InfoS("Persistent volume had no name for claim", "PVC", fmt.Sprintf("%s/%s", namespace, pvcName)) + klog.V(5).InfoS("Persistent volume had no name for claim", "PVC", klog.KObj(pvc)) return pl.getCSIDriverInfoFromSC(csiNode, pvc) } pv, err := pl.pvLister.Get(pvName) if err != nil { - klog.V(5).InfoS("Unable to look up PV info for PVC and PV", "PVC", fmt.Sprintf("%s/%s", namespace, pvcName), "PV", pvName) + klog.V(5).InfoS("Unable to look up PV info for PVC and PV", "PVC", klog.KObj(pvc), "PV", klog.KRef("", pvName)) // If we can't fetch PV associated with PVC, may be it got deleted // or PVC was prebound to a PVC that hasn't been created yet. // fallback to using StorageClass for volume counting @@ -276,13 +274,13 @@ func (pl *CSILimits) getCSIDriverInfoFromSC(csiNode *storagev1.CSINode, pvc *v1. // If StorageClass is not set or not found, then PVC must be using immediate binding mode // and hence it must be bound before scheduling. So it is safe to not count it. if scName == "" { - klog.V(5).InfoS("PVC has no StorageClass", "PVC", fmt.Sprintf("%s/%s", namespace, pvcName)) + klog.V(5).InfoS("PVC has no StorageClass", "PVC", klog.KObj(pvc)) return "", "" } storageClass, err := pl.scLister.Get(scName) if err != nil { - klog.V(5).InfoS("Could not get StorageClass for PVC", "PVC", fmt.Sprintf("%s/%s", namespace, pvcName), "err", err) + klog.V(5).InfoS("Could not get StorageClass for PVC", "PVC", klog.KObj(pvc), "err", err) return "", "" } diff --git a/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go b/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go index 78e8458b794..7673053b370 100644 --- a/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go +++ b/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go @@ -178,7 +178,7 @@ func newNonCSILimits( filter = cinderVolumeFilter volumeLimitKey = v1.ResourceName(volumeutil.CinderVolumeLimitKey) default: - klog.ErrorS(errors.New("wrong filterName"), "Cannot create nonCSILimits plugin", "candidates", fmt.Sprintf("%v %v %v %v", ebsVolumeFilterType, gcePDVolumeFilterType, azureDiskVolumeFilterType, cinderVolumeFilterType)) + klog.ErrorS(errors.New("wrong filterName"), "Cannot create nonCSILimits plugin") return nil } pl := &nonCSILimits{ @@ -242,7 +242,7 @@ func (pl *nonCSILimits) Filter(ctx context.Context, _ *framework.CycleState, pod if err != nil { // we don't fail here because the CSINode object is only necessary // for determining whether the migration is enabled or not - klog.V(5).InfoS("Could not get a CSINode object for the node", "node", node.Name, "err", err) + klog.V(5).InfoS("Could not get a CSINode object for the node", "node", klog.KObj(node), "err", err) } } @@ -327,7 +327,7 @@ func (pl *nonCSILimits) filterVolumes(pod *v1.Pod, newPod bool, filteredVolumes } // If the PVC is invalid, we don't count the volume because // there's no guarantee that it belongs to the running predicate. - klog.V(4).InfoS("Unable to look up PVC info, assuming PVC doesn't match predicate when counting limits", "PVC", fmt.Sprintf("%s/%s", pod.Namespace, pvcName), "err", err) + klog.V(4).InfoS("Unable to look up PVC info, assuming PVC doesn't match predicate when counting limits", "pod", klog.KObj(pod), "PVC", klog.KRef(pod.Namespace, pvcName), "err", err) continue } @@ -343,7 +343,7 @@ func (pl *nonCSILimits) filterVolumes(pod *v1.Pod, newPod bool, filteredVolumes // original PV where it was bound to, so we count the volume if // it belongs to the running predicate. if pl.matchProvisioner(pvc) { - klog.V(4).InfoS("PVC is not bound, assuming PVC matches predicate when counting limits", "PVC", fmt.Sprintf("%s/%s", pod.Namespace, pvcName)) + klog.V(4).InfoS("PVC is not bound, assuming PVC matches predicate when counting limits", "pod", klog.KObj(pod), "PVC", klog.KRef(pod.Namespace, pvcName)) filteredVolumes.Insert(pvID) } continue @@ -354,7 +354,7 @@ func (pl *nonCSILimits) filterVolumes(pod *v1.Pod, newPod bool, filteredVolumes // If the PV is invalid and PVC belongs to the running predicate, // log the error and count the PV towards the PV limit. if pl.matchProvisioner(pvc) { - klog.V(4).InfoS("Unable to look up PV, assuming PV matches predicate when counting limits", "PV", fmt.Sprintf("%s/%s/%s", pod.Namespace, pvcName, pvName), "err", err) + klog.V(4).InfoS("Unable to look up PV, assuming PV matches predicate when counting limits", "pod", klog.KObj(pod), "PVC", klog.KRef(pod.Namespace, pvcName), "PV", klog.KRef("", pvName), "err", err) filteredVolumes.Insert(pvID) } continue @@ -386,9 +386,9 @@ func (pl *nonCSILimits) matchProvisioner(pvc *v1.PersistentVolumeClaim) bool { func getMaxVolLimitFromEnv() int { if rawMaxVols := os.Getenv(KubeMaxPDVols); rawMaxVols != "" { if parsedMaxVols, err := strconv.Atoi(rawMaxVols); err != nil { - klog.ErrorS(err, "Unable to parse maximum PD volumes value, using default.") + klog.ErrorS(err, "Unable to parse maximum PD volumes value, using default") } else if parsedMaxVols <= 0 { - klog.Error("Maximum PD volumes must be a positive value, using default") + klog.ErrorS(errors.New("maximum PD volumes is negative"), "Unable to parse maximum PD volumes value, using default") } else { return parsedMaxVols }