mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
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
This commit is contained in:
parent
99ad414127
commit
3c87c43cef
@ -65,7 +65,8 @@ type Option func(runtime.Registry) error
|
|||||||
func NewSchedulerCommand(registryOptions ...Option) *cobra.Command {
|
func NewSchedulerCommand(registryOptions ...Option) *cobra.Command {
|
||||||
opts, err := options.NewOptions()
|
opts, err := options.NewOptions()
|
||||||
if err != nil {
|
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{
|
cmd := &cobra.Command{
|
||||||
@ -196,7 +197,7 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched *
|
|||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
// We were asked to terminate. Exit 0.
|
// We were asked to terminate. Exit 0.
|
||||||
klog.Info("Requested to terminate. Exiting.")
|
klog.InfoS("Requested to terminate, exiting")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
default:
|
default:
|
||||||
// We lost the lock.
|
// We lost the lock.
|
||||||
|
@ -51,7 +51,7 @@ func New(plArgs runtime.Object, handle framework.Handle) (framework.Plugin, erro
|
|||||||
return nil, err
|
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{
|
return &NodeLabel{
|
||||||
handle: handle,
|
handle: handle,
|
||||||
args: args,
|
args: args,
|
||||||
|
@ -96,7 +96,7 @@ func (pl *CSILimits) Filter(ctx context.Context, _ *framework.CycleState, pod *v
|
|||||||
csiNode, err := pl.csiNodeLister.Get(node.Name)
|
csiNode, err := pl.csiNodeLister.Get(node.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: return the error once CSINode is created by default (2 releases)
|
// 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)
|
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
|
// If the PVC is invalid, we don't count the volume because
|
||||||
// there's no guarantee that it belongs to the running predicate.
|
// 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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,17 +215,15 @@ func (pl *CSILimits) filterAttachableVolumes(
|
|||||||
// the information of the CSI driver that the plugin has been migrated to.
|
// 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) {
|
func (pl *CSILimits) getCSIDriverInfo(csiNode *storagev1.CSINode, pvc *v1.PersistentVolumeClaim) (string, string) {
|
||||||
pvName := pvc.Spec.VolumeName
|
pvName := pvc.Spec.VolumeName
|
||||||
namespace := pvc.Namespace
|
|
||||||
pvcName := pvc.Name
|
|
||||||
|
|
||||||
if pvName == "" {
|
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)
|
return pl.getCSIDriverInfoFromSC(csiNode, pvc)
|
||||||
}
|
}
|
||||||
|
|
||||||
pv, err := pl.pvLister.Get(pvName)
|
pv, err := pl.pvLister.Get(pvName)
|
||||||
if err != nil {
|
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
|
// 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.
|
// or PVC was prebound to a PVC that hasn't been created yet.
|
||||||
// fallback to using StorageClass for volume counting
|
// 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
|
// 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.
|
// and hence it must be bound before scheduling. So it is safe to not count it.
|
||||||
if scName == "" {
|
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 "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
|
|
||||||
storageClass, err := pl.scLister.Get(scName)
|
storageClass, err := pl.scLister.Get(scName)
|
||||||
if err != nil {
|
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 "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ func newNonCSILimits(
|
|||||||
filter = cinderVolumeFilter
|
filter = cinderVolumeFilter
|
||||||
volumeLimitKey = v1.ResourceName(volumeutil.CinderVolumeLimitKey)
|
volumeLimitKey = v1.ResourceName(volumeutil.CinderVolumeLimitKey)
|
||||||
default:
|
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
|
return nil
|
||||||
}
|
}
|
||||||
pl := &nonCSILimits{
|
pl := &nonCSILimits{
|
||||||
@ -242,7 +242,7 @@ func (pl *nonCSILimits) Filter(ctx context.Context, _ *framework.CycleState, pod
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// we don't fail here because the CSINode object is only necessary
|
// we don't fail here because the CSINode object is only necessary
|
||||||
// for determining whether the migration is enabled or not
|
// 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
|
// If the PVC is invalid, we don't count the volume because
|
||||||
// there's no guarantee that it belongs to the running predicate.
|
// 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
|
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
|
// original PV where it was bound to, so we count the volume if
|
||||||
// it belongs to the running predicate.
|
// it belongs to the running predicate.
|
||||||
if pl.matchProvisioner(pvc) {
|
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)
|
filteredVolumes.Insert(pvID)
|
||||||
}
|
}
|
||||||
continue
|
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,
|
// If the PV is invalid and PVC belongs to the running predicate,
|
||||||
// log the error and count the PV towards the PV limit.
|
// log the error and count the PV towards the PV limit.
|
||||||
if pl.matchProvisioner(pvc) {
|
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)
|
filteredVolumes.Insert(pvID)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@ -386,9 +386,9 @@ func (pl *nonCSILimits) matchProvisioner(pvc *v1.PersistentVolumeClaim) bool {
|
|||||||
func getMaxVolLimitFromEnv() int {
|
func getMaxVolLimitFromEnv() int {
|
||||||
if rawMaxVols := os.Getenv(KubeMaxPDVols); rawMaxVols != "" {
|
if rawMaxVols := os.Getenv(KubeMaxPDVols); rawMaxVols != "" {
|
||||||
if parsedMaxVols, err := strconv.Atoi(rawMaxVols); err != nil {
|
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 {
|
} 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 {
|
} else {
|
||||||
return parsedMaxVols
|
return parsedMaxVols
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user