Skip to content

Commit

Permalink
Add kwok operator
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Sep 5, 2024
1 parent 4726c33 commit 8789928
Show file tree
Hide file tree
Showing 69 changed files with 2,889 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ jobs:
run: |
./hack/e2e-test.sh e2e/kwok/single
- name: Test e2e single
shell: bash
run: |
./hack/e2e-test.sh e2e/kwok/operator
test-kwok:
strategy:
fail-fast: false
Expand Down
46 changes: 43 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ KUBE_RELEASES ?= $(shell echo $(SUPPORTED_KUBE_RELEASES) | cut -d ' ' -f 1-$(NUM
# The latest kube release
LATEST_KUBE_RELEASE ?= $(shell echo $(SUPPORTED_KUBE_RELEASES) | cut -d ' ' -f 1)

BINARY ?= kwok kwokctl
BINARY ?= kwok kwokctl kwok-operator

IMAGE_PREFIX ?=

Expand All @@ -64,9 +64,11 @@ PRE_RELEASE ?=

ifeq ($(STAGING_IMAGE_PREFIX),)
KWOK_IMAGE ?= kwok
KWOK_OPERATOR_IMAGE ?= operator
CLUSTER_IMAGE ?= cluster
else
KWOK_IMAGE ?= $(STAGING_IMAGE_PREFIX)/kwok
KWOK_OPERATOR_IMAGE ?= $(STAGING_IMAGE_PREFIX)/kwok-operator
CLUSTER_IMAGE ?= $(STAGING_IMAGE_PREFIX)/cluster
endif

Expand All @@ -76,7 +78,7 @@ IMAGE_PLATFORMS ?= linux/amd64 linux/arm64

BINARY_PLATFORMS ?= linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64

MANIFESTS ?= kwok kwokctl stage/fast metrics/usage
MANIFESTS ?= kwok kwokctl operator stage/fast metrics/usage

BUILDER ?= docker
DOCKER_CLI_EXPERIMENTAL ?= enabled
Expand Down Expand Up @@ -143,7 +145,20 @@ else
@echo "Unsupported OS: $(GOOS)"
endif

## cross-build: Build kwok and kwokctl for all supported platforms
## build-operator-image: Build operator binary and image
.PHONY: build-operator-image
build-operator-image:
ifeq ($(GOOS),linux)
@make BINARY=kwok-operator build && \
make operator-image
else ifeq ($(GOOS),darwin)
@make BINARY=kwok-operator BINARY_PLATFORMS=linux/$(GOARCH) cross-build && \
make IMAGE_PLATFORMS=linux/$(GOARCH) cross-operator-image
else
@echo "Unsupported OS: $(GOOS)"
endif

## cross-build: Build kwok, kwok-operator and kwokctl for all supported platforms
.PHONY: cross-build
cross-build:
@./hack/releases.sh \
Expand Down Expand Up @@ -187,6 +202,31 @@ cross-image:
--builder=${BUILDER} \
--push=${PUSH}

## operator-image: Build kwok operator image
.PHONY: operator-image
operator-image:
@./images/kwok-operator/build.sh \
$(addprefix --extra-tag=, $(EXTRA_TAGS)) \
--image=${KWOK_OPERATOR_IMAGE} \
--version=${VERSION} \
--staging-prefix=${STAGING_PREFIX} \
--dry-run=${DRY_RUN} \
--builder=${BUILDER} \
--push=${PUSH}

## cross-operator-image: Build kwok operator images for all supported platforms
.PHONY: cross-operator-image
cross-operator-image:
@./images/operator/build.sh \
$(addprefix --platform=, $(IMAGE_PLATFORMS)) \
$(addprefix --extra-tag=, $(EXTRA_TAGS)) \
--image=${KWOK_OPERATOR_IMAGE} \
--version=${VERSION} \
--staging-prefix=${STAGING_PREFIX} \
--dry-run=${DRY_RUN} \
--builder=${BUILDER} \
--push=${PUSH}

## cluster-image: Build cluster image
.PHONY: cluster-image
cluster-image:
Expand Down
1 change: 1 addition & 0 deletions charts/operator/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.helmignore
17 changes: 17 additions & 0 deletions charts/operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v2
description: KWOK Operator
type: application
home: https://kwok.sigs.k8s.io
icon: https://github.com/kubernetes-sigs/kwok/raw/main/logo/kwok.png
keywords:
- kubernetes
- kwok
- operator
sources:
- https://github.com/kubernetes-sigs/kwok
name: operator
maintainers:
- name: wzshiming
email: [email protected]
appVersion: v0.6.0
version: 0.0.1
49 changes: 49 additions & 0 deletions charts/operator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# KWOK (Kubernetes WithOut Kubelet)

[KWOK](https://kwok.sigs.k8s.io/) - 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
```

Set up default metrics usage policy (optional)

```shell
helm upgrade --install kwok kwok/metrics-usage
```

## Configuration

The following table lists the configurable parameters of the kwok chart and their default values.

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| affinity | object | `{}` | |
| fullnameOverride | string | `"kwok-controller"` | Override the `fullname` of the chart. |
| image.pullPolicy | string | `"IfNotPresent"` | Image pull policy. |
| image.repository | string | `"registry.k8s.io/kwok/kwok"` | Image repository. |
| image.tag | string | `""` | Overrides the image tag whose default is {{ .Chart.AppVersion }}. |
| imagePullSecrets | list | `[]` | Image pull secrets. |
| nameOverride | string | `""` | Override the `name` of the chart. |
| nodeSelector | object | `{}` | |
| podSecurityContext | object | `{}` | |
| replicas | int | `1` | The replica count for Deployment. |
| resources | object | `{}` | |
| securityContext | object | `{}` | |
9 changes: 9 additions & 0 deletions charts/operator/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# {{ template "chart.description" . }}

{{ template "extra.usage" . }}

## Configuration

The following table lists the configurable parameters of the kwok chart and their default values.

{{ template "chart.valuesTable" . }}
1 change: 1 addition & 0 deletions charts/operator/crds
62 changes: 62 additions & 0 deletions charts/operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "kwok.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "kwok.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "kwok.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "kwok.labels" -}}
helm.sh/chart: {{ include "kwok.chart" . }}
{{ include "kwok.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "kwok.selectorLabels" -}}
app.kubernetes.io/name: {{ include "kwok.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "kwok.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "kwok.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
46 changes: 46 additions & 0 deletions charts/operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "kwok.fullname" . }}
labels:
{{- include "kwok.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
{{- include "kwok.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "kwok.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "kwok.fullname" . }}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Always
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
securityContext:
{{- toYaml .Values.securityContext | nindent 10 }}
resources:
{{- toYaml .Values.resources | nindent 10 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
47 changes: 47 additions & 0 deletions charts/operator/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kwok-operator
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- create
- delete
- get
- apiGroups:
- apps
resources:
- deployments
verbs:
- get
- list
- watch
- apiGroups:
- apps
resources:
- deployments/scale
verbs:
- update
- apiGroups:
- kwok.x-k8s.io
resources:
- controllers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- kwok.x-k8s.io
resources:
- controllers/status
verbs:
- patch
- update
12 changes: 12 additions & 0 deletions charts/operator/templates/role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kwok-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kwok-operator
subjects:
- kind: ServiceAccount
name: kwok-operator
namespace: {{ .Release.Namespace }}
5 changes: 5 additions & 0 deletions charts/operator/templates/service_account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: kwok-operator
namespace: {{ .Release.Namespace }}
26 changes: 26 additions & 0 deletions charts/operator/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
image:
# -- Image pull policy.
pullPolicy: IfNotPresent
# -- Image repository.
repository: registry.k8s.io/kwok/operator
# -- Overrides the image tag whose default is {{ .Chart.AppVersion }}.
tag: ""

# -- Image pull secrets.
imagePullSecrets: []

# -- Override the `name` of the chart.
nameOverride: ""

# -- Override the `fullname` of the chart.
fullnameOverride: "kwok-operator"

podSecurityContext: {}
securityContext: {}

nodeSelector: {}
resources: {}
affinity: {}

# -- The replica count for Deployment.
replicas: 1
Loading

0 comments on commit 8789928

Please sign in to comment.