diff --git a/.ct.yaml b/.ct.yaml new file mode 100644 index 000000000..9fe0628d1 --- /dev/null +++ b/.ct.yaml @@ -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 diff --git a/.github/workflows/helm-lint-test.yaml b/.github/workflows/helm-lint-test.yaml index eebfcd276..a2fd88445 100644 --- a/.github/workflows/helm-lint-test.yaml +++ b/.github/workflows/helm-lint-test.yaml @@ -4,9 +4,11 @@ on: pull_request: paths: - charts/**/* + - .ct.yaml push: paths: - charts/**/* + - .ct.yaml jobs: lint-test: @@ -40,7 +42,7 @@ 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' @@ -48,7 +50,7 @@ jobs: - 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 diff --git a/.github/workflows/helm-releases.yaml b/.github/workflows/helm-releases.yaml index f15c93b84..d05294042 100644 --- a/.github/workflows/helm-releases.yaml +++ b/.github/workflows/helm-releases.yaml @@ -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 }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d310b5ef2..ab0fab477 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,6 +10,7 @@ on: - kustomize/**/* - go.mod - .github/workflows/test.yaml + - '!hack/releases-helm-chart.sh' push: paths: - pkg/**/* @@ -19,6 +20,7 @@ on: - kustomize/**/* - go.mod - .github/workflows/test.yaml + - '!hack/releases-helm-chart.sh' env: DOCKER_CLI_EXPERIMENTAL: "enabled" diff --git a/charts/metrics-usage/.helmignore b/charts/metrics-usage/.helmignore new file mode 100644 index 000000000..6b8c0abba --- /dev/null +++ b/charts/metrics-usage/.helmignore @@ -0,0 +1 @@ +.helmignore diff --git a/charts/metrics-usage/Chart.yaml b/charts/metrics-usage/Chart.yaml new file mode 100644 index 000000000..6ddc88db1 --- /dev/null +++ b/charts/metrics-usage/Chart.yaml @@ -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: wzshiming@hotmail.com +appVersion: v0.5.2 +version: 0.0.1 +dependencies: +- name: kwok + version: 0.0.1 + repository: https://kwok.sigs.k8s.io/charts/ diff --git a/charts/metrics-usage/README.md b/charts/metrics-usage/README.md new file mode 100644 index 000000000..f0f10f0c3 --- /dev/null +++ b/charts/metrics-usage/README.md @@ -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 +``` diff --git a/charts/metrics-usage/templates/metrics-resource.yaml b/charts/metrics-usage/templates/metrics-resource.yaml new file mode 100644 index 000000000..a542a65ec --- /dev/null +++ b/charts/metrics-usage/templates/metrics-resource.yaml @@ -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")' diff --git a/charts/metrics-usage/templates/usage-from-annotation.yaml b/charts/metrics-usage/templates/usage-from-annotation.yaml new file mode 100644 index 000000000..11876e758 --- /dev/null +++ b/charts/metrics-usage/templates/usage-from-annotation.yaml @@ -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") diff --git a/charts/metrics-usage/values.yaml b/charts/metrics-usage/values.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/hack/releases-helm-charts.sh b/hack/releases-helm-charts.sh index 5d837f3ce..034df3e97 100755 --- a/hack/releases-helm-charts.sh +++ b/hack/releases-helm-charts.sh @@ -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" || : diff --git a/hack/update-helm-charts.sh b/hack/update-helm-charts.sh index 466e92874..9f537a487 100755 --- a/hack/update-helm-charts.sh +++ b/hack/update-helm-charts.sh @@ -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 @@ -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