From e60977543889431e0460976b9fe607a253753a21 Mon Sep 17 00:00:00 2001 From: Isabela Guimaraes Date: Mon, 23 Dec 2024 04:30:47 -0800 Subject: [PATCH 1/7] e2e test that creates GKE cluster with default settings Signed-off-by: Isabela Guimaraes --- cypress.config.ts | 4 +- .../po/components/button-file-selector.po.ts | 12 ++ .../e2e/po/components/labeled-select.po.ts | 8 ++ .../e2e/po/edit/base-cloud-credentials.po.ts | 4 + .../e2e/po/edit/cloud-credentials-gke.po.ts | 13 ++ .../create/cluster-create-gke.po.ts | 34 ++++++ .../manager/gke-cluster-provisioning.spec.ts | 113 ++++++++++++++++++ pkg/gke/components/CruGKE.vue | 10 +- 8 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 cypress/e2e/po/components/button-file-selector.po.ts create mode 100644 cypress/e2e/po/edit/cloud-credentials-gke.po.ts create mode 100644 cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts create mode 100644 cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts diff --git a/cypress.config.ts b/cypress.config.ts index dcf8600021b..e39457b3ec5 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -94,7 +94,9 @@ export default defineConfig({ azureClientId: process.env.AZURE_CLIENT_ID, azureClientSecret: process.env.AZURE_CLIENT_SECRET, customNodeIp: process.env.CUSTOM_NODE_IP, - customNodeKey: process.env.CUSTOM_NODE_KEY + customNodeKey: process.env.CUSTOM_NODE_KEY, + gkeServiceAccount: process.env.GKE_SERVICE_ACCOUNT, + gkeProjectId: process.env.GKE_PROJECT_ID }, e2e: { fixturesFolder: 'cypress/e2e/blueprints', diff --git a/cypress/e2e/po/components/button-file-selector.po.ts b/cypress/e2e/po/components/button-file-selector.po.ts new file mode 100644 index 00000000000..a9071caff5d --- /dev/null +++ b/cypress/e2e/po/components/button-file-selector.po.ts @@ -0,0 +1,12 @@ +import ComponentPo from '@/cypress/e2e/po/components/component.po'; + +export default class ButtonFileSelectorPo extends ComponentPo { + /** + * Returns a file-selector button + * @param id + * @returns + */ + static readFromFileButton(): Cypress.Chainable { + return cy.getId('file-selector__uploader-button'); + } +} diff --git a/cypress/e2e/po/components/labeled-select.po.ts b/cypress/e2e/po/components/labeled-select.po.ts index 5768df906af..fd6e39f96dd 100644 --- a/cypress/e2e/po/components/labeled-select.po.ts +++ b/cypress/e2e/po/components/labeled-select.po.ts @@ -69,4 +69,12 @@ export default class LabeledSelectPo extends ComponentPo { filterByName(name: string) { return this.self().type(name); } + + static getGkeVersionSelect() { + return new LabeledSelectPo('[data-testid="gke-version-select"]'); + } + + static getGkeZoneSelect() { + return new LabeledSelectPo('[data-testid="gke-zone-select"]'); + } } diff --git a/cypress/e2e/po/edit/base-cloud-credentials.po.ts b/cypress/e2e/po/edit/base-cloud-credentials.po.ts index 42738cf040b..c9c54faf970 100644 --- a/cypress/e2e/po/edit/base-cloud-credentials.po.ts +++ b/cypress/e2e/po/edit/base-cloud-credentials.po.ts @@ -34,4 +34,8 @@ export default class BaseCloudCredentialsPo extends PagePo { saveButton() { return new AsyncButtonPo('[data-testid="form-save"]', this.self()); } + + authenticateButton() { + return new AsyncButtonPo('[data-testid="action-button-async-button"]', this.self()); + } } diff --git a/cypress/e2e/po/edit/cloud-credentials-gke.po.ts b/cypress/e2e/po/edit/cloud-credentials-gke.po.ts new file mode 100644 index 00000000000..3d0510f3d84 --- /dev/null +++ b/cypress/e2e/po/edit/cloud-credentials-gke.po.ts @@ -0,0 +1,13 @@ +import LabeledInputPo from '@/cypress/e2e/po/components/labeled-input.po'; +import ButtonFileSelectorPo from '@/cypress/e2e/po/components/button-file-selector.po'; +import BaseCloudCredentialsPo from '@/cypress/e2e/po/edit/base-cloud-credentials.po'; + +export default class GKECloudCredentialsCreateEditPo extends BaseCloudCredentialsPo { + serviceAccount(): LabeledInputPo { + return LabeledInputPo.byLabel(this.self(), 'Service Account'); + } + + readFromFile(): Cypress.Chainable { + return ButtonFileSelectorPo.readFromFileButton().click(); + } +} diff --git a/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts b/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts new file mode 100644 index 00000000000..8c14f1e5726 --- /dev/null +++ b/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts @@ -0,0 +1,34 @@ +import PagePo from '@/cypress/e2e/po/pages/page.po'; +import ClusterManagerCreatePagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create.po'; +import LabeledInputPo from '@/cypress/e2e/po/components/labeled-input.po'; +import GKECloudCredentialsCreateEditPo from '@/cypress/e2e/po/edit/cloud-credentials-gke.po'; +import AsyncButtonPo from '@/cypress/e2e/po/components/async-button.po'; + +/** + * Create page for a GKE cluster + */ +export default class ClusterManagerCreateGKEPagePo extends ClusterManagerCreatePagePo { + static url(clusterId: string) { + return `${ ClusterManagerCreatePagePo.url(clusterId) }/create?type=googlegke`; + } + + static goTo(clusterId: string): Cypress.Chainable { + return PagePo.goTo(ClusterManagerCreateGKEPagePo.url(clusterId)); + } + + goToGKEClusterCreation(clusterId: string): Cypress.Chainable { + return PagePo.goTo(`${ ClusterManagerCreatePagePo.url(clusterId) }?type=googlegke`); + } + + cloudCredentialsForm(): GKECloudCredentialsCreateEditPo { + return new GKECloudCredentialsCreateEditPo(); + } + + authProjectId(): LabeledInputPo { + return LabeledInputPo.byLabel(this.self(), 'Google Project ID'); + } + + saveCreateGkeCluster(): AsyncButtonPo { + return new AsyncButtonPo('[data-testid="form-save"]', this.self()); + } +} diff --git a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts new file mode 100644 index 00000000000..598eee8ea79 --- /dev/null +++ b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts @@ -0,0 +1,113 @@ +import HomePagePo from '@/cypress/e2e/po/pages/home.po'; +import ClusterManagerListPagePo from '@/cypress/e2e/po/pages/cluster-manager/cluster-manager-list.po'; +import LoadingPo from '@/cypress/e2e/po/components/loading.po'; +import ClusterManagerCreateGKEPagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po'; +import LabeledSelectPo from '@/cypress/e2e/po/components/labeled-select.po'; +import { DEFAULT_GCP_ZONE } from '@/pkg/gke/util/gcp'; + +// will only run this in jenkins pipeline where cloud credentials are stored +describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@adminUser', '@standardUser', '@jenkins'] }, () => { + const clusterList = new ClusterManagerListPagePo(); + const loadingPo = new LoadingPo('.loading-indicator'); + + let cloudcredentialId = ''; + const gkeDefaultZone = 'us-central1-c'; + let gkeVersion = ''; + // clusterId commented out as it will be used for the next tests of this suite, but not being used by the current test + // let clusterId = ''; + let clusterDescription = ''; + + before(() => { + cy.login(); + HomePagePo.goTo(); + + // clean up GKE cloud credentials + cy.getRancherResource('v3', 'cloudcredentials', null, null).then((resp: Cypress.Response) => { + const body = resp.body; + + if (body.pagination['total'] > 0) { + body.data.forEach((item: any) => { + if (item.googlecredentialConfig) { + const id = item.id; + + cy.deleteRancherResource('v3', 'cloudcredentials', id); + } else { + cy.log('There are no existing GKE cloud credentials to delete'); + } + }); + } + }); + }); + + beforeEach(() => { + cy.createE2EResourceName('gkecluster').as('gkeClusterName'); + cy.createE2EResourceName('gkecloudcredential').as('gkeCloudCredentialName'); + }); + + it('Successfully create GKE cluster with default settings', function() { + const createGKEClusterPage = new ClusterManagerCreateGKEPagePo(); + const cloudCredForm = createGKEClusterPage.cloudCredentialsForm(); + + // Select GKE and create GKE cluster page + ClusterManagerListPagePo.navTo(); + clusterList.waitForPage(); + clusterList.createCluster(); + createGKEClusterPage.selectKubeProvider(2); + loadingPo.checkNotExists(); + createGKEClusterPage.rke2PageTitle().should('include', 'Create Google GKE'); + createGKEClusterPage.waitForPage('type=googlegke&rkeType=rke2'); + + // create GKE cloud credential + cloudCredForm.saveButton().expectToBeDisabled(); + cloudCredForm.nameNsDescription().name().set(this.gkeCloudCredentialName); + cloudCredForm.serviceAccount().set(Cypress.env('gkeServiceAccount')); + cloudCredForm.saveButton().expectToBeEnabled(); + cy.intercept('GET', '/v1/management.cattle.io.users?exclude=metadata.managedFields').as('pageLoad'); + cloudCredForm.saveCreateForm().cruResource().saveAndWaitForRequests('POST', '/v3/cloudcredentials').then((req) => { + expect(req.response?.statusCode).to.equal(201); + cloudcredentialId = req.response?.body.id.replace(':', '%3A'); + + // Authenticate GKE credential by providing the Project ID + createGKEClusterPage.waitForPage('type=googlegke&rkeType=rke2'); + createGKEClusterPage.authProjectId().set(Cypress.env('gkeProjectId')); + cy.intercept('POST', `/meta/gkeVersions?cloudCredentialId=${ cloudcredentialId }&projectId=${ Cypress.env('gkeProjectId') }&zone=${ gkeDefaultZone }`).as('getGKEVersions'); + cloudCredForm.authenticateButton().click(); + cy.wait('@pageLoad').its('response.statusCode').should('eq', 200); + loadingPo.checkNotExists(); + + // Verify that gke-zone-select dropdown is set to the default zone + createGKEClusterPage.waitForPage('type=googlegke&rkeType=rke2'); + LabeledSelectPo.getGkeZoneSelect().checkOptionSelected(DEFAULT_GCP_ZONE); + + // Get latest GKE kubernetes version and verify that gke-version-select dropdown is set to the default version as defined by versionOptions(); in Config.vue + cy.wait('@getGKEVersions').then(({ response }) => { + expect(response.statusCode).to.eq(200); + gkeVersion = response.body.validMasterVersions[0]; + cy.wrap(gkeVersion).as('gkeVersion'); + LabeledSelectPo.getGkeVersionSelect().checkOptionSelected(gkeVersion); + }); + + // Set the cluster name and description in the Create GKE Page + createGKEClusterPage.nameNsDescription().name().set(this.gkeClusterName); + clusterDescription = `${ this.gkeClusterName }-description`; + createGKEClusterPage.nameNsDescription().description().set(clusterDescription); + }); + + // Create GKE Cluster and verify that the properties posted to the server match the expected settings + cy.intercept('POST', 'v3/clusters').as('createGKECluster'); + + createGKEClusterPage.saveCreateGkeCluster().click(); + cy.wait('@createGKECluster').then(({ response }) => { + expect(response?.statusCode).to.eq(201); + expect(response?.body).to.have.property('baseType', 'cluster'); + expect(response?.body.gkeConfig).to.have.property('clusterName', this.gkeClusterName); + expect(response?.body).to.have.property('description', clusterDescription); + expect(response?.body.gkeConfig).to.have.property('kubernetesVersion').contains(gkeVersion); + // clusterId = response?.body.id; + }); + + // Verify that the GKE created cluster is listed in the clusters list and has the Provisioning status + clusterList.waitForPage(); + clusterList.list().state(this.gkeClusterName).should('contain.text', 'Provisioning'); + }); +}); diff --git a/pkg/gke/components/CruGKE.vue b/pkg/gke/components/CruGKE.vue index 2ea85145e4c..81ad059495a 100644 --- a/pkg/gke/components/CruGKE.vue +++ b/pkg/gke/components/CruGKE.vue @@ -697,7 +697,10 @@ export default defineComponent({
-
+
-
+
Date: Wed, 1 Jan 2025 21:33:07 -0800 Subject: [PATCH 2/7] addressed changes requested from PR review Signed-off-by: Isabela Guimaraes --- cypress.config.ts | 1 - cypress/e2e/po/components/labeled-select.po.ts | 8 -------- cypress/e2e/po/edit/base-cloud-credentials.po.ts | 4 ---- cypress/e2e/po/edit/cloud-credentials-gke.po.ts | 5 +++++ .../create/cluster-create-gke.po.ts | 9 +++++++++ .../pages/manager/gke-cluster-provisioning.spec.ts | 11 +++++------ 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cypress.config.ts b/cypress.config.ts index e39457b3ec5..2b75ff0e4bf 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -96,7 +96,6 @@ export default defineConfig({ customNodeIp: process.env.CUSTOM_NODE_IP, customNodeKey: process.env.CUSTOM_NODE_KEY, gkeServiceAccount: process.env.GKE_SERVICE_ACCOUNT, - gkeProjectId: process.env.GKE_PROJECT_ID }, e2e: { fixturesFolder: 'cypress/e2e/blueprints', diff --git a/cypress/e2e/po/components/labeled-select.po.ts b/cypress/e2e/po/components/labeled-select.po.ts index fd6e39f96dd..5768df906af 100644 --- a/cypress/e2e/po/components/labeled-select.po.ts +++ b/cypress/e2e/po/components/labeled-select.po.ts @@ -69,12 +69,4 @@ export default class LabeledSelectPo extends ComponentPo { filterByName(name: string) { return this.self().type(name); } - - static getGkeVersionSelect() { - return new LabeledSelectPo('[data-testid="gke-version-select"]'); - } - - static getGkeZoneSelect() { - return new LabeledSelectPo('[data-testid="gke-zone-select"]'); - } } diff --git a/cypress/e2e/po/edit/base-cloud-credentials.po.ts b/cypress/e2e/po/edit/base-cloud-credentials.po.ts index c9c54faf970..42738cf040b 100644 --- a/cypress/e2e/po/edit/base-cloud-credentials.po.ts +++ b/cypress/e2e/po/edit/base-cloud-credentials.po.ts @@ -34,8 +34,4 @@ export default class BaseCloudCredentialsPo extends PagePo { saveButton() { return new AsyncButtonPo('[data-testid="form-save"]', this.self()); } - - authenticateButton() { - return new AsyncButtonPo('[data-testid="action-button-async-button"]', this.self()); - } } diff --git a/cypress/e2e/po/edit/cloud-credentials-gke.po.ts b/cypress/e2e/po/edit/cloud-credentials-gke.po.ts index 3d0510f3d84..ac12651f3e6 100644 --- a/cypress/e2e/po/edit/cloud-credentials-gke.po.ts +++ b/cypress/e2e/po/edit/cloud-credentials-gke.po.ts @@ -1,6 +1,7 @@ import LabeledInputPo from '@/cypress/e2e/po/components/labeled-input.po'; import ButtonFileSelectorPo from '@/cypress/e2e/po/components/button-file-selector.po'; import BaseCloudCredentialsPo from '@/cypress/e2e/po/edit/base-cloud-credentials.po'; +import AsyncButtonPo from '@/cypress/e2e/po/components/async-button.po'; export default class GKECloudCredentialsCreateEditPo extends BaseCloudCredentialsPo { serviceAccount(): LabeledInputPo { @@ -10,4 +11,8 @@ export default class GKECloudCredentialsCreateEditPo extends BaseCloudCredential readFromFile(): Cypress.Chainable { return ButtonFileSelectorPo.readFromFileButton().click(); } + + authenticateButton() { + return new AsyncButtonPo('[data-testid="action-button-async-button"]', this.self()); + } } diff --git a/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts b/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts index 8c14f1e5726..b839c9d9b6d 100644 --- a/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts +++ b/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts @@ -1,6 +1,7 @@ import PagePo from '@/cypress/e2e/po/pages/page.po'; import ClusterManagerCreatePagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create.po'; import LabeledInputPo from '@/cypress/e2e/po/components/labeled-input.po'; +import LabeledSelectPo from '@/cypress/e2e/po/components/labeled-select.po'; import GKECloudCredentialsCreateEditPo from '@/cypress/e2e/po/edit/cloud-credentials-gke.po'; import AsyncButtonPo from '@/cypress/e2e/po/components/async-button.po'; @@ -31,4 +32,12 @@ export default class ClusterManagerCreateGKEPagePo extends ClusterManagerCreateP saveCreateGkeCluster(): AsyncButtonPo { return new AsyncButtonPo('[data-testid="form-save"]', this.self()); } + + static getGkeVersionSelect() { + return new LabeledSelectPo('[data-testid="gke-version-select"]'); + } + + static getGkeZoneSelect() { + return new LabeledSelectPo('[data-testid="gke-zone-select"]'); + } } diff --git a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts index 598eee8ea79..f05f7766fe7 100644 --- a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts +++ b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts @@ -2,7 +2,6 @@ import HomePagePo from '@/cypress/e2e/po/pages/home.po'; import ClusterManagerListPagePo from '@/cypress/e2e/po/pages/cluster-manager/cluster-manager-list.po'; import LoadingPo from '@/cypress/e2e/po/components/loading.po'; import ClusterManagerCreateGKEPagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po'; -import LabeledSelectPo from '@/cypress/e2e/po/components/labeled-select.po'; import { DEFAULT_GCP_ZONE } from '@/pkg/gke/util/gcp'; // will only run this in jenkins pipeline where cloud credentials are stored @@ -16,6 +15,7 @@ describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@admi // clusterId commented out as it will be used for the next tests of this suite, but not being used by the current test // let clusterId = ''; let clusterDescription = ''; + const gkeProjectId = JSON.parse(Cypress.env('gkeServiceAccount')).project_id; before(() => { cy.login(); @@ -69,22 +69,22 @@ describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@admi // Authenticate GKE credential by providing the Project ID createGKEClusterPage.waitForPage('type=googlegke&rkeType=rke2'); - createGKEClusterPage.authProjectId().set(Cypress.env('gkeProjectId')); - cy.intercept('POST', `/meta/gkeVersions?cloudCredentialId=${ cloudcredentialId }&projectId=${ Cypress.env('gkeProjectId') }&zone=${ gkeDefaultZone }`).as('getGKEVersions'); + createGKEClusterPage.authProjectId().set( gkeProjectId ); + cy.intercept('POST', `/meta/gkeVersions?cloudCredentialId=${ cloudcredentialId }&projectId=${ gkeProjectId }&zone=${ gkeDefaultZone }`).as('getGKEVersions'); cloudCredForm.authenticateButton().click(); cy.wait('@pageLoad').its('response.statusCode').should('eq', 200); loadingPo.checkNotExists(); // Verify that gke-zone-select dropdown is set to the default zone createGKEClusterPage.waitForPage('type=googlegke&rkeType=rke2'); - LabeledSelectPo.getGkeZoneSelect().checkOptionSelected(DEFAULT_GCP_ZONE); + ClusterManagerCreateGKEPagePo.getGkeZoneSelect().checkOptionSelected(DEFAULT_GCP_ZONE); // Get latest GKE kubernetes version and verify that gke-version-select dropdown is set to the default version as defined by versionOptions(); in Config.vue cy.wait('@getGKEVersions').then(({ response }) => { expect(response.statusCode).to.eq(200); gkeVersion = response.body.validMasterVersions[0]; cy.wrap(gkeVersion).as('gkeVersion'); - LabeledSelectPo.getGkeVersionSelect().checkOptionSelected(gkeVersion); + ClusterManagerCreateGKEPagePo.getGkeVersionSelect().checkOptionSelected(gkeVersion); }); // Set the cluster name and description in the Create GKE Page @@ -103,7 +103,6 @@ describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@admi expect(response?.body.gkeConfig).to.have.property('clusterName', this.gkeClusterName); expect(response?.body).to.have.property('description', clusterDescription); expect(response?.body.gkeConfig).to.have.property('kubernetesVersion').contains(gkeVersion); - // clusterId = response?.body.id; }); // Verify that the GKE created cluster is listed in the clusters list and has the Provisioning status From 25bf4ac3d8b187babf04107c54ee70f59453e10c Mon Sep 17 00:00:00 2001 From: Isabela Guimaraes Date: Wed, 8 Jan 2025 19:09:58 -0800 Subject: [PATCH 3/7] added cleanup set after the test to remove the created cluster and cloud credentials Signed-off-by: Isabela Guimaraes --- .../manager/gke-cluster-provisioning.spec.ts | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts index f05f7766fe7..a60f7430c5a 100644 --- a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts +++ b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts @@ -4,6 +4,10 @@ import LoadingPo from '@/cypress/e2e/po/components/loading.po'; import ClusterManagerCreateGKEPagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po'; import { DEFAULT_GCP_ZONE } from '@/pkg/gke/util/gcp'; +/****** + * Running this test will delete all GKE cloud credentials from the target cluster + ******/ + // will only run this in jenkins pipeline where cloud credentials are stored describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@adminUser', '@standardUser', '@jenkins'] }, () => { const clusterList = new ClusterManagerListPagePo(); @@ -12,8 +16,7 @@ describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@admi let cloudcredentialId = ''; const gkeDefaultZone = 'us-central1-c'; let gkeVersion = ''; - // clusterId commented out as it will be used for the next tests of this suite, but not being used by the current test - // let clusterId = ''; + let clusterId = ''; let clusterDescription = ''; const gkeProjectId = JSON.parse(Cypress.env('gkeServiceAccount')).project_id; @@ -103,10 +106,34 @@ describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@admi expect(response?.body.gkeConfig).to.have.property('clusterName', this.gkeClusterName); expect(response?.body).to.have.property('description', clusterDescription); expect(response?.body.gkeConfig).to.have.property('kubernetesVersion').contains(gkeVersion); + clusterId = response?.body.id; }); // Verify that the GKE created cluster is listed in the clusters list and has the Provisioning status clusterList.waitForPage(); clusterList.list().state(this.gkeClusterName).should('contain.text', 'Provisioning'); }); + + after('clean up', () => { + // delete cluster + cy.deleteRancherResource('v1', 'provisioning.cattle.io.clusters', `fleet-default/${ clusterId }`, false); + + // clean up GKE cloud credentials + cy.getRancherResource('v3', 'cloudcredentials', null, null).then((resp: Cypress.Response) => { + const body = resp.body; + + if (body.pagination['total'] > 0) { + body.data.forEach((item: any) => { + if (item.googlecredentialConfig) { + const id = item.id; + + cy.deleteRancherResource('v3', 'cloudcredentials', id); + } else { + cy.log('There are no existing GKE cloud credentials to delete'); + } + }); + } + }); + } + ); }); From 5f7fa94fa00ecbee60f97ff1146b785ee5c2abd5 Mon Sep 17 00:00:00 2001 From: Isabela Guimaraes Date: Tue, 14 Jan 2025 17:29:43 -0800 Subject: [PATCH 4/7] modified GKE components to have an unique id Signed-off-by: Isabela Guimaraes --- .../create/cluster-create-gke.po.ts | 8 ++++++++ .../tests/pages/manager/gke-cluster-provisioning.spec.ts | 4 ++-- pkg/gke/components/CruGKE.vue | 2 -- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts b/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts index b839c9d9b6d..a2ecd46e7f7 100644 --- a/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts +++ b/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts @@ -40,4 +40,12 @@ export default class ClusterManagerCreateGKEPagePo extends ClusterManagerCreateP static getGkeZoneSelect() { return new LabeledSelectPo('[data-testid="gke-zone-select"]'); } + + getClusterName() { + return new LabeledInputPo('[data-testid="gke-cluster-name"]'); + } + + getClusterDescription() { + return new LabeledInputPo('[data-testid="gke-cluster-description"]'); + } } diff --git a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts index a60f7430c5a..e15a62eb816 100644 --- a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts +++ b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts @@ -91,9 +91,9 @@ describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@admi }); // Set the cluster name and description in the Create GKE Page - createGKEClusterPage.nameNsDescription().name().set(this.gkeClusterName); + createGKEClusterPage.getClusterName().set(this.gkeClusterName); clusterDescription = `${ this.gkeClusterName }-description`; - createGKEClusterPage.nameNsDescription().description().set(clusterDescription); + createGKEClusterPage.getClusterDescription().set(clusterDescription); }); // Create GKE Cluster and verify that the properties posted to the server match the expected settings diff --git a/pkg/gke/components/CruGKE.vue b/pkg/gke/components/CruGKE.vue index 81ad059495a..bdff8329fd0 100644 --- a/pkg/gke/components/CruGKE.vue +++ b/pkg/gke/components/CruGKE.vue @@ -699,7 +699,6 @@ export default defineComponent({ >
Date: Tue, 28 Jan 2025 16:37:30 -0800 Subject: [PATCH 5/7] removed standardUser tag from the e2e test Signed-off-by: Isabela Guimaraes --- .../e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts index e15a62eb816..d6c37b34a07 100644 --- a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts +++ b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts @@ -9,7 +9,7 @@ import { DEFAULT_GCP_ZONE } from '@/pkg/gke/util/gcp'; ******/ // will only run this in jenkins pipeline where cloud credentials are stored -describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@adminUser', '@standardUser', '@jenkins'] }, () => { +describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@adminUser', '@jenkins'] }, () => { const clusterList = new ClusterManagerListPagePo(); const loadingPo = new LoadingPo('.loading-indicator'); From f6dfa2a808a591ee01d0f03bbd9309569478772d Mon Sep 17 00:00:00 2001 From: Isabela Guimaraes Date: Mon, 3 Feb 2025 20:01:02 -0800 Subject: [PATCH 6/7] added a try catch to debug the undefined error in gkeServiceAccount Signed-off-by: Isabela Guimaraes --- .../manager/gke-cluster-provisioning.spec.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts index d6c37b34a07..3c5db43b902 100644 --- a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts +++ b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts @@ -18,7 +18,28 @@ describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@admi let gkeVersion = ''; let clusterId = ''; let clusterDescription = ''; - const gkeProjectId = JSON.parse(Cypress.env('gkeServiceAccount')).project_id; + const base64EncodedServiceAccount = Cypress.env('gkeServiceAccount'); + + // Check if the base64 string is defined and valid + if (base64EncodedServiceAccount) { + try { + // Decode the base64 string into a JSON string + const decodedServiceAccountJson = atob(base64EncodedServiceAccount); + + // Parse the decoded JSON string + const serviceAccount = JSON.parse(decodedServiceAccountJson); + + // Now you can access the project_id + const gkeProjectId = serviceAccount.project_id; + + console.log(gkeProjectId); // Check if the value is correct + } catch (error) { + // Handle any error that occurs during decoding or parsing + console.error('Error decoding or parsing service account JSON:', error); + } + } else { + console.warn('gkeServiceAccount environment variable is undefined or empty.'); + } before(() => { cy.login(); From 8f83f1e5ebf3d364175af42f55169b3456e35fe2 Mon Sep 17 00:00:00 2001 From: Isabela Guimaraes Date: Mon, 3 Feb 2025 21:45:54 -0800 Subject: [PATCH 7/7] addressed lint failures Signed-off-by: Isabela Guimaraes --- .../e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts index 3c5db43b902..0133e04a542 100644 --- a/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts +++ b/cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts @@ -19,6 +19,7 @@ describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@admi let clusterId = ''; let clusterDescription = ''; const base64EncodedServiceAccount = Cypress.env('gkeServiceAccount'); + let gkeProjectId = ''; // Check if the base64 string is defined and valid if (base64EncodedServiceAccount) { @@ -30,8 +31,8 @@ describe('Deploy GKE cluster with default settings', { tags: ['@manager', '@admi const serviceAccount = JSON.parse(decodedServiceAccountJson); // Now you can access the project_id - const gkeProjectId = serviceAccount.project_id; - + gkeProjectId = serviceAccount.project_id; + /* eslint-disable no-console */ console.log(gkeProjectId); // Check if the value is correct } catch (error) { // Handle any error that occurs during decoding or parsing