Skip to content

Commit b7fc2f3

Browse files
tmshortci-robot
authored andcommitted
UPSTREAM: <carry>: Add support for experimental manifests
Update the openshift kustomize configuration for both operator-controller and catalogd. Update the manifest generation scripts to put the core generation code into a function (ignore-whitespace will help with the review), so that it can be called twice; once for standard, and once for experimental. Move around some of the kustomization directives to * Create a patch kustomization (Component) file and move the patch directives from olmv1-ns there. This allows it to be referenced from a different directory. * Add a kustomization file for tusted-ca. This allows it to be referenced from a different directory. * Move the setting of the namePrefix for operator-controller; this makes the generation compatible with upstream feature components. * Define experimental kustomization files that reference existing components. * Reference the correct CRDs (standard or experimental). * Add references to upstream feature components into the experimental manifests. This *will* add `--feature-gates` options from the upstream feature components to the experimental manifests. The cluster-olm-operator will strip those arguments from the deployments before adding the enabled feature gates. Update the Dockerfiles to include the experimental manifests and a copy script (`cp-manifests`) into the image containers. The complexity of having multiple sets of manifests mean that the simple initContainer copy mechanism found in cluster-olm-operator is no longer sufficient. This attempts to keep backwards compatibility with older versions of cluster-olm-operator, specifically by keeping the original (standard) manifests in the original location, and adding the experimental manifests in a new directory. The new `cp-manifests` script is used by newer versions of cluster-olm-operator. Signed-off-by: Todd Short <[email protected]>
1 parent fc94ac8 commit b7fc2f3

File tree

68 files changed

+2705
-236
lines changed

Some content is hidden

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

68 files changed

+2705
-236
lines changed

openshift/catalogd.Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ RUN make go-build-local
66
FROM registry.ci.openshift.org/ocp/4.20:base-rhel9
77
USER 1001
88
COPY --from=builder /build/bin/catalogd /catalogd
9+
COPY openshift/catalogd/cp-manifests /cp-manifests
910
COPY openshift/catalogd/manifests /openshift/manifests
11+
COPY openshift/catalogd/manifests-experimental /openshift/manifests-experimental
1012

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

openshift/catalogd/cp-manifests

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
if [ -z "${1}" ]; then
4+
echo "No destination specified"
5+
exit 1
6+
fi
7+
8+
DEST=${1}
9+
10+
if [ -d /openshift/manifests ]; then
11+
mkdir -p "${DEST}/standard/catalogd"
12+
cp -a /openshift/manifests "${DEST}/standard/catalogd"
13+
fi
14+
15+
if [ -d /openshift/manifests-experimental ]; then
16+
mkdir -p "${DEST}/experimental/catalogd"
17+
cp -a /openshift/manifests "${DEST}/experimental/catalogd"
18+
fi
19+

openshift/catalogd/generate-manifests.sh

Lines changed: 95 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -44,88 +44,98 @@ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
4444
# Source bingo so we can use kustomize and yq
4545
. "${REPO_ROOT}/openshift/.bingo/variables.env"
4646

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}/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-
done
77-
78-
# Loop through any flag updates that need to be made to the manager container
79-
for flag_name in "${!FLAG_MAPPINGS[@]}"; do
80-
flagval="${FLAG_MAPPINGS[$flag_name]}"
81-
82-
# First, update the flag if it exists
83-
$YQ -i "(select(.kind == \"Deployment\") | .spec.template.spec.containers[] | select(.name == \"manager\") | .args[] | select(. | contains(\"--$flag_name=\")) | .) = \"--$flag_name=$flagval\"" "$TMP_KUSTOMIZE_OUTPUT"
84-
85-
# Then, append the flag if it doesn't exist
86-
$YQ -i "(select(.kind == \"Deployment\") | .spec.template.spec.containers[] | select(.name == \"manager\") | .args) |= (select(.[] | contains(\"--$flag_name=\")) | .) // . + [\"--$flag_name=$flagval\"]" "$TMP_KUSTOMIZE_OUTPUT"
87-
done
88-
89-
# Use yq to split the single yaml file into 1 per document.
90-
# Naming convention: $index-$kind-$namespace-$name. If $namespace is empty, just use the empty string.
91-
(
92-
cd "$TMP_MANIFEST_DIR"
93-
94-
# shellcheck disable=SC2016
95-
${YQ} -s '$index +"-"+ (.kind|downcase) +"-"+ (.metadata.namespace // "") +"-"+ .metadata.name' temp.yaml
96-
)
97-
98-
# Delete the single yaml file
99-
rm "$TMP_KUSTOMIZE_OUTPUT"
100-
101-
# Delete and recreate the actual manifests directory
102-
MANIFEST_DIR="${REPO_ROOT}/openshift/catalogd/manifests"
103-
rm -rf "${MANIFEST_DIR}"
104-
mkdir -p "${MANIFEST_DIR}"
105-
106-
# Copy everything we just generated and split into the actual manifests directory
107-
cp "$TMP_MANIFEST_DIR"/* "$MANIFEST_DIR"/
108-
109-
# Update file names to be in the format nn-$kind-$namespace-$name
110-
(
111-
cd "$MANIFEST_DIR"
112-
113-
for f in *; do
114-
# Get the numeric prefix from the filename
115-
index=$(echo "$f" | cut -d '-' -f 1)
116-
# Keep track of the full file name without the leading number and dash
117-
name_without_index=${f#$index-}
118-
# Fix the double dash in cluster-scoped names
119-
name_without_index=${name_without_index//--/-}
120-
# Reformat the name so the leading number is always padded to 2 digits
121-
new_name=$(printf "%02d" "$index")-$name_without_index
122-
# Some file names (namely CRDs) don't end in .yml - make them
123-
if ! [[ "$new_name" =~ yml$ ]]; then
124-
new_name="${new_name}".yml
125-
fi
126-
if [[ "$f" != "$new_name" ]]; then
127-
# Rename
128-
mv "$f" "${new_name}"
129-
fi
130-
done
131-
)
47+
# This function generates the manifests
48+
generate () {
49+
INPUT_DIR=${1}
50+
OUTPUT_DIR=${2}
51+
# We're going to do file manipulation, so let's work in a temp dir
52+
TMP_ROOT="$(mktemp -p . -d 2>/dev/null || mktemp -d ./tmpdir.XXXXXXX)"
53+
# Make sure to delete the temp dir when we exit
54+
trap 'rm -rf $TMP_ROOT' EXIT
55+
56+
# Copy all kustomize files into a temp dir
57+
cp -a "${REPO_ROOT}/config/" "${TMP_ROOT}/config/"
58+
59+
mkdir -p "${TMP_ROOT}/openshift/catalogd/"
60+
cp -a "${REPO_ROOT}/openshift/catalogd/kustomize" "${TMP_ROOT}/openshift/catalogd/kustomize"
61+
62+
# Override OPENSHIFT-NAMESPACE to ${NAMESPACE}
63+
find "${TMP_ROOT}" -name "*.yaml" -exec sed -i'.bak' "s/OPENSHIFT-NAMESPACE/${NAMESPACE}/g" {} \;
64+
find "${TMP_ROOT}" -name "*.bak" -exec rm {} \;
65+
66+
# Create a temp dir for manifests
67+
TMP_MANIFEST_DIR="${TMP_ROOT}/manifests"
68+
mkdir -p "$TMP_MANIFEST_DIR"
69+
70+
# Run kustomize, which emits a single yaml file
71+
TMP_KUSTOMIZE_OUTPUT="${TMP_MANIFEST_DIR}/temp.yaml"
72+
$KUSTOMIZE build "${TMP_ROOT}/openshift/catalogd/kustomize/overlays/${INPUT_DIR}" -o "$TMP_KUSTOMIZE_OUTPUT"
73+
74+
for container_name in "${!IMAGE_MAPPINGS[@]}"; do
75+
placeholder="${IMAGE_MAPPINGS[$container_name]}"
76+
$YQ -i "(select(.kind == \"Deployment\")|.spec.template.spec.containers[]|select(.name==\"$container_name\")|.image) = \"$placeholder\"" "$TMP_KUSTOMIZE_OUTPUT"
77+
$YQ -i 'select(.kind == "Deployment").spec.template.metadata.annotations += {"target.workload.openshift.io/management": "{\"effect\": \"PreferredDuringScheduling\"}"}' "$TMP_KUSTOMIZE_OUTPUT"
78+
$YQ -i 'select(.kind == "Deployment").spec.template.metadata.annotations += {"openshift.io/required-scc": "privileged"}' "$TMP_KUSTOMIZE_OUTPUT"
79+
$YQ -i 'select(.kind == "Deployment").spec.template.spec += {"priorityClassName": "system-cluster-critical"}' "$TMP_KUSTOMIZE_OUTPUT"
80+
done
81+
82+
# Loop through any flag updates that need to be made to the manager container
83+
for flag_name in "${!FLAG_MAPPINGS[@]}"; do
84+
flagval="${FLAG_MAPPINGS[$flag_name]}"
85+
86+
# First, update the flag if it exists
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+
89+
# Then, append the flag if it doesn't exist
90+
$YQ -i "(select(.kind == \"Deployment\") | .spec.template.spec.containers[] | select(.name == \"manager\") | .args) |= (select(.[] | contains(\"--$flag_name=\")) | .) // . + [\"--$flag_name=$flagval\"]" "$TMP_KUSTOMIZE_OUTPUT"
91+
done
92+
93+
# Use yq to split the single yaml file into 1 per document.
94+
# Naming convention: $index-$kind-$namespace-$name. If $namespace is empty, just use the empty string.
95+
(
96+
cd "$TMP_MANIFEST_DIR"
97+
98+
# shellcheck disable=SC2016
99+
${YQ} -s '$index +"-"+ (.kind|downcase) +"-"+ (.metadata.namespace // "") +"-"+ .metadata.name' temp.yaml
100+
)
101+
102+
# Delete the single yaml file
103+
rm "$TMP_KUSTOMIZE_OUTPUT"
104+
105+
# Delete and recreate the actual manifests directory
106+
MANIFEST_DIR="${REPO_ROOT}/openshift/catalogd/${OUTPUT_DIR}"
107+
rm -rf "${MANIFEST_DIR}"
108+
mkdir -p "${MANIFEST_DIR}"
109+
110+
# Copy everything we just generated and split into the actual manifests directory
111+
cp "$TMP_MANIFEST_DIR"/* "$MANIFEST_DIR"/
112+
113+
# Update file names to be in the format nn-$kind-$namespace-$name
114+
(
115+
cd "$MANIFEST_DIR"
116+
117+
for f in *; do
118+
# Get the numeric prefix from the filename
119+
index=$(echo "$f" | cut -d '-' -f 1)
120+
# Keep track of the full file name without the leading number and dash
121+
name_without_index=${f#$index-}
122+
# Fix the double dash in cluster-scoped names
123+
name_without_index=${name_without_index//--/-}
124+
# Reformat the name so the leading number is always padded to 2 digits
125+
new_name=$(printf "%02d" "$index")-$name_without_index
126+
# Some file names (namely CRDs) don't end in .yml - make them
127+
if ! [[ "$new_name" =~ yml$ ]]; then
128+
new_name="${new_name}".yml
129+
fi
130+
if [[ "$f" != "$new_name" ]]; then
131+
# Rename
132+
mv "$f" "${new_name}"
133+
fi
134+
done
135+
)
136+
rm -rf "$TMP_ROOT"
137+
}
138+
139+
# Generate the manifests
140+
generate openshift manifests
141+
generate openshift-experimental manifests-experimental
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resources:
2+
- ../../../../../config/base/catalogd/crd/experimental
3+
- ../openshift/olmv1-ns
4+
- ../openshift/openshift-config
5+
- ../openshift/catalogs
6+
7+
# Only those copinents that are part of catalogd TechPreview should be listed here
8+
components:
9+
- ../../../../../config/components/features/apiv1-metas-handler
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
resources:
2+
- ../../../../../config/base/catalogd/crd/standard
23
- olmv1-ns
34
- openshift-config
45
- catalogs

openshift/catalogd/kustomize/overlays/openshift/olmv1-ns/kustomization.yaml

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,10 @@ namespace: OPENSHIFT-NAMESPACE
44
namePrefix: catalogd-
55

66
resources:
7-
- ../../../../../../config/base/catalogd/crd
87
- ../../../../../../config/base/catalogd/rbac
98
- ../../../../../../config/base/catalogd/manager
109
- ../../../../../../config/base/common
1110
- metrics
12-
- trusted-ca/catalogd_trusted_ca_configmap.yaml
13-
14-
patches:
15-
- path: patches/manager_namespace_privileged.yaml
16-
- path: patches/manager_namespace_monitored.yaml
17-
- path: patches/manager_namespace_annotations.yaml
18-
- target:
19-
kind: Service
20-
name: service
21-
path: patches/manager_service.yaml
22-
- target:
23-
kind: MutatingWebhookConfiguration
24-
name: mutating-webhook-configuration
25-
path: patches/mutating_webhook_config.yaml
26-
- target:
27-
kind: ClusterRole
28-
name: manager-role
29-
path: patches/manager_role.yaml
30-
- target:
31-
kind: Deployment
32-
name: controller-manager
33-
path: patches/manager_deployment_certs.yaml
34-
- target:
35-
kind: Deployment
36-
name: controller-manager
37-
path: patches/manager_deployment_mount_etc_containers.yaml
38-
- target:
39-
kind: Deployment
40-
name: controller-manager
41-
path: patches/manager_deployment_log_verbosity.yaml
42-
- target:
43-
kind: Deployment
44-
name: controller-manager
45-
path: patches/manager_deployment_node_selection.yaml
11+
- trusted-ca
12+
components:
13+
- patches
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: kustomize.config.k8s.io/v1alpha1
2+
kind: Component
3+
patches:
4+
- path: manager_namespace_privileged.yaml
5+
- path: manager_namespace_monitored.yaml
6+
- path: manager_namespace_annotations.yaml
7+
- target:
8+
kind: Service
9+
name: service
10+
path: manager_service.yaml
11+
- target:
12+
kind: MutatingWebhookConfiguration
13+
name: mutating-webhook-configuration
14+
path: mutating_webhook_config.yaml
15+
- target:
16+
kind: ClusterRole
17+
name: manager-role
18+
path: manager_role.yaml
19+
- target:
20+
kind: Deployment
21+
name: controller-manager
22+
path: manager_deployment_certs.yaml
23+
- target:
24+
kind: Deployment
25+
name: controller-manager
26+
path: manager_deployment_mount_etc_containers.yaml
27+
- target:
28+
kind: Deployment
29+
name: controller-manager
30+
path: manager_deployment_log_verbosity.yaml
31+
- target:
32+
kind: Deployment
33+
name: controller-manager
34+
path: manager_deployment_node_selection.yaml
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
resources:
2+
- catalogd_trusted_ca_configmap.yaml
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
annotations:
5+
openshift.io/node-selector: ""
6+
workload.openshift.io/allowed: management
7+
labels:
8+
app.kubernetes.io/part-of: olm
9+
openshift.io/cluster-monitoring: "true"
10+
pod-security.kubernetes.io/audit: privileged
11+
pod-security.kubernetes.io/audit-version: latest
12+
pod-security.kubernetes.io/enforce: privileged
13+
pod-security.kubernetes.io/enforce-version: latest
14+
pod-security.kubernetes.io/warn: privileged
15+
pod-security.kubernetes.io/warn-version: latest
16+
name: openshift-catalogd

0 commit comments

Comments
 (0)