Skip to content

Commit

Permalink
Migrates to upstream well known labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ellistarn committed Aug 20, 2021
1 parent cb274e9 commit 1bf104f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
1 change: 1 addition & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 4 additions & 9 deletions pkg/apis/provisioning/v1alpha3/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/provisioning/v1alpha3/provisioner_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/provisioning/v1alpha3/provisioner_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
18 changes: 9 additions & 9 deletions pkg/controllers/allocation/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -138,27 +138,27 @@ 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"}}),
}
unschedulable := []client.Object{
// 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...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/node/liveness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1bf104f

Please sign in to comment.