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

app.NewCloudControllerManagerCommand additionalFlags not working as expected #62

Closed
snebel29 opened this issue Jun 2, 2022 · 6 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@snebel29
Copy link

snebel29 commented Jun 2, 2022

Hi,
Poking around with app.NewCloudControllerManagerCommand I noticed additionalFlags argument does not seems to be working as I would expect, while the flag is parsed it is not show in the usage or help.

When an additional flagSet is passed it is parsed, and can be used however it is not shown in the usage or help of the command.

To reproduce, use the following snippet of code:

package main

import (
	"os"

	"k8s.io/apimachinery/pkg/util/wait"
	cloudprovider "k8s.io/cloud-provider"
	"k8s.io/cloud-provider/app"
	"k8s.io/cloud-provider/app/config"
	"k8s.io/cloud-provider/fake"
	"k8s.io/cloud-provider/options"
	kflag "k8s.io/component-base/cli/flag"
	klog "k8s.io/klog/v2"
)

var myFlag string

func main() {

	additionalFlags := kflag.NamedFlagSets{}
	additionalFlags.FlagSet("myFlagSet").StringVar(&myFlag, "abcd", "defaultValue", "n/a")

	opts, err := options.NewCloudControllerManagerOptions()
	if err != nil {
		klog.Fatalf("Failed to create new cloud controller manager options: %v", err)
	}
	opts.KubeCloudShared.CloudProvider.Name = "myProvider"
	home, _ := os.LookupEnv("HOME")
	opts.Kubeconfig = home + "/.kube/config"

	command := app.NewCloudControllerManagerCommand(
		opts,
		cloudProviderInitializer,
		app.DefaultInitFuncConstructors,
		additionalFlags,
		wait.NeverStop,
	)

	if err := command.Execute(); err != nil {
		klog.Fatalf("Failed to execute cloud controller manager command: %v", err)
	}
}

func cloudProviderInitializer(_ *config.CompletedConfig) cloudprovider.Interface {
	klog.Info("abcd flag value is: ", myFlag)
	return &fake.Cloud{}
}

The flag is not shown in the help with the existing cloud controller manager flags, the following command return no results.

$ go run cmd/test/main.go --help |grep abcd

While the flag has been really bound and parsed and can In fact be used.

$  go run cmd/test/main.go --abcd 123456             
I0602 19:23:40.055119   44145 serving.go:348] Generated self-signed cert in-memory
W0602 19:23:40.376430   44145 authentication.go:317] No authentication-kubeconfig provided in order to lookup client-ca-file in configmap/extension-apiserver-authentication in kube-system, so client certificate authentication won't work.
W0602 19:23:40.376466   44145 authentication.go:341] No authentication-kubeconfig provided in order to lookup requestheader-client-ca-file in configmap/extension-apiserver-authentication in kube-system, so request-header client certificate authentication won't work.
W0602 19:23:40.376521   44145 authorization.go:193] No authorization-kubeconfig provided, so SubjectAccessReview of authorization tokens won't work.
I0602 19:23:40.381690   44145 main.go:45] abcd flag value is: 123456

It does feel either a bug or an unimplemented feature, while the additional flags are successfully bound in

fs.AddFlagSet(f)

The problem seems to be in the the use namedFlagSets which does not contain the additional flags to print he usage and help sections

cliflag.PrintSections(cmd.OutOrStderr(), namedFlagSets, cols)

cliflag.PrintSections(cmd.OutOrStdout(), namedFlagSets, cols)

I wouldn't mind having a closer look and propose a fix if one would be accepted, I just wanted to share and get feedback first to ensure this make sense.

Cheers.

@snebel29
Copy link
Author

Hi, If I spend my time looking to propose a fix to this issue, and assuming the code is good, would it be reviewed and merged?

Thank in advance.

@snebel29
Copy link
Author

I have created kubernetes/kubernetes#112405 with a fix for this which is awaiting for review, feedback is welcomed.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 12, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jan 11, 2023
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

3 participants