Skip to content

Commit

Permalink
Provide an option to set cluster and infra ids for image based instal…
Browse files Browse the repository at this point in the history
…lation
  • Loading branch information
tsorya committed Oct 2, 2024
1 parent 325e310 commit f11a447
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/asset/agent/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

const (
// ExternalPlatformNameOci is the name of the external platform for OCP.
ExternalPlatformNameOci = "oci"
)

Expand Down
6 changes: 6 additions & 0 deletions pkg/asset/imagebased/configimage/clusterconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func (cc *ClusterConfiguration) Generate(_ context.Context, dependencies asset.P
if installConfig.Config == nil || imageBasedConfig.Config == nil {
return cc.finish()
}
if imageBasedConfig.Config.ClusterID != "" {
clusterID.UUID = imageBasedConfig.Config.ClusterID
}
if imageBasedConfig.Config.InfraID != "" {
clusterID.InfraID = imageBasedConfig.Config.InfraID
}

cc.Config = &imagebased.SeedReconfiguration{
APIVersion: imagebased.SeedReconfigurationVersion,
Expand Down
23 changes: 23 additions & 0 deletions pkg/asset/imagebased/configimage/clusterconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ func TestClusterConfiguration_Generate(t *testing.T) {

expectedConfig: clusterConfiguration().build().Config,
},
{
name: "valid configuration with cluster and infra ID",
dependencies: []asset.Asset{
clusterID(),
kubeadminPassword(),
lbCertKey(),
localhostCertKey(),
serviceNetworkCertKey(),
adminKubeConfigCertKey(),
ingressCertKey(),
installConfig().build(),
imageBasedConfigWithSetClusterID("some-id", "some-infra-id"),
},

expectedConfig: clusterConfigurationWithProvidedIDs("some-id", "some-infra-id").build().Config,
},
{
name: "valid configuration with proxy",
dependencies: []asset.Asset{
Expand Down Expand Up @@ -340,6 +356,13 @@ func clusterConfiguration() *ClusterConfigurationBuilder {
return ccb
}

func clusterConfigurationWithProvidedIDs(clusterID string, infraID string) *ClusterConfigurationBuilder {
ccb := clusterConfiguration()
ccb.ClusterConfiguration.Config.ClusterID = clusterID
ccb.ClusterConfiguration.Config.InfraID = infraID
return ccb
}

func clusterID() *ClusterID {
return &ClusterID{
installconfig.ClusterID{
Expand Down
1 change: 0 additions & 1 deletion pkg/asset/imagebased/configimage/imagebased_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ func (i *ImageBasedConfig) validateImageBasedConfig() field.ErrorList {
func (i *ImageBasedConfig) validateNetworkConfig() field.ErrorList {
var allErrs field.ErrorList

fmt.Sprintf("NetworkConfig: %s", i.Config.NetworkConfig)
// empty NetworkConfig is fine
if i.Config.NetworkConfig == nil || i.Config.NetworkConfig.String() == "" {
return nil
Expand Down
5 changes: 2 additions & 3 deletions pkg/asset/imagebased/configimage/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ func (i *InstallConfig) Generate(_ context.Context, parents asset.Parents) error
return nil
}

// adding custom loadFromFile method to load the install-config.yaml file
// as default one adds many default values that are not needed for image-based install config and can break our logic
// such as machine network for example
// loadFromFile method to load the install-config.yaml file.
// Default one adds many default values that are not needed for image-based install config and can break our logic such as machine network for example.
func (i *InstallConfig) loadFromFile(f asset.FileFetcher) (found bool, err error) {
file, err := f.FetchByName(InstallConfigFilename)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions pkg/asset/imagebased/configimage/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ func imageBasedConfig() *ImageBasedConfig {
return ibConfig
}

func imageBasedConfigWithSetClusterID(clusterID string, infraID string) *ImageBasedConfig {
ibConfig := imageBasedConfig()
ibConfig.Config.ClusterID = clusterID
ibConfig.Config.InfraID = infraID
return ibConfig
}

func unmarshalJSON(b []byte) []byte {
output, err := yaml.JSONToYAML(b)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions pkg/types/imagebased/imagebased_config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ type Config struct {
// ReleaseRegistry is the container registry used to host the release image of the seed cluster.
// +optional
ReleaseRegistry string `json:"releaseRegistry,omitempty"`

// ClusterID is the desired cluster ID.
// Will be generated by the installer in case it is not provided.
// +optional
ClusterID string `json:"cluster_id,omitempty"`

// InfraID is the desired infra ID.
// Will be generated by the installer in case it is not provided.
// +optional
InfraID string `json:"infra_id,omitempty"`
}

// InstallationConfig is the API for specifying configuration for the
Expand Down

0 comments on commit f11a447

Please sign in to comment.