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

[OCPCLOUD-1706] Migrate test utils from CPMSO repository #265

Merged
merged 7 commits into from
Feb 9, 2023

Conversation

RadekManak
Copy link
Contributor

This PR moves test utilities and resource builders from CPMSO repository into this repository. This will allow us to reuse them in other test suites.

Tooling for unit test is created as this repo currently only has e2e tests. This will need to be enabled in openshift/release after this PR merges.
The MachineInfoBuilder is kept in the CPMSO repo. MachineInfo's are used only in CPMSO. Moving the builder over would create cyclic dependency.

@damdo
Copy link
Member

damdo commented Jan 10, 2023

FYI: I got some more resourcebuilders in this PR, we might want to include them there too, openshift/cluster-control-plane-machine-set-operator#156

Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

What is the effect on CPMS of importing these changes? Do we need to make a separate go module to confine the imports to just the testutils module or does it work well as is?

Do we have appropriate linting rules on the testutils?

Do we want to keep the resource builders as a flat structure, or group them by API group/versions as you'd expect for other helpers?

// Machine API namespace.
OpenshiftMachineAPINamespaceName = "openshift-machine-api"

testClusterIDValue = "cpms-cluster-test-id"
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably don't want this to be cpms anymore, where else is it used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As machine label, machine selector. I have dropped the cpms prefix.

@RadekManak
Copy link
Contributor Author

RadekManak commented Jan 11, 2023

What is the effect on CPMS of importing these changes? Do we need to make a separate go module to confine the imports to just the testutils module or does it work well as is?

I was able to import from CPMSO without issues.

Do we have appropriate linting rules on the testutils?

The linter is running on the files. (with slightly different settings)

Do we want to keep the resource builders as a flat structure, or group them by API group/versions as you'd expect for other helpers?

Probably good idea to structure it now that it will be imported from other repositories. I have restructured it. Let me know if it looks good to you.

@damdo
Copy link
Member

damdo commented Jan 12, 2023

@RadekManak this PR is merged now FYI, if you want to pull in also those builders.
#265 (comment)

@RadekManak
Copy link
Contributor Author

Yes, thanks already done. :)

Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

Couple of nits, otherwise LGTM

@JoelSpeed JoelSpeed changed the title Migrate test utils from CPMSO repository [OCPCLOUD-1706] Migrate test utils from CPMSO repository Jan 23, 2023
Copy link
Contributor

@elmiko elmiko left a comment

Choose a reason for hiding this comment

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

looks mostly good to me, just a question

Makefile Outdated
@@ -69,6 +73,10 @@ vet: ## Apply go vet to all go files
build-e2e:
$(DOCKER_CMD) go test -c -o "$(BUILD_DEST)" github.com/openshift/cluster-api-actuator-pkg/pkg/

.PHONY: unit
unit: ## Run unit tests
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 to add a prow configuration to exercise this new target?

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, this needs to be set up. The tests do pass locally right now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get that set up before we merge this? Should be a PR to the release repo to add it 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.

I have openshift/release@09ee970 prepared, but we need to merge this first. There is no unit target on master, so it won't pass until this PR adds it.

Copy link
Member

@damdo damdo left a comment

Choose a reason for hiding this comment

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

Generally LGTM. Thanks for putting this together.
Left mainly a comment regarding importing.

Makefile Outdated Show resolved Hide resolved
go.mod Show resolved Hide resolved
pkg/testutils/cleanup.go Outdated Show resolved Hide resolved
Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

I think I would advise considering the testutils module as if it were a completely independent repository. Set up its own makefile and hack scripts for running the tests, and then link to those targets from the top level using make -C testutils, it will simplify a lot of the bash/makefile logic and keep them better isolated

Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
hack/go-vet.sh Outdated Show resolved Hide resolved
hack/test.sh Outdated Show resolved Hide resolved
testutils/resourcebuilder/meta/v1/conditions.go Outdated Show resolved Hide resolved
Makefile Outdated
Comment on lines 10 to 14
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26

PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
ENVTEST = go run ${PROJECT_DIR}/vendor/sigs.k8s.io/controller-runtime/tools/setup-envtest
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these new additions used now we've moved things to a separate makefile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to remove this. Thanks

Comment on lines 60 to 66
.PHONY: fmt
fmt: ## Go fmt your code
$(DOCKER_CMD) hack/go-fmt.sh .

.PHONY: goimports
goimports: ## run goimports
$(DOCKER_CMD) hack/goimports.sh .
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these not covered by GolangCI Lint? My understanding was they are both run as part of its suite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct. I have kept them because, they were being executed by CI. There are currently two targets that run on this repo. (excluding E2Es). check that on main branch runs fmt and vet, and goimports. The golanCI lint has been added recently and is not being executed by CI. If you want, we can remove these and only keep golangci lint and unit.

Copy link
Contributor

Choose a reason for hiding this comment

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

If that's the case, then yep, lets keep them for now but I think we should migrate to golangci-lint as the single source moving forward, that can be a follow up PR though

go.mod Outdated
k8s.io/klog v1.0.0
k8s.io/utils v0.0.0-20220823124924-e9cbc92d1a73
sigs.k8s.io/controller-runtime v0.13.0
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20221222054525-3c4deba74e5c
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct? I didn't think setup-entest was needed at this level anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to remove this. Thanks

@RadekManak
Copy link
Contributor Author

/retest-required

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 8, 2023

@RadekManak: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@JoelSpeed
Copy link
Contributor

/approve

/assign @damdo

Dam for LGTM on this as we talked about it during standup

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 8, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JoelSpeed

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 Feb 8, 2023
Copy link
Member

@damdo damdo left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together Radek.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 9, 2023
@openshift-merge-robot openshift-merge-robot merged commit 2ec5c87 into openshift:master Feb 9, 2023
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.

5 participants