diff --git a/pkg/providers/nutanix/provider.go b/pkg/providers/nutanix/provider.go index e624a1e7df0d..5b13803fac15 100644 --- a/pkg/providers/nutanix/provider.go +++ b/pkg/providers/nutanix/provider.go @@ -526,6 +526,11 @@ func (p *Provider) Version(clusterSpec *cluster.Spec) string { return versionsBundle.Nutanix.Version } +// VersionFromManagementComponents returns the version of the provider. +func (p *Provider) VersionFromManagementComponents(components *cluster.ManagementComponents) string { + return components.Nutanix.Version +} + func (p *Provider) EnvMap(_ *cluster.Spec) (map[string]string, error) { // TODO(nutanix): determine if any env vars are needed and add them to requiredEnvs envMap := make(map[string]string) @@ -560,6 +565,21 @@ func (p *Provider) GetInfrastructureBundle(clusterSpec *cluster.Spec) *types.Inf return &infraBundle } +// GetInfrastructureBundleFromManagementComponents returns the infrastructure bundle for the provider. +func (p *Provider) GetInfrastructureBundleFromManagementComponents(components *cluster.ManagementComponents) *types.InfrastructureBundle { + manifests := []releasev1alpha1.Manifest{ + components.Nutanix.Components, + components.Nutanix.Metadata, + components.Nutanix.ClusterTemplate, + } + folderName := fmt.Sprintf("infrastructure-nutanix/%s/", components.Nutanix.Version) + infraBundle := types.InfrastructureBundle{ + FolderName: folderName, + Manifests: manifests, + } + return &infraBundle +} + func (p *Provider) DatacenterConfig(_ *cluster.Spec) providers.DatacenterConfig { return p.datacenterConfig } @@ -625,6 +645,19 @@ func (p *Provider) ChangeDiff(currentSpec, newSpec *cluster.Spec) *types.Compone } } +// ChangeDiffFromManagementComponents returns the component change diff for the provider. +func (p *Provider) ChangeDiffFromManagementComponents(currentComponents, newComponents *cluster.ManagementComponents) *types.ComponentChangeDiff { + if currentComponents.Nutanix.Version == newComponents.Nutanix.Version { + return nil + } + + return &types.ComponentChangeDiff{ + ComponentName: constants.NutanixProviderName, + NewVersion: newComponents.Nutanix.Version, + OldVersion: currentComponents.Nutanix.Version, + } +} + func (p *Provider) RunPostControlPlaneUpgrade(ctx context.Context, oldClusterSpec *cluster.Spec, clusterSpec *cluster.Spec, workloadCluster *types.Cluster, managementCluster *types.Cluster) error { // TODO(nutanix): figure out if we need something else here return nil diff --git a/pkg/providers/nutanix/provider_test.go b/pkg/providers/nutanix/provider_test.go index 060f6e8d0a1e..c622dca24a61 100644 --- a/pkg/providers/nutanix/provider_test.go +++ b/pkg/providers/nutanix/provider_test.go @@ -31,6 +31,7 @@ import ( filewritermocks "github.com/aws/eks-anywhere/pkg/filewriter/mocks" mocknutanix "github.com/aws/eks-anywhere/pkg/providers/nutanix/mocks" "github.com/aws/eks-anywhere/pkg/types" + releasev1alpha1 "github.com/aws/eks-anywhere/release/api/v1alpha1" ) //go:embed testdata/eksa-cluster.json @@ -106,6 +107,23 @@ func testNutanixProvider(t *testing.T, nutanixClient Client, kubectl *executable return provider } +func givenManagementComponents() *cluster.ManagementComponents { + return &cluster.ManagementComponents{ + Nutanix: releasev1alpha1.NutanixBundle{ + Version: "1.0.0", + Components: releasev1alpha1.Manifest{ + URI: "embed:///config/clusterctl/overrides/infrastructure-nutanix/v1.0.0/infrastructure-components-development.yaml", + }, + ClusterTemplate: releasev1alpha1.Manifest{ + URI: "embed:///config/clusterctl/overrides/infrastructure-nutanix/v1.0.0/cluster-template.yaml", + }, + Metadata: releasev1alpha1.Manifest{ + URI: "embed:///config/clusterctl/overrides/infrastructure-nutanix/v1.0.0/metadata.yaml", + }, + }, + } +} + func testNutanixProviderWithClusterSpec(t *testing.T, nutanixClient Client, kubectl *executables.Kubectl, certValidator crypto.TlsValidator, httpClient *http.Client, writer filewriter.FileWriter, clusterSpec *cluster.Spec) *Provider { t.Setenv(constants.EksaNutanixUsernameKey, "admin") t.Setenv(constants.EksaNutanixPasswordKey, "password") @@ -917,6 +935,21 @@ func TestNutanixProviderGetInfrastructureBundle(t *testing.T) { assert.NotNil(t, bundle) } +func TestNutanixProviderGetInfrastructureBundleFromManagementComponents(t *testing.T) { + provider := testDefaultNutanixProvider(t) + managementComponents := givenManagementComponents() + wantInfraBundle := &types.InfrastructureBundle{ + FolderName: "infrastructure-nutanix/1.0.0/", + Manifests: []releasev1alpha1.Manifest{ + managementComponents.Nutanix.Components, + managementComponents.Nutanix.Metadata, + managementComponents.Nutanix.ClusterTemplate, + }, + } + + assert.Equal(t, wantInfraBundle, provider.GetInfrastructureBundleFromManagementComponents(managementComponents)) +} + func TestNutanixProviderDatacenterConfig(t *testing.T) { provider := testDefaultNutanixProvider(t) clusterSpec := test.NewFullClusterSpec(t, "testdata/eksa-cluster.yaml") @@ -946,6 +979,13 @@ func TestNutanixProviderChangeDiff(t *testing.T) { assert.Nil(t, cd) } +func TestNutanixProviderChangeDiffFromManagementComponentsNoChange(t *testing.T) { + provider := testDefaultNutanixProvider(t) + managementComponents := givenManagementComponents() + got := provider.ChangeDiffFromManagementComponents(managementComponents, managementComponents) + assert.Nil(t, got) +} + func TestNutanixProviderChangeDiffWithChange(t *testing.T) { provider := testDefaultNutanixProvider(t) clusterSpec := test.NewFullClusterSpec(t, "testdata/eksa-cluster.yaml") @@ -961,6 +1001,23 @@ func TestNutanixProviderChangeDiffWithChange(t *testing.T) { assert.Equal(t, cd, want) } +func TestNutanixProviderChangeDiffFromManagementComponentsWithChange(t *testing.T) { + provider := testDefaultNutanixProvider(t) + managementComponents := givenManagementComponents() + managementComponents.Nutanix.Version = "v0.5.2" + + newManagementComponents := givenManagementComponents() + newManagementComponents.Nutanix.Version = "v1.0.0" + want := &types.ComponentChangeDiff{ + ComponentName: "nutanix", + NewVersion: "v1.0.0", + OldVersion: "v0.5.2", + } + + got := provider.ChangeDiffFromManagementComponents(managementComponents, newManagementComponents) + assert.Equal(t, got, want) +} + func TestNutanixProviderRunPostControlPlaneUpgrade(t *testing.T) { provider := testDefaultNutanixProvider(t) clusterSpec := test.NewFullClusterSpec(t, "testdata/eksa-cluster.yaml")