Skip to content

Commit

Permalink
Add Expiration testing for E2E for v1beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Oct 23, 2023
1 parent 6c50872 commit 26dec99
Show file tree
Hide file tree
Showing 3 changed files with 401 additions and 1 deletion.
8 changes: 8 additions & 0 deletions test/pkg/environment/common/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

coreapis "github.com/aws/karpenter-core/pkg/apis"
"github.com/aws/karpenter-core/pkg/apis/v1beta1"
"github.com/aws/karpenter-core/pkg/operator"
"github.com/aws/karpenter-core/pkg/operator/injection"
"github.com/aws/karpenter/pkg/apis"
Expand Down Expand Up @@ -116,6 +117,13 @@ func NewClient(ctx context.Context, config *rest.Config) client.Client {
node := o.(*v1.Node)
return []string{strconv.FormatBool(node.Spec.Unschedulable)}
}))
lo.Must0(cache.IndexField(ctx, &v1.Node{}, "spec.taints[*].karpenter.sh/disruption", func(o client.Object) []string {
node := o.(*v1.Node)
t, _ := lo.Find(node.Spec.Taints, func(t v1.Taint) bool {
return t.Key == v1beta1.DisruptionTaintKey
})
return []string{t.Value}
}))

c := lo.Must(client.New(config, client.Options{Scheme: scheme, Cache: &client.CacheOptions{Reader: cache}}))

Expand Down
36 changes: 35 additions & 1 deletion test/pkg/environment/common/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func (env *Environment) ConsistentlyExpectMachineCount(comparator string, count
return lo.ToSlicePtr(machineList.Items)
}

func (env *Environment) EventuallyExpectCordonedNodeCount(comparator string, count int) []*v1.Node {
func (env *Environment) EventuallyExpectCordonedNodeCountLegacy(comparator string, count int) []*v1.Node {
GinkgoHelper()
By(fmt.Sprintf("waiting for cordoned nodes to be %s to %d", comparator, count))
nodeList := &v1.NodeList{}
Expand All @@ -472,6 +472,40 @@ func (env *Environment) EventuallyExpectCordonedNodeCount(comparator string, cou
return lo.ToSlicePtr(nodeList.Items)
}

func (env *Environment) EventuallyExpectNodesUncordonedLegacyWithTimeout(timeout time.Duration, nodes ...*v1.Node) {
GinkgoHelper()
By(fmt.Sprintf("waiting for %d nodes to be uncordoned", len(nodes)))
nodeList := &v1.NodeList{}
Eventually(func(g Gomega) {
g.Expect(env.Client.List(env, nodeList, client.MatchingFields{"spec.unschedulable": "true"})).To(Succeed())
cordonedNodeNames := lo.Map(nodeList.Items, func(n v1.Node, _ int) string { return n.Name })
g.Expect(cordonedNodeNames).ToNot(ContainElements(lo.Map(nodes, func(n *v1.Node, _ int) interface{} { return n.Name })...))
}).WithTimeout(timeout).Should(Succeed())
}

func (env *Environment) EventuallyExpectCordonedNodeCount(comparator string, count int) []*v1.Node {
GinkgoHelper()
By(fmt.Sprintf("waiting for cordoned nodes to be %s to %d", comparator, count))
nodeList := &v1.NodeList{}
Eventually(func(g Gomega) {
g.Expect(env.Client.List(env, nodeList, client.MatchingFields{"spec.taints[*].karpenter.sh/disruption": "disrupting"})).To(Succeed())
g.Expect(len(nodeList.Items)).To(BeNumerically(comparator, count),
fmt.Sprintf("expected %d cordoned nodes, had %d (%v)", count, len(nodeList.Items), NodeNames(lo.ToSlicePtr(nodeList.Items))))
}).Should(Succeed())
return lo.ToSlicePtr(nodeList.Items)
}

func (env *Environment) EventuallyExpectNodesUncordonedWithTimeout(timeout time.Duration, nodes ...*v1.Node) {
GinkgoHelper()
By(fmt.Sprintf("waiting for %d nodes to be uncordoned", len(nodes)))
nodeList := &v1.NodeList{}
Eventually(func(g Gomega) {
g.Expect(env.Client.List(env, nodeList, client.MatchingFields{"spec.taints[*].karpenter.sh/disruption": "disrupting"})).To(Succeed())
cordonedNodeNames := lo.Map(nodeList.Items, func(n v1.Node, _ int) string { return n.Name })
g.Expect(cordonedNodeNames).ToNot(ContainElements(lo.Map(nodes, func(n *v1.Node, _ int) interface{} { return n.Name })...))
}).WithTimeout(timeout).Should(Succeed())
}

func (env *Environment) EventuallyExpectNodeCount(comparator string, count int) []*v1.Node {
GinkgoHelper()
By(fmt.Sprintf("waiting for nodes to be %s to %d", comparator, count))
Expand Down

0 comments on commit 26dec99

Please sign in to comment.