Skip to content

Commit

Permalink
test: implement nodeclaim.spec.terminationGracePeriod CEL tests
Browse files Browse the repository at this point in the history
Signed-off-by: wmgroot <wmgroot@gmail.com>
  • Loading branch information
wmgroot committed Jul 16, 2024
1 parent a122e25 commit 98c503c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/v1/nodeclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type NodeClaimSpec struct {
//
// The feature can also be used to allow maximum time limits for long-running jobs which can delay node termination with preStop hooks.
// If left undefined, the controller will wait indefinitely for pods to be drained.
// +kubebuilder:validation:Minimum:=0
// +kubebuilder:validation:Pattern=`^((([0-9]+(h|m))|([0-9]+h[0-9]+m))(0s)?)$`
// +kubebuilder:validation:Type="string"
// +optional
TerminationGracePeriod *metav1.Duration `json:"terminationGracePeriod,omitempty"`

Check failure on line 66 in pkg/apis/v1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.25.x)

must apply minimum to a numeric value, found string

Check failure on line 66 in pkg/apis/v1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / kind-e2e (1.25.x)

must apply minimum to a numeric value, found string

Check failure on line 66 in pkg/apis/v1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.26.x)

must apply minimum to a numeric value, found string

Check failure on line 66 in pkg/apis/v1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / kind-e2e (1.26.x)

must apply minimum to a numeric value, found string

Check failure on line 66 in pkg/apis/v1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.27.x)

must apply minimum to a numeric value, found string

Check failure on line 66 in pkg/apis/v1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / kind-e2e (1.27.x)

must apply minimum to a numeric value, found string

Check failure on line 66 in pkg/apis/v1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.28.x)

must apply minimum to a numeric value, found string

Check failure on line 66 in pkg/apis/v1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / kind-e2e (1.28.x)

must apply minimum to a numeric value, found string

Check failure on line 66 in pkg/apis/v1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.29.x)

must apply minimum to a numeric value, found string

Check failure on line 66 in pkg/apis/v1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.30.x)

must apply minimum to a numeric value, found string
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/v1/nodeclaim_validation_cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1_test
import (
"strconv"
"strings"
"time"

"sigs.k8s.io/karpenter/pkg/test"

Expand Down Expand Up @@ -223,4 +224,14 @@ var _ = Describe("Validation", func() {
Expect(env.Client.Create(ctx, nodeClaim)).ToNot(Succeed())
})
})
Context("TerminationGracePeriod", func() {
It("should succeed on a positive terminationGracePeriod duration", func() {
nodeClaim.Spec.TerminationGracePeriod = &metav1.Duration{Duration: time.Second * 300}
Expect(env.Client.Create(ctx, nodeClaim)).To(Succeed())
})
It("should fail on a negative terminationGracePeriod duration", func() {
nodeClaim.Spec.TerminationGracePeriod = &metav1.Duration{Duration: time.Second * -30}
Expect(env.Client.Create(ctx, nodeClaim)).ToNot(Succeed())
})
})
})
10 changes: 10 additions & 0 deletions pkg/apis/v1/nodepool_validation_cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,14 @@ var _ = Describe("CEL/Validation", func() {
}
})
})
Context("TerminationGracePeriod", func() {
It("should succeed on a positive terminationGracePeriod duration", func() {
nodePool.Spec.Template.Spec.TerminationGracePeriod = &metav1.Duration{Duration: time.Second * 300}
Expect(env.Client.Create(ctx, nodePool)).To(Succeed())
})
It("should fail on a negative terminationGracePeriod duration", func() {
nodePool.Spec.Template.Spec.TerminationGracePeriod = &metav1.Duration{Duration: time.Second * -30}
Expect(env.Client.Create(ctx, nodePool)).ToNot(Succeed())
})
})
})
3 changes: 3 additions & 0 deletions pkg/apis/v1beta1/nodeclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type NodeClaimSpec struct {
//
// The feature can also be used to allow maximum time limits for long-running jobs which can delay node termination with preStop hooks.
// If left undefined, the controller will wait indefinitely for pods to be drained.
// +kubebuilder:validation:Minimum:=0
// +kubebuilder:validation:Pattern=`^((([0-9]+(h|m))|([0-9]+h[0-9]+m))(0s)?)$`
// +kubebuilder:validation:Type="string"
// +optional
TerminationGracePeriod *metav1.Duration `json:"terminationGracePeriod,omitempty"`

Check failure on line 73 in pkg/apis/v1beta1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.25.x)

must apply minimum to a numeric value, found string

Check failure on line 73 in pkg/apis/v1beta1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / kind-e2e (1.25.x)

must apply minimum to a numeric value, found string

Check failure on line 73 in pkg/apis/v1beta1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.26.x)

must apply minimum to a numeric value, found string

Check failure on line 73 in pkg/apis/v1beta1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / kind-e2e (1.26.x)

must apply minimum to a numeric value, found string

Check failure on line 73 in pkg/apis/v1beta1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.27.x)

must apply minimum to a numeric value, found string

Check failure on line 73 in pkg/apis/v1beta1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / kind-e2e (1.27.x)

must apply minimum to a numeric value, found string

Check failure on line 73 in pkg/apis/v1beta1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.28.x)

must apply minimum to a numeric value, found string

Check failure on line 73 in pkg/apis/v1beta1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / kind-e2e (1.28.x)

must apply minimum to a numeric value, found string

Check failure on line 73 in pkg/apis/v1beta1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.29.x)

must apply minimum to a numeric value, found string

Check failure on line 73 in pkg/apis/v1beta1/nodeclaim.go

View workflow job for this annotation

GitHub Actions / presubmit (1.30.x)

must apply minimum to a numeric value, found string
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/v1beta1/nodeclaim_validation_cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,14 @@ var _ = Describe("Validation", func() {
})
})
})
Context("TerminationGracePeriod", func() {
It("should succeed on a positive terminationGracePeriod duration", func() {
nodeClaim.Spec.TerminationGracePeriod = &metav1.Duration{Duration: time.Second * 300}
Expect(env.Client.Create(ctx, nodeClaim)).To(Succeed())
})
It("should fail on a negative terminationGracePeriod duration", func() {
nodeClaim.Spec.TerminationGracePeriod = &metav1.Duration{Duration: time.Second * -30}
Expect(env.Client.Create(ctx, nodeClaim)).ToNot(Succeed())
})
})
})
10 changes: 10 additions & 0 deletions pkg/apis/v1beta1/nodepool_validation_cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,4 +878,14 @@ var _ = Describe("CEL/Validation", func() {
Expect(env.Client.Create(ctx, nodePool)).ToNot(Succeed())
})
})
Context("TerminationGracePeriod", func() {
It("should succeed on a positive terminationGracePeriod duration", func() {
nodePool.Spec.Template.Spec.TerminationGracePeriod = &metav1.Duration{Duration: time.Second * 300}
Expect(env.Client.Create(ctx, nodePool)).To(Succeed())
})
It("should fail on a negative terminationGracePeriod duration", func() {
nodePool.Spec.Template.Spec.TerminationGracePeriod = &metav1.Duration{Duration: time.Second * -30}
Expect(env.Client.Create(ctx, nodePool)).ToNot(Succeed())
})
})
})

0 comments on commit 98c503c

Please sign in to comment.