Skip to content

Commit

Permalink
Update e2e test flow so cluster ip pool is not required (#1213)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwesterfieldjr authored and danbudris committed Feb 22, 2022
1 parent 0ed18a9 commit cb0447f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
5 changes: 4 additions & 1 deletion internal/test/e2e/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ func (e *E2ESession) setupVSphereEnv(testRegex string) error {
}
}

e.testEnvVars[e2etests.ClusterIPPoolEnvVar] = e.ipPool.ToString()
ipPool := e.ipPool.ToString()
if ipPool != "" {
e.testEnvVars[e2etests.ClusterIPPoolEnvVar] = ipPool
}

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ VSPHERE_USERNAME
VSPHERE_PASSWORD
T_VSPHERE_CIDR
GOVC_URL
T_CLUSTER_IP_POOL
T_CLUSTER_IP_POOL # comma-separated list of CP ip addresses
```

# OIDC tests requisites
Expand Down
29 changes: 23 additions & 6 deletions test/framework/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/aws/eks-anywhere/internal/pkg/api"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/executables"
"github.com/aws/eks-anywhere/pkg/networkutils"
)

const (
Expand Down Expand Up @@ -56,7 +57,6 @@ var requiredEnvVars = []string{
cidrVar,
privateNetworkCidrVar,
govcUrlVar,
ClusterIPPoolEnvVar,
}

type VSphere struct {
Expand Down Expand Up @@ -114,11 +114,6 @@ func NewVSphere(t *testing.T, opts ...VSphereOpt) *VSphere {
}

v.cidr = os.Getenv(cidrVar)
clusterIP, err := PopIPFromEnv(ClusterIPPoolEnvVar)
if err != nil {
v.t.Fatalf("failed to pop cluster ip from test environment: %v", err)
}
v.clusterFillers = []api.ClusterFiller{api.WithControlPlaneEndpointIP(clusterIP)}

for _, opt := range opts {
opt(v)
Expand All @@ -127,6 +122,15 @@ func NewVSphere(t *testing.T, opts ...VSphereOpt) *VSphere {
return v
}

func (v *VSphere) generateUniqueIp() string {
ipgen := networkutils.NewIPGenerator(&networkutils.DefaultNetClient{})
ip, err := ipgen.GenerateUniqueIP(v.cidr)
if err != nil {
v.t.Fatalf("Error getting unique IP for vsphere: %v", err)
}
return ip
}

func WithUbuntu121() VSphereOpt {
return func(v *VSphere) {
v.fillers = append(v.fillers,
Expand Down Expand Up @@ -247,6 +251,19 @@ func (v *VSphere) WithNewVSphereWorkerNodeGroup(name string, workerNodeGroup *Wo
}

func (v *VSphere) ClusterConfigFillers() []api.ClusterFiller {
value, ok := os.LookupEnv(ClusterIPPoolEnvVar)
var clusterIP string
var err error
if ok && value != "" {
clusterIP, err = PopIPFromEnv(ClusterIPPoolEnvVar)
if err != nil {
v.t.Fatalf("failed to pop cluster ip from test environment: %v", err)
}
} else {
clusterIP = v.generateUniqueIp()
}

v.clusterFillers = append(v.clusterFillers, api.WithControlPlaneEndpointIP(clusterIP))
return v.clusterFillers
}

Expand Down

0 comments on commit cb0447f

Please sign in to comment.