Skip to content

Commit e5ed982

Browse files
fix PR: 5711 e2e
1 parent 15a2d14 commit e5ed982

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

test/e2e/suites/unmanaged/unmanaged_functional_test.go

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ var _ = ginkgo.Context("[unmanaged] [functional]", func() {
337337
configCluster.ControlPlaneMachineCount = ptr.To[int64](1)
338338
configCluster.WorkerMachineCount = ptr.To[int64](1)
339339
configCluster.Flavor = shared.SSMFlavor
340-
_, md, _ := createCluster(ctx, configCluster, result)
340+
cluster, md, _ := createCluster(ctx, configCluster, result)
341341

342342
workerMachines := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{
343343
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
@@ -352,6 +352,74 @@ var _ = ginkgo.Context("[unmanaged] [functional]", func() {
352352
})
353353
Expect(len(workerMachines)).To(Equal(1))
354354
Expect(len(controlPlaneMachines)).To(Equal(1))
355+
356+
ginkgo.By("Verifying AWSMachineTemplate capacity is populated for autoscaling from zero")
357+
awsMachineTemplateList := &infrav1.AWSMachineTemplateList{}
358+
err := e2eCtx.Environment.BootstrapClusterProxy.GetClient().List(ctx, awsMachineTemplateList, client.InNamespace(namespace.Name))
359+
Expect(err).To(BeNil())
360+
Expect(len(awsMachineTemplateList.Items)).To(BeNumerically(">", 0), "Expected at least one AWSMachineTemplate")
361+
362+
ginkgo.By(fmt.Sprintf("Found %d AWSMachineTemplates", len(awsMachineTemplateList.Items)))
363+
ginkgo.By(fmt.Sprintf("Cluster: name=%s, namespace=%s, infrastructureRef=%v",
364+
cluster.Name, cluster.Namespace, cluster.Spec.InfrastructureRef))
365+
366+
// Print each AWSMachineTemplate for debugging
367+
for i, template := range awsMachineTemplateList.Items {
368+
ginkgo.By(fmt.Sprintf("AWSMachineTemplate[%d]: %+v", i, template))
369+
}
370+
371+
foundTemplateWithCapacity := false
372+
foundTemplateWithNodeInfo := false
373+
ginkgo.By(fmt.Sprintf("DEBUG: Found %d AWSMachineTemplates in namespace %s", len(awsMachineTemplateList.Items), namespace.Name))
374+
for i, template := range awsMachineTemplateList.Items {
375+
ginkgo.By(fmt.Sprintf("DEBUG: Template[%d] - Name: %s", i, template.Name))
376+
ginkgo.By(fmt.Sprintf("DEBUG: Template[%d] - Spec.Template.Spec.InstanceType: %s", i, template.Spec.Template.Spec.InstanceType))
377+
ginkgo.By(fmt.Sprintf("DEBUG: Template[%d] - Status.Capacity: %v", i, template.Status.Capacity))
378+
ginkgo.By(fmt.Sprintf("DEBUG: Template[%d] - Status.NodeInfo: %+v", i, template.Status.NodeInfo))
379+
ginkgo.By(fmt.Sprintf("DEBUG: Template[%d] - Status.Conditions: %+v", i, template.Status.Conditions))
380+
381+
if len(template.Status.Capacity) > 0 {
382+
foundTemplateWithCapacity = true
383+
ginkgo.By(fmt.Sprintf("AWSMachineTemplate %s has capacity populated: %v", template.Name, template.Status.Capacity))
384+
Expect(template.Status.Capacity).To(HaveKey(corev1.ResourceCPU), "Expected CPU to be set in capacity")
385+
Expect(template.Status.Capacity).To(HaveKey(corev1.ResourceMemory), "Expected Memory to be set in capacity")
386+
} else {
387+
ginkgo.By(fmt.Sprintf("WARNING: Template %s has NO capacity populated", template.Name))
388+
}
389+
if template.Status.NodeInfo != nil {
390+
foundTemplateWithNodeInfo = true
391+
ginkgo.By(fmt.Sprintf("AWSMachineTemplate %s has nodeInfo populated: %v", template.Name, template.Status.NodeInfo))
392+
// Verify architecture is set (should be either amd64 or arm64 for AWS)
393+
ginkgo.By(fmt.Sprintf("DEBUG: Template %s - NodeInfo.Architecture: '%s' (len: %d)", template.Name, template.Status.NodeInfo.Architecture, len(template.Status.NodeInfo.Architecture)))
394+
ginkgo.By(fmt.Sprintf("DEBUG: Template %s - NodeInfo.OperatingSystem: '%s' (len: %d)", template.Name, template.Status.NodeInfo.OperatingSystem, len(template.Status.NodeInfo.OperatingSystem)))
395+
396+
// Verify architecture is set (should be either amd64 or arm64 for AWS)
397+
if len(template.Status.NodeInfo.Architecture) == 0 {
398+
ginkgo.By(fmt.Sprintf("ERROR: Template %s has empty Architecture field in NodeInfo", template.Name))
399+
}
400+
Expect(template.Status.NodeInfo.Architecture).ToNot(BeEmpty(), fmt.Sprintf("Expected architecture to be set in nodeInfo for template %s", template.Name))
401+
Expect(string(template.Status.NodeInfo.Architecture)).To(MatchRegexp("^(amd64|arm64)$"), fmt.Sprintf("Expected architecture to be amd64 or arm64 for template %s", template.Name))
402+
// Verify operating system is set (if available)
403+
// Note: OperatingSystem may be empty when:
404+
// 1. No explicit AMI ID is specified
405+
// 2. Kubernetes version cannot be determined (MachineDeployment not yet created)
406+
// 3. AMI lookup fails
407+
// In these cases, the controller falls back to instance type architecture only.
408+
// See: controllers/awsmachinetemplate_controller.go:319-323 (Strategy 3)
409+
if len(template.Status.NodeInfo.OperatingSystem) == 0 {
410+
ginkgo.By(fmt.Sprintf("INFO: Template %s has empty OperatingSystem (this is acceptable in fallback scenarios)", template.Name))
411+
ginkgo.By(fmt.Sprintf("DEBUG: Template %s full status: %+v", template.Name, template.Status))
412+
} else {
413+
ginkgo.By(fmt.Sprintf("INFO: Template %s has OperatingSystem set to: %s", template.Name, template.Status.NodeInfo.OperatingSystem))
414+
// If OperatingSystem is set, verify it's a valid value
415+
Expect(string(template.Status.NodeInfo.OperatingSystem)).To(MatchRegexp("^(linux|windows)$"), fmt.Sprintf("Expected operatingSystem to be linux or windows for template %s", template.Name))
416+
}
417+
} else {
418+
ginkgo.By(fmt.Sprintf("WARNING: Template %s has NodeInfo == nil", template.Name))
419+
}
420+
}
421+
Expect(foundTemplateWithCapacity).To(BeTrue(), "Expected at least one AWSMachineTemplate to have capacity populated")
422+
Expect(foundTemplateWithNodeInfo).To(BeTrue(), "Expected at least one AWSMachineTemplate to have nodeInfo populated")
355423
})
356424
})
357425

0 commit comments

Comments
 (0)