Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dprince committed Apr 29, 2022
0 parents commit f03257f
Show file tree
Hide file tree
Showing 12 changed files with 344 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

```

2 changes: 2 additions & 0 deletions crc/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- storage.yaml
150 changes: 150 additions & 0 deletions crc/storage.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions olm/catalogsource.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions olm/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resources:
- operatorgroup.yaml
- catalogsource.yaml
- subscription.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: bar
17 changes: 17 additions & 0 deletions olm/subscription.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions scripts/cleanup.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions scripts/create-pv.sh
Original file line number Diff line number Diff line change
@@ -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"
23 changes: 23 additions & 0 deletions scripts/gen-crc-pv-kustomize.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF_CAT
resources:
- ../../crc
patches:
- patch: |-
- op: replace
path: /spec/nodeAffinity/required/nodeSelectorTerms/0/matchExpressions/0/values/0
value: $NODE_NAME
target:
kind: PersistentVolume
EOF_CAT
54 changes: 54 additions & 0 deletions scripts/gen-olm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

OPERATOR_NAME=$1
IMAGE=$2
if [ -z "$OPERATOR_NAME" ]; then
echo "Please set OPERATOR_NAME as ARG1"; exit 1
fi
if [ -z "$IMAGE" ]; then
echo "Please set IMAGE as ARG2"; exit 1
fi

if [ ! -d out/$OPERATOR_NAME ]; then
mkdir -p out/$OPERATOR_NAME
fi

# can share this for all the operators, won't get re-applied if it already exists
cat > out/$OPERATOR_NAME/operatorgroup.yaml <<EOF_CAT
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: openstack
namespace: openstack
spec:
targetNamespaces:
- openstack
EOF_CAT

cat > out/$OPERATOR_NAME/catalogsource.yaml <<EOF_CAT
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: $OPERATOR_NAME-operator-index
namespace: openstack
spec:
image: $IMAGE
sourceType: grpc
EOF_CAT

cat > out/$OPERATOR_NAME/subscription.yaml <<EOF_CAT
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: $OPERATOR_NAME-operator
namespace: openstack
spec:
name: $OPERATOR_NAME-operator
channel: alpha
config:
env:
- name: WATCH_NAMESPACE
value: openstack
source: $OPERATOR_NAME-operator-index
sourceNamespace: openstack
EOF_CAT

0 comments on commit f03257f

Please sign in to comment.