Skip to content

Commit c071fea

Browse files
committed
UPSTREAM: <carry>: Use Helm charts for openshift manifests
Signed-off-by: Todd Short <[email protected]>
1 parent 6b9418d commit c071fea

File tree

13 files changed

+560
-4
lines changed

13 files changed

+560
-4
lines changed

openshift/.bingo/Variables.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ $(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
2929
@echo "(re)installing $(GOBIN)/golangci-lint-v2.1.6"
3030
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v2.1.6 "github.com/golangci/golangci-lint/v2/cmd/golangci-lint"
3131

32+
HELM := $(GOBIN)/helm-v3.18.4
33+
$(HELM): $(BINGO_DIR)/helm.mod
34+
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
35+
@echo "(re)installing $(GOBIN)/helm-v3.18.4"
36+
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=helm.mod -o=$(GOBIN)/helm-v3.18.4 "helm.sh/helm/v3/cmd/helm"
37+
3238
KUSTOMIZE := $(GOBIN)/kustomize-v5.0.1
3339
$(KUSTOMIZE): $(BINGO_DIR)/kustomize.mod
3440
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.

openshift/.bingo/helm.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT
2+
3+
go 1.24.3
4+
5+
require helm.sh/helm/v3 v3.18.4 // cmd/helm

openshift/.bingo/helm.sum

Lines changed: 303 additions & 0 deletions
Large diffs are not rendered by default.

openshift/.bingo/variables.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ GO_BINDATA="${GOBIN}/go-bindata-v3.1.2+incompatible"
1212

1313
GOLANGCI_LINT="${GOBIN}/golangci-lint-v2.1.6"
1414

15+
HELM="${GOBIN}/helm-v3.18.4"
16+
1517
KUSTOMIZE="${GOBIN}/kustomize-v5.0.1"
1618

1719
YQ="${GOBIN}/yq-v4.34.2"

openshift/Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ verify: ## Run downstream-specific verify
2424
git diff --exit-code
2525

2626
.PHONY: manifests
27-
manifests: $(KUSTOMIZE) $(YQ)
28-
$(DIR)/operator-controller/generate-manifests.sh
29-
$(DIR)/catalogd/generate-manifests.sh
27+
manifests: $(YQ) $(HELM)
28+
$(DIR)/helm/generate-manifests.sh
3029
# Make a single file of each manifest for comparison purposes
3130
cat $(DIR)/operator-controller/manifests/*.yml > $(DIR)/operator-controller/manifests.yaml
3231
cat $(DIR)/operator-controller/manifests-experimental/*.yml > $(DIR)/operator-controller/manifests-experimental.yaml
3332
cat $(DIR)/catalogd/manifests/*.yml > $(DIR)/catalogd/manifests.yaml
3433
cat $(DIR)/catalogd/manifests-experimental/*.yml > $(DIR)/catalogd/manifests-experimental.yaml
3534

36-
3735
.PHONY: verify-manifests
3836
verify-manifests: manifests
3937
git diff --exit-code

openshift/catalogd.Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ COPY --from=builder /build/bin/catalogd /catalogd
1212
COPY openshift/catalogd/cp-manifests /cp-manifests
1313
COPY openshift/catalogd/manifests /openshift/manifests
1414
COPY openshift/catalogd/manifests-experimental /openshift/manifests-experimental
15+
COPY helm/olmv1 /openshift/helm/olmv1
16+
COPY openshift/helm/experimental.yaml /openshift/helm
17+
COPY openshift/helm/catalogd.yaml /openshift/helm/openshift.yaml
1518

1619
LABEL io.k8s.display-name="OpenShift Operator Lifecycle Manager Catalog Controller" \
1720
io.k8s.description="This is a component of OpenShift Container Platform that provides operator catalog support."

openshift/catalogd/cp-manifests

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ if [ -d /openshift/manifests-experimental ]; then
1717
cp -a /openshift/manifests-experimental "${DEST}/experimental/catalogd"
1818
fi
1919

20+
if [ -d /openshift/helm ]; then
21+
mkdir -p "${DEST}/helm/catalogd"
22+
cp -a /openshift/helm "${DEST}/helm/catalogd"
23+
fi
24+

openshift/helm/catalogd.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Default values for OLMv1.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
5+
# List of components to include
6+
options:
7+
catalogd:
8+
enabled: true
9+
deployment:
10+
image: ${CATALOGD_IMAGE}
11+
operatorController:
12+
enabled: false
13+
openshift:
14+
enabled: true
15+
16+
# The set of namespaces
17+
namespaces:
18+
olmv1:
19+
name: openshift-catalogd
20+
21+
# Deployment values for catalogd
22+
deployments:
23+
templateSpec:
24+
priorityClassName: system-cluster-critical
25+
securityContext:
26+
seLinuxOptions:
27+
type: spc_t
28+
nodeSelector:
29+
node-role.kubernetes.io/master: ""
30+
tolerations:
31+
- effect: NoSchedule
32+
key: node-role.kubernetes.io/control-plane
33+
operator: Exists
34+
- effect: NoSchedule
35+
key: node-role.kubernetes.io/master
36+
operator: Exists
37+
- effect: NoExecute
38+
key: node.kubernetes.io/unreachable
39+
operator: Exists
40+
tolerationSeconds: 120
41+
- effect: NoExecute
42+
key: node.kubernetes.io/not-ready
43+
operator: Exists
44+
tolerationSeconds: 120

openshift/helm/experimental.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# experimental values for OLMv1.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
5+
# List of enabled experimental features for operator-controller
6+
# Use with {{- if has "FeatureGate" .Value.operatorControllerFeatures }}
7+
# to pull in resources or additions
8+
operatorControllerFeatures:
9+
- WebhookProviderOpenshiftServiceCA
10+
- SingleOwnNamespaceInstallSupport
11+
- PreflightPermissions
12+
13+
# Not yet supported
14+
# - HelmChartSupport
15+
# - BoxcutterRuntime
16+
17+
# List of enabled experimental features for catalogd
18+
# Use with {{- if has "FeatureGate" .Value.catalogdFeatures }}
19+
# to pull in resources or additions
20+
catalogdFeatures:
21+
- APIV1MetasHandler
22+
23+
# This can be one of: standard or experimental
24+
options:
25+
featureSet: experimental
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
##################################################
8+
# You shouldn't need to change anything below here
9+
##################################################
10+
11+
# Know where the repo root is so we can reference things relative to it
12+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
13+
14+
# Source bingo so we can use kustomize and yq
15+
. "${REPO_ROOT}/openshift/.bingo/variables.env"
16+
17+
# This function generates the manifests
18+
generate () {
19+
values=()
20+
OUTPUT_DIR=""
21+
local OPTIND
22+
while getopts "v:o:n:c:i:" arg; do
23+
case ${arg} in
24+
v)
25+
values+=(${OPTARG})
26+
;;
27+
o)
28+
OUTPUT_DIR=${OPTARG}
29+
;;
30+
*)
31+
echo "bad argument ${arg}"
32+
exit 1
33+
;;
34+
esac
35+
done
36+
37+
DOWNSTREAM="${REPO_ROOT}/openshift/helm"
38+
39+
VALUES=""
40+
for i in "${values[@]}"; do
41+
VALUES="${VALUES} --values ${DOWNSTREAM}/${i}"
42+
done
43+
44+
# We're going to do file manipulation, so let's work in a temp dir
45+
TMP_ROOT="$(mktemp -p . -d 2>/dev/null || mktemp -d ./tmpdir.XXXXXXX)"
46+
# Make sure to delete the temp dir when we exit
47+
trap 'rm -rf $TMP_ROOT' EXIT
48+
49+
# Copy upstream chart to temp
50+
cp -a "${REPO_ROOT}/helm" "${TMP_ROOT}/helm"
51+
52+
# Create a temp dir for manifests
53+
TMP_MANIFEST_DIR="${TMP_ROOT}/manifests"
54+
mkdir -p "$TMP_MANIFEST_DIR"
55+
56+
# Run helm template, which emits a single yaml file
57+
TMP_HELM_OUTPUT="${TMP_MANIFEST_DIR}/temp.yaml"
58+
${HELM} template olmv1 "${TMP_ROOT}/helm/olmv1" ${VALUES} > "${TMP_HELM_OUTPUT}"
59+
60+
# Use yq to split the single yaml file into 1 per document.
61+
# Naming convention: $index-$kind-$namespace-$name. If $namespace is empty, just use the empty string.
62+
(
63+
cd "$TMP_MANIFEST_DIR"
64+
65+
# shellcheck disable=SC2016
66+
${YQ} -s '$index +"-"+ (.kind|downcase) +"-"+ (.metadata.namespace // "") +"-"+ .metadata.name' temp.yaml
67+
)
68+
69+
# Delete the single yaml file
70+
rm "${TMP_HELM_OUTPUT}"
71+
72+
# Delete and recreate the actual manifests directory
73+
MANIFEST_DIR="${REPO_ROOT}/openshift/${OUTPUT_DIR}"
74+
rm -rf "${MANIFEST_DIR}"
75+
mkdir -p "${MANIFEST_DIR}"
76+
77+
# Copy everything we just generated and split into the actual manifests directory
78+
cp "$TMP_MANIFEST_DIR"/* "$MANIFEST_DIR"/
79+
80+
# Update file names to be in the format nn-$kind-$namespace-$name
81+
(
82+
cd "$MANIFEST_DIR"
83+
84+
for f in *; do
85+
# Get the numeric prefix from the filename
86+
index=$(echo "$f" | cut -d '-' -f 1)
87+
# Keep track of the full file name without the leading number and dash
88+
name_without_index=${f#$index-}
89+
# Fix the double dash in cluster-scoped names
90+
name_without_index=${name_without_index//--/-}
91+
# Reformat the name so the leading number is always padded to 2 digits
92+
new_name=$(printf "%02d" "$index")-$name_without_index
93+
# Some file names (namely CRDs) don't end in .yml - make them
94+
if ! [[ "$new_name" =~ yml$ ]]; then
95+
new_name="${new_name}".yml
96+
fi
97+
if [[ "$f" != "$new_name" ]]; then
98+
# Rename
99+
mv "$f" "${new_name}"
100+
fi
101+
done
102+
)
103+
rm -rf "$TMP_ROOT"
104+
}
105+
106+
#Generate the manifests
107+
generate -v operator-controller.yaml -o operator-controller/manifests
108+
generate -v operator-controller.yaml -v experimental.yaml -o operator-controller/manifests-experimental
109+
generate -v catalogd.yaml -o catalogd/manifests
110+
generate -v catalogd.yaml -v experimental.yaml -o catalogd/manifests-experimental

0 commit comments

Comments
 (0)