-
Notifications
You must be signed in to change notification settings - Fork 243
OCPBUGS-82584: Populate status label selector for scale subresource. #1490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| Copyright 2026 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 ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
| machinev1 "github.com/openshift/api/machine/v1beta1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/kubernetes/scheme" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| ) | ||
|
|
||
| // TestMachineSetStatusLabelSelectorMatchesScaleSubresource verifies that status.labelSelector is the | ||
| // serialized label selector string expected by the CRD scale subresource (labelSelectorPath | ||
| // -> .status.labelSelector), which the apiserver maps to autoscaling/v1 Scale status.selector. | ||
| func TestMachineSetStatusLabelSelectorMatchesScaleSubresource(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) { | ||
| g := NewWithT(t) | ||
|
|
||
| ms := &machinev1.MachineSet{ | ||
| Spec: machinev1.MachineSetSpec{ | ||
| Selector: tc.spec, | ||
| }, | ||
| } | ||
|
|
||
| got := (&ReconcileMachineSet{}).calculateStatus(ms, nil).LabelSelector | ||
| want := metav1.FormatLabelSelector(&ms.Spec.Selector) | ||
| g.Expect(got).To(Equal(want), "status.labelSelector must match Scale status.selector for HPA") | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestUpdateMachineSetStatusUpdatesLabelSelectorWithoutReplicaChanges(t *testing.T) { | ||
| t.Helper() | ||
|
|
||
| g := NewWithT(t) | ||
|
|
||
| ms := &machinev1.MachineSet{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "machineset-test", | ||
| Namespace: "openshift-machine-api", | ||
| Generation: 1, | ||
| }, | ||
| Status: machinev1.MachineSetStatus{ | ||
| Replicas: 0, | ||
| FullyLabeledReplicas: 0, | ||
| ReadyReplicas: 0, | ||
| AvailableReplicas: 0, | ||
| ObservedGeneration: 1, | ||
| }, | ||
| } | ||
|
|
||
| cl := fake.NewClientBuilder(). | ||
| WithScheme(scheme.Scheme). | ||
| WithRuntimeObjects(ms.DeepCopy()). | ||
| WithStatusSubresource(&machinev1.MachineSet{}). | ||
| Build() | ||
|
|
||
| current := &machinev1.MachineSet{} | ||
| key := client.ObjectKeyFromObject(ms) | ||
| g.Expect(cl.Get(context.Background(), key, current)).To(Succeed(), "failed to fetch machineset") | ||
|
|
||
| newStatus := current.Status | ||
| newStatus.LabelSelector = "machine.openshift.io/cluster-api-cluster=test-cluster" | ||
|
|
||
| updated, err := updateMachineSetStatus(cl, current, newStatus) | ||
| g.Expect(err).NotTo(HaveOccurred(), "failed to update machineset status") | ||
| g.Expect(updated.Status.LabelSelector).To(Equal(newStatus.LabelSelector)) | ||
|
|
||
| stored := &machinev1.MachineSet{} | ||
| g.Expect(cl.Get(context.Background(), key, stored)).To(Succeed(), "failed to refetch machineset") | ||
| g.Expect(stored.Status.LabelSelector).To(Equal(newStatus.LabelSelector)) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: openshift/machine-api-operator
Length of output: 296
Remove local
replaceoverrides before merge.Lines 9-10 contain local path overrides that make builds non-reproducible outside your workspace. The required pseudo-versions are already defined on lines 25-26 (v0.0.0-20260326111139-30c2ef7a272e and v0.0.0-20260317180604-743f664b82d1); simply remove the
replacedirectives to use them.Proposed go.mod adjustment
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This'll need to be addressed before we can merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nrb, agreed. The fix is straightforward — the two local path overrides should be removed from thereplaceblock before merging, since the pinned pseudo-versions are already present in therequireblock:These local overrides are useful during development when iterating against local checkouts of
openshift/apiandopenshift/client-go, but they'll cause builds to fail for anyone who doesn't have those directories checked out at../apiand../client-gorelative to this repo. Once the upstream API PR merges and therequireversions are updated accordingly, these lines should be dropped.