Skip to content
Merged
1 change: 1 addition & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ ignore: |
manifests/
vendor/
compiled/
tests/golden/**
22 changes: 22 additions & 0 deletions class/capi-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,25 @@ parameters:
- ${_base_directory}/component/main.jsonnet
input_type: jsonnet
output_path: capi-core/
- input_paths:
- ${_base_directory}/component/cluster-api.jsonnet
input_type: jsonnet
output_path: ${_base_directory}/manifests/cluster-api/
- input_type: external
output_path: .
input_paths:
- ${_kustomize_wrapper}
env_vars:
INPUT_DIR: ${_base_directory}/manifests/cluster-api/
args:
- ${_base_directory}/manifests/cluster-api-rendered/
- input_type: external
output_path: .
input_paths:
- ${_base_directory}/scripts/envsubst-dir
# map env vars from parameters as needed
env_vars:
ENVSUBST_VERSION: v1.4.3
args:
- ${_base_directory}/manifests/cluster-api-rendered
- \${compiled_target_dir}/capi-core/cluster-api/10_kustomize
14 changes: 13 additions & 1 deletion class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ parameters:
capi_core:
=_metadata:
multi_tenant: true
namespace: syn-capi-core
namespace: syn-cluster-api

images:
cluster-api:
registry: registry.k8s.io
image: cluster-api/cluster-api-controller
tag: v1.13.5

# An object with variables that the generated manifests will be templated with.
# They should be specified in the format:
# variables:
# foo: bar
variables: {}
63 changes: 63 additions & 0 deletions component/cluster-api.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// main template for capi-core
local com = import 'lib/commodore.libjsonnet';
local kap = import 'lib/kapitan.libjsonnet';
local inv = kap.inventory();
// The hiera parameters for the component
local params = inv.parameters.capi_core;

local capi_version =
local verparts = std.split(params.images['cluster-api'].tag[1:], '.');
local parseOrError(val, typ) =
local parsed = std.parseJson(val);
if std.isNumber(parsed) then
parsed
else
error
'Failed to parse %s version "%s" as number' % [
typ,
val,
];
{
major: parseOrError(verparts[0], 'major'),
minor: parseOrError(verparts[1], 'minor'),
};
local manifest_path = if capi_version.major > 1
|| capi_version.major == 1
&& capi_version.minor > 13 then
'core/config/default'
else
'config/default';

com.Kustomization(
'https://github.com/kubernetes-sigs/cluster-api/' + manifest_path,
params.images['cluster-api'].tag,
{
'gcr.io/k8s-staging-cluster-api/cluster-api-controller': {
local image = params.images['cluster-api'],
newTag: image.tag,
newName: '%(registry)s/%(image)s' % image,
},
},
{
namespace: params.namespace,
labels+: [
{
pairs: {
'app.kubernetes.io/managed-by': 'commodore',
},
},
],
patchesStrategicMerge: [ 'rm-namespace.yaml' ],
},
) {
'rm-namespace': [
{
'$patch': 'delete',
apiVersion: 'v1',
kind: 'Namespace',
metadata: {
name: 'capi-system',
},
},
],
}
3 changes: 2 additions & 1 deletion component/main.jsonnet
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// main template for capi-core
local com = import 'lib/commodore.libjsonnet';
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';
local inv = kap.inventory();
// The hiera parameters for the component
local params = inv.parameters.capi_core;

// Define outputs below
{
'00_namespace': kube.Namespace(params.namespace),
}
77 changes: 77 additions & 0 deletions scripts/envsubst-dir
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
set -euo pipefail

basedir=$(dirname "$0")/../dependencies
version="${ENVSUBST_VERSION:-v1.4.3}"

src="$1"
dst="$2"

ensure_envsubst () {
set -eu

local dir="$1"
# Version with leading `v`.
local version="$2"

local arch
arch=$(uname -m)
case $arch in
aarch64|arm64) arch="arm64";;
x86_64|amd64) arch="x86_64";;
*)
>&2 echo "Unsupported arch: $arch"
exit 5
::
esac

local os
os=$(uname -s)
if [[ "$os" != "Linux" && "$os" != "Darwin" ]]; then
>&2 echo "Unsupported os: $os"
exit 5
fi

if [ ! -x "${dir}/envsubst-${version}-${os}-${arch}" ]; then
download_envsubst "${dir}" "${version}" "${os}" "${arch}"
else
>&2 echo "envsubst-${version}-${os}-${arch} already installed"
fi

echo "${dir}/envsubst-${version}-${os}-${arch}"
}

download_envsubst () {
set -eu

local dir="$1"
local version="$2"
local os="$3"
local arch="$4"

local url="https://github.com/a8m/envsubst/releases/download/${version}/envsubst-${os}-${arch}"

>&2 echo "Downloading envsubst-${version}-${os}-${arch} from ${url}"

curl -fsSLo "${dir}/envsubst-${version}-${os}-${arch}" "${url}"
chmod +x "${dir}/envsubst-${version}-${os}-${arch}"

>&2 echo "envsubst-${version}-${os}-${arch} successfully installed"
}

envsubst="$(ensure_envsubst "${basedir}" "${version}")"

mkdir -p "$dst"

find "$src" -type f -name '*.yaml' -print0 |
while IFS= read -r -d '' file; do
relative="${file#$src/}"
output="$dst/$relative"

mkdir -p "$(dirname "$output")"

"$envsubst" \
-no-unset \
-i "$file" \
-o "$output"
done
2 changes: 0 additions & 2 deletions tests/defaults.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# Overwrite parameters here

# parameters: {...}
7 changes: 7 additions & 0 deletions tests/golden/defaults/capi-core/capi-core/00_namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Namespace
metadata:
annotations: {}
labels:
name: syn-cluster-api
name: syn-cluster-api
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
annotations:
cert-manager.io/inject-ca-from: capi-system/capi-serving-cert
labels:
app.kubernetes.io/managed-by: commodore
cluster.x-k8s.io/provider: cluster-api
name: capi-mutating-webhook-configuration
webhooks:
- admissionReviewVersions:
- v1
clientConfig:
service:
name: capi-webhook-service
namespace: syn-cluster-api
path: /mutate-cluster-x-k8s-io-v1beta2-cluster
failurePolicy: Fail
matchPolicy: Equivalent
name: default.cluster.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
apiVersions:
- v1beta2
operations:
- CREATE
- UPDATE
resources:
- clusters
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: capi-webhook-service
namespace: syn-cluster-api
path: /mutate-addons-cluster-x-k8s-io-v1beta2-clusterresourceset
failurePolicy: Fail
matchPolicy: Equivalent
name: default.clusterresourceset.addons.cluster.x-k8s.io
rules:
- apiGroups:
- addons.cluster.x-k8s.io
apiVersions:
- v1beta2
operations:
- CREATE
- UPDATE
resources:
- clusterresourcesets
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: capi-webhook-service
namespace: syn-cluster-api
path: /mutate-runtime-cluster-x-k8s-io-v1beta2-extensionconfig
failurePolicy: Fail
matchPolicy: Equivalent
name: default.extensionconfig.runtime.addons.cluster.x-k8s.io
rules:
- apiGroups:
- runtime.cluster.x-k8s.io
apiVersions:
- v1beta2
operations:
- CREATE
- UPDATE
resources:
- extensionconfigs
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: capi-webhook-service
namespace: syn-cluster-api
path: /mutate-cluster-x-k8s-io-v1beta2-machine
failurePolicy: Fail
matchPolicy: Equivalent
name: default.machine.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
apiVersions:
- v1beta2
operations:
- CREATE
- UPDATE
resources:
- machines
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: capi-webhook-service
namespace: syn-cluster-api
path: /mutate-cluster-x-k8s-io-v1beta2-machinedeployment
failurePolicy: Fail
matchPolicy: Equivalent
name: default.machinedeployment.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
apiVersions:
- v1beta2
operations:
- CREATE
- UPDATE
resources:
- machinedeployments
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: capi-webhook-service
namespace: syn-cluster-api
path: /mutate-cluster-x-k8s-io-v1beta2-machinehealthcheck
failurePolicy: Fail
matchPolicy: Equivalent
name: default.machinehealthcheck.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
apiVersions:
- v1beta2
operations:
- CREATE
- UPDATE
resources:
- machinehealthchecks
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: capi-webhook-service
namespace: syn-cluster-api
path: /mutate-cluster-x-k8s-io-v1beta2-machinepool
failurePolicy: Fail
matchPolicy: Equivalent
name: default.machinepool.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
apiVersions:
- v1beta2
operations:
- CREATE
- UPDATE
resources:
- machinepools
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: capi-webhook-service
namespace: syn-cluster-api
path: /mutate-cluster-x-k8s-io-v1beta2-machineset
failurePolicy: Fail
matchPolicy: Equivalent
name: default.machineset.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
apiVersions:
- v1beta2
operations:
- CREATE
- UPDATE
resources:
- machinesets
sideEffects: None
Loading
Loading