Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: require and then remove karpenter startup taint #1336

Merged
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ef3d6bd
feat: require and then remove karpenter startup taint
rschalo Jun 19, 2024
7b5f994
fix pointer
rschalo Jun 19, 2024
571d8c9
Revert "feat: require and then remove karpenter startup taint"
rschalo Jun 20, 2024
0dd19f8
feat: inject and remove karpenter unregistered taint
rschalo Jun 20, 2024
37c393c
minor updates
rschalo Jun 20, 2024
5df32d4
remove requeue
rschalo Jun 20, 2024
5073f98
test fix
rschalo Jun 20, 2024
203e729
fix copying taint to node
rschalo Jun 24, 2024
05c0e37
fix taint length
rschalo Jun 26, 2024
eb164ab
extend timeout
rschalo Jun 26, 2024
f2b58cf
remove focus
rschalo Jun 26, 2024
d47b4ef
fix test
rschalo Jun 26, 2024
bb3e2c2
remove test focus
rschalo Jun 26, 2024
0bb3d62
drift test fix
rschalo Jun 26, 2024
88bc9d0
typo
rschalo Jun 26, 2024
841c23d
pr review response
rschalo Jun 27, 2024
6972dce
remove val from taint
rschalo Jun 27, 2024
3d193a2
add registration test
rschalo Jun 28, 2024
6fe8c6b
Merge branch 'main' into remove-karpenter-startup-taint
rschalo Jun 28, 2024
6311ffd
golint fixes
rschalo Jun 28, 2024
a19bf98
remove startup tain
rschalo Jun 28, 2024
1da7ca9
expand test message and fix test
rschalo Jun 28, 2024
4495665
fix test
rschalo Jun 28, 2024
5e9fd9c
put env back
rschalo Jun 28, 2024
a83dd05
update instead of patch
rschalo Jun 28, 2024
8c0544c
Merge branch 'main' into remove-karpenter-startup-taint
rschalo Jun 28, 2024
16d1293
run presubmit
rschalo Jun 28, 2024
bda2e40
fix testing
rschalo Jun 28, 2024
97f3153
fix tests
rschalo Jul 1, 2024
00a642e
add test condition
rschalo Jul 2, 2024
3699f21
env fix
rschalo Jul 2, 2024
9193211
Merge branch 'main' into remove-karpenter-startup-taint
rschalo Jul 2, 2024
8513f99
clean up test
rschalo Jul 2, 2024
ca86579
test simplification
rschalo Jul 2, 2024
fe4eefe
satisfy lint
rschalo Jul 2, 2024
42a0694
test removal of after
rschalo Jul 2, 2024
1d97908
remove after
rschalo Jul 2, 2024
76fedbf
remove another after
rschalo Jul 2, 2024
cd00b23
pr feedback
rschalo Jul 2, 2024
2342664
respond to pr comments
rschalo Jul 3, 2024
a665237
fix presubmit
rschalo Jul 3, 2024
180e804
add registered label check
rschalo Jul 3, 2024
44753f0
Update pkg/controllers/nodeclaim/lifecycle/registration_test.go
rschalo Jul 3, 2024
3f2cfb4
pr comments
rschalo Jul 3, 2024
103987c
pr response
rschalo Jul 3, 2024
53a81d4
fix pr tests
rschalo Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ delete: ## Delete the controller from your ~/.kube/config cluster
test: ## Run tests
go test ./pkg/... \
-race \
-timeout 15m \
-timeout 20m \
--ginkgo.focus="${FOCUS}" \
--ginkgo.randomize-all \
--ginkgo.v \
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/client_model v0.6.1
github.com/samber/lo v1.43.0
github.com/samber/lo v1.44.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/sync v0.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.43.0 h1:ts0VhPi8+ZQZFVLv/2Vkgt2Cds05FM2v3Enmv+YMBtg=
github.com/samber/lo v1.43.0/go.mod h1:w7R6fO7h2lrnx/s0bWcZ55vXJI89p5UPM6+kyDL373E=
github.com/samber/lo v1.44.0 h1:5il56KxRE+GHsm1IR+sZ/6J42NODigFiqCWpSc2dybA=
github.com/samber/lo v1.44.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/v1beta1/taints.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
const (
DisruptionTaintKey = apis.Group + "/disruption"
DisruptingNoScheduleTaintValue = "disrupting"
UnregisteredTaintKey = apis.Group + "/unregistered"
)

var (
Expand All @@ -36,6 +37,10 @@ var (
Effect: v1.TaintEffectNoSchedule,
Value: DisruptingNoScheduleTaintValue,
}
UnregisteredNoExecuteTaint = v1.Taint{
Key: UnregisteredTaintKey,
Effect: v1.TaintEffectNoExecute,
}
)

func IsDisruptingTaint(taint v1.Taint) bool {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (its InstanceTypes) SatisfiesMinValues(requirements scheduling.Requirements
// Truncate truncates the InstanceTypes based on the passed-in requirements
// It returns an error if it isn't possible to truncate the instance types on maxItems without violating minValues
func (its InstanceTypes) Truncate(requirements scheduling.Requirements, maxItems int) (InstanceTypes, error) {
truncatedInstanceTypes := InstanceTypes(lo.Slice(its.OrderByPrice(requirements), 0, maxItems))
truncatedInstanceTypes := lo.Slice(its.OrderByPrice(requirements), 0, maxItems)
// Only check for a validity of NodeClaim if its requirement has minValues in it.
if requirements.HasMinValues() {
if _, err := truncatedInstanceTypes.SatisfiesMinValues(requirements); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/nodeclaim/disruption/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ var _ = Describe("Disruption", func() {
Expect(nodeClaim.StatusConditions().Get(v1beta1.ConditionTypeEmpty).IsTrue()).To(BeTrue())
})
It("should remove multiple disruption conditions simultaneously", func() {
cp.Drifted = ""
rschalo marked this conversation as resolved.
Show resolved Hide resolved
nodePool.Spec.Disruption.ExpireAfter.Duration = nil
nodePool.Spec.Disruption.ConsolidateAfter = &v1beta1.NillableDuration{Duration: nil}

Expand All @@ -124,7 +125,7 @@ var _ = Describe("Disruption", func() {
ExpectObjectReconciled(ctx, env.Client, nodeClaimDisruptionController, nodeClaim)

nodeClaim = ExpectExists(ctx, env.Client, nodeClaim)
Expect(nodeClaim.StatusConditions().Get(v1beta1.ConditionTypeDrifted).IsTrue()).To(BeTrue())
Expect(nodeClaim.StatusConditions().Get(v1beta1.ConditionTypeDrifted)).To(BeNil())
Expect(nodeClaim.StatusConditions().Get(v1beta1.ConditionTypeEmpty)).To(BeNil())
})
})
9 changes: 9 additions & 0 deletions pkg/controllers/nodeclaim/lifecycle/initialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var _ = Describe("Initialization", func() {

node := test.Node(test.NodeOptions{
ProviderID: nodeClaim.Status.ProviderID,
Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint},
})
ExpectApplied(ctx, env.Client, node)
ExpectMakeNodesReady(ctx, env.Client, node) // Remove the not-ready taint
Expand Down Expand Up @@ -122,6 +123,7 @@ var _ = Describe("Initialization", func() {
v1.ResourceMemory: resource.MustParse("80Mi"),
v1.ResourcePods: resource.MustParse("110"),
},
Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint},
})
ExpectApplied(ctx, env.Client, node)
ExpectMakeNodesReady(ctx, env.Client, node) // Remove the not-ready taint
Expand Down Expand Up @@ -165,6 +167,7 @@ var _ = Describe("Initialization", func() {
v1.ResourcePods: resource.MustParse("110"),
},
ReadyStatus: v1.ConditionFalse,
Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint},
})
ExpectApplied(ctx, env.Client, node)
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
Expand Down Expand Up @@ -213,6 +216,7 @@ var _ = Describe("Initialization", func() {
v1.ResourceMemory: resource.MustParse("80Mi"),
v1.ResourcePods: resource.MustParse("110"),
},
Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint},
})
ExpectApplied(ctx, env.Client, node)
ExpectMakeNodesReady(ctx, env.Client, node) // Remove the not-ready taint
Expand Down Expand Up @@ -263,6 +267,7 @@ var _ = Describe("Initialization", func() {
v1.ResourceMemory: resource.MustParse("80Mi"),
v1.ResourcePods: resource.MustParse("110"),
},
Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint},
})
ExpectApplied(ctx, env.Client, node)
ExpectMakeNodesReady(ctx, env.Client, node) // Remove the not-ready taint
Expand Down Expand Up @@ -330,6 +335,7 @@ var _ = Describe("Initialization", func() {
v1.ResourceMemory: resource.MustParse("80Mi"),
v1.ResourcePods: resource.MustParse("110"),
},
Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint},
})
ExpectApplied(ctx, env.Client, node)
ExpectMakeNodesReady(ctx, env.Client, node) // Remove the not-ready taint
Expand Down Expand Up @@ -401,6 +407,7 @@ var _ = Describe("Initialization", func() {
v1.ResourceMemory: resource.MustParse("80Mi"),
v1.ResourcePods: resource.MustParse("110"),
},
Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint},
})
ExpectApplied(ctx, env.Client, node)
ExpectMakeNodesReady(ctx, env.Client, node) // Remove the not-ready taint
Expand Down Expand Up @@ -480,6 +487,7 @@ var _ = Describe("Initialization", func() {
Effect: v1.TaintEffectNoSchedule,
Value: "true",
},
v1beta1.UnregisteredNoExecuteTaint,
},
})
ExpectApplied(ctx, env.Client, node)
Expand Down Expand Up @@ -549,6 +557,7 @@ var _ = Describe("Initialization", func() {
Effect: v1.TaintEffectNoSchedule,
Value: "true",
},
v1beta1.UnregisteredNoExecuteTaint,
},
})
ExpectApplied(ctx, env.Client, node)
Expand Down
16 changes: 13 additions & 3 deletions pkg/controllers/nodeclaim/lifecycle/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ func (r *Registration) Reconcile(ctx context.Context, nodeClaim *v1beta1.NodeCla
}
return reconcile.Result{}, fmt.Errorf("getting node for nodeclaim, %w", err)
}
if _, hasStartupTaint := lo.Find(node.Spec.Taints, func(t v1.Taint) bool {
rschalo marked this conversation as resolved.
Show resolved Hide resolved
return t.MatchTaint(&v1beta1.UnregisteredNoExecuteTaint)
}); !hasStartupTaint {
return reconcile.Result{}, fmt.Errorf("missing required startup taint, %s", v1beta1.UnregisteredTaintKey)
}
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KRef("", node.Name)))
if err = r.syncNode(ctx, nodeClaim, node); err != nil {
return reconcile.Result{}, fmt.Errorf("syncing node, %w", err)
return reconcile.Result{Requeue: true}, err
rschalo marked this conversation as resolved.
Show resolved Hide resolved
}
log.FromContext(ctx).Info("registered nodeclaim")
nodeClaim.StatusConditions().SetTrue(v1beta1.ConditionTypeRegistered)
Expand All @@ -88,12 +93,17 @@ func (r *Registration) syncNode(ctx context.Context, nodeClaim *v1beta1.NodeClai
// Sync all taints inside NodeClaim into the Node taints
node.Spec.Taints = scheduling.Taints(node.Spec.Taints).Merge(nodeClaim.Spec.Taints)
node.Spec.Taints = scheduling.Taints(node.Spec.Taints).Merge(nodeClaim.Spec.StartupTaints)
// Remove karpenter.sh/unregistered taint
taints := lo.Reject(node.Spec.Taints, func(t v1.Taint, _ int) bool {
rschalo marked this conversation as resolved.
Show resolved Hide resolved
return t.MatchTaint(&v1beta1.UnregisteredNoExecuteTaint)
})
node.Labels = lo.Assign(node.Labels, nodeClaim.Labels, map[string]string{
v1beta1.NodeRegisteredLabelKey: "true",
})
node.Spec.Taints = taints
if !equality.Semantic.DeepEqual(stored, node) {
if err := r.kubeClient.Patch(ctx, node, client.StrategicMergeFrom(stored)); err != nil {
return fmt.Errorf("syncing node labels, %w", err)
if err := r.kubeClient.Update(ctx, node); err != nil {
return fmt.Errorf("syncing node, %w", err)
}
}
return nil
Expand Down
36 changes: 28 additions & 8 deletions pkg/controllers/nodeclaim/lifecycle/registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var _ = Describe("Registration", func() {
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
nodeClaim = ExpectExists(ctx, env.Client, nodeClaim)

node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID})
node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID, Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint}})
ExpectApplied(ctx, env.Client, node)
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)

Expand All @@ -66,7 +66,7 @@ var _ = Describe("Registration", func() {
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
nodeClaim = ExpectExists(ctx, env.Client, nodeClaim)

node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID})
node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID, Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint}})
ExpectApplied(ctx, env.Client, node)
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)

Expand All @@ -85,12 +85,32 @@ var _ = Describe("Registration", func() {
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
nodeClaim = ExpectExists(ctx, env.Client, nodeClaim)

node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID})
node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID, Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint}})
ExpectApplied(ctx, env.Client, node)
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
node = ExpectExists(ctx, env.Client, node)
Expect(node.Labels).To(HaveKeyWithValue(v1beta1.NodeRegisteredLabelKey, "true"))
})
It("should remove the karpenter.sh/unregistered taint from the Node when the Node comes online", func() {
rschalo marked this conversation as resolved.
Show resolved Hide resolved
rschalo marked this conversation as resolved.
Show resolved Hide resolved
nodeClaim := test.NodeClaim(v1beta1.NodeClaim{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
v1beta1.NodePoolLabelKey: nodePool.Name,
},
},
})
ExpectApplied(ctx, env.Client, nodePool, nodeClaim)
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
nodeClaim = ExpectExists(ctx, env.Client, nodeClaim)

node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID, Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint}})
ExpectApplied(ctx, env.Client, node)
Expect(node.Spec.Taints).To(ContainElement(v1beta1.UnregisteredNoExecuteTaint))
rschalo marked this conversation as resolved.
Show resolved Hide resolved
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
node = ExpectExists(ctx, env.Client, node)
Expect(node.Labels).To(HaveKeyWithValue(v1beta1.NodeRegisteredLabelKey, "true"))
Expect(node.Spec.Taints).To(Not(ContainElement(v1beta1.UnregisteredNoExecuteTaint)))
})
It("should sync the labels to the Node when the Node comes online", func() {
nodeClaim := test.NodeClaim(v1beta1.NodeClaim{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -107,7 +127,7 @@ var _ = Describe("Registration", func() {
Expect(nodeClaim.Labels).To(HaveKeyWithValue("custom-label", "custom-value"))
Expect(nodeClaim.Labels).To(HaveKeyWithValue("other-custom-label", "other-custom-value"))

node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID})
node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID, Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint}})
ExpectApplied(ctx, env.Client, node)
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
node = ExpectExists(ctx, env.Client, node)
Expand Down Expand Up @@ -135,7 +155,7 @@ var _ = Describe("Registration", func() {
Expect(nodeClaim.Annotations).To(HaveKeyWithValue(v1beta1.DoNotDisruptAnnotationKey, "true"))
Expect(nodeClaim.Annotations).To(HaveKeyWithValue("my-custom-annotation", "my-custom-value"))

node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID})
node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID, Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint}})
ExpectApplied(ctx, env.Client, node)
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
node = ExpectExists(ctx, env.Client, node)
Expand Down Expand Up @@ -183,7 +203,7 @@ var _ = Describe("Registration", func() {
},
))

node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID})
node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID, Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint}})
ExpectApplied(ctx, env.Client, node)
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
node = ExpectExists(ctx, env.Client, node)
Expand Down Expand Up @@ -251,7 +271,7 @@ var _ = Describe("Registration", func() {
},
))

node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID})
node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID, Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint}})
ExpectApplied(ctx, env.Client, node)
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
node = ExpectExists(ctx, env.Client, node)
Expand Down Expand Up @@ -305,7 +325,7 @@ var _ = Describe("Registration", func() {
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
nodeClaim = ExpectExists(ctx, env.Client, nodeClaim)

node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID})
node := test.Node(test.NodeOptions{ProviderID: nodeClaim.Status.ProviderID, Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint}})
ExpectApplied(ctx, env.Client, node)
ExpectObjectReconciled(ctx, env.Client, nodeClaimController, nodeClaim)
node = ExpectExists(ctx, env.Client, node)
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/provisioning/scheduling/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,7 @@ var _ = Context("Scheduling", func() {
// delete the pod so that the node is empty
ExpectDeleted(ctx, env.Client, initialPod)
// startup taint + node not ready taint = 2
rschalo marked this conversation as resolved.
Show resolved Hide resolved
// note that this node is not post registration so the unregistered taint is present
rschalo marked this conversation as resolved.
Show resolved Hide resolved
Expect(node1.Spec.Taints).To(HaveLen(2))
Expect(node1.Spec.Taints).To(ContainElement(v1.Taint{
Key: "foo.com/taint",
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/provisioning/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ var _ = Describe("Provisioning", func() {
},
Finalizers: []string{v1beta1.TerminationFinalizer},
},
Taints: []v1.Taint{v1beta1.UnregisteredNoExecuteTaint},
rschalo marked this conversation as resolved.
Show resolved Hide resolved
},
)
ExpectApplied(ctx, env.Client, node, nodePool)
Expand Down
3 changes: 3 additions & 0 deletions pkg/scheduling/taints.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"go.uber.org/multierr"
v1 "k8s.io/api/core/v1"
cloudproviderapi "k8s.io/cloud-provider/api"

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

// KnownEphemeralTaints are taints that are expected to be added to a node while it's initializing
Expand All @@ -32,6 +34,7 @@ var KnownEphemeralTaints = []v1.Taint{
{Key: v1.TaintNodeNotReady, Effect: v1.TaintEffectNoSchedule},
{Key: v1.TaintNodeUnreachable, Effect: v1.TaintEffectNoSchedule},
{Key: cloudproviderapi.TaintExternalCloudProvider, Effect: v1.TaintEffectNoSchedule, Value: "true"},
v1beta1.UnregisteredNoExecuteTaint,
}

// Taints is a decorated alias type for []v1.Taint
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/expectations/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func ExpectMakeNodesReady(ctx context.Context, c client.Client, nodes ...*v1.Nod
// Remove any of the known ephemeral taints to make the Node ready
nodes[i].Spec.Taints = lo.Reject(nodes[i].Spec.Taints, func(taint v1.Taint, _ int) bool {
_, found := lo.Find(pscheduling.KnownEphemeralTaints, func(t v1.Taint) bool {
return t.MatchTaint(&taint)
return t.MatchTaint(&taint) && !t.MatchTaint(&v1beta1.UnregisteredNoExecuteTaint)
rschalo marked this conversation as resolved.
Show resolved Hide resolved
})
return found
})
Expand Down
11 changes: 10 additions & 1 deletion pkg/test/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"

"github.com/imdario/mergo"
"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -67,15 +68,23 @@ func Node(overrides ...NodeOptions) *v1.Node {
}
}

// this check is done for tests that assume the nodeclaim is past registration but will not go through reconciliation
rschalo marked this conversation as resolved.
Show resolved Hide resolved
func NodeClaimLinkedNode(nodeClaim *v1beta1.NodeClaim) *v1.Node {
taints := lo.Reject(nodeClaim.Spec.StartupTaints, func(t v1.Taint, _ int) bool {
rschalo marked this conversation as resolved.
Show resolved Hide resolved
return t.MatchTaint(&v1beta1.UnregisteredNoExecuteTaint)
})
if nodeClaim.StatusConditions().Get(v1beta1.ConditionTypeRegistered).IsFalse() &&
nodeClaim.StatusConditions().Get(v1beta1.ConditionTypeInitialized).IsFalse() {
taints = append(taints, v1beta1.UnregisteredNoExecuteTaint)
}
return Node(
NodeOptions{
ObjectMeta: metav1.ObjectMeta{
Labels: nodeClaim.Labels,
Annotations: nodeClaim.Annotations,
Finalizers: nodeClaim.Finalizers,
},
Taints: append(nodeClaim.Spec.Taints, nodeClaim.Spec.StartupTaints...),
Taints: append(nodeClaim.Spec.Taints, taints...),
Capacity: nodeClaim.Status.Capacity,
Allocatable: nodeClaim.Status.Allocatable,
ProviderID: nodeClaim.Status.ProviderID,
Expand Down
Loading