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

Add variable for global flags to runlabel #2905

Merged
merged 1 commit into from May 3, 2019

Conversation

QiWang19
Copy link
Collaborator

@QiWang19 QiWang19 commented Apr 11, 2019

close #2399
use $GLOBAL_OPTS to pass global flags to the runlabel command.
Signed-off-by: Qi Wang qiwan@redhat.com

@QiWang19
Copy link
Collaborator Author

@mheon will this satisfy the requirement in #2399 ? Then I need to look up the flags in GlobalFlags?

@QiWang19 QiWang19 changed the title [WPI]Add variable for global flags to runlabel [WIP]Add variable for global flags to runlabel Apr 11, 2019
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 11, 2019
@mheon
Copy link
Member

mheon commented Apr 11, 2019

Initial impression is that this looks about right - just needs to pick up the rest of the local flags

@QiWang19 QiWang19 changed the title [WIP]Add variable for global flags to runlabel Add variable for global flags to runlabel Apr 12, 2019
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 12, 2019
@QiWang19
Copy link
Collaborator Author

do I need to add tests for this?

@mheon
Copy link
Member

mheon commented Apr 15, 2019

Tests are always appreciated!

@QiWang19
Copy link
Collaborator Author

Test added

@TomSweeneyRedHat
Copy link
Member

/approved

@@ -179,3 +180,66 @@ func runlabelCmd(c *cliconfig.RunlabelValues) error {

return utils.ExecCmdWithStdStreams(stdIn, stdOut, stdErr, env, cmd[0], cmd[1:]...)
}

func getGlobalOpts(c *cliconfig.RunlabelValues) string {
Copy link
Member

Choose a reason for hiding this comment

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

@mheon, should this live in a common or util file somewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've moved it to package util

@TomSweeneyRedHat
Copy link
Member

LGTM, just one question on a final resting place for one of the functions.

@@ -60,6 +60,8 @@ func GenerateCommand(command, imageName, name string) ([]string, error) {
}
newCommand = append(newCommand, prog)

fmt.Println(strings.Join(cmd, ","))
Copy link
Member

Choose a reason for hiding this comment

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

Leftover debug?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah... deleted.

@@ -324,3 +325,67 @@ func ParseInputTime(inputTime string) (time.Time, error) {
}
return time.Now().Add(-duration), nil
}

// GetGlobalOpts checks all global flags and generates the command string
func GetGlobalOpts(c *cliconfig.RunlabelValues) string {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can somehow pull the names of the global flags straight out of Cobra - @baude you know if there's a way to do this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I found FlagSet.VisitAll() for all flags, not just for global flags...

Copy link
Member

Choose a reason for hiding this comment

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

Hm. This could be painful if we add more global flags, but no helping that, I suppose.

@mheon
Copy link
Member

mheon commented Apr 17, 2019

/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mheon, QiWang19

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-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 17, 2019
@rh-atomic-bot
Copy link
Collaborator

☔ The latest upstream changes (presumably #3031) made this pull request unmergeable. Please resolve the merge conflicts.

@mheon
Copy link
Member

mheon commented May 1, 2019

LGTM
@rhatdan @baude @vrothberg @TomSweeneyRedHat PTAL

use $GLOBAL_OPTS to pass global flags to the runlabel command.

Signed-off-by: Qi Wang <qiwan@redhat.com>
// GetGlobalOpts checks all global flags and generates the command string
func GetGlobalOpts(c *cliconfig.RunlabelValues) string {
globalFlags := map[string]bool{
"cgroup-manager": true, "cni-config-dir": true, "conmon": true, "default-mounts-file": true,
Copy link
Member

Choose a reason for hiding this comment

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

Separate PR, but could you move this to main_local.go
Add one line after each global flag gets added

	rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.CGroupManager, "cgroup-manager", "", "Cgroup manager to use (cgroupfs or systemd, default systemd)")
        globalFlags["cgroup-manager"]=true
	rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.CpuProfile, "cpu-profile", "", "Path for the cpu profiling results")
        globalFlags["cpu-profile"]=true

That way if a user adds a global flag, it is much more likely they will do the right thing.

@rhatdan
Copy link
Member

rhatdan commented May 3, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 3, 2019
@openshift-merge-robot openshift-merge-robot merged commit a7809fa into containers:master May 3, 2019
@QiWang19 QiWang19 deleted the globalvar branch June 26, 2020 15:11
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add variable for global flags to runlabel command
7 participants