Skip to content

Commit 66d060b

Browse files
committed
add lifecycle stage
1 parent b89a440 commit 66d060b

11 files changed

+507
-0
lines changed

charts/lifecycle/.helmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.helmignore

charts/lifecycle/Chart.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v2
2+
description: Lifecycle stage policy of KWOK (Kubernetes WithOut Kubelet)
3+
type: application
4+
home: https://kwok.sigs.k8s.io
5+
icon: https://github.com/kubernetes-sigs/kwok/raw/main/logo/kwok.png
6+
keywords:
7+
- kubernetes
8+
- kwok
9+
- kwok stage policy
10+
sources:
11+
- https://github.com/kubernetes-sigs/kwok
12+
name: lifecycle
13+
maintainers:
14+
- name: wzshiming
15+
email: wzshiming@hotmail.com
16+
appVersion: v0.7.0
17+
version: 0.2.0
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
apiVersion: kwok.x-k8s.io/v1alpha1
2+
kind: Stage
3+
metadata:
4+
name: node-heartbeat-with-lease
5+
spec:
6+
resourceRef:
7+
apiGroup: v1
8+
kind: Node
9+
selector:
10+
matchExpressions:
11+
- key: '.status.phase'
12+
operator: 'In'
13+
values:
14+
- 'Running'
15+
- key: '.status.conditions.[] | select( .type == "Ready" ) | .status'
16+
operator: 'In'
17+
values:
18+
- 'True'
19+
delay:
20+
durationMilliseconds: 600000
21+
jitterDurationMilliseconds: 610000
22+
next:
23+
statusTemplate: |
24+
{{ `{{ $now := Now }}` }}
25+
{{ `{{ $lastTransitionTime := or .metadata.creationTimestamp $now }}` }}
26+
conditions:
27+
{{ `{{ range NodeConditions }}` }}
28+
- lastHeartbeatTime: {{ `{{ $now | Quote }}` }}
29+
lastTransitionTime: {{ `{{ $lastTransitionTime | Quote }}` }}
30+
message: {{ `{{ .message | Quote }}` }}
31+
reason: {{ `{{ .reason | Quote }}` }}
32+
status: {{ `{{ .status | Quote }}` }}
33+
type: {{ `{{ .type | Quote }}` }}
34+
{{ `{{ end }}` }}
35+
36+
addresses:
37+
{{ `{{ with .status.addresses }}` }}
38+
{{ `{{ YAML . 1 }}` }}
39+
{{ `{{ else }}` }}
40+
{{ `{{ with NodeIP }}` }}
41+
- address: {{ `{{ . | Quote }}` }}
42+
type: InternalIP
43+
{{ `{{ end }}` }}
44+
{{ `{{ with NodeName }}` }}
45+
- address: {{ `{{ . | Quote }}` }}
46+
type: Hostname
47+
{{ `{{ end }}` }}
48+
{{ `{{ end }}` }}
49+
50+
{{ `{{ with NodePort }}` }}
51+
daemonEndpoints:
52+
kubeletEndpoint:
53+
Port: {{ `{{ . }}` }}
54+
{{ `{{ end }}` }}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
apiVersion: kwok.x-k8s.io/v1alpha1
2+
kind: Stage
3+
metadata:
4+
name: node-initialize
5+
spec:
6+
resourceRef:
7+
apiGroup: v1
8+
kind: Node
9+
selector:
10+
matchExpressions:
11+
- key: '.status.conditions.[] | select( .type == "Ready" ) | .status'
12+
operator: 'NotIn'
13+
values:
14+
- 'True'
15+
next:
16+
statusTemplate: |
17+
{{ `{{ $now := Now }}` }}
18+
{{ `{{ $lastTransitionTime := or .metadata.creationTimestamp $now }}` }}
19+
conditions:
20+
{{ `{{ range NodeConditions }}` }}
21+
- lastHeartbeatTime: {{ `{{ $now | Quote }}` }}
22+
lastTransitionTime: {{ `{{ $lastTransitionTime | Quote }}` }}
23+
message: {{ `{{ .message | Quote }}` }}
24+
reason: {{ `{{ .reason | Quote }}` }}
25+
status: {{ `{{ .status | Quote }}` }}
26+
type: {{ `{{ .type | Quote}}` }}
27+
{{ `{{ end }}` }}
28+
29+
addresses:
30+
{{ `{{ with .status.addresses }}` }}
31+
{{ `{{ YAML . 1 }}` }}
32+
{{ `{{ else }}` }}
33+
{{ `{{ with NodeIP }}` }}
34+
- address: {{ `{{ . | Quote }}` }}
35+
type: InternalIP
36+
{{ `{{ end }}` }}
37+
{{ `{{ with NodeName }}` }}
38+
- address: {{ `{{ . | Quote }}` }}
39+
type: Hostname
40+
{{ `{{ end }}` }}
41+
{{ `{{ end }}` }}
42+
43+
{{ `{{ with NodePort }}` }}
44+
daemonEndpoints:
45+
kubeletEndpoint:
46+
Port: {{ `{{ . }}` }}
47+
{{ `{{ end }}` }}
48+
49+
allocatable:
50+
{{ `{{ with .status.allocatable }}` }}
51+
{{ `{{ YAML . 1 }}` }}
52+
{{ `{{ else }}` }}
53+
cpu: 1k
54+
memory: 1Ti
55+
pods: 1M
56+
{{ `{{ end }}` }}
57+
capacity:
58+
{{ `{{ with .status.capacity }}` }}
59+
{{ `{{ YAML . 1 }}` }}
60+
{{ `{{ else }}` }}
61+
cpu: 1k
62+
memory: 1Ti
63+
pods: 1M
64+
{{ `{{ end }}` }}
65+
66+
{{ `{{ $nodeInfo := .status.nodeInfo }}` }}
67+
{{ `{{ $kwokVersion := printf "kwok-%s" Version }}` }}
68+
nodeInfo:
69+
architecture: {{ `{{ or $nodeInfo.architecture "amd64" }}` }}
70+
bootID: {{ `{{ or $nodeInfo.bootID "" }}` }}
71+
containerRuntimeVersion: {{ `{{ or $nodeInfo.containerRuntimeVersion $kwokVersion }}` }}
72+
kernelVersion: {{ `{{ or $nodeInfo.kernelVersion $kwokVersion }}` }}
73+
kubeProxyVersion: {{ `{{ or $nodeInfo.kubeProxyVersion $kwokVersion }}` }}
74+
kubeletVersion: {{ `{{ or $nodeInfo.kubeletVersion $kwokVersion }}` }}
75+
machineID: {{ `{{ or $nodeInfo.machineID "" }}` }}
76+
operatingSystem: {{ `{{ or $nodeInfo.operatingSystem "linux" }}` }}
77+
osImage: {{ `{{ or $nodeInfo.osImage "" }}` }}
78+
systemUUID: {{ `{{ or $nodeInfo.systemUUID "" }}` }}
79+
phase: Running
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
apiVersion: kwok.x-k8s.io/v1alpha1
2+
kind: Stage
3+
metadata:
4+
name: pod-complete
5+
spec:
6+
resourceRef:
7+
apiGroup: v1
8+
kind: Pod
9+
selector:
10+
matchExpressions:
11+
- key: '.metadata.deletionTimestamp'
12+
operator: 'DoesNotExist'
13+
- key: '.status.phase'
14+
operator: 'In'
15+
values:
16+
- 'Running'
17+
- key: '.status.conditions.[] | select( .type == "Ready" ) | .status'
18+
operator: 'In'
19+
values:
20+
- 'True'
21+
- key: '.metadata.ownerReferences.[].kind'
22+
operator: 'In'
23+
values:
24+
- 'Job'
25+
weight: 1
26+
weightFrom:
27+
expressionFrom: '.metadata.annotations["pod-complete.stage.kwok.x-k8s.io/weight"]'
28+
delay:
29+
durationMilliseconds: 1000
30+
durationFrom:
31+
expressionFrom: '.metadata.annotations["pod-complete.stage.kwok.x-k8s.io/delay"]'
32+
jitterDurationMilliseconds: 5000
33+
jitterDurationFrom:
34+
expressionFrom: '.metadata.annotations["pod-complete.stage.kwok.x-k8s.io/jitter-delay"]'
35+
next:
36+
delete: false
37+
statusTemplate: |
38+
{{ `{{ $now := Now }}` }}
39+
{{ `{{ $root := . }}` }}
40+
containerStatuses:
41+
{{ `{{ range $index, $item := .spec.containers }}` }}
42+
{{ `{{ $origin := index $root.status.containerStatuses $index }}` }}
43+
- image: {{ `{{ $item.image | Quote }}` }}
44+
name: {{ `{{ $item.name | Quote }}` }}
45+
ready: true
46+
restartCount: 0
47+
started: false
48+
state:
49+
terminated:
50+
exitCode: 0
51+
finishedAt: {{ `{{ $now | Quote }}` }}
52+
reason: Completed
53+
startedAt: {{ `{{ $now | Quote }}` }}
54+
{{ `{{ end }}` }}
55+
phase: Succeeded
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
apiVersion: kwok.x-k8s.io/v1alpha1
2+
kind: Stage
3+
metadata:
4+
name: pod-create
5+
spec:
6+
resourceRef:
7+
apiGroup: v1
8+
kind: Pod
9+
selector:
10+
matchExpressions:
11+
- key: '.metadata.deletionTimestamp'
12+
operator: 'DoesNotExist'
13+
- key: '.status.podIP'
14+
operator: 'DoesNotExist'
15+
weight: 1
16+
weightFrom:
17+
expressionFrom: '.metadata.annotations["pod-create.stage.kwok.x-k8s.io/weight"]'
18+
delay:
19+
durationMilliseconds: 1000
20+
durationFrom:
21+
expressionFrom: '.metadata.annotations["pod-create.stage.kwok.x-k8s.io/delay"]'
22+
jitterDurationMilliseconds: 5000
23+
jitterDurationFrom:
24+
expressionFrom: '.metadata.annotations["pod-create.stage.kwok.x-k8s.io/jitter-delay"]'
25+
next:
26+
event:
27+
type: Normal
28+
reason: Created
29+
message: Created container
30+
statusTemplate: |
31+
{{ `{{ $now := Now }}` }}
32+
33+
conditions:
34+
{{ `{{ if .spec.initContainers }}` }}
35+
- lastProbeTime: null
36+
lastTransitionTime: {{ `{{ $now | Quote }}` }}
37+
message: 'containers with incomplete status: [{{ `{{ range .spec.initContainers }}` }} {{ `{{ .name }}` }} {{ `{{ end }}` }}]'
38+
reason: ContainersNotInitialized
39+
status: "False"
40+
type: Initialized
41+
{{ `{{ else }}` }}
42+
- lastProbeTime: null
43+
lastTransitionTime: {{ `{{ $now | Quote }}` }}
44+
status: "True"
45+
type: Initialized
46+
{{ `{{ end }}` }}
47+
- lastProbeTime: null
48+
lastTransitionTime: {{ `{{ $now | Quote }}` }}
49+
message: 'containers with unready status: [{{ `{{ range .spec.containers }}` }} {{ `{{ .name }}` }} {{ `{{ end }}` }}]'
50+
reason: ContainersNotReady
51+
status: "False"
52+
type: Ready
53+
- lastProbeTime: null
54+
lastTransitionTime: {{ `{{ $now | Quote }}` }}
55+
message: 'containers with unready status: [{{ `{{ range .spec.containers }}` }} {{ `{{ .name }}` }} {{ `{{ end }}` }}]'
56+
reason: ContainersNotReady
57+
status: "False"
58+
type: ContainersReady
59+
{{ `{{ range .spec.readinessGates }}` }}
60+
- lastTransitionTime: {{ `{{ $now | Quote }}` }}
61+
status: "True"
62+
type: {{ `{{ .conditionType | Quote }}` }}
63+
{{ `{{ end }}` }}
64+
65+
{{ `{{ if .spec.initContainers }}` }}
66+
initContainerStatuses:
67+
{{ `{{ range .spec.initContainers }}` }}
68+
- image: {{ `{{ .image | Quote }}` }}
69+
name: {{ `{{ .name | Quote }}` }}
70+
ready: false
71+
restartCount: 0
72+
started: false
73+
state:
74+
waiting:
75+
reason: PodInitializing
76+
{{ `{{ end }}` }}
77+
containerStatuses:
78+
{{ `{{ range .spec.containers }}` }}
79+
- image: {{ `{{ .image | Quote }}` }}
80+
name: {{ `{{ .name | Quote }}` }}
81+
ready: false
82+
restartCount: 0
83+
started: false
84+
state:
85+
waiting:
86+
reason: PodInitializing
87+
{{ `{{ end }}` }}
88+
{{ `{{ else }}` }}
89+
containerStatuses:
90+
{{ `{{ range .spec.containers }}` }}
91+
- image: {{ `{{ .image | Quote }}` }}
92+
name: {{ `{{ .name | Quote }}` }}
93+
ready: false
94+
restartCount: 0
95+
started: false
96+
state:
97+
waiting:
98+
reason: ContainerCreating
99+
{{ `{{ end }}` }}
100+
{{ `{{ end }}` }}
101+
102+
hostIP: {{ `{{ NodeIPWith .spec.nodeName | Quote }}` }}
103+
podIP: {{ `{{ PodIPWith .spec.nodeName ( or .spec.hostNetwork false ) ( or .metadata.uid "" ) ( or .metadata.name "" ) ( or .metadata.namespace "" ) | Quote }}` }}
104+
phase: Pending
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: kwok.x-k8s.io/v1alpha1
2+
kind: Stage
3+
metadata:
4+
name: pod-delete
5+
spec:
6+
resourceRef:
7+
apiGroup: v1
8+
kind: Pod
9+
selector:
10+
matchExpressions:
11+
- key: '.metadata.deletionTimestamp'
12+
operator: 'Exists'
13+
- key: '.metadata.finalizers'
14+
operator: 'DoesNotExist'
15+
weight: 1
16+
weightFrom:
17+
expressionFrom: '.metadata.annotations["pod-delete.stage.kwok.x-k8s.io/weight"]'
18+
delay:
19+
durationMilliseconds: 1000
20+
durationFrom:
21+
expressionFrom: '.metadata.annotations["pod-delete.stage.kwok.x-k8s.io/delay"]'
22+
jitterDurationFrom:
23+
expressionFrom: '.metadata.deletionTimestamp'
24+
next:
25+
delete: true

0 commit comments

Comments
 (0)