...

Source file src/k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodevolumelimits/utils.go

Documentation: k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodevolumelimits

     1  /*
     2  Copyright 2019 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package nodevolumelimits
    18  
    19  import (
    20  	"strings"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  	storagev1 "k8s.io/api/storage/v1"
    24  	"k8s.io/apimachinery/pkg/util/sets"
    25  	utilfeature "k8s.io/apiserver/pkg/util/feature"
    26  	csilibplugins "k8s.io/csi-translation-lib/plugins"
    27  	v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
    28  	"k8s.io/kubernetes/pkg/features"
    29  	"k8s.io/kubernetes/pkg/scheduler/framework"
    30  )
    31  
    32  // isCSIMigrationOn returns a boolean value indicating whether
    33  // the CSI migration has been enabled for a particular storage plugin.
    34  func isCSIMigrationOn(csiNode *storagev1.CSINode, pluginName string) bool {
    35  	if csiNode == nil || len(pluginName) == 0 {
    36  		return false
    37  	}
    38  
    39  	// In-tree storage to CSI driver migration feature should be enabled,
    40  	// along with the plugin-specific one
    41  	switch pluginName {
    42  	case csilibplugins.AWSEBSInTreePluginName:
    43  		return true
    44  	case csilibplugins.PortworxVolumePluginName:
    45  		if !utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationPortworx) {
    46  			return false
    47  		}
    48  	case csilibplugins.GCEPDInTreePluginName:
    49  		return true
    50  	case csilibplugins.AzureDiskInTreePluginName:
    51  		return true
    52  	case csilibplugins.CinderInTreePluginName:
    53  		return true
    54  	case csilibplugins.RBDVolumePluginName:
    55  		if !utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationRBD) {
    56  			return false
    57  		}
    58  	default:
    59  		return false
    60  	}
    61  
    62  	// The plugin name should be listed in the CSINode object annotation.
    63  	// This indicates that the plugin has been migrated to a CSI driver in the node.
    64  	csiNodeAnn := csiNode.GetAnnotations()
    65  	if csiNodeAnn == nil {
    66  		return false
    67  	}
    68  
    69  	var mpaSet sets.Set[string]
    70  	mpa := csiNodeAnn[v1.MigratedPluginsAnnotationKey]
    71  	if len(mpa) == 0 {
    72  		mpaSet = sets.New[string]()
    73  	} else {
    74  		tok := strings.Split(mpa, ",")
    75  		mpaSet = sets.New(tok...)
    76  	}
    77  
    78  	return mpaSet.Has(pluginName)
    79  }
    80  
    81  // volumeLimits returns volume limits associated with the node.
    82  func volumeLimits(n *framework.NodeInfo) map[v1.ResourceName]int64 {
    83  	volumeLimits := map[v1.ResourceName]int64{}
    84  	for k, v := range n.Allocatable.ScalarResources {
    85  		if v1helper.IsAttachableVolumeResourceName(k) {
    86  			volumeLimits[k] = v
    87  		}
    88  	}
    89  	return volumeLimits
    90  }
    91  

View as plain text