From d0f3c3143e3c7fff598f04701a4d2be34c3b8047 Mon Sep 17 00:00:00 2001 From: Marcin Ciszak Date: Tue, 21 Jun 2022 18:15:00 +0100 Subject: [PATCH] Adds helm chart (#245) * Adds helm chart * Update README * Adds workflow to publish helm chart * Add workflow to lint helm chart on PRs --- .github/workflows/helm.yaml | 29 ++++ .github/workflows/lint.yaml | 29 ++++ README.md | 130 ++++++++------- charts/krane/.helmignore | 23 +++ charts/krane/Chart.yaml | 15 ++ charts/krane/templates/NOTES.txt | 22 +++ charts/krane/templates/_helpers.tpl | 75 +++++++++ charts/krane/templates/deployment.yaml | 152 ++++++++++++++++++ charts/krane/templates/ingress.yaml | 61 +++++++ charts/krane/templates/networkpolicy.yaml | 27 ++++ charts/krane/templates/rbac.yaml | 26 +++ charts/krane/templates/service.yaml | 48 ++++++ charts/krane/templates/serviceaccount.yaml | 12 ++ .../templates/tests/test-connection.yaml | 15 ++ charts/krane/values.yaml | 84 ++++++++++ 15 files changed, 693 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/helm.yaml create mode 100644 .github/workflows/lint.yaml create mode 100644 charts/krane/.helmignore create mode 100644 charts/krane/Chart.yaml create mode 100644 charts/krane/templates/NOTES.txt create mode 100644 charts/krane/templates/_helpers.tpl create mode 100644 charts/krane/templates/deployment.yaml create mode 100644 charts/krane/templates/ingress.yaml create mode 100644 charts/krane/templates/networkpolicy.yaml create mode 100644 charts/krane/templates/rbac.yaml create mode 100644 charts/krane/templates/service.yaml create mode 100644 charts/krane/templates/serviceaccount.yaml create mode 100644 charts/krane/templates/tests/test-connection.yaml create mode 100644 charts/krane/values.yaml diff --git a/.github/workflows/helm.yaml b/.github/workflows/helm.yaml new file mode 100644 index 0000000..4b8bdb5 --- /dev/null +++ b/.github/workflows/helm.yaml @@ -0,0 +1,29 @@ +--- +name: Publish Chart + +on: + push: + branches: + - master + +jobs: + release-helm-chart: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + - name: Install Helm + uses: azure/setup-helm@v1 + with: + version: v3.8.1 + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.4.0 + env: + CR_SKIP_EXISTING: true + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..4b8bdb8 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,29 @@ +--- +name: Lint + +on: + pull_request: + types: [opened, reopened, synchronize] + +permissions: + contents: read + +jobs: + helm: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Helm + uses: azure/setup-helm@v1 + with: + version: v3.8.1 + - uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.2.1 + - name: Run chart-testing (lint) + run: ct lint diff --git a/README.md b/README.md index 403e1b9..7f17e2d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ![Stability:Beta](https://img.shields.io/badge/stability-beta-orange) ![CircleCI](https://img.shields.io/circleci/build/github/appvia/krane/master) [![GitHub tag (latest SemVer)](https://img.shields.io/github/v/release/appvia/krane)](https://github.com/appvia/krane/releases/latest) -![License: Apache-2.0](https://img.shields.io/github/license/appvia/kore) +![License: Apache-2.0](https://img.shields.io/github/license/appvia/krane) ![Docker Repository on Quay.io](https://img.shields.io/badge/container-ready-brightgreen) _Krane_ is a simple Kubernetes RBAC static analysis tool. It identifies potential security risks in K8s RBAC design and makes suggestions on how to mitigate them. _Krane_ dashboard presents current RBAC security posture and lets you navigate through its definition. @@ -55,14 +55,14 @@ _Krane_ docker image will be pre-built automatically if not already present on l Note that when running `docker-compose` locally, _Krane_ won't start RBAC _report_ and _dashboard_ automatically. Instead, the container will sleep for 24h by default - this value can be adjusted in `docker-compose.override.yml`. Exec into a running _Krane_ container to run commands. Local `docker-compose` will also mount kube config (`~/.kube/config`) inside the container enabling you to run reports against any Kubernetes clusters to which you already have access to. +Exec into a running Krane container. ```sh -# Exec into a running Krane container - docker-compose exec krane bash +``` -# Once in the container you can start using `krane` commands. Try `krane -help`. - -$ krane -h +Once in the container you can start using `krane` commands. Try `krane -help`. +```sh +krane -h ``` To inspect what services are running and the associated ports: @@ -136,6 +136,13 @@ NOTE: _Krane_ expects the following files (in either YAML or JSON format) to be - rolebindings - clusterrolebindings +If Pod Security Policies are not in use you may bypass the expectation above by creating a `psp` file manually with the following content: +```json +{ + "items": [] +} +``` + #### Inside a Kubernetes cluster To run a report from a container running in Kubernetes cluster @@ -417,9 +424,50 @@ You may control certain aspects of in-cluster execution with the following envir ### Local or Remote K8s Cluster -If your K8s cluster comes with built-in [Compose-on-Kubernetes](https://github.com/docker/compose-on-kubernetes) controller support (`docker-desktop` supports it by default), then you can deploy _Krane_ and its dependencies with a single [docker stack](https://docs.docker.com/engine/reference/commandline/stack_deploy/) command: +#### Helm Chart + +Before we begin, you'll need the following tools: +* [Helm CLI](https://helm.sh/docs/intro/install/) + +Install helm chart: +```sh +$ helm repo add appvia https://appvia.github.io/krane +$ helm repo update +$ helm install krane appvia/krane --namespace krane --create-namespace --set image.tag=latest +``` + +See [values.yaml](helm/krane/values.yaml) file for details of other settable options and parameters. + +#### K8s manifests + +```sh +kubectl create \ + --context \ + --namespace krane \ + -f k8s/redisgraph-service.yaml \ + -f k8s/redisgraph-deployment.yaml \ + -f k8s/krane-service.yaml \ + -f k8s/krane-deployment.yaml +``` + +Note that _Krane_ dashboard service is not exposed by default! +```sh +kubectl port-forward svc/krane 8000 \ + --context= \ + --namespace=krane +# Open Krane dashboard at http://localhost:8000 ``` + +You can find the example deployment manifests in [k8s](k8s/) directory. + +Modify manifests as required for your deployments making sure you reference the correct version of _Krane_ docker image in its [deployment file](k8s/krane-deployment.yml). See [Krane Docker Registry](https://quay.io/repository/appvia/krane?tab=tags) for available tags, or just use `latest`. + +#### Compose-on-Kubernetes + +If your K8s cluster comes with built-in [Compose-on-Kubernetes](https://github.com/docker/compose-on-kubernetes) controller support (`docker-desktop` supports it by default), then you can deploy _Krane_ and its dependencies with a single [docker stack](https://docs.docker.com/engine/reference/commandline/stack_deploy/) command: + +```sh docker stack deploy \ --orchestrator kubernetes \ --namespace krane \ @@ -431,58 +479,30 @@ Note: Make sure your current kube context is set correctly prior to running the The application Stack should be now deployed to a Kubernetes cluster and all services ready and exposed. Note that _Krane_ will automatically start its report loop and dashboard server. +```sh +docker stack services --orchestrator kubernetes --namespace krane krane ``` -$ docker stack services --orchestrator kubernetes --namespace krane krane +Command above will produce the following output: +``` ID NAME MODE REPLICAS IMAGE PORTS 0de30651-dd5 krane_redisgraph replicated 1/1 redislabs/redisgraph:1.99.7 *:6379->6379/tcp aa377a5f-62b krane_krane replicated 1/1 quay.io/appvia/krane:latest *:8000->8000/tcp ``` -Check your Kubernetes cluster RBAC security posture by visiting -``` -http://localhost:8000 -``` +Check your Kubernetes cluster RBAC security posture by visiting http://localhost:8000. Note that for remote cluster deployments you'll likely need to port-forward _Krane_ service first -``` +```sh kubectl --context=my-remote-cluster --namespace=krane port-forward svc/krane 8000 ``` To delete the Stack -``` +```sh docker stack rm krane \ --orchestrator kubernetes \ --namespace krane ``` - -Alternatively, deploy with [kubectl](https://kubectl.docs.kubernetes.io/): - -``` -kubectl create \ - --context docker-desktop \ - --namespace krane \ - -f k8s/redisgraph-service.yaml \ - -f k8s/redisgraph-deployment.yaml \ - -f k8s/krane-service.yaml \ - -f k8s/krane-deployment.yaml -``` - -Note that _Krane_ dashboard services are not exposed by default! -```sh -kubectl port-forward svc/krane 8000 \ - --context=docker-desktop \ - --namespace=krane - -# Open Krane dashboard - -http://localhost:8000 -``` - -You can find the example deployment manifests in [k8s](k8s/) directory. - -Modify manifests as required for your deployments making sure you reference the correct version of _Krane_ docker image in its [deployment file](k8s/krane-deployment.yml). See [Krane Docker Registry](https://quay.io/repository/appvia/krane?tab=tags) for available tags, or just use `latest`. - ## Notifications Krane will notify you about detected anomalies of medium and high severity via its Slack integration. @@ -496,7 +516,7 @@ This section describes steps to enable local development. ### Setup Install _Krane_ code dependencies with -``` +```sh ./bin/setup ``` @@ -504,17 +524,17 @@ Install _Krane_ code dependencies with _Krane_ depends on [RedisGraph](https://oss.redislabs.com/redisgraph/). `docker-compose` is the quickest way to get _Krane_'s dependencies running locally. -``` +```sh docker-compose up -d redisgraph ``` To inspect RedisGraph service is up: -``` +```sh docker-compose ps ``` To stop services: -``` +```sh docker-compose down ``` @@ -523,17 +543,17 @@ docker-compose down At this point you should be able to modify _Krane_ codebase and test results by invoking commands in local shell. ```sh -./bin/krane --help # to get help -./bin/krane report -k docker-desktop # to generate your first report for - # local docker-desktop k8s cluster +$ ./bin/krane --help # to get help +$ ./bin/krane report -k docker-desktop # to generate your first report for + # local docker-desktop k8s cluster ... ``` To enable Dashboard UI local development mode -``` -cd dashboard -npm install -npm start +```sh +$ cd dashboard +$ npm install +$ npm start ``` This will automatically start the Dashboard server, open default browser and watch for source files changes. @@ -541,14 +561,14 @@ This will automatically start the Dashboard server, open default browser and wat _Krane_ comes preconfigured for improved developer experience with [Skaffold](https://skaffold.dev/). Iterating on the project and validating the application by running the entire stack in local or remote Kubernetes cluster just got easier. Code hot-reload enables local changes to be automatically propagated to the running container for faster development lifecycle. -``` +```sh skaffold dev --kube-context docker-desktop --namespace krane --port-forward ``` ### Tests Run tests locally with -``` +```sh bundle exec rspec ``` diff --git a/charts/krane/.helmignore b/charts/krane/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/krane/.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/krane/Chart.yaml b/charts/krane/Chart.yaml new file mode 100644 index 0000000..d2635ee --- /dev/null +++ b/charts/krane/Chart.yaml @@ -0,0 +1,15 @@ +apiVersion: v2 +name: krane +description: A Helm chart for Krane +type: application +version: 0.1.1 +appVersion: "v0.1.1" +sources: + - https://github.com/appvia/krane +maintainers: + - name: Appvia + email: info@appvia.io + url: https://appvia.io + - name: Marcin + email: marcin.ciszak@appvia.io + url: https://github.com/marcinc diff --git a/charts/krane/templates/NOTES.txt b/charts/krane/templates/NOTES.txt new file mode 100644 index 0000000..1179a72 --- /dev/null +++ b/charts/krane/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 "krane.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 "krane.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "krane.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 "krane.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/krane/templates/_helpers.tpl b/charts/krane/templates/_helpers.tpl new file mode 100644 index 0000000..c1a1e86 --- /dev/null +++ b/charts/krane/templates/_helpers.tpl @@ -0,0 +1,75 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "krane.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 "krane.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 "krane.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "krane.labels" -}} +helm.sh/chart: {{ include "krane.chart" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "krane.selectorLabels" -}} +app.kubernetes.io/name: {{ include "krane.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/component: {{ include "krane.name" . }} +app.kubernetes.io/part-of: {{ include "krane.name" . }} +network/krane: "true" +{{- end }} + +{{/* +RedisGraph Selector labels +*/}} +{{- define "krane.redisgraphSelectorLabels" -}} +app.kubernetes.io/name: redisgraph +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/component: redisgraph +app.kubernetes.io/part-of: {{ include "krane.name" . }} +network/krane: "true" +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "krane.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "krane.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/krane/templates/deployment.yaml b/charts/krane/templates/deployment.yaml new file mode 100644 index 0000000..fb21050 --- /dev/null +++ b/charts/krane/templates/deployment.yaml @@ -0,0 +1,152 @@ +# Copyright 2020 Appvia Ltd + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# RedisGraph +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redisgraph + labels: + {{- include "krane.labels" . | nindent 4 }} + {{- include "krane.redisgraphSelectorLabels" . | nindent 4 }} +spec: + replicas: 1 + selector: + matchLabels: + {{- include "krane.redisgraphSelectorLabels" . | nindent 6 }} + strategy: {} + template: + metadata: + labels: + {{- include "krane.redisgraphSelectorLabels" . | nindent 8 }} + spec: + containers: + - image: "{{ .Values.redisgraph.image }}:{{ .Values.redisgraph.tag }}" + imagePullPolicy: "IfNotPresent" + name: redisgraph + ports: + - containerPort: 6379 + resources: + limits: + cpu: 1 + memory: 200Mi + requests: + cpu: 200m + memory: 20Mi + restartPolicy: Always + serviceAccountName: "" + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + restartPolicy: Always + +# Krane +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "krane.fullname" . }} + labels: + {{- include "krane.labels" . | nindent 4 }} + {{- include "krane.selectorLabels" . | nindent 4 }} + network/krane: "true" +spec: + replicas: 1 + selector: + matchLabels: + {{- include "krane.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "krane.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "krane.serviceAccountName" . }} + automountServiceAccountToken: true + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + command: + - /bin/bash + - -c + - bin/in-cluster-run + env: + - name: KRANE_REPORT_INTERVAL + value: "{{ .Values.params.reportInterval }}" + - name: KRANE_REPORT_OUTPUT + value: "{{ .Values.params.reportOutput }}" + - name: REDIS_GRAPH_HOST + value: "{{ .Values.params.redisGraphHost }}" + - name: SLACK_WEBHOOK_URL + value: "{{ .Values.params.slackWebhookURL }}" + - name: SLACK_CHANNEL + value: "{{ .Values.params.slackChannel }}" + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 8000 + protocol: TCP + livenessProbe: + exec: + command: + - /bin/bash + - -c + - bin/krane --version + failureThreshold: 3 + initialDelaySeconds: 20 + periodSeconds: 60 + timeoutSeconds: 5 + readinessProbe: + exec: + command: + - /bin/bash + - -c + - bin/krane --version + failureThreshold: 3 + successThreshold: 1 + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 5 + 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 }} + restartPolicy: Always diff --git a/charts/krane/templates/ingress.yaml b/charts/krane/templates/ingress.yaml new file mode 100644 index 0000000..a982631 --- /dev/null +++ b/charts/krane/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "krane.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 "krane.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/krane/templates/networkpolicy.yaml b/charts/krane/templates/networkpolicy.yaml new file mode 100644 index 0000000..3f14041 --- /dev/null +++ b/charts/krane/templates/networkpolicy.yaml @@ -0,0 +1,27 @@ +# Copyright 2020 Appvia Ltd + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: krane-default +spec: + ingress: + - from: + - podSelector: + matchLabels: + network/krane: "true" + podSelector: + matchLabels: + network/krane: "true" diff --git a/charts/krane/templates/rbac.yaml b/charts/krane/templates/rbac.yaml new file mode 100644 index 0000000..35203f9 --- /dev/null +++ b/charts/krane/templates/rbac.yaml @@ -0,0 +1,26 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: rbac-reader +rules: +- apiGroups: ["policy"] + resources: ["podsecuritypolicies"] + verbs: ["get", "list"] +- apiGroups: ["rbac.authorization.k8s.io"] + resources: ["roles", "clusterroles", "rolebindings", "clusterrolebindings"] + verbs: ["get", "list"] + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: rbac-reader +subjects: +- kind: ServiceAccount + name: {{ .Values.serviceAccount.name }} + namespace: {{ .Release.Namespace }} +roleRef: + kind: ClusterRole + name: rbac-reader + apiGroup: rbac.authorization.k8s.io diff --git a/charts/krane/templates/service.yaml b/charts/krane/templates/service.yaml new file mode 100644 index 0000000..9ea2193 --- /dev/null +++ b/charts/krane/templates/service.yaml @@ -0,0 +1,48 @@ +# Copyright 2020 Appvia Ltd + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# RedisGraph +--- +apiVersion: v1 +kind: Service +metadata: + name: redisgraph + labels: + {{- include "krane.labels" . | nindent 4 }} +spec: + ports: + - name: redis + port: 6379 + targetPort: 6379 + protocol: TCP + selector: + {{- include "krane.redisgraphSelectorLabels" . | nindent 4 }} + +# Krane +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ include "krane.fullname" . }} + labels: + {{- include "krane.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: 8000 + protocol: TCP + name: http + selector: + {{- include "krane.selectorLabels" . | nindent 4 }} diff --git a/charts/krane/templates/serviceaccount.yaml b/charts/krane/templates/serviceaccount.yaml new file mode 100644 index 0000000..67f6fe5 --- /dev/null +++ b/charts/krane/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "krane.serviceAccountName" . }} + labels: + {{- include "krane.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/krane/templates/tests/test-connection.yaml b/charts/krane/templates/tests/test-connection.yaml new file mode 100644 index 0000000..4116d75 --- /dev/null +++ b/charts/krane/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "krane.fullname" . }}-test-connection" + labels: + {{- include "krane.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "krane.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/krane/values.yaml b/charts/krane/values.yaml new file mode 100644 index 0000000..04b70de --- /dev/null +++ b/charts/krane/values.yaml @@ -0,0 +1,84 @@ +# Default values for krane. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +image: + repository: quay.io/appvia/krane + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +params: + reportInterval: 30 + reportOutput: none + redisGraphHost: redisgraph + slackWebhookURL: "" + slackChannel: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "krane-sa" + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: + # 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:'. + limits: + cpu: 1 + memory: 512Mi + requests: + cpu: 200m + memory: 20Mi + + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +# Dependencies +redisgraph: + image: redislabs/redisgraph + tag: 2.6.1