Skip to content

Commit f940a7c

Browse files
Adds CloudConfigTransformer for Azure
This adds a CloudConfigTransformer for Azure that will set the VMType to 'standard' if unset. See #291, OCPBUGS-25483 and OCPBUGS-20213 for more information.
1 parent d9a1ea3 commit f940a7c

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

pkg/cloud/azure/azure.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ package azure
22

33
import (
44
"embed"
5+
"encoding/json"
56
"fmt"
67

78
"github.com/asaskevich/govalidator"
9+
configv1 "github.com/openshift/api/config/v1"
810
appsv1 "k8s.io/api/apps/v1"
911
"sigs.k8s.io/controller-runtime/pkg/client"
1012

13+
azureconsts "sigs.k8s.io/cloud-provider-azure/pkg/consts"
14+
azure "sigs.k8s.io/cloud-provider-azure/pkg/provider"
15+
1116
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/common"
1217
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
1318
)
@@ -85,3 +90,23 @@ func NewProviderAssets(config config.OperatorConfig) (common.CloudProviderAssets
8590
}
8691
return assets, nil
8792
}
93+
94+
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error) {
95+
var cfg azure.Config
96+
if err := json.Unmarshal([]byte(source), &cfg); err != nil {
97+
return "", fmt.Errorf("failed to unmarshal the cloud.conf: %w", err)
98+
}
99+
100+
// If the virtual machine type is not set we need to make sure it uses the
101+
// "standard" instance type. See OCPBUGS-25483 and OCPBUGS-20213 for more
102+
// information
103+
if cfg.VMType == "" {
104+
cfg.VMType = azureconsts.VMTypeStandard
105+
}
106+
107+
cfgbytes, err := json.Marshal(cfg)
108+
if err != nil {
109+
return "", fmt.Errorf("failed to marshal the cloud.conf: %w", err)
110+
}
111+
return string(cfgbytes), nil
112+
}

pkg/cloud/cloud.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ func GetCloudConfigTransformer(platformStatus *configv1.PlatformStatus) (cloudCo
5353
if azurestack.IsAzureStackHub(platformStatus) {
5454
return azurestack.CloudConfigTransformer, true, nil
5555
}
56-
return nil, true, nil
56+
// We need to use the azure CloudConfigTransformer to fix OCPBUGS-25483
57+
return azure.CloudConfigTransformer, true, nil
5758
case configv1.GCPPlatformType:
5859
return common.NoOpTransformer, false, nil
5960
case configv1.IBMCloudPlatformType:

pkg/controllers/cloud_config_sync_controller_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,22 @@ func makeInfraCloudConfig() *corev1.ConfigMap {
6868
return &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{
6969
Name: infraCloudConfName,
7070
Namespace: OpenshiftConfigNamespace,
71-
}, Data: map[string]string{infraCloudConfKey: "bar"}}
71+
}, Data: map[string]string{infraCloudConfKey: `{
72+
"cloud":"AzurePublicCloud",
73+
"tenantId": "0000000-0000-0000-0000-000000000000",
74+
"subscriptionId": "0000000-0000-0000-0000-000000000000"
75+
}`}}
7276
}
7377

7478
func makeManagedCloudConfig() *corev1.ConfigMap {
7579
return &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{
7680
Name: managedCloudConfigMapName,
7781
Namespace: OpenshiftManagedConfigNamespace,
78-
}, Data: map[string]string{"cloud.conf": "bar"}}
82+
}, Data: map[string]string{"cloud.conf": `{
83+
"cloud":"AzurePublicCloud",
84+
"tenantId": "0000000-0000-0000-0000-000000000000",
85+
"subscriptionId": "0000000-0000-0000-0000-000000000000"
86+
}`}}
7987
}
8088

8189
var _ = Describe("isCloudConfigEqual reconciler method", func() {

0 commit comments

Comments
 (0)