-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
e2e test that creates GKE cluster with default settings #12934
Open
IsaSih
wants to merge
5
commits into
master
Choose a base branch
from
gke-po
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e609775
e2e test that creates GKE cluster with default settings
IsaSih 60e6fa5
addressed changes requested from PR review
IsaSih 25bf4ac
added cleanup set after the test to remove the created cluster and cl…
IsaSih 5f7fa94
modified GKE components to have an unique id
IsaSih 03c2be9
removed standardUser tag from the e2e test
IsaSih File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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 { | ||
return LabeledInputPo.byLabel(this.self(), 'Service Account'); | ||
} | ||
|
||
readFromFile(): Cypress.Chainable { | ||
return ButtonFileSelectorPo.readFromFileButton().click(); | ||
} | ||
|
||
authenticateButton() { | ||
return new AsyncButtonPo('[data-testid="action-button-async-button"]', this.self()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-gke.po.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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'; | ||
|
||
/** | ||
* 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<Cypress.AUTWindow> { | ||
return PagePo.goTo(ClusterManagerCreateGKEPagePo.url(clusterId)); | ||
} | ||
|
||
goToGKEClusterCreation(clusterId: string): Cypress.Chainable<Cypress.AUTWindow> { | ||
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()); | ||
} | ||
|
||
static getGkeVersionSelect() { | ||
return new LabeledSelectPo('[data-testid="gke-version-select"]'); | ||
} | ||
|
||
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"]'); | ||
} | ||
} |
139 changes: 139 additions & 0 deletions
139
cypress/e2e/tests/pages/manager/gke-cluster-provisioning.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
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 { 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', '@jenkins'] }, () => { | ||
const clusterList = new ClusterManagerListPagePo(); | ||
const loadingPo = new LoadingPo('.loading-indicator'); | ||
|
||
let cloudcredentialId = ''; | ||
const gkeDefaultZone = 'us-central1-c'; | ||
let gkeVersion = ''; | ||
let clusterId = ''; | ||
let clusterDescription = ''; | ||
const gkeProjectId = JSON.parse(Cypress.env('gkeServiceAccount')).project_id; | ||
|
||
before(() => { | ||
cy.login(); | ||
HomePagePo.goTo(); | ||
|
||
// clean up GKE cloud credentials | ||
cy.getRancherResource('v3', 'cloudcredentials', null, null).then((resp: Cypress.Response<any>) => { | ||
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); | ||
IsaSih marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} 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'); | ||
IsaSih marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Authenticate GKE credential by providing the Project ID | ||
createGKEClusterPage.waitForPage('type=googlegke&rkeType=rke2'); | ||
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'); | ||
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'); | ||
ClusterManagerCreateGKEPagePo.getGkeVersionSelect().checkOptionSelected(gkeVersion); | ||
}); | ||
|
||
// Set the cluster name and description in the Create GKE Page | ||
createGKEClusterPage.getClusterName().set(this.gkeClusterName); | ||
clusterDescription = `${ this.gkeClusterName }-description`; | ||
createGKEClusterPage.getClusterDescription().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'); | ||
}); | ||
|
||
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<any>) => { | ||
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'); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is failing CI due to this line. We would need this new variable,
GKE_SERVICE_ACCOUNT
, present in the environment for it to work correctly. I'm not personally sure how to do it, but maybe @richard-cox or @izaac can instruct us?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error ref:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't expecting this to run in Github Actions with the
@jenkins
tag. Only on Jenkins.Edit: I am not sure how the
grepTags
change the behavior of Cypress'describe
andit
blocks internally but I guess the code gets interpreted before the tag logic is applied.I see other filtered specs still selected but then the greptags logic blocks the test from execution.
Catching the
undefined
might shed some light to my theory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the meantime we should catch the
undefined
value before attempting to parse the variable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like it's only an issue with
@standardUser
tag. we can remove that tag to get unblocked and create a separate issue to investigate thisThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scratch that idea, it didn't work (test is still picked up when
@standardUser
tag removed). We should handle undefined or null values using try catch as Izaac suggested. Sent Isabela some pointersThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created an issue to investigate the problem we're seeing with the grep tags rancher/qa-tasks#1663