Skip to content

Commit

Permalink
extend nutanix provider api surface to use management components (#7395)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxbrowne1207 authored Jan 27, 2024
1 parent cea79ed commit 7c1388b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/providers/nutanix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions pkg/providers/nutanix/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 7c1388b

Please sign in to comment.