Skip to content

Commit

Permalink
test machine deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
muraee committed Mar 3, 2023
1 parent 5c84246 commit 2b5062f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
11 changes: 5 additions & 6 deletions test/e2e/suites/unmanaged/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func assertSpotInstanceType(instanceID string) {
Expect(len(result.Reservations[0].Instances)).To(Equal(1))
}

func assertInstanceMetadataOptions(instanceID string) {
func assertInstanceMetadataOptions(instanceID string, expected infrav1.InstanceMetadataOptions) {
ginkgo.By(fmt.Sprintf("Finding EC2 instance with ID: %s", instanceID))
ec2Client := ec2.New(e2eCtx.AWSSession)
input := &ec2.DescribeInstancesInput{
Expand All @@ -594,11 +594,10 @@ func assertInstanceMetadataOptions(instanceID string) {
metadataOptions := result.Reservations[0].Instances[0].MetadataOptions
Expect(metadataOptions).ToNot(BeNil())

// assert defaults
Expect(metadataOptions.HttpTokens).To(HaveValue(Equal(string(infrav1.HTTPTokensStateRequired)))) // IMDSv2 enabled
Expect(metadataOptions.HttpEndpoint).To(HaveValue(Equal(string(infrav1.InstanceMetadataEndpointStateEnabled))))
Expect(metadataOptions.InstanceMetadataTags).To(HaveValue(Equal(string(infrav1.InstanceMetadataEndpointStateDisabled))))
Expect(metadataOptions.HttpPutResponseHopLimit).To(HaveValue(Equal(1)))
Expect(metadataOptions.HttpTokens).To(HaveValue(Equal(string(expected.HTTPTokens)))) // IMDSv2 enabled
Expect(metadataOptions.HttpEndpoint).To(HaveValue(Equal(string(expected.HTTPEndpoint))))
Expect(metadataOptions.InstanceMetadataTags).To(HaveValue(Equal(string(expected.InstanceMetadataTags))))
Expect(metadataOptions.HttpPutResponseHopLimit).To(HaveValue(Equal(expected.HTTPPutResponseHopLimit)))
}

func terminateInstance(instanceID string) {
Expand Down
36 changes: 30 additions & 6 deletions test/e2e/suites/unmanaged/unmanaged_functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,38 @@ var _ = ginkgo.Context("[unmanaged] [functional]", func() {
Expect(awsCluster.Status.Bastion.State).To(Equal(infrav1.InstanceStateRunning))
expectAWSClusterConditions(awsCluster, []conditionAssertion{{infrav1.BastionHostReadyCondition, corev1.ConditionTrue, "", ""}})

controlPlaneMachines := framework.GetControlPlaneMachinesByCluster(ctx, framework.GetControlPlaneMachinesByClusterInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
mdName := clusterName + "-md01"
machineTempalte := makeAWSMachineTemplate(namespace.Name, mdName, e2eCtx.E2EConfig.GetVariable(shared.AwsNodeMachineType), nil)
machineTempalte.Spec.Template.Spec.InstanceMetadataOptions = &infrav1.InstanceMetadataOptions{
HTTPEndpoint: infrav1.InstanceMetadataEndpointStateEnabled,
HTTPPutResponseHopLimit: 1,
HTTPTokens: infrav1.HTTPTokensStateRequired, // IMDSv2
InstanceMetadataTags: infrav1.InstanceMetadataEndpointStateDisabled,
}

machineDeployment := makeMachineDeployment(namespace.Name, mdName, clusterName, nil, int32(1))
framework.CreateMachineDeployment(ctx, framework.CreateMachineDeploymentInput{
Creator: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
MachineDeployment: machineDeployment,
BootstrapConfigTemplate: makeJoinBootstrapConfigTemplate(namespace.Name, mdName),
InfraMachineTemplate: machineTempalte,
})

Expect(len(controlPlaneMachines)).To(Equal(1))
assertInstanceMetadataOptions(*controlPlaneMachines[0].Spec.ProviderID)
framework.WaitForMachineDeploymentNodesToExist(ctx, framework.WaitForMachineDeploymentNodesToExistInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
Cluster: result.Cluster,
MachineDeployment: machineDeployment,
}, e2eCtx.E2EConfig.GetIntervals("", "wait-worker-nodes")...)

workerMachines := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
MachineDeployment: *machineDeployment,
})
Expect(len(workerMachines)).To(Equal(1))

assertInstanceMetadataOptions(*workerMachines[0].Spec.ProviderID, *machineTempalte.Spec.Template.Spec.InstanceMetadataOptions)
ginkgo.By("PASSED!")
})
})
Expand Down

0 comments on commit 2b5062f

Please sign in to comment.