This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
test-prow-e2e.sh
executable file
·162 lines (125 loc) · 5.23 KB
/
test-prow-e2e.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env bash
set -eExuo pipefail
if [ $# -eq 0 ]
then
echo "nmstate console plugin image not provided"
echo "exiting..."
exit 1
fi
PULL_SECRET_PATH="/var/run/operator-secret/dockerconfig"
NAMESPACE="openshift-marketplace"
SECRET_NAME="ocs-secret"
NS="nmstate"
ARTIFACT_DIR=${ARTIFACT_DIR:=/tmp/artifacts}
SCREENSHOTS_DIR="cypress/screenshots"
# Enable console plugin for nmstate
export CONSOLE_CONFIG_NAME="cluster"
export NMSTATE_PLUGIN_NAME="nmstate-console-plugin"
NMSTATE_PLUGIN_IMAGE="$1"
function generateLogsAndCopyArtifacts {
oc cluster-info dump > ${ARTIFACT_DIR}/cluster_info.json
oc get catalogsource -A -o wide > ${ARTIFACT_DIR}/catalogsource.yaml
oc get catalogsource -A -o yaml >> ${ARTIFACT_DIR}/catalogsource.yaml
oc get subscriptions -n ${NS} -o wide > ${ARTIFACT_DIR}/subscription_details.yaml
oc get subscriptions -n ${NS} -o yaml >> ${ARTIFACT_DIR}/subscription_details.yaml
oc get csvs -n ${NS} -o wide > ${ARTIFACT_DIR}/csvs.yaml
oc get csvs -n ${NS} -o yaml >> ${ARTIFACT_DIR}/csvs.yaml
oc get deployments -n ${NS} -o wide > ${ARTIFACT_DIR}/deployment_details.yaml
oc get deployments -n ${NS} -o yaml >> ${ARTIFACT_DIR}/deployment_details.yaml
oc get installplan -n ${NS} -o wide > ${ARTIFACT_DIR}/installplan.yaml
oc get installplan -n ${NS} -o yaml >> ${ARTIFACT_DIR}/installplan.yaml
oc get nodes -o wide > ${ARTIFACT_DIR}/node.yaml
oc get nodes -o yaml >> ${ARTIFACT_DIR}/node.yaml
oc get pods -n ${NS} -o wide >> ${ARTIFACT_DIR}/pod_details_openshift-kubevirt.yaml
oc get pods -n ${NS} -o yaml >> ${ARTIFACT_DIR}/pod_details_openshift-kubevirt.yaml
for pod in `oc get pods -n ${NS} --no-headers -o custom-columns=":metadata.name" | grep "kubevirt"`; do
echo $pod
oc logs $pod -n ${NS} > ${ARTIFACT_DIR}/${pod}.logs
done
oc get serviceaccounts -n ${NS} -o wide > ${ARTIFACT_DIR}/serviceaccount.yaml
oc get serviceaccounts -n ${NS} -o yaml >> ${ARTIFACT_DIR}/serviceaccount.yaml
oc get console.v1.operator.openshift.io cluster -o yaml >> ${ARTIFACT_DIR}/cluster.yaml
if [ -d "$ARTIFACT_DIR" ] && [ -d "$SCREENSHOTS_DIR" ]; then
if [[ -z "$(ls -A -- "$SCREENSHOTS_DIR")" ]]; then
echo "No artifacts were copied."
else
echo "Copying artifacts from $(pwd)..."
cp -r "$SCREENSHOTS_DIR" "${ARTIFACT_DIR}/screenshots"
fi
fi
}
echo "Creating namespace nmstate"
cat <<EOF | oc create -f -
apiVersion: v1
kind: Namespace
metadata:
name: ${NS}
labels:
name: nmstate
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/audit: restricted
pod-security.kubernetes.io/warn: restricted
EOF
trap generateLogsAndCopyArtifacts EXIT
trap generateLogsAndCopyArtifacts ERR
function createSecret {
oc create secret generic ${SECRET_NAME} --from-file=.dockerconfigjson=${PULL_SECRET_PATH} --type=kubernetes.io/dockerconfigjson -n $1
}
function linkSecrets {
for serviceAccount in `oc get serviceaccounts -n ${NS} --no-headers -o custom-columns=":metadata.name" | sed 's/"//g'`; do
echo "Linking ${SECRET_NAME} to ${serviceAccount}"
oc secrets link ${serviceAccount} ${SECRET_NAME} -n ${NS} --for=pull
done
}
function deleteAllPods {
oc delete pods --all -n $1
}
echo "Creating secret for CI builds in ${NAMESPACE}"
createSecret ${NAMESPACE}
echo "Creating secret for linking pods"
createSecret ${NS}
echo "Adding secret to all service accounts in ${NS} namespace"
linkSecrets
echo "Restarting pods for secret update"
deleteAllPods ${NS}
sleep 30
echo "Adding secret to all service accounts in ${NS} namespace"
linkSecrets
echo "Restarting pods for secret update"
deleteAllPods ${NS}
sleep 120
echo "Adding secret to all service accounts in ${NS} namespace"
linkSecrets
echo "Restarting pods for secret update"
deleteAllPods ${NS}
sleep 120
echo "deploy nmstate CRDs"
oc apply -f src/nmstate-types/crds/nmstate.io_nmstates.yaml
oc apply -f src/nmstate-types/crds/nmstate.io_nodenetworkconfigurationenactments.yaml
oc apply -f src/nmstate-types/crds/nmstate.io_nodenetworkconfigurationpolicies.yaml
oc apply -f src/nmstate-types/crds/nmstate.io_nodenetworkstates.yaml
cat <<EOF | oc create -f -
apiVersion: nmstate.io/v1
kind: NMState
metadata:
name: nmstate
EOF
echo "Deploy nmstate console plugin"
oc process -n ${NS} -f oc-manifest.yaml -p IMAGE=${NMSTATE_PLUGIN_IMAGE} -p NAMESPACE=${NS} -o yaml
oc process -n ${NS} -f oc-manifest.yaml -p IMAGE=${NMSTATE_PLUGIN_IMAGE} -p NAMESPACE=${NS} | oc create -f -
oc patch consoles.operator.openshift.io cluster --patch '{ "spec": { "plugins": ["nmstate-console-plugin"] } }' --type=merge
until \
oc wait pods -n ${NS} --for=jsonpath='{.spec.containers[0].image}'="$NMSTATE_PLUGIN_IMAGE" -l app=nmstate-console-plugin
do
sleep 1
done
INSTALLER_DIR=${INSTALLER_DIR:=${ARTIFACT_DIR}/installer}
export CYPRESS_KUBEADMIN_PASSWORD="$(cat "${KUBEADMIN_PASSWORD_FILE:-${INSTALLER_DIR}/auth/kubeadmin-password}")"
export BRIDGE_BASE_ADDRESS="$(oc get consoles.config.openshift.io cluster -o jsonpath='{.status.consoleURL}')"
# Disable color codes in Cypress since they do not render well CI test logs.
# https://docs.cypress.io/guides/guides/continuous-integration.html#Colors
export NO_COLOR=1
# Install dependencies.
yarn install --ignore-engines
# Run tests.
yarn run cypress