Skip to content
This repository was archived by the owner on Aug 2, 2019. It is now read-only.

Commit 58176a6

Browse files
committed
Create a shared enable_admission_webhooks function
Some tweaking necessary for RHPDS, specifically overriding KUBE_SSH_USER to ec2-user. Still some opportunity with the redundant json config string
1 parent a2c1dc6 commit 58176a6

File tree

4 files changed

+84
-82
lines changed

4 files changed

+84
-82
lines changed

etc/scripts/install-on-minishift.sh

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,7 @@ minishift start
2828

2929
eval "$(minishift oc-env)"
3030

31-
if ! minishift openshift config view --target=kube | grep ValidatingAdmissionWebhook >/dev/null; then
32-
minishift openshift config set --target=kube --patch '{
33-
"admissionConfig": {
34-
"pluginConfig": {
35-
"ValidatingAdmissionWebhook": {
36-
"configuration": {
37-
"apiVersion": "apiserver.config.k8s.io/v1alpha1",
38-
"kind": "WebhookAdmission",
39-
"kubeConfigFile": "/dev/null"
40-
}
41-
},
42-
"MutatingAdmissionWebhook": {
43-
"configuration": {
44-
"apiVersion": "apiserver.config.k8s.io/v1alpha1",
45-
"kind": "WebhookAdmission",
46-
"kubeConfigFile": "/dev/null"
47-
}
48-
}
49-
}
50-
}
51-
}'
52-
fi
53-
54-
# wait until the kube-apiserver is restarted
55-
until oc login -u admin -p admin 2>/dev/null; do sleep 5; done;
31+
oc login -u admin -p admin
5632

5733
# these perms are required by istio
5834
oc project myproject

etc/scripts/install-on-okd.sh

Lines changed: 0 additions & 55 deletions
This file was deleted.

etc/scripts/install.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
if [ "$1" != "-q" ]; then
66
echo
77
echo " WARNING: This script will blindly attempt to install OLM, istio, and knative"
8-
echo " on your OKD cluster, so if any are already there, hijinks will ensue."
8+
echo " on your OpenShift cluster, so if any are already there, hijinks may ensue."
99
echo
10-
echo " If your cluster is minishift, run $(dirname $0)/install-on-minishift.sh instead."
10+
echo " If your cluster isn't minishift, ensure \$KUBE_SSH_KEY and \$KUBE_SSH_USER are set"
1111
echo
1212
echo " Pass -q to disable this warning"
1313
echo
@@ -20,6 +20,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
2020

2121
source "$DIR/installation-functions.sh"
2222

23+
enable_admission_webhooks
2324
install_olm
2425
install_istio
2526
install_knative_build

etc/scripts/installation-functions.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,87 @@ function wait_for_all_pods {
2222
timeout 300 "oc get pods -n $1 2>&1 | grep -v -E '(Running|Completed|STATUS)'"
2323
}
2424

25+
function check_minishift {
26+
(hash minishift && oc whoami --show-server | grep "$(minishift ip)") >/dev/null 2>&1
27+
}
28+
29+
function enable_admission_webhooks {
30+
if check_minishift; then
31+
if ! minishift openshift config view --target=kube | grep ValidatingAdmissionWebhook >/dev/null; then
32+
minishift openshift config set --target=kube --patch '{
33+
"admissionConfig": {
34+
"pluginConfig": {
35+
"ValidatingAdmissionWebhook": {
36+
"configuration": {
37+
"apiVersion": "apiserver.config.k8s.io/v1alpha1",
38+
"kind": "WebhookAdmission",
39+
"kubeConfigFile": "/dev/null"
40+
}
41+
},
42+
"MutatingAdmissionWebhook": {
43+
"configuration": {
44+
"apiVersion": "apiserver.config.k8s.io/v1alpha1",
45+
"kind": "WebhookAdmission",
46+
"kubeConfigFile": "/dev/null"
47+
}
48+
}
49+
}
50+
}
51+
}'
52+
# wait until the kube-apiserver is restarted
53+
until oc login -u admin -p admin 2>/dev/null; do sleep 5; done;
54+
fi
55+
else
56+
KUBE_SSH_USER=${KUBE_SSH_USER:-cloud-user}
57+
API_SERVER=$(oc config view --minify | grep server | awk -F'//' '{print $2}' | awk -F':' '{print $1}')
58+
59+
ssh $KUBE_SSH_USER@$API_SERVER -i $KUBE_SSH_KEY /bin/bash <<- EOF
60+
sudo -i
61+
cp -n /etc/origin/master/master-config.yaml /etc/origin/master/master-config.yaml.backup
62+
oc ex config patch /etc/origin/master/master-config.yaml --type=merge -p '{
63+
"admissionConfig": {
64+
"pluginConfig": {
65+
"ValidatingAdmissionWebhook": {
66+
"configuration": {
67+
"apiVersion": "apiserver.config.k8s.io/v1alpha1",
68+
"kind": "WebhookAdmission",
69+
"kubeConfigFile": "/dev/null"
70+
}
71+
},
72+
"MutatingAdmissionWebhook": {
73+
"configuration": {
74+
"apiVersion": "apiserver.config.k8s.io/v1alpha1",
75+
"kind": "WebhookAdmission",
76+
"kubeConfigFile": "/dev/null"
77+
}
78+
}
79+
}
80+
}
81+
}' >/etc/origin/master/master-config.yaml.patched
82+
if [ $? == 0 ]; then
83+
mv /etc/origin/master/master-config.yaml.patched /etc/origin/master/master-config.yaml
84+
/usr/local/bin/master-restart api && /usr/local/bin/master-restart controllers
85+
else
86+
exit
87+
fi
88+
EOF
89+
90+
if [ $? == 0 ]; then
91+
# wait until the kube-apiserver is restarted
92+
until oc status 2>/dev/null; do sleep 5; done
93+
else
94+
echo 'Remote command failed; check $KUBE_SSH_USER and/or $KUBE_SSH_KEY'
95+
return -1
96+
fi
97+
fi
98+
}
99+
25100
function install_olm {
101+
# Scale down existing OLM, if any
102+
if oc get ns operator-lifecycle-manager; then
103+
oc scale -n operator-lifecycle-manager --replicas=0 deployment/catalog-operator
104+
oc scale -n operator-lifecycle-manager --replicas=0 deployment/olm-operator
105+
fi
26106
local ROOT_DIR="$INSTALL_SCRIPT_DIR/../.."
27107
local REPO_DIR="$ROOT_DIR/.repos"
28108
local OLM_DIR="$REPO_DIR/olm"

0 commit comments

Comments
 (0)