diff --git a/README.md b/README.md index c7427a6..6bed394 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ crossplane configurations, apis and examples ## DEV KIND CLUSTER DEPLOYMENT & CONFIGURATION OF CROSSPLANE -
CREATE KIND CLUSTER w/ DAGGER (DOCKER MUST RUN ON THE MACHINE) +
CREATE KIND CLUSTER w/ DAGGER (DOCKER+KIND ARE REQUIRED) ```bash export TASK_X_REMOTE_TASKFILES=1 @@ -32,7 +32,6 @@ execute-ansible \
-
CROSSPLANE DEPLOYMENT w/ DAGGER/HELMFILE ```bash @@ -62,7 +61,6 @@ kubectl apply -k https://github.com/stuttgart-things/helm/cicd/crds/tekton ``` ```bash -# DEPLOY OPENEBS w/ DAGGER dagger call -m github.com/stuttgart-things/dagger/helm@v0.57.0 \ helmfile-operation \ --helmfile-ref "git::https://github.com/stuttgart-things/helm.git@infra/openebs.yaml.gotmpl" \ diff --git a/Taskfile.yaml b/Taskfile.yaml index 847f425..83f49b4 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -20,8 +20,6 @@ includes: taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/configuration/k2n.yaml tasks: - - push-configuration-package: desc: Push crossplane configuration package cmds: @@ -86,7 +84,7 @@ tasks: SOURCE_FOLDER: "./configurations" ALL_CONFIGURATION_PACKAGES: sh: | - find {{ .SOURCE_FOLDER }}/k8s {{ .SOURCE_FOLDER }}/cluster {{ .SOURCE_FOLDER }}/infra {{ .SOURCE_FOLDER }}/config {{ .SOURCE_FOLDER }}/terraform {{ .SOURCE_FOLDER }}/apps \ + find {{ .SOURCE_FOLDER }}/claims {{ .SOURCE_FOLDER }}/k8s {{ .SOURCE_FOLDER }}/infra {{ .SOURCE_FOLDER }}/config {{ .SOURCE_FOLDER }}/terraform {{ .SOURCE_FOLDER }}/apps \ -mindepth 1 -maxdepth 1 -type d | \ sed "s|^\./configurations/||" | \ sort | \ diff --git a/cmds.md b/cmds.md index 89688c4..41bd024 100644 --- a/cmds.md +++ b/cmds.md @@ -1,5 +1,14 @@ # COMMANDS/TROUBLESHOOTING +
HELM RELEASES + +```bash +kubectl get releases.helm.m.crossplane.io -A +kubectl get releases.helm.crossplane.io -A +``` + +
+
DEBUG CROSSPLANE PROVIDER ```bash @@ -39,3 +48,16 @@ EOF ```
+ +
CREATE KCL SCHEMAS FROM XRD + +```bash +# APPLY AGAINST K8S +kubectl apply -f ./definition.yaml +# READ CRD +kubectl get crd volumeclaims.resources.stuttgart-things.com -o yaml > /tmp/generated-crd-vc.yaml +# CREATE SCHEMA w/ KCL +kcl import -m crd /tmp/generated-crd-vc.yaml -o /tmp/schema +``` + +
diff --git a/configurations/infra/storage-platform/README.md b/configurations/infra/storage-platform/README.md index 02ec651..8a1a488 100644 --- a/configurations/infra/storage-platform/README.md +++ b/configurations/infra/storage-platform/README.md @@ -5,7 +5,7 @@ ```bash # RENDER NFS crossplane render examples/nfs.yaml \ -./compositions/storageplatform-openebs.yaml \ +./compositions/storageplatform-nfs.yaml \ examples/functions.yaml \ --include-function-results ``` diff --git a/configurations/infra/storage-platform/apis/definition.yaml b/configurations/infra/storage-platform/apis/definition.yaml index 81e87b4..84b19fa 100644 --- a/configurations/infra/storage-platform/apis/definition.yaml +++ b/configurations/infra/storage-platform/apis/definition.yaml @@ -1,17 +1,16 @@ +--- apiVersion: apiextensions.crossplane.io/v2 kind: CompositeResourceDefinition metadata: - name: storageplatforms.storage.platform.example.org + name: storageplatforms.resources.stuttgart-things.com spec: - group: storage.platform.example.org + group: resources.stuttgart-things.com defaultCompositeDeletePolicy: Foreground scope: Namespaced - names: kind: StoragePlatform plural: storageplatforms singular: storageplatform - versions: - name: v1alpha1 served: true @@ -26,7 +25,6 @@ spec: required: - engine properties: - engine: type: object required: @@ -38,22 +36,23 @@ spec: - openebs - nfs description: Selected storage engine - - providerConfigRef: + targetCluster: type: object - description: Helm provider override + required: + - name properties: name: type: string - default: helm-provider-cluster - - kubernetesProviderConfigRef: - type: object - description: Kubernetes provider override - properties: - name: + description: Name of the ProviderConfig / ClusterProviderConfig + scope: type: string - default: kubernetes-provider-cluster + enum: + - Namespaced + - Cluster + default: Namespaced + description: | + Whether to use ProviderConfig (Namespaced) + or ClusterProviderConfig (Cluster) # -------------------- # OpenEBS configuration diff --git a/configurations/infra/storage-platform/compositions/storageplatform-nfs.yaml b/configurations/infra/storage-platform/compositions/storageplatform-nfs.yaml index 7e0d91c..97d9a08 100644 --- a/configurations/infra/storage-platform/compositions/storageplatform-nfs.yaml +++ b/configurations/infra/storage-platform/compositions/storageplatform-nfs.yaml @@ -4,11 +4,11 @@ kind: Composition metadata: name: storageplatform-nfs labels: - crossplane.io/xrd: storageplatforms.storage.platform.example.org + crossplane.io/xrd: storageplatforms.resources.stuttgart-things.com storage.platform.example.org/engine: nfs spec: compositeTypeRef: - apiVersion: storage.platform.example.org/v1alpha1 + apiVersion: resources.stuttgart-things.com/v1alpha1 kind: StoragePlatform mode: Pipeline pipeline: @@ -24,6 +24,13 @@ spec: {{- $spec := .observed.composite.resource.spec -}} {{- $nfs := $spec.nfs -}} + {{- $scope := $spec.targetCluster.scope | default "Namespaced" -}} + {{- $pcKind := "ProviderConfig" -}} + {{- if eq $scope "Cluster" -}} + {{- $pcKind = "ClusterProviderConfig" -}} + {{- end -}} + + {{- if $nfs.namespace }} --- apiVersion: helm.m.crossplane.io/v1beta1 kind: Release @@ -36,38 +43,29 @@ spec: storage.platform.example.org/engine: nfs spec: deletionPolicy: Delete - providerConfigRef: - name: {{ $spec.providerConfigRef.name | default "helm-provider-cluster" }} - kind: ClusterProviderConfig - + name: {{ $spec.targetCluster.name }} + kind: {{ $pcKind }} forProvider: namespace: {{ $nfs.namespace | default "kube-system" }} - chart: name: csi-driver-nfs repository: https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/charts version: {{ $nfs.version | default "v4.11.0" }} - values: serviceAccount: create: {{ $nfs.serviceAccountCreate | default true }} controller: {{ $nfs.serviceAccountController | default "csi-nfs-controller-sa" }} - rbac: create: {{ $nfs.rbacCreate | default true }} name: {{ $nfs.rbacName | default "nfs" }} - driver: name: {{ $nfs.driverName | default "nfs.csi.k8s.io" }} mountPermissions: {{ $nfs.mountPermissions | default 0 }} - feature: enableFSGroupPolicy: {{ $nfs.enableFSGroupPolicy | default true }} enableInlineVolume: {{ $nfs.enableInlineVolume | default false }} - kubeletDir: {{ $nfs.kubeletDir | default "/var/lib/kubelet" }} - externalSnapshotter: enabled: {{ $nfs.externalSnapshotterEnabled | default false }} @@ -83,11 +81,9 @@ spec: storage.platform.example.org/engine: nfs spec: deletionPolicy: Delete - providerConfigRef: - name: {{ $spec.kubernetesProviderConfigRef.name | default "kubernetes-provider-cluster" }} - kind: ClusterProviderConfig - + name: {{ $spec.targetCluster.name }} + kind: {{ $pcKind }} forProvider: manifest: apiVersion: storage.k8s.io/v1 @@ -106,10 +102,8 @@ spec: {{- range $nfs.mountOptions | default (list "nfsvers=4.1") }} - {{ . }} {{- end }} + {{- end }} - --- - apiVersion: storage.platform.example.org/v1alpha1 - kind: StoragePlatform - status: - installed: true - observedVersion: {{ $nfs.version | default "v4.11.0" }} + - step: automatically-detect-ready-composed-resources + functionRef: + name: function-auto-ready diff --git a/configurations/infra/storage-platform/compositions/storageplatform-openebs.yaml b/configurations/infra/storage-platform/compositions/storageplatform-openebs.yaml index bd55d91..3efa6d3 100644 --- a/configurations/infra/storage-platform/compositions/storageplatform-openebs.yaml +++ b/configurations/infra/storage-platform/compositions/storageplatform-openebs.yaml @@ -4,11 +4,11 @@ kind: Composition metadata: name: storageplatform-openebs labels: - crossplane.io/xrd: storageplatforms.storage.platform.example.org + crossplane.io/xrd: storageplatforms.resources.stuttgart-things.com storage.platform.example.org/engine: openebs spec: compositeTypeRef: - apiVersion: storage.platform.example.org/v1alpha1 + apiVersion: resources.stuttgart-things.com/v1alpha1 kind: StoragePlatform mode: Pipeline pipeline: @@ -20,8 +20,34 @@ spec: kind: GoTemplate source: Inline inline: - template: | # pragma: allowlist secret + template: | {{- $spec := .observed.composite.resource.spec -}} + {{- $openebs := $spec.openebs -}} + + {{- $scope := $spec.targetCluster.scope | default "Namespaced" -}} + {{- $pcKind := "ProviderConfig" -}} + {{- if eq $scope "Cluster" -}} + {{- $pcKind = "ClusterProviderConfig" -}} + {{- end -}} + + {{- if $openebs.namespace }} + --- + apiVersion: kubernetes.m.crossplane.io/v1alpha1 + kind: Object + metadata: + annotations: + {{ setResourceNameAnnotation "openebs-namespace" }} + spec: + providerConfigRef: + name: {{ $spec.targetCluster.name }} + kind: {{ $pcKind }} + forProvider: + manifest: + apiVersion: v1 + kind: Namespace + metadata: + name: {{ $openebs.namespace }} + {{- end }} --- apiVersion: helm.m.crossplane.io/v1beta1 @@ -29,42 +55,46 @@ spec: metadata: annotations: {{ setResourceNameAnnotation "openebs-release" }} - labels: - app.kubernetes.io/name: openebs - app.kubernetes.io/managed-by: crossplane - storage.platform.example.org/engine: openebs spec: providerConfigRef: - name: {{ $spec.providerConfigRef.name | default "helm-provider-cluster" }} - kind: ProviderConfig - + name: {{ $spec.targetCluster.name }} + kind: {{ $pcKind }} forProvider: - namespace: {{ $spec.openebs.namespace | default "openebs-system" }} - + namespace: {{ $openebs.namespace | default "openebs-system" }} chart: name: openebs - repository: https://openebs.github.io/openebs - version: {{ $spec.openebs.version | default "4.2.0" }} - + repository: {{ $openebs.chartRepository | default "https://openebs.github.io/openebs" }} + version: {{ $openebs.version | default "4.2.0" }} values: openebs-crds: csi: volumeSnapshots: - enabled: {{ $spec.openebs.features.volumeSnapshots | default false }} + enabled: {{ $openebs.features.volumeSnapshots | default false }} mayastor: csi: node: initContainers: - enabled: {{ $spec.openebs.features.csiNodeInitContainers | default false }} + enabled: {{ $openebs.features.csiNodeInitContainers | default false }} engines: local: lvm: - enabled: {{ $spec.openebs.engines.local.lvm | default false }} + enabled: {{ $openebs.engines.local.lvm | default false }} zfs: - enabled: {{ $spec.openebs.engines.local.zfs | default false }} + enabled: {{ $openebs.engines.local.zfs | default false }} replicated: mayastor: - enabled: {{ $spec.openebs.engines.replicated.mayastor | default false }} + enabled: {{ $openebs.engines.replicated.mayastor | default false }} + + --- + apiVersion: resources.stuttgart-things.com/v1alpha1 + kind: StoragePlatform + status: + installed: true + observedVersion: {{ $openebs.version | default "4.2.0" }} + + - step: automatically-detect-ready-composed-resources + functionRef: + name: function-auto-ready diff --git a/configurations/infra/storage-platform/examples/functions.yaml b/configurations/infra/storage-platform/examples/functions.yaml index 3575509..9f82445 100644 --- a/configurations/infra/storage-platform/examples/functions.yaml +++ b/configurations/infra/storage-platform/examples/functions.yaml @@ -5,3 +5,10 @@ metadata: name: function-go-templating spec: package: xpkg.crossplane.io/crossplane-contrib/function-go-templating:v0.11.3 +--- +apiVersion: pkg.crossplane.io/v1beta1 +kind: Function +metadata: + name: function-auto-ready +spec: + package: xpkg.crossplane.io/crossplane-contrib/function-auto-ready:v0.6.0 diff --git a/configurations/infra/storage-platform/examples/nfs.yaml b/configurations/infra/storage-platform/examples/nfs.yaml index 3cf1f74..e767e25 100644 --- a/configurations/infra/storage-platform/examples/nfs.yaml +++ b/configurations/infra/storage-platform/examples/nfs.yaml @@ -1,16 +1,16 @@ --- -apiVersion: storage.platform.example.org/v1alpha1 +apiVersion: resources.stuttgart-things.com/v1alpha1 kind: StoragePlatform metadata: name: nfs-storage spec: engine: type: nfs - providerConfigRef: - name: helm-provider-prod - kubernetesProviderConfigRef: - name: kubernetes-provider-prod + targetCluster: + name: in-cluster + scope: Cluster nfs: + namespace: kube-system serverFQDN: nfs.example.com sharePath: /exports/k8s storageClass: nfs-client diff --git a/configurations/infra/storage-platform/examples/openebs.yaml b/configurations/infra/storage-platform/examples/openebs.yaml index d3b390e..315967f 100644 --- a/configurations/infra/storage-platform/examples/openebs.yaml +++ b/configurations/infra/storage-platform/examples/openebs.yaml @@ -1,13 +1,14 @@ --- -apiVersion: storage.platform.example.org/v1alpha1 +apiVersion: resources.stuttgart-things.com/v1alpha1 kind: StoragePlatform metadata: name: openebs-local spec: engine: type: openebs - providerConfigRef: + targetCluster: name: in-cluster + scope: Cluster openebs: namespace: openebs-system version: "4.2.0"