Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cmd/vsphere/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func main() {
EventRecorder: mgr.GetEventRecorderFor("vspherecontroller"),
TaskIDCache: taskIDCache,
FeatureGates: defaultMutableGate,
OpenshiftConfigNamespace: vsphere.OpenshiftConfigNamespace,
OpenshiftConfigNamespace: vsphere.OpenshiftConfigManagedNamespace,
})

if err := configv1.Install(mgr.GetScheme()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/onsi/ginkgo/v2 v2.23.4
github.com/onsi/gomega v1.37.0
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250711173707-dc2a20e5a5f8
github.com/openshift/api v0.0.0-20260605122244-2c1c5b39566d
github.com/openshift/api v0.0.0-20260923123119-b32f49f8a709
github.com/openshift/client-go v0.0.0-20250710075018-396b36f983ee
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20250718085303-e712b1ebf374
github.com/openshift/cluster-control-plane-machine-set-operator v0.0.0-20250424110138-1dbf0c7a5d51
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ github.com/openshift-eng/openshift-tests-extension v0.0.0-20250711173707-dc2a20e
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250711173707-dc2a20e5a5f8/go.mod h1:6gkP5f2HL0meusT0Aim8icAspcD1cG055xxBZ9yC68M=
github.com/openshift-sustaining/net v0.50.0-sec.4 h1:jmkVQIRNrS0DAs24K0yLYJHqH5e+svnbXb/ihoTPKRs=
github.com/openshift-sustaining/net v0.50.0-sec.4/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
github.com/openshift/api v0.0.0-20260605122244-2c1c5b39566d h1:Djz4aG2W0ypAHQEtubqbXpxeWGwdCds05w6dfz1GVWk=
github.com/openshift/api v0.0.0-20260605122244-2c1c5b39566d/go.mod h1:SPLf21TYPipzCO67BURkCfK6dcIIxx0oNRVWaOyRcXM=
github.com/openshift/api v0.0.0-20260923123119-b32f49f8a709 h1:4+OKNqHoQ9e4v6LdPFpjpiJXs1UJklvNiPo4O80jO8I=
github.com/openshift/api v0.0.0-20260923123119-b32f49f8a709/go.mod h1:SPLf21TYPipzCO67BURkCfK6dcIIxx0oNRVWaOyRcXM=
github.com/openshift/client-go v0.0.0-20250710075018-396b36f983ee h1:tOtrrxfDEW8hK3eEsHqxsXurq/D6LcINGfprkQC3hqY=
github.com/openshift/client-go v0.0.0-20250710075018-396b36f983ee/go.mod h1:zhRiYyNMk89llof2qEuGPWPD+joQPhCRUc2IK0SB510=
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20250718085303-e712b1ebf374 h1:ldUi0e64kdYJC2+ucB24GRXIXfMnI3NpSkcnalPqBGo=
Expand Down
16 changes: 16 additions & 0 deletions install/0000_30_machine-api-operator_09_rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,29 @@ rules:
resources:
- validatingwebhookconfigurations
- mutatingwebhookconfigurations
- validatingadmissionpolicies
- validatingadmissionpolicybindings
verbs:
- get
- list
- watch
- create
- update

# The machine-api-operator service account must be able to read Machines,
# ControlPlaneMachineSets, and MachineSets so the kube-apiserver can resolve
# them as VAP params when validating Infrastructure/cluster updates.
- apiGroups:
- machine.openshift.io
resources:
- machines
- controlplanemachinesets
- machinesets
verbs:
- get
- list
- watch

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
20 changes: 2 additions & 18 deletions pkg/controller/vsphere/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ func TestMachineEvents(t *testing.T) {
testConfig := fmt.Sprintf(testConfigFmt, port, credentialsSecretName, testNamespaceName)
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "testname",
Name: OpenshiftConfigManagedConfigMap,
Namespace: openshiftConfigNamespaceForTest,
},
Data: map[string]string{
"testkey": testConfig,
OpenshiftConfigManagedCloudConfigKey: testConfig,
},
}

Expand All @@ -150,22 +150,6 @@ func TestMachineEvents(t *testing.T) {
g.Expect(k8sClient.Delete(context.Background(), configMap)).To(Succeed())
}()

infra := &configv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{
Name: globalInfrastuctureName,
},
Spec: configv1.InfrastructureSpec{
CloudConfig: configv1.ConfigMapFileReference{
Name: "testname",
Key: "testkey",
},
},
}
g.Expect(k8sClient.Create(context.Background(), infra)).To(Succeed())
defer func() {
g.Expect(k8sClient.Delete(context.Background(), infra)).To(Succeed())
}()

userDataSecretName := "vsphere-ignition"
userDataSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand Down
21 changes: 2 additions & 19 deletions pkg/controller/vsphere/machine_scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

. "github.com/onsi/gomega"
configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -355,34 +354,18 @@ func TestPatchMachine(t *testing.T) {
testConfig := fmt.Sprintf(testConfigFmt, port, credentialsSecretName, testNamespaceName)
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "testname",
Name: OpenshiftConfigManagedConfigMap,
Namespace: openshiftConfigNamespaceForTest,
},
Data: map[string]string{
"testkey": testConfig,
OpenshiftConfigManagedCloudConfigKey: testConfig,
},
}
g.Expect(k8sClient.Create(ctx, configMap)).To(Succeed())
defer func() {
g.Expect(k8sClient.Delete(ctx, configMap)).To(Succeed())
}()

infra := &configv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{
Name: globalInfrastuctureName,
},
Spec: configv1.InfrastructureSpec{
CloudConfig: configv1.ConfigMapFileReference{
Name: "testname",
Key: "testkey",
},
},
}
g.Expect(k8sClient.Create(ctx, infra)).To(Succeed())
defer func() {
g.Expect(k8sClient.Delete(ctx, infra)).To(Succeed())
}()

failedPhase := "Failed"

providerStatus := &machinev1.VSphereMachineProviderStatus{}
Expand Down
56 changes: 7 additions & 49 deletions pkg/controller/vsphere/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,6 @@ func TestConvertUUIDToProviderID(t *testing.T) {

func TestDelete(t *testing.T) {
type vCenterSimConfig struct {
infra *configv1.Infrastructure
secret *corev1.Secret
configMap *corev1.ConfigMap
featureGate *configv1.FeatureGate
Expand Down Expand Up @@ -2000,23 +1999,11 @@ func TestDelete(t *testing.T) {
testConfig := fmt.Sprintf(testConfigFmt, port, credentialsSecretName, ns)
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "testName",
Name: OpenshiftConfigManagedConfigMap,
Namespace: openshiftConfigNamespaceForTest,
},
Data: map[string]string{
"testKey": testConfig,
},
}

infra := &configv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{
Name: globalInfrastuctureName,
},
Spec: configv1.InfrastructureSpec{
CloudConfig: configv1.ConfigMapFileReference{
Name: "testName",
Key: "testKey",
},
OpenshiftConfigManagedCloudConfigKey: testConfig,
},
}

Expand All @@ -2027,7 +2014,6 @@ func TestDelete(t *testing.T) {
}

return &vCenterSimConfig{
infra: infra,
secret: secret,
configMap: configMap,
host: host,
Expand Down Expand Up @@ -2179,7 +2165,6 @@ func TestDelete(t *testing.T) {
simParams.secret,
tc.machine(t, simParams.host),
simParams.configMap,
simParams.infra,
tc.node(t)).Build()
machineScope, err := newMachineScope(machineScopeParams{
client: client,
Expand Down Expand Up @@ -2459,7 +2444,6 @@ func TestDelete(t *testing.T) {
simParams.secret,
tc.machine(t, simParams.host),
simParams.configMap,
simParams.infra,
tc.node(t),
).Build()
mScope, err := newMachineScope(machineScopeParams{
Expand Down Expand Up @@ -2529,23 +2513,11 @@ func TestCreate(t *testing.T) {
testConfig := fmt.Sprintf(testConfigFmt, port, credentialsSecretName, namespace)
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "testName",
Name: OpenshiftConfigManagedConfigMap,
Namespace: openshiftConfigNamespaceForTest,
},
Data: map[string]string{
"testKey": testConfig,
},
}

infra := &configv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{
Name: globalInfrastuctureName,
},
Spec: configv1.InfrastructureSpec{
CloudConfig: configv1.ConfigMapFileReference{
Name: "testName",
Key: "testKey",
},
OpenshiftConfigManagedCloudConfigKey: testConfig,
},
}

Expand Down Expand Up @@ -2888,7 +2860,6 @@ func TestCreate(t *testing.T) {
builder := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(
credentialsSecret,
configMap,
infra,
userDataSecret,
machine)
if tc.ipAddressClaim != nil {
Expand Down Expand Up @@ -3025,23 +2996,11 @@ func TestUpdate(t *testing.T) {
testConfig := fmt.Sprintf(testConfigFmt, port, credentialsSecretName, namespace)
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "testName",
Name: OpenshiftConfigManagedConfigMap,
Namespace: openshiftConfigNamespaceForTest,
},
Data: map[string]string{
"testKey": testConfig,
},
}

infra := &configv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{
Name: globalInfrastuctureName,
},
Spec: configv1.InfrastructureSpec{
CloudConfig: configv1.ConfigMapFileReference{
Name: "testName",
Key: "testKey",
},
OpenshiftConfigManagedCloudConfigKey: testConfig,
},
}

Expand Down Expand Up @@ -3111,8 +3070,7 @@ func TestUpdate(t *testing.T) {

client := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(
credentialsSecret,
configMap,
infra).Build()
configMap).Build()

rawProviderSpec, err := RawExtensionFromProviderSpec(&tc.providerSpec)
if err != nil {
Expand Down
25 changes: 9 additions & 16 deletions pkg/controller/vsphere/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
)

const (
globalInfrastuctureName = "cluster"
OpenshiftConfigNamespace = "openshift-config"
globalInfrastuctureName = "cluster"
OpenshiftConfigManagedNamespace = "openshift-config-managed"
OpenshiftConfigManagedConfigMap = "kube-cloud-config"
OpenshiftConfigManagedCloudConfigKey = "cloud.conf"
)

// GetInfrastructure retrieves the Infrastructure object from the provided API reader.
Expand All @@ -46,33 +48,24 @@ func getVSphereConfig(c runtimeclient.Reader, configNamespace string) (*vsphere.
return nil, errors.New("no API reader -- will not fetch vSphere config")
}

infra, err := GetInfrastructure(c)
if err != nil {
return nil, err
}

if infra.Spec.CloudConfig.Name == "" {
return nil, fmt.Errorf("cluster infrastructure CloudConfig has empty name")
}

if infra.Spec.CloudConfig.Key == "" {
return nil, fmt.Errorf("cluster infrastructure CloudConfig has empty key")
if configNamespace == "" {
configNamespace = OpenshiftConfigManagedNamespace
}

cm := &corev1.ConfigMap{}
cmName := runtimeclient.ObjectKey{
Name: infra.Spec.CloudConfig.Name,
Name: OpenshiftConfigManagedConfigMap,
Namespace: configNamespace,
}

if err := c.Get(context.Background(), cmName, cm); err != nil {
return nil, err
}

cloudConfig, found := cm.Data[infra.Spec.CloudConfig.Key]
cloudConfig, found := cm.Data[OpenshiftConfigManagedCloudConfigKey]
if !found {
return nil, fmt.Errorf("cloud-config ConfigMap has no %q key",
infra.Spec.CloudConfig.Key,
OpenshiftConfigManagedCloudConfigKey,
)
}

Expand Down
19 changes: 3 additions & 16 deletions pkg/controller/vsphere/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"testing"

configv1 "github.com/openshift/api/config/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -34,27 +33,15 @@ func TestGetVSphereConfig(t *testing.T) {
testConfig := fmt.Sprintf(testConfigFmt, "443", "test", "test-namespace")
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "testName",
Name: OpenshiftConfigManagedConfigMap,
Namespace: openshiftConfigNamespaceForTest,
},
Data: map[string]string{
"testKey": testConfig,
OpenshiftConfigManagedCloudConfigKey: testConfig,
},
}

infra := &configv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{
Name: globalInfrastuctureName,
},
Spec: configv1.InfrastructureSpec{
CloudConfig: configv1.ConfigMapFileReference{
Name: "testName",
Key: "testKey",
},
},
}

client := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(infra, configMap).Build()
client := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(configMap).Build()

vSphereConfig, err := getVSphereConfig(client, openshiftConfigNamespaceForTest)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Operator struct {
mutatingWebhookListerSynced cache.InformerSynced

featureGateAccessor featuregates.FeatureGateAccess
featureGates featuregates.FeatureGate

// queue only ever has one item, but it has nice error handling backoff/retry semantics
queue workqueue.TypedRateLimitingInterface[string]
Expand Down Expand Up @@ -166,6 +167,7 @@ func New(
recorder,
)
featureGateAccessor.SetChangeHandler(func(featureChange featuregates.FeatureChange) {
optr.featureGates = featuregates.NewFeatureGate(featureChange.New.Enabled, featureChange.New.Disabled)
if featureChange.Previous == nil {
// When the initial featuregate is set, the previous version is nil.
// Nothing to do in this case, it's handled by the 1st sync, which only runs after the initial feature set was received.
Expand All @@ -175,7 +177,7 @@ func New(
klog.V(4).InfoS("FeatureGates changed", "enabled", featureChange.New.Enabled, "disabled", featureChange.New.Disabled)
prevDisableMHC := featuregates.NewFeatureGate(featureChange.Previous.Enabled, featureChange.Previous.Disabled).
Enabled(apifeatures.FeatureGateMachineAPIOperatorDisableMachineHealthCheckController)
newDisableMHC := featuregates.NewFeatureGate(featureChange.New.Enabled, featureChange.New.Disabled).
newDisableMHC := optr.featureGates.
Enabled(apifeatures.FeatureGateMachineAPIOperatorDisableMachineHealthCheckController)

if prevDisableMHC != newDisableMHC {
Expand Down
Loading