add deprecated warning for node beta labels in pv/sc/rc/csi storage capacity

- (pv) deprecated label using warning for node affinity
- (storageclass)  deprecated node labels: allowedTopologies.matchLabelExpressions.key
- (CSIStorageCapacity) deprecated node labels
- (RuntimeClass) deprecated node labels
This commit is contained in:
Paco Xu
2022-03-07 15:40:02 +08:00
parent 6605e526b0
commit 3fbfd7eb1b
9 changed files with 173 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
/*
Copyright 2017 The Kubernetes Authors.
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,28 +17,42 @@ limitations under the License.
package persistentvolume
import (
utilfeature "k8s.io/apiserver/pkg/util/feature"
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
nodeapi "k8s.io/kubernetes/pkg/api/node"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/features"
)
// DropDisabledFields removes disabled fields from the pv spec.
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pv spec.
func DropDisabledFields(pvSpec *api.PersistentVolumeSpec, oldPVSpec *api.PersistentVolumeSpec) {
if !utilfeature.DefaultFeatureGate.Enabled(features.CSINodeExpandSecret) && !hasNodeExpansionSecrets(oldPVSpec) {
if pvSpec.CSI != nil {
pvSpec.CSI.NodeExpandSecretRef = nil
func GetWarningsForPersistentVolume(ctx context.Context, pv *api.PersistentVolume) []string {
if pv == nil {
return nil
}
return warningsForPersistentVolumeSpecAndMeta(nil, &pv.Spec, &pv.ObjectMeta)
}
func warningsForPersistentVolumeSpecAndMeta(fieldPath *field.Path, pvSpec *api.PersistentVolumeSpec, meta *metav1.ObjectMeta) []string {
var warnings []string
// use of deprecated node labels in node affinity
for i, k := range pvSpec.NodeAffinity.Required.NodeSelectorTerms {
expressions := k.MatchExpressions
for j, e := range expressions {
if msg, deprecated := nodeapi.DeprecatedNodeLabels[e.Key]; deprecated {
warnings = append(
warnings,
fmt.Sprintf(
"%s: %s is %s",
fieldPath.Child("spec", "NodeAffinity").Child("Required").Child("NodeSelectorTerms").Index(i).Child("MatchExpressions").Index(j).Child("key"),
e.Key,
msg,
),
)
}
}
}
}
func hasNodeExpansionSecrets(oldPVSpec *api.PersistentVolumeSpec) bool {
if oldPVSpec == nil || oldPVSpec.CSI == nil {
return false
}
if oldPVSpec.CSI.NodeExpandSecretRef != nil {
return true
}
return false
return warnings
}