Skip to content

Commit

Permalink
fix: add default disruption stanza (kubernetes-sigs#1662) (kubernetes…
Browse files Browse the repository at this point in the history
  • Loading branch information
njtran authored Sep 17, 2024
1 parent b69e975 commit ffa6fc1
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 6 deletions.
2 changes: 1 addition & 1 deletion kwok/apis/crds/karpenter.kwok.sh_kwoknodeclasses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.2
controller-gen.kubebuilder.io/version: v0.16.3
name: kwoknodeclasses.karpenter.kwok.sh
spec:
group: karpenter.kwok.sh
Expand Down
2 changes: 1 addition & 1 deletion kwok/charts/crds/karpenter.sh_nodeclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.2
controller-gen.kubebuilder.io/version: v0.16.3
name: nodeclaims.karpenter.sh
spec:
group: karpenter.sh
Expand Down
4 changes: 3 additions & 1 deletion kwok/charts/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.2
controller-gen.kubebuilder.io/version: v0.16.3
name: nodepools.karpenter.sh
spec:
group: karpenter.sh
Expand Down Expand Up @@ -71,6 +71,8 @@ spec:
from a combination of nodepool and pod scheduling constraints.
properties:
disruption:
default:
consolidateAfter: 0s
description: Disruption contains the parameters that relate to Karpenter's disruption logic
properties:
budgets:
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/crds/karpenter.sh_nodeclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.2
controller-gen.kubebuilder.io/version: v0.16.3
name: nodeclaims.karpenter.sh
spec:
group: karpenter.sh
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.2
controller-gen.kubebuilder.io/version: v0.16.3
name: nodepools.karpenter.sh
spec:
group: karpenter.sh
Expand Down Expand Up @@ -71,6 +71,8 @@ spec:
from a combination of nodepool and pod scheduling constraints.
properties:
disruption:
default:
consolidateAfter: 0s
description: Disruption contains the parameters that relate to Karpenter's disruption logic
properties:
budgets:
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/v1/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type NodePoolSpec struct {
// +required
Template NodeClaimTemplate `json:"template"`
// Disruption contains the parameters that relate to Karpenter's disruption logic
// +kubebuilder:default:={consolidateAfter: "0s"}
// +optional
Disruption Disruption `json:"disruption"`
// Limits define a set of bounds for provisioning capacity.
Expand Down
71 changes: 71 additions & 0 deletions pkg/apis/v1/nodepool_default_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1_test

import (
"strings"
"time"

"github.com/Pallinder/go-randomdata"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"sigs.k8s.io/controller-runtime/pkg/client"

. "sigs.k8s.io/karpenter/pkg/apis/v1"
)

var _ = Describe("CEL/Default", func() {
var nodePool *NodePool

BeforeEach(func() {
nodePool = &NodePool{
ObjectMeta: metav1.ObjectMeta{Name: strings.ToLower(randomdata.SillyName())},
Spec: NodePoolSpec{
Template: NodeClaimTemplate{
Spec: NodeClaimTemplateSpec{
NodeClassRef: &NodeClassReference{
Kind: "NodeClaim",
Name: "default",
},
Requirements: []NodeSelectorRequirementWithMinValues{
{
NodeSelectorRequirement: v1.NodeSelectorRequirement{
Key: CapacityTypeLabelKey,
Operator: v1.NodeSelectorOpExists,
},
},
},
},
},
},
}
})
Context("Defaults/TopLevel", func() {
It("should default the disruption stanza when undefined", func() {
Expect(env.Client.Create(ctx, nodePool)).To(Succeed())
Expect(env.Client.Get(ctx, client.ObjectKeyFromObject(nodePool), nodePool)).To(Succeed())
Expect(nodePool.Spec.Disruption).ToNot(BeNil())
Expect(lo.FromPtr(nodePool.Spec.Disruption.ConsolidateAfter.Duration)).To(Equal(0 * time.Second))
Expect(nodePool.Spec.Disruption.ConsolidationPolicy).To(Equal(ConsolidationPolicyWhenEmptyOrUnderutilized))
Expect(nodePool.Spec.Disruption.Budgets).To(Equal([]Budget{{Nodes: "10%"}}))
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.2
controller-gen.kubebuilder.io/version: v0.16.3
name: testnodeclasses.karpenter.test.sh
spec:
group: karpenter.test.sh
Expand Down

0 comments on commit ffa6fc1

Please sign in to comment.