Skip to content

Commit

Permalink
fix: add default disruption stanza (kubernetes-sigs#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
njtran committed Sep 17, 2024
1 parent 43c867d commit 19d5a36
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kwok/charts/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
../../../pkg/apis/crds/karpenter.sh_nodepools.yaml
../../../pkg/apis/crds/karpenter.sh_nodepools.yaml
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 @@ -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%"}}))
})
})
})

0 comments on commit 19d5a36

Please sign in to comment.