-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathcluster-manager.spec.ts
More file actions
910 lines (718 loc) · 38.4 KB
/
cluster-manager.spec.ts
File metadata and controls
910 lines (718 loc) · 38.4 KB
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
import { isMatch } from 'lodash';
import ClusterManagerCreatePagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create.po';
import { providersList } from '@/cypress/e2e/blueprints/manager/clusterProviderUrlCheck';
import ClusterManagerListPagePo from '@/cypress/e2e/po/pages/cluster-manager/cluster-manager-list.po';
import ClusterDashboardPagePo from '@/cypress/e2e/po/pages/explorer/cluster-dashboard.po';
import ClusterManagerDetailRke2CustomPagePo from '@/cypress/e2e/po/detail/provisioning.cattle.io.cluster/cluster-detail-rke2-custom.po';
import ClusterManagerDetailImportedGenericPagePo from '@/cypress/e2e/po/detail/provisioning.cattle.io.cluster/cluster-detail-import-generic.po';
import ClusterManagerCreateRke2CustomPagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-rke2-custom.po';
import ClusterManagerEditRke2CustomPagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/edit/cluster-edit-rke2-custom.po';
import ClusterManagerImportGenericPagePo from '@/cypress/e2e/po/extensions/imported/cluster-import-generic.po';
import ClusterManagerEditImportedPagePo from '@/cypress/e2e/po/extensions/imported/cluster-edit.po';
import ClusterManagerNamespacePagePo from '@/cypress/e2e/po/pages/cluster-manager/namespace.po';
import PromptRemove from '@/cypress/e2e/po/prompts/promptRemove.po';
import * as path from 'path';
import * as jsyaml from 'js-yaml';
import Shell from '@/cypress/e2e/po/components/shell.po';
import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';
import HomePagePo from '@/cypress/e2e/po/pages/home.po';
import { nodeDriveResponse } from '@/cypress/e2e/tests/pages/manager/mock-responses';
import TabbedPo from '@/cypress/e2e/po/components/tabbed.po';
import LoadingPo from '@/cypress/e2e/po/components/loading.po';
import {
VERY_LONG_TIMEOUT_OPT,
EXTRA_LONG_TIMEOUT_OPT,
MEDIUM_TIMEOUT_OPT,
RESTART_TIMEOUT_OPT
} from '@/cypress/support/utils/timeouts';
import HostedProvidersPagePo from '@/cypress/e2e/po/pages/cluster-manager/hosted-providers.po';
import { USERS_BASE_URL } from '@/cypress/support/utils/api-endpoints';
// At some point these will come from somewhere central, then we can make tools to remove resources from this or all runs
const createClusterTestName = (suffix: string) => `e2e-test-${ +new Date() }-create-${ suffix }`;
// File specific consts
const namespace = 'fleet-default';
const type = 'provisioning.cattle.io.cluster';
const importType = 'cluster';
let rke2CustomName = createClusterTestName('rke2-custom');
let importGenericName = createClusterTestName('import-generic');
let reenableAKS = false;
let originalSettings = '[{"name":"aks","active":true},{"name":"alibaba","active":true},{"name":"eks","active":true},{"name":"gke","active":true}]';
const downloadsFolder = Cypress.config('downloadsFolder');
describe('Cluster Manager', { testIsolation: 'off', tags: ['@manager', '@adminUser'] }, () => {
const clusterList = new ClusterManagerListPagePo();
const loadingPo = new LoadingPo('.loading-indicator');
before(() => {
cy.login();
cy.getRancherResource('v1', 'management.cattle.io.settings', 'kev2-operators', null).then((resp: Cypress.Response<any>) => {
const response = resp.body;
// update original data before sending request
originalSettings = response.value;
});
});
it('deactivating a hosted provider should hide its card from the cluster creation page', () => {
cy.intercept('PUT', `v1/management.cattle.io.settings/kev2-operators`).as('updateProviders');
const providersPage = new HostedProvidersPagePo();
const clusterCreatePage = new ClusterManagerCreatePagePo();
HostedProvidersPagePo.navTo();
providersPage.waitForPage();
// assert AKS kontainer driver is in Active state
providersPage.list().details('Azure AKS', 1).should('contain', 'Active');
// deactivate the AKS driver
providersPage.list().actionMenu('Azure AKS').getMenuItem('Deactivate').click();
cy.wait('@updateProviders').its('response.statusCode').should('eq', 200).then(() => {
reenableAKS = true;
});
// verify that the AKS card is not shown
clusterList.goTo();
clusterList.checkIsCurrentPage();
clusterList.createCluster();
clusterCreatePage.gridElementExistanceByName('Azure AKS', 'not.exist');
// re-enable the AKS kontainer driver
HostedProvidersPagePo.navTo();
providersPage.waitForPage();
providersPage.list().actionMenu('Azure AKS').getMenuItem('Activate').click();
cy.wait('@updateProviders').its('response.statusCode').should('eq', 200).then(() => {
reenableAKS = false;
});
// verify that the AKS card is back
clusterList.goTo();
clusterList.checkIsCurrentPage();
clusterList.createCluster();
clusterCreatePage.gridElementExistanceByName('Azure AKS', 'exist');
});
describe('RKE2 providers', () => {
providersList.forEach((prov) => {
it(`should be able to access RKE2 cluster creation for provider ${ prov.label } via url`, () => {
const clusterCreate = new ClusterManagerCreatePagePo();
clusterCreate.goTo(`type=${ prov.clusterProviderQueryParam }&rkeType=rke2`);
clusterCreate.waitForPage();
loadingPo.checkNotExists();
clusterCreate.rke2PageTitle().should('contain', `Create ${ prov.label }`);
});
});
});
describe('Created', () => {
const createRKE2ClusterPage = new ClusterManagerCreateRke2CustomPagePo();
const detailRKE2ClusterPage = () => new ClusterManagerDetailRke2CustomPagePo(undefined, rke2CustomName);
const tabbedPo = new TabbedPo('[data-testid="tabbed-block"]');
describe('RKE2 Custom', { tags: ['@jenkins', '@customCluster', '@provisioning'] }, () => {
const editCreatedClusterPage = () => new ClusterManagerEditRke2CustomPagePo(undefined, rke2CustomName);
it('can create new cluster', { retries: 0 }, () => {
rke2CustomName = createClusterTestName('rke2-custom');
cy.intercept('POST', `/v1/${ type }s`).as('createRequest');
const request = {
type,
metadata: {
namespace,
name: rke2CustomName
},
// Test for https://github.com/rancher/dashboard/issues/10338 (added option 'none' for CNI)
// The test validate the warning when selecting none, but now this get back to calico.
// A CNI is mandatory to get the cluster active otherwise manual intervention is needed or
// the use of a cloud provider but that's not in scope.
spec: { rkeConfig: { machineGlobalConfig: { cni: 'calico' }, machinePoolDefaults: { hostnameLengthLimit: 15 } } }
};
cy.userPreferences();
clusterList.goTo();
// check if burguer menu nav is highlighted correctly for cluster manager
BurgerMenuPo.checkIfMenuItemLinkIsHighlighted('Cluster Management');
clusterList.checkIsCurrentPage();
clusterList.createCluster();
createRKE2ClusterPage.waitForPage();
// EO test for https://github.com/rancher/dashboard/issues/9823
createRKE2ClusterPage.selectCustom(0);
createRKE2ClusterPage.nameNsDescription().name().set(rke2CustomName);
// Test for https://github.com/rancher/dashboard/issues/10338 (added option 'none' for CNI)
createRKE2ClusterPage.basicsTab().networks().checkExists();
createRKE2ClusterPage.basicsTab().networks().self().scrollIntoView();
createRKE2ClusterPage.basicsTab().networks().toggle();
createRKE2ClusterPage.basicsTab().networks().clickOptionWithLabel('none');
createRKE2ClusterPage.basicsTab().networks().checkOptionSelected('none');
// banner with additional info about 'none' option should be visible
createRKE2ClusterPage.basicsTab().networkNoneSelectedForCni().should('exist');
// EO test for https://github.com/rancher/dashboard/issues/10338 (added option 'none' for CNI)
createRKE2ClusterPage.basicsTab().networks().toggle();
createRKE2ClusterPage.basicsTab().networks().clickOptionWithLabel('calico');
createRKE2ClusterPage.basicsTab().networks().checkOptionSelected('calico');
// testing https://github.com/rancher/dashboard/issues/10159
createRKE2ClusterPage.selectTab(tabbedPo, '[data-testid="btn-networking"]');
createRKE2ClusterPage.network().truncateHostnameCheckbox().set();
// EO test for https://github.com/rancher/dashboard/issues/10159
createRKE2ClusterPage.create();
cy.wait('@createRequest').then((intercept) => {
// Issue with linter https://github.com/cypress-io/eslint-plugin-cypress/issues/3
expect(isMatch(intercept.request.body, request)).to.equal(true);
expect(['ingress-nginx', 'traefik']).to.include(intercept.request.body.spec?.rkeConfig?.machineGlobalConfig?.['ingress-controller']);
});
detailRKE2ClusterPage().waitForPage(undefined, 'registration');
createRKE2ClusterPage.activateInsecureRegistrationCommandFromUI().click();
createRKE2ClusterPage.commandFromCustomClusterUI().then(($value) => {
const registrationCommand = $value.text();
const customNodeKey = `${ Cypress.env('customNodeKey') || '' }`;
const decodedCustomNodeKey = customNodeKey.includes('BEGIN') ? customNodeKey : Cypress.Buffer.from(customNodeKey, 'base64').toString('utf8');
cy.writeFile('custom_node.key', decodedCustomNodeKey).then(() => {
cy.log('Creating the custom_node.key');
});
cy.exec('chmod 600 custom_node.key').then((result) => {
cy.log(result.stderr);
cy.log(result.stdout);
expect(result.code).to.eq(0);
});
cy.exec(`head custom_node.key`).then((result) => {
cy.log(result.stdout);
cy.log(result.stderr);
expect(result.code).to.eq(0);
});
cy.exec(createRKE2ClusterPage.customClusterRegistrationCmd(registrationCommand)).then((result) => {
cy.log(result.stderr);
cy.log(result.stdout);
expect(result.code).to.eq(0);
});
});
ClusterManagerListPagePo.navTo();
clusterList.waitForPage();
clusterList.list().state(rke2CustomName).should('contain.text', 'Updating');
clusterList.list().state(rke2CustomName).contains('Active', VERY_LONG_TIMEOUT_OPT); // super long timeout needed for cluster provisioning to complete
});
it('can copy config to clipboard', () => {
// Stub clipboard methods to avoid permission prompts
cy.visit('/', {
onBeforeLoad(win) {
cy.stub(win.navigator.clipboard, 'writeText').resolves();
},
});
ClusterManagerListPagePo.navTo();
cy.intercept('POST', '/v1/ext.cattle.io.kubeconfigs').as('copyKubeConfig');
clusterList.list().actionMenu(rke2CustomName).getMenuItem('Copy KubeConfig to Clipboard').click();
cy.wait('@copyKubeConfig');
// Verify confirmation message displays and is hidden after ~3 sec
cy.get('.growl-text').contains('Copied KubeConfig to Clipboard').should('be.visible');
cy.get('.growl-text', { timeout: 4000 }).should('not.exist');
// Skipping following assertion for now as it is failing due to Cypress' limitations with accessing the clipboard in Chrome browser and headless mode. Works in Electron browser
// see https://github.com/cypress-io/cypress/issues/2752
// read text saved in the browser clipboard
// cy.window().its('navigator.clipboard')
// .invoke('readText').should('include', rke2CustomName);
});
it('can edit cluster and see changes afterwards', () => {
clusterList.goTo();
clusterList.list().actionMenu(rke2CustomName).getMenuItem('Edit Config').click();
editCreatedClusterPage().waitForPage('mode=edit', 'basic');
editCreatedClusterPage().nameNsDescription().description().set(rke2CustomName);
editCreatedClusterPage().save();
// We should be taken back to the list page if the save was successful
clusterList.waitForPage();
clusterList.list().actionMenu(rke2CustomName).getMenuItem('Edit Config').click();
editCreatedClusterPage().waitForPage('mode=edit', 'basic');
editCreatedClusterPage().nameNsDescription().description().self()
.should('have.value', rke2CustomName);
});
it('will disable saving if an addon config has invalid data', () => {
clusterList.goTo();
clusterList.checkIsCurrentPage();
clusterList.createCluster();
createRKE2ClusterPage.waitForPage();
createRKE2ClusterPage.selectCustom(0);
createRKE2ClusterPage.nameNsDescription().name().set('abc');
createRKE2ClusterPage.clusterConfigurationTabs().clickTabWithSelector('#rke2-calico');
createRKE2ClusterPage.resourceDetail().createEditView().saveButtonPo().expectToBeEnabled();
createRKE2ClusterPage.calicoAddonConfig().yamlEditor().input().set('badvalue: -');
createRKE2ClusterPage.resourceDetail().createEditView().saveButtonPo().expectToBeDisabled();
createRKE2ClusterPage.calicoAddonConfig().yamlEditor().input().set('goodvalue: yay');
createRKE2ClusterPage.resourceDetail().createEditView().saveButtonPo().expectToBeEnabled();
});
it('can view cluster YAML editor', () => {
clusterList.goTo();
clusterList.list().actionMenu(rke2CustomName).getMenuItem('Edit YAML').click();
editCreatedClusterPage().waitForPage('mode=edit&as=yaml');
editCreatedClusterPage().resourceDetail().resourceYaml().checkVisible();
});
it('can download KubeConfig', () => {
cy.deleteDownloadsFolder();
clusterList.goTo();
cy.intercept('POST', '/v1/ext.cattle.io.kubeconfigs').as('generateKubeconfig');
clusterList.list().actionMenu(rke2CustomName).getMenuItem('Download KubeConfig').click();
cy.wait('@generateKubeconfig').its('response.statusCode').should('be.oneOf', [200, 201]);
const downloadedFilename = path.join(downloadsFolder, `${ rke2CustomName }.yaml`);
cy.readFile(downloadedFilename).then((buffer) => {
// This will throw an exception which will fail the test if not valid yaml
const obj: any = jsyaml.load(buffer);
// Basic checks on the downloaded YAML
expect(obj.clusters.some((cluster: { name: string }) => cluster.name === rke2CustomName)).to.equal(true);
expect(obj.apiVersion).to.equal('v1');
expect(obj.kind).to.equal('Config');
});
});
it('can download YAML', () => {
// Delete downloads directory. Need a fresh start to avoid conflicting file names
cy.deleteDownloadsFolder();
ClusterManagerListPagePo.navTo();
clusterList.list().actionMenu(rke2CustomName).getMenuItem('Download YAML').click();
const downloadedFilename = path.join(downloadsFolder, `${ rke2CustomName }.yaml`);
cy.readFile(downloadedFilename).then((buffer) => {
const obj: any = jsyaml.load(buffer);
// Basic checks on the downloaded YAML
expect(obj.apiVersion).to.equal('provisioning.cattle.io/v1');
expect(obj.metadata.annotations['field.cattle.io/description']).to.equal(rke2CustomName);
expect(obj.kind).to.equal('Cluster');
});
});
it('preserves custom addon config values after saving cluster config', () => {
const customAddonConfig = `goodvalue: yay\nnested:\n enabled: true`;
const updatedDescription = `${ rke2CustomName }-addon-persist-check`;
clusterList.goTo();
clusterList.list().actionMenu(rke2CustomName).getMenuItem('Edit Config').click();
editCreatedClusterPage().waitForPage('mode=edit', 'basic');
editCreatedClusterPage().clusterConfigurationTabs().clickTabWithSelector('#rke2-calico');
editCreatedClusterPage().calicoAddonConfig().yamlEditor().input()
.set(customAddonConfig);
editCreatedClusterPage().save();
clusterList.waitForPage();
clusterList.list().actionMenu(rke2CustomName).getMenuItem('Edit Config').click();
editCreatedClusterPage().waitForPage('mode=edit', 'basic');
editCreatedClusterPage().nameNsDescription().description().set(updatedDescription);
editCreatedClusterPage().save();
clusterList.waitForPage();
clusterList.list().actionMenu(rke2CustomName).getMenuItem('Edit Config').click();
editCreatedClusterPage().waitForPage('mode=edit', 'basic');
editCreatedClusterPage().clusterConfigurationTabs().clickTabWithSelector('#rke2-calico');
editCreatedClusterPage().calicoAddonConfig().yamlEditor().input()
.value()
.should('equal', customAddonConfig);
});
it('can delete cluster', () => {
clusterList.goTo();
clusterList.sortableTable().rowElementWithName(rke2CustomName).should('exist', MEDIUM_TIMEOUT_OPT);
clusterList.list().actionMenu(rke2CustomName).getMenuItem('Delete').click();
const promptRemove = new PromptRemove();
promptRemove.confirm(rke2CustomName);
promptRemove.remove();
clusterList.waitForPage();
clusterList.sortableTable().rowElementWithName(rke2CustomName).should('not.exist');
});
});
});
describe('Imported', { tags: ['@jenkins', '@importedCluster', '@provisioning'] }, () => {
const importClusterPage = new ClusterManagerImportGenericPagePo();
const fqdn = 'fqdn';
const cacert = 'cacert';
const privateRegistry = 'registry.io';
describe('Generic', () => {
it('can create new cluster', () => {
importGenericName = createClusterTestName('import-generic');
cy.intercept('GET', `${ USERS_BASE_URL }?*`).as('getUsers');
cy.intercept('POST', `/v3/${ importType }s`).as('importRequest');
clusterList.goTo();
clusterList.checkIsCurrentPage();
clusterList.importCluster();
importClusterPage.waitForPage('mode=import');
importClusterPage.selectGeneric(0);
// Verify that we only show when editing
importClusterPage.waitForPage('mode=import&type=import&rkeType=rke2');
cy.wait('@getUsers');
// check accordions are displayed or not
importClusterPage.accordion(2, 'Basics').should('be.visible');
importClusterPage.accordion(3, 'Member Roles').should('be.visible');
importClusterPage.accordion(4, 'Labels and Annotations').scrollIntoView().should('be.visible');
importClusterPage.accordion(5, 'Registries').scrollIntoView().should('be.visible');
importClusterPage.accordion(6, 'Advanced').scrollIntoView().should('be.visible');
importClusterPage.networkingAccordion().should('not.exist');
importClusterPage.nameNsDescription().name().checkVisible();
importClusterPage.nameNsDescription().name().set(importGenericName);
// Issue #13614: Imported Cluster Version Mgmt: Conditionally show warning message
importClusterPage.versionManagementBanner().should('exist').and('be.visible');
importClusterPage.create();
cy.wait('@importRequest').then((intercept) => {
expect(intercept.response.statusCode).to.eq(201);
expect(intercept.request.body).to.deep.equal({
type: importType,
agentEnvVars: [],
annotations: { 'rancher.io/imported-cluster-version-management': 'system-default' },
importedConfig: { privateRegistryURL: null },
labels: {},
name: importGenericName
});
});
cy.getClusterIdByName(importGenericName).then((clusterId) => {
const detailClusterPage = new ClusterManagerDetailImportedGenericPagePo(undefined, clusterId);
detailClusterPage.waitForPage(undefined, 'registration');
detailClusterPage.kubectlCommandForImported().contains('--insecure').then(($value) => {
const kubectlCommand = $value.text();
expect(kubectlCommand).to.contain('--insecure');
cy.log(kubectlCommand);
cy.exec(kubectlCommand, { failOnNonZeroExit: false, timeout: RESTART_TIMEOUT_OPT.timeout }).then((result) => {
cy.log(result.stderr);
cy.log(result.stdout);
expect(result.code).to.eq(0);
});
});
});
ClusterManagerListPagePo.navTo();
clusterList.waitForPage();
clusterList.list().state(importGenericName).should('be.visible', EXTRA_LONG_TIMEOUT_OPT)
.and(($el) => {
const status = $el.text().trim();
expect(['Provisioning', 'Waiting']).to.include(status);
});
clusterList.list().state(importGenericName).contains('Active', EXTRA_LONG_TIMEOUT_OPT);
// Issue #6836: Provider field on Imported clusters states "Imported" instead of cluster type
clusterList.list().provider(importGenericName).should('contain.text', 'Imported');
clusterList.list().providerSubType(importGenericName).should('contain.text', 'K3s');
});
it('creation page should include a table of contents containing an entry for each Accordion on the page', () => {
cy.intercept('GET', `${ USERS_BASE_URL }?*`).as('getUsers');
clusterList.goTo();
clusterList.checkIsCurrentPage();
clusterList.importCluster();
importClusterPage.waitForPage('mode=import');
importClusterPage.selectGeneric(0);
importClusterPage.waitForPage('mode=import&type=import&rkeType=rke2');
cy.wait('@getUsers');
// verify that the table of contents is shown and contains the same number of entries as there are accordions on the page
cy.get('[data-testid="accordion-header"]')
.its('length')
.then((accordionHeaderCount) => {
cy.get('[data-testid^="toc-list-item-"]')
.should('have.length', accordionHeaderCount);
});
// verify that clicking an accordion label in the table of contents scrolls the page to the associated accordion and opens it
cy.get('[data-testid="toc-list-item-3"] button').click();
cy.window().its('scrollY').should('be.greaterThan', 0);
cy.get('[data-testid="registries-accordion"]')
.find('[data-testid="accordion-body"]')
.should('be.visible');
});
it('can edit imported cluster and see changes afterwards', () => {
cy.getClusterIdByName(importGenericName).then((clusterId) => {
const editImportedClusterPage = new ClusterManagerEditImportedPagePo(undefined, 'fleet-default', clusterId);
cy.intercept('GET', `${ USERS_BASE_URL }?*`).as('pageLoad');
clusterList.goTo();
clusterList.list().actionMenu(importGenericName).getMenuItem('Edit Config').click();
editImportedClusterPage.waitForPage('mode=edit');
editImportedClusterPage.nameNsDescription().name().value().should('eq', importGenericName);
cy.wait('@pageLoad');
// check accordions are properly displayed
editImportedClusterPage.accordion(2, 'K3S Options').should('be.visible');
editImportedClusterPage.accordion(3, 'Member Roles').should('be.visible');
editImportedClusterPage.accordion(4, 'Labels and Annotations').scrollIntoView().should('be.visible');
editImportedClusterPage.accordion(5, 'Networking').scrollIntoView().should('be.visible');
editImportedClusterPage.accordion(6, 'Registries').scrollIntoView().should('be.visible');
editImportedClusterPage.accordion(7, 'Advanced').scrollIntoView().should('be.visible');
// Issue #10432: Edit Cluster screen falsely gives impression imported cluster's name and description can be edited
editImportedClusterPage.nameNsDescription().name().expectToBeDisabled();
// Issue #13614: Imported Cluster Version Mgmt: Conditionally show warning message
editImportedClusterPage.versionManagementBanner().should('not.exist');
editImportedClusterPage.enableVersionManagement();
editImportedClusterPage.versionManagementBanner().should('exist').and('be.visible');
editImportedClusterPage.defaultVersionManagement();
editImportedClusterPage.toggleAccordion(5, 'Networking');
editImportedClusterPage.ace().enable();
editImportedClusterPage.ace().enterFdqn(fqdn);
editImportedClusterPage.ace().enterCaCerts(cacert);
editImportedClusterPage.toggleAccordion(6, 'Registries');
editImportedClusterPage.enablePrivateRegistryCheckbox();
editImportedClusterPage.privateRegistry().set(privateRegistry);
editImportedClusterPage.save();
// We should be taken back to the list page if the save was successful
clusterList.waitForPage();
clusterList.list().actionMenu(importGenericName).getMenuItem('Edit Config').click();
editImportedClusterPage.waitForPage('mode=edit');
editImportedClusterPage.ace().fqdn().value().should('eq', fqdn );
editImportedClusterPage.ace().caCerts().value().should('eq', cacert );
// Verify the private registry values
editImportedClusterPage.privateRegistryCheckbox().isChecked();
editImportedClusterPage.privateRegistry().value().should('eq', privateRegistry);
});
});
it('can delete cluster by bulk actions', () => {
clusterList.goTo();
clusterList.sortableTable().rowElementWithName(importGenericName).should('exist', MEDIUM_TIMEOUT_OPT);
clusterList.sortableTable().rowSelectCtlWithName(importGenericName).set();
clusterList.sortableTable().bulkActionDropDownOpen();
clusterList.sortableTable().bulkActionDropDownButton('Delete').click();
const promptRemove = new PromptRemove();
promptRemove.confirm(importGenericName);
promptRemove.remove();
clusterList.waitForPage();
clusterList.sortableTable().rowElementWithName(importGenericName).should('not.exist');
});
});
});
it('can navigate to Cluster Management Page', () => {
HomePagePo.goTo();
const burgerMenu = new BurgerMenuPo();
BurgerMenuPo.toggle();
const clusterManagementNavItem = burgerMenu.links().contains(`Cluster Management`);
clusterManagementNavItem.should('exist');
clusterManagementNavItem.click();
const clusterList = new ClusterManagerListPagePo('_');
clusterList.waitForPage();
});
describe('Cluster Details Page and Tabs', () => {
const tabbedPo = new TabbedPo('[data-testid="tabbed-block"]');
const clusterDetail = new ClusterManagerDetailImportedGenericPagePo(undefined, 'local');
beforeEach( () => {
ClusterManagerListPagePo.navTo();
const clusterList = new ClusterManagerListPagePo('_');
clusterList.waitForPage();
clusterList.list().resourceTable().sortableTable().filter('local', 100);
clusterList.waitForPage('q=local');
clusterList.goToDetailsPage('local', '.cluster-link a');
clusterDetail.waitForPage();
});
it('can navigate to Cluster Conditions Page', () => {
clusterDetail.selectTab(tabbedPo, '[data-testid="btn-conditions"]');
clusterDetail.waitForPage(undefined, 'conditions');
clusterDetail.conditionsList().details('Created', 1).should('include.text', 'True');
});
it('can navigate to Cluster Related Page', () => {
clusterDetail.selectTab(tabbedPo, '[data-testid="btn-related"]');
clusterDetail.waitForPage(undefined, 'related');
clusterDetail.referredToList().details('Mgmt', 2).should('include.text', 'local');
});
it('can navigate to Cluster Provisioning Log Page', () => {
clusterDetail.selectTab(tabbedPo, '[data-testid="btn-log"]');
clusterDetail.waitForPage(undefined, 'log');
clusterDetail.logsContainer().should('be.visible');
});
it('can navigate to Cluster Machines Page', () => {
clusterDetail.selectTab(tabbedPo, '[data-testid="btn-node-pools"]');
clusterDetail.waitForPage(undefined, 'node-pools');
clusterDetail.poolsList('node').details('machine-', 2).should('be.visible');
clusterDetail.poolsList('node').downloadYamlButton().should('be.disabled');
});
it(`Show Configuration allows to edit config and view yaml for local cluster`, () => {
clusterDetail.openShowConfiguration();
const drawer = clusterDetail.detailDrawer();
drawer.checkExists();
drawer.checkVisible();
drawer.saveButton().should('be.visible');
const tabs = ['Config', 'YAML'];
drawer.tabs().tabNames().each((el, i) => {
expect(el).to.eq(tabs[i]);
});
drawer.tabs().clickTabWithName('yaml-tab');
drawer.saveButton().should('not.exist');
});
it('can navigate to namespace from cluster detail view', () => {
clusterDetail.namespace().should('contain.text', 'fleet-local');
clusterDetail.namespace().click();
const nsPage = new ClusterManagerNamespacePagePo();
nsPage.waitForPage(undefined, 'Resources');
nsPage.namespace().should('contain.text', 'fleet-local');
});
});
describe('Local', () => {
it(`can open edit for local cluster`, () => {
const editLocalClusterPage = new ClusterManagerEditImportedPagePo(undefined, 'fleet-local', 'local');
cy.intercept('GET', `${ USERS_BASE_URL }?*`).as('pageLoad');
clusterList.goTo();
clusterList.list().actionMenu('local').getMenuItem('Edit Config').click();
editLocalClusterPage.waitForPage('mode=edit');
cy.wait('@pageLoad');
editLocalClusterPage.nameNsDescription().name().value().should('eq', 'local' );
// check accordions are properly displayed
editLocalClusterPage.accordion(2, 'K3S Options').should('be.visible'); // for K3S local cluster its K3S Options
editLocalClusterPage.accordion(3, 'Member Roles').scrollIntoView().should('be.visible');
editLocalClusterPage.accordion(4, 'Labels and Annotations').scrollIntoView().should('be.visible');
editLocalClusterPage.accordion(5, 'Networking').should('not.exist');
editLocalClusterPage.accordion(5, 'Registries').scrollIntoView().should('be.visible');
editLocalClusterPage.accordion(6, 'Advanced').scrollIntoView().should('be.visible');
// Issue #13614: Imported Cluster Version Mgmt: Conditionally show warning message
editLocalClusterPage.versionManagementBanner().should('not.exist');
editLocalClusterPage.enableVersionManagement();
editLocalClusterPage.versionManagementBanner().should('not.contain.text', 'This change will trigger cluster agent redeployment.');
editLocalClusterPage.disableVersionManagement();
editLocalClusterPage.versionManagementBanner().should('not.contain.text', 'This change will trigger cluster agent redeployment.');
editLocalClusterPage.cancel();
// We should be taken back to the list page if the save was successful
clusterList.waitForPage();
});
it(`can navigate to local cluster's explore product`, () => {
const clusterName = 'local';
const clusterDashboard = new ClusterDashboardPagePo(clusterName);
clusterList.goTo();
clusterList.list().explore(clusterName).click();
clusterDashboard.waitForPage(undefined, 'cluster-events');
});
});
it('can download YAML via bulk actions', () => {
// Delete downloads directory. Need a fresh start to avoid conflicting file names
cy.deleteDownloadsFolder();
ClusterManagerListPagePo.navTo();
clusterList.list().resourceTable().sortableTable().rowElementWithName('local')
.click();
clusterList.list().openBulkActionDropdown();
clusterList.list().bulkActionButton('Download YAML').click({ force: true });
const downloadedFilename = path.join(downloadsFolder, `local.yaml`);
cy.readFile(downloadedFilename).then((buffer) => {
const obj: any = jsyaml.load(buffer);
// Basic checks on the downloaded YAML
expect(obj.apiVersion).to.equal('provisioning.cattle.io/v1');
expect(obj.metadata.name).to.equal('local');
expect(obj.kind).to.equal('Cluster');
});
});
it('can download KubeConfig via bulk actions', () => {
// Delete downloads directory. Need a fresh start to avoid conflicting file names
cy.deleteDownloadsFolder();
ClusterManagerListPagePo.navTo();
clusterList.list().resourceTable().sortableTable().rowElementWithName('local')
.click();
cy.intercept('POST', '/v1/ext.cattle.io.kubeconfigs').as('generateKubeConfig');
clusterList.list().openBulkActionDropdown();
clusterList.list().bulkActionButton('Download KubeConfig').click();
cy.wait('@generateKubeConfig').its('response.statusCode').should('eq', 201);
const downloadedFilename = path.join(downloadsFolder, 'local.yaml');
cy.readFile(downloadedFilename).then((buffer) => {
const obj: any = jsyaml.load(buffer);
// Basic checks on the downloaded YAML
expect(obj.apiVersion).to.equal('v1');
expect(obj.clusters[1].name).to.equal('local');
expect(obj.kind).to.equal('Config');
});
});
it('can connect to kubectl shell', () => {
ClusterManagerListPagePo.navTo();
clusterList.list().actionMenu('local').getMenuItem('Kubectl Shell').click();
const shellPo = new Shell();
shellPo.terminalStatus('Connected');
shellPo.closeTerminal();
});
describe('Credential Step', () => {
const drivers = ['nutanix', 'oci'];
Cypress._.each(drivers, (driver) => {
describe(`should always show credentials for ${ driver } driver`, () => {
it('should show credential step when `addCloudCredential` is true', () => {
cy.intercept({
method: 'GET',
path: `/v1/management.cattle.io.nodedrivers*`,
}, (req) => {
req.continue((res) => {
res.body.data = nodeDriveResponse(true, driver).data;
});
});
const clusterCreate = new ClusterManagerCreatePagePo();
clusterCreate.goTo(`type=${ driver }&rkeType=rke2`);
clusterCreate.waitForPage();
clusterCreate.credentialsBanner().checkExists();
});
it('should show credential step when `addCloudCredential` is false', () => {
cy.intercept({
method: 'GET',
path: `/v1/management.cattle.io.nodedrivers*`,
}, (req) => {
req.continue((res) => {
res.body.data = nodeDriveResponse(false, driver).data;
});
});
const clusterCreate = new ClusterManagerCreatePagePo();
clusterCreate.goTo(`type=${ driver }&rkeType=rke2`);
clusterCreate.waitForPage();
clusterCreate.credentialsBanner().checkExists();
});
});
});
const driver2 = 'outscale';
describe('should show on condition of addCloudCredential', () => {
it('should show credential step when `addCloudCredential` is true', () => {
cy.intercept({
method: 'GET',
path: `/v1/management.cattle.io.nodedrivers*`,
}, (req) => {
req.continue((res) => {
res.body.data = nodeDriveResponse(true, driver2).data;
});
});
const clusterCreate = new ClusterManagerCreatePagePo();
clusterCreate.goTo(`type=${ driver2 }&rkeType=rke2`);
clusterCreate.waitForPage();
clusterCreate.credentialsBanner().checkExists();
});
it('should NOT show credential step when `addCloudCredential` is false', () => {
cy.intercept({
method: 'GET',
path: `/v1/management.cattle.io.nodedrivers*`,
}, (req) => {
req.continue((res) => {
res.body.data = nodeDriveResponse(false, driver2).data;
});
});
const clusterCreate = new ClusterManagerCreatePagePo();
clusterCreate.goTo(`type=${ driver2 }&rkeType=rke2`);
clusterCreate.waitForPage();
clusterCreate.credentialsBanner().checkNotExists();
});
});
});
after(() => {
if (reenableAKS) {
cy.setRancherResource('v1', 'management.cattle.io.settings', 'kev2-operators', { value: originalSettings });
}
});
});
describe('Cluster Manager as standard user', { testIsolation: 'off', tags: ['@manager', '@standardUser'] }, () => {
before(() => {
cy.login();
});
it('can navigate to Cluster Management Page', () => {
HomePagePo.goTo();
const burgerMenu = new BurgerMenuPo();
BurgerMenuPo.toggle();
const clusterManagementNavItem = burgerMenu.links().contains(`Cluster Management`);
clusterManagementNavItem.should('exist');
clusterManagementNavItem.click();
const clusterList = new ClusterManagerListPagePo('_');
clusterList.waitForPage();
});
describe('Cluster Detail Page', () => {
const clusterDetail = new ClusterManagerDetailImportedGenericPagePo(undefined, 'local');
beforeEach( () => {
ClusterManagerListPagePo.navTo();
const clusterList = new ClusterManagerListPagePo('_');
clusterList.waitForPage();
clusterList.goToDetailsPage('local', '.cluster-link a');
});
it(`Show Configuration allows to view but not edit config and yaml for local cluster`, () => {
clusterDetail.waitForPage();
clusterDetail.openShowConfiguration();
const drawer = clusterDetail.detailDrawer();
drawer.checkExists();
drawer.checkVisible();
drawer.saveButton().should('not.exist');
const tabs = ['Config', 'YAML'];
drawer.tabs().tabNames().each((el, i) => {
expect(el).to.eq(tabs[i]);
});
drawer.tabs().clickTabWithName('yaml-tab');
drawer.saveButton().should('not.exist');
});
it('Shows the explore button and navigates to the cluster explorer when clicked', () => {
clusterDetail.waitForPage();
clusterDetail.exploreButton().should('exist');
clusterDetail.exploreButton().click();
cy.url().should('include', '/c/local/explorer');
});
});
});
describe('Visual Testing', { tags: ['@percy', '@manager', '@adminUser'] }, () => {
before(() => {
cy.login();
cy.applyDefaultTestTheme();
});
it('should display cluster manager page', () => {
const clusterList = new ClusterManagerListPagePo();
clusterList.goTo();
clusterList.checkIsCurrentPage();
clusterList.sortableTable().checkVisible();
clusterList.sortableTable().checkLoadingIndicatorNotVisible();
clusterList.sortableTable().noRowsShouldNotExist();
// hide elements before taking percy snapshot
cy.hideElementBySelector('[data-testid="nav_header_showUserMenu"]', 'td.col-live-date span.live-date');
// takes percy snapshot.
cy.percySnapshot('cluster manager list page');
});
after(() => {
cy.restoreProductDefaultTestTheme();
});
});