diff --git a/.github/workflows/ah-lint.yaml b/.github/workflows/ah-lint.yaml new file mode 100644 index 00000000..adc05d75 --- /dev/null +++ b/.github/workflows/ah-lint.yaml @@ -0,0 +1,27 @@ +name: ArtifactHub Lint + +# permissions: {} + +on: + pull_request: + branches: + - '*' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + required: + runs-on: ubuntu-latest + container: + image: artifacthub/ah + options: --user root + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Run ah lint + working-directory: ./charts/ + run: | + set -e + ah lint diff --git a/.github/workflows/ct-lint.yaml b/.github/workflows/ct-lint.yaml new file mode 100644 index 00000000..738fb56f --- /dev/null +++ b/.github/workflows/ct-lint.yaml @@ -0,0 +1,33 @@ +name: CT Lint + +# permissions: {} + +on: + pull_request: + branches: + - '*' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + required: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + fetch-depth: 0 + - name: Set up Helm + uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5 + - name: Setup python + uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1 + with: + python-version: 3.7 + - name: Set up chart-testing + uses: helm/chart-testing-action@e8788873172cb653a90ca2e819d79d65a66d4e76 # v2.4.0 + - name: Run chart-testing (lint) + run: | + set -e + ct lint --target-branch=main --check-version-increment=false diff --git a/.github/workflows/helm-install.yaml b/.github/workflows/helm-install.yaml new file mode 100644 index 00000000..01da90ad --- /dev/null +++ b/.github/workflows/helm-install.yaml @@ -0,0 +1,32 @@ +name: Helm install + +# permissions: {} + +on: + pull_request: + branches: + - '*' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + required: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Set up Go + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 + with: + go-version-file: go.mod + cache-dependency-path: go.sum + - name: Create cluster + run: | + set -e + make kind-create + - name: Install chart + run: | + set -e + make kind-install diff --git a/.gitignore b/.gitignore index c9390ab3..86395a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .DS_Store .tools .gopath -kyverno-json +/kyverno-json website/site playground/assets/main.wasm diff --git a/Makefile b/Makefile index 8c77da36..dd658a59 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,24 @@ .DEFAULT_GOAL := build +########## +# CONFIG # +########## + +ORG ?= kyverno +PACKAGE ?= github.com/$(ORG)/kyverno-json +KIND_IMAGE ?= kindest/node:v1.28.0 +KIND_NAME ?= kind +GIT_SHA := $(shell git rev-parse HEAD) +GOOS ?= $(shell go env GOOS) +GOARCH ?= $(shell go env GOARCH) +REGISTRY ?= ghcr.io +REPO ?= kyverno-json +LOCAL_PLATFORM := linux/$(GOARCH) +KO_REGISTRY := ko.local +KO_PLATFORMS := all +KO_TAGS := $(GIT_SHA) +KO_CACHE ?= /tmp/ko-cache + ######### # TOOLS # ######### @@ -17,7 +36,11 @@ REFERENCE_DOCS := $(TOOLS_DIR)/genref REFERENCE_DOCS_VERSION := latest KIND := $(TOOLS_DIR)/kind KIND_VERSION := v0.20.0 -TOOLS := $(CLIENT_GEN) $(LISTER_GEN) $(INFORMER_GEN) $(REGISTER_GEN) $(DEEPCOPY_GEN) $(CONTROLLER_GEN) $(REFERENCE_DOCS) $(KIND) +HELM := $(TOOLS_DIR)/helm +HELM_VERSION := v3.10.1 +KO := $(TOOLS_DIR)/ko +KO_VERSION := v0.14.1 +TOOLS := $(CLIENT_GEN) $(LISTER_GEN) $(INFORMER_GEN) $(REGISTER_GEN) $(DEEPCOPY_GEN) $(CONTROLLER_GEN) $(REFERENCE_DOCS) $(KIND) $(HELM) $(KO) PIP ?= "pip" ifeq ($(GOOS), darwin) SED := gsed @@ -58,6 +81,14 @@ $(KIND): @echo Install kind... >&2 @GOBIN=$(TOOLS_DIR) go install sigs.k8s.io/kind@$(KIND_VERSION) +$(HELM): + @echo Install helm... >&2 + @GOBIN=$(TOOLS_DIR) go install helm.sh/helm/v3/cmd/helm@$(HELM_VERSION) + +$(KO): + @echo Install ko... >&2 + @GOBIN=$(TOOLS_DIR) go install github.com/google/ko@$(KO_VERSION) + .PHONY: install-tools install-tools: $(TOOLS) ## Install tools @@ -72,7 +103,6 @@ clean-tools: ## Remove installed tools CLI_BIN := kyverno-json CGO_ENABLED ?= 0 -GOOS ?= $(shell go env GOOS) ifdef VERSION LD_FLAGS := "-s -w -X $(PACKAGE)/pkg/version.BuildVersion=$(VERSION)" else @@ -104,17 +134,20 @@ build-wasm: fmt vet ## Build the wasm binary serve: build-wasm ## Serve static files. python3 -m http.server -d playground/ 8080 +.PHONY: ko-build +ko-build: $(KO) ## Build image (with ko) + @echo Build image with ko... >&2 + @LDFLAGS=$(LD_FLAGS) KOCACHE=$(KO_CACHE) KO_DOCKER_REPO=$(KO_REGISTRY) \ + $(KO) build . --preserve-import-paths --tags=$(KO_TAGS) --platform=$(LOCAL_PLATFORM) + ########### # CODEGEN # ########### -ORG ?= kyverno -PACKAGE ?= github.com/$(ORG)/kyverno-json GOPATH_SHIM := ${PWD}/.gopath PACKAGE_SHIM := $(GOPATH_SHIM)/src/$(PACKAGE) INPUT_DIRS := $(PACKAGE)/pkg/apis/v1alpha1 CRDS_PATH := ${PWD}/config/crds -KIND_IMAGE ?= kindest/node:v1.28.0 INPUT_DIRS := $(PACKAGE)/pkg/apis/v1alpha1 OUT_PACKAGE := $(PACKAGE)/pkg/client CLIENTSET_PACKAGE := $(OUT_PACKAGE)/clientset @@ -234,8 +267,29 @@ codegen-schema-json: codegen-schema-openapi ## Generate json schemas .PHONY: codegen-schema-all codegen-schema-all: codegen-schema-openapi codegen-schema-json ## Generate openapi and json schemas +.PHONY: codegen-helm-crds +codegen-helm-crds: codegen-crds ## Generate helm CRDs + @echo Generate helm crds... >&2 + @cat $(CRDS_PATH)/* \ + | $(SED) -e '1i{{- if .Values.crds.install }}' \ + | $(SED) -e '$$a{{- end }}' \ + | $(SED) -e '/^ annotations:/a \ \ \ \ {{- end }}' \ + | $(SED) -e '/^ annotations:/a \ \ \ \ {{- toYaml . | nindent 4 }}' \ + | $(SED) -e '/^ annotations:/a \ \ \ \ {{- with .Values.crds.annotations }}' \ + | $(SED) -e '/^ annotations:/i \ \ labels:' \ + | $(SED) -e '/^ labels:/a \ \ \ \ {{- end }}' \ + | $(SED) -e '/^ labels:/a \ \ \ \ {{- toYaml . | nindent 4 }}' \ + | $(SED) -e '/^ labels:/a \ \ \ \ {{- with .Values.crds.labels }}' \ + | $(SED) -e '/^ labels:/a \ \ \ \ {{- include "kyverno-json.labels" . | nindent 4 }}' \ + > ./charts/kyverno-json/templates/crds.yaml + +.PHONY: codegen-helm-docs +codegen-helm-docs: ## Generate helm docs + @echo Generate helm docs... >&2 + @docker run -v ${PWD}/charts:/work -w /work jnorwood/helm-docs:v1.11.0 -s file + .PHONY: codegen -codegen: codegen-crds codegen-deepcopy codegen-register codegen-client codegen-docs codegen-mkdocs codegen-schema-all ## Rebuild all generated code and docs +codegen: codegen-crds codegen-deepcopy codegen-register codegen-client codegen-docs codegen-mkdocs codegen-schema-all codegen-helm-docs ## Rebuild all generated code and docs .PHONY: verify-codegen verify-codegen: codegen ## Verify all generated code and docs are up to date @@ -258,10 +312,28 @@ tests: $(CLI_BIN) ## Run tests # KIND # ######## -.PHONY: kind-cluster -kind-cluster: $(KIND) ## Create kind cluster +.PHONY: kind-create +kind-create: $(KIND) ## Create kind cluster @echo Create kind cluster... >&2 - @$(KIND) create cluster --image $(KIND_IMAGE) + @$(KIND) create cluster --name $(KIND_NAME) --image $(KIND_IMAGE) + +.PHONY: kind-delete +kind-delete: $(KIND) ## Delete kind cluster + @echo Delete kind cluster... >&2 + @$(KIND) delete cluster --name $(KIND_NAME) + +.PHONY: kind-load +kind-load: $(KIND) ko-build ## Build image and load in kind cluster + @echo Load image... >&2 + @$(KIND) load docker-image --name $(KIND_NAME) $(KO_REGISTRY)/$(PACKAGE):$(GIT_SHA) + +.PHONY: kind-install +kind-install: $(HELM) kind-load ## Build image, load it in kind cluster and deploy helm chart + @echo Install chart... >&2 + @$(HELM) upgrade --install kyverno-json --namespace kyverno-json --create-namespace --wait ./charts/kyverno-json \ + --set image.registry=$(KO_REGISTRY) \ + --set image.repository=$(PACKAGE) \ + --set image.tag=$(GIT_SHA) ########### # INSTALL # diff --git a/charts/kyverno-json/.helmignore b/charts/kyverno-json/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/charts/kyverno-json/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/kyverno-json/Chart.yaml b/charts/kyverno-json/Chart.yaml new file mode 100644 index 00000000..afd3f39e --- /dev/null +++ b/charts/kyverno-json/Chart.yaml @@ -0,0 +1,16 @@ +apiVersion: v2 +name: kyverno-json +type: application +version: 0.1.0 +appVersion: v0.1.0 +icon: https://github.com/kyverno/kyverno-json/blob/main/website/docs/static/kyverno-json-logo.png +description: Kyverno for JSON +keywords: + - kubernetes + - policy agent +sources: + - https://github.com/kyverno/kyverno-json +maintainers: + - name: Nirmata + url: https://kyverno.io/ +kubeVersion: ">=1.16.0-0" diff --git a/charts/kyverno-json/README.md b/charts/kyverno-json/README.md new file mode 100644 index 00000000..1ec95255 --- /dev/null +++ b/charts/kyverno-json/README.md @@ -0,0 +1,91 @@ +# kyverno-json + +Kyverno for JSON + +![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.1.0](https://img.shields.io/badge/AppVersion-v0.1.0-informational?style=flat-square) + +## About + +TODO + +## Features + +TODO + +## Installing the Chart + +Add `kyverno-json` Helm repository: + +```shell +helm repo add kyverno-json https://kyverno.github.io/kyverno-json/ +``` + +Install `kyverno-json` Helm chart: + +```shell +helm install kyverno-json --namespace kyverno --create-namespace kyverno-json/kyverno-json +``` + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| nameOverride | string | `""` | Name override | +| fullnameOverride | string | `""` | Full name override | +| crds.install | bool | `true` | Whether to have Helm install the CRDs, if the CRDs are not installed by Helm, they must be added before policies can be created | +| crds.annotations | object | `{}` | Additional CRDs annotations | +| crds.labels | object | `{}` | Additional CRDs labels | +| replicaCount | int | `1` | Number of pod replicas | +| image.registry | string | `"ghcr.io"` | Image registry | +| image.repository | string | `"kyverno/kyverno-json"` | Image repository | +| image.pullPolicy | string | `"IfNotPresent"` | Image pull policy | +| image.tag | string | `nil` | Image tag (will default to app version if not set) | +| imagePullSecrets | list | `[]` | Image pull secrets | +| priorityClassName | string | `""` | Priority class name | +| serviceAccount.create | bool | `true` | Create service account | +| serviceAccount.annotations | object | `{}` | Service account annotations | +| serviceAccount.name | string | `""` | Service account name (required if `serviceAccount.create` is `false`) | +| podAnnotations | object | `{}` | Pod annotations | +| podSecurityContext | object | `{"fsGroup":2000}` | Pod security context | +| securityContext | object | See [values.yaml](values.yaml) | Container security context | +| service.type | string | `"ClusterIP"` | Service type | +| service.port | int | `8080` | Service port | +| ingress.enabled | bool | `false` | Enable ingress | +| ingress.className | string | `""` | Ingress class name | +| ingress.annotations | object | `{}` | Ingress annotations | +| ingress.hosts | list | `[]` | Ingress hosts | +| ingress.tls | list | `[]` | Ingress tls | +| resources.limits | string | `nil` | Container resource limits | +| resources.requests | string | `nil` | Container resource requests | +| autoscaling.enabled | bool | `false` | Enable autoscaling | +| autoscaling.minReplicas | int | `1` | Min number of replicas | +| autoscaling.maxReplicas | int | `100` | Max number of replicas | +| autoscaling.targetCPUUtilizationPercentage | int | `80` | Target CPU utilisation | +| autoscaling.targetMemoryUtilizationPercentage | string | `nil` | Target Memory utilisation | +| nodeSelector | object | `{}` | Node selector | +| tolerations | list | `[]` | Tolerations | +| affinity | object | `{}` | Affinity | +| config.gin.mode | string | `"release"` | Gin mode (`release` or `debug`) | +| config.gin.cors | bool | `false` | Gin cors middleware | +| config.gin.logger | bool | `false` | Gin logger middleware | +| config.gin.maxBodySize | int | `2097152` | Gin max body size | +| config.server.host | string | `"0.0.0.0"` | Server host | +| config.server.port | int | `8080` | Server port | +| config.cluster | string | `nil` | | + +## Source Code + +* + +## Requirements + +Kubernetes: `>=1.16.0-0` + +## Maintainers + +| Name | Email | Url | +| ---- | ------ | --- | +| Nirmata | | | + +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0) diff --git a/charts/kyverno-json/README.md.gotmpl b/charts/kyverno-json/README.md.gotmpl new file mode 100644 index 00000000..0a18b311 --- /dev/null +++ b/charts/kyverno-json/README.md.gotmpl @@ -0,0 +1,37 @@ +{{ template "chart.header" . }} +{{ template "chart.deprecationWarning" . }} +{{ template "chart.description" . }} + +{{ template "chart.badgesSection" . }} + +## About + +TODO + +## Features + +TODO + +## Installing the Chart + +Add `kyverno-json` Helm repository: + +```shell +helm repo add kyverno-json https://kyverno.github.io/kyverno-json/ +``` + +Install `kyverno-json` Helm chart: + +```shell +helm install kyverno-json --namespace kyverno --create-namespace kyverno-json/kyverno-json +``` + +{{ template "chart.valuesSection" . }} + +{{ template "chart.sourcesSection" . }} + +{{ template "chart.requirementsSection" . }} + +{{ template "chart.maintainersSection" . }} + +{{ template "helm-docs.versionFooter" . }} diff --git a/charts/kyverno-json/templates/NOTES.txt b/charts/kyverno-json/templates/NOTES.txt new file mode 100644 index 00000000..011efde4 --- /dev/null +++ b/charts/kyverno-json/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "kyverno-json.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "kyverno-json.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "kyverno-json.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "kyverno-json.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/kyverno-json/templates/_helpers.tpl b/charts/kyverno-json/templates/_helpers.tpl new file mode 100644 index 00000000..c833e612 --- /dev/null +++ b/charts/kyverno-json/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "kyverno-json.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 "kyverno-json.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 "kyverno-json.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "kyverno-json.labels" -}} +helm.sh/chart: {{ include "kyverno-json.chart" . }} +{{ include "kyverno-json.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "kyverno-json.selectorLabels" -}} +app.kubernetes.io/name: {{ include "kyverno-json.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "kyverno-json.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "kyverno-json.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/kyverno-json/templates/clusterroles.yaml b/charts/kyverno-json/templates/clusterroles.yaml new file mode 100644 index 00000000..8a4d8632 --- /dev/null +++ b/charts/kyverno-json/templates/clusterroles.yaml @@ -0,0 +1,30 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: +metadata: + name: {{ include "kyverno-json.fullname" . }} + labels: + {{- include "kyverno-json.labels" . | nindent 4 }} +rules: + - apiGroups: + - json.kyverno.io + resources: + - validationpolicies + verbs: + - get + - list +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ include "kyverno-json.fullname" . }} + labels: + {{- include "kyverno-json.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ include "kyverno-json.fullname" . }} +subjects: + - kind: ServiceAccount + name: {{ include "kyverno-json.serviceAccountName" $ }} + namespace: {{ $.Release.Namespace }} diff --git a/charts/kyverno-json/templates/crds.yaml b/charts/kyverno-json/templates/crds.yaml new file mode 100644 index 00000000..dab12bf2 --- /dev/null +++ b/charts/kyverno-json/templates/crds.yaml @@ -0,0 +1,163 @@ +{{- if .Values.crds.install }} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + labels: + {{- include "kyverno-json.labels" . | nindent 4 }} + {{- with .Values.crds.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + annotations: + {{- with .Values.crds.annotations }} + {{- toYaml . | nindent 4 }} + {{- end }} + controller-gen.kubebuilder.io/version: v0.12.0 + name: validationpolicies.json.kyverno.io +spec: + group: json.kyverno.io + names: + kind: ValidationPolicy + listKind: ValidationPolicyList + plural: validationpolicies + singular: validationpolicy + scope: Cluster + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: ValidationPolicy is the resource that contains the policy definition. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: Policy spec. + properties: + rules: + description: Rules is a list of Rule instances. A Policy contains + multiple rules and each rule can validate, mutate, or generate resources. + items: + properties: + assert: + description: Assert is used to validate matching resources. + properties: + all: + description: All allows specifying resources which will + be ANDed. + items: + properties: + check: + description: Check is the assertion check definition. + type: object + x-kubernetes-preserve-unknown-fields: true + message: + description: Message is the variable associated message. + type: string + required: + - check + type: object + type: array + any: + description: Any allows specifying resources which will + be ORed. + items: + properties: + check: + description: Check is the assertion check definition. + type: object + x-kubernetes-preserve-unknown-fields: true + message: + description: Message is the variable associated message. + type: string + required: + - check + type: object + type: array + type: object + context: + description: Context defines variables and data sources that + can be used during rule execution. + items: + description: ContextEntry adds variables and data sources + to a rule Context. + properties: + name: + description: Name is the variable name. + type: string + variable: + description: Variable defines an arbitrary JMESPath context + variable that can be defined inline. + x-kubernetes-preserve-unknown-fields: true + required: + - name + type: object + type: array + exclude: + description: Exclude defines when this policy rule should not + be applied. The exclude criteria can include resource information + (e.g. kind, name, namespace, labels) and admission review + request information like the name or role. + properties: + all: + description: All allows specifying resources which will + be ANDed. + items: + type: object + x-kubernetes-preserve-unknown-fields: true + type: array + any: + description: Any allows specifying resources which will + be ORed. + items: + type: object + x-kubernetes-preserve-unknown-fields: true + type: array + type: object + match: + description: Match defines when this policy rule should be applied. + The match criteria can include resource information (e.g. + kind, name, namespace, labels) and admission review request + information like the user name or role. At least one kind + is required. + properties: + all: + description: All allows specifying resources which will + be ANDed. + items: + type: object + x-kubernetes-preserve-unknown-fields: true + type: array + any: + description: Any allows specifying resources which will + be ORed. + items: + type: object + x-kubernetes-preserve-unknown-fields: true + type: array + type: object + name: + description: Name is a label to identify the rule, It must be + unique within the policy. + maxLength: 63 + type: string + required: + - name + type: object + type: array + type: object + required: + - spec + type: object + served: true + storage: true +{{- end }} diff --git a/charts/kyverno-json/templates/deployment.yaml b/charts/kyverno-json/templates/deployment.yaml new file mode 100644 index 00000000..8f823de1 --- /dev/null +++ b/charts/kyverno-json/templates/deployment.yaml @@ -0,0 +1,72 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "kyverno-json.fullname" . }} + labels: + {{- include "kyverno-json.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "kyverno-json.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "kyverno-json.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.priorityClassName }} + priorityClassName: {{ . }} + {{- end }} + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "kyverno-json.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + args: + - serve + - --gin-mode={{ .Values.config.gin.mode }} + - --gin-cors={{ .Values.config.gin.cors }} + - --gin-log={{ .Values.config.gin.logger }} + - --gin-max-body-size={{ int .Values.config.gin.maxBodySize }} + - --server-host={{ .Values.config.server.host }} + - --server-port={{ int .Values.config.server.port }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + {{- with .Values.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/kyverno-json/templates/hpa.yaml b/charts/kyverno-json/templates/hpa.yaml new file mode 100644 index 00000000..95c1940a --- /dev/null +++ b/charts/kyverno-json/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "kyverno-json.fullname" . }} + labels: + {{- include "kyverno-json.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "kyverno-json.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/kyverno-json/templates/ingress.yaml b/charts/kyverno-json/templates/ingress.yaml new file mode 100644 index 00000000..11818804 --- /dev/null +++ b/charts/kyverno-json/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "kyverno-json.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "kyverno-json.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/kyverno-json/templates/service.yaml b/charts/kyverno-json/templates/service.yaml new file mode 100644 index 00000000..db3b2740 --- /dev/null +++ b/charts/kyverno-json/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "kyverno-json.fullname" . }} + labels: + {{- include "kyverno-json.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "kyverno-json.selectorLabels" . | nindent 4 }} diff --git a/charts/kyverno-json/templates/serviceaccount.yaml b/charts/kyverno-json/templates/serviceaccount.yaml new file mode 100644 index 00000000..4b67c919 --- /dev/null +++ b/charts/kyverno-json/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "kyverno-json.serviceAccountName" . }} + labels: + {{- include "kyverno-json.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/kyverno-json/values.yaml b/charts/kyverno-json/values.yaml new file mode 100644 index 00000000..e326f7b9 --- /dev/null +++ b/charts/kyverno-json/values.yaml @@ -0,0 +1,162 @@ +# -- Name override +nameOverride: "" + +# -- Full name override +fullnameOverride: "" + +crds: + # -- Whether to have Helm install the CRDs, if the CRDs are not installed by Helm, they must be added before policies can be created + install: true + # -- Additional CRDs annotations + annotations: {} + # argocd.argoproj.io/sync-options: Replace=true + # strategy.spinnaker.io/replace: 'true' + # -- Additional CRDs labels + labels: {} + +# -- Number of pod replicas +replicaCount: 1 + +image: + # -- Image registry + registry: ghcr.io + # -- Image repository + repository: kyverno/kyverno-json + # -- Image pull policy + pullPolicy: IfNotPresent + # -- Image tag (will default to app version if not set) + tag: ~ + +# -- Image pull secrets +imagePullSecrets: [] + +# -- Priority class name +priorityClassName: "" + +serviceAccount: + # -- Create service account + create: true + + # -- Service account annotations + annotations: {} + + # -- Service account name (required if `serviceAccount.create` is `false`) + name: "" + +# -- Pod annotations +podAnnotations: {} + +# -- Pod security context +podSecurityContext: + fsGroup: 2000 + +# -- Container security context +# @default -- See [values.yaml](values.yaml) +securityContext: + capabilities: + drop: + - ALL + readOnlyRootFilesystem: true + runAsNonRoot: true + runAsUser: 1000 + privileged: false + allowPrivilegeEscalation: false + seccompProfile: + type: RuntimeDefault + +service: + # -- Service type + type: ClusterIP + + # -- Service port + port: 8080 + +# # -- Liveness probe +# livenessProbe: +# httpGet: +# path: / +# port: http + +# # -- Readiness probe +# readinessProbe: +# httpGet: +# path: / +# port: http + +ingress: + # -- Enable ingress + enabled: false + + # -- Ingress class name + className: "" + + # -- Ingress annotations + annotations: {} + + # -- Ingress hosts + hosts: [] + # - host: chart-example.local + # paths: + # - path: / + # pathType: ImplementationSpecific + + # -- Ingress tls + tls: [] + +# We usually recommend not to specify default resources and to leave this as a conscious +# choice for the user. This also increases chances charts run on environments with little +# resources, such as Minikube. If you do want to specify resources, uncomment the following +# lines, adjust them as necessary, and remove the curly braces after 'resources:'. +resources: + # -- Container resource limits + limits: + # cpu: 100m + # memory: 128Mi + + # -- Container resource requests + requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + # -- Enable autoscaling + enabled: false + + # -- Min number of replicas + minReplicas: 1 + + # -- Max number of replicas + maxReplicas: 100 + + # -- Target CPU utilisation + targetCPUUtilizationPercentage: 80 + + # -- Target Memory utilisation + targetMemoryUtilizationPercentage: ~ + +# -- Node selector +nodeSelector: {} + +# -- Tolerations +tolerations: [] + +# -- Affinity +affinity: {} + +config: + gin: + # -- Gin mode (`release` or `debug`) + mode: release + # -- Gin cors middleware + cors: false + # -- Gin logger middleware + logger: false + # -- Gin max body size + maxBodySize: 2097152 + server: + # -- Server host + host: '0.0.0.0' + # -- Server port + port: 8080 + cluster: + # TODO: kube config flags diff --git a/test/api/README.md b/test/api/README.md index 1bd8ef9d..6d657300 100644 --- a/test/api/README.md +++ b/test/api/README.md @@ -3,7 +3,7 @@ ## Create a cluster ```bash -make kind-cluster +make kind-create ``` ## Install CRDs