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:
48
pkg/api/node/util.go
Normal file
48
pkg/api/node/util.go
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package persistentvolume
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
"k8s.io/kubernetes/pkg/apis/node"
|
||||
)
|
||||
|
||||
var DeprecatedNodeLabels = map[string]string{
|
||||
`beta.kubernetes.io/arch`: `deprecated since v1.14; use "kubernetes.io/arch" instead`,
|
||||
`beta.kubernetes.io/os`: `deprecated since v1.14; use "kubernetes.io/os" instead`,
|
||||
`failure-domain.beta.kubernetes.io/region`: `deprecated since v1.17; use "topology.kubernetes.io/region" instead`,
|
||||
`failure-domain.beta.kubernetes.io/zone`: `deprecated since v1.17; use "topology.kubernetes.io/zone" instead`,
|
||||
`beta.kubernetes.io/instance-type`: `deprecated since v1.17; use "node.kubernetes.io/instance-type" instead`,
|
||||
}
|
||||
|
||||
func GetWarningsForRuntimeClass(ctx context.Context, rc *node.RuntimeClass) []string {
|
||||
var warnings []string
|
||||
|
||||
if rc != nil {
|
||||
// use of deprecated node labels in scheduling's node affinity
|
||||
for key, _ := range rc.Scheduling.NodeSelector {
|
||||
if msg, deprecated := DeprecatedNodeLabels[key]; deprecated {
|
||||
warnings = append(warnings, fmt.Sprintf("%s: %s", field.NewPath("scheduling", "nodeSelector"), msg))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return warnings
|
||||
}
|
@@ -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
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"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/apis/core/pods"
|
||||
)
|
||||
@@ -60,14 +61,6 @@ func GetWarningsForPodTemplate(ctx context.Context, fieldPath *field.Path, podTe
|
||||
return warningsForPodSpecAndMeta(fieldPath, &podTemplate.Spec, &podTemplate.ObjectMeta, oldSpec, oldMeta)
|
||||
}
|
||||
|
||||
var deprecatedNodeLabels = map[string]string{
|
||||
`beta.kubernetes.io/arch`: `deprecated since v1.14; use "kubernetes.io/arch" instead`,
|
||||
`beta.kubernetes.io/os`: `deprecated since v1.14; use "kubernetes.io/os" instead`,
|
||||
`failure-domain.beta.kubernetes.io/region`: `deprecated since v1.17; use "topology.kubernetes.io/region" instead`,
|
||||
`failure-domain.beta.kubernetes.io/zone`: `deprecated since v1.17; use "topology.kubernetes.io/zone" instead`,
|
||||
`beta.kubernetes.io/instance-type`: `deprecated since v1.17; use "node.kubernetes.io/instance-type" instead`,
|
||||
}
|
||||
|
||||
var deprecatedAnnotations = []struct {
|
||||
key string
|
||||
prefix string
|
||||
@@ -92,7 +85,7 @@ func warningsForPodSpecAndMeta(fieldPath *field.Path, podSpec *api.PodSpec, meta
|
||||
|
||||
// use of deprecated node labels in selectors/affinity/topology
|
||||
for k := range podSpec.NodeSelector {
|
||||
if msg, deprecated := deprecatedNodeLabels[k]; deprecated {
|
||||
if msg, deprecated := nodeapi.DeprecatedNodeLabels[k]; deprecated {
|
||||
warnings = append(warnings, fmt.Sprintf("%s: %s", fieldPath.Child("spec", "nodeSelector").Key(k), msg))
|
||||
}
|
||||
}
|
||||
@@ -101,7 +94,7 @@ func warningsForPodSpecAndMeta(fieldPath *field.Path, podSpec *api.PodSpec, meta
|
||||
if n.RequiredDuringSchedulingIgnoredDuringExecution != nil {
|
||||
for i, t := range n.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms {
|
||||
for j, e := range t.MatchExpressions {
|
||||
if msg, deprecated := deprecatedNodeLabels[e.Key]; deprecated {
|
||||
if msg, deprecated := nodeapi.DeprecatedNodeLabels[e.Key]; deprecated {
|
||||
warnings = append(
|
||||
warnings,
|
||||
fmt.Sprintf(
|
||||
@@ -119,7 +112,7 @@ func warningsForPodSpecAndMeta(fieldPath *field.Path, podSpec *api.PodSpec, meta
|
||||
}
|
||||
for i, t := range n.PreferredDuringSchedulingIgnoredDuringExecution {
|
||||
for j, e := range t.Preference.MatchExpressions {
|
||||
if msg, deprecated := deprecatedNodeLabels[e.Key]; deprecated {
|
||||
if msg, deprecated := nodeapi.DeprecatedNodeLabels[e.Key]; deprecated {
|
||||
warnings = append(
|
||||
warnings,
|
||||
fmt.Sprintf(
|
||||
@@ -137,7 +130,7 @@ func warningsForPodSpecAndMeta(fieldPath *field.Path, podSpec *api.PodSpec, meta
|
||||
}
|
||||
}
|
||||
for i, t := range podSpec.TopologySpreadConstraints {
|
||||
if msg, deprecated := deprecatedNodeLabels[t.TopologyKey]; deprecated {
|
||||
if msg, deprecated := nodeapi.DeprecatedNodeLabels[t.TopologyKey]; deprecated {
|
||||
warnings = append(warnings, fmt.Sprintf(
|
||||
"%s: %s is %s",
|
||||
fieldPath.Child("spec", "topologySpreadConstraints").Index(i).Child("topologyKey"),
|
||||
|
73
pkg/api/storage/util.go
Normal file
73
pkg/api/storage/util.go
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
nodeapi "k8s.io/kubernetes/pkg/api/node"
|
||||
"k8s.io/kubernetes/pkg/apis/storage"
|
||||
)
|
||||
|
||||
func GetWarningsForStorageClass(ctx context.Context, sc *storage.StorageClass) []string {
|
||||
var warnings []string
|
||||
|
||||
if sc != nil {
|
||||
// use of deprecated node labels in allowedTopologies's matchLabelExpressions
|
||||
for i, topo := range sc.AllowedTopologies {
|
||||
for j, expression := range topo.MatchLabelExpressions {
|
||||
if msg, deprecated := nodeapi.DeprecatedNodeLabels[expression.Key]; deprecated {
|
||||
warnings = append(warnings, fmt.Sprintf("%s: %s", field.NewPath("allowedTopologies").Index(i).Child("matchLabelExpressions").Index(j), msg))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return warnings
|
||||
}
|
||||
|
||||
func GetWarningsForCSIStorageCapacity(ctx context.Context, csc *storage.CSIStorageCapacity) []string {
|
||||
var warnings []string
|
||||
|
||||
if csc != nil {
|
||||
// use of deprecated node labels in allowedTopologies's matchLabelExpressions
|
||||
for i, expression := range csc.NodeTopology.MatchExpressions {
|
||||
if msg, deprecated := nodeapi.DeprecatedNodeLabels[expression.Key]; deprecated {
|
||||
warnings = append(
|
||||
warnings,
|
||||
fmt.Sprintf(
|
||||
"%s: %s is %s",
|
||||
field.NewPath("nodeTopology").Child("matchExpressions").Index(i),
|
||||
expression.Key,
|
||||
msg,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// use of deprecated node labels in allowedTopologies's matchLabels
|
||||
for label, _ := range csc.NodeTopology.MatchLabels {
|
||||
if msg, deprecated := nodeapi.DeprecatedNodeLabels[label]; deprecated {
|
||||
warnings = append(warnings, fmt.Sprintf("%s: %s", field.NewPath("nodeTopology").Child("matchLabels").Child(label), msg))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return warnings
|
||||
}
|
Reference in New Issue
Block a user