diff --git a/class/defaults.yml b/class/defaults.yml index 8921e52..50dabf4 100644 --- a/class/defaults.yml +++ b/class/defaults.yml @@ -1,4 +1,26 @@ parameters: local_path_provisioner: =_metadata: {} + namespace: syn-local-path-provisioner + + charts: + local_path_provisioner: + source: https://github.com/rancher/local-path-provisioner.git + version: v0.0.24 + + helmValues: + storageClass: + name: local-path + nodePathMap: + - node: DEFAULT_PATH_FOR_NON_LISTED_NODES + paths: + - /var/lib/local-storage + resources: + requests: + cpu: 50m + memory: 128Mi + limits: + memory: 128Mi + image: + tag: v0.0.24 diff --git a/class/local-path-provisioner.yml b/class/local-path-provisioner.yml index e09a51b..e8c2a5d 100644 --- a/class/local-path-provisioner.yml +++ b/class/local-path-provisioner.yml @@ -1,5 +1,11 @@ parameters: kapitan: + dependencies: + - type: git + source: ${local_path_provisioner:charts:local_path_provisioner:source} + subdir: deploy/chart/local-path-provisioner + ref: ${local_path_provisioner:charts:local_path_provisioner:version} + output_path: ${_base_directory}/helmcharts/local_path_provisioner/${local_path_provisioner:charts:local_path_provisioner:version}/ compile: - input_paths: - ${_base_directory}/component/app.jsonnet @@ -9,3 +15,13 @@ parameters: - ${_base_directory}/component/main.jsonnet input_type: jsonnet output_path: local-path-provisioner/ + # Helmchart + - input_paths: + - ${_base_directory}/helmcharts/local_path_provisioner/${local_path_provisioner:charts:local_path_provisioner:version} + input_type: helm + output_path: local-path-provisioner/10_helmchart + helm_values: ${local_path_provisioner:helmValues} + helm_params: + name: local-path-provisioner + namespace: ${local_path_provisioner:namespace} + dependency_update: true diff --git a/component/main.jsonnet b/component/main.jsonnet index d70f6ae..265bc41 100644 --- a/component/main.jsonnet +++ b/component/main.jsonnet @@ -1,10 +1,21 @@ -// main template for local-path-provisioner +// main template for rook-mini local kap = import 'lib/kapitan.libjsonnet'; local kube = import 'lib/kube.libjsonnet'; +local prom = import 'lib/prometheus.libsonnet'; local inv = kap.inventory(); // The hiera parameters for the component local params = inv.parameters.local_path_provisioner; +local hasPrometheus = std.member(inv.applications, 'prometheus'); + +local namespace = kube.Namespace(params.namespace) + { + metadata+: { + labels+: { + 'pod-security.kubernetes.io/enforce': 'privileged', + }, + }, +}; // Define outputs below { + '00_namespace': if hasPrometheus then prom.RegisterNamespace(namespace) else namespace, } diff --git a/tests/defaults.yml b/tests/defaults.yml index a4da5b7..3d36c4d 100644 --- a/tests/defaults.yml +++ b/tests/defaults.yml @@ -1,3 +1,12 @@ -# Overwrite parameters here +applications: + - prometheus -# parameters: {...} +parameters: + kapitan: + dependencies: + - type: https + source: https://raw.githubusercontent.com/projectsyn/component-prometheus/master/lib/prometheus.libsonnet + output_path: vendor/lib/prometheus.libsonnet + + prometheus: + defaultInstance: system diff --git a/tests/golden/defaults/local-path-provisioner/local-path-provisioner/00_namespace.yaml b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/00_namespace.yaml new file mode 100644 index 0000000..24760c0 --- /dev/null +++ b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/00_namespace.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Namespace +metadata: + annotations: {} + labels: + monitoring.syn.tools/system: 'true' + name: syn-local-path-provisioner + pod-security.kubernetes.io/enforce: privileged + name: syn-local-path-provisioner diff --git a/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/clusterrole.yaml b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/clusterrole.yaml new file mode 100644 index 0000000..aca06b1 --- /dev/null +++ b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/clusterrole.yaml @@ -0,0 +1,44 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/instance: local-path-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: local-path-provisioner + app.kubernetes.io/version: v0.0.24 + helm.sh/chart: local-path-provisioner-0.0.24 + name: local-path-provisioner +rules: + - apiGroups: + - '' + resources: + - nodes + - persistentvolumeclaims + - configmaps + verbs: + - get + - list + - watch + - apiGroups: + - '' + resources: + - endpoints + - persistentvolumes + - pods + verbs: + - '*' + - apiGroups: + - '' + resources: + - events + verbs: + - create + - patch + - apiGroups: + - storage.k8s.io + resources: + - storageclasses + verbs: + - get + - list + - watch diff --git a/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/clusterrolebinding.yaml b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/clusterrolebinding.yaml new file mode 100644 index 0000000..8b849ea --- /dev/null +++ b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/clusterrolebinding.yaml @@ -0,0 +1,18 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + labels: + app.kubernetes.io/instance: local-path-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: local-path-provisioner + app.kubernetes.io/version: v0.0.24 + helm.sh/chart: local-path-provisioner-0.0.24 + name: local-path-provisioner +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: local-path-provisioner +subjects: + - kind: ServiceAccount + name: local-path-provisioner + namespace: syn-local-path-provisioner diff --git a/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/configmap.yaml b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/configmap.yaml new file mode 100644 index 0000000..458817b --- /dev/null +++ b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/configmap.yaml @@ -0,0 +1,42 @@ +apiVersion: v1 +data: + config.json: |- + { + "nodePathMap": [ + { + "node": "DEFAULT_PATH_FOR_NON_LISTED_NODES", + "paths": [ + "/var/lib/local-storage" + ] + } + ] + } + helperPod.yaml: |- + apiVersion: v1 + kind: Pod + metadata: + name: helper-pod + spec: + containers: + - name: helper-pod + image: busybox:latest + imagePullPolicy: IfNotPresent + setup: |2- + + #!/bin/sh + set -eu + mkdir -m 0777 -p "$VOL_DIR" + teardown: |2- + + #!/bin/sh + set -eu + rm -rf "$VOL_DIR" +kind: ConfigMap +metadata: + labels: + app.kubernetes.io/instance: local-path-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: local-path-provisioner + app.kubernetes.io/version: v0.0.24 + helm.sh/chart: local-path-provisioner-0.0.24 + name: local-path-config diff --git a/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/deployment.yaml b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/deployment.yaml new file mode 100644 index 0000000..0814538 --- /dev/null +++ b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/deployment.yaml @@ -0,0 +1,57 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/instance: local-path-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: local-path-provisioner + app.kubernetes.io/version: v0.0.24 + helm.sh/chart: local-path-provisioner-0.0.24 + name: local-path-provisioner +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: local-path-provisioner + app.kubernetes.io/name: local-path-provisioner + template: + metadata: + labels: + app.kubernetes.io/instance: local-path-provisioner + app.kubernetes.io/name: local-path-provisioner + spec: + containers: + - command: + - local-path-provisioner + - --debug + - start + - --config + - /etc/config/config.json + - --service-account-name + - local-path-provisioner + - --provisioner-name + - cluster.local/local-path-provisioner + - --helper-image + - busybox:latest + - --configmap-name + - local-path-config + env: + - name: POD_NAMESPACE + value: syn-local-path-provisioner + image: rancher/local-path-provisioner:v0.0.24 + imagePullPolicy: IfNotPresent + name: local-path-provisioner + resources: + limits: + memory: 128Mi + requests: + cpu: 50m + memory: 128Mi + volumeMounts: + - mountPath: /etc/config/ + name: config-volume + serviceAccountName: local-path-provisioner + volumes: + - configMap: + name: local-path-config + name: config-volume diff --git a/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/serviceaccount.yaml b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/serviceaccount.yaml new file mode 100644 index 0000000..58ef412 --- /dev/null +++ b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/serviceaccount.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +imagePullSecrets: null +kind: ServiceAccount +metadata: + labels: + app.kubernetes.io/instance: local-path-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: local-path-provisioner + app.kubernetes.io/version: v0.0.24 + helm.sh/chart: local-path-provisioner-0.0.24 + name: local-path-provisioner diff --git a/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/storageclass.yaml b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/storageclass.yaml new file mode 100644 index 0000000..78e0a29 --- /dev/null +++ b/tests/golden/defaults/local-path-provisioner/local-path-provisioner/10_helmchart/local-path-provisioner/templates/storageclass.yaml @@ -0,0 +1,14 @@ +allowVolumeExpansion: true +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + labels: + app.kubernetes.io/instance: local-path-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: local-path-provisioner + app.kubernetes.io/version: v0.0.24 + helm.sh/chart: local-path-provisioner-0.0.24 + name: local-path +provisioner: cluster.local/local-path-provisioner +reclaimPolicy: Delete +volumeBindingMode: WaitForFirstConsumer