Skip to content
Merged
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
4 changes: 1 addition & 3 deletions Gopkg.lock

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

940 changes: 467 additions & 473 deletions docs/design/resource_dep.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions pkg/asset/cluster/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions pkg/asset/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand All @@ -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'")
Expand All @@ -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() {
Expand All @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/asset/cluster/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
10 changes: 7 additions & 3 deletions pkg/asset/cluster/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/openshift/installer/pkg/asset/ignition/bootstrap"
"github.com/openshift/installer/pkg/asset/ignition/machine"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/rhcos"
"github.com/openshift/installer/pkg/tfvars"
"github.com/pkg/errors"
)
Expand All @@ -33,24 +34,27 @@ 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{},
new(rhcos.Image),
&bootstrap.Bootstrap{},
&machine.Master{},
}
}

// 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)
rhcosImage := new(rhcos.Image)
parents.Get(clusterID, installConfig, bootstrap, master, rhcosImage)

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, string(*rhcosImage), bootstrapIgn, masterIgn)
if err != nil {
return errors.Wrap(err, "failed to get Tfvars")
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/asset/installconfig/clusterid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 0 additions & 4 deletions pkg/asset/installconfig/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var _ asset.WritableAsset = (*InstallConfig)(nil)
// InstallConfig asset.
func (a *InstallConfig) Dependencies() []asset.Asset {
return []asset.Asset{
&clusterID{},
&sshPublicKey{},
&baseDomain{},
&clusterName{},
Expand All @@ -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,
Expand All @@ -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{
Expand Down
1 change: 0 additions & 1 deletion pkg/asset/installconfig/installconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func validInstallConfig() *types.InstallConfig {
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
ClusterID: "test-cluster-id",
BaseDomain: "test-domain",
Networking: types.Networking{
Type: "OpenshiftSDN",
Expand Down
12 changes: 0 additions & 12 deletions pkg/asset/installconfig/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
package libvirt

import (
"context"

"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"

"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/types/libvirt"
"github.com/openshift/installer/pkg/validate"
)
Expand Down Expand Up @@ -40,18 +36,10 @@ func Platform() (*libvirt.Platform, error) {
return nil, err
}

qcowImage, err := rhcos.QEMU(context.TODO(), rhcos.DefaultChannel)
if err != nil {
return nil, errors.Wrap(err, "failed to fetch QEMU image URL")
}

return &libvirt.Platform{
Network: libvirt.Network{
IfName: defaultNetworkIfName,
},
DefaultMachinePlatform: &libvirt.MachinePool{
Image: qcowImage,
},
URI: uri,
}, nil
}
Expand Down
29 changes: 0 additions & 29 deletions pkg/asset/installconfig/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,6 @@ func Platform() (*openstack.Platform, error) {
return nil, err
}

imageNames, err := validValuesFetcher.GetImageNames(cloud)
if err != nil {
return nil, err
}
sort.Strings(imageNames)
var image string
err = survey.Ask([]*survey.Question{
{
Prompt: &survey.Select{
Message: "Image",
Help: "The OpenStack image name to be used for installation.",
Default: "rhcos",
Options: imageNames,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
value := ans.(string)
i := sort.SearchStrings(imageNames, value)
if i == len(imageNames) || imageNames[i] != value {
return errors.Errorf("invalid image name %q, should be one of %+v", value, strings.Join(imageNames, ", "))
}
return nil
}),
},
}, &image)
if err != nil {
return nil, err
}

networkNames, err := validValuesFetcher.GetNetworkNames(cloud)
if err != nil {
return nil, err
Expand Down Expand Up @@ -169,7 +141,6 @@ func Platform() (*openstack.Platform, error) {

return &openstack.Platform{
Region: region,
BaseImage: image,
Cloud: cloud,
ExternalNetwork: extNet,
FlavorName: flavor,
Expand Down
9 changes: 5 additions & 4 deletions pkg/asset/machines/aws/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, osImage, role, userDataSecret string) ([]clusterapi.Machine, error) {
if configPlatform := config.Platform.Name(); configPlatform != aws.Name {
return nil, fmt.Errorf("non-AWS configuration: %q", configPlatform)
}
Expand All @@ -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, osImage, azIndex, role, userDataSecret)
if err != nil {
return nil, errors.Wrap(err, "failed to create provider")
}
Expand Down Expand Up @@ -69,8 +69,9 @@ func Machines(config *types.InstallConfig, pool *types.MachinePool, role, userDa
return machines, nil
}

func provider(clusterID, clusterName string, platform *aws.Platform, mpool *aws.MachinePool, azIdx int, role, userDataSecret string) (*awsprovider.AWSMachineProviderConfig, error) {
func provider(clusterID, clusterName string, platform *aws.Platform, mpool *aws.MachinePool, osImage string, azIdx int, role, userDataSecret string) (*awsprovider.AWSMachineProviderConfig, error) {
az := mpool.Zones[azIdx]
amiID := osImage
tags, err := tagsFromUserTags(clusterID, clusterName, platform.UserTags)
if err != nil {
return nil, errors.Wrap(err, "failed to create awsprovider.TagSpecifications from UserTags")
Expand All @@ -81,7 +82,7 @@ func provider(clusterID, clusterName string, platform *aws.Platform, mpool *aws.
Kind: "AWSMachineProviderConfig",
},
InstanceType: mpool.InstanceType,
AMI: awsprovider.AWSResourceReference{ID: &mpool.AMIID},
AMI: awsprovider.AWSResourceReference{ID: &amiID},
Tags: tags,
IAMInstanceProfile: &awsprovider.AWSResourceReference{ID: pointer.StringPtr(fmt.Sprintf("%s-%s-profile", clusterName, role))},
UserDataSecret: &corev1.LocalObjectReference{Name: userDataSecret},
Expand Down
4 changes: 2 additions & 2 deletions pkg/asset/machines/aws/machinesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, osImage, role, userDataSecret string) ([]clusterapi.MachineSet, error) {
if configPlatform := config.Platform.Name(); configPlatform != aws.Name {
return nil, fmt.Errorf("non-AWS configuration: %q", configPlatform)
}
Expand All @@ -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, osImage, idx, role, userDataSecret)
if err != nil {
return nil, errors.Wrap(err, "failed to create provider")
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/asset/machines/libvirt/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@ 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)
}
// FIXME: empty is a valid case for Libvirt as we don't use it.
if poolPlatform := pool.Platform.Name(); poolPlatform != "" && poolPlatform != libvirt.Name {
if poolPlatform := pool.Platform.Name(); poolPlatform != libvirt.Name {
return nil, fmt.Errorf("non-Libvirt machine-pool: %q", poolPlatform)
}
clustername := config.ObjectMeta.Name
platform := config.Platform.Libvirt
// FIXME: libvirt actuator does not support any options from machinepool.
// mpool := pool.Platform.Libvirt

total := int64(1)
if pool.Replicas != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/machines/libvirt/machinesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading