Skip to content

Commit 0f9d642

Browse files
Mikalai Radchukopenshift-merge-bot[bot]
authored andcommitted
UPSTREAM: <drop>: Add global-pull-secret flag
Pass global-pull-secret to the manager container. Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 8d16b39 commit 0f9d642

File tree

29 files changed

+149
-22
lines changed

29 files changed

+149
-22
lines changed

openshift/generate-manifests.sh

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ IMAGE_MAPPINGS[kube-rbac-proxy]='${KUBE_RBAC_PROXY_IMAGE}'
2020
# shellcheck disable=SC2016
2121
IMAGE_MAPPINGS[manager]='${OPERATOR_CONTROLLER_IMAGE}'
2222

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[global-pull-secret]="openshift-config/pull-secret"
35+
2336
##################################################
2437
# You shouldn't need to change anything below here
2538
##################################################
@@ -36,29 +49,41 @@ TMP_ROOT="$(mktemp -p . -d 2>/dev/null || mktemp -d ./tmpdir.XXXXXXX)"
3649
trap 'rm -rf $TMP_ROOT' EXIT
3750

3851
# Copy all kustomize files into a temp dir
39-
TMP_CONFIG="${TMP_ROOT}/config"
40-
cp -a "${REPO_ROOT}/config" "$TMP_CONFIG"
52+
cp -a "${REPO_ROOT}/config" "${TMP_ROOT}/config"
53+
mkdir -p "${TMP_ROOT}/openshift"
54+
cp -a "${REPO_ROOT}/openshift/kustomize" "${TMP_ROOT}/openshift/kustomize"
4155

42-
# Override namespace to openshift-operator-controller
43-
$YQ -i ".namespace = \"${NAMESPACE}\"" "${TMP_CONFIG}/base/kustomization.yaml"
56+
# Override OPENSHIFT-NAMESPACE to ${NAMESPACE}
57+
find "${TMP_ROOT}" -name "*.yaml" -exec sed -i "s/OPENSHIFT-NAMESPACE/${NAMESPACE}/g" {} \;
4458

4559
# Create a temp dir for manifests
4660
TMP_MANIFEST_DIR="${TMP_ROOT}/manifests"
4761
mkdir -p "$TMP_MANIFEST_DIR"
4862

4963
# Run kustomize, which emits a single yaml file
5064
TMP_KUSTOMIZE_OUTPUT="${TMP_MANIFEST_DIR}/temp.yaml"
51-
$KUSTOMIZE build "${REPO_ROOT}"/openshift/kustomize/overlays/openshift -o "$TMP_KUSTOMIZE_OUTPUT"
65+
$KUSTOMIZE build "${TMP_ROOT}/openshift/kustomize/overlays/openshift" -o "$TMP_KUSTOMIZE_OUTPUT"
5266

5367
for container_name in "${!IMAGE_MAPPINGS[@]}"; do
5468
placeholder="${IMAGE_MAPPINGS[$container_name]}"
5569
$YQ -i "(select(.kind == \"Deployment\")|.spec.template.spec.containers[]|select(.name==\"$container_name\")|.image) = \"$placeholder\"" "$TMP_KUSTOMIZE_OUTPUT"
5670
$YQ -i 'select(.kind == "Deployment").spec.template.metadata.annotations += {"target.workload.openshift.io/management": "{\"effect\": \"PreferredDuringScheduling\"}"}' "$TMP_KUSTOMIZE_OUTPUT"
57-
$YQ -i 'select(.kind == "Deployment").spec.template.metadata.annotations += {"openshift.io/required-scc": "restricted-v2"}' "$TMP_KUSTOMIZE_OUTPUT"
71+
$YQ -i 'select(.kind == "Deployment").spec.template.metadata.annotations += {"openshift.io/required-scc": "privileged"}' "$TMP_KUSTOMIZE_OUTPUT"
5872
$YQ -i 'select(.kind == "Deployment").spec.template.spec += {"priorityClassName": "system-cluster-critical"}' "$TMP_KUSTOMIZE_OUTPUT"
5973
$YQ -i 'select(.kind == "Namespace").metadata.annotations += {"workload.openshift.io/allowed": "management"}' "$TMP_KUSTOMIZE_OUTPUT"
6074
done
6175

76+
# Loop through any flag updates that need to be made to the manager container
77+
for flag_name in "${!FLAG_MAPPINGS[@]}"; do
78+
flagval="${FLAG_MAPPINGS[$flag_name]}"
79+
80+
# First, update the flag if it exists
81+
$YQ -i "(select(.kind == \"Deployment\") | .spec.template.spec.containers[] | select(.name == \"manager\") | .args[] | select(. | contains(\"--$flag_name=\")) | .) = \"--$flag_name=$flagval\"" "$TMP_KUSTOMIZE_OUTPUT"
82+
83+
# Then, append the flag if it doesn't exist
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+
done
86+
6287
# Use yq to split the single yaml file into 1 per document.
6388
# Naming convention: $index-$kind-$namespace-$name. If $namespace is empty, just use the empty string.
6489
(
@@ -102,4 +127,3 @@ cp "$TMP_MANIFEST_DIR"/* "$MANIFEST_DIR"/
102127
fi
103128
done
104129
)
105-
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
# Adds namespace to all resources.
2-
namespace: openshift-operator-controller
3-
41
namePrefix: operator-controller-
52

63
resources:
7-
- resources/ca_configmap.yaml
8-
- ../../../../config/base/crd
9-
- ../../../../config/base/rbac
10-
- ../../../../config/base/manager
11-
12-
patches:
13-
- target:
14-
kind: Deployment
15-
name: controller-manager
16-
path: patches/manager_deployment_ca.yaml
4+
- olmv1-ns
5+
- openshift-config
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Adds namespace to all resources.
2+
namespace: OPENSHIFT-NAMESPACE
3+
4+
resources:
5+
- resources/ca_configmap.yaml
6+
- ../../../../../config/base/crd
7+
- ../../../../../config/base/rbac
8+
- ../../../../../config/base/manager
9+
10+
patches:
11+
- target:
12+
kind: ClusterRole
13+
name: manager-role
14+
path: patches/manager_role.yaml
15+
- target:
16+
kind: Deployment
17+
name: controller-manager
18+
path: patches/manager_deployment_ca.yaml
19+
- path: patches/manager_namespace_privileged.yaml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: system
5+
labels:
6+
pod-security.kubernetes.io/enforce: privileged
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- op: add
2+
path: /rules/-
3+
value:
4+
apiGroups: [security.openshift.io]
5+
resources: [securitycontextconstraints]
6+
resourceNames: [privileged]
7+
verbs: [use]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Adds namespace to all resources.
2+
namespace: openshift-config
3+
4+
resources:
5+
- rbac/operator-controller_manager_role.yaml
6+
- rbac/operator-controller_manager_role_binding.yaml
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# permissions to do leader election.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: Role
4+
metadata:
5+
labels:
6+
app.kubernetes.io/part-of: olm
7+
app.kubernetes.io/name: catalogd
8+
name: manager-role
9+
rules:
10+
- apiGroups:
11+
- ""
12+
resources:
13+
- secrets
14+
verbs:
15+
- get
16+
- list
17+
- watch
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: RoleBinding
3+
metadata:
4+
labels:
5+
app.kubernetes.io/part-of: olm
6+
app.kubernetes.io/name: catalogd
7+
name: manager-rolebinding
8+
roleRef:
9+
apiGroup: rbac.authorization.k8s.io
10+
kind: Role
11+
name: manager-role
12+
subjects:
13+
- kind: ServiceAccount
14+
name: controller-manager
15+
namespace: OPENSHIFT-NAMESPACE

0 commit comments

Comments
 (0)