Skip to content

Commit

Permalink
Add kwok metrics usage chart
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Jul 3, 2024
1 parent 51af635 commit a815fd1
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .ct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
remote: origin
target-branch: main

validate-maintainers: false
check-version-increment: false

chart-repos:
- kwok=https://kwok.sigs.k8s.io/charts/
helm-extra-args: --timeout 800s

chart-dirs:
- charts
6 changes: 4 additions & 2 deletions .github/workflows/helm-lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
pull_request:
paths:
- charts/**/*
- .ct.yaml
push:
paths:
- charts/**/*
- .ct.yaml

jobs:
lint-test:
Expand Down Expand Up @@ -40,15 +42,15 @@ jobs:
- name: Run chart-testing (lint)
if: steps.list-changed.outputs.changed == 'true'
run: ct lint --target-branch ${{ github.event.repository.default_branch }}
run: ct lint --target-branch ${{ github.event.repository.default_branch }} --config ./.ct.yaml

- name: Create kind cluster
if: steps.list-changed.outputs.changed == 'true'
uses: helm/[email protected]

- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.event.repository.default_branch }}
run: ct install --target-branch ${{ github.event.repository.default_branch }} --config ./.ct.yaml

linter-artifacthub:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/helm-releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
paths:
- charts/kwok/Chart.yaml
- charts/stage-fast/Chart.yaml
- charts/metrics-usage/Chart.yaml

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- kustomize/**/*
- go.mod
- .github/workflows/test.yaml
- '!hack/releases-helm-chart.sh'
push:
paths:
- pkg/**/*
Expand All @@ -19,6 +20,7 @@ on:
- kustomize/**/*
- go.mod
- .github/workflows/test.yaml
- '!hack/releases-helm-chart.sh'

env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
Expand Down
1 change: 1 addition & 0 deletions charts/metrics-usage/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.helmignore
21 changes: 21 additions & 0 deletions charts/metrics-usage/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
description: Default metrics usage policy of KWOK (Kubernetes WithOut Kubelet)
type: application
home: https://kwok.sigs.k8s.io
icon: https://github.com/kubernetes-sigs/kwok/raw/main/logo/kwok.png
keywords:
- kubernetes
- kwok
- kwok metrics usage policy
sources:
- https://github.com/kubernetes-sigs/kwok
name: metrics-usage
maintainers:
- name: wzshiming
email: [email protected]
appVersion: v0.5.2
version: 0.0.1
dependencies:
- name: kwok
version: 0.0.1
repository: https://kwok.sigs.k8s.io/charts/
24 changes: 24 additions & 0 deletions charts/metrics-usage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Default metrics usage of KWOK (Kubernetes WithOut Kubelet)

[KWOK](https://github.com/kubernetes-sigs/kwok/) - Simulates thousands of Nodes and Clusters.

## Installing the Chart

Before you can install the chart you will need to add the `kwok` repo to [Helm](https://helm.sh/).

```shell
helm repo add kwok https://kwok.sigs.k8s.io/charts/
```

After you've installed the repo you can install the chart.

```shell
helm upgrade --namespace kube-system --install kwok kwok/kwok
```

Set up default stage policy (required)
> NOTE: This configures the pod/node emulation behavior, if not it will do nothing.
```shell
helm upgrade --install kwok kwok/stage-fast
```
92 changes: 92 additions & 0 deletions charts/metrics-usage/templates/metrics-resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
kind: Metric
apiVersion: kwok.x-k8s.io/v1alpha1
metadata:
name: metrics-resource
spec:
path: "/metrics/nodes/{nodeName}/metrics/resource"
metrics:
- name: scrape_error
dimension: node
help: |
[ALPHA] 1 if there was an error while getting metrics from the node, 0 otherwise
kind: gauge
value: '0'
- name: container_start_time_seconds
dimension: container
help: |
[ALPHA] Start time of the container since unix epoch in seconds
kind: gauge
labels:
- name: container
value: 'container.name'
- name: namespace
value: 'pod.metadata.namespace'
- name: pod
value: 'pod.metadata.name'
value: 'pod.SinceSecond()'
# CPU of the container
- name: container_cpu_usage_seconds_total
dimension: container
help: |
[ALPHA] Cumulative cpu time consumed by the container in core-seconds
kind: counter
labels:
- name: container
value: 'container.name'
- name: namespace
value: 'pod.metadata.namespace'
- name: pod
value: 'pod.metadata.name'
value: 'pod.CumulativeUsage("cpu", container.name)'
# Memory of the container
- name: container_memory_working_set_bytes
dimension: container
help: |
[ALPHA] Current working set of the container in bytes
kind: gauge
labels:
- name: container
value: 'container.name'
- name: namespace
value: 'pod.metadata.namespace'
- name: pod
value: 'pod.metadata.name'
value: 'pod.Usage("memory", container.name)'
# CPU of the pod
- name: pod_cpu_usage_seconds_total
dimension: pod
help: |
[ALPHA] Cumulative cpu time consumed by the pod in core-seconds
kind: counter
labels:
- name: namespace
value: 'pod.metadata.namespace'
- name: pod
value: 'pod.metadata.name'
value: 'pod.CumulativeUsage("cpu")'
# Memory of the pod
- name: pod_memory_working_set_bytes
dimension: pod
help: |
[ALPHA] Current working set of the pod in bytes
kind: gauge
labels:
- name: namespace
value: 'pod.metadata.namespace'
- name: pod
value: 'pod.metadata.name'
value: 'pod.Usage("memory")'
# CPU of the node
- name: node_cpu_usage_seconds_total
dimension: node
help: |
[ALPHA] Cumulative cpu time consumed by the node in core-seconds
kind: counter
value: 'node.CumulativeUsage("cpu")'
# Memory of the node
- name: node_memory_working_set_bytes
dimension: node
help: |
[ALPHA] Current working set of the node in bytes
kind: gauge
value: 'node.Usage("memory")'
17 changes: 17 additions & 0 deletions charts/metrics-usage/templates/usage-from-annotation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: kwok.x-k8s.io/v1alpha1
kind: ClusterResourceUsage
metadata:
name: usage-from-annotation
spec:
usages:
- usage:
cpu:
expression: |
"kwok.x-k8s.io/usage-cpu" in pod.metadata.annotations
? Quantity(pod.metadata.annotations["kwok.x-k8s.io/usage-cpu"])
: Quantity("1m")
memory:
expression: |
"kwok.x-k8s.io/usage-memory" in pod.metadata.annotations
? Quantity(pod.metadata.annotations["kwok.x-k8s.io/usage-memory"])
: Quantity("1Mi")
Empty file.
1 change: 1 addition & 0 deletions hack/releases-helm-charts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ index_dir="${ROOT_DIR}/site/static/charts"

package_and_index "${index_dir}" "${chart_dir}/kwok" "kwok-chart" || :
package_and_index "${index_dir}" "${chart_dir}/stage-fast" "kwok-stage-fast-chart" || :
package_and_index "${index_dir}" "${chart_dir}/metrics-usage" "kwok-metrics-usage-chart" || :
10 changes: 10 additions & 0 deletions hack/update-helm-charts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ function sync_stage_to_chart() {
>"${dest}"
}

function sync_to_chart() {
local src=$1
local dest=$2

cp "${src}" "${dest}"
}

function sync() {
sync_object_to_chart kustomize/rbac/role.yaml charts/kwok/templates/role.yaml
sync_object_to_chart kustomize/rbac/role_binding.yaml charts/kwok/templates/role_binding.yaml
Expand All @@ -56,6 +63,9 @@ function sync() {

sync_stage_to_chart kustomize/stage/node/fast/node-initialize.yaml charts/stage-fast/templates/node-initialize.yaml
sync_stage_to_chart kustomize/stage/node/heartbeat-with-lease/node-heartbeat-with-lease.yaml charts/stage-fast/templates/node-heartbeat-with-lease.yaml

sync_stage_to_chart kustomize/metrics/resource/metrics-resource.yaml charts/metrics-usage/templates/metrics-resource.yaml
sync_stage_to_chart kustomize/metrics/usage/usage-from-annotation.yaml charts/metrics-usage/templates/usage-from-annotation.yaml
}

cd "${ROOT_DIR}" && sync

0 comments on commit a815fd1

Please sign in to comment.