Skip to content

Commit 84b884c

Browse files
camilamacedo86ci-robot
authored andcommitted
UPSTREAM: <carry>: Add Openshift's catalogd manifests
- Move to openshift/catalogd the specific manifest under: https://github.com/openshift/operator-framework-catalogd/tree/main/openshift - Add call to generate catalogd manifest to 'make manifest'. Make verify test is now done for catalogd and operator-controller Openshift's manifests
1 parent eb0ff78 commit 84b884c

File tree

43 files changed

+1261
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1261
-0
lines changed

openshift/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ verify: ## Run downstream-specific verify
1616
.PHONY: manifests
1717
manifests: $(KUSTOMIZE) $(YQ)
1818
$(DIR)/operator-controller/generate-manifests.sh
19+
$(DIR)/catalogd/generate-manifests.sh
1920

2021
.PHONY: verify-manifests
2122
verify-manifests: manifests
@@ -35,3 +36,8 @@ test-e2e: ## Run the e2e tests.
3536
$(DIR)/operator-controller/build-test-registry.sh $(E2E_REGISTRY_NAMESPACE) $(E2E_REGISTRY_NAME) $(E2E_REGISTRY_IMAGE)
3637
cd $(DIR)/../; \
3738
go test $(DOWNSTREAM_E2E_FLAGS) ./test/e2e/...;
39+
# Run e2e tests for catalogd
40+
# TODO: Add build of the testdata/test-catalog.Dockerfile to openshift/release
41+
# See that catalogd e2e tests uses testdata/test-catalog.Dockerfile
42+
# More info: https://github.com/openshift/release/blob/master/ci-operator/config/openshift/operator-framework-catalogd/openshift-operator-framework-catalogd-main.yaml#L26-L29
43+
#$(MAKE) test-e2e -C $(DIR)/../catalogd/

openshift/catalogd.Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.23-openshift-4.19 AS builder
2+
WORKDIR /build
3+
COPY . .
4+
RUN make go-build-local
5+
6+
FROM registry.ci.openshift.org/ocp/4.19:base-rhel9
7+
USER 1001
8+
COPY --from=builder /build/bin/catalogd /catalogd
9+
COPY openshift/catalogd/manifests /openshift/manifests
10+
11+
LABEL io.k8s.display-name="OpenShift Operator Lifecycle Manager Catalog Controller" \
12+
io.k8s.description="This is a component of OpenShift Container Platform that provides operator catalog support."

openshift/catalogd/dependencies.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//go:build tools
2+
// +build tools
3+
4+
package catalogd
5+
6+
import _ "github.com/openshift/build-machinery-go"
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
##################################################
8+
# Modify these as needed
9+
##################################################
10+
11+
# This is the namespace where all namespace-scoped resources live
12+
NAMESPACE=openshift-catalogd
13+
14+
# This is a mapping of deployment container names to image placeholder values. For example, given a deployment with
15+
# 2 containers named kube-rbac-proxy and manager, their images will be set to ${KUBE_RBAC_PROXY_IMAGE} and
16+
# ${CATALOGD_IMAGE}, respectively. The cluster-olm-operator will replace these placeholders will real image values.
17+
declare -A IMAGE_MAPPINGS
18+
# shellcheck disable=SC2016
19+
IMAGE_MAPPINGS[kube-rbac-proxy]='${KUBE_RBAC_PROXY_IMAGE}'
20+
# shellcheck disable=SC2016
21+
IMAGE_MAPPINGS[manager]='${CATALOGD_IMAGE}'
22+
23+
# This is a mapping of catalogd flag names to values. For example, given a deployment with a container
24+
# named "manager" and arguments:
25+
# args:
26+
# - --flagname=one
27+
# and an entry to the FLAG_MAPPINGS of FLAG_MAPPINGS[flagname]='two', the argument will be updated to:
28+
# args:
29+
# - --flagname=two
30+
#
31+
# If the flag doesn't already exist - it will be appended to the list.
32+
declare -A FLAG_MAPPINGS
33+
# shellcheck disable=SC2016
34+
FLAG_MAPPINGS[external-address]="catalogd-service.${NAMESPACE}.svc"
35+
FLAG_MAPPINGS[global-pull-secret]="openshift-config/pull-secret"
36+
37+
##################################################
38+
# You shouldn't need to change anything below here
39+
##################################################
40+
41+
# Know where the repo root is so we can reference things relative to it
42+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
43+
44+
# Source bingo so we can use kustomize and yq
45+
. "${REPO_ROOT}/openshift/.bingo/variables.env"
46+
47+
# We're going to do file manipulation, so let's work in a temp dir
48+
TMP_ROOT="$(mktemp -p . -d 2>/dev/null || mktemp -d ./tmpdir.XXXXXXX)"
49+
# Make sure to delete the temp dir when we exit
50+
trap 'rm -rf $TMP_ROOT' EXIT
51+
52+
# Copy all kustomize files into a temp dir
53+
cp -a "${REPO_ROOT}/catalogd/config/" "${TMP_ROOT}/config/"
54+
55+
mkdir -p "${TMP_ROOT}/openshift/catalogd/"
56+
cp -a "${REPO_ROOT}/openshift/catalogd/kustomize" "${TMP_ROOT}/openshift/catalogd/kustomize"
57+
58+
# Override OPENSHIFT-NAMESPACE to ${NAMESPACE}
59+
find "${TMP_ROOT}" -name "*.yaml" -exec sed -i'.bak' "s/OPENSHIFT-NAMESPACE/${NAMESPACE}/g" {} \;
60+
find "${TMP_ROOT}" -name "*.bak" -exec rm {} \;
61+
62+
# Create a temp dir for manifests
63+
TMP_MANIFEST_DIR="${TMP_ROOT}/manifests"
64+
mkdir -p "$TMP_MANIFEST_DIR"
65+
66+
# Run kustomize, which emits a single yaml file
67+
TMP_KUSTOMIZE_OUTPUT="${TMP_MANIFEST_DIR}/temp.yaml"
68+
$KUSTOMIZE build "${TMP_ROOT}/openshift/catalogd/kustomize/overlays/openshift" -o "$TMP_KUSTOMIZE_OUTPUT"
69+
70+
for container_name in "${!IMAGE_MAPPINGS[@]}"; do
71+
placeholder="${IMAGE_MAPPINGS[$container_name]}"
72+
$YQ -i "(select(.kind == \"Deployment\")|.spec.template.spec.containers[]|select(.name==\"$container_name\")|.image) = \"$placeholder\"" "$TMP_KUSTOMIZE_OUTPUT"
73+
$YQ -i 'select(.kind == "Deployment").spec.template.metadata.annotations += {"target.workload.openshift.io/management": "{\"effect\": \"PreferredDuringScheduling\"}"}' "$TMP_KUSTOMIZE_OUTPUT"
74+
$YQ -i 'select(.kind == "Deployment").spec.template.metadata.annotations += {"openshift.io/required-scc": "privileged"}' "$TMP_KUSTOMIZE_OUTPUT"
75+
$YQ -i 'select(.kind == "Deployment").spec.template.spec += {"priorityClassName": "system-cluster-critical"}' "$TMP_KUSTOMIZE_OUTPUT"
76+
$YQ -i 'select(.kind == "Namespace").metadata.annotations += {"workload.openshift.io/allowed": "management"}' "$TMP_KUSTOMIZE_OUTPUT"
77+
done
78+
79+
# Loop through any flag updates that need to be made to the manager container
80+
for flag_name in "${!FLAG_MAPPINGS[@]}"; do
81+
flagval="${FLAG_MAPPINGS[$flag_name]}"
82+
83+
# First, update the flag if it exists
84+
$YQ -i "(select(.kind == \"Deployment\") | .spec.template.spec.containers[] | select(.name == \"manager\") | .args[] | select(. | contains(\"--$flag_name=\")) | .) = \"--$flag_name=$flagval\"" "$TMP_KUSTOMIZE_OUTPUT"
85+
86+
# Then, append the flag if it doesn't exist
87+
$YQ -i "(select(.kind == \"Deployment\") | .spec.template.spec.containers[] | select(.name == \"manager\") | .args) |= (select(.[] | contains(\"--$flag_name=\")) | .) // . + [\"--$flag_name=$flagval\"]" "$TMP_KUSTOMIZE_OUTPUT"
88+
done
89+
90+
# Use yq to split the single yaml file into 1 per document.
91+
# Naming convention: $index-$kind-$namespace-$name. If $namespace is empty, just use the empty string.
92+
(
93+
cd "$TMP_MANIFEST_DIR"
94+
95+
# shellcheck disable=SC2016
96+
${YQ} -s '$index +"-"+ (.kind|downcase) +"-"+ (.metadata.namespace // "") +"-"+ .metadata.name' temp.yaml
97+
)
98+
99+
# Delete the single yaml file
100+
rm "$TMP_KUSTOMIZE_OUTPUT"
101+
102+
# Delete and recreate the actual manifests directory
103+
MANIFEST_DIR="${REPO_ROOT}/openshift/catalogd/manifests"
104+
rm -rf "${MANIFEST_DIR}"
105+
mkdir -p "${MANIFEST_DIR}"
106+
107+
# Copy everything we just generated and split into the actual manifests directory
108+
cp "$TMP_MANIFEST_DIR"/* "$MANIFEST_DIR"/
109+
110+
# Update file names to be in the format nn-$kind-$namespace-$name
111+
(
112+
cd "$MANIFEST_DIR"
113+
114+
for f in *; do
115+
# Get the numeric prefix from the filename
116+
index=$(echo "$f" | cut -d '-' -f 1)
117+
# Keep track of the full file name without the leading number and dash
118+
name_without_index=${f#$index-}
119+
# Fix the double dash in cluster-scoped names
120+
name_without_index=${name_without_index//--/-}
121+
# Reformat the name so the leading number is always padded to 2 digits
122+
new_name=$(printf "%02d" "$index")-$name_without_index
123+
# Some file names (namely CRDs) don't end in .yml - make them
124+
if ! [[ "$new_name" =~ yml$ ]]; then
125+
new_name="${new_name}".yml
126+
fi
127+
if [[ "$f" != "$new_name" ]]; then
128+
# Rename
129+
mv "$f" "${new_name}"
130+
fi
131+
done
132+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resources:
2+
- openshift-certified-operators.yaml
3+
- openshift-community-operators.yaml
4+
- openshift-redhat-marketplace.yaml
5+
- openshift-redhat-operators.yaml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: olm.operatorframework.io/v1
2+
kind: ClusterCatalog
3+
metadata:
4+
name: openshift-certified-operators
5+
spec:
6+
priority: -200
7+
source:
8+
type: Image
9+
image:
10+
pollIntervalMinutes: 10
11+
ref: registry.redhat.io/redhat/certified-operator-index:v4.18
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: olm.operatorframework.io/v1
2+
kind: ClusterCatalog
3+
metadata:
4+
name: openshift-community-operators
5+
spec:
6+
priority: -400
7+
source:
8+
type: Image
9+
image:
10+
pollIntervalMinutes: 10
11+
ref: registry.redhat.io/redhat/community-operator-index:v4.18
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: olm.operatorframework.io/v1
2+
kind: ClusterCatalog
3+
metadata:
4+
name: openshift-redhat-marketplace
5+
spec:
6+
priority: -300
7+
source:
8+
type: Image
9+
image:
10+
pollIntervalMinutes: 10
11+
ref: registry.redhat.io/redhat/redhat-marketplace-index:v4.18
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: olm.operatorframework.io/v1
2+
kind: ClusterCatalog
3+
metadata:
4+
name: openshift-redhat-operators
5+
spec:
6+
priority: -100
7+
source:
8+
type: Image
9+
image:
10+
pollIntervalMinutes: 10
11+
ref: registry.redhat.io/redhat/redhat-operator-index:v4.18
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resources:
2+
- olmv1-ns
3+
- openshift-config
4+
- catalogs

0 commit comments

Comments
 (0)