Skip to content

Commit

Permalink
operator: sync the cloud config in bootstrap and cluster mode
Browse files Browse the repository at this point in the history
The cloud provider config is optionaly present on the bootstrap node based on the user choice or platform.

When the `.spec.cloudConfig` [1] is set, that requires the cloud provider config file to be provided.
In cluster operator uses the same field from `infrastructure.config.openshift.io/cluster` object to selectively fetch the cloud config configmap reference.

[1]: openshift/api#245
  • Loading branch information
abhinavdahiya committed Apr 24, 2019
1 parent 94b84f3 commit 5fb9632
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
27 changes: 15 additions & 12 deletions cmd/machine-config-operator/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,25 @@ var (
}

bootstrapOpts struct {
cloudConfigFile string
configFile string
destinationDir string
etcdCAFile string
etcdImage string
etcdMetricCAFile string
rootCAFile string
kubeCAFile string
pullSecretFile string
configFile string
oscontentImage string
infraConfigFile string
networkConfigFile string
imagesConfigMapFile string
infraConfigFile string
infraImage string
kubeCAFile string
kubeClientAgentImage string
mccImage string
mcsImage string
mcdImage string
etcdImage string
mcsImage string
networkConfigFile string
oscontentImage string
pullSecretFile string
rootCAFile string
setupEtcdEnvImage string
infraImage string
kubeClientAgentImage string
destinationDir string
}
)

Expand Down Expand Up @@ -74,6 +75,7 @@ func init() {
bootstrapCmd.MarkFlagRequired("config-file")
bootstrapCmd.PersistentFlags().StringVar(&bootstrapOpts.infraConfigFile, "infra-config-file", "/assets/manifests/cluster-infrastructure-02-config.yml", "File containing infrastructure.config.openshift.io manifest.")
bootstrapCmd.PersistentFlags().StringVar(&bootstrapOpts.networkConfigFile, "network-config-file", "/assets/manifests/cluster-network-02-config.yml", "File containing network.config.openshift.io manifest.")
bootstrapCmd.PersistentFlags().StringVar(&bootstrapOpts.cloudConfigFile, "cloud-config-file", "", "File containing the config map that contains the cloud config for cloudprovider.")
}

func runBootstrapCmd(cmd *cobra.Command, args []string) {
Expand All @@ -97,6 +99,7 @@ func runBootstrapCmd(cmd *cobra.Command, args []string) {
if err := operator.RenderBootstrap(
bootstrapOpts.configFile,
bootstrapOpts.infraConfigFile, bootstrapOpts.networkConfigFile,
bootstrapOpts.cloudConfigFile,
bootstrapOpts.etcdCAFile, bootstrapOpts.etcdMetricCAFile, bootstrapOpts.rootCAFile, bootstrapOpts.kubeCAFile, bootstrapOpts.pullSecretFile,
imgs,
bootstrapOpts.destinationDir,
Expand Down
19 changes: 19 additions & 0 deletions pkg/operator/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

configv1 "github.com/openshift/api/config/v1"
configscheme "github.com/openshift/client-go/config/clientset/versioned/scheme"
corev1 "k8s.io/api/core/v1"

templatectrl "github.com/openshift/machine-config-operator/pkg/controller/template"
)
Expand All @@ -20,6 +21,7 @@ import (
func RenderBootstrap(
clusterConfigConfigMapFile string,
infraFile, networkFile string,
cloudConfigFile string,
etcdCAFile, etcdMetricCAFile string, rootCAFile string, kubeAPIServerServingCA string, pullSecretFile string,
imgs Images,
destinationDir string,
Expand Down Expand Up @@ -68,6 +70,23 @@ func RenderBootstrap(
return err
}

// if the cloudConfig is set in infra read the cloudConfigFile
if infra.Spec.CloudConfig.Name != "" {
data, err := ioutil.ReadFile(cloudConfigFile)
if err != nil {
return err
}
obji, err := runtime.Decode(configscheme.Codecs.UniversalDecoder(corev1.SchemeGroupVersion), data)
if err != nil {
return err
}
cm, ok := obji.(*corev1.ConfigMap)
if !ok {
return fmt.Errorf("expected *corev1.ConfigMap found %T", obji)
}
spec.CloudProviderConfig = cm.Data[infra.Spec.CloudConfig.Key]
}

bundle := make([]byte, 0)
bundle = append(bundle, filesData[rootCAFile]...)
// Append the kube-ca if given.
Expand Down
21 changes: 21 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ func (optr *Operator) sync(key string) error {
return err
}

// 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
}

spec.EtcdCAData = etcdCA
spec.EtcdMetricCAData = etcdMetricCA
spec.RootCAData = bundle
Expand Down Expand Up @@ -421,6 +430,18 @@ func (optr *Operator) getCAsFromConfigMap(namespace, name, key string) ([]byte,
}
}

func (optr *Operator) getCloudConfigFromConfigMap(namespace, name, key string) (string, error) {
cm, err := optr.clusterCmLister.ConfigMaps(namespace).Get(name)
if err != nil {
return "", err
}
if cc, ok := cm.Data[key]; ok {
return cc, nil
} else {
return "", fmt.Errorf("%s not found in %s/%s", key, namespace, name)
}
}

// getGlobalConfig gets global configuration for the cluster, namely, the Infrastructure and Network types.
// Each type of global configuration is named `cluster` for easy discovery in the cluster.
func (optr *Operator) getGlobalConfig() (*configv1.Infrastructure, *configv1.Network, error) {
Expand Down

0 comments on commit 5fb9632

Please sign in to comment.