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 17, 2024
1 parent a122e25 commit c09227b
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kwok/charts/crds/karpenter.sh_nodeclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ spec:
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.
pattern: ^([0-9]+(\\.[0-9]+)?(s|m|h))+$
type: string
required:
- nodeClassRef
Expand Down Expand Up @@ -731,6 +732,7 @@ spec:
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.
pattern: ^([0-9]+(\\.[0-9]+)?(s|m|h))+$
type: string
required:
- nodeClassRef
Expand Down
2 changes: 2 additions & 0 deletions kwok/charts/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ spec:
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.
pattern: ^([0-9]+(\\.[0-9]+)?(s|m|h))+$
type: string
required:
- nodeClassRef
Expand Down Expand Up @@ -1009,6 +1010,7 @@ spec:
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.
pattern: ^([0-9]+(\\.[0-9]+)?(s|m|h))+$
type: string
required:
- nodeClassRef
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/crds/karpenter.sh_nodeclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ spec:
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.
pattern: ^([0-9]+(\\.[0-9]+)?(s|m|h))+$
type: string
required:
- nodeClassRef
Expand Down Expand Up @@ -727,6 +728,7 @@ spec:
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.
pattern: ^([0-9]+(\\.[0-9]+)?(s|m|h))+$
type: string
required:
- nodeClassRef
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ spec:
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.
pattern: ^([0-9]+(\\.[0-9]+)?(s|m|h))+$
type: string
required:
- nodeClassRef
Expand Down Expand Up @@ -1005,6 +1006,7 @@ spec:
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.
pattern: ^([0-9]+(\\.[0-9]+)?(s|m|h))+$
type: string
required:
- nodeClassRef
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/v1/nodeclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ 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:Pattern=`^([0-9]+(\\.[0-9]+)?(s|m|h))+$`
// +kubebuilder:validation:Type="string"
// +optional
TerminationGracePeriod *metav1.Duration `json:"terminationGracePeriod,omitempty"`
}
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())
})
})
})
2 changes: 2 additions & 0 deletions pkg/apis/v1beta1/nodeclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ 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:Pattern=`^([0-9]+(\\.[0-9]+)?(s|m|h))+$`
// +kubebuilder:validation:Type="string"
// +optional
TerminationGracePeriod *metav1.Duration `json:"terminationGracePeriod,omitempty"`
}
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 c09227b

Please sign in to comment.