Skip to content

Commit

Permalink
Use job to init CR
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Jun 30, 2023
1 parent 879eed0 commit 8bb904f
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 3 deletions.
27 changes: 27 additions & 0 deletions kustomize/kwok-with-crd/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: batch/v1
kind: Job
metadata:
name: init-kwok-controller
spec:
template:
spec:
containers:
- name: init-kwok-controller
image: registry.k8s.io/kubectl:v1.28.0-alpha.3
imagePullPolicy: IfNotPresent
command:
- kubectl
args:
- apply
- -f
- /init-kwok-controller
volumeMounts:
- mountPath: /init-kwok-controller
name: init-kwok-controller
volumes:
- name: init-kwok-controller
configMap:
name: init-kwok-controller
serviceAccount: kwok-controller
serviceAccountName: kwok-controller
restartPolicy: OnFailure
14 changes: 14 additions & 0 deletions kustomize/kwok-with-crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ kind: Kustomization

resources:
- ../kwok
- job.yaml

patches:
- path: deployment-patch.yaml

configMapGenerator:
- name: init-kwok-controller
files:
- pod-fast.yaml=./pod-fast.yaml
- node-fast.yaml=./node-fast.yaml

namespace: kube-system

labels:
- includeSelectors: true
pairs:
app: kwok-controller
79 changes: 79 additions & 0 deletions kustomize/kwok-with-crd/node-fast.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
kind: Stage
apiVersion: kwok.x-k8s.io/v1alpha1
metadata:
name: node-initialize
spec:
resourceRef:
apiGroup: v1
kind: Node
selector:
matchExpressions:
- key: '.status.conditions.[] | select( .type == "Ready" ) | .status'
operator: 'NotIn'
values:
- 'True'
next:
statusTemplate: |
{{ $now := Now }}
{{ $lastTransitionTime := or .creationTimestamp $now }}
conditions:
{{ range NodeConditions }}
- lastHeartbeatTime: {{ $now | Quote }}
lastTransitionTime: {{ $lastTransitionTime | Quote }}
message: {{ .message | Quote }}
reason: {{ .reason | Quote }}
status: {{ .status | Quote }}
type: {{ .type | Quote}}
{{ end }}
addresses:
{{ with .status.addresses }}
{{ YAML . 1 }}
{{ else }}
{{ with NodeIP }}
- address: {{ . | Quote }}
type: InternalIP
{{ end }}
{{ with NodeName }}
- address: {{ . | Quote }}
type: Hostname
{{ end }}
{{ end }}
{{ with NodePort }}
daemonEndpoints:
kubeletEndpoint:
Port: {{ . }}
{{ end }}
allocatable:
{{ with .status.allocatable }}
{{ YAML . 1 }}
{{ else }}
cpu: 1k
memory: 1Ti
pods: 1M
{{ end }}
capacity:
{{ with .status.capacity }}
{{ YAML . 1 }}
{{ else }}
cpu: 1k
memory: 1Ti
pods: 1M
{{ end }}
{{ with .status.nodeInfo }}
nodeInfo:
architecture: {{ with .architecture }} {{ . }} {{ else }} "amd64" {{ end }}
bootID: {{ with .bootID }} {{ . }} {{ else }} "" {{ end }}
containerRuntimeVersion: {{ with .containerRuntimeVersion }} {{ . }} {{ else }} "kwok-{{ Version }}" {{ end }}
kernelVersion: {{ with .kernelVersion }} {{ . }} {{ else }} "kwok-{{ Version }}" {{ end }}
kubeProxyVersion: {{ with .kubeProxyVersion }} {{ . }} {{ else }} "kwok-{{ Version }}" {{ end }}
kubeletVersion: {{ with .kubeletVersion }} {{ . }} {{ else }} "kwok-{{ Version }}" {{ end }}
machineID: {{ with .machineID }} {{ . }} {{ else }} "" {{ end }}
operatingSystem: {{ with .operatingSystem }} {{ . }} {{ else }} "linux" {{ end }}
osImage: {{ with .osImage }} {{ . }} {{ else }} "" {{ end }}
systemUUID: {{ with .systemUUID }} {{ . }} {{ else }} "" {{ end }}
{{ end }}
phase: Running
immediateNextStage: true
121 changes: 121 additions & 0 deletions kustomize/kwok-with-crd/pod-fast.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
kind: Stage
apiVersion: kwok.x-k8s.io/v1alpha1
metadata:
name: pod-ready
spec:
resourceRef:
apiGroup: v1
kind: Pod
selector:
matchExpressions:
- key: '.metadata.deletionTimestamp'
operator: 'DoesNotExist'
- key: '.status.podIP'
operator: 'DoesNotExist'
next:
statusTemplate: |
{{ $now := Now }}
conditions:
- lastTransitionTime: {{ $now | Quote }}
status: "True"
type: Initialized
- lastTransitionTime: {{ $now | Quote }}
status: "True"
type: Ready
- lastTransitionTime: {{ $now | Quote }}
status: "True"
type: ContainersReady
{{ range .spec.readinessGates }}
- lastTransitionTime: {{ $now | Quote }}
status: "True"
type: {{ .conditionType | Quote }}
{{ end }}
containerStatuses:
{{ range .spec.containers }}
- image: {{ .image | Quote }}
name: {{ .name | Quote }}
ready: true
restartCount: 0
state:
running:
startedAt: {{ $now | Quote }}
{{ end }}
initContainerStatuses:
{{ range .spec.initContainers }}
- image: {{ .image | Quote }}
name: {{ .name | Quote }}
ready: true
restartCount: 0
state:
terminated:
exitCode: 0
finishedAt: {{ $now | Quote }}
reason: Completed
startedAt: {{ $now | Quote }}
{{ end }}
hostIP: {{ NodeIPWith .spec.nodeName | Quote }}
podIP: {{ PodIPWith .spec.nodeName ( or .spec.hostNetwork false ) ( or .metadata.uid "" ) ( or .metadata.name "" ) ( or .metadata.namespace "" ) | Quote }}
phase: Running
startTime: {{ $now | Quote }}
---
kind: Stage
apiVersion: kwok.x-k8s.io/v1alpha1
metadata:
name: pod-complete
spec:
resourceRef:
apiGroup: v1
kind: Pod
selector:
matchExpressions:
- key: '.metadata.deletionTimestamp'
operator: 'DoesNotExist'
- key: '.status.phase'
operator: 'In'
values:
- 'Running'
- key: '.metadata.ownerReferences.[].kind'
operator: 'In'
values:
- 'Job'
next:
statusTemplate: |
{{ $now := Now }}
{{ $root := . }}
containerStatuses:
{{ range $index, $item := .spec.containers }}
{{ $origin := index $root.status.containerStatuses $index }}
- image: {{ $item.image | Quote }}
name: {{ $item.name | Quote }}
ready: false
restartCount: 0
started: false
state:
terminated:
exitCode: 0
finishedAt: {{ $now | Quote }}
reason: Completed
startedAt: {{ $now | Quote }}
{{ end }}
phase: Succeeded
---
kind: Stage
apiVersion: kwok.x-k8s.io/v1alpha1
metadata:
name: pod-delete
spec:
resourceRef:
apiGroup: v1
kind: Pod
selector:
matchExpressions:
- key: '.metadata.deletionTimestamp'
operator: 'Exists'
next:
finalizers:
empty: true
delete: true
4 changes: 2 additions & 2 deletions kustomize/kwok/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: kube-system

resources:
- ../crd
- ../rbac
- service.yaml
- deployment.yaml

namespace: kube-system

labels:
- includeSelectors: true
pairs:
Expand Down
1 change: 0 additions & 1 deletion test/kwok-with-crd/kwok-with-crd.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function start_cluster() {
kind load docker-image --name="${CLUSTER_NAME}" "${KWOK_IMAGE}:${KWOK_VERSION}"

kubectl kustomize "${DIR}" | kubectl apply -f -
kubectl kustomize "${ROOT_DIR}/stages" | kubectl apply -f -
}

# Check for normal heartbeat
Expand Down

0 comments on commit 8bb904f

Please sign in to comment.