-
Notifications
You must be signed in to change notification settings - Fork 21
feat: add runtimeRequiredCordonAfter to support persistent node cordons #401
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # | ||
| # 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. | ||
|
|
||
| # yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json | ||
| apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
| kind: Test | ||
| metadata: | ||
| name: runtime-required-cordon-after | ||
| labels: | ||
| pool: interrupt | ||
| spec: | ||
| timeouts: | ||
| assert: 120s | ||
| catch: | ||
| - get: | ||
| apiVersion: v1 | ||
| kind: Node | ||
| selector: nodewright.nvidia.com/runtime-required-cordon-after-test=true | ||
| format: yaml | ||
| - get: | ||
| apiVersion: nodewright.nvidia.com/v1alpha1 | ||
| kind: NodeWright | ||
| name: runtime-required-cordon-after | ||
| format: yaml | ||
| steps: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test has no It taints Both tests carry One real flake here becomes a cascade of misleading failures elsewhere. A |
||
| # Phase 1: Apply node label matching NodeWright selector and apply runtime-required taint to the matching node | ||
| - name: setup | ||
| try: | ||
| - script: | ||
| content: | | ||
| ../nodewright-cli reset runtime-required-cordon-after --confirm 2>/dev/null || true | ||
| kubectl patch node kind-worker --type=merge \ | ||
| -p '{"metadata":{"annotations":{"nodewright.nvidia.com/runtimeRequiredCordon":null}},"spec":{"unschedulable":false}}' \ | ||
| 2>/dev/null || true | ||
|
|
||
| kubectl label node kind-worker nodewright.nvidia.com/runtime-required-cordon-after-test=true --overwrite | ||
| ../nodes_add_taint.sh all skyhook.nvidia.com=runtime-required:NoSchedule nodewright.nvidia.com/runtime-required-cordon-after-test=true | ||
|
|
||
| # Phase 2: Create the NodeWright with runtimeRequired and runtimeRequiredCordonAfter true | ||
| - name: apply-nodewright | ||
| try: | ||
| - create: | ||
| resource: | ||
| apiVersion: nodewright.nvidia.com/v1alpha1 | ||
| kind: NodeWright | ||
| metadata: | ||
| labels: | ||
| app.kubernetes.io/part-of: skyhook-operator | ||
| app.kubernetes.io/created-by: skyhook-operator | ||
| name: runtime-required-cordon-after | ||
| spec: | ||
| runtimeRequired: true | ||
| runtimeRequiredCordonAfter: true | ||
| nodeSelectors: | ||
| matchLabels: | ||
| nodewright.nvidia.com/runtime-required-cordon-after-test: "true" | ||
| packages: | ||
| spencer: | ||
| version: "3.2.3" | ||
| image: ghcr.io/nvidia/skyhook/agentless | ||
| env: | ||
| - name: SLEEP_LEN | ||
| value: "2" | ||
|
|
||
| # Phase 3: Wait for the NodeWright to complete on the targeted node | ||
| - name: assert-nodewright-complete | ||
| try: | ||
| - assert: | ||
| resource: | ||
| apiVersion: v1 | ||
| kind: Node | ||
| metadata: | ||
| name: kind-worker | ||
| labels: | ||
| nodewright.nvidia.com/status_runtime-required-cordon-after: complete | ||
| annotations: | ||
| nodewright.nvidia.com/status_runtime-required-cordon-after: complete | ||
|
|
||
| # Phase 4: Assert the runtime-required taint was removed and the cordon was applied | ||
| - name: assert-taint-removed-and-node-cordoned | ||
| try: | ||
| - assert: | ||
| resource: | ||
| apiVersion: v1 | ||
| kind: Node | ||
| metadata: | ||
| name: kind-worker | ||
| annotations: | ||
| nodewright.nvidia.com/runtimeRequiredCordon: "true" | ||
| spec: | ||
| unschedulable: true | ||
| (!taints || length(taints[?key == 'skyhook.nvidia.com' && effect == 'NoSchedule' && value == 'runtime-required'])==`0`): true | ||
|
|
||
| # Phase 5: External actor releases the cordon | ||
| - name: release-cordon | ||
| try: | ||
| - script: | ||
| content: | | ||
| kubectl patch node kind-worker --type=merge \ | ||
| -p '{"metadata":{"annotations":{"nodewright.nvidia.com/runtimeRequiredCordon":null}},"spec":{"unschedulable":false}}' | ||
|
natherz97 marked this conversation as resolved.
|
||
|
|
||
| # Phase 6: Assert the cordon annotation is removed and the node is schedulable | ||
| - name: assert-cordon-released | ||
| try: | ||
| - script: | ||
| content: | | ||
| set -eu | ||
| unschedulable=$(kubectl get node kind-worker -o jsonpath='{.spec.unschedulable}' 2>/dev/null || true) | ||
| if [ -n "$unschedulable" ] && [ "$unschedulable" != "false" ]; then | ||
| kubectl get node kind-worker -o yaml | ||
| echo "expected node to be schedulable after cordon release, got unschedulable=${unschedulable}" | ||
| exit 1 | ||
| fi | ||
| annotation=$(kubectl get node kind-worker \ | ||
| -o jsonpath='{.metadata.annotations.nodewright\.nvidia\.com/runtimeRequiredCordon}' 2>/dev/null || true) | ||
| if [ -n "$annotation" ]; then | ||
| kubectl get node kind-worker -o yaml | ||
| echo "expected runtimeRequiredCordon annotation to be absent after cordon release" | ||
| exit 1 | ||
| fi | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3168,8 +3168,19 @@ func (r *SkyhookReconciler) HandleRuntimeRequired(ctx context.Context, clusterSt | |
| // RemoveTaint will ALWAYS return nil for its error so no need to check it | ||
| new_node, updated, _ := taints.RemoveTaint(node, &taint_to_remove) | ||
| if updated { | ||
| err := r.Patch(ctx, new_node, client.MergeFrom(node)) | ||
| if err != nil { | ||
| // If any runtime-required Skyhook sets runtimeRequiredCordonAfter to true, the cordon and | ||
| // runtimeRequiredCordon annotation are only applied if the runtime-required taint exists. This means that a | ||
| // runtime-required Skyhook with runtimeRequiredCordonAfter true will not apply the persistent cordon if the | ||
| // runtime-required taint was already removed. Removing the taint and applying the node cordon in the same patch | ||
| // request ensures a scheduling gate is always applied to the targeted node. | ||
| if runtimeRequiredCordonAfterEnabled(node_to_skyhooks[node.UID]) { | ||
| if new_node.Annotations == nil { | ||
| new_node.Annotations = make(map[string]string) | ||
| } | ||
| new_node.Annotations[v1alpha1.RuntimeRequiredCordonAnnotation] = annotationTrueValue | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only place the persistent cordon is ever written, which has a consequence worth stating alongside the The write sits inside the The consequence: if someone runs To be clear, the patch itself is correct and idempotent: |
||
| new_node.Spec.Unschedulable = true | ||
| } | ||
| if err := r.Patch(ctx, new_node, client.MergeFrom(node)); err != nil { | ||
| errs = append(errs, err) | ||
| } | ||
| } | ||
|
|
@@ -3180,6 +3191,16 @@ func (r *SkyhookReconciler) HandleRuntimeRequired(ctx context.Context, clusterSt | |
| return nil | ||
| } | ||
|
|
||
| func runtimeRequiredCordonAfterEnabled(skyhooks []SkyhookNodes) bool { | ||
| for _, skyhook := range skyhooks { | ||
| spec := skyhook.GetSkyhook().Spec | ||
| if spec.RuntimeRequired && spec.RuntimeRequiredCordonAfter { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // Group Skyhooks by what node they target | ||
| func groupSkyhooksByNode(clusterState *clusterState) (map[types.UID][]SkyhookNodes, map[types.UID]*corev1.Node) { | ||
| node_to_skyhooks := make(map[types.UID][]SkyhookNodes) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.