Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manifests: add cloudproviderconfig asset #1479

Closed
Closed
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
8 changes: 4 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions pkg/asset/manifests/cloudproviderconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package manifests

import (
"path/filepath"

"github.com/ghodss/yaml"
ospclientconfig "github.com/gophercloud/utils/openstack/clientconfig"
"github.com/pkg/errors"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
osmachine "github.com/openshift/installer/pkg/asset/machines/openstack"
awstypes "github.com/openshift/installer/pkg/types/aws"
libvirttypes "github.com/openshift/installer/pkg/types/libvirt"
nonetypes "github.com/openshift/installer/pkg/types/none"
openstacktypes "github.com/openshift/installer/pkg/types/openstack"
vspheretypes "github.com/openshift/installer/pkg/types/vsphere"
)

var (
cloudProviderConfigFileName = filepath.Join(manifestDir, "cloud-provider-config.yaml")
)

const (
cloudProviderConfigDataKey = "config"
)

// CloudProviderConfig generates the cloud-provider-config.yaml files.
type CloudProviderConfig struct {
ConfigMap *corev1.ConfigMap
File *asset.File
}

var _ asset.WritableAsset = (*CloudProviderConfig)(nil)

// Name returns a human friendly name for the asset.
func (*CloudProviderConfig) Name() string {
return "Cloud Provider Config"
}

// Dependencies returns all of the dependencies directly needed to generate
// the asset.
func (*CloudProviderConfig) Dependencies() []asset.Asset {
return []asset.Asset{
&installconfig.InstallConfig{},
// PlatformCredsCheck just checks the creds (and asks, if needed)
// We do not actually use it in this asset directly, hence
// it is put in the dependencies but not fetched in Generate
&installconfig.PlatformCredsCheck{},
}
}

// Generate generates the CloudProviderConfig.
func (cpc *CloudProviderConfig) Generate(dependencies asset.Parents) error {
installConfig := &installconfig.InstallConfig{}
dependencies.Get(installConfig)

cm := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: corev1.SchemeGroupVersion.String(),
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "openshift-config",
Name: "cloud-provider-config",
},
Data: map[string]string{},
}

switch installConfig.Config.Platform.Name() {
case awstypes.Name, libvirttypes.Name, vspheretypes.Name, nonetypes.Name:
return nil
case openstacktypes.Name:
opts := &ospclientconfig.ClientOpts{}
opts.Cloud = installConfig.Config.Platform.OpenStack.Cloud
cloud, err := ospclientconfig.GetCloudFromYAML(opts)
if err != nil {
return errors.Wrap(err, "failed to get cloud config for openstack")
}
clouds := make(map[string]map[string]*ospclientconfig.Cloud)
clouds["clouds"] = map[string]*ospclientconfig.Cloud{
osmachine.CloudName: cloud,
}
marshalled, err := yaml.Marshal(clouds)
if err != nil {
return err
}
cm.Data[cloudProviderConfigDataKey] = string(marshalled)
default:
return errors.New("invalid Platform")
}

cmData, err := yaml.Marshal(cm)
if err != nil {
return errors.Wrapf(err, "failed to create %s manifest", cpc.Name())
}
cpc.ConfigMap = cm
cpc.File = &asset.File{
Filename: cloudProviderConfigFileName,
Data: cmData,
}
return nil
}

// Files returns the files generated by the asset.
func (cpc *CloudProviderConfig) Files() []*asset.File {
return []*asset.File{cpc.File}
}

// Load loads the already-rendered files back from disk.
func (cpc *CloudProviderConfig) Load(f asset.FileFetcher) (bool, error) {
return false, nil
}
22 changes: 13 additions & 9 deletions pkg/asset/manifests/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ func (*Infrastructure) Name() string {
func (*Infrastructure) Dependencies() []asset.Asset {
return []asset.Asset{
&installconfig.InstallConfig{},
&CloudProviderConfig{},
}
}

// Generate generates the Infrastructure config and its CRD.
func (i *Infrastructure) Generate(dependencies asset.Parents) error {
installConfig := &installconfig.InstallConfig{}
dependencies.Get(installConfig)
cloudproviderconfig := &CloudProviderConfig{}
dependencies.Get(installConfig, cloudproviderconfig)

var platform configv1.PlatformType
switch installConfig.Config.Platform.Name() {
Expand Down Expand Up @@ -80,18 +82,20 @@ func (i *Infrastructure) Generate(dependencies asset.Parents) error {
},
}

if cloudproviderconfig.ConfigMap != nil {
// set the configmap reference.
config.Spec.CloudConfig = configv1.ConfigMapFileReference{Name: cloudproviderconfig.ConfigMap.Name, Key: cloudProviderConfigDataKey}
i.FileList = append(i.FileList, cloudproviderconfig.File)
}

configData, err := yaml.Marshal(config)
if err != nil {
return errors.Wrapf(err, "failed to marshal config: %#v", config)
}

i.FileList = []*asset.File{
{
Filename: infraCfgFilename,
Data: configData,
},
}

i.FileList = append(i.FileList, &asset.File{
Filename: infraCfgFilename,
Data: configData,
})
return nil
}

Expand Down
41 changes: 20 additions & 21 deletions pkg/asset/manifests/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,26 @@ func (m *Manifests) generateBootKubeManifests(dependencies asset.Parents) []*ass
}

templateData := &bootkubeTemplateData{
Base64encodeCloudProviderConfig: "", // FIXME
CVOClusterID: clusterID.UUID,
EtcdCaBundle: base64.StdEncoding.EncodeToString(etcdCABundle.Cert()),
EtcdCaCert: string(etcdCA.Cert()),
EtcdClientCaCert: base64.StdEncoding.EncodeToString(etcdCA.Cert()),
EtcdClientCaKey: base64.StdEncoding.EncodeToString(etcdCA.Key()),
EtcdClientCert: base64.StdEncoding.EncodeToString(etcdClientCertKey.Cert()),
EtcdClientKey: base64.StdEncoding.EncodeToString(etcdClientCertKey.Key()),
EtcdEndpointDNSSuffix: installConfig.Config.ClusterDomain(),
EtcdEndpointHostnames: etcdEndpointHostnames,
EtcdMetricsCaCert: string(etcdMetricsCABundle.Cert()),
EtcdMetricsClientCert: base64.StdEncoding.EncodeToString(etcdMetricsSignerClientCertKey.Cert()),
EtcdMetricsClientKey: base64.StdEncoding.EncodeToString(etcdMetricsSignerClientCertKey.Key()),
EtcdSignerCert: base64.StdEncoding.EncodeToString(etcdSignerCertKey.Cert()),
EtcdSignerClientCert: base64.StdEncoding.EncodeToString(etcdSignerClientCertKey.Cert()),
EtcdSignerClientKey: base64.StdEncoding.EncodeToString(etcdSignerClientCertKey.Key()),
EtcdSignerKey: base64.StdEncoding.EncodeToString(etcdSignerCertKey.Key()),
McsTLSCert: base64.StdEncoding.EncodeToString(mcsCertKey.Cert()),
McsTLSKey: base64.StdEncoding.EncodeToString(mcsCertKey.Key()),
PullSecretBase64: base64.StdEncoding.EncodeToString([]byte(installConfig.Config.PullSecret)),
RootCaCert: string(rootCA.Cert()),
CVOClusterID: clusterID.UUID,
EtcdCaBundle: base64.StdEncoding.EncodeToString(etcdCABundle.Cert()),
EtcdCaCert: string(etcdCA.Cert()),
EtcdClientCaCert: base64.StdEncoding.EncodeToString(etcdCA.Cert()),
EtcdClientCaKey: base64.StdEncoding.EncodeToString(etcdCA.Key()),
EtcdClientCert: base64.StdEncoding.EncodeToString(etcdClientCertKey.Cert()),
EtcdClientKey: base64.StdEncoding.EncodeToString(etcdClientCertKey.Key()),
EtcdEndpointDNSSuffix: installConfig.Config.ClusterDomain(),
EtcdEndpointHostnames: etcdEndpointHostnames,
EtcdMetricsCaCert: string(etcdMetricsCABundle.Cert()),
EtcdMetricsClientCert: base64.StdEncoding.EncodeToString(etcdMetricsSignerClientCertKey.Cert()),
EtcdMetricsClientKey: base64.StdEncoding.EncodeToString(etcdMetricsSignerClientCertKey.Key()),
EtcdSignerCert: base64.StdEncoding.EncodeToString(etcdSignerCertKey.Cert()),
EtcdSignerClientCert: base64.StdEncoding.EncodeToString(etcdSignerClientCertKey.Cert()),
EtcdSignerClientKey: base64.StdEncoding.EncodeToString(etcdSignerClientCertKey.Key()),
EtcdSignerKey: base64.StdEncoding.EncodeToString(etcdSignerCertKey.Key()),
McsTLSCert: base64.StdEncoding.EncodeToString(mcsCertKey.Cert()),
McsTLSKey: base64.StdEncoding.EncodeToString(mcsCertKey.Key()),
PullSecretBase64: base64.StdEncoding.EncodeToString([]byte(installConfig.Config.PullSecret)),
RootCaCert: string(rootCA.Cert()),
}

files := []*asset.File{}
Expand Down
43 changes: 21 additions & 22 deletions pkg/asset/manifests/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@ type cloudCredsSecretData struct {
}

type bootkubeTemplateData struct {
Base64encodeCloudProviderConfig string
CVOClusterID string
EtcdCaBundle string
EtcdCaCert string
EtcdClientCaCert string
EtcdClientCaKey string
EtcdClientCert string
EtcdClientKey string
EtcdEndpointDNSSuffix string
EtcdEndpointHostnames []string
EtcdMetricsCaCert string
EtcdMetricsClientCert string
EtcdMetricsClientKey string
EtcdSignerCert string
EtcdSignerClientCert string
EtcdSignerClientKey string
EtcdSignerKey string
McsTLSCert string
McsTLSKey string
PullSecretBase64 string
RootCaCert string
WorkerIgnConfig string
CVOClusterID string
EtcdCaBundle string
EtcdCaCert string
EtcdClientCaCert string
EtcdClientCaKey string
EtcdClientCert string
EtcdClientKey string
EtcdEndpointDNSSuffix string
EtcdEndpointHostnames []string
EtcdMetricsCaCert string
EtcdMetricsClientCert string
EtcdMetricsClientKey string
EtcdSignerCert string
EtcdSignerClientCert string
EtcdSignerClientKey string
EtcdSignerKey string
McsTLSCert string
McsTLSKey string
PullSecretBase64 string
RootCaCert string
WorkerIgnConfig string
}

type openshiftTemplateData struct {
Expand Down
4 changes: 2 additions & 2 deletions vendor/github.com/openshift/api/config/v1/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions vendor/github.com/openshift/api/config/v1/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading