From 1bf104ff0f790764e03f6422bca93bfeb9335d7e Mon Sep 17 00:00:00 2001 From: Ellis Tarn Date: Fri, 20 Aug 2021 11:20:42 -0700 Subject: [PATCH] Migrates to upstream well known labels --- cmd/controller/main.go | 1 + pkg/apis/provisioning/v1alpha3/provisioner.go | 13 ++++--------- .../v1alpha3/provisioner_validation.go | 8 ++++---- .../v1alpha3/provisioner_validation_test.go | 8 ++++---- pkg/controllers/allocation/suite_test.go | 18 +++++++++--------- pkg/controllers/node/liveness.go | 2 +- 6 files changed, 23 insertions(+), 27 deletions(-) diff --git a/cmd/controller/main.go b/cmd/controller/main.go index cd4aac145901..013190f58dd7 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -64,6 +64,7 @@ func main() { flag.Parse() config := controllerruntime.GetConfigOrDie() + config.QPS = 200 clientSet := kubernetes.NewForConfigOrDie(config) // 1. Setup logger and watch for changes to log level diff --git a/pkg/apis/provisioning/v1alpha3/provisioner.go b/pkg/apis/provisioning/v1alpha3/provisioner.go index 38a4593ece0f..0686c7e9d924 100644 --- a/pkg/apis/provisioning/v1alpha3/provisioner.go +++ b/pkg/apis/provisioning/v1alpha3/provisioner.go @@ -113,11 +113,6 @@ var ( ) var ( - // Well known labels - ArchitectureLabelKey = "kubernetes.io/arch" - OperatingSystemLabelKey = "kubernetes.io/os" - ZoneLabelKey = "topology.kubernetes.io/zone" - InstanceTypeLabelKey = "node.kubernetes.io/instance-type" // Reserved labels ProvisionerNameLabelKey = SchemeGroupVersion.Group + "/provisioner-name" // Reserved taints @@ -169,7 +164,7 @@ func (c *Constraints) WithOverrides(pod *v1.Pod) *Constraints { func (c *Constraints) getZones(pod *v1.Pod) []string { // Pod may override zone - if zone, ok := pod.Spec.NodeSelector[ZoneLabelKey]; ok { + if zone, ok := pod.Spec.NodeSelector[v1.LabelTopologyZone]; ok { return []string{zone} } // Default to provisioner constraints @@ -182,7 +177,7 @@ func (c *Constraints) getZones(pod *v1.Pod) []string { func (c *Constraints) getInstanceTypes(pod *v1.Pod) []string { // Pod may override instance type - if instanceType, ok := pod.Spec.NodeSelector[InstanceTypeLabelKey]; ok { + if instanceType, ok := pod.Spec.NodeSelector[v1.LabelInstanceTypeStable]; ok { return []string{instanceType} } // Default to provisioner constraints @@ -195,7 +190,7 @@ func (c *Constraints) getInstanceTypes(pod *v1.Pod) []string { func (c *Constraints) getArchitecture(pod *v1.Pod) *string { // Pod may override arch - if architecture, ok := pod.Spec.NodeSelector[ArchitectureLabelKey]; ok { + if architecture, ok := pod.Spec.NodeSelector[v1.LabelArchStable]; ok { return &architecture } // Use constraints if defined @@ -208,7 +203,7 @@ func (c *Constraints) getArchitecture(pod *v1.Pod) *string { func (c *Constraints) getOperatingSystem(pod *v1.Pod) *string { // Pod may override os - if operatingSystem, ok := pod.Spec.NodeSelector[OperatingSystemLabelKey]; ok { + if operatingSystem, ok := pod.Spec.NodeSelector[v1.LabelOSStable]; ok { return &operatingSystem } // Use constraints if defined diff --git a/pkg/apis/provisioning/v1alpha3/provisioner_validation.go b/pkg/apis/provisioning/v1alpha3/provisioner_validation.go index 155392a41930..4c724d38baf5 100644 --- a/pkg/apis/provisioning/v1alpha3/provisioner_validation.go +++ b/pkg/apis/provisioning/v1alpha3/provisioner_validation.go @@ -30,12 +30,12 @@ import ( var ( // RestrictedLabels prevent usage of specific labels. Instead, use top level provisioner fields (e.g. zone) RestrictedLabels = []string{ - ArchitectureLabelKey, - OperatingSystemLabelKey, + v1.LabelArchStable, + v1.LabelOSStable, + v1.LabelTopologyZone, + v1.LabelInstanceTypeStable, ProvisionerNameLabelKey, EmptinessTimestampAnnotationKey, - ZoneLabelKey, - InstanceTypeLabelKey, } // The following fields are injected by Cloud Providers diff --git a/pkg/apis/provisioning/v1alpha3/provisioner_validation_test.go b/pkg/apis/provisioning/v1alpha3/provisioner_validation_test.go index 70d69cab747c..ce1057ca0bd5 100644 --- a/pkg/apis/provisioning/v1alpha3/provisioner_validation_test.go +++ b/pkg/apis/provisioning/v1alpha3/provisioner_validation_test.go @@ -104,11 +104,11 @@ var _ = Describe("Validation", func() { }) It("should fail for restricted labels", func() { for _, label := range []string{ - ArchitectureLabelKey, - OperatingSystemLabelKey, + v1.LabelArchStable, + v1.LabelOSStable, ProvisionerNameLabelKey, - ZoneLabelKey, - InstanceTypeLabelKey, + v1.LabelTopologyZone, + v1.LabelInstanceTypeStable, } { provisioner.Spec.Labels = map[string]string{label: randomdata.SillyName()} Expect(provisioner.Validate(ctx)).ToNot(Succeed()) diff --git a/pkg/controllers/allocation/suite_test.go b/pkg/controllers/allocation/suite_test.go index d63727df3502..f790bc9fd1f0 100644 --- a/pkg/controllers/allocation/suite_test.go +++ b/pkg/controllers/allocation/suite_test.go @@ -114,7 +114,7 @@ var _ = Describe("Allocation", func() { provisioner.Spec.Zones = []string{"test-zone-1"} ExpectCreated(env.Client, provisioner) pods := ExpectProvisioningSucceeded(ctx, env.Client, controller, provisioner, - test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1alpha3.ZoneLabelKey: "test-zone-2"}}), + test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1.LabelTopologyZone: "test-zone-2"}}), ) // Assertions node := ExpectNodeExists(env.Client, pods[0].Spec.NodeName) @@ -138,13 +138,13 @@ var _ = Describe("Allocation", func() { // Constrained by provisioner test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1alpha3.ProvisionerNameLabelKey: provisioner.Name}}), // Constrained by zone - test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1alpha3.ZoneLabelKey: "test-zone-1"}}), + test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1.LabelTopologyZone: "test-zone-1"}}), // Constrained by instanceType - test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1alpha3.InstanceTypeLabelKey: "default-instance-type"}}), + test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1.LabelInstanceTypeStable: "default-instance-type"}}), // Constrained by architecture - test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1alpha3.ArchitectureLabelKey: "arm64"}}), + test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1.LabelArchStable: "arm64"}}), // Constrained by operating system - test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1alpha3.OperatingSystemLabelKey: "windows"}}), + test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1.LabelOSStable: "windows"}}), // Constrained by arbitrary label test.PendingPod(test.PodOptions{NodeSelector: map[string]string{"foo": "bar"}}), } @@ -152,13 +152,13 @@ var _ = Describe("Allocation", func() { // Ignored, matches another provisioner test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1alpha3.ProvisionerNameLabelKey: "unknown"}}), // Ignored, invalid zone - test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1alpha3.ZoneLabelKey: "unknown"}}), + test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1.LabelTopologyZone: "unknown"}}), // Ignored, invalid instance type - test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1alpha3.InstanceTypeLabelKey: "unknown"}}), + test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1.LabelInstanceTypeStable: "unknown"}}), // Ignored, invalid architecture - test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1alpha3.ArchitectureLabelKey: "unknown"}}), + test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1.LabelArchStable: "unknown"}}), // Ignored, invalid operating system - test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1alpha3.OperatingSystemLabelKey: "unknown"}}), + test.PendingPod(test.PodOptions{NodeSelector: map[string]string{v1.LabelOSStable: "unknown"}}), } ExpectCreated(env.Client, provisioner) ExpectCreatedWithStatus(env.Client, schedulable...) diff --git a/pkg/controllers/node/liveness.go b/pkg/controllers/node/liveness.go index 3fe25e376ec1..9ce4d6bfe53e 100644 --- a/pkg/controllers/node/liveness.go +++ b/pkg/controllers/node/liveness.go @@ -39,7 +39,7 @@ func (r *Liveness) Reconcile(ctx context.Context, provisioner *v1alpha3.Provisio if Now().Sub(n.GetCreationTimestamp().Time) < LivenessTimeout { return reconcile.Result{}, nil } - condition := node.GetCondition(n.Status.Conditions, v1.NodeReady); + condition := node.GetCondition(n.Status.Conditions, v1.NodeReady) // If the reason is "", then the condition has never been set. We expect // either the kubelet to set this reason, or the kcm's // node-livecycle-controller to set the status to NodeStatusNeverUpdated if