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

Fixed the default namespace issue #150

Merged

Conversation

Bharadwajshivam28
Copy link
Member

Currently if namespace is not passed and we run the command bin/hydrophone --cleanup then the command breaks so we can pass a default namespace it users run the command bin/hydrophone --cleanup then also the default namespace will be taken.

fixes #149

Previous behaviour-

Screenshot from 2024-02-11 07-32-15

Current behaviour-
Screenshot from 2024-02-11 07-32-55

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 11, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @Bharadwajshivam28. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Feb 11, 2024
@@ -323,6 +323,12 @@ func RunE2E(clientset *kubernetes.Clientset) {
// Cleanup removes all resources created during E2E tests.
func Cleanup(clientset *kubernetes.Clientset) {
namespace := viper.GetString("namespace")

if namespace == "" {
Copy link
Contributor

@reetasingh reetasingh Feb 11, 2024

Choose a reason for hiding this comment

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

@Bharadwajshivam28 A cleaner solution would be to reuse the ValidateArgs method https://github.com/kubernetes-sigs/hydrophone/blob/main/pkg/common/args.go#L52. its currently validating multiple things. maybe we can introduce a new method for validating namespace?

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay works for me... let me change it @reetasingh

@Bharadwajshivam28
Copy link
Member Author

@reetasingh I have made some changes..
could you please review it?

viper.Set("namespace", DefaultNamespace)
}
}

func ValidateArgs() error {
if viper.Get("namespace") == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

reuse SetDefaultNamespace() here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay...

Copy link
Member Author

Choose a reason for hiding this comment

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

reuse SetDefaultNamespace() here too.

can you please elaborate this one? sorry but i not understood it..

@@ -48,6 +48,12 @@ func PrintInfo(clientSet *kubernetes.Clientset, config *rest.Config) {
// ValidateArgs validates the arguments passed to the program
// and creates the output directory if it doesn't exist

func SetDefaultNamespace() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@Bharadwajshivam28 if possible can you add unit test for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Bharadwajshivam28 if possible can you add unit test for this?

I have implemented unit test but can you please elaborate this?
I will be happy to make the changes @reetasingh

Copy link
Contributor

Choose a reason for hiding this comment

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

you can add the unit test for this in args_test.go

@@ -48,6 +48,12 @@ func PrintInfo(clientSet *kubernetes.Clientset, config *rest.Config) {
// ValidateArgs validates the arguments passed to the program
Copy link
Contributor

Choose a reason for hiding this comment

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

above comment is for ValidateArgs() method. I think you have not added it in right place

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I missed it... Let me take a look at it..

Will push the changes soon..

namespace := viper.GetString("namespace")
fmt.Println("using namespace:", namespace)
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -322,7 +322,9 @@ func RunE2E(clientset *kubernetes.Clientset) {

// Cleanup removes all resources created during E2E tests.
func Cleanup(clientset *kubernetes.Clientset) {
common.SetDefaultNamespace()
Copy link
Contributor

Choose a reason for hiding this comment

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

@Bharadwajshivam28 I think we can call this from cmd/root.go before calling Cleanup

Copy link
Member Author

Choose a reason for hiding this comment

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

can you please make me understand this? I think you are saying to call this common.SetDefaultNamespace() from the root.go?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

@Bharadwajshivam28 Bharadwajshivam28 Feb 13, 2024

Choose a reason for hiding this comment

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

oh.. you are saying to remove the line common.SetDefaultNamespace() from init.go and call it from here ?

if cleanup {
			common.SetDefaultNamespace()
			service.Cleanup(client.ClientSet)

from root.go file

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

@reetasingh
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 13, 2024
Signed-off-by: shivam <shivambharadwaj822@gmail.com>
@Bharadwajshivam28
Copy link
Member Author

Bharadwajshivam28 commented Feb 13, 2024

@reetasingh I moved common.SetDefaultNamespace() to root.go file and tested it too...

@Bharadwajshivam28
Copy link
Member Author

Bharadwajshivam28 commented Feb 13, 2024

@reetasingh Just a small review i need that for the unit test what i understand for the function SetDefaultNamespace is-

Case 1

  1. When Namespace is not passed, will set the DefaultNamespace.
  2. After setting Namespace will check if the current namespace matches the DefaultNamespace.

Case 2

  1. When Namespace is already set.
  2. When Namesapce is set then we will check that the Namespace should not be replaced with the Default Namespace. Will call the SetDefaultNamespace() function before checking that the namespace not gets replaced with DefaultNamespace.

I saw the Pre declared test in args_test.go file.

Is this way we are looking? as the function SetDefaultNamespace just checks and sets namespace.

@reetasingh
Copy link
Contributor

reetasingh commented Feb 14, 2024

@reetasingh Just a small review i need that for the unit test what i understand for the function SetDefaultNamespace is-

Case 1

  1. When Namespace is not passed, will set the DefaultNamespace.
  2. After setting Namespace will check if the current namespace matches the DefaultNamespace.

Case 2

  1. When Namespace is already set.
  2. When Namesapce is set then we will check that the Namespace should not be replaced with the Default Namespace. Will call the SetDefaultNamespace() function before checking that the namespace not gets replaced with DefaultNamespace.

I saw the Pre declared test in args_test.go file.

Is this way we are looking? as the function SetDefaultNamespace just checks and sets namespace.

@Bharadwajshivam28 Its easier to review if you write the test case itself. and yes, right for each of the test case above do viper.get("namespace") and check the value of namespace matches what is expected

@reetasingh
Copy link
Contributor

reetasingh commented Feb 14, 2024

I see the presumbit job is failing

sigs.k8s.io/hydrophone/pkg/common	0.017s
FAIL	sigs.k8s.io/hydrophone/pkg/service [build failed]
FAIL
make: *** [Makefile:25: test] Error 1

can you run make test locally to see everything passes?

@Bharadwajshivam28
Copy link
Member Author

I see the presumbit job is failing

sigs.k8s.io/hydrophone/pkg/common	0.017s
FAIL	sigs.k8s.io/hydrophone/pkg/service [build failed]
FAIL
make: *** [Makefile:25: test] Error 1

can you run make test locally to see everything passes?

ya let me check it

@Bharadwajshivam28
Copy link
Member Author

Bharadwajshivam28 commented Feb 14, 2024

@reetasingh Just a small review i need that for the unit test what i understand for the function SetDefaultNamespace is-
Case 1

  1. When Namespace is not passed, will set the DefaultNamespace.
  2. After setting Namespace will check if the current namespace matches the DefaultNamespace.

Case 2

  1. When Namespace is already set.
  2. When Namesapce is set then we will check that the Namespace should not be replaced with the Default Namespace. Will call the SetDefaultNamespace() function before checking that the namespace not gets replaced with DefaultNamespace.

I saw the Pre declared test in args_test.go file.
Is this way we are looking? as the function SetDefaultNamespace just checks and sets namespace.

@Bharadwajshivam28 Its easier to review if you write the test case itself. and yes, right for each of the test case above do viper.get("namespace") and check the value of namespace matches what is expected

Just a question @reetasingh our default namespace is conformance which will be set if namespace is not passed and if user passes the namespace then we just need to skip the test. like we dont need to do any action if users passes the namespace we just need to take actions in when users don't pass namespace..

Like we can log the namespace in both cases

Signed-off-by: shivam <shivambharadwaj822@gmail.com>
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 14, 2024
@Bharadwajshivam28
Copy link
Member Author

I see the presumbit job is failing

sigs.k8s.io/hydrophone/pkg/common	0.017s
FAIL	sigs.k8s.io/hydrophone/pkg/service [build failed]
FAIL
make: *** [Makefile:25: test] Error 1

can you run make test locally to see everything passes?

Pushed the code which fixes test
Screenshot from 2024-02-14 08-03-07

@rjsadow
Copy link
Collaborator

rjsadow commented Feb 14, 2024

Please run make fmt and commit to make the verify test pass.

Signed-off-by: shivam <shivambharadwaj822@gmail.com>
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 14, 2024
@reetasingh
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 15, 2024
@Bharadwajshivam28
Copy link
Member Author

Is there any more changes to be done mam @reetasingh

@rjsadow
Copy link
Collaborator

rjsadow commented Feb 15, 2024

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Bharadwajshivam28, rjsadow

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 15, 2024
@k8s-ci-robot k8s-ci-robot merged commit eb138c8 into kubernetes-sigs:main Feb 15, 2024
7 checks passed
@Bharadwajshivam28 Bharadwajshivam28 deleted the default_namespace branch February 16, 2024 00:34
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hydrophone --cleanup is broken
4 participants