Skip to content
Open
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 @@ -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
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