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 1, 2024
1 parent 4cdbfd8 commit 889aff1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
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
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 889aff1

Please sign in to comment.