-
Notifications
You must be signed in to change notification settings - Fork 592
/
installOperatorOnCluster.ts
263 lines (249 loc) · 9.88 KB
/
installOperatorOnCluster.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import { modal } from '@console/cypress-integration-tests/views/modal';
import { pipelinesPage } from '@console/pipelines-plugin/integration-tests/support/pages';
import { detailsPage } from '../../../../../integration-tests-cypress/views/details-page';
import { pageTitle, operators, switchPerspective } from '../../constants';
import { operatorsPO } from '../../pageObjects';
import { app, perspective, projectNameSpace, sidePane } from '../app';
import { operatorsPage } from '../operators-page';
import { installCRW, waitForCRWToBeAvailable } from './installCRW';
import { createKnativeEventing, createKnativeServing } from './knativeSubscriptions';
export const installOperator = (operatorName: operators) => {
operatorsPage.navigateToOperatorHubPage();
operatorsPage.searchOperator(operatorName);
operatorsPage.selectOperator(operatorName);
cy.get('body').then(($body) => {
if ($body.text().includes('Show community Operator')) {
cy.log('Installing community operator');
modal.submit();
modal.shouldBeClosed();
}
});
operatorsPage.verifySidePane();
cy.get(operatorsPO.alertDialog).then(($sidePane) => {
if ($sidePane.find(operatorsPO.sidePane.install).length) {
cy.get(operatorsPO.sidePane.install).click({ force: true });
cy.get(operatorsPO.installOperators.title).should('contain.text', pageTitle.InstallOperator);
if (operatorName === operators.WebTerminalOperator) {
cy.get(operatorsPO.warningAlert, { timeout: 3000 }).should('be.visible');
}
cy.get(operatorsPO.operatorHub.install).click();
cy.get(operatorsPO.operatorHub.installingOperatorModal).should('be.visible');
app.waitForLoad();
// workaround for https://bugzilla.redhat.com/show_bug.cgi?id=2059865
const waitForResult = (tries: number = 10) => {
if (tries < 1) {
return;
}
cy.wait(2000);
cy.get('body').then((body) => {
if (body.find(`[data-test="success-icon"]`).length > 0) {
cy.byTestID('success-icon').should('be.visible');
} else if (body.find(`.pf-c-alert`).length > 0) {
cy.log('Installation flow interrupted, check the Installed Operators page for status');
operatorsPage.navigateToInstallOperatorsPage();
operatorsPage.searchOperatorInInstallPage(operatorName);
cy.contains('Succeeded', { timeout: 300000 });
} else {
waitForResult(tries - 1);
}
});
};
waitForResult();
} else {
cy.log(`${operatorName} Operator is already installed`);
sidePane.close();
}
operatorsPage.navigateToInstallOperatorsPage();
operatorsPage.verifyInstalledOperator(operatorName);
});
};
// Conditional wait (recursive).
// Installs operator if it's not installed.
// Needs to be done this way, beacuse the operators list is not updated quickly enough after filtering.
const installIfNotInstalled = (operator: operators, tries: number = 4, polling: number = 500) => {
if (tries === 0) {
cy.log(`Operator ${operator} is already installed.`);
return;
}
cy.get('body', {
timeout: 50000,
}).then(($ele) => {
if ($ele.find(operatorsPO.installOperators.noOperatorsFound).length) {
cy.log(`Operator ${operator} was not yet installed.`);
installOperator(operator);
} else {
// "No operators found" element was not found. Wait and try again.
cy.wait(polling);
installIfNotInstalled(operator, tries - 1, polling);
}
});
};
export const waitForCRDs = (operator: operators) => {
switch (operator) {
case operators.PipelinesOperator:
cy.log(`Verify the CRD's for the "${operator}"`);
operatorsPage.navigateToCustomResourceDefinitions();
cy.byTestID('name-filter-input')
.clear()
.type('Pipeline');
cy.get('tr[data-test-rows="resource-row"]', { timeout: 300000 }).should(
'have.length.within',
4,
6,
);
cy.get('[data-test-id="TektonPipeline"]', { timeout: 80000 }).should('be.visible');
cy.get('[data-test-id="PipelineResource"]', { timeout: 80000 }).should('be.visible');
cy.get('[data-test-id="PipelineRun"]', { timeout: 80000 }).should('be.visible');
cy.get('[data-test-id="Pipeline"]', { timeout: 80000 }).should('be.visible');
break;
case operators.WebTerminalOperator:
cy.log(`Verify the CRD's for the "${operator}"`);
operatorsPage.navigateToCustomResourceDefinitions();
cy.byTestID('name-filter-input')
.clear()
.type('DevWorkspace');
cy.get('tr[data-test-rows="resource-row"]', { timeout: 300000 }).should(
'have.length.within',
4,
6,
);
cy.get('[data-test-id="DevWorkspace"]', { timeout: 80000 }).should('be.visible');
cy.get('[data-test-id="DevWorkspaceOperatorConfig"]', { timeout: 80000 }).should(
'be.visible',
);
cy.get('[data-test-id="DevWorkspaceRouting"]', { timeout: 80000 }).should('be.visible');
cy.get('[data-test-id="DevWorkspaceTemplate"]', { timeout: 80000 }).should('be.visible');
break;
default:
cy.log(`waiting for CRC's is not applicable for this ${operator} operator`);
}
};
const waitForPipelineTasks = (retries: number = 30) => {
if (retries === 0) {
return;
}
cy.contains('h1', 'Pipeline builder').should('be.visible');
cy.byTestID('loading-indicator').should('not.exist');
cy.wait(500);
cy.get('body').then(($body) => {
if ($body.find(`[data-id="pipeline-builder"]`).length === 0) {
cy.wait(10000);
cy.reload();
waitForPipelineTasks(retries - 1);
}
});
};
const createShipwrightBuild = () => {
projectNameSpace.selectProject(Cypress.env('NAMESPACE'));
cy.get('body').then(($body) => {
if ($body.find(operatorsPO.installOperators.search)) {
cy.get(operatorsPO.installOperators.search)
.clear()
.type(operators.ShipwrightOperator);
}
});
cy.get(operatorsPO.installOperators.shipwrightBuildLink).click({ force: true });
cy.get('body').then(($body) => {
if ($body.text().includes('Page Not Found')) {
cy.reload();
}
});
detailsPage.titleShouldContain(pageTitle.ShipwrightBuild);
app.waitForLoad();
cy.get('body').then(($body) => {
if ($body.find('[role="grid"]').length > 0) {
cy.log(`${pageTitle.ShipwrightBuild} already subscribed`);
} else {
cy.byTestID('item-create').click();
detailsPage.titleShouldContain(pageTitle.ShipwrightBuild);
cy.byTestID('create-dynamic-form').click();
cy.byLegacyTestID('details-actions').should('be.visible');
cy.contains('Ready', { timeout: 150000 }).should('be.visible');
}
});
};
const performPostInstallationSteps = (operator: operators): void => {
switch (operator) {
case operators.ServerlessOperator:
cy.log(`Performing Serverless post installation steps`);
createKnativeServing();
createKnativeEventing();
operatorsPage.navigateToOperatorHubPage();
break;
case operators.RedHatCodereadyWorkspaces:
cy.log(`Performing CRW post-installation steps`);
installCRW();
waitForCRWToBeAvailable();
break;
case operators.PipelinesOperator:
cy.log(`Performing Pipelines post-installation steps`);
cy.request(
'api/kubernetes/apis/operators.coreos.com/v1alpha1/namespaces/openshift-operators/subscriptions/openshift-pipelines-operator-rh',
).then((resp) => {
expect(resp.status).toEqual(200);
});
waitForCRDs(operators.PipelinesOperator);
cy.visit('/pipelines/ns/default');
pipelinesPage.clickOnCreatePipeline();
waitForPipelineTasks();
break;
case operators.WebTerminalOperator:
cy.log(`Performing Web Terminal post-installation steps`);
waitForCRDs(operators.WebTerminalOperator);
break;
case operators.ShipwrightOperator:
cy.log(`Performing Shipwright Operator post-installation steps`);
createShipwrightBuild();
break;
default:
cy.log(`Nothing to do in post-installation steps`);
}
};
export const verifyAndInstallOperator = (operator: operators, namespace?: string) => {
cy.log(`Installing operator: "${operator}"`);
perspective.switchTo(switchPerspective.Administrator);
operatorsPage.navigateToInstallOperatorsPage();
if (namespace !== undefined) {
projectNameSpace.selectProjectOrDoNothing(namespace);
}
operatorsPage.searchOperatorInInstallPage(operator);
installIfNotInstalled(operator);
performPostInstallationSteps(operator);
};
export const verifyAndInstallPipelinesOperator = () => {
perspective.switchTo(switchPerspective.Administrator);
verifyAndInstallOperator(operators.PipelinesOperator);
};
export const verifyAndInstallKnativeOperator = () => {
perspective.switchTo(switchPerspective.Administrator);
verifyAndInstallOperator(operators.ServerlessOperator);
};
export const verifyAndInstallGitopsPrimerOperator = () => {
perspective.switchTo(switchPerspective.Administrator);
verifyAndInstallOperator(operators.GitopsPrimer);
};
export const verifyAndInstallWebTerminalOperator = () => {
perspective.switchTo(switchPerspective.Administrator);
operatorsPage.navigateToInstallOperatorsPage();
cy.get(operatorsPO.installOperators.search)
.should('be.visible')
.clear()
.type(operators.WebTerminalOperator);
cy.get('body', {
timeout: 50000,
}).then(($ele) => {
if ($ele.find(operatorsPO.installOperators.noOperatorsFound)) {
installOperator(operators.WebTerminalOperator);
operatorsPage.navigateToInstallOperatorsPage();
operatorsPage.searchOperatorInInstallPage('DevWorkspace Operator');
cy.get('.co-clusterserviceversion-logo__name__clusterserviceversion').should(
'include.text',
'DevWorkspace Operator',
);
cy.contains('Succeeded', { timeout: 300000 });
performPostInstallationSteps(operators.WebTerminalOperator);
} else {
cy.log('Web Terminal operator is installed in cluster');
}
});
};