forked from kiali/kiali
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.ts
150 lines (130 loc) · 5.56 KB
/
hooks.ts
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
import { Before, After } from '@badeball/cypress-cucumber-preprocessor';
const CLUSTER1_CONTEXT = Cypress.env('CLUSTER1_CONTEXT');
const CLUSTER2_CONTEXT = Cypress.env('CLUSTER2_CONTEXT');
const install_demoapp = (demoapp: string): void => {
let namespaces = 'bookinfo';
let deletion = `--delete-${demoapp}`;
let tg = '-tg';
let istio = '-in istio-system';
if (demoapp === 'error-rates') {
namespaces = 'alpha beta gamma';
deletion = '--delete';
tg = '';
} else if (demoapp === 'sleep') {
namespaces = 'sleep';
tg = '';
istio = '';
}
cy.exec(`../hack/istio/cypress/${demoapp}-status.sh`, { failOnNonZeroExit: false, timeout: 120000 }).then(result => {
cy.log(result.stdout);
if (result.code === 0) {
cy.log(`${demoapp} demo app is up and running`);
} else {
cy.log(`${demoapp} demo app is either broken or not present. Installing now.`);
cy.log(`Detecting pod architecture.`);
cy.exec('../hack/istio/cypress/get-node-architecture.sh', { failOnNonZeroExit: false }).then(result => {
if (result.code === 0) {
const arch: string = result.stdout;
cy.log(`Installing apps on ${arch} architecture.`);
// is the suite running on openshift?
cy.exec('kubectl api-versions | grep --quiet "route.openshift.io";', { failOnNonZeroExit: false }).then(
result => {
if (result.code === 0) {
cy.log('Openshift detected.').log(`Removing old ${demoapp} installations.`);
cy.exec(`../hack/istio/install-${demoapp}-demo.sh ${deletion} true`).then(() => {
cy.log('Installing new demo app.');
cy.exec(`../hack/istio/install-${demoapp}-demo.sh ${tg} ${istio} -a ${arch}`, {
timeout: 300000
}).then(() => {
cy.log('Waiting for demoapp to be ready.');
cy.exec(`../hack/istio/wait-for-namespace.sh -n ${namespaces}`, { timeout: 400000 });
});
});
} else {
cy.log(`Removing old ${demoapp} installations.`)
.exec(`../hack/istio/install-${demoapp}-demo.sh ${deletion} true -c kubectl`)
.then(() => {
cy.log('Installing new demo app.');
cy.exec(`../hack/istio/install-${demoapp}-demo.sh -c kubectl ${tg} ${istio} -a ${arch}`, {
timeout: 300000
});
});
}
}
);
} else {
cy.log(
'Different architectures on various nodes detected. Failed to install the demoapp using the Cypress hook.'
);
}
});
}
});
};
Before(() => {
// Focing to not stop cypress on unexpected errors not related to the tests.
// There are some random failures due timeouts/loadtime/framework that throws some error in the browser.
// After reviewing the tests failures, those are unrelated to the app, so,
// it needs this event to not fail the CI action due some "slow" action or similar.
// This is something to review in future iterations when tests are solid, but I haven't found a better way to
// solve this issue.
cy.on('uncaught:exception', (err, runnable, promise) => {
// when the exception originated from an unhandled promise
// rejection, the promise is provided as a third argument
// you can turn off failing the test in this case
if (promise) {
return false;
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
});
});
Before({ tags: '@gateway-api' }, () => {
cy.exec('kubectl get crd gateways.gateway.networking.k8s.io', { failOnNonZeroExit: false }).then(result => {
if (result.code !== 0) {
cy.log('Gateway API not found. Enabling it now.');
cy.exec(
'kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd/experimental?ref=v1.1.0" | kubectl apply -f -;'
)
.its('code')
.should('eq', 0);
}
});
});
Before({ tags: '@bookinfo-app' }, () => {
install_demoapp('bookinfo');
});
Before({ tags: '@error-rates-app' }, () => {
install_demoapp('error-rates');
});
Before({ tags: '@sleep-app' }, () => {
install_demoapp('sleep');
});
Before({ tags: '@remote-istio-crds' }, () => {
cy.exec(
`kubectl get crd --context ${CLUSTER2_CONTEXT} -o=custom-columns=NAME:.metadata.name | grep -E -i '.(istio|k8s).io$'`,
{ failOnNonZeroExit: false }
).then(result => {
if (result.code !== 0) {
cy.log('Istio CRDs not found on the remote cluster. Enabling it now.');
cy.exec(
`kubectl apply -f https://raw.githubusercontent.com/istio/istio/master/manifests/charts/base/crds/crd-all.gen.yaml --context ${CLUSTER2_CONTEXT}`
)
.its('code')
.should('eq', 0)
.then(() => {
cy.exec(
`kubectl rollout restart deployment/kiali -n istio-system --context ${CLUSTER1_CONTEXT} && kubectl rollout status deployment/kiali -n istio-system --context ${CLUSTER1_CONTEXT}`
);
});
}
});
});
After({ tags: '@sleep-app-scaleup-after' }, () => {
cy.exec('kubectl scale -n sleep --replicas=1 deployment/sleep');
});
// remove resources created in the istio-system namespace to not influence istio instance after the test
After({ tags: '@clean-istio-namespace-resources-after' }, () => {
cy.exec('kubectl -n istio-system delete PeerAuthentication default', { failOnNonZeroExit: false });
cy.exec('kubectl -n istio-system delete Sidecar default', { failOnNonZeroExit: false });
});