Skip to content

Commit

Permalink
more fixes and enable tests to pass uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakm-ntnx committed Dec 6, 2022
1 parent f5e59b7 commit f23b655
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 67 deletions.
4 changes: 4 additions & 0 deletions pkg/api/v1alpha1/nutanixmachineconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
// NutanixIdentifierType is an enumeration of different resource identifier types.
type NutanixIdentifierType string

func (c NutanixIdentifierType) String() string {
return string(c)
}

const (
// NutanixMachineConfigKind is the kind for a NutanixMachineConfig.
NutanixMachineConfigKind = "NutanixMachineConfig"
Expand Down
15 changes: 15 additions & 0 deletions pkg/providers/nutanix/config/cp-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,26 @@ spec:
memorySize: {{.memorySize}}
systemDiskSize: {{.systemDiskSize}}
image:
{{- if and .imageIDType (eq .format "name") }}
type: name
name: "{{.imageName}}"
{{ else if and .imageIDType (eq .format "uuid") }}
type: uuid
name: "{{.imageUUID}}"
{{ end }}
cluster:
{{- if and .nutanixPEClusterIDType (eq .format "name") }}
type: name
name: "{{.nutanixPEClusterName}}"
{{- else if and .nutanixPEClusterIDType (eq .format "uuid") }}
type: uuid
name: "{{.nutanixPEClusterUUID}}"
{{ end }}
subnet:
{{- if and .subnetIDType (eq .format "name") }}
- type: name
name: "{{.subnetName}}"
{{- else if and .subnetIDType (eq .format "uuid") }}
- type: uuid
name: "{{.subnetUUID}}"
{{ end }}
12 changes: 9 additions & 3 deletions pkg/providers/nutanix/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,15 @@ func buildTemplateMapMD(clusterSpec *cluster.Spec, workerNodeGroupMachineSpec v1
"vcpuSockets": workerNodeGroupMachineSpec.VCPUSockets,
"memorySize": workerNodeGroupMachineSpec.MemorySize.String(),
"systemDiskSize": workerNodeGroupMachineSpec.SystemDiskSize.String(),
"imageName": workerNodeGroupMachineSpec.Image.Name, // TODO(nutanix): pass name or uuid based on type of identifier
"nutanixPEClusterName": workerNodeGroupMachineSpec.Cluster.Name, // TODO(nutanix): pass name or uuid based on type of identifier
"subnetName": workerNodeGroupMachineSpec.Subnet.Name, // TODO(nutanix): pass name or uuid based on type of identifier
"imageIDType": workerNodeGroupMachineSpec.Image.Type,
"imageName": workerNodeGroupMachineSpec.Image.Name,
"imageUUID": workerNodeGroupMachineSpec.Image.UUID,
"nutanixPEClusterIDType": workerNodeGroupMachineSpec.Cluster.Type,
"nutanixPEClusterName": workerNodeGroupMachineSpec.Cluster.Name,
"nutanixPEClusterUUID": workerNodeGroupMachineSpec.Cluster.UUID,
"subnetIDType": workerNodeGroupMachineSpec.Subnet.Type,
"subnetName": workerNodeGroupMachineSpec.Subnet.Name,
"subnetUUID": workerNodeGroupMachineSpec.Subnet.UUID,
"workerNodeGroupName": fmt.Sprintf("%s-%s", clusterSpec.Cluster.Name, workerNodeGroupConfiguration.Name),
}
return values
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ func TestNutanixKubernetes121To122UbuntuUpgrade(t *testing.T) {
test,
v1alpha1.Kube122,
framework.WithClusterUpgrade(api.WithKubernetesVersion(v1alpha1.Kube122)),
provider.WithProviderUpgrade(framework.UpdateNutanixUbuntuTemplate122Var()),
provider.WithProviderUpgrade(framework.GetUbuntu122NutanixFillers()...),
)
}

Expand All @@ -822,7 +822,7 @@ func TestNutanixKubernetes122To123UbuntuUpgrade(t *testing.T) {
test,
v1alpha1.Kube123,
framework.WithClusterUpgrade(api.WithKubernetesVersion(v1alpha1.Kube123)),
provider.WithProviderUpgrade(framework.UpdateNutanixUbuntuTemplate123Var()),
provider.WithProviderUpgrade(framework.GetUbuntu123NutanixFillers()...),
)
}

Expand All @@ -839,7 +839,7 @@ func TestNutanixKubernetes123To124UbuntuUpgrade(t *testing.T) {
test,
v1alpha1.Kube124,
framework.WithClusterUpgrade(api.WithKubernetesVersion(v1alpha1.Kube124)),
provider.WithProviderUpgrade(framework.UpdateNutanixUbuntuTemplate124Var()),
provider.WithProviderUpgrade(framework.GetUbuntu124NutanixFillers()...),
)
}

Expand Down
137 changes: 76 additions & 61 deletions test/framework/nutanix.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package framework

import (
"fmt"
"os"
"strings"
"testing"

"github.com/aws/eks-anywhere/internal/pkg/api"
Expand Down Expand Up @@ -35,7 +37,7 @@ const (
nutanixPodCidrVar = "T_NUTANIX_POD_CIDR"
nutanixServiceCidrVar = "T_NUTANIX_SERVICE_CIDR"

nutanixMachineTemplateIDTypeVar = "T_NUTANIX_TEMPLATE_ID_TYPE"
nutanixMachineTemplateIDTypeVar = "T_NUTANIX_MACHINE_TEMPLATE_ID_TYPE"

nutanixTemplateNameUbuntu121Var = "T_NUTANIX_TEMPLATE_NAME_UBUNTU_1_21"
nutanixTemplateNameUbuntu122Var = "T_NUTANIX_TEMPLATE_NAME_UBUNTU_1_22"
Expand Down Expand Up @@ -184,98 +186,111 @@ func (s *Nutanix) WithProviderUpgrade(fillers ...api.NutanixFiller) ClusterE2ETe
// and the "ubuntu" osFamily in all machine configs.
func WithUbuntu121Nutanix() NutanixOpt {
return func(v *Nutanix) {
nutanixMachineTemplateIDType := os.Getenv(nutanixMachineTemplateIDTypeVar)
if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierName) {
v.fillers = append(v.fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateNameUbuntu121Var, api.WithNutanixMachineTemplateImageName),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
} else if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierUUID) {
v.fillers = append(v.fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateUUIDUbuntu121Var, api.WithNutanixMachineTemplateImageUUID),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
}
v.fillers = append(v.fillers, GetUbuntu121NutanixFillers()...)
}
}

// WithUbuntu122Nutanix returns a NutanixOpt that adds API fillers to use a Ubuntu vSphere template for k8s 1.22
// and the "ubuntu" osFamily in all machine configs.
func WithUbuntu122Nutanix() NutanixOpt {
return func(v *Nutanix) {
nutanixMachineTemplateIDType := os.Getenv(nutanixMachineTemplateIDTypeVar)
if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierName) {
v.fillers = append(v.fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateNameUbuntu122Var, api.WithNutanixMachineTemplateImageName),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
} else if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierUUID) {
v.fillers = append(v.fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateUUIDUbuntu122Var, api.WithNutanixMachineTemplateImageUUID),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
}
v.fillers = append(v.fillers, GetUbuntu122NutanixFillers()...)
}
}

// WithUbuntu123Nutanix returns a NutanixOpt that adds API fillers to use a Ubuntu vSphere template for k8s 1.23
// and the "ubuntu" osFamily in all machine configs.
func WithUbuntu123Nutanix() NutanixOpt {
return func(v *Nutanix) {
nutanixMachineTemplateIDType := os.Getenv(nutanixMachineTemplateIDTypeVar)
if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierName) {
v.fillers = append(v.fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateNameUbuntu123Var, api.WithNutanixMachineTemplateImageName),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
} else if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierUUID) {
v.fillers = append(v.fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateUUIDUbuntu123Var, api.WithNutanixMachineTemplateImageUUID),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
}
v.fillers = append(v.fillers, GetUbuntu123NutanixFillers()...)
}
}

// WithUbuntu124Nutanix returns a NutanixOpt that adds API fillers to use a Ubuntu vSphere template for k8s 1.24
// and the "ubuntu" osFamily in all machine configs.
func WithUbuntu124Nutanix() NutanixOpt {
return func(v *Nutanix) {
nutanixMachineTemplateIDType := os.Getenv(nutanixMachineTemplateIDTypeVar)
if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierName) {
v.fillers = append(v.fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateNameUbuntu124Var, api.WithNutanixMachineTemplateImageName),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
} else if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierUUID) {
v.fillers = append(v.fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateUUIDUbuntu124Var, api.WithNutanixMachineTemplateImageUUID),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
}
v.fillers = append(v.fillers, GetUbuntu124NutanixFillers()...)
}
}

// UpdateNutanixUbuntuTemplate121Var returns NutanixFiller by reading the env var and setting machine config's
// GetUbuntu121NutanixFillers returns NutanixFiller by reading the env var and setting machine config's
// image name parameter in the spec.
func UpdateNutanixUbuntuTemplate121Var() api.NutanixFiller {
return api.WithNutanixStringFromEnvVar(nutanixTemplateUbuntu121Var, api.WithNutanixMachineTemplateImageName)
func GetUbuntu121NutanixFillers() []api.NutanixFiller {
var fillers []api.NutanixFiller
nutanixMachineTemplateIDType := os.Getenv(nutanixMachineTemplateIDTypeVar)
if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierName) {
fillers = append(fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateNameUbuntu121Var, api.WithNutanixMachineTemplateImageName),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
} else if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierUUID) {
fillers = append(fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateUUIDUbuntu121Var, api.WithNutanixMachineTemplateImageUUID),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
}
return fillers
}

// UpdateNutanixUbuntuTemplate122Var returns NutanixFiller by reading the env var and setting machine config's
// GetUbuntu122NutanixFillers returns NutanixFiller by reading the env var and setting machine config's
// image name parameter in the spec.
func UpdateNutanixUbuntuTemplate122Var() api.NutanixFiller {
return api.WithNutanixStringFromEnvVar(nutanixTemplateUbuntu122Var, api.WithNutanixMachineTemplateImageName)
func GetUbuntu122NutanixFillers() []api.NutanixFiller {
var fillers []api.NutanixFiller
nutanixMachineTemplateIDType := os.Getenv(nutanixMachineTemplateIDTypeVar)
if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierName) {
fillers = append(fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateNameUbuntu122Var, api.WithNutanixMachineTemplateImageName),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
} else if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierUUID) {
fillers = append(fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateUUIDUbuntu122Var, api.WithNutanixMachineTemplateImageUUID),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
}
return fillers
}

// UpdateNutanixUbuntuTemplate123Var returns NutanixFiller by reading the env var and setting machine config's
// GetUbuntu123NutanixFillers returns NutanixFiller by reading the env var and setting machine config's
// image name parameter in the spec.
func UpdateNutanixUbuntuTemplate123Var() api.NutanixFiller {
return api.WithNutanixStringFromEnvVar(nutanixTemplateUbuntu123Var, api.WithNutanixMachineTemplateImageName)
func GetUbuntu123NutanixFillers() []api.NutanixFiller {
var fillers []api.NutanixFiller
nutanixMachineTemplateIDType := os.Getenv(nutanixMachineTemplateIDTypeVar)
if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierName) {
fillers = append(fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateNameUbuntu123Var, api.WithNutanixMachineTemplateImageName),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
} else if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierUUID) {
fillers = append(fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateUUIDUbuntu123Var, api.WithNutanixMachineTemplateImageUUID),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
}
return fillers
}

// UpdateNutanixUbuntuTemplate124Var returns NutanixFiller by reading the env var and setting machine config's
// GetUbuntu124NutanixFillers returns NutanixFiller by reading the env var and setting machine config's
// image name parameter in the spec.
func UpdateNutanixUbuntuTemplate124Var() api.NutanixFiller {
return api.WithNutanixStringFromEnvVar(nutanixTemplateUbuntu124Var, api.WithNutanixMachineTemplateImageName)
func GetUbuntu124NutanixFillers() []api.NutanixFiller {
fmt.Println("here 1")
var fillers []api.NutanixFiller
nutanixMachineTemplateIDType := strings.Trim(os.Getenv(nutanixMachineTemplateIDTypeVar), "\"")
nutanixMachineTemplateIDType = strings.Trim(nutanixMachineTemplateIDType, "'")
fmt.Printf("nutanixMachineTemplateIDType %s\n", nutanixMachineTemplateIDType)
if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierName) {
fmt.Println("here name")
fillers = append(fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateNameUbuntu124Var, api.WithNutanixMachineTemplateImageName),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
} else if nutanixMachineTemplateIDType == string(anywherev1.NutanixIdentifierUUID) {
fmt.Println("here uuid")
fillers = append(fillers,
api.WithNutanixStringFromEnvVar(nutanixTemplateUUIDUbuntu124Var, api.WithNutanixMachineTemplateImageUUID),
api.WithOsFamilyForAllNutanixMachines(anywherev1.Ubuntu),
)
}
return fillers
}

0 comments on commit f23b655

Please sign in to comment.