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

Added Koperator end to end tests #987

Merged
merged 22 commits into from
Jun 19, 2023
Merged

Conversation

bartam1
Copy link
Contributor

@bartam1 bartam1 commented May 28, 2023

Description

Adding basic end to end tests for Koperator.
Included tests:

  • helm uninstallation and check remained resources
  • kafkacluster, zookeepercluster uninstallation and check remained resources
  • Internal consumer producer test

Type of Change

  • Other (test)

Checklist

@bartam1 bartam1 requested a review from a team as a code owner May 28, 2023 14:12
@bartam1 bartam1 changed the base branch from master to test/de2e-koperator-install May 28, 2023 14:12
tests/e2e/k8s_test.go Outdated Show resolved Hide resolved
@bartam1 bartam1 changed the title Added Koperator uninstallation end to end test Added Koperator end to end tests Jun 5, 2023
Copy link
Contributor

@Kuvesz Kuvesz left a comment

Choose a reason for hiding this comment

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

Sorry, got a lot of comments, many of them are repeating though, so it's okay to answer those only once and they shouldn't require too much effort to fix. Overall I've got some suggestions that I'd like to see implemented, but these are suggestions, it's all up for discussion.

Makefile Outdated
@@ -102,7 +102,11 @@ test: generate fmt vet manifests bin/setup-envtest
test-e2e:
go test github.com/banzaicloud/koperator/tests/e2e \
-v \
-timeout 5m
-timeout 15m \
--ginkgo.fail-fast \
Copy link
Contributor

@Kuvesz Kuvesz Jun 5, 2023

Choose a reason for hiding this comment

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

I think we agreed the tests should be slow failing, so this line might need to be removed when we're done with testing the tests. Just a note really.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is now only for testing purposes after Patrik PR I will change it.

tests/e2e/cert_manager_test.go Outdated Show resolved Hide resolved
tests/e2e/cert_manager_test.go Outdated Show resolved Hide resolved
tests/e2e/cert_manager_test.go Outdated Show resolved Hide resolved
fmt.Sprintf(managedByHelmLabelTemplate, "cert-manager"),
"",
kubectlArgGoTemplateKindNameNamespace,
"--all-namespaces")
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Will this overwrite the namespace in the kubectlOptions?

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, the --all-namespaces overwrites the -n namespace parameter effect

tests/e2e/koperator_test.go Outdated Show resolved Hide resolved
tests/e2e/koperator_test.go Outdated Show resolved Hide resolved
tests/e2e/koperator_test.go Outdated Show resolved Hide resolved
tests/e2e/prometheus_test.go Outdated Show resolved Hide resolved
tests/e2e/zookeeper_test.go Outdated Show resolved Hide resolved
@pregnor pregnor force-pushed the test/de2e-koperator-install branch 2 times, most recently from 1f98ba9 to 9db5a56 Compare June 6, 2023 11:48
panyuenlau
panyuenlau previously approved these changes Jun 7, 2023
Copy link
Member

@panyuenlau panyuenlau left a comment

Choose a reason for hiding this comment

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

Implementation looks great! Just something very minor

purge bool,
extraArgs ...string,
) {
By(fmt.Sprintf("Checking for existing Helm release names %s", helmReleaseName))
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't use plural since we are checking for one single here

Suggested change
By(fmt.Sprintf("Checking for existing Helm release names %s", helmReleaseName))
By(fmt.Sprintf("Checking for existing Helm release name %s", helmReleaseName))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed: b0b2558

}

// installHelmChart deploys a Helm chart to the specified kubectl context and
// namespace using the specified infos, extra arguments can be any of the helm
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// namespace using the specified infos, extra arguments can be any of the helm
// namespace using the specified info, extra arguments can be any of the helm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed: b0b2558

// installHelmChart checks whether the specified named Helm release exists in
// the provided kubectl context and namespace, logs it if it does and returns or
// alternatively deploys the Helm chart to the specified kubectl context and
// namespace using the specified infos, extra arguments can be any of the helm
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// namespace using the specified infos, extra arguments can be any of the helm
// namespace using the specified info, extra arguments can be any of the helm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed:b0b2558

tests/e2e/utils.go Show resolved Hide resolved
Base automatically changed from test/de2e-koperator-install to master June 8, 2023 11:07
@pregnor pregnor dismissed panyuenlau’s stale review June 8, 2023 11:07

The base branch was changed.

@bartam1 bartam1 force-pushed the test/de2e-koperator-uninstall branch from b905456 to 56b6b8a Compare June 14, 2023 15:21
Kuvesz
Kuvesz previously approved these changes Jun 15, 2023
Copy link
Contributor

@Kuvesz Kuvesz left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 296 to 299
// uninstallHelmChart uninstall Helm chart from the specified kubectl context and
// namespace using the specified helm release name. When purge is true, it removes records
// and make that name free to be reused for another installation.
// Extra arguments can be any of the helm CLI uninstall flag arguments.
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
// uninstallHelmChart uninstall Helm chart from the specified kubectl context and
// namespace using the specified helm release name. When purge is true, it removes records
// and make that name free to be reused for another installation.
// Extra arguments can be any of the helm CLI uninstall flag arguments.
// uninstallHelmChart uninstalls a Helm chart from the specified kubectl context and
// namespace using the specified helm release name. When purge is true, it removes records
// and makes that name free to be reused for another installation.
// Extra arguments can be any of the helm CLI uninstall flag arguments.

tests/e2e/test_test.go Outdated Show resolved Hide resolved
tests/e2e/uninstall.go Show resolved Hide resolved
Copy link
Member

@pregnor pregnor left a comment

Choose a reason for hiding this comment

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

There are multiple files in which the It(...) executed functions should be error-checked. (At some places this is fixed, but you missed a couple. Let me know if I should provide a list of places.)

tests/e2e/const.go Show resolved Hide resolved
tests/e2e/helm.go Outdated Show resolved Hide resolved
tests/e2e/k8s.go Outdated Show resolved Hide resolved
tests/e2e/k8s.go Outdated Show resolved Hide resolved
tests/e2e/k8s.go Outdated Show resolved Hide resolved
Comment on lines 48 to 63
k8sResourceKinds, err := listK8sAllResourceKind(kubectlOptions)
Expect(err).ShouldNot(HaveOccurred())

koperatorAvailableResourceKinds := stringSlicesUnion(koperatorCRDs(), k8sResourceKinds)
koperatorAvailableResourceKinds = append(koperatorAvailableResourceKinds, basicK8sResourceKinds()...)

remainedResources, err := getK8sResources(kubectlOptions,
koperatorAvailableResourceKinds,
fmt.Sprintf(managedByHelmLabelTemplate, koperatorLocalHelmDescriptor.ReleaseName),
"",
kubectlArgGoTemplateKindNameNamespace,
"--all-namespaces")

Expect(err).ShouldNot(HaveOccurred())
Expect(remainedResources).Should(BeEmpty())
})
Copy link
Member

Choose a reason for hiding this comment

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

Note: This is fine like this for now, but in a follow-up ticket we want to move these kind of checks higher up onto case level when this becomes unnecessary.
Then everything will fold up because the Helm chart uninstallation becomes only 1 line, the Koperator uninstallation becomes only 1 line so we can omit those and put the uninstall Koperator It(...) directly into the uninstall test case.

Same thing I did at the last refactor of the install test case.

Same holds true for the other components.

CC: @panyuenlau @Kuvesz @mihaialexandrescu

Copy link
Contributor Author

@bartam1 bartam1 Jun 15, 2023

Choose a reason for hiding this comment

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

I dont understand what do you mean. Please explain in priv.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know you put in your test_install.go directly those tests under When containers. Somehow I felt that it is clener and maybe more reusable if I kept the original form and put evreything in functions.

Copy link
Member

Choose a reason for hiding this comment

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

I wrote in private.

tests/e2e/helm.go Outdated Show resolved Hide resolved
tests/e2e/uninstall_cluster_test.go Outdated Show resolved Hide resolved
tests/e2e/utils.go Outdated Show resolved Hide resolved
tests/e2e/utils.go Outdated Show resolved Hide resolved
@bartam1 bartam1 force-pushed the test/de2e-koperator-uninstall branch from 1a732a8 to 46b2d71 Compare June 16, 2023 01:38
Copy link
Member

@pregnor pregnor left a comment

Choose a reason for hiding this comment

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

Earlier unresolved threads:

  1. Added Koperator end to end tests #987 (comment)
  2. Added Koperator end to end tests #987 (comment)
  3. (fixed since) Added Koperator end to end tests #987 (comment)

The fixes were great, thanks.
There were a couple error checks missed so I'm commenting them by line to make it easier to go through.

Test after my suggestions, I wrote them from the top of my mind.

tests/e2e/kafka.go Outdated Show resolved Hide resolved
},
)
err := waitK8sResourceCondition(kubectlOptions, kafkaTopicKind, "jsonpath={.status.state}=created", defaultTopicCreationWaitTime, "", topicName)
Expect(err).ShouldNot(HaveOccurred())
Copy link
Member

Choose a reason for hiding this comment

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

Note: According to https://pkg.go.dev/github.com/onsi/gomega#Assertion typically expect uses NotTo compared to ShouldNot, but I'm not picky about that, but we should use one of the two throughout the tests for easier human pattern recognition. I don't mind which one we use, if we feel like ShouldNot is easier to read, fine for me. I used NotTo due to being used to that, but no hard feelings.

Copy link
Contributor Author

@bartam1 bartam1 Jun 19, 2023

Choose a reason for hiding this comment

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

I saw somewhere (gomega tooltip) that the "Expect(err).ShouldNot(HaveOccurred())" should be used to check error

Copy link
Member

Choose a reason for hiding this comment

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

Could you search around just quickly in 5m what is the official suggestion here?
What I linked is the official gomega docs, so I don't understand why some tooltip would be the direct opposite.
But as I said, I don't care which, whatever is preferred officially is fine for me, I care about not mixing the two.

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally have no preference in this, both are easy to understand really. My only issue is that it would be nice to be consistent across our code, so we should really pick one. I'm not saying we have to fix this now as all occurrences can be easily replaced at any time but at some point we should I think.

tests/e2e/kafka.go Outdated Show resolved Hide resolved
tests/e2e/kafka.go Outdated Show resolved Hide resolved
tests/e2e/produce_consume.go Outdated Show resolved Hide resolved
tests/e2e/uninstall.go Outdated Show resolved Hide resolved
tests/e2e/uninstall.go Outdated Show resolved Hide resolved
tests/e2e/uninstall.go Outdated Show resolved Hide resolved
tests/e2e/uninstall_cluster.go Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Optional: I MAY consider renaming this file to string.go for now.
Generic util packages and files are an anti-pattern because they are used as dumps instead of thinking through the organization of the units, currently this only has a string function so I would use this as string function collector file, in the future we can figure out if there is anything else to add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im sure that we will have things what will need to be added into the utils.go later.
Creating a new file for one function I think is not worth.
Because it is optional from you I would keep it as it is.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, consider this resolved, feel free to mark the conversation as resolved.

Context: The problem is, when you are looking for something in a structured way util.go is difficult to decipher without looking into it and if there are multiple not connected functions in it, it will become a mess internally.
Instead if we structurize these functions based on their nature/topic/etc. such as string modification functions it is easier to look at the files list in the package and quickly guess where you should look for different top level functions.
That was behind the helm.go, k8s.go files as well.

Comment on lines +34 to +37
It("Setting globals", func() {
err := dependencyCRDs.Initialize(kubectlOptions)
Expect(err).NotTo(HaveOccurred())
})
Copy link
Member

Choose a reason for hiding this comment

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

Note: This needs to be moved to the per case before once we handle that ticket. Nothing to do now.

pregnor
pregnor previously approved these changes Jun 19, 2023
Copy link
Member

@pregnor pregnor left a comment

Choose a reason for hiding this comment

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

Couple optional things and arguable recommendations, otherwise looks ok.

tests/e2e/types.go Outdated Show resolved Hide resolved
@@ -0,0 +1,52 @@
package e2e
Copy link
Member

Choose a reason for hiding this comment

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

(For some reason my file level commend does not work this morning.)

Optional: IMO this other than the version type which I commented, the rest of the file would fit into k8s.go with the dependencyCRDsType and the functions because we are doing k8s related ops with those.

I'm fine to leave this here if others agree it's more clear this way, but it's weird for me.

Copy link
Contributor

@Kuvesz Kuvesz left a comment

Choose a reason for hiding this comment

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

Still looks good to me overall

@bartam1 bartam1 merged commit 24ec257 into master Jun 19, 2023
3 checks passed
@bartam1 bartam1 deleted the test/de2e-koperator-uninstall branch June 19, 2023 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants