From f03257f41fa10b61988065aaa0034bde5b36857f Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 29 Apr 2022 08:10:21 -0400 Subject: [PATCH] Initial commit --- .gitignore | 1 + Makefile | 39 +++++++++ README.md | 29 ++++++ crc/kustomization.yaml | 2 + crc/storage.yaml | 150 ++++++++++++++++++++++++++++++++ olm/catalogsource.yaml | 8 ++ olm/kustomization.yaml | 7 ++ olm/subscription.yaml | 17 ++++ scripts/cleanup.sh | 7 ++ scripts/create-pv.sh | 7 ++ scripts/gen-crc-pv-kustomize.sh | 23 +++++ scripts/gen-olm.sh | 54 ++++++++++++ 12 files changed, 344 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 crc/kustomization.yaml create mode 100644 crc/storage.yaml create mode 100644 olm/catalogsource.yaml create mode 100644 olm/kustomization.yaml create mode 100644 olm/subscription.yaml create mode 100644 scripts/cleanup.sh create mode 100644 scripts/create-pv.sh create mode 100644 scripts/gen-crc-pv-kustomize.sh create mode 100644 scripts/gen-olm.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1fcb152 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5f9fcef --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +KEYSTONE_IMG=quay.io/openstack-k8s-operators/keystone-operator-index:latest +MARIADB_IMG=quay.io/openstack-k8s-operators/mariadb-operator-index:latest + +all: keystone mariadb + +crc_init: + bash scripts/create-pv.sh + bash scripts/gen-crc-pv-kustomize.sh + oc kustomize out/crc | oc apply -f - + +# KEYSTONE +out/keystone/subscription.yaml: + bash scripts/gen-olm.sh keystone ${KEYSTONE_IMG} + +.PHONY: keystone +keystone: out/keystone/subscription.yaml + oc apply -f out/keystone + +.PHONY: keystone_cleanup +keystone_cleanup: + oc delete -n openstack csv keystone-operator.v0.0.1 || true + oc delete -n openstack subscription keystone-operator || true + oc delete -n openstack catalogsource keystone-operator-index || true + rm -Rf out/keystone + +# MARIADB +out/mariadb/subscription.yaml: + bash scripts/gen-olm.sh mariadb ${MARIADB_IMG} + +.PHONY: mariadb +mariadb: out/mariadb/subscription.yaml + oc apply -f out/mariadb + +.PHONY: mariadb_cleanup +mariadb_cleanup: + oc delete -n openstack csv mariadb-operator.v0.0.1 || true + oc delete -n openstack subscription mariadb-operator || true + oc delete -n openstack catalogsource mariadb-operator-index || true + rm -Rf out/mariadb diff --git a/README.md b/README.md new file mode 100644 index 0000000..8be0642 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# k8s yaml generator/installer for Cloud Native OpenStack + +Scripts to automate Installing OpenStack in your *pre-installed* OpenShift environment. + +Aside from generating Yaml and running *oc* commands to apply them to your cluster nothing in this repo should modify the local machine, require sudo, or make any changes to the local environment. + +## Goals + +1) WIP: Support installing individual operators for fast testing iteration + +2) TODO: Support installing the combined Openstack umbrella operator + +### Example using your preinstalled CRC (Code Ready Containers) Environment +### Similar commands should work in any OCP environment though. +```bash +# set your CRC ENV variables and PATH for 'oc' +eval $(crc oc-env) + +# one time operation to initialize PVs within the CRC VM +make crc_init + +# Install MariaDB Operator using OLM (defaults to quay.io/openstack-k8s-operators) +make mariadb MARIADB_IMG=quay.io/openstack-k8s-operators/mariadb-operator-index:latest + +# Install Keystone Operator using OLM (defaults to quay.io/openstack-k8s-operators) +make keystone KEYSTONE_IMG=quay.io/openstack-k8s-operators/keystone-operator-index:latest + +``` + diff --git a/crc/kustomization.yaml b/crc/kustomization.yaml new file mode 100644 index 0000000..9a80610 --- /dev/null +++ b/crc/kustomization.yaml @@ -0,0 +1,2 @@ +resources: +- storage.yaml diff --git a/crc/storage.yaml b/crc/storage.yaml new file mode 100644 index 0000000..ac97013 --- /dev/null +++ b/crc/storage.yaml @@ -0,0 +1,150 @@ +kind: StorageClass +apiVersion: storage.k8s.io/v1 +metadata: + name: local-storage +provisioner: kubernetes.io/no-provisioner +volumeBindingMode: WaitForFirstConsumer +--- +kind: PersistentVolume +apiVersion: v1 +metadata: + name: local-storage001 +spec: + storageClassName: local-storage + capacity: + storage: 500M + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Delete + local: + path: "/mnt/openstack/pv001" + type: DirectoryOrCreate + volumeMode: Filesystem + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - server +--- +kind: PersistentVolume +apiVersion: v1 +metadata: + name: local-storage002 +spec: + storageClassName: local-storage + capacity: + storage: 500M + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Delete + local: + path: "/mnt/openstack/pv002" + type: DirectoryOrCreate + volumeMode: Filesystem + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - server +--- +kind: PersistentVolume +apiVersion: v1 +metadata: + name: local-storage003 +spec: + storageClassName: local-storage + capacity: + storage: 500M + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Delete + local: + path: "/mnt/openstack/pv003" + type: DirectoryOrCreate + volumeMode: Filesystem + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - server +--- +kind: PersistentVolume +apiVersion: v1 +metadata: + name: local-storage004 +spec: + storageClassName: local-storage + capacity: + storage: 500M + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Delete + local: + path: "/mnt/openstack/pv004" + type: DirectoryOrCreate + volumeMode: Filesystem + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - server +--- +kind: PersistentVolume +apiVersion: v1 +metadata: + name: local-storage005 +spec: + storageClassName: local-storage + capacity: + storage: 500M + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Delete + local: + path: "/mnt/openstack/pv005" + type: DirectoryOrCreate + volumeMode: Filesystem + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - server +--- +kind: PersistentVolume +apiVersion: v1 +metadata: + name: local-storage006 +spec: + storageClassName: local-storage + capacity: + storage: 500M + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Delete + local: + path: "/mnt/openstack/pv006" + type: DirectoryOrCreate + volumeMode: Filesystem + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - server diff --git a/olm/catalogsource.yaml b/olm/catalogsource.yaml new file mode 100644 index 0000000..4b88c09 --- /dev/null +++ b/olm/catalogsource.yaml @@ -0,0 +1,8 @@ +apiVersion: operators.coreos.com/v1alpha1 +kind: CatalogSource +metadata: + name: osp-director-operator-index + namespace: openstack +spec: + sourceType: grpc + image: operator-index:latest diff --git a/olm/kustomization.yaml b/olm/kustomization.yaml new file mode 100644 index 0000000..92a04df --- /dev/null +++ b/olm/kustomization.yaml @@ -0,0 +1,7 @@ +resources: +- operatorgroup.yaml +- catalogsource.yaml +- subscription.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: bar diff --git a/olm/subscription.yaml b/olm/subscription.yaml new file mode 100644 index 0000000..630cd73 --- /dev/null +++ b/olm/subscription.yaml @@ -0,0 +1,17 @@ +apiVersion: operators.coreos.com/v1alpha1 +kind: Subscription +metadata: + name: operator-name + namespace: openstack +spec: + config: + env: + - name: WATCH_NAMESPACE + value: openstack + source: operator-index + sourceNamespace: openstack + name: operator-name + # to install a specific version + # installPlanApproval: Manual + # startingCSV: operator.vX.X.X + channel: alpha diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh new file mode 100644 index 0000000..f01244e --- /dev/null +++ b/scripts/cleanup.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +oc delete -n default pv local-storage001 +oc delete -n default pv local-storage002 +oc delete -n default pv local-storage003 +oc delete -n default pv local-storage004 +oc delete -n default storageclass local-storage diff --git a/scripts/create-pv.sh b/scripts/create-pv.sh new file mode 100644 index 0000000..44c7960 --- /dev/null +++ b/scripts/create-pv.sh @@ -0,0 +1,7 @@ +#!/bin/bash +NODE_NAME=$(oc get node -o name) +if [ -z "$NODE_NAME" ]; then + echo "Unable to determine node name with 'oc' command." + exit 1 +fi +oc debug $NODE_NAME -T -- chroot /host /usr/bin/bash -c "for i in {0..5}; do echo \"creating dir /mnt/openstack/pv00\$i\"; mkdir -p /mnt/openstack/pv00\$i; done" diff --git a/scripts/gen-crc-pv-kustomize.sh b/scripts/gen-crc-pv-kustomize.sh new file mode 100644 index 0000000..2f1e13c --- /dev/null +++ b/scripts/gen-crc-pv-kustomize.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +if [ ! -d out ]; then + mkdir -p out/crc +fi + +NODE_NAME=$(oc get node -o name) +if [ -z "$NODE_NAME" ]; then + echo "Unable to determine node name with 'oc' command." + exit 1 +fi + +cat > out/crc/kustomization.yaml < out/$OPERATOR_NAME/operatorgroup.yaml < out/$OPERATOR_NAME/catalogsource.yaml < out/$OPERATOR_NAME/subscription.yaml <