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

kwokctl scale command and Resource API #668

Closed
Tracked by #413
wzshiming opened this issue Jun 20, 2023 · 0 comments · Fixed by #707
Closed
Tracked by #413

kwokctl scale command and Resource API #668

wzshiming opened this issue Jun 20, 2023 · 0 comments · Fixed by #707
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Milestone

Comments

@wzshiming
Copy link
Member

wzshiming commented Jun 20, 2023

What would you like to be added?

# Create a Node with generate name "kwok-node"
kwokctl scale node kwok-node --replicas 1
#              |
#         resource name

# Create a Node with generate name "kwok-node-arm64"
kwokctl scale node kwok-node-arm64 --replicas 1 --param '.nodeInfo.architecture="arm64"'
#                                                                               |
#                                                                        Modify the arch

# Create 10 Pods with generate name "fake-pod"
kwokctl scale pod fake-pod --replicas 10 --param '.containers[0].image="nginx"' --param '.containers+=[{name:"name",image:"image"}]'
#                                      |                               |                              |
#                               Scale up to 10 from 0           Modify the image       Inject a new container

# Scale down to 5 Pods
kwokctl scale pod fake-pod --replicas 5

The expression of --param content is JQ

apiVersion: config.kwok.x-k8s.io/v1alpha1
kind: KwokctlResource
metadata:
  name: node
parameters:
  podCIDR: "10.0.0.1/24"
  allocatable:
    cpu: 32
    memory: 256Gi
    pods: 110
  capacity: {}
  nodeInfo:
    architecture: amd64
    operatingSystem: linux
template: |-
  kind: Node
  apiVersion: v1
  metadata:
    name: {{ Name }}
    annotations:
      kwok.x-k8s.io/node: fake
      node.alpha.kubernetes.io/ttl: "0"
    labels:
      beta.kubernetes.io/arch: {{ .nodeInfo.architecture }}
      beta.kubernetes.io/os: {{ .nodeInfo.operatingSystem }}
      kubernetes.io/arch: {{ .nodeInfo.architecture }}
      kubernetes.io/hostname: {{ Name }}
      kubernetes.io/os: {{ .nodeInfo.operatingSystem }}
      kubernetes.io/role: agent
      node-role.kubernetes.io/agent: ""
      type: kwok
  spec:
    podCIDR: {{ AddCIDR .podCIDR Index }}
  status:
    allocatable:
    {{ range $key, $value := .allocatable }}
      {{ $key }}: {{ $value }}
    {{ end }}
    {{ $capacity := .capacity }}
    capacity:
    {{ range $key, $value := .allocatable }}
      {{ $key }}: {{ or ( index $capacity $key ) $value }}
    {{ end }}
    nodeInfo:
    {{ range $key, $value := .nodeInfo }}
      {{ $key }}: {{ $value }}
    {{ end }}

---
apiVersion: config.kwok.x-k8s.io/v1alpha1
kind: KwokctlResource
metadata:
  name: pod
parameters:
  initContainers: []
  containers:
  - name: container-0
    image: busybox
  hostNetwork: false
  nodeName: ""
template: |-
  kind: Pod
  apiVersion: v1
  metadata:
    name: {{ Name }}
    namespace: {{ or Namespace "default" }}
  spec:
    containers:
    {{ range $index, $container := .containers }}
    - name: {{ $container.name }}
      image: {{ $container.image }}
    {{ end }}
    initContainers:
    {{ range $index, $container := .initContainers }}
    - name: {{ $container.name }}
      image: {{ $container.image }}
    {{ end }}
    hostNetwork: {{ .hostNetwork }}
    nodeName: {{ .nodeName }}

Why is this needed?

Easy to mock data

@wzshiming wzshiming mentioned this issue Jun 20, 2023
2 tasks
@wzshiming wzshiming added the kind/feature Categorizes issue or PR as related to a new feature. label Jun 20, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in KWOK Tracking Jun 20, 2023
@wzshiming wzshiming added this to the v0.4 milestone Jun 20, 2023
@wzshiming wzshiming changed the title Resource API kwokctl scale command and Resource API Jun 26, 2023
This was referenced Jul 7, 2023
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in KWOK Tracking Jul 17, 2023
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
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant