Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions cmd/infra/aws/util/sts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,8 @@ func TestParseSTSCredentialsFileV2_RealWorldFormat(t *testing.T) {
}

creds, err := ParseSTSCredentialsFileV2(tmpFile.Name())
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}

if creds == nil {
t.Fatal("Expected non-nil credentials")
if err != nil || creds == nil {
t.Fatalf("Unexpected error or nil credentials: err=%v, creds=%v", err, creds)
}

expectedAccessKey := "ASIAIOSFODNN7EXAMPLE"
Expand Down
36 changes: 21 additions & 15 deletions test/e2e/create_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ func TestOnCreateAPIUX(t *testing.T) {
g.Expect(err).NotTo(HaveOccurred(), "couldn't get client")

testCases := []struct {
name string
file string
validations []struct {
name string
file string
platformType hyperv1.PlatformType // empty = use globalOpts.Platform
validations []struct {
name string
mutateInput func(*hyperv1.HostedCluster)
expectedErrorSubstring string
Expand Down Expand Up @@ -319,8 +320,9 @@ func TestOnCreateAPIUX(t *testing.T) {
},
},
{
name: "when GCP project/region validation is applied it should handle formats",
file: "hostedcluster-base.yaml",
name: "when GCP project/region validation is applied it should handle formats",
file: "hostedcluster-base.yaml",
platformType: hyperv1.GCPPlatform,
validations: []struct {
name string
mutateInput func(*hyperv1.HostedCluster)
Expand Down Expand Up @@ -359,8 +361,9 @@ func TestOnCreateAPIUX(t *testing.T) {
},
},
{
name: "when GCP network configuration is not valid it should fail",
file: "hostedcluster-base.yaml",
name: "when GCP network configuration is not valid it should fail",
file: "hostedcluster-base.yaml",
platformType: hyperv1.GCPPlatform,
validations: []struct {
name string
mutateInput func(*hyperv1.HostedCluster)
Expand Down Expand Up @@ -1363,8 +1366,9 @@ func TestOnCreateAPIUX(t *testing.T) {
},
},
{
name: "when Azure authentication configuration is not properly configured it should fail",
file: "hostedcluster-base.yaml",
name: "when Azure authentication configuration is not properly configured it should fail",
file: "hostedcluster-base.yaml",
platformType: hyperv1.AzurePlatform,
validations: []struct {
name string
mutateInput func(*hyperv1.HostedCluster)
Expand All @@ -1373,7 +1377,6 @@ func TestOnCreateAPIUX(t *testing.T) {
{
name: "when azureAuthenticationConfigType is ManagedIdentities but managedIdentities field is missing it should fail",
mutateInput: func(hc *hyperv1.HostedCluster) {
hc.Spec.Platform.Type = hyperv1.AzurePlatform
hc.Spec.Platform.Azure = &hyperv1.AzurePlatformSpec{
Location: "eastus",
ResourceGroupName: "test-rg",
Expand All @@ -1393,7 +1396,6 @@ func TestOnCreateAPIUX(t *testing.T) {
{
name: "when azureAuthenticationConfigType is WorkloadIdentities but workloadIdentities field is missing it should fail",
mutateInput: func(hc *hyperv1.HostedCluster) {
hc.Spec.Platform.Type = hyperv1.AzurePlatform
hc.Spec.Platform.Azure = &hyperv1.AzurePlatformSpec{
Location: "eastus",
ResourceGroupName: "test-rg",
Expand All @@ -1413,7 +1415,6 @@ func TestOnCreateAPIUX(t *testing.T) {
{
name: "when azureAuthenticationConfigType is ManagedIdentities but workloadIdentities field is present it should fail",
mutateInput: func(hc *hyperv1.HostedCluster) {
hc.Spec.Platform.Type = hyperv1.AzurePlatform
hc.Spec.Platform.Azure = &hyperv1.AzurePlatformSpec{
Location: "eastus",
ResourceGroupName: "test-rg",
Expand Down Expand Up @@ -1441,7 +1442,6 @@ func TestOnCreateAPIUX(t *testing.T) {
{
name: "when azureAuthenticationConfigType is WorkloadIdentities but managedIdentities field is present it should fail",
mutateInput: func(hc *hyperv1.HostedCluster) {
hc.Spec.Platform.Type = hyperv1.AzurePlatform
hc.Spec.Platform.Azure = &hyperv1.AzurePlatformSpec{
Location: "eastus",
ResourceGroupName: "test-rg",
Expand Down Expand Up @@ -1634,13 +1634,19 @@ func TestOnCreateAPIUX(t *testing.T) {

t.Logf("Running validation %q", v.name)
hostedCluster := assets.ShouldHostedCluster(content.ReadFile, fmt.Sprintf("assets/%s", tc.file))
// Set platform type: explicit per test case, or fall back to environment
if tc.platformType != "" {
hostedCluster.Spec.Platform.Type = tc.platformType
} else {
hostedCluster.Spec.Platform.Type = globalOpts.Platform
}
// Generate unique name to avoid "already exists" race condition
hostedCluster.Name = fmt.Sprintf("test-%d-%d", time.Now().UnixNano(), i)
defer client.Delete(ctx, hostedCluster)
v.mutateInput(hostedCluster)

// Skip GCP validations outside TechPreviewNoUpgrade
if hostedCluster.Spec.Platform.Type == hyperv1.GCPPlatform && os.Getenv("TECH_PREVIEW_NO_UPGRADE") != "true" {
if tc.platformType == hyperv1.GCPPlatform && os.Getenv("TECH_PREVIEW_NO_UPGRADE") != "true" {
t.Logf("Skipping GCP validation outside TechPreviewNoUpgrade: %s", v.name)
continue
}
Expand Down Expand Up @@ -2426,7 +2432,7 @@ func TestCreateCluster(t *testing.T) {

clusterOpts := globalOpts.DefaultClusterOptions(t)
zones := strings.Split(globalOpts.ConfigurableClusterOptions.Zone.String(), ",")
if len(zones) >= 3 {
if len(zones) >= 3 && globalOpts.Platform == hyperv1.AWSPlatform {
// CreateCluster also tests multi-zone workers work properly if a sufficient number of zones are configured
t.Logf("Sufficient zones available for InfrastructureAvailabilityPolicy HighlyAvailable")
clusterOpts.AWSPlatform.Zones = zones
Expand Down
22 changes: 20 additions & 2 deletions test/e2e/util/hypershift_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ func (h *hypershiftTest) WithAssetReader(reader assets.AssetReader) *hypershiftT
return h
}

// numExpectedNodes returns the number of nodes expected for a cluster based on platform.
// On AWS and Azure, nodes are spread across zones, so the count is replicas * zones.
// On all other platforms, the count is just replicas.
func numExpectedNodes(opts *PlatformAgnosticOptions, platform hyperv1.PlatformType) int32 {
switch platform {
case hyperv1.AWSPlatform:
if len(opts.AWSPlatform.Zones) > 0 {
return opts.NodePoolReplicas * int32(len(opts.AWSPlatform.Zones))
}
case hyperv1.AzurePlatform:
if len(opts.AzurePlatform.AvailabilityZones) > 0 {
return opts.NodePoolReplicas * int32(len(opts.AzurePlatform.AvailabilityZones))
}
}
return opts.NodePoolReplicas
Comment thread
devguyio marked this conversation as resolved.
}

func (h *hypershiftTest) Execute(opts *PlatformAgnosticOptions, platform hyperv1.PlatformType, artifactDir, name string, serviceAccountSigningKey []byte) {
artifactDir = filepath.Join(artifactDir, artifactSubdirFor(h.T))

Expand Down Expand Up @@ -124,7 +141,7 @@ func (h *hypershiftTest) Execute(opts *PlatformAgnosticOptions, platform hyperv1
h.after(hostedCluster, platform)

if h.Failed() {
numNodes := opts.NodePoolReplicas * int32(len(opts.AWSPlatform.Zones))
numNodes := numExpectedNodes(opts, platform)
h.Logf("Summarizing unexpected conditions for HostedCluster %s ", hostedCluster.Name)
ValidateHostedClusterConditions(h.T, h.ctx, h.client, hostedCluster, numNodes > 0, 2*time.Second)
}
Expand All @@ -134,7 +151,8 @@ func (h *hypershiftTest) Execute(opts *PlatformAgnosticOptions, platform hyperv1
func (h *hypershiftTest) before(hostedCluster *hyperv1.HostedCluster, opts *PlatformAgnosticOptions, platform hyperv1.PlatformType) {
h.Run("ValidateHostedCluster", func(t *testing.T) {
if platform != hyperv1.NonePlatform && hostedCluster.Spec.Networking.NetworkType != hyperv1.Other {
if opts.AWSPlatform.EndpointAccess == string(hyperv1.Private) {
isPrivate := platform == hyperv1.AWSPlatform && opts.AWSPlatform.EndpointAccess == string(hyperv1.Private)
Comment thread
devguyio marked this conversation as resolved.
if isPrivate {
ValidatePrivateCluster(t, h.ctx, h.client, hostedCluster, opts)
} else {
ValidatePublicCluster(t, h.ctx, h.client, hostedCluster, opts)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2857,7 +2857,7 @@ func ValidatePublicCluster(t *testing.T, ctx context.Context, client crclient.Cl
}

// Wait for Nodes to be Ready
numNodes := clusterOpts.NodePoolReplicas * int32(len(clusterOpts.AWSPlatform.Zones))
numNodes := numExpectedNodes(clusterOpts, hostedCluster.Spec.Platform.Type)
WaitForNReadyNodes(t, ctx, guestClient, numNodes, hostedCluster.Spec.Platform.Type)

// rollout will not complete if there are no worker nodes.
Expand Down Expand Up @@ -2910,7 +2910,7 @@ func ValidatePrivateCluster(t *testing.T, ctx context.Context, client crclient.C
// Ensure NodePools have all Nodes ready.
WaitForNodePoolDesiredNodes(t, ctx, client, hostedCluster)

numNodes := clusterOpts.NodePoolReplicas * int32(len(clusterOpts.AWSPlatform.Zones))
numNodes := numExpectedNodes(clusterOpts, hostedCluster.Spec.Platform.Type)
// rollout will not complete if there are no worker nodes.
if numNodes > 0 {
WaitForImageRollout(t, ctx, client, hostedCluster)
Expand Down