Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add selector.matchExtraResources into Stage API #977

Open
wzshiming opened this issue Feb 18, 2024 · 6 comments
Open

Add selector.matchExtraResources into Stage API #977

wzshiming opened this issue Feb 18, 2024 · 6 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Milestone

Comments

@wzshiming
Copy link
Member

What would you like to be added?

Add Trigger API allow to modify any resources

Why is this needed?

Closer to Kubelet

@wzshiming wzshiming added the kind/feature Categorizes issue or PR as related to a new feature. label Feb 18, 2024
@wzshiming
Copy link
Member Author

wzshiming commented Feb 18, 2024

# 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

@wzshiming
Copy link
Member Author

wzshiming commented Feb 18, 2024

# 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 }}

@caozhuozi
Copy link
Contributor

caozhuozi commented Feb 19, 2024

Whats the major difference between Trigger and Stage v1alpha2? Do they have any overlap in functionality?

@wzshiming
Copy link
Member Author

Whats the major difference between Trigger and Stage v1alpha2?

Trigger can be thought of as a Stage between different resources.

@wzshiming wzshiming added this to the v0.6 milestone Feb 19, 2024
@wzshiming wzshiming pinned this issue Mar 1, 2024
@wzshiming wzshiming unpinned this issue Mar 6, 2024
@wzshiming wzshiming changed the title Add Trigger API Add selector.matchExtraResources into Stage API Mar 6, 2024
@wzshiming
Copy link
Member Author

Redesigning the API to put it in Stage

@Manoramsharma
Copy link
Contributor

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

3 participants