Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,12 @@ spec:
labels of the machine template of the MachineSet.
format: int32
type: integer
selector:
description: |-
selector is the string form of the label selector in spec.selector, in the same format as
autoscaling/v1 Scale status.selector (for example "app=myapp,role=worker"). It is written by the
machineset controller so the scale subresource's labelSelectorPath resolves for HPAs and other autoscalers.
type: string
observedGeneration:
description: observedGeneration reflects the generation of the most
recently observed MachineSet.
Expand Down Expand Up @@ -708,7 +714,7 @@ spec:
storage: true
subresources:
scale:
labelSelectorPath: .status.labelSelector
labelSelectorPath: .status.selector
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,12 @@ spec:
labels of the machine template of the MachineSet.
format: int32
type: integer
selector:
description: |-
selector is the string form of the label selector in spec.selector, in the same format as
autoscaling/v1 Scale status.selector (for example "app=myapp,role=worker"). It is written by the
machineset controller so the scale subresource's labelSelectorPath resolves for HPAs and other autoscalers.
type: string
observedGeneration:
description: observedGeneration reflects the generation of the most
recently observed MachineSet.
Expand All @@ -635,7 +641,7 @@ spec:
storage: true
subresources:
scale:
labelSelectorPath: .status.labelSelector
labelSelectorPath: .status.selector
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,12 @@ spec:
labels of the machine template of the MachineSet.
format: int32
type: integer
selector:
description: |-
selector is the string form of the label selector in spec.selector, in the same format as
autoscaling/v1 Scale status.selector (for example "app=myapp,role=worker"). It is written by the
machineset controller so the scale subresource's labelSelectorPath resolves for HPAs and other autoscalers.
type: string
observedGeneration:
description: observedGeneration reflects the generation of the most
recently observed MachineSet.
Expand Down Expand Up @@ -708,7 +714,7 @@ spec:
storage: true
subresources:
scale:
labelSelectorPath: .status.labelSelector
labelSelectorPath: .status.selector
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,12 @@ spec:
labels of the machine template of the MachineSet.
format: int32
type: integer
selector:
description: |-
selector is the string form of the label selector in spec.selector, in the same format as
autoscaling/v1 Scale status.selector (for example "app=myapp,role=worker"). It is written by the
machineset controller so the scale subresource's labelSelectorPath resolves for HPAs and other autoscalers.
type: string
observedGeneration:
description: observedGeneration reflects the generation of the most
recently observed MachineSet.
Expand All @@ -635,7 +641,7 @@ spec:
storage: true
subresources:
scale:
labelSelectorPath: .status.labelSelector
labelSelectorPath: .status.selector
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,12 @@ spec:
labels of the machine template of the MachineSet.
format: int32
type: integer
selector:
description: |-
selector is the string form of the label selector in spec.selector, in the same format as
autoscaling/v1 Scale status.selector (for example "app=myapp,role=worker"). It is written by the
machineset controller so the scale subresource's labelSelectorPath resolves for HPAs and other autoscalers.
type: string
observedGeneration:
description: observedGeneration reflects the generation of the most
recently observed MachineSet.
Expand Down Expand Up @@ -708,7 +714,7 @@ spec:
storage: true
subresources:
scale:
labelSelectorPath: .status.labelSelector
labelSelectorPath: .status.selector
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
status: {}
2 changes: 2 additions & 0 deletions pkg/controller/machineset/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (c *ReconcileMachineSet) calculateStatus(ms *machinev1.MachineSet, filtered
newStatus.FullyLabeledReplicas = int32(fullyLabeledReplicasCount)
newStatus.ReadyReplicas = int32(readyReplicasCount)
newStatus.AvailableReplicas = int32(availableReplicasCount)
newStatus.Selector = metav1.FormatLabelSelector(&ms.Spec.Selector)
return newStatus
}

Expand All @@ -80,6 +81,7 @@ func updateMachineSetStatus(c client.Client, ms *machinev1.MachineSet, newStatus
ms.Status.FullyLabeledReplicas == newStatus.FullyLabeledReplicas &&
ms.Status.ReadyReplicas == newStatus.ReadyReplicas &&
ms.Status.AvailableReplicas == newStatus.AvailableReplicas &&
ms.Status.Selector == newStatus.Selector &&
reflect.DeepEqual(ms.Status.Conditions, newStatus.Conditions) &&
ms.Generation == ms.Status.ObservedGeneration {
return ms, nil
Expand Down
67 changes: 67 additions & 0 deletions pkg/controller/machineset/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright 2018 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 machineset

import (
"testing"

machinev1 "github.com/openshift/api/machine/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// TestMachineSetStatusSelectorMatchesScaleSubresource verifies that status.selector is the
// serialized label selector string expected by the CRD scale subresource (labelSelectorPath
// -> .status.selector), which the apiserver maps to autoscaling/v1 Scale status.selector.
func TestMachineSetStatusSelectorMatchesScaleSubresource(t *testing.T) {
tests := []struct {
name string
spec metav1.LabelSelector
}{
{
name: "matchLabels",
spec: metav1.LabelSelector{
MatchLabels: map[string]string{
"machine.openshift.io/cluster-api-cluster": "cluster-id",
"machine.openshift.io/cluster-api-machineset": "workers",
},
},
},
{
name: "matchExpressions",
spec: metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{Key: "role", Operator: metav1.LabelSelectorOpIn, Values: []string{"worker", "infra"}},
},
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
ms := &machinev1.MachineSet{
Spec: machinev1.MachineSetSpec{
Selector: tc.spec,
},
}
r := &ReconcileMachineSet{}
got := r.calculateStatus(ms, nil).Selector
want := metav1.FormatLabelSelector(&ms.Spec.Selector)
if got != want {
t.Fatalf("status.selector = %q, want %q (must match Scale status.selector for HPA)", got, want)
}
})
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.