diff --git a/pkg/asset/cluster/aws/aws.go b/pkg/asset/cluster/aws/aws.go index c2b4615afde..7c31f22ebc4 100644 --- a/pkg/asset/cluster/aws/aws.go +++ b/pkg/asset/cluster/aws/aws.go @@ -9,12 +9,12 @@ import ( ) // Metadata converts an install configuration to AWS metadata. -func Metadata(config *types.InstallConfig) *aws.Metadata { +func Metadata(clusterID string, config *types.InstallConfig) *aws.Metadata { return &aws.Metadata{ Region: config.Platform.AWS.Region, Identifier: []map[string]string{ { - "openshiftClusterID": config.ClusterID, + "openshiftClusterID": clusterID, }, { fmt.Sprintf("kubernetes.io/cluster/%s", config.ObjectMeta.Name): "owned", diff --git a/pkg/asset/cluster/cluster.go b/pkg/asset/cluster/cluster.go index 4173f7647e2..7b6e8b223b6 100644 --- a/pkg/asset/cluster/cluster.go +++ b/pkg/asset/cluster/cluster.go @@ -47,6 +47,7 @@ func (c *Cluster) Name() string { // the cluster. func (c *Cluster) Dependencies() []asset.Asset { return []asset.Asset{ + &installconfig.ClusterID{}, &installconfig.InstallConfig{}, &TerraformVariables{}, &password.KubeadminPassword{}, @@ -55,10 +56,11 @@ func (c *Cluster) Dependencies() []asset.Asset { // Generate launches the cluster and generates the terraform state file on disk. func (c *Cluster) Generate(parents asset.Parents) (err error) { + clusterID := &installconfig.ClusterID{} installConfig := &installconfig.InstallConfig{} terraformVariables := &TerraformVariables{} kubeadminPassword := &password.KubeadminPassword{} - parents.Get(installConfig, terraformVariables, kubeadminPassword) + parents.Get(clusterID, installConfig, terraformVariables, kubeadminPassword) if installConfig.Config.Platform.None != nil { return errors.New("cluster cannot be created with platform set to 'none'") @@ -78,6 +80,7 @@ func (c *Cluster) Generate(parents asset.Parents) (err error) { metadata := &types.ClusterMetadata{ ClusterName: installConfig.Config.ObjectMeta.Name, + ClusterID: clusterID.ClusterID, } defer func() { @@ -103,11 +106,11 @@ func (c *Cluster) Generate(parents asset.Parents) (err error) { switch { case installConfig.Config.Platform.AWS != nil: - metadata.ClusterPlatformMetadata.AWS = aws.Metadata(installConfig.Config) + metadata.ClusterPlatformMetadata.AWS = aws.Metadata(clusterID.ClusterID, installConfig.Config) case installConfig.Config.Platform.Libvirt != nil: metadata.ClusterPlatformMetadata.Libvirt = libvirt.Metadata(installConfig.Config) case installConfig.Config.Platform.OpenStack != nil: - metadata.ClusterPlatformMetadata.OpenStack = openstack.Metadata(installConfig.Config) + metadata.ClusterPlatformMetadata.OpenStack = openstack.Metadata(clusterID.ClusterID, installConfig.Config) default: return fmt.Errorf("no known platform") } diff --git a/pkg/asset/cluster/openstack/openstack.go b/pkg/asset/cluster/openstack/openstack.go index b1fa29e6406..6f182c061a8 100644 --- a/pkg/asset/cluster/openstack/openstack.go +++ b/pkg/asset/cluster/openstack/openstack.go @@ -8,12 +8,12 @@ import ( ) // Metadata converts an install configuration to OpenStack metadata. -func Metadata(config *types.InstallConfig) *openstack.Metadata { +func Metadata(clusterID string, config *types.InstallConfig) *openstack.Metadata { return &openstack.Metadata{ Region: config.Platform.OpenStack.Region, Cloud: config.Platform.OpenStack.Cloud, Identifier: map[string]string{ - "openshiftClusterID": config.ClusterID, + "openshiftClusterID": clusterID, }, } } diff --git a/pkg/asset/cluster/tfvars.go b/pkg/asset/cluster/tfvars.go index f8dd936fa8d..97751cba8f7 100644 --- a/pkg/asset/cluster/tfvars.go +++ b/pkg/asset/cluster/tfvars.go @@ -33,6 +33,7 @@ func (t *TerraformVariables) Name() string { // Dependencies returns the dependency of the TerraformVariable func (t *TerraformVariables) Dependencies() []asset.Asset { return []asset.Asset{ + &installconfig.ClusterID{}, &installconfig.InstallConfig{}, &bootstrap.Bootstrap{}, &machine.Master{}, @@ -41,16 +42,17 @@ func (t *TerraformVariables) Dependencies() []asset.Asset { // Generate generates the terraform.tfvars file. func (t *TerraformVariables) Generate(parents asset.Parents) error { + clusterID := &installconfig.ClusterID{} installConfig := &installconfig.InstallConfig{} bootstrap := &bootstrap.Bootstrap{} master := &machine.Master{} - parents.Get(installConfig, bootstrap, master) + parents.Get(clusterID, installConfig, bootstrap, master) bootstrapIgn := string(bootstrap.Files()[0].Data) masterIgn := string(master.Files()[0].Data) - data, err := tfvars.TFVars(installConfig.Config, bootstrapIgn, masterIgn) + data, err := tfvars.TFVars(clusterID.ClusterID, installConfig.Config, bootstrapIgn, masterIgn) if err != nil { return errors.Wrap(err, "failed to get Tfvars") } diff --git a/pkg/asset/installconfig/clusterid.go b/pkg/asset/installconfig/clusterid.go index f075d1f53d0..f7b35cd3159 100644 --- a/pkg/asset/installconfig/clusterid.go +++ b/pkg/asset/installconfig/clusterid.go @@ -6,24 +6,25 @@ import ( "github.com/openshift/installer/pkg/asset" ) -type clusterID struct { +// ClusterID is the unique ID of the cluster, immutable during the cluster's life +type ClusterID struct { ClusterID string } -var _ asset.Asset = (*clusterID)(nil) +var _ asset.Asset = (*ClusterID)(nil) // Dependencies returns no dependencies. -func (a *clusterID) Dependencies() []asset.Asset { +func (a *ClusterID) Dependencies() []asset.Asset { return []asset.Asset{} } // Generate generates a new UUID -func (a *clusterID) Generate(asset.Parents) error { +func (a *ClusterID) Generate(asset.Parents) error { a.ClusterID = uuid.New() return nil } // Name returns the human-friendly name of the asset. -func (a *clusterID) Name() string { +func (a *ClusterID) Name() string { return "Cluster ID" } diff --git a/pkg/asset/installconfig/installconfig.go b/pkg/asset/installconfig/installconfig.go index e0d2ce584be..2bb59e5ef4b 100644 --- a/pkg/asset/installconfig/installconfig.go +++ b/pkg/asset/installconfig/installconfig.go @@ -41,7 +41,6 @@ var _ asset.WritableAsset = (*InstallConfig)(nil) // InstallConfig asset. func (a *InstallConfig) Dependencies() []asset.Asset { return []asset.Asset{ - &clusterID{}, &sshPublicKey{}, &baseDomain{}, &clusterName{}, @@ -52,14 +51,12 @@ func (a *InstallConfig) Dependencies() []asset.Asset { // Generate generates the install-config.yaml file. func (a *InstallConfig) Generate(parents asset.Parents) error { - clusterID := &clusterID{} sshPublicKey := &sshPublicKey{} baseDomain := &baseDomain{} clusterName := &clusterName{} pullSecret := &pullSecret{} platform := &platform{} parents.Get( - clusterID, sshPublicKey, baseDomain, clusterName, @@ -71,7 +68,6 @@ func (a *InstallConfig) Generate(parents asset.Parents) error { ObjectMeta: metav1.ObjectMeta{ Name: clusterName.ClusterName, }, - ClusterID: clusterID.ClusterID, SSHKey: sshPublicKey.Key, BaseDomain: baseDomain.BaseDomain, Networking: types.Networking{ diff --git a/pkg/asset/machines/aws/machines.go b/pkg/asset/machines/aws/machines.go index c117678ae69..215df92f25a 100644 --- a/pkg/asset/machines/aws/machines.go +++ b/pkg/asset/machines/aws/machines.go @@ -18,7 +18,7 @@ import ( ) // Machines returns a list of machines for a machinepool. -func Machines(config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.Machine, error) { +func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.Machine, error) { if configPlatform := config.Platform.Name(); configPlatform != aws.Name { return nil, fmt.Errorf("non-AWS configuration: %q", configPlatform) } @@ -37,7 +37,7 @@ func Machines(config *types.InstallConfig, pool *types.MachinePool, role, userDa var machines []clusterapi.Machine for idx := int64(0); idx < total; idx++ { azIndex := int(idx) % len(azs) - provider, err := provider(config.ClusterID, clustername, platform, mpool, azIndex, role, userDataSecret) + provider, err := provider(clusterID, clustername, platform, mpool, azIndex, role, userDataSecret) if err != nil { return nil, errors.Wrap(err, "failed to create provider") } diff --git a/pkg/asset/machines/aws/machinesets.go b/pkg/asset/machines/aws/machinesets.go index 1c93d498674..fdbb3fbaf3b 100644 --- a/pkg/asset/machines/aws/machinesets.go +++ b/pkg/asset/machines/aws/machinesets.go @@ -14,7 +14,7 @@ import ( ) // MachineSets returns a list of machinesets for a machinepool. -func MachineSets(config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.MachineSet, error) { +func MachineSets(clusterID string, config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.MachineSet, error) { if configPlatform := config.Platform.Name(); configPlatform != aws.Name { return nil, fmt.Errorf("non-AWS configuration: %q", configPlatform) } @@ -38,7 +38,7 @@ func MachineSets(config *types.InstallConfig, pool *types.MachinePool, role, use replicas++ } - provider, err := provider(config.ClusterID, clustername, platform, mpool, idx, role, userDataSecret) + provider, err := provider(clusterID, clustername, platform, mpool, idx, role, userDataSecret) if err != nil { return nil, errors.Wrap(err, "failed to create provider") } diff --git a/pkg/asset/machines/libvirt/machines.go b/pkg/asset/machines/libvirt/machines.go index 9d3ccf66fb7..e32cbbe13dd 100644 --- a/pkg/asset/machines/libvirt/machines.go +++ b/pkg/asset/machines/libvirt/machines.go @@ -14,7 +14,7 @@ import ( ) // Machines returns a list of machines for a machinepool. -func Machines(config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.Machine, error) { +func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.Machine, error) { if configPlatform := config.Platform.Name(); configPlatform != libvirt.Name { return nil, fmt.Errorf("non-Libvirt configuration: %q", configPlatform) } diff --git a/pkg/asset/machines/libvirt/machinesets.go b/pkg/asset/machines/libvirt/machinesets.go index 675f2d3e80e..cbbfd98c19d 100644 --- a/pkg/asset/machines/libvirt/machinesets.go +++ b/pkg/asset/machines/libvirt/machinesets.go @@ -14,7 +14,7 @@ import ( ) // MachineSets returns a list of machinesets for a machinepool. -func MachineSets(config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.MachineSet, error) { +func MachineSets(clusterID string, config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.MachineSet, error) { if configPlatform := config.Platform.Name(); configPlatform != libvirt.Name { return nil, fmt.Errorf("non-Libvirt configuration: %q", configPlatform) } diff --git a/pkg/asset/machines/master.go b/pkg/asset/machines/master.go index 7152f2d12c9..bcab64a1318 100644 --- a/pkg/asset/machines/master.go +++ b/pkg/asset/machines/master.go @@ -42,6 +42,7 @@ func (m *Master) Name() string { // Master asset func (m *Master) Dependencies() []asset.Asset { return []asset.Asset{ + &installconfig.ClusterID{}, &installconfig.InstallConfig{}, &machine.Master{}, } @@ -49,9 +50,10 @@ func (m *Master) Dependencies() []asset.Asset { // Generate generates the Master asset. func (m *Master) Generate(dependencies asset.Parents) error { + clusterID := &installconfig.ClusterID{} installconfig := &installconfig.InstallConfig{} mign := &machine.Master{} - dependencies.Get(installconfig, mign) + dependencies.Get(clusterID, installconfig, mign) var err error userDataMap := map[string][]byte{"master-user-data": mign.File.Data} @@ -84,7 +86,7 @@ func (m *Master) Generate(dependencies asset.Parents) error { mpool.Zones = azs } pool.Platform.AWS = &mpool - machines, err := aws.Machines(ic, &pool, "master", "master-user-data") + machines, err := aws.Machines(clusterID.ClusterID, ic, &pool, "master", "master-user-data") if err != nil { return errors.Wrap(err, "failed to create master machine objects") } @@ -97,7 +99,7 @@ func (m *Master) Generate(dependencies asset.Parents) error { } m.MachinesRaw = raw case libvirttypes.Name: - machines, err := libvirt.Machines(ic, &pool, "master", "master-user-data") + machines, err := libvirt.Machines(clusterID.ClusterID, ic, &pool, "master", "master-user-data") if err != nil { return errors.Wrap(err, "failed to create master machine objects") } @@ -128,7 +130,7 @@ func (m *Master) Generate(dependencies asset.Parents) error { } tags := map[string]string{ - "openshiftClusterID": ic.ClusterID, + "openshiftClusterID": clusterID.ClusterID, } config.Tags = tags diff --git a/pkg/asset/machines/worker.go b/pkg/asset/machines/worker.go index 65519826bca..dbf268765b2 100644 --- a/pkg/asset/machines/worker.go +++ b/pkg/asset/machines/worker.go @@ -65,6 +65,7 @@ func (w *Worker) Name() string { // Worker asset func (w *Worker) Dependencies() []asset.Asset { return []asset.Asset{ + &installconfig.ClusterID{}, &installconfig.InstallConfig{}, &machine.Worker{}, } @@ -72,9 +73,10 @@ func (w *Worker) Dependencies() []asset.Asset { // Generate generates the Worker asset. func (w *Worker) Generate(dependencies asset.Parents) error { - installconfig := &installconfig.InstallConfig{} + clusterID := &installconfig.ClusterID{} + installConfig := &installconfig.InstallConfig{} wign := &machine.Worker{} - dependencies.Get(installconfig, wign) + dependencies.Get(clusterID, installConfig, wign) var err error userDataMap := map[string][]byte{"worker-user-data": wign.File.Data} @@ -83,7 +85,7 @@ func (w *Worker) Generate(dependencies asset.Parents) error { return errors.Wrap(err, "failed to create user-data secret for worker machines") } - ic := installconfig.Config + ic := installConfig.Config pool := workerPool(ic.Machines) switch ic.Platform.Name() { case awstypes.Name: @@ -107,7 +109,7 @@ func (w *Worker) Generate(dependencies asset.Parents) error { mpool.Zones = azs } pool.Platform.AWS = &mpool - sets, err := aws.MachineSets(ic, &pool, "worker", "worker-user-data") + sets, err := aws.MachineSets(clusterID.ClusterID, ic, &pool, "worker", "worker-user-data") if err != nil { return errors.Wrap(err, "failed to create worker machine objects") } @@ -119,7 +121,7 @@ func (w *Worker) Generate(dependencies asset.Parents) error { } w.MachineSetRaw = raw case libvirttypes.Name: - sets, err := libvirt.MachineSets(ic, &pool, "worker", "worker-user-data") + sets, err := libvirt.MachineSets(clusterID.ClusterID, ic, &pool, "worker", "worker-user-data") if err != nil { return errors.Wrap(err, "failed to create worker machine objects") } @@ -146,7 +148,7 @@ func (w *Worker) Generate(dependencies asset.Parents) error { } tags := map[string]string{ - "openshiftClusterID": ic.ClusterID, + "openshiftClusterID": clusterID.ClusterID, } config.Tags = tags diff --git a/pkg/asset/manifests/operators.go b/pkg/asset/manifests/operators.go index 5444a1855ef..3c3ebddcbbb 100644 --- a/pkg/asset/manifests/operators.go +++ b/pkg/asset/manifests/operators.go @@ -52,6 +52,7 @@ func (m *Manifests) Name() string { // Manifests asset. func (m *Manifests) Dependencies() []asset.Asset { return []asset.Asset{ + &installconfig.ClusterID{}, &installconfig.InstallConfig{}, &Ingress{}, &DNS{}, @@ -121,6 +122,7 @@ func (m *Manifests) Files() []*asset.File { } func (m *Manifests) generateBootKubeManifests(dependencies asset.Parents) []*asset.File { + clusterID := &installconfig.ClusterID{} installConfig := &installconfig.InstallConfig{} etcdCA := &tls.EtcdCA{} kubeCA := &tls.KubeCA{} @@ -129,6 +131,7 @@ func (m *Manifests) generateBootKubeManifests(dependencies asset.Parents) []*ass rootCA := &tls.RootCA{} serviceServingCA := &tls.ServiceServingCA{} dependencies.Get( + clusterID, installConfig, etcdCA, etcdClientCertKey, @@ -156,7 +159,7 @@ func (m *Manifests) generateBootKubeManifests(dependencies asset.Parents) []*ass RootCaCert: string(rootCA.Cert()), ServiceServingCaCert: base64.StdEncoding.EncodeToString(serviceServingCA.Cert()), ServiceServingCaKey: base64.StdEncoding.EncodeToString(serviceServingCA.Key()), - CVOClusterID: installConfig.Config.ClusterID, + CVOClusterID: clusterID.ClusterID, EtcdEndpointHostnames: etcdEndpointHostnames, EtcdEndpointDNSSuffix: installConfig.Config.BaseDomain, } diff --git a/pkg/tfvars/tfvars.go b/pkg/tfvars/tfvars.go index d0956151b90..e5223648142 100644 --- a/pkg/tfvars/tfvars.go +++ b/pkg/tfvars/tfvars.go @@ -31,9 +31,9 @@ type config struct { // TFVars converts the InstallConfig and Ignition content to // terraform.tfvar JSON. -func TFVars(cfg *types.InstallConfig, bootstrapIgn, masterIgn string) ([]byte, error) { +func TFVars(clusterID string, cfg *types.InstallConfig, bootstrapIgn, masterIgn string) ([]byte, error) { config := &config{ - ClusterID: cfg.ClusterID, + ClusterID: clusterID, Name: cfg.ObjectMeta.Name, BaseDomain: cfg.BaseDomain, MachineCIDR: cfg.Networking.MachineCIDR.String(), diff --git a/pkg/types/clustermetadata.go b/pkg/types/clustermetadata.go index d7482334fd5..e380088e8ad 100644 --- a/pkg/types/clustermetadata.go +++ b/pkg/types/clustermetadata.go @@ -10,6 +10,7 @@ import ( // regarding the cluster that was created by installer. type ClusterMetadata struct { ClusterName string `json:"clusterName"` + ClusterID string `json:"clusterID"` ClusterPlatformMetadata `json:",inline"` } diff --git a/pkg/types/installconfig.go b/pkg/types/installconfig.go index cccdb89f862..4ddecf1e3fc 100644 --- a/pkg/types/installconfig.go +++ b/pkg/types/installconfig.go @@ -33,9 +33,6 @@ type InstallConfig struct { metav1.ObjectMeta `json:"metadata"` - // ClusterID is the ID of the cluster. - ClusterID string `json:"clusterID"` - // SSHKey is the public ssh key to provide access to instances. SSHKey string `json:"sshKey"` diff --git a/pkg/types/validation/installconfig.go b/pkg/types/validation/installconfig.go index cf982adcbb5..385a2d5dba8 100644 --- a/pkg/types/validation/installconfig.go +++ b/pkg/types/validation/installconfig.go @@ -25,9 +25,6 @@ func ValidateInstallConfig(c *types.InstallConfig, openStackValidValuesFetcher o if c.ObjectMeta.Name == "" { allErrs = append(allErrs, field.Required(field.NewPath("metadata", "name"), "cluster name required")) } - if c.ClusterID == "" { - allErrs = append(allErrs, field.Required(field.NewPath("clusterID"), "cluster ID required")) - } if c.SSHKey != "" { if err := validate.SSHPublicKey(c.SSHKey); err != nil { allErrs = append(allErrs, field.Invalid(field.NewPath("sshKey"), c.SSHKey, err.Error()))