Skip to content

Commit

Permalink
cloudConfig: read cloud Config from openshift-config-managed/kube-clo…
Browse files Browse the repository at this point in the history
…ud-config ConfigMap

cloudConfig is now generated by kube_cloud_config controller for all supported
platforms. Controller generates kube-cloud-config ConfigMap in openshift-config-managed
namespace where cloud.conf key is stored.

Links:
- https://github.com/openshift/enhancements/blob/master/enhancements/installer/aws-custom-region-and-endpoints.md
- openshift/api#599
- openshift/api#621
  • Loading branch information
sinnykumari committed Apr 24, 2020
1 parent 0553938 commit e7455dc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/template/render.go
Expand Up @@ -504,7 +504,7 @@ func cloudConfigFlag(cfg RenderConfig) interface{} {
}
flag := "--cloud-config=/etc/kubernetes/cloud.conf"
switch cfg.Platform {
case platformAzure, platformOpenStack:
case platformAWS, platformAzure, platformBaremetal, platformGCP, platformOpenStack, platformOvirt, platformVSphere:
return flag
default:
return ""
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/template/render_test.go
Expand Up @@ -83,11 +83,22 @@ func TestCloudConfigFlag(t *testing.T) {
platform: "azure",
content: "",
res: "",
}, {
platform: "libvirt",
content: "",
res: "",
}, {
platform: "aws",
content: `
[dummy-config]
option = a
`,
res: "--cloud-config=/etc/kubernetes/cloud.conf",
}, {
platform: "libvirt",
content: `
[dummy-config]
option = a
`,
res: "",
}, {
Expand Down
58 changes: 46 additions & 12 deletions pkg/operator/sync.go
Expand Up @@ -97,6 +97,50 @@ func (optr *Operator) syncAll(syncFuncs []syncFunc) error {
return syncErr.err
}

// Return true if cloud config is required on a platform.
func isCloudConfigRequired(infra *configv1.Infrastructure) bool {
if infra.Spec.CloudConfig.Name != "" {
return true
}
for _, platform := range []configv1.PlatformType{configv1.AzurePlatformType, configv1.BareMetalPlatformType, configv1.GCPPlatformType, configv1.OpenStackPlatformType,
configv1.OvirtPlatformType, configv1.VSpherePlatformType} {
if platform == infra.Status.PlatformStatus.Type {
return true
}
}
return false
}

// Sync cloud config on supported platform from cloud.conf available in openshift-config-managed/kube-cloud-config ConfigMap.
func (optr *Operator) syncCloudConfig(spec *mcfgv1.ControllerConfigSpec, infra *configv1.Infrastructure) error {
if _, err := optr.clusterCmLister.ConfigMaps("openshift-config-managed").Get("kube-cloud-config"); err != nil {
if apierrors.IsNotFound(err) {
if isCloudConfigRequired(infra) {
// Return error only if cloud config is required, otherwise prceeds further.
return fmt.Errorf("%s/%s configmap is required on platform %s but not found: %v",
"openshift-config-managed", "kube-cloud-config", infra.Status.PlatformStatus.Type, err)
}
} else {
return err
}

} else {
// Read cloud.conf from openshift-config-managed/kube-cloud-config ConfigMap.
cc, err := optr.getCloudConfigFromConfigMap("openshift-config-managed", "kube-cloud-config", "cloud.conf")
if err != nil {
return err
}

spec.CloudProviderConfig = cc

caCert, err := optr.getCAsFromConfigMap("openshift-config-managed", "kube-cloud-config", "ca-bundle.pem")
if err == nil {
spec.CloudProviderCAData = caCert
}
}
return nil
}

func (optr *Operator) syncRenderConfig(_ *renderConfig) error {
if err := optr.syncCustomResourceDefinitions(); err != nil {
return err
Expand Down Expand Up @@ -206,18 +250,8 @@ func (optr *Operator) syncRenderConfig(_ *renderConfig) error {
}
spec.AdditionalTrustBundle = trustBundle

// if the cloudConfig is set in infra read the cloud config reference
if infra.Spec.CloudConfig.Name != "" {
cc, err := optr.getCloudConfigFromConfigMap("openshift-config", infra.Spec.CloudConfig.Name, infra.Spec.CloudConfig.Key)
if err != nil {
return err
}
spec.CloudProviderConfig = cc

caCert, err := optr.getCAsFromConfigMap("openshift-config", infra.Spec.CloudConfig.Name, "ca-bundle.pem")
if err == nil {
spec.CloudProviderCAData = caCert
}
if err := optr.syncCloudConfig(spec, infra); err != nil {
return err
}

//TODO: alaypatel07 remove after cluster-etcd-operator deployed via CVO as Managed
Expand Down

0 comments on commit e7455dc

Please sign in to comment.