From bd4fd9be09631dfb8a33983591b190b99bf4cac6 Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Thu, 31 Mar 2022 18:13:02 +0200 Subject: [PATCH] Add a Helm chart to create the custom resource. --- .github/workflows/build-push.yml | 12 ++- README.md | 14 ++- charts/cmcc-operator/README.md | 12 +-- charts/cmcc/.helmignore | 23 +++++ charts/cmcc/Chart.yaml | 6 ++ charts/cmcc/README.md | 94 +++++++++++++++++++ charts/cmcc/templates/NOTES.txt | 5 + charts/cmcc/templates/_helpers.tpl | 66 +++++++++++++ charts/cmcc/templates/cmcc.yaml | 20 ++++ charts/cmcc/values.yaml | 43 +++++++++ docs/custom-resource.md | 63 ++++++------- k8s/example.yaml | 8 +- .../cmccoperator/crds/ComponentDefaults.java | 2 +- 13 files changed, 322 insertions(+), 46 deletions(-) create mode 100644 charts/cmcc/.helmignore create mode 100644 charts/cmcc/Chart.yaml create mode 100644 charts/cmcc/README.md create mode 100644 charts/cmcc/templates/NOTES.txt create mode 100644 charts/cmcc/templates/_helpers.tpl create mode 100644 charts/cmcc/templates/cmcc.yaml create mode 100644 charts/cmcc/values.yaml diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index 3ffb0f7..16441e1 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -42,9 +42,17 @@ jobs: git config user.email "$GITHUB_ACTOR@users.noreply.github.com" - name: update Chart.yaml - working-directory: charts/cmcc-operator + working-directory: charts run: | - cat < Chart.yaml + cat <cmcc/Chart.yaml + apiVersion: v2 + name: cmcc + description: CoreMedia Content Cloud through cmcc-operator + type: application + version: ${{github.ref_name}} + appVersion: ${{github.ref_name}} + EOF + cat <cmcc-operator/Chart.yaml apiVersion: v2 name: cmcc-operator description: Kubernetes Operator to bring up a CoreMedia Content Cloud installation diff --git a/README.md b/README.md index 1eb84a3..66b3b3b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ Planned features include: ## Quick Links -* [Helm chart cmcc-operator](charts/cmcc-operator) +* [Helm chart cmcc-operator](charts/cmcc-operator) to install the operator +* [Helm chart cmcc](charts/cmcc) to create a CoreMedia Content Cloud deployment with the operator * [CoreMediaContentClouds custom resource documentation](docs/custom-resource.md) * [Installing the Operator](#preparing-your-cluster-and-installing-the-operator) * [Using the Operator to create a CoreMedia installation](#using-the-operator) @@ -120,7 +121,7 @@ The operator has a number of configuration parameters that can be set using the | Property | Environment | Default | Description | |-----------------------|-----------------------|-------------|-------------------------------------------------------------------------------------------------------------------------------------------| | `cmcc.ingressbuilder` | `CMCC_INGRESSBUILDER` | `blueprint` | The ingress builder to use. See [site mappings](docs/custom-resource.md#automatic-generation-of-ingresses-and-site-mappings-sitemappings) | -| `cmcc.useConfigMap` | `CMCC_USECONFIGMAP` | `false` | Use the ConfigMap reconciler (see [Installing the Operator Using a Config Map](#installing-the-operator-using-a-config-map)) | +| `cmcc.useConfigMap` | `CMCC_USECONFIGMAP` | `false` | Use the ConfigMap reconciler (see [Using a Config Map](#using-a-config-map)) | | `cmcc.useCrd` | `CMCC_USECRD` | `true` | Use the Custom Resource reconciler | ## Using the Operator @@ -138,6 +139,15 @@ kubectl create secret generic license-cms --from-file=license.zip=license/cms-li The license secrets need to be created in the same namespace you plan to install CoreMedia in. See `licenseSecrets`, below. +### Creating a CoreMedia Installation – Helm Chart + +The [Helm chart cmcc](charts/cmcc) can be used to create a deployment for CoreMedia Content Cloud. See the documentation there for information on how to supply the necessary values to Helm. + +````shell +$ helm repo add cmcc-operator https://t-systems-mms.github.io/cmcc-operator/ +$ helm upgrade --install my-release cmcc-operator/cmcc --values my-values.yaml +```` + ### Creating a CoreMedia Installation – Custom Resource You can create a complete CoreMedia installation by creating the custom resource `CoreMediaContentClouds` with the desired properties. An example can be found in [`k8s/example.yaml`](k8s/example.yaml), and can be created in the cluster like this: diff --git a/charts/cmcc-operator/README.md b/charts/cmcc-operator/README.md index 91711fa..d221655 100644 --- a/charts/cmcc-operator/README.md +++ b/charts/cmcc-operator/README.md @@ -8,7 +8,7 @@ operator; an accompanying chart helps managing the custom resource or config map ```console $ helm repo add cmcc-operator https://t-systems-mms.github.io/cmcc-operator/ -$ helm upgrade --install --create-namespace --namespace cmcc-operator cmcc-operator charts/cmcc-operator +$ helm upgrade --install --create-namespace --namespace cmcc-operator cmcc-operator cmcc-operator/cmcc-operator ``` ## Introduction @@ -24,23 +24,23 @@ operator; an accompanying chart helps managing the custom resource or config map ## Installing the Chart -To install the chart with the release name `my-release`: +To install the chart with the release name `cmcc-operator`: ```console -$ helm upgrade --install --create-namespace --namespace cmcc-operator cmcc-operator charts/cmcc-operator +$ helm upgrade --install --create-namespace --namespace cmcc-operator cmcc-operator cmcc-operator/cmcc-operator ``` -The command deploys Joomla! on the Kubernetes cluster in the default configuration. The [Parameters](#parameters) +The command deploys the operator on the Kubernetes cluster in the default configuration. The [Parameters](#parameters) section lists the parameters that can be configured during installation. > **Tip**: List all releases using `helm list` ## Uninstalling the Chart -To uninstall/delete the `my-release` deployment: +To uninstall/delete the `cmcc-operator` deployment: ```console -$ helm delete my-release +$ helm delete cmcc-operator ``` The command removes all the Kubernetes components associated with the chart and deletes the release. diff --git a/charts/cmcc/.helmignore b/charts/cmcc/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/cmcc/.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/cmcc/Chart.yaml b/charts/cmcc/Chart.yaml new file mode 100644 index 0000000..0ff92aa --- /dev/null +++ b/charts/cmcc/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: cmcc +description: CoreMedia Content Cloud through cmcc-operator +# this will be set during the release process +version: 0.1.0-alpha1 +appVersion: 0.1.0-alpha1 diff --git a/charts/cmcc/README.md b/charts/cmcc/README.md new file mode 100644 index 0000000..cfabbd3 --- /dev/null +++ b/charts/cmcc/README.md @@ -0,0 +1,94 @@ +# CoreMedia Content Cloud + +This helm chart creates a custom resource for the [CoreMedia Content Cloud Operator](https://github.com/T-Systems-MMS/cmcc-operator), configures and manages a [CoreMedia Content Cloud](https://www.coremedia.com/) deployment based on the configuration in that resource. + +## TL;DR + +```console +$ helm repo add cmcc-operator https://t-systems-mms.github.io/cmcc-operator/ +$ helm upgrade --install my-release cmcc-operator/cmcc --values my-values.yaml +``` + +## Introduction + +The [CoreMedia Content Cloud Operator](https://github.com/T-Systems-MMS/cmcc-operator) provides an easy to use way to +manage deployments of [CoreMedia Content Cloud](https://www.coremedia.com/). This Helm chart helps managing the custom resource or config map to manage an individual deployment. + +## Prerequisites + +- Kubernetes 1.19+ +- Helm 3.2.0+ + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```console +$ helm upgrade --install my-release cmcc-operator/cmcc --values my-values.yaml +``` + +The command deploys CoreMedia Content Cloud on the Kubernetes cluster. You will need to set a number of parameters, in particular `default.image.registry` to the Docker registry hosting your CoreMedia Content Cloud images. The [Parameters](#parameters) section lists the parameters that can be configured during installation. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```console +$ helm delete my-release +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Parameters + +| Name | Description | Value | +|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------| +| `cmcc` | The contents of the custom resource. See [Custom Resource CoreMediaContentClouds](https://github.com/T-Systems-MMS/cmcc-operator/blob/main/docs/custom-resource.md) for more information | – | +| `fullnameOverride` | Overrides the full name of components, which is used for the deployment, clusterrole and clusterrolemapping, and the service account. | the chart name plus the release name | +| `nameOverride` | Overrides the short name. Used for the selector labels. | the chart name | +| `useConfigMap` | Instead of creating a custom resource with the deployment description, use a config map. | the chart name | + + +## Configuration and Installation Details + + +### Substitution of variables inside values + +The contents of the `cmcc` value is fed through the Helm [`tpl()`](https://helm.sh/docs/howto/charts_tips_and_tricks/#using-the-tpl-function) function. This allows you to refer to other values from values inside the `cmcc` map. For example, if you need to configure an HTTPS_PROXY for multiple components, you could write: + +```yaml +httpProxy: https://proxy.example.com:3128 +cmcc: + ... + components: + - name: import-theme + type: management-tools + env: + - name: HTTPS_PROXY + value: "{{ .Values.httpProxy }}" + ... + - name: import-content + type: management-tools + env: + - name: HTTPS_PROXY + value: "{{ .Values.httpProxy }}" +``` + +### Using a Config Map Instead + +The operator uses a custom resource definition to obtain the deployment description for the CoreMedia Content Cloud installation. If you've installed the operator with support for using a `ConfigMap` (instead of or in addition to the custom resource), you can set `--set useConfigMap=true` to have this Helm chart create a config map. + +## License + +Copyright © 2022 T-Systems Multimedia Solutions GmbH + +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. diff --git a/charts/cmcc/templates/NOTES.txt b/charts/cmcc/templates/NOTES.txt new file mode 100644 index 0000000..6a4c19e --- /dev/null +++ b/charts/cmcc/templates/NOTES.txt @@ -0,0 +1,5 @@ +CoreMedia Content Cloud deployment resource has been updated. + +You can watch the progress of the deployment using: + kubectl --namespace {{ .Release.Namespace }} get cmcc {{ include "cmcc.fullname" . }} + diff --git a/charts/cmcc/templates/_helpers.tpl b/charts/cmcc/templates/_helpers.tpl new file mode 100644 index 0000000..ef828be --- /dev/null +++ b/charts/cmcc/templates/_helpers.tpl @@ -0,0 +1,66 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "cmcc.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 "cmcc.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 "cmcc.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "cmcc.labels" -}} +helm.sh/chart: {{ include "cmcc.chart" . }} +{{ include "cmcc.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "cmcc.selectorLabels" -}} +app.kubernetes.io/name: {{ include "cmcc.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "cmcc.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "cmcc.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{- define "cmcc.cmcc" -}} +{{- tpl (toYaml .Values.cmcc) . }} +{{- end }} diff --git a/charts/cmcc/templates/cmcc.yaml b/charts/cmcc/templates/cmcc.yaml new file mode 100644 index 0000000..d78e9ca --- /dev/null +++ b/charts/cmcc/templates/cmcc.yaml @@ -0,0 +1,20 @@ +{{- if .Values.useConfigMap }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }} + labels: + {{- include "cmcc.labels" . | nindent 4 }} +data: + spec: | + {{- include "cmcc.cmcc" . | nindent 4 }} +{{- else }} +apiVersion: cmcc.tsystemsmms.com/v1 +kind: CoreMediaContentCloud +metadata: + name: {{ .Release.Name }} + labels: + {{- include "cmcc.labels" . | nindent 4 }} +spec: + {{- include "cmcc.cmcc" . | nindent 2 }} +{{- end }} diff --git a/charts/cmcc/values.yaml b/charts/cmcc/values.yaml new file mode 100644 index 0000000..3f9eeb0 --- /dev/null +++ b/charts/cmcc/values.yaml @@ -0,0 +1,43 @@ +# Default values for cmcc. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +cmcc: + clientSecretRefs: {} + comment: "" + components: [] + defaultIngressTls: + enabled: true + secretName: "" + defaults: + curlImage: docker.io/alpine/curl:latest + image: + pullPolicy: IfNotPresent + registry: gitlab.exmaple.com/my-cmcc-project + tag: latest + insecureDatabasePassword: "" + ingressDomain: 127.0.0.1.nip.io + namePrefix: "" + previewHostname: preview + resources: {} + studioHostname: studio + job: "" +# licenseSecrets: +# cmsLicense: license-cms +# mlsLicense: license-mls +# rlsLicense: license-rls + siteMappings: [] + with: + contentImport: true + databases: true + delivery: + maxCae: 1 + minCae: 1 + rls: 0 + management: true + +nameOverride: "" +fullnameOverride: "" + +# should the deployment description be created as a config map instead of a custom resource? +useConfigMap: false \ No newline at end of file diff --git a/docs/custom-resource.md b/docs/custom-resource.md index 13ba017..e68367d 100644 --- a/docs/custom-resource.md +++ b/docs/custom-resource.md @@ -35,38 +35,37 @@ The `milestone` status column shows the creation status of the installation: The `spec` field defines these properties to allow you to deploy a CoreMedia installation. Whenever possible, these properties have suitable defaults. -| Property | Type | Default | Description | -|----------------------------------------|----------------------|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------| -| `comment` | String | "" | Arbitrary comment, can be used to force an update to the resource | -| `components` | array | [] | List of CoreMedia components to be created. See below for available components and their parameters | -| `clientSecretRefs` | map of map of object | – | Pre-existing secrets to use, see below | -| `defaults` | object | – | Default values for components | -| `defaults.curlImage` | String | `docker.io/alpine/k8s:1.19.15` | A Docker image with curl available. Used in init containers to wait for Content Server components to become available. | -| `defaults.image` | object | – | Defaults for the image specification | -| `defaults.image.registry` | String | "" | Docker Image Registry to pull images from | -| `defaults.image.tag` | String | `latest` | Docker Image Tag to pull images from | -| `defaults.image.pullPolicy` | String | `IfNotPresent` | default imagePullPolicy | -| `defaults.ingressDomain` | String | "" | Fully qualified domain name to append to ingress host names | -| `defaults.insecureDatabasePassword` | String | "" | **DO NOT | -| SET**. See below for more information. | | | | -| `defaults.namePrefix` | String | "" | Prefix resources with this name plus '-'. | -| `defaults.previewHostname` | String | `preview` | Hostname of the preview CAE. Unless it is a fully-qualified domain name, the `namePrefix` and the `ingressDomain` will be pre- and appended. | -| `defaults.resources` | resources | – | Default [resources to apply to component pods](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#resources) | -| `defaults.studioHostname` | String | `studio` | Hostname of the Studio. Unless it is a fully-qualified domain name, the `namePrefix` and the `ingressDomain` will be pre- and appended. | -| `defaultIngressTls` | object | – | Defaults for the site mapping TLS settings, see below | -| `job` | String | "" | name of a component to run as a job, see below | -| `licenseSecrets` | object | – | Names of the secrets containing the license | -| `licenseSecrets.CMSLicense` | String | `license-cms` | Name of the secret containing a `license.zip` entry with the appropriate file contents | -| `licenseSecrets.MLSLicense` | String | `license-mls` | Name of the secret containing a `license.zip` entry with the appropriate file contents | -| `licenseSecrets.RLSLicense` | String | `license-rls` | Name of the secret containing a `license.zip` entry with the appropriate file contents | -| `siteMappings` | array | – | Mappings between DNS names and site segments, see below | -| `with` | object | – | Optional special components and configurations | -| `with.databases` | boolean | false | Create both a MariaDB and MongoDB server, and schemas and secrets for all components that require them | -| `with.delivery` | object | – | Create all components required for a CoreMedia delivery stage | -| `with.delivery.rls` | int | 0 | Number of Replication Live Servers to create | -| `with.delivery.minCae` | int | 0 | Minimum number of CAEs per RLS | -| `with.delivery.maxCae` | int | 0 | Maximum number of CAEs per RLS | -| `with.management` | boolean | true | Create all components required for a CoreMedia management stage | +| Property | Type | Default | Description | +|-------------------------------------|----------------------|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------| +| `comment` | String | "" | Arbitrary comment, can be used to force an update to the resource | +| `components` | array | [] | List of CoreMedia components to be created. See below for available components and their parameters | +| `clientSecretRefs` | map of map of object | – | Pre-existing secrets to use, see below | +| `defaults` | object | – | Default values for components | +| `defaults.curlImage` | String | `docker.io/alpine/curl:latest` | A Docker image with curl available. Used in init containers to wait for Content Server components to become available. | +| `defaults.image` | object | – | Defaults for the image specification | +| `defaults.image.registry` | String | "" | Docker Image Registry to pull images from | +| `defaults.image.tag` | String | `latest` | Docker Image Tag to pull images from | +| `defaults.image.pullPolicy` | String | `IfNotPresent` | default imagePullPolicy | +| `defaults.ingressDomain` | String | "" | Fully qualified domain name to append to ingress host names | +| `defaults.insecureDatabasePassword` | String | "" | **DO NOT SET**. See below for more information. | +| `defaults.namePrefix` | String | "" | Prefix resources with this name plus '-'. | +| `defaults.previewHostname` | String | `preview` | Hostname of the preview CAE. Unless it is a fully-qualified domain name, the `namePrefix` and the `ingressDomain` will be pre- and appended. | +| `defaults.resources` | resources | – | Default [resources to apply to component pods](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#resources) | +| `defaults.studioHostname` | String | `studio` | Hostname of the Studio. Unless it is a fully-qualified domain name, the `namePrefix` and the `ingressDomain` will be pre- and appended. | +| `defaultIngressTls` | object | – | Defaults for the site mapping TLS settings, see below | +| `job` | String | "" | name of a component to run as a job, see below | +| `licenseSecrets` | object | – | Names of the secrets containing the license | +| `licenseSecrets.CMSLicense` | String | `license-cms` | Name of the secret containing a `license.zip` entry with the appropriate file contents | +| `licenseSecrets.MLSLicense` | String | `license-mls` | Name of the secret containing a `license.zip` entry with the appropriate file contents | +| `licenseSecrets.RLSLicense` | String | `license-rls` | Name of the secret containing a `license.zip` entry with the appropriate file contents | +| `siteMappings` | array | – | Mappings between DNS names and site segments, see below | +| `with` | object | – | Optional special components and configurations | +| `with.databases` | boolean | false | Create both a MariaDB and MongoDB server, and schemas and secrets for all components that require them | +| `with.delivery` | object | – | Create all components required for a CoreMedia delivery stage | +| `with.delivery.rls` | int | 0 | Number of Replication Live Servers to create | +| `with.delivery.minCae` | int | 0 | Minimum number of CAEs per RLS | +| `with.delivery.maxCae` | int | 0 | Maximum number of CAEs per RLS | +| `with.management` | boolean | true | Create all components required for a CoreMedia management stage | ## Enabling Convenience Options `with` diff --git a/k8s/example.yaml b/k8s/example.yaml index 8368e8c..354e9ef 100644 --- a/k8s/example.yaml +++ b/k8s/example.yaml @@ -3,10 +3,13 @@ kind: CoreMediaContentCloud metadata: name: example spec: - comment: a comment. with: + contentImport: true databases: true - live: true + delivery: + maxCae: 1 + minCae: 1 + rls: 0 management: true prefix: example defaults: @@ -22,4 +25,3 @@ spec: - corporate-de-de - corporate-en-ca - corporate-en-gb - diff --git a/src/main/java/com/tsystemsmms/cmcc/cmccoperator/crds/ComponentDefaults.java b/src/main/java/com/tsystemsmms/cmcc/cmccoperator/crds/ComponentDefaults.java index c324df7..f7e808d 100644 --- a/src/main/java/com/tsystemsmms/cmcc/cmccoperator/crds/ComponentDefaults.java +++ b/src/main/java/com/tsystemsmms/cmcc/cmccoperator/crds/ComponentDefaults.java @@ -22,7 +22,7 @@ @Data public class ComponentDefaults { @JsonPropertyDescription("Docker image with curl available") - private String curlImage = "docker.io/alpine/k8s:1.19.15"; + private String curlImage = "docker.io/alpine/curl:latest"; @JsonPropertyDescription("Defaults for the image specification") private ImageSpec image;