modified generation of controller-registration.yaml - added globalyEnabled: true, improved examples

This commit is contained in:
Jakub Vavřík
2021-01-30 11:14:15 +01:00
parent 0d74cb5852
commit 46ab0c5eae
9 changed files with 129 additions and 38 deletions

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:generate ../../vendor/github.com/gardener/gardener/hack/generate-controller-registration.sh extension-shoot-fleet-agent . ../../VERSION ../../example/controller-registration.yaml Extension:shoot-fleet-agent
//go:generate ../../hack/generate-controller-registration.sh extension-shoot-fleet-agent . ../../VERSION ../../example/controller-registration.yaml Extension:shoot-fleet-agent
// Package chart enables go:generate support for generating the correct controller registration.
package chart

View File

@@ -9,7 +9,10 @@ kind: FleetAgentConfig
clientConnection:
kubeconfig: {{ .Values.fleetManager.kubeconfig }}
{{- if .Values.fleetManager.labels }}
labels: {{ .Values.fleetManager.labels | toYaml }}
labels: {{ .Values.fleetManager.labels | toYaml | nindent 6 }}
{{- end }}
{{- if .Values.fleetManager.namespace }}
namespace: {{ .Values.fleetManager.namespace }}
{{- end }}
{{- end }}

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
apiVersion: shoot-fleet-agent-service.extensions.config.gardener.cloud/v1alpha1
kind: FleetAgentConfig
clientConnection:
kubeconfig: #base64 encoded kubeconfig
kubeconfig: #base64 encoded kubeconfig of fleet cluster
namespace: clusters #namespace to register clusters in fleet manager cluster

View File

@@ -1,28 +0,0 @@
---
apiVersion: extensions.gardener.cloud/v1alpha1
kind: Cluster
metadata:
name: shoot--foo--bar
spec:
cloudProfile:
apiVersion: core.gardener.cloud/v1beta1
kind: CloudProfile
seed:
apiVersion: core.gardener.cloud/v1beta1
kind: Seed
shoot:
apiVersion: core.gardener.cloud/v1beta1
kind: Shoot
metadata:
generation: 1
name: shoot--foo--bar
spec:
dns:
domain: foo.bar.example.com
kubernetes:
version: 1.18.2
status:
lastOperation:
state: Succeeded
observedGeneration: 1

View File

@@ -7,5 +7,8 @@ metadata:
spec:
type: shoot-fleet-agent
providerConfig:
apiVersion: service.cert.extensions.gardener.cloud/v1alpha1
kind: CertConfig
apiVersion: shoot-fleet-agent-service.extensions.config.gardener.cloud/v1alpha1
kind: FleetAgentConfig
clientConnection:
kubeconfig: #base64 encoded kubeconfig of fleet cluster
namespace: clusters #namespace to register clusters in fleet manager cluster

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,109 @@
#!/bin/bash
#
# Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
#
# 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.
set -e
set -o pipefail
function usage {
cat <<EOM
Usage:
generate-controller-registration <name> <chart-dir> <dest> <kind-and-type> [kinds-and-types ...]
<name> Name of the controller registration to generate.
<chart-dir> Location of the chart directory.
<version-file> Location of the VERSION file.
<dest> The destination file to write the registration YAML to.
<kind-and-type> A tuple of kind and type of the controller registration to generate.
Separated by ':'.
Example: OperatingSystemConfig:foobar
<kinds-and-types> Further tuples of kind and type of the controller registration to generate.
Separated by ':'.
EOM
exit 0
}
if [ "$1" == "--optional" ]; then
shift
MODE=$'\n globallyEnabled: false'
fi
NAME="$1"
CHART_DIR="$2"
VERSION_FILE="$3"
DEST="$4"
KIND_AND_TYPE="$5"
VERSION="$(cat "$VERSION_FILE")"
( [[ -z "$NAME" ]] || [[ -z "$CHART_DIR" ]] || [[ -z "$DEST" ]] || [[ -z "$KIND_AND_TYPE" ]]) && usage
KINDS_AND_TYPES=("$KIND_AND_TYPE" "${@:6}")
# The following code is to make `helm package` idempotent: Usually, everytime `helm package` is invoked,
# it produces a different `.tgz` due to modification timestamps and some special shasums of gzip. We
# resolve this by unarchiving the `.tgz`, compressing it again with a constant `mtime` and no gzip
# checksums.
temp_dir="$(mktemp -d)"
temp_helm_home="$(mktemp -d)"
temp_extract_dir="$(mktemp -d)"
function cleanup {
rm -rf "$temp_dir"
rm -rf "$temp_helm_home"
rm -rf "$temp_extract_dir"
}
trap cleanup EXIT ERR INT TERM
export HELM_HOME="$temp_helm_home"
[ "$(helm version --client --template "{{.Version}}" | head -c2 | tail -c1)" = "3" ] || helm init --client-only > /dev/null 2>&1
helm package "$CHART_DIR" --version "$VERSION" --app-version "$VERSION" --destination "$temp_dir" > /dev/null
tar -xzm -C "$temp_extract_dir" -f "$temp_dir"/*
chart="$(tar --sort=name -c --owner=root:0 --group=root:0 --mtime='UTC 2019-01-01' -C "$temp_extract_dir" "$(basename "$temp_extract_dir"/*)" | gzip -n | base64 | tr -d '\n')"
mkdir -p "$(dirname "$DEST")"
cat <<EOM > "$DEST"
---
apiVersion: core.gardener.cloud/v1beta1
kind: ControllerRegistration
metadata:
name: $NAME
spec:
resources:
EOM
for kind_and_type in "${KINDS_AND_TYPES[@]}"; do
KIND="$(echo "$kind_and_type" | cut -d ':' -f 1)"
TYPE="$(echo "$kind_and_type" | cut -d ':' -f 2)"
cat <<EOM >> "$DEST"
- kind: $KIND
type: $TYPE$MODE
globallyEnabled: true
EOM
done
cat <<EOM >> "$DEST"
deployment:
type: helm
providerConfig:
chart: $chart
values:
image:
tag: $VERSION
fleetManager:
kubeconfig: #base64 encoded kubeconfig of Fleet manager cluster with user that has write access to Cluster and Secret
namespace: clusters
EOM
echo "Successfully generated controller registration at $DEST"

View File

@@ -45,5 +45,4 @@ bash "${PROJECT_ROOT}"/vendor/k8s.io/code-generator/generate-internal-groups.sh
github.com/rancher/fleet/pkg/apis \
github.com/rancher/fleet/pkg/apis \
"fleet.cattle.io:v1alpha1" \
--go-header-file "${PROJECT_ROOT}/vendor/github.com/gardener/gardener/hack/LICENSE_BOILERPLATE.txt"
#--extra-peer-dirs=github.com/javamachr/gardener-extension-shoot-fleet-agent/pkg/apis/config,github.com/javamachr/gardener-extension-shoot-fleet-agent/pkg/apis/config/v1alpha1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/conversion,k8s.io/apimachinery/pkg/runtime, github.com/gardener/gardener/extensions/pkg/controller/healthcheck/config/v1alpha1
--go-header-file "${PROJECT_ROOT}/vendor/github.com/gardener/gardener/hack/LICENSE_BOILERPLATE.txt"