Skip to content

Commit 2092956

Browse files
Apply suggestions from code review
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 58dfeba commit 2092956

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

installers/olm/generate.sh

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Install
44
# brew install gawk coreutils
55
for command in gawk gcsplit; do
6-
if ! command -v $command &> /dev/null; then
7-
echo "Error: $command is not installed. Please install it: brew install $command" >&2
8-
exit 1
9-
fi
6+
if ! command -v $command &>/dev/null; then
7+
echo "Error: $command is not installed. Please install it: brew install $command" >&2
8+
exit 1
9+
fi
1010
done
1111

1212
set -eu
@@ -38,18 +38,18 @@ NS_RESOURCE_OPERATOR="../manager/namespace"
3838
CLUSTER_RESOURCE_OPERATOR="../manager/cluster"
3939
KUSTOMIZATION_FILE="../../config/bundle/kustomization.yaml"
4040

41-
if [ ${MODE} == "cluster" ]; then
41+
if [ "${MODE}" == "cluster" ]; then
4242
suffix="-cw"
4343
mode="Cluster"
4444
rulesLevel="ClusterPermissions"
4545
sed -i '' "s|$NS_RESOURCE_RBAC|$CLUSTER_RESOURCE_RBAC|g" "$KUSTOMIZATION_FILE"
4646
sed -i '' "s|$NS_RESOURCE_OPERATOR|$CLUSTER_RESOURCE_OPERATOR|g" "$KUSTOMIZATION_FILE"
47-
elif [ ${MODE} == "namespace" ]; then
47+
elif [ "${MODE}" == "namespace" ]; then
4848
suffix=""
4949
mode=""
5050
rulesLevel="permissions"
51-
sed -i '' "s|$CLUSTER_RESOURCE_RBAC|$NS_RESOURCE_RBAC|g" "$KUSTOMIZATION_FILE"
52-
sed -i '' "s|$CLUSTER_RESOURCE_OPERATOR|$NS_RESOURCE_OPERATOR|g" "$KUSTOMIZATION_FILE"
51+
sed -i '' "s|$CLUSTER_RESOURCE_RBAC|$NS_RESOURCE_RBAC|g" "$KUSTOMIZATION_FILE"
52+
sed -i '' "s|$CLUSTER_RESOURCE_OPERATOR|$NS_RESOURCE_OPERATOR|g" "$KUSTOMIZATION_FILE"
5353
else
5454
echo "Please add MODE variable. It could be either namespace or cluster"
5555
exit 1
@@ -77,19 +77,19 @@ kubectl kustomize "../../config/${DISTRIBUTION}" >operator_yamls.yaml
7777
export role="${mode}Role"
7878

7979
update_yaml_images() {
80-
local yaml_file="$1"
80+
local yaml_file="$1"
8181

82-
if [ ! -f "$yaml_file" ]; then
83-
echo "Error: File '$yaml_file' does not exist."
84-
return 1
85-
fi
82+
if [ ! -f "$yaml_file" ]; then
83+
echo "Error: File '$yaml_file' does not exist."
84+
return 1
85+
fi
8686

87-
local temp_file=$(mktemp)
87+
local temp_file=$(mktemp)
8888

89-
sed -E 's/(("image":|containerImage:|image:)[ ]*"?)([^"]+)("?)/\1docker.io\/\3\4/g' "$yaml_file" > "$temp_file"
90-
mv "$temp_file" "$yaml_file"
89+
sed -E 's/(("image":|containerImage:|image:)[ ]*"?)([^"]+)("?)/\1docker.io\/\3\4/g' "$yaml_file" >"$temp_file"
90+
mv "$temp_file" "$yaml_file"
9191

92-
echo "File '$yaml_file' updated successfully."
92+
echo "File '$yaml_file' updated successfully."
9393
}
9494

9595
yq eval '. | select(.kind == "CustomResourceDefinition")' operator_yamls.yaml >operator_crds.yaml
@@ -135,23 +135,23 @@ yq eval '.annotations["operators.operatorframework.io.bundle.channels.v1"] = env
135135
.annotations["com.redhat.openshift.versions"] = env(openshift_supported_versions)' \
136136
bundle.annotations.yaml >"${bundle_directory}/metadata/annotations.yaml"
137137

138-
if [ ${DISTRIBUTION} == 'community' ]; then
138+
if [ "${DISTRIBUTION}" == 'community' ]; then
139139
# community-operators
140140
yq eval --inplace '
141141
.annotations["operators.operatorframework.io.bundle.package.v1"] = "percona-server-mongodb-operator" |
142142
.annotations["org.opencontainers.image.authors"] = "info@percona.com" |
143143
.annotations["org.opencontainers.image.url"] = "https://percona.com" |
144144
.annotations["org.opencontainers.image.vendor"] = "Percona"' \
145-
"${bundle_directory}/metadata/annotations.yaml"
145+
"${bundle_directory}/metadata/annotations.yaml"
146146

147147
# certified-operators
148-
elif [ ${DISTRIBUTION} == 'redhat' ]; then
148+
elif [ "${DISTRIBUTION}" == 'redhat' ]; then
149149
yq eval --inplace '
150150
.annotations["operators.operatorframework.io.bundle.package.v1"] = "percona-server-mongodb-operator-certified" ' \
151151
"${bundle_directory}/metadata/annotations.yaml"
152152

153153
# redhat-marketplace
154-
elif [ ${DISTRIBUTION} == 'marketplace' ]; then
154+
elif [ "${DISTRIBUTION}" == 'marketplace' ]; then
155155
yq eval --inplace '
156156
.annotations["operators.operatorframework.io.bundle.package.v1"] = "percona-server-mongodb-operator-certified-rhmp" ' \
157157
"${bundle_directory}/metadata/annotations.yaml"
@@ -160,17 +160,17 @@ fi
160160
# Copy annotations into Dockerfile LABELs.
161161

162162
labels=$(yq eval -r '.annotations | to_entries | map("LABEL " + .key + "=" + (.value | tojson)) | join("\n")' \
163-
"${bundle_directory}/metadata/annotations.yaml")
163+
"${bundle_directory}/metadata/annotations.yaml")
164164

165165
labels="${labels}
166166
LABEL com.redhat.delivery.backport=true
167167
LABEL com.redhat.delivery.operator.bundle=true"
168168

169-
echo $labels
169+
echo "$labels"
170170

171171
LABELS="${labels}" envsubst <bundle.Dockerfile >"${bundle_directory}/Dockerfile"
172172

173-
awk '{gsub(/^[ \t]+/, " "); print}' "${bundle_directory}/Dockerfile" > "${bundle_directory}/Dockerfile.new" && mv "${bundle_directory}/Dockerfile.new" "${bundle_directory}/Dockerfile"
173+
awk '{gsub(/^[ \t]+/, " "); print}' "${bundle_directory}/Dockerfile" >"${bundle_directory}/Dockerfile.new" && mv "${bundle_directory}/Dockerfile.new" "${bundle_directory}/Dockerfile"
174174

175175
# Include CRDs as manifests.
176176
crd_names=$(yq eval -o=tsv '.metadata.name' ../../deploy/crd.yaml)
@@ -215,7 +215,6 @@ yq eval -i '[.]' operator_roles${suffix}.yaml && yq eval 'length == 1' operator_
215215
# Render bundle CSV and strip comments.
216216
csv_stem=$(yq -r '.projectName' "${project_directory}/PROJECT")
217217

218-
219218
cr_example=$(yq eval -o=json ../../deploy/cr.yaml)
220219
backup_example=$(yq eval -o=json ../../deploy/backup/backup.yaml)
221220
restore_example=$(yq eval -o=json ../../deploy/backup/restore.yaml)
@@ -259,7 +258,7 @@ elif [ ${DISTRIBUTION} == "redhat" ]; then
259258
.metadata.name = strenv(name_certified)' \
260259
"${bundle_directory}/manifests/${file_name}.clusterserviceversion.yaml"
261260

262-
elif [ ${DISTRIBUTION} == "marketplace" ]; then
261+
elif [ "${DISTRIBUTION}" == "marketplace" ]; then
263262
# Annotations needed when targeting Red Hat Marketplace
264263
export package_url="https://marketplace.redhat.com/en-us/operators/${file_name}"
265264
yq --inplace '
@@ -278,4 +277,4 @@ sed -i '' '/^$/d' "${bundle_directory}/manifests/${file_name}.clusterservicevers
278277

279278
if >/dev/null command -v tree; then tree -C "${bundle_directory}"; fi
280279

281-
yamllint -d '{extends: default, rules: {line-length: disable, indentation: disable}}' bundles/$DISTRIBUTION
280+
yamllint -d '{extends: default, rules: {line-length: disable, indentation: disable}}' bundles/"$DISTRIBUTION"

0 commit comments

Comments
 (0)