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

🐛(go/v4, deployImage): fix scaffold to allow run the tests directly. Currently, is only possible run via the makefile targets #3365

Merged

Conversation

camilamacedo86
Copy link
Member

Description

Fix the scaffold to allow running the tests directly. Currently, it will fail because we install the required binaries at the bin directory inside of the project but that is not the default path configured in controller-runtime.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 23, 2023
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 23, 2023
@camilamacedo86 camilamacedo86 force-pushed the fix-run-tests-via-ide branch 2 times, most recently from 235bc4a to 4e05690 Compare April 23, 2023 17:50
@camilamacedo86
Copy link
Member Author

/pull-kubebuilder-e2e-k8s-1-24-7
/pull-kubebuilder-e2e-k8s-1-26-0

@camilamacedo86
Copy link
Member Author

pull-kubebuilder-e2e-k8s-1-26-0

@camilamacedo86
Copy link
Member Author

/pull-kubebuilder-e2e-k8s-1-26-0

@camilamacedo86
Copy link
Member Author

/pull-kubebuilder-e2e-k8s-1-24-7

2 similar comments
@camilamacedo86
Copy link
Member Author

/pull-kubebuilder-e2e-k8s-1-24-7

@camilamacedo86
Copy link
Member Author

/pull-kubebuilder-e2e-k8s-1-24-7

@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-26-0

@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-24-7

@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-26-0

@pratikmota
Copy link
Contributor

One small observation:
BinaryAssetsDirectory: filepath.Join("..", "..", "..", "bin", "k8s",fmt.Sprintf("1.26.1-%s-%s", runtime.GOOS, runtime.GOARCH)),

  • For all test suites, Here static string is added for k8 version - 1.26.1 , May be we can make it dynamic ?
  • We can take current version from K8SVersion = "1.26.1"
  • So in future if we change K8 version then doese not require to change in all places of BinaryAssetsDirectory ?

// K8SVersion define the k8s version used to do the scaffold
// so that is possible retrieve the binaries
K8SVersion string

Copy link
Member

Choose a reason for hiding this comment

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

@camilamacedo86 I like this change. But have this question on adding this option. Having k8s version here would not necessarily mean that my project is compatible with that particular version of K8s. It would just mean that we are scaffolding our test suite such that binaries for that version are downloaded. Do we need docs on this, or can we rename this to be K8sTestVersion?

Copy link
Member Author

@camilamacedo86 camilamacedo86 May 1, 2023

Choose a reason for hiding this comment

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

The binaries downloaded are within the version defined on the Makefile. Users would need to update the K8s version here at the same way that they need to update in the Makefile when then want to change that.

Please, feel free to provide any wording suggestion that you see that would fit better and make things more understandable that I will accepted :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated to have the same name used in the Makefile. (ENVTEST_K8S_VERSION)

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 5, 2023
@camilamacedo86
Copy link
Member Author

Hi @pratikmota,

One small observation:
BinaryAssetsDirectory: filepath.Join("..", "..", "..", "bin", "k8s",fmt.Sprintf("1.26.1-%s-%s", runtime.GOOS, runtime.GOARCH)),

For all test suites, Here static string is added for k8 version - 1.26.1 , May be we can make it dynamic ?
We can take current version from K8SVersion = "1.26.1"
So in future if we change K8 version then doese not require to change in all places of BinaryAssetsDirectory ?

How would we be able to change it dynamic? What is your suggestion to do that?
Note that we scaffold the binary version that should be used in the makefile. So that in the same way that if users change the k8s version used and want to use another envtest bin, they must update the Makefile, they would need to update the version here as well.

@camilamacedo86 camilamacedo86 force-pushed the fix-run-tests-via-ide branch 2 times, most recently from c88175d to d99a712 Compare May 6, 2023 16:14
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 6, 2023
@kubernetes-sigs kubernetes-sigs deleted a comment from k8s-ci-robot May 6, 2023
@pratikmota
Copy link
Contributor

pratikmota commented May 7, 2023

Hi @pratikmota,

One small observation:
BinaryAssetsDirectory: filepath.Join("..", "..", "..", "bin", "k8s",fmt.Sprintf("1.26.1-%s-%s", runtime.GOOS, runtime.GOARCH)),
For all test suites, Here static string is added for k8 version - 1.26.1 , May be we can make it dynamic ?
We can take current version from K8SVersion = "1.26.1"
So in future if we change K8 version then doese not require to change in all places of BinaryAssetsDirectory ?

How would we be able to change it dynamic? What is your suggestion to do that? Note that we scaffold the binary version that should be used in the makefile. So that in the same way that if users change the k8s version used and want to use another envtest bin, they must update the Makefile, they would need to update the version here as well.

@camilamacedo86 Okay. I just saw similar changes without hardcode version- "BinaryAssetsDirectory: filepath.Join({{ .BaseDirectoryRelativePath }}, "bin", "k8s",fmt.Sprintf("{{ .K8SVersion }}-%%s-%%s", runtime.GOOS, runtime.GOARCH)),"
This might be helpful? so will not require to change here version manually in all files.

Comment on lines +186 to +193
// The BinaryAssetsDirectory is only required if you want to run the tests directly
// without call the makefile target test. If not informed it will look for the
// default path defined in controller-runtime which is /usr/local/kubebuilder/.
// Note that you must have the required binaries setup under the bin directory to perform
// the tests directly. When we run make test it will be setup and used automatically.
BinaryAssetsDirectory: filepath.Join({{ .BaseDirectoryRelativePath }}, "bin", "k8s",
fmt.Sprintf("{{ .K8SVersion }}-%%s-%%s", runtime.GOOS, runtime.GOARCH)),

Copy link
Member Author

Choose a reason for hiding this comment

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

@pratikmota see ^

@camilamacedo86
Copy link
Member Author

Hi @pratikmota,

@camilamacedo86 Okay. I just saw similar changes without hardcode version- "BinaryAssetsDirectory: filepath.Join({{ .BaseDirectoryRelativePath }}, "bin", "k8s",fmt.Sprintf("{{ .K8SVersion }}-%%s-%%s", runtime.GOOS, runtime.GOARCH)),"
This might be helpful? so will not require to change here version manually in all files.

It is in this way in the boilerplate/templates see https://github.com/kubernetes-sigs/kubebuilder/pull/3365/files#r1186883942. However, the tool does the scaffolds of the code within the values that exist in the K8SVersion in the specific Kubebuilder. Then, after that, if users want to change their projects they need to update manually as in any other place that we scaffold versions.

@camilamacedo86
Copy link
Member Author

@varshaprasad96 all concerns, questions and suggestions shows are addressed now. WDYT?
Could we get this one merged?

@camilamacedo86
Copy link
Member Author

@Kavinjsir , @varshaprasad96 @everettraven @rashansmith

Could we get this one merged? WDYT?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 13, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 20, 2023
@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-26-0

Copy link
Member

@varshaprasad96 varshaprasad96 left a comment

Choose a reason for hiding this comment

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

Just 2 nits in the comments. Rest looks good to me! Thanks @camilamacedo86
/lgtm
/approve

@@ -165,6 +171,14 @@ var _ = BeforeSuite(func() {
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join({{ .CRDDirectoryRelativePath }}, "config", "crd", "bases")},
ErrorIfCRDPathMissing: {{ .Resource.HasAPI }},

// The BinaryAssetsDirectory is only required if you want to run the tests directly
// without call the makefile target test. If not informed it will look for the
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
// without call the makefile target test. If not informed it will look for the
// without calling the makefile target test. If not informed it will look for the

// without call the makefile target test. If not informed it will look for the
// default path defined in controller-runtime which is /usr/local/kubebuilder/.
// Note that you must have the required binaries setup under the bin directory to perform
// the tests directly. When we run make test it will be setup and used automatically.
Copy link
Member

Choose a reason for hiding this comment

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

Nit ```suggestion
// the tests directly. When we run make test it will be setup using "setup-envtest" and used automatically.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 14, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, varshaprasad96

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:
  • OWNERS [camilamacedo86,varshaprasad96]

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

@k8s-ci-robot k8s-ci-robot merged commit 6de498c into kubernetes-sigs:master Jul 14, 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants