diff --git a/Makefile b/Makefile index 44a6139090..29186093df 100644 --- a/Makefile +++ b/Makefile @@ -62,6 +62,10 @@ gen-release-csv: operator-sdk manifests kustomize @echo "Generating unified CSV from sourced component-level operators" hack/generate-unified-csv.sh +gen-rook-csv: + @echo "Generating rook CSV" + hack/generate-rook-csv.sh + gen-latest-deploy-yaml: @echo "Generating latest deployment yaml file" hack/gen-deployment-yaml.sh diff --git a/hack/generate-rook-csv.sh b/hack/generate-rook-csv.sh new file mode 100644 index 0000000000..f2cbc9ee33 --- /dev/null +++ b/hack/generate-rook-csv.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash +set -e + +############# +# VARIABLES # +############# + +operator_sdk="${OPERATOR_SDK:-operator-sdk}" +yq="${YQv3:-yq}" +PLATFORM=$(go env GOARCH) + +YQ_CMD_DELETE=("$yq" delete -i) +YQ_CMD_MERGE_OVERWRITE=("$yq" merge --inplace --overwrite --prettyPrint) +YQ_CMD_MERGE=("$yq" merge --arrays=append --inplace) +YQ_CMD_WRITE=("$yq" write --inplace -P) +CSV_FILE_NAME="deploy/csv-templates/crds/rook/manifests/rook-ceph.clusterserviceversion.yaml" +CEPH_EXTERNAL_SCRIPT_FILE="https://raw.githubusercontent.com/rook/rook/master/deploy/examples/create-external-cluster-resources.py" +wget --no-verbose $CEPH_EXTERNAL_SCRIPT_FILE +ASSEMBLE_FILE_COMMON="https://raw.githubusercontent.com/rook/rook/master/deploy/olm/assemble/metadata-common.yaml" +ASSEMBLE_FILE_OCP="https://raw.githubusercontent.com/rook/rook/master/deploy/olm/assemble/metadata-ocp.yaml" +############# +# FUNCTIONS # +############# + +function generate_csv() { + # If you want to use specific branch, tags or commit has refer to this doc https://github.com/kubernetes-sigs/kustomize/blob/master/examples/remoteBuild.md#remote-directories + kubectl kustomize https://github.com/rook/rook//deploy/examples | "$operator_sdk" generate bundle --package="rook-ceph" --output-dir="deploy/csv-templates/crds/rook/" --extra-service-accounts=rook-ceph-system,rook-csi-rbd-provisioner-sa,rook-csi-rbd-plugin-sa,rook-csi-cephfs-provisioner-sa,rook-csi-nfs-provisioner-sa,rook-csi-nfs-plugin-sa,rook-csi-cephfs-plugin-sa,rook-ceph-system,rook-ceph-rgw,rook-ceph-purge-osd,rook-ceph-osd,rook-ceph-mgr,rook-ceph-cmd-reporter + + directory="deploy/csv-templates/crds/rook/manifests" + filename=$(basename "$CSV_FILE_NAME") + + # Below line removes the ObjectBucket from owned CRD section and converts yaml to json file + yq read --prettyPrint --tojson "$CSV_FILE_NAME" | jq 'del(.spec.customresourcedefinitions.owned[] | select(.kind | test("ObjectBucket.*")))' >"$directory"/temp.json + # Belo lines convert the json to yaml + yq read --prettyPrint "$directory"/temp.json >"$CSV_FILE_NAME" + # Below lines remove the extra json file + rm -f "$directory"/temp.json + + for file in "$directory"/*; do + if [ -f "$file" ]; then + filename=$(basename "$file") + # We want to remove the description from rook-crd files only + if [[ "$filename" == "ceph.rook.io"* ]]; then + # Below lines converts the file to json format and then remove the description field from the file. + yq read --prettyPrint --tojson "$file" | jq 'walk(if type == "object" then with_entries(select(.key != "description")) else . end)' >"$directory"/temp.json + # Belo lines convert the json to yaml + yq read --prettyPrint "$directory"/temp.json >"$directory"/"$filename" + # Below lines remove the extra json file + rm -f "$directory/temp.json" + fi + fi + done + + # cleanup to get the expected state before merging the real data from assembles + "${YQ_CMD_DELETE[@]}" "$CSV_FILE_NAME" 'spec.installModes[*]' + "${YQ_CMD_DELETE[@]}" "$CSV_FILE_NAME" 'spec.keywords[0]' + "${YQ_CMD_DELETE[@]}" "$CSV_FILE_NAME" 'spec.maintainers[0]' + + "${YQ_CMD_MERGE_OVERWRITE[@]}" "$CSV_FILE_NAME" <(curl -sL $ASSEMBLE_FILE_COMMON) + "${YQ_CMD_WRITE[@]}" "$CSV_FILE_NAME" metadata.annotations.externalClusterScript "$(base64