Skip to content

Commit c6a8cf0

Browse files
vsphere namespace test fix
1 parent 4b3b30f commit c6a8cf0

File tree

9 files changed

+53
-37
lines changed

9 files changed

+53
-37
lines changed

cmd/vsphere/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
1717
"github.com/openshift/library-go/pkg/operator/events"
1818
capimachine "github.com/openshift/machine-api-operator/pkg/controller/machine"
19+
"github.com/openshift/machine-api-operator/pkg/controller/vsphere"
1920
machine "github.com/openshift/machine-api-operator/pkg/controller/vsphere"
2021
machinesetcontroller "github.com/openshift/machine-api-operator/pkg/controller/vsphere/machineset"
2122
"github.com/openshift/machine-api-operator/pkg/metrics"
@@ -183,6 +184,7 @@ func main() {
183184
EventRecorder: mgr.GetEventRecorderFor("vspherecontroller"),
184185
TaskIDCache: taskIDCache,
185186
StaticIPFeatureGateEnabled: staticIPFeatureGateEnabled,
187+
OpenshiftConfigNamespace: vsphere.OpenshiftConfigNamespace,
186188
})
187189

188190
if err := configv1.Install(mgr.GetScheme()); err != nil {

pkg/controller/vsphere/actuator.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Actuator struct {
3232
eventRecorder record.EventRecorder
3333
TaskIDCache map[string]string
3434
StaticIPFeatureGateEnabled bool
35+
openshiftConfigNamespace string
3536
}
3637

3738
// ActuatorParams holds parameter information for Actuator.
@@ -41,6 +42,7 @@ type ActuatorParams struct {
4142
EventRecorder record.EventRecorder
4243
TaskIDCache map[string]string
4344
StaticIPFeatureGateEnabled bool
45+
OpenshiftConfigNamespace string
4446
}
4547

4648
// NewActuator returns an actuator.
@@ -51,6 +53,7 @@ func NewActuator(params ActuatorParams) *Actuator {
5153
eventRecorder: params.EventRecorder,
5254
TaskIDCache: params.TaskIDCache,
5355
StaticIPFeatureGateEnabled: params.StaticIPFeatureGateEnabled,
56+
openshiftConfigNamespace: params.OpenshiftConfigNamespace,
5457
}
5558
}
5659

@@ -74,6 +77,7 @@ func (a *Actuator) Create(ctx context.Context, machine *machinev1.Machine) error
7477
machine: machine,
7578
apiReader: a.apiReader,
7679
StaticIPFeatureGateEnabled: a.StaticIPFeatureGateEnabled,
80+
openshiftConfigNameSpace: a.openshiftConfigNamespace,
7781
})
7882
if err != nil {
7983
fmtErr := fmt.Errorf(scopeFailFmt, machine.GetName(), err)
@@ -117,6 +121,7 @@ func (a *Actuator) Exists(ctx context.Context, machine *machinev1.Machine) (bool
117121
machine: machine,
118122
apiReader: a.apiReader,
119123
StaticIPFeatureGateEnabled: a.StaticIPFeatureGateEnabled,
124+
openshiftConfigNameSpace: a.openshiftConfigNamespace,
120125
})
121126
if err != nil {
122127
return false, fmt.Errorf(scopeFailFmt, machine.GetName(), err)
@@ -135,6 +140,7 @@ func (a *Actuator) Update(ctx context.Context, machine *machinev1.Machine) error
135140
machine: machine,
136141
apiReader: a.apiReader,
137142
StaticIPFeatureGateEnabled: a.StaticIPFeatureGateEnabled,
143+
openshiftConfigNameSpace: a.openshiftConfigNamespace,
138144
})
139145
if err != nil {
140146
fmtErr := fmt.Errorf(scopeFailFmt, machine.GetName(), err)
@@ -176,6 +182,7 @@ func (a *Actuator) Delete(ctx context.Context, machine *machinev1.Machine) error
176182
machine: machine,
177183
apiReader: a.apiReader,
178184
StaticIPFeatureGateEnabled: a.StaticIPFeatureGateEnabled,
185+
openshiftConfigNameSpace: a.openshiftConfigNamespace,
179186
})
180187
if err != nil {
181188
fmtErr := fmt.Errorf(scopeFailFmt, machine.GetName(), err)

pkg/controller/vsphere/actuator_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ func TestMachineEvents(t *testing.T) {
9393

9494
k8sClient := mgr.GetClient()
9595
eventRecorder := mgr.GetEventRecorderFor("vspherecontroller")
96-
9796
configNamespace := &corev1.Namespace{
9897
ObjectMeta: metav1.ObjectMeta{
99-
Name: openshiftConfigNamespace,
98+
Name: openshiftConfigNamespaceForTest,
10099
},
101100
}
102101
g.Expect(k8sClient.Create(context.Background(), configNamespace)).To(Succeed())
@@ -136,7 +135,7 @@ func TestMachineEvents(t *testing.T) {
136135
configMap := &corev1.ConfigMap{
137136
ObjectMeta: metav1.ObjectMeta{
138137
Name: "testname",
139-
Namespace: openshiftConfigNamespace,
138+
Namespace: openshiftConfigNamespaceForTest,
140139
},
141140
Data: map[string]string{
142141
"testkey": testConfig,
@@ -365,10 +364,11 @@ func TestMachineEvents(t *testing.T) {
365364

366365
taskIDCache := make(map[string]string)
367366
params := ActuatorParams{
368-
Client: k8sClient,
369-
EventRecorder: eventRecorder,
370-
APIReader: k8sClient,
371-
TaskIDCache: taskIDCache,
367+
Client: k8sClient,
368+
EventRecorder: eventRecorder,
369+
APIReader: k8sClient,
370+
TaskIDCache: taskIDCache,
371+
OpenshiftConfigNamespace: openshiftConfigNamespaceForTest,
372372
}
373373

374374
actuator := NewActuator(params)

pkg/controller/vsphere/machine_scope.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type machineScopeParams struct {
2626
apiReader runtimeclient.Reader
2727
machine *machinev1.Machine
2828
StaticIPFeatureGateEnabled bool
29+
openshiftConfigNameSpace string
2930
}
3031

3132
// machineScope defines a scope defined around a machine and its cluster.
@@ -54,7 +55,7 @@ func newMachineScope(params machineScopeParams) (*machineScope, error) {
5455
return nil, fmt.Errorf("%v: machine scope require a context", params.machine.GetName())
5556
}
5657

57-
vSphereConfig, err := getVSphereConfig(params.apiReader)
58+
vSphereConfig, err := getVSphereConfig(params.apiReader, params.openshiftConfigNameSpace)
5859
if err != nil {
5960
klog.Errorf("Failed to fetch vSphere config: %v", err)
6061
}

pkg/controller/vsphere/machine_scope_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,9 @@ func TestPatchMachine(t *testing.T) {
313313

314314
// fake objects for newMachineScope()
315315
password, _ := server.URL.User.Password()
316-
317316
configNamespace := &corev1.Namespace{
318317
ObjectMeta: metav1.ObjectMeta{
319-
Name: openshiftConfigNamespace,
318+
Name: openshiftConfigNamespaceForTest,
320319
},
321320
}
322321
g.Expect(k8sClient.Create(ctx, configNamespace)).To(Succeed())
@@ -356,7 +355,7 @@ func TestPatchMachine(t *testing.T) {
356355
configMap := &corev1.ConfigMap{
357356
ObjectMeta: metav1.ObjectMeta{
358357
Name: "testname",
359-
Namespace: openshiftConfigNamespace,
358+
Namespace: openshiftConfigNamespaceForTest,
360359
},
361360
Data: map[string]string{
362361
"testkey": testConfig,
@@ -507,10 +506,11 @@ func TestPatchMachine(t *testing.T) {
507506
gs.Eventually(getMachine, timeout).Should(Succeed())
508507

509508
machineScope, err := newMachineScope(machineScopeParams{
510-
client: k8sClient,
511-
machine: machine,
512-
apiReader: k8sClient,
513-
Context: ctx,
509+
client: k8sClient,
510+
machine: machine,
511+
apiReader: k8sClient,
512+
Context: ctx,
513+
openshiftConfigNameSpace: openshiftConfigNamespaceForTest,
514514
})
515515

516516
gs.Expect(err).ToNot(HaveOccurred())

pkg/controller/vsphere/reconciler_test.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ func TestDelete(t *testing.T) {
17781778
configMap := &corev1.ConfigMap{
17791779
ObjectMeta: metav1.ObjectMeta{
17801780
Name: "testName",
1781-
Namespace: openshiftConfigNamespace,
1781+
Namespace: openshiftConfigNamespaceForTest,
17821782
},
17831783
Data: map[string]string{
17841784
"testKey": testConfig,
@@ -1954,10 +1954,11 @@ func TestDelete(t *testing.T) {
19541954
simParams.infra,
19551955
tc.node(t)).Build()
19561956
machineScope, err := newMachineScope(machineScopeParams{
1957-
client: client,
1958-
Context: context.Background(),
1959-
machine: tc.machine(t, simParams.host),
1960-
apiReader: client,
1957+
client: client,
1958+
Context: context.Background(),
1959+
machine: tc.machine(t, simParams.host),
1960+
apiReader: client,
1961+
openshiftConfigNameSpace: openshiftConfigNamespaceForTest,
19611962
})
19621963
if err != nil {
19631964
t.Fatal(err)
@@ -2233,10 +2234,11 @@ func TestDelete(t *testing.T) {
22332234
tc.node(t),
22342235
).Build()
22352236
mScope, err := newMachineScope(machineScopeParams{
2236-
client: cl,
2237-
Context: context.Background(),
2238-
machine: tc.machine(t, simParams.host),
2239-
apiReader: cl,
2237+
client: cl,
2238+
Context: context.Background(),
2239+
machine: tc.machine(t, simParams.host),
2240+
apiReader: cl,
2241+
openshiftConfigNameSpace: openshiftConfigNamespaceForTest,
22402242
})
22412243
g.Expect(err).NotTo(HaveOccurred())
22422244

@@ -2285,7 +2287,7 @@ func TestCreate(t *testing.T) {
22852287
configMap := &corev1.ConfigMap{
22862288
ObjectMeta: metav1.ObjectMeta{
22872289
Name: "testName",
2288-
Namespace: openshiftConfigNamespace,
2290+
Namespace: openshiftConfigNamespaceForTest,
22892291
},
22902292
Data: map[string]string{
22912293
"testKey": testConfig,
@@ -2611,6 +2613,7 @@ func TestCreate(t *testing.T) {
26112613
machine: machine,
26122614
apiReader: client,
26132615
StaticIPFeatureGateEnabled: tc.staticIPFeatureGateEnabled,
2616+
openshiftConfigNameSpace: openshiftConfigNamespaceForTest,
26142617
})
26152618
if err != nil {
26162619
t.Fatal(err)
@@ -2699,7 +2702,7 @@ func TestUpdate(t *testing.T) {
26992702
configMap := &corev1.ConfigMap{
27002703
ObjectMeta: metav1.ObjectMeta{
27012704
Name: "testName",
2702-
Namespace: openshiftConfigNamespace,
2705+
Namespace: openshiftConfigNamespaceForTest,
27032706
},
27042707
Data: map[string]string{
27052708
"testKey": testConfig,
@@ -2808,7 +2811,8 @@ func TestUpdate(t *testing.T) {
28082811
},
28092812
},
28102813
},
2811-
apiReader: client,
2814+
apiReader: client,
2815+
openshiftConfigNameSpace: openshiftConfigNamespaceForTest,
28122816
})
28132817
if err != nil {
28142818
t.Fatal(err)

pkg/controller/vsphere/util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
const (
2424
globalInfrastuctureName = "cluster"
25-
openshiftConfigNamespace = "openshift-config-1"
25+
OpenshiftConfigNamespace = "openshift-config"
2626
)
2727

2828
// vSphereConfig is a copy of the Kubernetes vSphere cloud provider config type
@@ -69,7 +69,7 @@ func getInfrastructure(c runtimeclient.Reader) (*configv1.Infrastructure, error)
6969
return infra, nil
7070
}
7171

72-
func getVSphereConfig(c runtimeclient.Reader) (*vSphereConfig, error) {
72+
func getVSphereConfig(c runtimeclient.Reader, configNamespace string) (*vSphereConfig, error) {
7373
if c == nil {
7474
return nil, errors.New("no API reader -- will not fetch vSphere config")
7575
}
@@ -90,7 +90,7 @@ func getVSphereConfig(c runtimeclient.Reader) (*vSphereConfig, error) {
9090
cm := &corev1.ConfigMap{}
9191
cmName := runtimeclient.ObjectKey{
9292
Name: infra.Spec.CloudConfig.Name,
93-
Namespace: openshiftConfigNamespace,
93+
Namespace: configNamespace,
9494
}
9595

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

pkg/controller/vsphere/util_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import (
1212
)
1313

1414
const (
15-
testRegion = "testRegion"
16-
testZone = "testZone"
17-
testPort = "443"
18-
testInsecureFlag = "1"
19-
testConfigFmt = `
15+
testRegion = "testRegion"
16+
testZone = "testZone"
17+
testPort = "443"
18+
testInsecureFlag = "1"
19+
openshiftConfigNamespaceForTest = "openshift-config-test"
20+
testConfigFmt = `
2021
[Labels]
2122
zone = "testZone"
2223
region = "testRegion"
@@ -31,7 +32,7 @@ func TestGetVSphereConfig(t *testing.T) {
3132
configMap := &corev1.ConfigMap{
3233
ObjectMeta: metav1.ObjectMeta{
3334
Name: "testName",
34-
Namespace: openshiftConfigNamespace,
35+
Namespace: openshiftConfigNamespaceForTest,
3536
},
3637
Data: map[string]string{
3738
"testKey": testConfig,
@@ -52,7 +53,7 @@ func TestGetVSphereConfig(t *testing.T) {
5253

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

55-
vSphereConfig, err := getVSphereConfig(client)
56+
vSphereConfig, err := getVSphereConfig(client, openshiftConfigNamespaceForTest)
5657
if err != nil {
5758
t.Fatal(err)
5859
}

pkg/webhooks/machine_webhook.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,7 @@ func validateGVK(gvk schema.GroupVersionKind, platform osconfigv1.PlatformType)
20692069
}
20702070
}
20712071

2072+
// validateAzureCapacityReservationGroupID validate capacity reservation group ID.
20722073
func validateAzureCapacityReservationGroupID(capacityReservationGroupID string) error {
20732074
id := strings.TrimPrefix(capacityReservationGroupID, azureProviderIDPrefix)
20742075
err := parseAzureResourceID(id)

0 commit comments

Comments
 (0)