mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-17 12:46:05 +00:00
Use k8s.io/api well-known label constants instead of hardcoded strings (#10279)
* refactor: use k8s.io/api well-known label constants Several well-known Kubernetes label strings were hardcoded across the codebase instead of using the constants already exported by k8s.io/api/core/v1, which is an existing dependency: "kubernetes.io/hostname" -> corev1api.LabelHostname "kubernetes.io/os" -> corev1api.LabelOSStable "topology.kubernetes.io/zone" -> corev1api.LabelTopologyZone The local kube.NodeOSLabel and zoneLabel consts, which duplicated the upstream values verbatim, are now defined in terms of the upstream constants rather than repeating the literal. Both are kept: NodeOSLabel is exported and referenced from four packages alongside NodeOSLinux and NodeOSWindows, which have no upstream equivalent, and zoneLabel sits beside the deprecated-label fallback it is compared against. No functional change - every replacement is a constant with an identical value. Signed-off-by: Harshit saini <harshitsaini1188@gmail.com> * Add changelog for #10279 Signed-off-by: Harshit saini <harshitsaini1188@gmail.com> * Cover the selected-node path in createRestorePod TestCreateRestorePod only exercised selectedNode == "", so the branch that pins the restore pod to a node was never executed. Add a case with a selected node and assert the resulting pod carries the hostname label in its node selector. Signed-off-by: Harshit saini <harshitsaini1188@gmail.com> * Also use constants for the arch and deprecated zone labels Extends the same replacement to the two remaining well-known labels raised on the issue: "kubernetes.io/arch" -> corev1api.LabelArchStable "failure-domain.beta.kubernetes.io/zone" -> corev1api.LabelFailureDomainBetaZone zoneLabelDeprecated in item_backupper.go was the last local const still repeating a literal that upstream already exports, so the zone pair now reads consistently against k8s.io/api. The deprecation note upstream applies to the label itself, not the constant; Velero reads that label deliberately as the fallback for PVs created before the topology labels existed. Signed-off-by: Harshit saini <harshitsaini1188@gmail.com> --------- Signed-off-by: Harshit saini <harshitsaini1188@gmail.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Use the well-known label constants exported by k8s.io/api/core/v1 instead of hardcoded label strings for kubernetes.io/hostname, kubernetes.io/os, kubernetes.io/arch, topology.kubernetes.io/zone and failure-domain.beta.kubernetes.io/zone
|
||||
@@ -131,7 +131,7 @@ func TestExecute(t *testing.T) {
|
||||
vsClass: builder.ForVolumeSnapshotClass("testVSClass").Driver("hostpath").ObjectMeta(builder.WithLabels(velerov1api.VolumeSnapshotClassSelectorLabel, "")).Result(),
|
||||
extraObjects: []runtime.Object{
|
||||
&corev1api.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "linux-node", Labels: map[string]string{"kubernetes.io/os": "linux"}},
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "linux-node", Labels: map[string]string{corev1api.LabelOSStable: "linux"}},
|
||||
},
|
||||
&appsv1api.DaemonSet{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: "velero", Name: "node-agent"},
|
||||
@@ -186,7 +186,7 @@ func TestExecute(t *testing.T) {
|
||||
vsClass: builder.ForVolumeSnapshotClass("tescVSClass").Driver("hostpath").ObjectMeta(builder.WithLabels(velerov1api.VolumeSnapshotClassSelectorLabel, "")).Result(),
|
||||
extraObjects: []runtime.Object{
|
||||
&corev1api.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "linux-node", Labels: map[string]string{"kubernetes.io/os": "linux"}},
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "linux-node", Labels: map[string]string{corev1api.LabelOSStable: "linux"}},
|
||||
},
|
||||
&appsv1api.DaemonSet{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: "velero", Name: "node-agent"},
|
||||
|
||||
@@ -2991,7 +2991,7 @@ func TestBackupWithSnapshots(t *testing.T) {
|
||||
},
|
||||
apiResources: []*test.APIResource{
|
||||
test.PVs(
|
||||
builder.ForPersistentVolume("pv-1").ObjectMeta(builder.WithLabels("failure-domain.beta.kubernetes.io/zone", "zone-1")).Result(),
|
||||
builder.ForPersistentVolume("pv-1").ObjectMeta(builder.WithLabels(corev1api.LabelFailureDomainBetaZone, "zone-1")).Result(),
|
||||
),
|
||||
},
|
||||
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
|
||||
@@ -3028,7 +3028,7 @@ func TestBackupWithSnapshots(t *testing.T) {
|
||||
},
|
||||
apiResources: []*test.APIResource{
|
||||
test.PVs(
|
||||
builder.ForPersistentVolume("pv-1").ObjectMeta(builder.WithLabels("topology.kubernetes.io/zone", "zone-1")).Result(),
|
||||
builder.ForPersistentVolume("pv-1").ObjectMeta(builder.WithLabels(corev1api.LabelTopologyZone, "zone-1")).Result(),
|
||||
),
|
||||
},
|
||||
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
|
||||
@@ -3065,7 +3065,7 @@ func TestBackupWithSnapshots(t *testing.T) {
|
||||
},
|
||||
apiResources: []*test.APIResource{
|
||||
test.PVs(
|
||||
builder.ForPersistentVolume("pv-1").ObjectMeta(builder.WithLabelsMap(map[string]string{"failure-domain.beta.kubernetes.io/zone": "zone-1-deprecated", "topology.kubernetes.io/zone": "zone-1-ga"})).Result(),
|
||||
builder.ForPersistentVolume("pv-1").ObjectMeta(builder.WithLabelsMap(map[string]string{corev1api.LabelFailureDomainBetaZone: "zone-1-deprecated", corev1api.LabelTopologyZone: "zone-1-ga"})).Result(),
|
||||
),
|
||||
},
|
||||
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
|
||||
|
||||
@@ -569,9 +569,9 @@ func (ib *itemBackupper) executeActions(
|
||||
// zoneLabel is the label that stores availability-zone info
|
||||
// on PVs
|
||||
const (
|
||||
zoneLabelDeprecated = "failure-domain.beta.kubernetes.io/zone"
|
||||
zoneLabelDeprecated = corev1api.LabelFailureDomainBetaZone
|
||||
// this is reused for nodeAffinity requirements
|
||||
zoneLabel = "topology.kubernetes.io/zone"
|
||||
zoneLabel = corev1api.LabelTopologyZone
|
||||
|
||||
awsEbsCsiZoneKey = "topology.ebs.csi.aws.com/zone"
|
||||
azureCsiZoneKey = "topology.disk.csi.azure.com/zone"
|
||||
|
||||
@@ -676,11 +676,11 @@ func TestNeedPatch(t *testing.T) {
|
||||
{
|
||||
name: "same label key different values",
|
||||
newPV: builder.ForPersistentVolume("pv1").
|
||||
ObjectMeta(builder.WithLabels("topology.kubernetes.io/zone", "us-west-2a")).
|
||||
ObjectMeta(builder.WithLabels(corev1api.LabelTopologyZone, "us-west-2a")).
|
||||
ReclaimPolicy(corev1api.PersistentVolumeReclaimDelete).Result(),
|
||||
pvInfo: &volume.PVInfo{
|
||||
ReclaimPolicy: string(corev1api.PersistentVolumeReclaimDelete),
|
||||
Labels: map[string]string{"topology.kubernetes.io/zone": "us-east-1a"},
|
||||
Labels: map[string]string{corev1api.LabelTopologyZone: "us-east-1a"},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
|
||||
@@ -811,7 +811,7 @@ func (e *csiSnapshotExposer) createBackupPod(
|
||||
}
|
||||
|
||||
affinity.NodeSelector.MatchExpressions = append(affinity.NodeSelector.MatchExpressions, metav1.LabelSelectorRequirement{
|
||||
Key: "kubernetes.io/hostname",
|
||||
Key: corev1api.LabelHostname,
|
||||
Values: intoleratableNodes,
|
||||
Operator: metav1.LabelSelectorOpNotIn,
|
||||
})
|
||||
@@ -839,7 +839,7 @@ func (e *csiSnapshotExposer) createBackupPod(
|
||||
TopologySpreadConstraints: []corev1api.TopologySpreadConstraint{
|
||||
{
|
||||
MaxSkew: 1,
|
||||
TopologyKey: "kubernetes.io/hostname",
|
||||
TopologyKey: corev1api.LabelHostname,
|
||||
WhenUnsatisfiable: corev1api.ScheduleAnyway,
|
||||
LabelSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
|
||||
@@ -492,7 +492,7 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -530,7 +530,7 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -570,7 +570,7 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -615,7 +615,7 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -661,7 +661,7 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -705,7 +705,7 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -732,7 +732,7 @@ func TestExpose(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"Linux"},
|
||||
},
|
||||
@@ -757,12 +757,12 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpIn,
|
||||
Values: []string{"Linux"},
|
||||
},
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -794,7 +794,7 @@ func TestExpose(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/arch",
|
||||
Key: corev1api.LabelArchStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"amd64"},
|
||||
},
|
||||
@@ -820,12 +820,12 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/arch",
|
||||
Key: corev1api.LabelArchStable,
|
||||
Operator: corev1api.NodeSelectorOpIn,
|
||||
Values: []string{"amd64"},
|
||||
},
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -870,7 +870,7 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -923,7 +923,7 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -968,7 +968,7 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -1015,12 +1015,12 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
{
|
||||
Key: "kubernetes.io/hostname",
|
||||
Key: corev1api.LabelHostname,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"node-1", "node-2"},
|
||||
},
|
||||
@@ -1061,7 +1061,7 @@ func TestExpose(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
|
||||
@@ -620,7 +620,7 @@ func (e *genericRestoreExposer) createRestorePod(
|
||||
nodeSelector := map[string]string{}
|
||||
if selectedNode != "" {
|
||||
affinity = nil
|
||||
nodeSelector["kubernetes.io/hostname"] = selectedNode
|
||||
nodeSelector[corev1api.LabelHostname] = selectedNode
|
||||
e.log.Infof("Selected node for restore pod. Ignore affinity from the node-agent config.")
|
||||
}
|
||||
|
||||
@@ -762,7 +762,7 @@ func (e *genericRestoreExposer) createRestorePod(
|
||||
TopologySpreadConstraints: []corev1api.TopologySpreadConstraint{
|
||||
{
|
||||
MaxSkew: 1,
|
||||
TopologyKey: "kubernetes.io/hostname",
|
||||
TopologyKey: corev1api.LabelHostname,
|
||||
WhenUnsatisfiable: corev1api.ScheduleAnyway,
|
||||
LabelSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
|
||||
@@ -1330,12 +1330,13 @@ func TestCreateRestorePod(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
kubeClientObj []runtime.Object
|
||||
selectedNode string
|
||||
affinity *kube.LoadAffinity
|
||||
nodeOS string
|
||||
expectedPod *corev1api.Pod
|
||||
name string
|
||||
kubeClientObj []runtime.Object
|
||||
selectedNode string
|
||||
affinity *kube.LoadAffinity
|
||||
nodeOS string
|
||||
expectedPod *corev1api.Pod
|
||||
expectedNodeSelector map[string]string
|
||||
}{
|
||||
{
|
||||
name: "linux",
|
||||
@@ -1345,7 +1346,7 @@ func TestCreateRestorePod(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"linux"},
|
||||
},
|
||||
@@ -1363,7 +1364,7 @@ func TestCreateRestorePod(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"windows"},
|
||||
},
|
||||
@@ -1373,6 +1374,29 @@ func TestCreateRestorePod(t *testing.T) {
|
||||
},
|
||||
nodeOS: "windows",
|
||||
},
|
||||
{
|
||||
// A selected node is pinned through the node selector, and the
|
||||
// affinity from the node-agent config is ignored.
|
||||
name: "selected node",
|
||||
kubeClientObj: []runtime.Object{daemonSet, daemonSetWin, targetPVCObj},
|
||||
selectedNode: "fake-selected-node",
|
||||
affinity: &kube.LoadAffinity{
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"linux"},
|
||||
},
|
||||
},
|
||||
},
|
||||
StorageClass: scName,
|
||||
},
|
||||
nodeOS: "linux",
|
||||
expectedNodeSelector: map[string]string{
|
||||
corev1api.LabelHostname: "fake-selected-node",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -1407,6 +1431,9 @@ func TestCreateRestorePod(t *testing.T) {
|
||||
if test.expectedPod != nil {
|
||||
assert.Equal(t, test.expectedPod, pod)
|
||||
}
|
||||
if test.expectedNodeSelector != nil {
|
||||
assert.Equal(t, test.expectedNodeSelector, pod.Spec.NodeSelector)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1api.DaemonSet
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Values: []string{"windows"},
|
||||
Operator: corev1api.NodeSelectorOpIn,
|
||||
},
|
||||
@@ -280,7 +280,7 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1api.DaemonSet
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Values: []string{"windows"},
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
},
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestDaemonSet(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Values: []string{"windows"},
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
},
|
||||
@@ -107,7 +107,7 @@ func TestDaemonSet(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Values: []string{"windows"},
|
||||
Operator: corev1api.NodeSelectorOpIn,
|
||||
},
|
||||
|
||||
@@ -395,7 +395,7 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1api.Deployme
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Values: []string{"windows"},
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
},
|
||||
|
||||
@@ -120,7 +120,7 @@ func TestDeployment(t *testing.T) {
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Values: []string{"windows"},
|
||||
Operator: corev1api.NodeSelectorOpNotIn,
|
||||
},
|
||||
|
||||
@@ -357,7 +357,7 @@ func createPVBObj(fail bool, withSnapshot bool, index int, uploaderType string)
|
||||
}
|
||||
|
||||
func createNodeObj() *corev1api.Node {
|
||||
return builder.ForNode("fake-node-name").Labels(map[string]string{"kubernetes.io/os": "linux"}).Result()
|
||||
return builder.ForNode("fake-node-name").Labels(map[string]string{corev1api.LabelOSStable: "linux"}).Result()
|
||||
}
|
||||
|
||||
func TestBackupPodVolumes(t *testing.T) {
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
const (
|
||||
NodeOSLinux = "linux"
|
||||
NodeOSWindows = "windows"
|
||||
NodeOSLabel = "kubernetes.io/os"
|
||||
NodeOSLabel = corev1api.LabelOSStable
|
||||
)
|
||||
|
||||
var realNodeOSMap = map[string]string{
|
||||
|
||||
@@ -35,8 +35,8 @@ import (
|
||||
|
||||
func TestIsLinuxNode(t *testing.T) {
|
||||
nodeNoOSLabel := builder.ForNode("fake-node").Result()
|
||||
nodeWindows := builder.ForNode("fake-node").Labels(map[string]string{"kubernetes.io/os": "windows"}).Result()
|
||||
nodeLinux := builder.ForNode("fake-node").Labels(map[string]string{"kubernetes.io/os": "linux"}).Result()
|
||||
nodeWindows := builder.ForNode("fake-node").Labels(map[string]string{corev1api.LabelOSStable: "windows"}).Result()
|
||||
nodeLinux := builder.ForNode("fake-node").Labels(map[string]string{corev1api.LabelOSStable: "linux"}).Result()
|
||||
|
||||
scheme := runtime.NewScheme()
|
||||
corev1api.AddToScheme(scheme)
|
||||
@@ -90,8 +90,8 @@ func TestIsLinuxNode(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithLinuxNode(t *testing.T) {
|
||||
nodeWindows := builder.ForNode("fake-node-1").Labels(map[string]string{"kubernetes.io/os": "windows"}).Result()
|
||||
nodeLinux := builder.ForNode("fake-node-2").Labels(map[string]string{"kubernetes.io/os": "linux"}).Result()
|
||||
nodeWindows := builder.ForNode("fake-node-1").Labels(map[string]string{corev1api.LabelOSStable: "windows"}).Result()
|
||||
nodeLinux := builder.ForNode("fake-node-2").Labels(map[string]string{corev1api.LabelOSStable: "linux"}).Result()
|
||||
|
||||
scheme := runtime.NewScheme()
|
||||
corev1api.AddToScheme(scheme)
|
||||
@@ -135,8 +135,8 @@ func TestWithLinuxNode(t *testing.T) {
|
||||
|
||||
func TestGetNodeOSType(t *testing.T) {
|
||||
nodeNoOSLabel := builder.ForNode("fake-node").Result()
|
||||
nodeWindows := builder.ForNode("fake-node").Labels(map[string]string{"kubernetes.io/os": "windows"}).Result()
|
||||
nodeLinux := builder.ForNode("fake-node").Labels(map[string]string{"kubernetes.io/os": "linux"}).Result()
|
||||
nodeWindows := builder.ForNode("fake-node").Labels(map[string]string{corev1api.LabelOSStable: "windows"}).Result()
|
||||
nodeLinux := builder.ForNode("fake-node").Labels(map[string]string{corev1api.LabelOSStable: "linux"}).Result()
|
||||
scheme := runtime.NewScheme()
|
||||
corev1api.AddToScheme(scheme)
|
||||
tests := []struct {
|
||||
@@ -185,8 +185,8 @@ func TestGetNodeOSType(t *testing.T) {
|
||||
|
||||
func TestHasNodeWithOS(t *testing.T) {
|
||||
nodeNoOSLabel := builder.ForNode("fake-node-1").Result()
|
||||
nodeWindows := builder.ForNode("fake-node-2").Labels(map[string]string{"kubernetes.io/os": "windows"}).Result()
|
||||
nodeLinux := builder.ForNode("fake-node-3").Labels(map[string]string{"kubernetes.io/os": "linux"}).Result()
|
||||
nodeWindows := builder.ForNode("fake-node-2").Labels(map[string]string{corev1api.LabelOSStable: "windows"}).Result()
|
||||
nodeLinux := builder.ForNode("fake-node-3").Labels(map[string]string{corev1api.LabelOSStable: "linux"}).Result()
|
||||
|
||||
scheme := runtime.NewScheme()
|
||||
corev1api.AddToScheme(scheme)
|
||||
|
||||
+11
-11
@@ -1374,7 +1374,7 @@ func TestGetLoadAffinityByStorageClass(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/arch",
|
||||
Key: corev1api.LabelArchStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"amd64"},
|
||||
},
|
||||
@@ -1386,7 +1386,7 @@ func TestGetLoadAffinityByStorageClass(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"Linux"},
|
||||
},
|
||||
@@ -1399,7 +1399,7 @@ func TestGetLoadAffinityByStorageClass(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"Linux"},
|
||||
},
|
||||
@@ -1414,7 +1414,7 @@ func TestGetLoadAffinityByStorageClass(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"Linux"},
|
||||
},
|
||||
@@ -1425,7 +1425,7 @@ func TestGetLoadAffinityByStorageClass(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/arch",
|
||||
Key: corev1api.LabelArchStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"amd64"},
|
||||
},
|
||||
@@ -1436,7 +1436,7 @@ func TestGetLoadAffinityByStorageClass(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"Windows"},
|
||||
},
|
||||
@@ -1449,7 +1449,7 @@ func TestGetLoadAffinityByStorageClass(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"Linux"},
|
||||
},
|
||||
@@ -1475,7 +1475,7 @@ func TestGetLoadAffinityByStorageClass(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"Linux"},
|
||||
},
|
||||
@@ -1487,7 +1487,7 @@ func TestGetLoadAffinityByStorageClass(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/arch",
|
||||
Key: corev1api.LabelArchStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"amd64"},
|
||||
},
|
||||
@@ -1501,7 +1501,7 @@ func TestGetLoadAffinityByStorageClass(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"Linux"},
|
||||
},
|
||||
@@ -1517,7 +1517,7 @@ func TestGetLoadAffinityByStorageClass(t *testing.T) {
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/arch",
|
||||
Key: corev1api.LabelArchStable,
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"amd64"},
|
||||
},
|
||||
|
||||
@@ -1729,7 +1729,7 @@ func TestDiagnosePV(t *testing.T) {
|
||||
func TestGetPVCAttachingNodeOS(t *testing.T) {
|
||||
storageClass := "fake-storage-class"
|
||||
nodeNoOSLabel := builder.ForNode("fake-node").Result()
|
||||
nodeWindows := builder.ForNode("fake-node").Labels(map[string]string{"kubernetes.io/os": "windows"}).Result()
|
||||
nodeWindows := builder.ForNode("fake-node").Labels(map[string]string{corev1api.LabelOSStable: "windows"}).Result()
|
||||
|
||||
pvcObj := &corev1api.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
||||
@@ -62,7 +62,7 @@ var LoadAffinities func() = TestFunc(&NodeAgentConfigTestCase{
|
||||
{
|
||||
NodeSelector: metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"kubernetes.io/arch": "amd64",
|
||||
corev1api.LabelArchStable: "amd64",
|
||||
},
|
||||
},
|
||||
StorageClass: test.StorageClassName2,
|
||||
|
||||
@@ -102,7 +102,7 @@ func NewDeployment(
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Values: []string{common.WorkerOSWindows},
|
||||
Operator: corev1api.NodeSelectorOpIn,
|
||||
},
|
||||
|
||||
@@ -84,7 +84,7 @@ func CreatePod(
|
||||
{
|
||||
MatchExpressions: []corev1api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/os",
|
||||
Key: corev1api.LabelOSStable,
|
||||
Values: []string{common.WorkerOSWindows},
|
||||
Operator: corev1api.NodeSelectorOpIn,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user