10000 cert-manager-ctl CLI with version by JoshVanL · Pull Request #2725 · cert-manager/cert-manager · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cert-manager-ctl CLI with version #2725

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

Merged
merged 8 commits into from
Apr 8, 2020

Conversation

JoshVanL
Copy link
Contributor
@JoshVanL JoshVanL commented Mar 21, 2020

This PR adds the cert-manager-ctl CLI which has a version sub command.

Currently also gets built to a binary in the host arch.

TODO: fix version injection

Adds cert-manager-ctl command with version

/assign @munnerz

8000
@jetstack-bot jetstack-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Mar 21, 2020
@jetstack-bot jetstack-bot requested a review from munnerz March 21, 2020 18:41
@jetstack-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JoshVanL

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

@jetstack-bot jetstack-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 21, 2020
cmd/ctl/main.go Outdated
func SetupSignalHandler() (stopCh <-chan struct{}) {
stop := make(chan struct{})
c := make(chan os.Signal, 2)
signal.Notify(c, []os.Signal{os.Interrupt, syscall.SIGTERM}...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would signal.Notify(c, os.Interrupt, syscall.SIGTERM) not be simpler here?


// Run executes version command
func (o *Options) Run() error {
var err error
Copy link
Contributor

Choose a reason for hiding this comment

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

We never seem to use this error

= vendor/github.com/fatih/color/LICENSE.md 316e6d590bdcde7993fb175662c0dd5a
================================================================================

= vendor/github.com/docker/docker licensed under: =
Copy link
Member

Choose a reason for hiding this comment

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

🙄 what caused us to start depending on docker/docker?! 😬

Copy link
Member
@munnerz munnerz left a comment

Choose a reason for hiding this comment

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

Looking good! I'm going to give this a go locally and get it running - we can get the release targets wired up after this merges...

cmd/ctl/cmd.go Outdated
@@ -0,0 +1,45 @@
/*
Copyright 2019 The Jetstack cert-manager contributors.
Copy link
Member

Choose a reason for hiding this comment

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

nit: 2020

cmd/ctl/main.go Outdated
@@ -0,0 +1,53 @@
/*
Copyright 2019 The Jetstack cert-manager contributors.
Copy link
Member

Choose a reason for hiding this comment

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

nit: 2020

cmd/ctl/main.go Outdated
// SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned
// which is closed on one of these signals. If a second signal is caught, the program
// is terminated with exit code 1.
func SetupSignalHandler() (stopCh <-chan struct{}) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: doesn't this exist somewhere already? If not, can we un-export this? It's not importable anyway as this is a main package so 🤷‍♂

@@ -0,0 +1,105 @@
/*
Copyright 2019 The Jetstack cert-manager contributors.
Copy link
Member

Choose a reason for hiding this comment

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

nit: 2020

// Options is a struct to support version command
type Options struct {
Output string
Short bool
Copy link
Member

Choose a reason for hiding this comment

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

nit: comments here would be great - could just be copied from the flag description

},
}

cmd.Flags().StringVarP(&o.Output, "output", "o", o.Output, "One of 'yaml' or 'json'.")
Copy link
Member
10000

Choose a reason for hiding this comment

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

You're setting the default value here to o.Output - shouldn't this be yaml or json? It'll be `` (empty) otherwise

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, I see, 'empty' means 'human readable'. Maybe just change this to "" then instead of o.Short? :)

}

cmd.Flags().StringVarP(&o.Output, "output", "o", o.Output, "One of 'yaml' or 'json'.")
cmd.Flags().BoolVar(&o.Short, "short", o.Short, "If true, print just the version number.")
Copy link
Member

Choose a reason for hiding this comment

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

Again, not sure why defaulting to o.Short - can you change this to be false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Taken from kubectl code. I agree, hate that

go.mod Outdated
k8s.io/cli-runtime v0.17.4
k8s.io/client-go v0.17.4
k8s.io/code-generator v0.17.4
k8s.io/component-base v0.17.4
Copy link
Member

Choose a reason for hiding this comment

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

FYI #2731 will conflict with this PR, depending which merges first 😄

Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}

func version() string {
Copy link
Member

Choose a reason for hiding this comment

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

May be one for a follow up, but can we remove this function now? canary should never be set as the version tag anymore since the build infra changes. May be easiest to follow up though 😄

@munnerz
Copy link
Member
munnerz commented Mar 24, 2020

Also, this pulls in github.com/docker/docker via:

$ go mod why -m github.com/docker/docker
# github.com/docker/docker
github.com/jetstack/cert-manager/cmd/ctl/pkg/version
k8s.io/kubectl/pkg/cmd/util
k8s.io/kubectl/pkg/util/templates
k8s.io/kubectl/pkg/util/term
github.com/docker/docker/pkg/term

@munnerz
Copy link
Member
munnerz commented Mar 24, 2020

Hm, it also appears that the dependency has changed to use moby/moby in Kubernetes 1.18... may be worth waiting until #2731 merges? Unless we remove use of CheckErr, this looks non-trivial to extract code to avoid the extra dependency.

@munnerz munnerz added this to the v0.15 milestone Mar 25, 2020
cmd/ctl/main.go Outdated
)

func main() {
stopCh := genericapiserver.SetupSignalHandler()
Copy link
Member

Choose a reason for hiding this comment

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

nit (one to follow up on as there's a few places that call this) - given the generic nature of the pkg/server package, I'm concerned that this probably adds some extra bloat to all our binaries when it is pulled in. This will be especially relevant with a CLI tool as users will be downloading this to their own machines. Perhaps we should have our own version of this in the repo 😄

cmd/ctl/cmd.go Outdated
Use: "cert-manager-ctl",
Short: "cert-manager CLI tool to manage and configure cert-manager resources",
Long: `
cert-manager-ctl is a CLI tool managage and confiure cert-manager resources for Kubernetes`,
Copy link
Member

Choose a reason for hiding this comment

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

configure

JoshVanL added 7 commits April 1, 2020 18:54
Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
@JoshVanL JoshVanL force-pushed the ctl-version branch 2 times, most recently from 82187b9 to 2ed9ec4 Compare April 1, 2020 19:36
Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
@munnerz
Copy link
Member
munnerz commented Apr 8, 2020

/lgtm
/kind feature

@jetstack-bot jetstack-bot added lgtm Indicates that a PR is ready to be merged. kind/feature Categorizes issue or PR as related to a new feature. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Apr 8, 2020
@jetstack-bot jetstack-bot merged commit fba7b09 into cert-manager:master Apr 8, 2020
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. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0