e2e-framework icon indicating copy to clipboard operation
e2e-framework copied to clipboard

support/kind: create kubeconfig with stdout

Open heylongdacoder opened this issue 2 years ago • 26 comments
trafficstars

What type of PR is this?

/kind bug

What this PR does / why we need it:

The current kubeconfig is created with both stdout and stderr. We should only use stdout to create the kubeconfig.

Which issue(s) this PR fixes:

Fixes #347

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., Usage docs, etc.:

NONE

heylongdacoder avatar Nov 04 '23 10:11 heylongdacoder

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: heylongdacoder / name: Wen Long (02eca98bf5fc6c2e9f2f55a2b0b34830c5b9b8c2)

Welcome @heylongdacoder!

It looks like this is your first PR to kubernetes-sigs/e2e-framework 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/e2e-framework has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. :smiley:

k8s-ci-robot avatar Nov 04 '23 10:11 k8s-ci-robot

Hi @heylongdacoder. 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 avatar Nov 04 '23 10:11 k8s-ci-robot

Definitely, nice to have!

tingsl409 avatar Nov 04 '23 11:11 tingsl409

/ok-to-test

harshanarayana avatar Nov 04 '23 19:11 harshanarayana

/retest

harshanarayana avatar Nov 04 '23 20:11 harshanarayana

/retest

heylongdacoder avatar Nov 05 '23 01:11 heylongdacoder

seems like the TestKwokCluster is completely broken, I can try to have a look. But should I open another Issue and PR for that? Or I can do it with this PR? 😄

heylongdacoder avatar Nov 05 '23 06:11 heylongdacoder

/retest

heylongdacoder avatar Nov 05 '23 10:11 heylongdacoder

The test passed. 😄

heylongdacoder avatar Nov 05 '23 12:11 heylongdacoder

@heylongdacoder You are right. That test has been flaking a bit lately. I will take a look at that over the weekend to see if we can fix that once and for all.

/lgtm

/cc @vladimirvivien

harshanarayana avatar Nov 06 '23 11:11 harshanarayana

Thanks for the review, everyone!

@vladimirvivien, I agree with your suggestion. Just want to confirm before I implement. Is that your idea is to add one more field to kind.Cluster(https://github.com/kubernetes-sigs/e2e-framework/blob/main/support/kind/kind.go#L43) like getKubeConfigOpts []string? 😄

heylongdacoder avatar Nov 12 '23 15:11 heylongdacoder

@heylongdacoder yes, you will need a field to capture that configuration

*Cluster.WithQuiet()

Or something like that.

vladimirvivien avatar Nov 12 '23 16:11 vladimirvivien

@vladimirvivien, please correct me if I misunderstood, are you suggesting that WithQuiet() will append -q to all the kind commands, such as kind get kubeconfig, kind create cluster, and so on? However, in my case, I only want the framework to produce a correct kubeconfig without silencing other commands. Now, I have another idea to fix this.

var stdout, stderr bytes.Buffer
p := gexe.NewProc(fmt.Sprintf(`%s get kubeconfig --name %s`, k.path, k.name))
p.SetStdout(&stdout)
p.SetStderr(&stderr)

What if we maintain the current get kubeconfig command and separate stdout and stderr? Stdout will be used to create the kubeconfig, and stderr will be used for logging, like log.V(4).Info(stderr.String()).

WDYT? 😄

heylongdacoder avatar Nov 13 '23 08:11 heylongdacoder

@heylongdacoder originally, yes that was the intention. When/if someone uses Cluster.WithQuiet, it would append the -q to the command and therefore ignores errors. But, as you pointed out, it would

With respect to your new suggestion, how would separating the output help ? Let me know.

Another approach is to add a new method for getting the kubeconfig with options.

func (k *Cluster) GetKubeconfigWithOption(opts ...support.ClusterOpts) (string, error) {
...
}

Let me know if that makes sense.

vladimirvivien avatar Nov 19 '23 18:11 vladimirvivien

With respect to your new suggestion, how would separating the output help ? Let me know.

Screenshot 2023-11-20 at 2 25 34 PM

^This is the combined stderr and stdout output.

Screenshot 2023-11-20 at 2 25 49 PM

^This is stdout output

Screenshot 2023-11-20 at 2 41 22 PM

^This is stderr output

@vladimirvivien This is the result I obtained with kind v0.17.0. Therefore, using only stdout to create the kubeconfig can also resolve this issue. 😄

heylongdacoder avatar Nov 20 '23 07:11 heylongdacoder

@heylongdacoder I get a different result running on MacOS

 kind get kubeconfig --name kind
apiVersion: v1
clusters:
...

Notice that there is no extraneous text in the combined about, just the config. And my version

kind version
kind v0.17.0 go1.19 darwin/arm64

Is this behavior tied to your environment ?

I am asking these questions to make sure this will be a one-off and that it is a general fix/enhancement.

vladimirvivien avatar Nov 20 '23 23:11 vladimirvivien

@vladimirvivien I guess this only happen when you are using podman as kind provider. I also found another merged PR(https://github.com/kubernetes-sigs/e2e-framework/pull/84) that fixed this issue. 😄

heylongdacoder avatar Nov 21 '23 12:11 heylongdacoder

@heylongdacoder Ok. So can this PR be closed ? Or does #84 fixes your issue?

vladimirvivien avatar Nov 24 '23 13:11 vladimirvivien

@vladimirvivien I think there was a regression. In #84, the kubeconfig was being retrieved from stdout (https://github.com/kubernetes-sigs/e2e-framework/pull/84/files#diff-c66ce9879f2c64ba698cc9f0688530c2068a838797e98b94080045eb1122d235R58). However, in the latest code (https://github.com/kubernetes-sigs/e2e-framework/blob/main/support/kind/kind.go#L119), it seems to be using both stderr and stdout again. 😄

I think the fixes in #84 make sense, I would like to do a similar fix. 🙏

heylongdacoder avatar Nov 24 '23 13:11 heylongdacoder

Ok @heylongdacoder , can this PR put back what got regressed in #84 and we'll (re)start from there.

vladimirvivien avatar Nov 24 '23 13:11 vladimirvivien

/retest

heylongdacoder avatar Nov 27 '23 02:11 heylongdacoder

We run into the same. Thanks @heylongdacoder for the PR. Will you have time to finish the PR?

Cajga avatar Feb 26 '24 10:02 Cajga

hey @Cajga, recently got very busy with my new job. Probably I will have time to continue this weekend. Thanks!

heylongdacoder avatar Mar 01 '24 01:03 heylongdacoder

@heylongdacoder Any progress on this front ?

vladimirvivien avatar Apr 08 '24 14:04 vladimirvivien

yes, tested with podman and kind on my M1 chip Macbook. 😄

heylongdacoder avatar Apr 26 '24 02:04 heylongdacoder

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: harshanarayana, heylongdacoder

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 avatar Apr 29 '24 09:04 k8s-ci-robot