Skip to content
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

test: refactoring e2e #227

Merged
merged 1 commit into from
Jul 25, 2022

Conversation

riya-singhal31
Copy link
Contributor

@riya-singhal31 riya-singhal31 commented Jul 6, 2022

Removed the Deploy Manager package as it was being used by e2e only.
Created and accessed the clients, configs and all the required functions in the e2e folder itself.

Signed-off-by: riya-singhal31 [email protected]

@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 6, 2022
@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 12, 2022
@riya-singhal31 riya-singhal31 force-pushed the refactoring branch 4 times, most recently from e5e3b7b to 3639d7b Compare July 12, 2022 09:00
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 12, 2022
@riya-singhal31 riya-singhal31 changed the title [WIP]test: refactoring e2e test: refactoring e2e Jul 12, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 12, 2022
@riya-singhal31 riya-singhal31 requested review from nbalacha and sp98 July 12, 2022 11:13
e2e/config.go Outdated
// SuiteFailed indicates whether any test in the current suite has failed
var SuiteFailed = false
var scheme = runtime.NewScheme()
var CrClient crclient.Client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the variable used outside the package? If not, then it should start with small case. Also, why the name CrClient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, used this client in pvc_test.go
So that's why initialised it with upper case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a different package for pvc? Can everything be done in the e2e pkg?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so inside lvm only lvm_suite_test.go should reside right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it can be done. Updating

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the lvm pkg at all? Can everything be in a single e2e pkg?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, everything inside the same package.

e2e/config.go Outdated
utilruntime.Must(snapapi.AddToScheme(scheme))

kubeconfig := os.Getenv("KUBECONFIG")
config, _ := getKubeconfig(kubeconfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error is not handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

e2e/config.go Outdated

kubeconfig := os.Getenv("KUBECONFIG")
config, _ := getKubeconfig(kubeconfig)
CrClient, _ = crclient.New(config, crclient.Options{Scheme: scheme})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error is not handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

e2e/helper.go Outdated
if err != nil && !errors.IsNotFound(err) {
return err
}
err := CrClient.Delete(context.TODO(), ns)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to pass proper context rather than context.TODO() for every function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.TODO() is still being used in a lot of places.

e2e/config.go Outdated
// SuiteFailed indicates whether any test in the current suite has failed
var SuiteFailed = false
var scheme = runtime.NewScheme()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of having var declared in each line, it can be grouped together. For example:
var ( )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grouped all the vars and const.

e2e/config.go Outdated
@@ -23,11 +32,10 @@ var LvmSubscriptionChannel string
// DiskInstall indicates whether disks are needed to be installed.
var DiskInstall bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please recheck all these variables. The ones within the scope of the package should be in small case. Like DiskInstall.

e2e/helper.go Outdated
return err
}
err := CrClient.Create(context.TODO(), ns)
gomega.Expect(err).To(gomega.BeNil())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

earlier it was validating against two errors ( not nil and IsAlreadyExists). But looks like the change (gomega error handling) does not cover IsAlreadyExists

@@ -150,7 +150,7 @@ func (t *DeployManager) waitForLVMCatalogSource() error {
}

// WaitForLVMOperator waits for the lvm-operator to come online.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// WaitForLVMOperator waits for the lvm-operator to come online.
// waitForLVMOperator waits for the lvm-operator to come online.

@@ -275,11 +275,11 @@ func (t *DeployManager) DeployLVMWithOLM(lvmCatalogImage string, subscriptionCha
}

// DeleteClusterObjects deletes remaining operator manifests.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// DeleteClusterObjects deletes remaining operator manifests.
// deleteClusterObjects deletes remaining operator manifests.

@@ -275,11 +275,11 @@ func (t *DeployManager) DeployLVMWithOLM(lvmCatalogImage string, subscriptionCha
}

// DeleteClusterObjects deletes remaining operator manifests.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// DeleteClusterObjects deletes remaining operator manifests.
// deleteClusterObjects deletes remaining operator manifests.

@@ -306,15 +306,15 @@ func (t *DeployManager) deleteClusterObjects(co *clusterObjects) error {
}

// UninstallLVM uninstalls lvm operator.
func (t *DeployManager) UninstallLVM(lvmCatalogImage string, subscriptionChannel string) error {
func UninstallLVM(lvmCatalogImage string, subscriptionChannel string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start function with lower case if its not used outside the package. Please check this for all the other functions as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@riya-singhal31
Copy link
Contributor Author

Thanks @sp98 , @nbalacha for the reviews.
Addressed all of them.

@@ -53,7 +53,7 @@ func diskSetup() error {
func diskRemoval() error {
// get nodes
nodeList := &corev1.NodeList{}
err := DeployManagerObj.GetCrClient().List(context.TODO(), nodeList, client.HasLabels{labelNodeRoleWorker})
err := crClient.List(context.TODO(), nodeList, client.HasLabels{labelNodeRoleWorker})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uses context.TODO()

e2e/pvc_check.go Outdated
@@ -29,184 +25,183 @@ func PVCTest() {
var clonePod *k8sv1.Pod
var restorePvc *k8sv1.PersistentVolumeClaim
var restorePod *k8sv1.Pod
client := tests.DeployManagerObj.GetCrClient()
ctx := context.TODO()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using context.TODO()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@riya-singhal31 riya-singhal31 force-pushed the refactoring branch 2 times, most recently from 822e48d to 52e44df Compare July 15, 2022 10:51
@riya-singhal31 riya-singhal31 requested a review from sp98 July 15, 2022 10:55
@riya-singhal31 riya-singhal31 force-pushed the refactoring branch 2 times, most recently from 98f2e7e to 091755c Compare July 15, 2022 11:00
return t.crClient.Create(context.TODO(), lvmClusterRes)
func startLVMCluster() error {
lvmClusterRes := generateLVMCluster()
return crClient.Create(context.Background(), lvmClusterRes)
}

// Deletes a sample CR.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per golang coding convention, doc comment for an exported function should start with the function name. Please fix this for other functions as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is used only in this package(not an exported func), so will correct the name of function with lower case.

@riya-singhal31 riya-singhal31 force-pushed the refactoring branch 2 times, most recently from a62500c to 61101c6 Compare July 18, 2022 07:09
@riya-singhal31 riya-singhal31 requested a review from sp98 July 18, 2022 07:10
@sp98
Copy link
Contributor

sp98 commented Jul 21, 2022

discussed some more improvements that can be made in the PR offline. Adding them here:

  1. Don't create context for each function. Have a single parent context that can be used by all the functions. Possible ways are:

    • Function receiver that holds the context.
    • Or pass the context as function argument.
  2. Avoid using package level variables that are used for all the functions, for example, the way the crClient being used.
    A good read on why package level variables are not recommended.

e2e/config.go Outdated
// SuiteFailed indicates whether any test in the current suite has failed
var SuiteFailed = false
const (
testNamespace = "lvm-endtoendtest"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments describing the constants and variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

e2e/config.go Outdated
kubeconfig := os.Getenv("KUBECONFIG")
config, err := getKubeconfig(kubeconfig)
if err != nil {
panic(fmt.Sprintf("Failed to set kubecofig: %v", err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
panic(fmt.Sprintf("Failed to set kubecofig: %v", err))
panic(fmt.Sprintf("Failed to set kubeconfig: %v", err))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

type clusterObjects struct {
namespaces []k8sv1.Namespace
operatorGroups []v1.OperatorGroup
catalogSources []v1alpha1.CatalogSource
subscriptions []v1alpha1.Subscription
}

// Generating the cluster objects.
func (t *DeployManager) generateClusterObjects(lvmCatalogImage string, subscriptionChannel string) *clusterObjects {
// generateClusterObjects generates the cluster objects.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// generateClusterObjects generates the cluster objects.
// generateClusterObjects generates the cluster objects required for deploying the operator using OLM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@riya-singhal31
Copy link
Contributor Author

Thanks @sp98, @nbalacha for the reviews.
Addressed them all.

Signed-off-by: riya-singhal31 <[email protected]>
lvmSubscriptionChannel string
// diskInstall indicates whether disks are needed to be installed.
diskInstall bool
lvmOperatorInstall bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comments for lvmOperatorInstall and lvmOperatorUninstall.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 25, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 25, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nbalacha, riya-singhal31

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 25, 2022
@openshift-merge-robot openshift-merge-robot merged commit cc63237 into openshift:main Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants