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

if err := configv1.Install(mgr.GetScheme()); err != nil {
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 @@ -472,13 +472,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 @@ -1930,7 +1930,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 @@ -1982,23 +1981,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 @@ -2009,7 +1996,6 @@ func TestDelete(t *testing.T) {
}

return &vCenterSimConfig{
infra: infra,
secret: secret,
configMap: configMap,
host: host,
Expand Down Expand Up @@ -2161,7 +2147,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 @@ -2441,7 +2426,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 @@ -2511,23 +2495,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 @@ -2870,7 +2842,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 @@ -3007,23 +2978,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 @@ -3093,8 +3052,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 @@ -80,6 +80,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 @@ -167,6 +168,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 @@ -176,7 +178,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