Skip to content

Commit

Permalink
PoC: add helm chart to install kiali-operator (#93)
Browse files Browse the repository at this point in the history
* Add helm chart

Signed-off-by: Jake Hill <[email protected]>

* complete the helm chart work

* Do not install istio-specific resources. There are too many ways users may want to customize the Gateway/VirtualService/DestinationRule.
And since those configs involves Kiali Server config, not Operator, we do not want to create a bunch of customized values for this stuff.
This helm chart should concentrate on installing only the Operator (with at most being able to install a Kiali CR but allowing the user to provide their own cr.spec since Kiali Server itself can be highly customizable).

Co-authored-by: Jake Hill <[email protected]>
  • Loading branch information
jmazzitelli and naphta authored Jul 30, 2020
1 parent 95e717f commit f0da889
Show file tree
Hide file tree
Showing 36 changed files with 847 additions and 988 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ script:
# This also downloads operator-sdk which we will use below to validate the metadata.
- make build

# ensures the helm chart is still valid
- make build-helm-chart

# test the validity of the ossm metadata
- _output/operator-sdk-install/operator-sdk version
- cat manifests/kiali-ossm/manifests/kiali.clusterserviceversion.yaml | KIALI_OPERATOR_VERSION="2.0.0" KIALI_OLD_OPERATOR_VERSION="1.0.0" KIALI_OPERATOR_TAG=":2.0.0" KIALI_1_12_TAG=":1.12.0" KIALI_1_0_TAG=":1.0.0" CREATED_AT="2020-01-01T00:00:00Z" envsubst > manifests/kiali-ossm/manifests/csv.yaml ; mv manifests/kiali-ossm/manifests/csv.yaml manifests/kiali-ossm/manifests/kiali.clusterserviceversion.yaml
Expand Down
46 changes: 45 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ OPERATOR_QUAY_TAG = ${OPERATOR_QUAY_NAME}:${OPERATOR_CONTAINER_VERSION}
# Determine if we should use Docker OR Podman - value must be one of "docker" or "podman"
DORP ?= docker

# When building the helm chart, this is the helm version to use
HELM_VERSION ?= v3.2.4

.PHONY: help
help: Makefile
@echo
Expand All @@ -30,6 +33,32 @@ help: Makefile
clean:
@rm -rf ${OUTDIR}

.download-helm-if-needed:
@$(eval HELM ?= $(shell if (which helm 2>/dev/null 1>&2 && helm version --short 2>/dev/null | grep -q "v3"); then echo "helm"; else echo "${OUTDIR}/helm-install/helm"; fi))
@if ! which ${HELM} 2>/dev/null 1>&2; then \
mkdir -p "${OUTDIR}/helm-install" ;\
if [ -x "${OUTDIR}/helm-install/helm" ]; then \
echo "You do not have helm installed in your PATH. Will use the one found here: ${OUTDIR}/helm-install/helm" ;\
else \
echo "You do not have helm installed in your PATH. The binary will be downloaded to ${OUTDIR}/helm-install/helm" ;\
os=$$(uname -s | tr '[:upper:]' '[:lower:]') ;\
arch="" ;\
case $$(uname -m) in \
i386) arch="386" ;; \
i686) arch="386" ;; \
x86_64) arch="amd64" ;; \
arm) dpkg --print-architecture | grep -q "arm64" && arch="arm64" || arch="arm" ;; \
esac ;\
cd "${OUTDIR}/helm-install" ;\
curl -L "https://get.helm.sh/helm-${HELM_VERSION}-$${os}-$${arch}.tar.gz" > "${OUTDIR}/helm-install/helm.tar.gz" ;\
tar xzf "${OUTDIR}/helm-install/helm.tar.gz" ;\
mv "${OUTDIR}/helm-install/$${os}-$${arch}/helm" "${OUTDIR}/helm-install/helm" ;\
chmod +x "${OUTDIR}/helm-install/helm" ;\
rm -rf "${OUTDIR}/helm-install/$${os}-$${arch}" "${OUTDIR}/helm-install/helm.tar.gz" ;\
fi ;\
fi
@echo Will use this helm executable: ${HELM}

.download-operator-sdk-if-needed:
@if [ "$(shell which operator-sdk 2>/dev/null || echo -n "")" == "" ]; then \
mkdir -p "${OUTDIR}/operator-sdk-install" ;\
Expand All @@ -51,6 +80,21 @@ build: .ensure-operator-sdk-exists
@echo Building container image for Kiali operator using operator-sdk
cd "${ROOTDIR}" && "${OP_SDK}" build --image-builder ${DORP} --image-build-args "--pull" "${OPERATOR_QUAY_TAG}"

## build-helm-chart: Build Kiali operator Helm Chart
build-helm-chart: .download-helm-if-needed
@echo Building Helm Chart for Kiali operator
@rm -rf "${OUTDIR}/charts"
@mkdir -p "${OUTDIR}/charts"
@cp -R "${ROOTDIR}/deploy/charts/kiali-operator" "${OUTDIR}/charts/"
@HELM_IMAGE_REPO="${OPERATOR_QUAY_NAME}" HELM_IMAGE_TAG="${OPERATOR_CONTAINER_VERSION}" envsubst < "${ROOTDIR}/deploy/charts/kiali-operator/values.yaml" > "${OUTDIR}/charts/kiali-operator/values.yaml"
@"${HELM}" lint "${OUTDIR}/charts/kiali-operator"
@"${HELM}" package "${OUTDIR}/charts/kiali-operator" -d "${OUTDIR}/charts" --version ${OPERATOR_CONTAINER_VERSION} --app-version ${OPERATOR_CONTAINER_VERSION}

## update-helm-repo: Build the latest Kiali operator Helm Chart and adds it to the local Helm repo directory.
update-helm-repo: build-helm-chart
cp "${OUTDIR}/charts/kiali-operator-${OPERATOR_CONTAINER_VERSION}.tgz" "${ROOTDIR}/docs/charts"
"${HELM}" repo index "${ROOTDIR}/docs/charts" --url https://kiali.org/kiali-operator/charts

## push: Pushes the operator image to quay.
push:
ifeq ($(DORP),docker)
Expand All @@ -62,7 +106,7 @@ else
endif

## generate-all-in-one: Creates the all-in-one yaml file that can be used to deploy the operator via kubectl apply.
generate-all-in-one:
generate-all-in-one: build-helm-chart
@mkdir -p ${OUTDIR}
@OPERATOR_IMAGE_VERSION=$${OPERATOR_IMAGE_VERSION:-${VERSION}} \
${ROOTDIR}/deploy/merge-operator-yaml.sh --file ${OUTDIR}/kiali-operator-all-in-one.yaml
17 changes: 17 additions & 0 deletions deploy/charts/kiali-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v2
name: kiali-operator
description: Kiali is an open source project for service mesh observability, refer to https://www.kiali.io for details.
version: 0.0.0
appVersion: 0.0.0
home: https://github.com/kiali/kiali-operator
maintainers:
- name: Kiali
email: [email protected]
url: https://kiali.io
keywords:
- istio
- operator
- kiali
sources:
- https://github.com/kiali/kiali-operator/tree/master/charts/kiali-operator
icon: https://raw.githubusercontent.com/kiali/kiali.io/master/themes/kiali/static/img/kiali_logo_masthead.png
14 changes: 6 additions & 8 deletions deploy/crd.yaml → deploy/charts/kiali-operator/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: monitoringdashboards.monitoring.kiali.io
labels:
app: kiali
version: ${OPERATOR_VERSION_LABEL}
spec:
group: monitoring.kiali.io
names:
Expand All @@ -14,15 +11,16 @@ spec:
plural: monitoringdashboards
singular: monitoringdashboard
scope: Namespaced
version: v1alpha1
versions:
- name: v1alpha1
served: true
storage: true
...
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: kialis.kiali.io
labels:
app: kiali-operator
version: ${OPERATOR_VERSION_LABEL}
spec:
group: kiali.io
names:
Expand All @@ -33,8 +31,8 @@ spec:
scope: Namespaced
subresources:
status: {}
version: v1alpha1
versions:
- name: v1alpha1
served: true
storage: true
...
30 changes: 30 additions & 0 deletions deploy/charts/kiali-operator/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Welcome to Kiali! For more details on Kiali, see: https://kiali.io

The Kiali Operator [{{ .Chart.AppVersion }}] has been installed in namespace [{{ .Release.Namespace }}]. It will be ready soon.

{{- if .Values.cr.create }}
{{- if or (and (not .Values.watchNamespace) (not .Values.cr.namespace)) (and (.Values.watchNamespace) (eq .Values.watchNamespace .Release.Namespace)) (and (.Values.cr.namespace) (eq .Values.cr.namespace .Release.Namespace)) }}
You have elected to install a Kiali CR in the same namespace as the operator [{{ .Release.Namespace }}]. You should be able to access Kiali soon.

================================
PLEASE READ THIS WARNING NOTICE:
Because the Kiali CR lives in the same namespace as the operator, DO NOT uninstall the operator or delete the operator namespace without first removing the Kiali CR. If you do not follow this advice then the Kiali Operator deletion will hang indefinitely until you remove the finalizer from the Kiali CR, and then you may find your Kubernetes environment still has Kiali Server remnants left behind.
================================
{{- else if .Values.watchNamespace }}
You have elected to install a Kiali CR in the operator watch namespace [{{ .Values.watchNamespace }}]. You should be able to access Kiali soon.
{{- else if .Values.cr.namespace }}
You have elected to install a Kiali CR in the namespace [{{ .Values.cr.namespace }}]. You should be able to access Kiali soon.
{{- else }}
You have elected to install a Kiali CR. You should be able to access Kiali soon.
{{- end }}
{{- else }}
{{- if (not .Values.watchNamespace) }}
You have elected not to install a Kiali CR. You must first install a Kiali CR before you can access Kiali. The operator is watching all namespaces, so you can create the Kiali CR anywhere.
{{- else }}
You have elected not to install a Kiali CR. You must first install a Kiali CR in the operator watch namespace [{{ .Values.watchNamespace }}] before you can access Kiali.
{{- end }}
{{- end }}

If you ever want to uninstall the Kiali Operator, remember to delete the Kiali CR first before uninstalling the operator to give the operator a chance to uninstall and remove all the Kiali Server resources.

(Helm: Chart=[{{ .Chart.Name }}], Release=[{{ .Release.Name }}], Version=[{{ .Chart.Version }}])
55 changes: 55 additions & 0 deletions deploy/charts/kiali-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "kiali-operator.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 "kiali-operator.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 "kiali-operator.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

61 changes: 39 additions & 22 deletions deploy/role.yaml → ...kiali-operator/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
---
# NOTE: Changes to this file must be reflected in the OperatorHub.io CSV file
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kiali-operator
name: {{ include "kiali-operator.fullname" . }}
labels:
app: kiali-operator
version: ${OPERATOR_VERSION_LABEL}
{{- include "kiali-operator.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources:
Expand Down Expand Up @@ -90,8 +88,10 @@ rules:
- watch
- apiGroups: ["rbac.authorization.k8s.io"]
resources:
${OPERATOR_ROLE_CLUSTERROLEBINDINGS}
${OPERATOR_ROLE_CLUSTERROLES}
{{- if or (and (.Values.cr.create) (has "**" .Values.cr.spec.deployment.accessible_namespaces)) (.Values.clusterRoleCreator) }}
- clusterrolebindings
- clusterroles
{{- end }}
- rolebindings
- roles
verbs:
Expand Down Expand Up @@ -191,8 +191,10 @@ rules:
verbs:
- get
- list
${OPERATOR_ROLE_PATCH}
- watch
{{- if eq .Values.onlyViewOnlyMode false }}
- patch
{{- end }}
- apiGroups: ["extensions", "apps"]
resources:
- deployments
Expand All @@ -201,8 +203,10 @@ rules:
verbs:
- get
- list
${OPERATOR_ROLE_PATCH}
- watch
{{- if eq .Values.onlyViewOnlyMode false }}
- patch
{{- end }}
- apiGroups: ["autoscaling"]
resources:
- horizontalpodautoscalers
Expand All @@ -217,8 +221,10 @@ rules:
verbs:
- get
- list
${OPERATOR_ROLE_PATCH}
- watch
{{- if eq .Values.onlyViewOnlyMode false }}
- patch
{{- end }}
- apiGroups:
- config.istio.io
- networking.istio.io
Expand All @@ -227,40 +233,48 @@ rules:
- security.istio.io
resources: ["*"]
verbs:
${OPERATOR_ROLE_CREATE}
${OPERATOR_ROLE_DELETE}
- get
- list
${OPERATOR_ROLE_PATCH}
- watch
{{- if eq .Values.onlyViewOnlyMode false }}
- create
- delete
- patch
{{- end }}
- apiGroups: ["authentication.maistra.io"]
resources:
- servicemeshpolicies
verbs:
${OPERATOR_ROLE_CREATE}
${OPERATOR_ROLE_DELETE}
- get
- list
${OPERATOR_ROLE_PATCH}
- watch
{{- if eq .Values.onlyViewOnlyMode false }}
- create
- delete
- patch
{{- end }}
- apiGroups: ["rbac.maistra.io"]
resources:
- servicemeshrbacconfigs
verbs:
${OPERATOR_ROLE_CREATE}
${OPERATOR_ROLE_DELETE}
- get
- list
${OPERATOR_ROLE_PATCH}
- watch
{{- if eq .Values.onlyViewOnlyMode false }}
- create
- delete
- patch
{{- end }}
- apiGroups: ["apps.openshift.io"]
resources:
- deploymentconfigs
verbs:
- get
- list
${OPERATOR_ROLE_PATCH}
- watch
{{- if eq .Values.onlyViewOnlyMode false }}
- patch
{{- end }}
- apiGroups: ["project.openshift.io"]
resources:
- projects
Expand All @@ -281,9 +295,12 @@ rules:
resources:
- experiments
verbs:
${OPERATOR_ROLE_CREATE}
${OPERATOR_ROLE_DELETE}
- get
- list
${OPERATOR_ROLE_PATCH}
- watch
{{- if eq .Values.onlyViewOnlyMode false }}
- create
- delete
- patch
{{- end }}
...
16 changes: 16 additions & 0 deletions deploy/charts/kiali-operator/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "kiali-operator.fullname" . }}
labels:
{{- include "kiali-operator.labels" . | nindent 4 }}
subjects:
- kind: ServiceAccount
name: {{ include "kiali-operator.fullname" . }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: {{ include "kiali-operator.fullname" . }}
apiGroup: rbac.authorization.k8s.io
...
Loading

0 comments on commit f0da889

Please sign in to comment.