Skip to content

Commit

Permalink
Add release manifests stage-fast.yaml and kwokctl.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Jul 19, 2023
1 parent 303c34e commit 5614cd5
Show file tree
Hide file tree
Showing 25 changed files with 673 additions and 57 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ IMAGE_PLATFORMS ?= linux/amd64 linux/arm64

BINARY_PLATFORMS ?= linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64

MANIFESTS ?= kwok kwokctl stage/fast

BUILDER ?= docker
DOCKER_CLI_EXPERIMENTAL ?= enabled

Expand Down Expand Up @@ -219,7 +221,7 @@ cross-cluster-image:
.PHONY: manifests
manifests:
@./hack/manifests.sh \
--kustomize=kwok \
$(addprefix --kustomize=, $(MANIFESTS)) \
--bucket=${BUCKET} \
--gh-release=${GH_RELEASE} \
--image-prefix=${IMAGE_PREFIX} \
Expand Down
9 changes: 5 additions & 4 deletions hack/manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,25 @@ function main() {
dry_run mkdir -p "./artifacts"
dry_run cp -r "./kustomize" "./artifacts/"
for kustomize in "${KUSTOMIZES[@]}"; do
outfile="${kustomize//\//-}"
dry_run cd "./artifacts/kustomize/${kustomize}"
dry_run kustomize edit set image "${DEFAULT_IMAGE_PREFIX}/kwok=${IMAGE_PREFIX}/kwok:${VERSION}"
dry_run kustomize build "." -o "../../${kustomize}.yaml"
dry_run cd -
dry_run rm -r "./artifacts/kustomize"
dry_run kustomize build "./artifacts/kustomize/${kustomize}" -o "./artifacts/${outfile}.yaml"
if [[ "${PUSH}" == "true" ]]; then
if [[ "${BUCKET}" != "" ]]; then
prefix="${BUCKET}/releases/"
if [[ "${STAGING_PREFIX}" != "" ]]; then
prefix="${BUCKET}/releases/${STAGING_PREFIX}-"
fi
dry_run gsutil cp -P "./artifacts/${kustomize}.yaml" "${prefix}${VERSION}/manifests/${kustomize}.yaml"
dry_run gsutil cp -P "./artifacts/${outfile}.yaml" "${prefix}${VERSION}/manifests/${outfile}.yaml"
fi
if [[ "${GH_RELEASE}" != "" ]]; then
dry_run gh -R "${GH_RELEASE}" release upload "${VERSION}" "./artifacts/${kustomize}.yaml"
dry_run gh -R "${GH_RELEASE}" release upload "${VERSION}" "./artifacts/${outfile}.yaml"
fi
fi
done
dry_run rm -r "./artifacts/kustomize"
}

args "$@"
Expand Down
5 changes: 5 additions & 0 deletions kustomize/stage/fast/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../node/fast
- ../pod/fast
7 changes: 7 additions & 0 deletions kustomize/stage/node/fast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Node Fast Stage

This Stage only initializes the node.

The `node-initialize` Stage is applied to nodes that do not have any conditions set in their `status.conditions` field.
When applied, this Stage sets the `status.conditions` field for the node, as well as the `status.addresses`, `status.allocatable`,
and `status.capacity` fields.
4 changes: 4 additions & 0 deletions kustomize/stage/node/fast/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- node-initialize.yaml
78 changes: 78 additions & 0 deletions kustomize/stage/node/fast/node-initialize.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
apiVersion: kwok.x-k8s.io/v1alpha1
kind: Stage
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
6 changes: 6 additions & 0 deletions kustomize/stage/node/heartbeat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Node Heartbeat Stage (DEPRECATED)

This Stage configures the node heartbeat, only for prior to v0.3.

The `node-heartbeat` Stage is applied to nodes that have the `Ready` condition set to `True` in their `status.conditions` field.
When applied, this Stage maintains the `status.conditions` field for the node.
4 changes: 4 additions & 0 deletions kustomize/stage/node/heartbeat/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- node-heartbeat.yaml
35 changes: 35 additions & 0 deletions kustomize/stage/node/heartbeat/node-heartbeat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: kwok.x-k8s.io/v1alpha1
kind: Stage
metadata:
name: node-heartbeat
spec:
resourceRef:
apiGroup: v1
kind: Node
selector:
matchExpressions:
- key: '.status.phase'
operator: 'In'
values:
- 'Running'
- key: '.status.conditions.[] | select( .type == "Ready" ) | .status'
operator: 'In'
values:
- 'True'
delay:
durationMilliseconds: 20000
jitterDurationMilliseconds: 25000
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 }}
immediateNextStage: true
15 changes: 15 additions & 0 deletions kustomize/stage/pod/fast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Pod Fast Stage

These Stages make the pod ready, completed or deleted.

The `pod-ready` Stage is applied to pods that do not have a `status.podIP` set and do not have a `metadata.deletionTimestamp` set.
When applied, this Stage sets the `status.conditions`, `status.containerStatuses`, and `status.initContainerStatuses` fields for the pod,
as well as the `status.hostIP` and `status.podIP` fields. It will also set the phase and startTime fields, indicating that the pod is running and has been started.

The `pod-complete` Stage is applied to pods that are running, do not have a `metadata.deletionTimestamp` set,
and are owned by a Job. When applied, this Stage updates the `status.containerStatuses` field for the pod,
setting the ready and started fields to true and the `state.terminated` field to indicate that the pod has completed.
It also sets the phase field to Succeeded, indicating that the pod has completed successfully.

The `pod-delete` Stage is applied to pods that have a `metadata.deletionTimestamp` set.
When applied, this Stage empties the `metadata.finalizers` field for the pod, allowing it to be deleted, and then delete the pod.
6 changes: 6 additions & 0 deletions kustomize/stage/pod/fast/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- pod-ready.yaml
- pod-complete.yaml
- pod-delete.yaml
40 changes: 40 additions & 0 deletions kustomize/stage/pod/fast/pod-complete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: kwok.x-k8s.io/v1alpha1
kind: Stage
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
16 changes: 16 additions & 0 deletions kustomize/stage/pod/fast/pod-delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: kwok.x-k8s.io/v1alpha1
kind: Stage
metadata:
name: pod-delete
spec:
resourceRef:
apiGroup: v1
kind: Pod
selector:
matchExpressions:
- key: '.metadata.deletionTimestamp'
operator: 'Exists'
next:
finalizers:
empty: true
delete: true
63 changes: 63 additions & 0 deletions kustomize/stage/pod/fast/pod-ready.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: kwok.x-k8s.io/v1alpha1
kind: Stage
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 }}
4 changes: 4 additions & 0 deletions kustomize/stage/pod/general/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Pod General Stage (WIP)

These Stages simulate real Pod behavior as closely as possible in the future,
which is not perfect at the moment, so the refinement of this configuration is still a *Work In Progress*.
10 changes: 10 additions & 0 deletions kustomize/stage/pod/general/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- pod-create.yaml
- pod-init-container-running.yaml
- pod-init-container-completed.yaml
- pod-ready.yaml
- pod-complete.yaml
- pod-remove-finalizer.yaml
- pod-delete.yaml
Loading

0 comments on commit 5614cd5

Please sign in to comment.