kwok
kwok copied to clipboard
Add selector.matchExtraResources into Stage API
What would you like to be added?
Add Trigger API allow to modify any resources
Why is this needed?
Closer to Kubelet
# oom.yaml
apiVersion: kwok.x-k8s.io/v1alpha1
kind: Stage
metadata:
name: oom
spec:
resourceRef:
apiGroup: v1
kind: Pod
selector:
matchExpressions:
- key: .status.phase
operator: In
values:
- Running
matchExtraResources:
- resourceRef:
apiGroup: custom.metrics.k8s.io/v1beta2
kind: MetricValue
selector:
matchCEL:
- expression: |
self.metadata.name == target.metadata.name &&
self.metadata.namespace == target.metadata.namespace &&
OOM(self.spec.containers, target.spec.containers)
next:
patches:
- subresource: status
root: status
template: |
{{ $now := Now }}
{{ $root := target }}
conditions:
- lastProbeTime: null
lastTransitionTime: {{ $now | Quote }}
message: ''
reason: ''
status: "False"
type: Ready
- lastProbeTime: null
lastTransitionTime: {{ $now | Quote }}
message: ''
reason: ''
status: "True"
type: OutOfMemory
containerStatuses:
{{ range $index, $item := .spec.containers }}
{{ $origin := index $root.status.containerStatuses $index }}
- image: {{ $item.image | Quote }}
name: {{ $item.name | Quote }}
ready: false
restartCount: {{ $origin.restartCount }}
started: false
state:
terminated:
exitCode: 137
finishedAt: {{ $now | Quote }}
reason: OOMKilled
startedAt: {{ $now | Quote }}
{{ end }}
phase: Failed
# node-image-exists.yaml
apiVersion: kwok.x-k8s.io/v1alpha1
kind: Stage
metadata:
name: node-image-exists
spec:
resourceRef:
apiGroup: v1
kind: Node
selector:
matchExtraResources:
- resourceRef:
apiGroup: v1
kind: Pod
selector:
matchExpressions:
- key: .status.phase
operator: In
values:
- Running
- ContainerCreating
next:
patches:
- subresource: status
root: status
template: |
{{ $exist := list }}
images:
{{ range .status.images }}
- names:
{{ range .names }}
{{ $exist = append $exist . }}
- {{ . | Quote }}
{{ end }}
{{ if .sizeBytes }}
sizeBytes: {{ .sizeBytes }}
{{ end }}
{{ end }}
{{ range matchExtraResources }}
{{ range .spec.containers }}
{{ if not (in $exist .image) }}
- names:
- {{ .image | Quote }}
{{ end }}
{{ end }}
{{ end }}
Whats the major difference between Trigger
and Stage v1alpha2
? Do they have any overlap in functionality?
Whats the major difference between
Trigger
andStage v1alpha2
?
Trigger can be thought of as a Stage between different resources.
Redesigning the API to put it in Stage
Hi @wzshiming with the reference of #839 , I have figured that you planned to redesign the API instead of adding a template function to node template that would look like this
images:
{{ with NodeImages status.images }}
{{ YAML . 1 }}
{{ end }}
Can you guide how to achieve this trigger API? Do I have to include corresponding .yaml
files(Commented) to kustomize/stage/pod/fast/
and kustomize/stage/node/fast/
directories in order to achieve the resource matching in the API configuration.
If YES, how can I test my changes after applying them as I have already successfully setup the KWOK project in my local system (MacOS arm64)