Skip to content

Commit

Permalink
Merge pull request #1159 from wzshiming/feat/node-not-ready-stage
Browse files Browse the repository at this point in the history
Add node not ready stage
  • Loading branch information
wzshiming authored Jul 5, 2024
2 parents 40ac0f4 + 9c38e4f commit adaad65
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
61 changes: 61 additions & 0 deletions kustomize/stage/node/chaos/node-not-ready.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: kwok.x-k8s.io/v1alpha1
kind: Stage
metadata:
name: node-not-ready
spec:
resourceRef:
apiGroup: v1
kind: Node
selector:
matchExpressions:
- key: '.metadata.labels["node-not-ready.stage.kwok.x-k8s.io"]'
operator: 'In'
values:
- 'true'
- key: '.status.phase'
operator: 'In'
values:
- 'Running'
delay:
durationMilliseconds: 1000
durationFrom:
expressionFrom: '.metadata.annotations["node-not-ready.stage.kwok.x-k8s.io/delay"]'
jitterDurationMilliseconds: 1000
jitterDurationFrom:
expressionFrom: '.metadata.annotations["node-not-ready.stage.kwok.x-k8s.io/jitter-delay"]'
weight: 10000
next:
statusTemplate: |
{{ $now := Now }}
{{ $defaultReason := "nodeFailed" }}
{{ $defaultMessage := "node failed" }}
{{ $annotations := or .metadata.annotations dict }}
{{ $failureType := or ( index $annotations "node-not-ready.stage.kwok.x-k8s.io/type" ) "" }}
{{ $failureReason := or ( index $annotations "node-not-ready.stage.kwok.x-k8s.io/reason" ) $defaultReason }}
{{ $failureMessage := or ( index $annotations "node-not-ready.stage.kwok.x-k8s.io/message" ) $defaultMessage }}
{{ $lastTransitionTime := or .metadata.creationTimestamp $now }}
conditions:
{{ range NodeConditions }}
{{ if eq .type "Ready" }}
- lastHeartbeatTime: {{ $now | Quote }}
lastTransitionTime: {{ $lastTransitionTime | Quote }}
message: {{ $failureMessage | Quote }}
reason: {{ $failureReason | Quote }}
status: "False"
type: {{ .type | Quote}}
{{ else if eq .type $failureType }}
- lastHeartbeatTime: {{ $now | Quote }}
lastTransitionTime: {{ $lastTransitionTime | Quote }}
message: {{ $failureMessage | Quote }}
reason: {{ $failureReason | Quote }}
status: "True"
type: {{ .type | Quote}}
{{ else }}
- lastHeartbeatTime: {{ $now | Quote }}
lastTransitionTime: {{ $lastTransitionTime | Quote }}
message: {{ .message | Quote }}
reason: {{ .reason | Quote }}
status: {{ .status | Quote }}
type: {{ .type | Quote}}
{{ end }}
{{ end }}
11 changes: 11 additions & 0 deletions kustomize/stage/node/chaos/testdata/node-not-ready.input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @Stage: ../node-not-ready.yaml
apiVersion: v1
kind: Node
metadata:
name: node-not-ready
labels:
node-not-ready.stage.kwok.x-k8s.io: "true"
annotations:
node-not-ready.stage.kwok.x-k8s.io/type: NetworkUnavailable
status:
phase: Running
44 changes: 44 additions & 0 deletions kustomize/stage/node/chaos/testdata/node-not-ready.output.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiGroup: v1
kind: Node
name: node-not-ready
stages:
- delay: 1000000000
next:
- data:
status:
conditions:
- lastHeartbeatTime: <Now>
lastTransitionTime: <Now>
message: node failed
reason: nodeFailed
status: "False"
type: Ready
- lastHeartbeatTime: <Now>
lastTransitionTime: <Now>
message: kubelet has sufficient memory available
reason: KubeletHasSufficientMemory
status: "False"
type: MemoryPressure
- lastHeartbeatTime: <Now>
lastTransitionTime: <Now>
message: kubelet has no disk pressure
reason: KubeletHasNoDiskPressure
status: "False"
type: DiskPressure
- lastHeartbeatTime: <Now>
lastTransitionTime: <Now>
message: kubelet has sufficient PID available
reason: KubeletHasSufficientPID
status: "False"
type: PIDPressure
- lastHeartbeatTime: <Now>
lastTransitionTime: <Now>
message: node failed
reason: nodeFailed
status: "True"
type: NetworkUnavailable
kind: patch
subresource: status
type: application/merge-patch+json
stage: node-not-ready
weight: 10000

0 comments on commit adaad65

Please sign in to comment.