Updates all sub commands to discover the CLI name using the build

package name

Signed-off-by: joshvanl <vleeuwenjoshua@gmail.com>
This commit is contained in:
joshvanl
2021-10-14 14:45:01 +01:00
parent 5f5217b412
commit ce1424162e
27 changed files with 125 additions and 90 deletions
+1
View File
@@ -33,6 +33,7 @@ filegroup(
":package-srcs",
"//cmd/ctl/cmd:all-srcs",
"//cmd/ctl/pkg/approve:all-srcs",
"//cmd/ctl/pkg/build:all-srcs",
"//cmd/ctl/pkg/check:all-srcs",
"//cmd/ctl/pkg/completion:all-srcs",
"//cmd/ctl/pkg/convert:all-srcs",
+1
View File
@@ -6,6 +6,7 @@ go_library(
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/approve",
visibility = ["//visibility:public"],
deps = [
"//cmd/ctl/pkg/build:go_default_library",
"//cmd/ctl/pkg/factory:go_default_library",
"//pkg/api/util:go_default_library",
"//pkg/apis/certmanager/v1:go_default_library",
+7 -6
View File
@@ -28,6 +28,7 @@ import (
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
apiutil "github.com/jetstack/cert-manager/pkg/api/util"
cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
@@ -35,16 +36,16 @@ import (
)
var (
example = templates.Examples(i18n.T(`
example = templates.Examples(i18n.T(build.WithTemplate(`
# Approve a CertificateRequest with the name 'my-cr'
kubectl cert-manager approve my-cr
{{.BuildName}} approve my-cr
# Approve a CertificateRequest in namespace default
kubectl cert-manager approve my-cr --namespace default
{{.BuildName}} approve my-cr --namespace default
# Approve a CertificateRequest giving a custom reason and message
kubectl cert-manager approve my-cr --reason "ManualApproval" --reason "Approved by PKI department"
`))
{{.BuildName}} approve my-cr --reason "ManualApproval" --reason "Approved by PKI department"
`)))
)
// Options is a struct to support create certificaterequest command
@@ -84,7 +85,7 @@ func NewCmdApprove(ctx context.Context, ioStreams genericclioptions.IOStreams) *
cmd.Flags().StringVar(&o.Reason, "reason", "KubectlCertManager",
"The reason to give as to what approved this CertificateRequest.")
cmd.Flags().StringVar(&o.Message, "message", `manually approved by "kubectl cert-manager"`,
cmd.Flags().StringVar(&o.Message, "message", fmt.Sprintf("manually approved by %q", build.Name()),
"The message to give as to why this CertificateRequest was approved.")
o.Factory = factory.New(ctx, cmd)
+1
View File
@@ -12,6 +12,7 @@ go_library(
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/completion",
visibility = ["//visibility:public"],
deps = [
"//cmd/ctl/pkg/build:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@io_k8s_cli_runtime//pkg/genericclioptions:go_default_library",
"@io_k8s_kubectl//pkg/cmd/util:go_default_library",
+7 -5
View File
@@ -20,22 +20,24 @@ import (
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/cmd/util"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
)
func newCmdCompletionBash(ioStreams genericclioptions.IOStreams) *cobra.Command {
return &cobra.Command{
Use: "bash",
Short: "Generate cert-manager CLI scripts for a Bash shell",
Long: `To load completions:
Long: build.WithTemplate(`To load completions:
Bash:
$ source <(kubectl cert-manager completion bash)
$ source <({{.BuildName}} completion bash)
# To load completions for each session, execute once:
# Linux:
$ cert-manager completion bash > /etc/bash_completion.d/cert-manager
$ {{.BuildName}} completion bash > /etc/bash_completion.d/{{.BuildName}}
# macOS:
$ cert-manager completion bash > /usr/local/etc/bash_completion.d/cert-manager
`,
$ {{.BuildName}} completion bash > /usr/local/etc/bash_completion.d/{{.BuildName}}
`),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(cmd.Root().GenBashCompletion(ioStreams.Out))
+6 -4
View File
@@ -20,18 +20,20 @@ import (
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/cmd/util"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
)
func newCmdCompletionFish(ioStreams genericclioptions.IOStreams) *cobra.Command {
return &cobra.Command{
Use: "fish",
Short: "Generate cert-manager CLI scripts for a Fish shell",
Long: `To load completions:
$ cert-manager completion fish | source
Long: build.WithTemplate(`To load completions:
$ {{.BuildName}} completion fish | source
# To load completions for each session, execute once:
$ cert-manager completion fish > ~/.config/fish/completions/cert-manager.fish
`,
$ {{.BuildName}} completion fish > ~/.config/fish/completions/{{.BuildName}}.fish
`),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(cmd.Root().GenFishCompletion(ioStreams.Out, true))
+6 -4
View File
@@ -20,19 +20,21 @@ import (
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/cmd/util"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
)
func newCmdCompletionPowerShell(ioStreams genericclioptions.IOStreams) *cobra.Command {
return &cobra.Command{
Use: "powershell",
Short: "Generate cert-manager CLI scripts for a PowerShell shell",
Long: `To load completions:
PS> cert-manager completion powershell | Out-String | Invoke-Expression
Long: build.WithTemplate(`To load completions:
PS> {{.BuildName}} completion powershell | Out-String | Invoke-Expression
# To load completions for every new session, run:
PS> cert-manager completion powershell > cert-manager.ps1
PS> {{.BuildName}} completion powershell > {{.BuildName}}.ps1
# and source this file from your PowerShell profile.
`,
`),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(cmd.Root().GenPowerShellCompletion(ioStreams.Out))
+5 -3
View File
@@ -20,21 +20,23 @@ import (
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/cmd/util"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
)
func newCmdCompletionZSH(ioStreams genericclioptions.IOStreams) *cobra.Command {
return &cobra.Command{
Use: "zsh",
Short: "Generation cert-manager CLI scripts for a ZSH shell",
Long: `To load completions:
Long: build.WithTemplate(`To load completions:
# If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once:
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
# To load completions for each session, execute once:
$ cert-manager completion zsh > "${fpath[1]}/_cert-manager"
$ {{.BuildName}} completion zsh > "${fpath[1]}/_{{.BuildName}}"
# You will need to start a new shell for this setup to take effect.
`,
`),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(cmd.Root().GenZshCompletion(ioStreams.Out))
+1
View File
@@ -6,6 +6,7 @@ go_library(
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/convert",
visibility = ["//visibility:public"],
deps = [
"//cmd/ctl/pkg/build:go_default_library",
"//pkg/ctl:go_default_library",
"//pkg/logs:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
+4 -3
View File
@@ -20,6 +20,7 @@ import (
"context"
"fmt"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
logf "github.com/jetstack/cert-manager/pkg/logs"
"github.com/spf13/cobra"
@@ -39,12 +40,12 @@ import (
)
var (
example = templates.Examples(i18n.T(`
example = templates.Examples(i18n.T(build.WithTemplate(`
# Convert 'cert.yaml' to latest version and print to stdout.
kubectl cert-manager convert -f cert.yaml
{{.BuildName}} convert -f cert.yaml
# Convert kustomize overlay under current directory to 'cert-manager.io/v1alpha3'
kubectl cert-manager convert -k . --output-version cert-manager.io/v1alpha3`))
{{.BuildName}} convert -k . --output-version cert-manager.io/v1alpha3`)))
longDesc = templates.LongDesc(i18n.T(`
Convert cert-manager config files between different API versions. Both YAML
@@ -6,6 +6,7 @@ go_library(
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/create/certificaterequest",
visibility = ["//visibility:public"],
deps = [
"//cmd/ctl/pkg/build:go_default_library",
"//cmd/ctl/pkg/factory:go_default_library",
"//pkg/api/util:go_default_library",
"//pkg/apis/certmanager/v1:go_default_library",
@@ -35,6 +35,7 @@ import (
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
apiutil "github.com/jetstack/cert-manager/pkg/api/util"
cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
@@ -47,22 +48,22 @@ var (
long = templates.LongDesc(i18n.T(`
Create a new CertificateRequest resource based on a Certificate resource, by generating a private key locally and create a 'certificate signing request' to be submitted to a cert-manager Issuer.`))
example = templates.Examples(i18n.T(`
example = templates.Examples(i18n.T(build.WithTemplate(`
# Create a CertificateRequest with the name 'my-cr', saving the private key in a file named 'my-cr.key'.
kubectl cert-manager create certificaterequest my-cr --from-certificate-file my-certificate.yaml
{{.BuildName}} create certificaterequest my-cr --from-certificate-file my-certificate.yaml
# Create a CertificateRequest in namespace default, provided no conflict with namespace defined in file.
kubectl cert-manager create certificaterequest my-cr --namespace default --from-certificate-file my-certificate.yaml
{{.BuildName}} create certificaterequest my-cr --namespace default --from-certificate-file my-certificate.yaml
# Create a CertificateRequest and store private key in file 'new.key'.
kubectl cert-manager create certificaterequest my-cr --from-certificate-file my-certificate.yaml --output-key-file new.key
{{.BuildName}} create certificaterequest my-cr --from-certificate-file my-certificate.yaml --output-key-file new.key
# Create a CertificateRequest, wait for it to be signed for up to 5 minutes (default) and store the x509 certificate in file 'new.crt'.
kubectl cert-manager create certificaterequest my-cr --from-certificate-file my-certificate.yaml --fetch-certificate --output-cert-file new.crt
{{.BuildName}} create certificaterequest my-cr --from-certificate-file my-certificate.yaml --fetch-certificate --output-cert-file new.crt
# Create a CertificateRequest, wait for it to be signed for up to 20 minutes and store the x509 certificate in file 'my-cr.crt'.
kubectl cert-manager create certificaterequest my-cr --from-certificate-file my-certificate.yaml --fetch-certificate --timeout 20m
`))
{{.BuildName}} create certificaterequest my-cr --from-certificate-file my-certificate.yaml --fetch-certificate --timeout 20m
`)))
)
var (
@@ -6,6 +6,7 @@ go_library(
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/create/certificatesigningrequest",
visibility = ["//visibility:public"],
deps = [
"//cmd/ctl/pkg/build:go_default_library",
"//cmd/ctl/pkg/factory:go_default_library",
"//pkg/api/util:go_default_library",
"//pkg/apis/certmanager:go_default_library",
@@ -39,6 +39,7 @@ import (
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
apiutil "github.com/jetstack/cert-manager/pkg/api/util"
"github.com/jetstack/cert-manager/pkg/apis/certmanager"
@@ -54,19 +55,19 @@ cert-manager versions 1.4+ with experimental controllers enabled.
Create a new CertificateSigningRequest resource based on a Certificate resource, by generating a private key locally and create a 'certificate signing request' to be submitted to a cert-manager Issuer.`))
example = templates.Examples(i18n.T(`
example = templates.Examples(i18n.T(build.WithTemplate(`
# Create a CertificateSigningRequest with the name 'my-csr', saving the private key in a file named 'my-cr.key'.
kubectl cert-manager x create certificatesigningrequest my-csr --from-certificate-file my-certificate.yaml
{{.BuildName}} x create certificatesigningrequest my-csr --from-certificate-file my-certificate.yaml
# Create a CertificateSigningRequest and store private key in file 'new.key'.
kubectl cert-manager x create certificatesigningrequest my-csr --from-certificate-file my-certificate.yaml --output-key-file new.key
{{.BuildName}} x create certificatesigningrequest my-csr --from-certificate-file my-certificate.yaml --output-key-file new.key
# Create a CertificateSigningRequest, wait for it to be signed for up to 5 minutes (default) and store the x509 certificate in file 'new.crt'.
kubectl cert-manager x create csr my-cr -f my-certificate.yaml -c new.crt -w
{{.BuildName}} x create csr my-cr -f my-certificate.yaml -c new.crt -w
# Create a CertificateSigningRequest, wait for it to be signed for up to 20 minutes and store the x509 certificate in file 'my-cr.crt'.
kubectl cert-manager x create csr my-cr --from-certificate-file my-certificate.yaml --fetch-certificate --timeout 20m
`))
{{.BuildName}} x create csr my-cr --from-certificate-file my-certificate.yaml --fetch-certificate --timeout 20m
`)))
)
var (
+1
View File
@@ -6,6 +6,7 @@ go_library(
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/deny",
visibility = ["//visibility:public"],
deps = [
"//cmd/ctl/pkg/build:go_default_library",
"//cmd/ctl/pkg/factory:go_default_library",
"//pkg/api/util:go_default_library",
"//pkg/apis/certmanager/v1:go_default_library",
+7 -6
View File
@@ -28,6 +28,7 @@ import (
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
apiutil "github.com/jetstack/cert-manager/pkg/api/util"
cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
@@ -35,16 +36,16 @@ import (
)
var (
example = templates.Examples(i18n.T(`
example = templates.Examples(i18n.T(build.WithTemplate(`
# Deny a CertificateRequest with the name 'my-cr'
kubectl cert-manager deny my-cr
{{.BuildName}} deny my-cr
# Deny a CertificateRequest in namespace default
kubectl cert-manager deny my-cr --namespace default
{{.BuildName}} deny my-cr --namespace default
# Deny a CertificateRequest giving a custom reason and message
kubectl cert-manager deny my-cr --reason "ManualDenial" --reason "Denied by PKI department"
`))
{{.BuildName}} deny my-cr --reason "ManualDenial" --reason "Denied by PKI department"
`)))
)
// Options is a struct to support create certificaterequest command
@@ -84,7 +85,7 @@ func NewCmdDeny(ctx context.Context, ioStreams genericclioptions.IOStreams) *cob
cmd.Flags().StringVar(&o.Reason, "reason", "KubectlCertManager",
"The reason to give as to what denied this CertificateRequest.")
cmd.Flags().StringVar(&o.Message, "message", `manually denied by "kubectl cert-manager"`,
cmd.Flags().StringVar(&o.Message, "message", fmt.Sprintf("manually denied by %q", build.Name()),
"The message to give as to why this CertificateRequest was denied.")
o.Factory = factory.New(ctx, cmd)
+1
View File
@@ -9,6 +9,7 @@ go_library(
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/inspect/secret",
visibility = ["//visibility:public"],
deps = [
"//cmd/ctl/pkg/build:go_default_library",
"//cmd/ctl/pkg/factory:go_default_library",
"//pkg/apis/certmanager/v1:go_default_library",
"//pkg/apis/meta/v1:go_default_library",
+4 -3
View File
@@ -36,6 +36,7 @@ import (
"k8s.io/kubectl/pkg/util/templates"
k8sclock "k8s.io/utils/clock"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"
"github.com/jetstack/cert-manager/pkg/util/pki"
@@ -84,10 +85,10 @@ var (
long = templates.LongDesc(i18n.T(`
Get details about a kubernetes.io/tls typed secret`))
example = templates.Examples(i18n.T(`
example = templates.Examples(i18n.T(build.WithTemplate(`
# Query information about a secret with name 'my-crt' in namespace 'my-namespace'
kubectl cert-manager inspect secret my-crt --namespace my-namespace
`))
{{.BuildName}} inspect secret my-crt --namespace my-namespace
`)))
)
// Options is a struct to support status certificate command
+1
View File
@@ -9,6 +9,7 @@ go_library(
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/install",
visibility = ["//visibility:public"],
deps = [
"//cmd/ctl/pkg/build:go_default_library",
"//cmd/ctl/pkg/install/helm:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@com_github_spf13_pflag//:go_default_library",
+23 -19
View File
@@ -35,6 +35,7 @@ import (
"helm.sh/helm/v3/pkg/release"
"k8s.io/cli-runtime/pkg/genericclioptions"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/install/helm"
)
@@ -56,24 +57,26 @@ const (
defaultCertManagerNamespace = "cert-manager"
)
const installDesc = `This command installs cert-manager. It uses the Helm libraries to do so.
func installDesc() string {
return build.WithTemplate(`This command installs cert-manager. It uses the Helm libraries to do so.
The latest published cert-manager chart in the "https://charts.jetstack.io" repo is used.
Most of the features supported by 'helm install' are also supported by this command.
In addition, his command will always correctly install the required CRD resources.
Some example uses:
$ kubectl cert-manager x install
$ {{.BuildName}} x install
or
$ kubectl cert-manager x install -n new-cert-manager
$ {{.BuildName}} x install -n new-cert-manager
or
$ kubectl cert-manager x install --version v1.4.0
$ {{.BuildName}} x install --version v1.4.0
or
$ kubectl cert-manager x install --set prometheus.enabled=false
$ {{.BuildName}} x install --set prometheus.enabled=false
To override values in the cert-manager chart, use either the '--values' flag and
pass in a file or use the '--set' flag and pass configuration from the command line.
`
`)
}
func NewCmdInstall(ctx context.Context, ioStreams genericclioptions.IOStreams) *cobra.Command {
settings := cli.New()
@@ -91,7 +94,7 @@ func NewCmdInstall(ctx context.Context, ioStreams genericclioptions.IOStreams) *
cmd := &cobra.Command{
Use: "install",
Short: "Install cert-manager",
Long: installDesc,
Long: installDesc(),
RunE: func(cmd *cobra.Command, args []string) error {
options.client.Namespace = settings.Namespace()
@@ -130,18 +133,19 @@ func NewCmdInstall(ctx context.Context, ioStreams genericclioptions.IOStreams) *
return cmd
}
// The overall strategy is to install the CRDs first, and not as part of a Helm release,
// and then to install a Helm release without the CRDs.
// This is to ensure that CRDs are not removed by a subsequent helm uninstall or by a
// future kubectl cert-manager uninstall. We want the removal of CRDs to only be performed
// by an administrator who understands that the consequences of removing CRDs will be the
// garbage collection of all the related CRs in the cluster.
// We first do a dry-run install of the chart (effectively helm template --validate=false) to
// render the CRDs from the CRD templates in the Chart. The ClientOnly option is required,
// otherwise Helm will return an error in case the CRDs are already installed in the cluster.
// We then extract the CRDs from the resulting dry-run manifests and install those first.
// Finally, we perform a helm install to install the remaining non-CRD resources and wait for
// those to be "Ready".
// The overall strategy is to install the CRDs first, and not as part of a Helm
// release, and then to install a Helm release without the CRDs. This is to
// ensure that CRDs are not removed by a subsequent helm uninstall or by a
// future cmctl uninstall. We want the removal of CRDs to only be performed by
// an administrator who understands that the consequences of removing CRDs will
// be the garbage collection of all the related CRs in the cluster. We first
// do a dry-run install of the chart (effectively helm template
// --validate=false) to render the CRDs from the CRD templates in the Chart.
// The ClientOnly option is required, otherwise Helm will return an error in
// case the CRDs are already installed in the cluster. We then extract the
// CRDs from the resulting dry-run manifests and install those first. Finally,
// we perform a helm install to install the remaining non-CRD resources and
// wait for those to be "Ready".
// This creates a Helm "release" artifact in a Secret in the target namespace, which contains
// a record of all the resources installed by Helm (except the CRDs).
func (o *InstallOptions) runInstall(ctx context.Context) (*release.Release, error) {
+1 -1
View File
@@ -42,7 +42,7 @@ func addInstallFlags(f *pflag.FlagSet, client *action.Install) {
f.MarkHidden("generate-name")
f.StringVar(&client.NameTemplate, "name-template", "", "Specify template used to name the release")
f.MarkHidden("name-template")
f.StringVar(&client.Description, "description", "Cert-manager was installed using the cert-manager kubectl plugin", "Add a custom description")
f.StringVar(&client.Description, "description", "Cert-manager was installed using the cert-manager CLI", "Add a custom description")
f.MarkHidden("description")
}
+1
View File
@@ -6,6 +6,7 @@ go_library(
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/renew",
visibility = ["//visibility:public"],
deps = [
"//cmd/ctl/pkg/build:go_default_library",
"//cmd/ctl/pkg/factory:go_default_library",
"//pkg/api/util:go_default_library",
"//pkg/apis/certmanager/v1:go_default_library",
+5 -4
View File
@@ -30,6 +30,7 @@ import (
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
apiutil "github.com/jetstack/cert-manager/pkg/api/util"
cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
@@ -41,15 +42,15 @@ var (
long = templates.LongDesc(i18n.T(`
Mark cert-manager Certificate resources for manual renewal.`))
example = templates.Examples(i18n.T(`
example = templates.Examples(i18n.T(build.WithTemplate(`
# Renew the Certificates named 'my-app' and 'vault' in the current context namespace.
kubectl cert-manager renew my-app vault
{{.BuildName}} renew my-app vault
# Renew all Certificates in the 'kube-system' namespace.
kubectl cert-manager renew --namespace kube-system --all
{{.BuildName}} renew --namespace kube-system --all
# Renew all Certificates in all namespaces, provided those Certificates have the label 'app=my-service'
kubectl cert-manager renew --all-namespaces -l app=my-service`))
{{.BuildName}} renew --all-namespaces -l app=my-service`)))
)
// Options is a struct to support renew command
@@ -9,6 +9,7 @@ go_library(
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/status/certificate",
visibility = ["//visibility:public"],
deps = [
"//cmd/ctl/pkg/build:go_default_library",
"//cmd/ctl/pkg/factory:go_default_library",
"//cmd/ctl/pkg/status/util:go_default_library",
"//pkg/apis/acme/v1beta1:go_default_library",
@@ -32,6 +32,7 @@ import (
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
cmacme "github.com/jetstack/cert-manager/pkg/apis/acme/v1beta1"
cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
@@ -44,10 +45,10 @@ var (
long = templates.LongDesc(i18n.T(`
Get details about the current status of a cert-manager Certificate resource, including information on related resources like CertificateRequest or Order.`))
example = templates.Examples(i18n.T(`
example = templates.Examples(i18n.T(build.WithTemplate(`
# Query status of Certificate with name 'my-crt' in namespace 'my-namespace'
kubectl cert-manager status certificate my-crt --namespace my-namespace
`))
{{.BuildName}} status certificate my-crt --namespace my-namespace
`)))
)
// Options is a struct to support status certificate command
+1
View File
@@ -6,6 +6,7 @@ go_library(
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/version",
visibility = ["//visibility:public"],
deps = [
"//cmd/ctl/pkg/build:go_default_library",
"//cmd/ctl/pkg/factory:go_default_library",
"//pkg/util:go_default_library",
"//pkg/util/versionchecker:go_default_library",
+19 -16
View File
@@ -28,6 +28,7 @@ import (
"k8s.io/kubectl/pkg/scheme"
"sigs.k8s.io/yaml"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
"github.com/jetstack/cert-manager/pkg/util"
"github.com/jetstack/cert-manager/pkg/util/versionchecker"
@@ -64,29 +65,31 @@ func NewOptions(ioStreams genericclioptions.IOStreams) *Options {
}
}
const versionLong = `Print the cert-manager kubectl plugin version and the deployed cert-manager version.
The kubectl plugin version is embedded in the binary and directly displayed. Determining
the the deployed cert-manager version is done by querying the cert-manger resources.
First, the tool looks at the labels of the cert-manager CRD resources. Then, it searches
for the labels of the resources related the the cert-manager webhook linked in the CRDs.
It also tries to derive the version from the docker image tag of that webhook service.
After gathering all this version information, the tool checks if all versions are the same
and returns that version. If no version information is found or the found versions differ,
func versionLong() string {
return build.WithTemplate(`Print the cert-manager CLI version and the deployed cert-manager version.
The CLI version is embedded in the binary and directly displayed. Determining
the the deployed cert-manager version is done by querying the cert-manger
resources. First, the tool looks at the labels of the cert-manager CRD
resources. Then, it searches for the labels of the resources related the the
cert-manager webhook linked in the CRDs. It also tries to derive the version
from the docker image tag of that webhook service. After gathering all this
version information, the tool checks if all versions are the same and returns
that version. If no version information is found or the found versions differ,
an error will be displayed.
The '--client' flag can be used to disable the logic that tries to determine the installed
cert-manager version.
Some example uses:
$ kubectl cert-manager version
$ {{.BuildName}} version
or
$ kubectl cert-manager version --client
$ {{.BuildName}} version --client
or
$ kubectl cert-manager version --short
$ {{.BuildName}} version --short
or
$ kubectl cert-manager version -o yaml
`
$ {{.BuildName}} version -o yaml
`)
}
// NewCmdVersion returns a cobra command for fetching versions
func NewCmdVersion(ctx context.Context, ioStreams genericclioptions.IOStreams) *cobra.Command {
@@ -94,8 +97,8 @@ func NewCmdVersion(ctx context.Context, ioStreams genericclioptions.IOStreams) *
cmd := &cobra.Command{
Use: "version",
Short: "Print the cert-manager kubectl plugin version and the deployed cert-manager version",
Long: versionLong,
Short: "Print the cert-manager CLI version and the deployed cert-manager version",
Long: versionLong(),
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.Validate())
cmdutil.CheckErr(o.Complete())