From 54c0f8b677d0b82258f3b4df6d325cc3c0011661 Mon Sep 17 00:00:00 2001 From: wawa0210 Date: Wed, 13 May 2020 08:22:43 +0800 Subject: [PATCH] Remove the 'beta' version of the node label (os and arch types) --- .../node_lifecycle_controller.go | 20 ++--- .../node_lifecycle_controller_test.go | 16 ++-- pkg/kubelet/BUILD | 2 - pkg/kubelet/apis/well_known_labels.go | 8 +- pkg/kubelet/kubelet_node_status.go | 11 +-- pkg/kubelet/kubelet_node_status_test.go | 83 ++++++++----------- 6 files changed, 57 insertions(+), 83 deletions(-) diff --git a/pkg/controller/nodelifecycle/node_lifecycle_controller.go b/pkg/controller/nodelifecycle/node_lifecycle_controller.go index 42e85fc480f..b3dbe5c559b 100644 --- a/pkg/controller/nodelifecycle/node_lifecycle_controller.go +++ b/pkg/controller/nodelifecycle/node_lifecycle_controller.go @@ -145,21 +145,17 @@ var labelReconcileInfo = []struct { ensureSecondaryExists bool }{ { - // Reconcile the beta and the stable OS label using the beta label as - // the source of truth. - // TODO(#73084): switch to using the stable label as the source of - // truth in v1.18. - primaryKey: kubeletapis.LabelOS, - secondaryKey: v1.LabelOSStable, + // Reconcile the beta and the stable OS label using the stable label as the source of truth. + // TODO(#89477): no earlier than 1.22: drop the beta labels if they differ from the GA labels + primaryKey: v1.LabelOSStable, + secondaryKey: kubeletapis.LabelOS, ensureSecondaryExists: true, }, { - // Reconcile the beta and the stable arch label using the beta label as - // the source of truth. - // TODO(#73084): switch to using the stable label as the source of - // truth in v1.18. - primaryKey: kubeletapis.LabelArch, - secondaryKey: v1.LabelArchStable, + // Reconcile the beta and the stable arch label using the stable label as the source of truth. + // TODO(#89477): no earlier than 1.22: drop the beta labels if they differ from the GA labels + primaryKey: v1.LabelArchStable, + secondaryKey: kubeletapis.LabelArch, ensureSecondaryExists: true, }, } diff --git a/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go b/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go index 890a16e0f97..cd44946c4cb 100644 --- a/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go +++ b/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go @@ -3288,14 +3288,14 @@ func TestReconcileNodeLabels(t *testing.T) { }, }, { - Name: "Create OS/arch stable labels when they don't exist", + Name: "Create OS/arch beta labels when they don't exist", Node: &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: "node0", CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), Labels: map[string]string{ - kubeletapis.LabelOS: "linux", - kubeletapis.LabelArch: "amd64", + v1.LabelOSStable: "linux", + v1.LabelArchStable: "amd64", }, }, }, @@ -3307,16 +3307,16 @@ func TestReconcileNodeLabels(t *testing.T) { }, }, { - Name: "Reconcile OS/arch stable labels to match beta labels", + Name: "Reconcile OS/arch beta labels to match stable labels", Node: &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: "node0", CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), Labels: map[string]string{ - kubeletapis.LabelOS: "linux", - kubeletapis.LabelArch: "amd64", - v1.LabelOSStable: "windows", - v1.LabelArchStable: "arm", + kubeletapis.LabelOS: "windows", + kubeletapis.LabelArch: "arm", + v1.LabelOSStable: "linux", + v1.LabelArchStable: "amd64", }, }, }, diff --git a/pkg/kubelet/BUILD b/pkg/kubelet/BUILD index 84a6190319e..1117573150b 100644 --- a/pkg/kubelet/BUILD +++ b/pkg/kubelet/BUILD @@ -43,7 +43,6 @@ go_library( "//pkg/apis/core/v1/helper/qos:go_default_library", "//pkg/features:go_default_library", "//pkg/fieldpath:go_default_library", - "//pkg/kubelet/apis:go_default_library", "//pkg/kubelet/apis/config:go_default_library", "//pkg/kubelet/apis/podresources:go_default_library", "//pkg/kubelet/cadvisor:go_default_library", @@ -184,7 +183,6 @@ go_test( deps = [ "//pkg/apis/core/install:go_default_library", "//pkg/features:go_default_library", - "//pkg/kubelet/apis:go_default_library", "//pkg/kubelet/cadvisor/testing:go_default_library", "//pkg/kubelet/cm:go_default_library", "//pkg/kubelet/config:go_default_library", diff --git a/pkg/kubelet/apis/well_known_labels.go b/pkg/kubelet/apis/well_known_labels.go index a38ad13b545..1472f692080 100644 --- a/pkg/kubelet/apis/well_known_labels.go +++ b/pkg/kubelet/apis/well_known_labels.go @@ -25,14 +25,10 @@ import ( const ( // LabelOS is a label to indicate the operating system of the node. - // The OS labels are promoted to GA in 1.14. kubelet applies both beta - // and GA labels to ensure backward compatibility. - // TODO: stop applying the beta OS labels in Kubernetes 1.18. + // The OS labels are promoted to GA in 1.14. kubelet applies GA labels and stop applying the beta OS labels in Kubernetes 1.19. LabelOS = "beta.kubernetes.io/os" // LabelArch is a label to indicate the architecture of the node. - // The Arch labels are promoted to GA in 1.14. kubelet applies both beta - // and GA labels to ensure backward compatibility. - // TODO: stop applying the beta Arch labels in Kubernetes 1.18. + // The Arch labels are promoted to GA in 1.14. kubelet applies GA labels and stop applying the beta Arch labels in Kubernetes 1.19. LabelArch = "beta.kubernetes.io/arch" ) diff --git a/pkg/kubelet/kubelet_node_status.go b/pkg/kubelet/kubelet_node_status.go index 5f10945b041..72df42557c7 100644 --- a/pkg/kubelet/kubelet_node_status.go +++ b/pkg/kubelet/kubelet_node_status.go @@ -36,7 +36,6 @@ import ( "k8s.io/klog" k8s_api_v1 "k8s.io/kubernetes/pkg/apis/core/v1" v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper" - kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis" "k8s.io/kubernetes/pkg/kubelet/events" "k8s.io/kubernetes/pkg/kubelet/nodestatus" "k8s.io/kubernetes/pkg/kubelet/util" @@ -157,8 +156,6 @@ func (kl *Kubelet) updateDefaultLabels(initialNode, existingNode *v1.Node) bool v1.LabelOSStable, v1.LabelArchStable, v1.LabelWindowsBuild, - kubeletapis.LabelOS, - kubeletapis.LabelArch, } needsUpdate := false @@ -221,11 +218,9 @@ func (kl *Kubelet) initialNode(ctx context.Context) (*v1.Node, error) { ObjectMeta: metav1.ObjectMeta{ Name: string(kl.nodeName), Labels: map[string]string{ - v1.LabelHostname: kl.hostname, - v1.LabelOSStable: goruntime.GOOS, - v1.LabelArchStable: goruntime.GOARCH, - kubeletapis.LabelOS: goruntime.GOOS, - kubeletapis.LabelArch: goruntime.GOARCH, + v1.LabelHostname: kl.hostname, + v1.LabelOSStable: goruntime.GOOS, + v1.LabelArchStable: goruntime.GOARCH, }, }, Spec: v1.NodeSpec{ diff --git a/pkg/kubelet/kubelet_node_status_test.go b/pkg/kubelet/kubelet_node_status_test.go index 491d207371d..0316ce6bb42 100644 --- a/pkg/kubelet/kubelet_node_status_test.go +++ b/pkg/kubelet/kubelet_node_status_test.go @@ -49,7 +49,6 @@ import ( "k8s.io/client-go/rest" core "k8s.io/client-go/testing" "k8s.io/component-base/version" - kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis" cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing" "k8s.io/kubernetes/pkg/kubelet/cm" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" @@ -1131,11 +1130,9 @@ func TestRegisterWithApiServer(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: testKubeletHostname, Labels: map[string]string{ - v1.LabelHostname: testKubeletHostname, - v1.LabelOSStable: goruntime.GOOS, - v1.LabelArchStable: goruntime.GOARCH, - kubeletapis.LabelOS: goruntime.GOOS, - kubeletapis.LabelArch: goruntime.GOARCH, + v1.LabelHostname: testKubeletHostname, + v1.LabelOSStable: goruntime.GOOS, + v1.LabelArchStable: goruntime.GOARCH, }, }, }, nil @@ -1178,11 +1175,9 @@ func TestTryRegisterWithApiServer(t *testing.T) { node := &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - v1.LabelHostname: testKubeletHostname, - v1.LabelOSStable: goruntime.GOOS, - v1.LabelArchStable: goruntime.GOARCH, - kubeletapis.LabelOS: goruntime.GOOS, - kubeletapis.LabelArch: goruntime.GOARCH, + v1.LabelHostname: testKubeletHostname, + v1.LabelOSStable: goruntime.GOOS, + v1.LabelArchStable: goruntime.GOARCH, }, }, } @@ -1417,8 +1412,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", }, }, }, @@ -1436,8 +1431,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", }, }, { @@ -1452,8 +1447,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", }, }, }, @@ -1467,8 +1462,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "old-zone-region", v1.LabelInstanceTypeStable: "old-instance-type", v1.LabelInstanceType: "old-instance-type", - kubeletapis.LabelOS: "old-os", - kubeletapis.LabelArch: "old-arch", + v1.LabelOSStable: "old-os", + v1.LabelArchStable: "old-arch", }, }, }, @@ -1481,8 +1476,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", }, }, { @@ -1497,8 +1492,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", }, }, }, @@ -1512,8 +1507,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", "please-persist": "foo", }, }, @@ -1527,8 +1522,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", "please-persist": "foo", }, }, @@ -1549,8 +1544,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", "please-persist": "foo", }, }, @@ -1564,8 +1559,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", "please-persist": "foo", }, }, @@ -1581,8 +1576,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", }, }, }, @@ -1596,8 +1591,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", }, }, }, @@ -1610,8 +1605,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", }, }, { @@ -1626,8 +1621,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", }, }, }, @@ -1643,8 +1638,8 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", + v1.LabelOSStable: "new-os", + v1.LabelArchStable: "new-arch", }, }, { @@ -1659,8 +1654,6 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", v1.LabelOSStable: "new-os", v1.LabelArchStable: "new-arch", }, @@ -1673,8 +1666,6 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneFailureDomain: "new-zone-failure-domain", v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", }, }, }, @@ -1687,8 +1678,6 @@ func TestUpdateDefaultLabels(t *testing.T) { v1.LabelZoneRegion: "new-zone-region", v1.LabelInstanceTypeStable: "new-instance-type", v1.LabelInstanceType: "new-instance-type", - kubeletapis.LabelOS: "new-os", - kubeletapis.LabelArch: "new-arch", v1.LabelOSStable: "new-os", v1.LabelArchStable: "new-arch", },