Skip to content

Commit

Permalink
Add e2e test for Node Requirement Drift
Browse files Browse the repository at this point in the history
  • Loading branch information
engedaam committed Jul 31, 2023
1 parent e08a862 commit 431e1c3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
51 changes: 49 additions & 2 deletions test/suites/drift/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,50 @@ var _ = Describe("Drift", Label("AWS"), func() {
env.ExpectUpdated(pod)
env.EventuallyExpectNotFound(pod, node)
})
DescribeTable("NodeRequirement Drift", func(provisionerOption test.ProvisionerOptions) {
nodeTemplate := awstest.AWSNodeTemplate(v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{
SecurityGroupSelector: map[string]string{"karpenter.sh/discovery": settings.FromContext(env.Context).ClusterName},
SubnetSelector: map[string]string{"karpenter.sh/discovery": settings.FromContext(env.Context).ClusterName},
}})
provisioner := test.Provisioner(test.ProvisionerOptions{
Requirements: []v1.NodeSelectorRequirement{{Key: v1alpha5.LabelCapacityType, Operator: v1.NodeSelectorOpIn, Values: []string{v1alpha5.CapacityTypeOnDemand}}},
ProviderRef: &v1alpha5.MachineTemplateRef{Name: nodeTemplate.Name},
})
// Add a do-not-evict pod so that we can check node metadata before we deprovision
pod := test.Pod(test.PodOptions{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
v1alpha5.DoNotEvictPodAnnotationKey: "true",
},
},
})

provisionerOption.ObjectMeta = provisioner.ObjectMeta
updatedProvisioner := test.Provisioner(
test.ProvisionerOptions{ProviderRef: &v1alpha5.MachineTemplateRef{Name: nodeTemplate.Name}},
provisionerOption,
)

env.ExpectCreated(pod, nodeTemplate, provisioner)
machine := env.EventuallyExpectCreatedMachineCount("==", 1)[0]
node := env.EventuallyExpectCreatedNodeCount("==", 1)[0]
env.EventuallyExpectHealthy(pod)

env.ExpectCreatedOrUpdated(updatedProvisioner)

By("validating the drifted status condition has propagated")
EventuallyWithOffset(1, func(g Gomega) {
g.Expect(env.Client.Get(env, client.ObjectKeyFromObject(machine), machine)).To(Succeed())
g.Expect(machine.StatusConditions().GetCondition(v1alpha5.MachineDrifted)).ToNot(BeNil())
g.Expect(machine.StatusConditions().GetCondition(v1alpha5.MachineDrifted).IsTrue()).To(BeTrue())
}).Should(Succeed())

delete(pod.Annotations, v1alpha5.DoNotEvictPodAnnotationKey)
env.ExpectUpdated(pod)
env.EventuallyExpectNotFound(pod, node)
},
Entry("NodeRequirement Drift", test.ProvisionerOptions{Requirements: []v1.NodeSelectorRequirement{{Key: v1alpha5.LabelCapacityType, Operator: v1.NodeSelectorOpIn, Values: []string{v1alpha5.CapacityTypeSpot}}}}),
)
Describe("Provisioner Drift", func() {
var pod *v1.Pod
var nodeTemplate *v1alpha1.AWSNodeTemplate
Expand All @@ -279,7 +323,10 @@ var _ = Describe("Drift", Label("AWS"), func() {
SecurityGroupSelector: map[string]string{"karpenter.sh/discovery": settings.FromContext(env.Context).ClusterName},
SubnetSelector: map[string]string{"karpenter.sh/discovery": settings.FromContext(env.Context).ClusterName},
}})
provisioner = test.Provisioner(test.ProvisionerOptions{ProviderRef: &v1alpha5.MachineTemplateRef{Name: nodeTemplate.Name}})
provisioner = test.Provisioner(test.ProvisionerOptions{
Requirements: []v1.NodeSelectorRequirement{{Key: v1alpha5.LabelCapacityType, Operator: v1.NodeSelectorOpIn, Values: []string{v1alpha5.CapacityTypeOnDemand}}},
ProviderRef: &v1alpha5.MachineTemplateRef{Name: nodeTemplate.Name},
})
// Add a do-not-evict pod so that we can check node metadata before we deprovision
pod = test.Pod(test.PodOptions{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -289,7 +336,7 @@ var _ = Describe("Drift", Label("AWS"), func() {
},
})
})
DescribeTable("provisioner static drift", func(fieldName string, provisionerOption test.ProvisionerOptions) {
DescribeTable("provisioner drift", func(fieldName string, provisionerOption test.ProvisionerOptions) {
provisionerOption.ObjectMeta = provisioner.ObjectMeta
updatedProvisioner := test.Provisioner(
test.ProvisionerOptions{ProviderRef: &v1alpha5.MachineTemplateRef{Name: nodeTemplate.Name}},
Expand Down
2 changes: 1 addition & 1 deletion website/content/en/preview/concepts/deprovisioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Read the [Drift Design](https://github.com/aws/karpenter-core/pull/366/files) fo
| Taints | x | | | x |
| Labels | x | | | x |
| Annotations | x | | | x |
| Node Requirements | | x | | |
| Node Requirements | | x | | x |
| Kubelet Configuration | x | | | x |
| Weight | | | x | NA |
| Limits | | | x | NA |
Expand Down

0 comments on commit 431e1c3

Please sign in to comment.