Improve kubectl plugin
This commit is contained in:
parent
ef0b1633e2
commit
9d62ec97de
14 changed files with 1117 additions and 464 deletions
|
|
@ -18,11 +18,17 @@ package util
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
)
|
||||
|
||||
// The default deployment and service names for ingress-nginx
|
||||
const (
|
||||
DefaultIngressDeploymentName = "nginx-ingress-controller"
|
||||
DefaultIngressServiceName = "ingress-nginx"
|
||||
)
|
||||
|
||||
// PrintError receives an error value and prints it if it exists
|
||||
func PrintError(e error) {
|
||||
if e != nil {
|
||||
|
|
@ -45,6 +51,20 @@ func printOrError(s string, e error) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// AddPodFlag adds a --pod flag to a cobra command
|
||||
func AddPodFlag(cmd *cobra.Command) *string {
|
||||
v := ""
|
||||
cmd.Flags().StringVar(&v, "pod", "", "Query a particular ingress-nginx pod")
|
||||
return &v
|
||||
}
|
||||
|
||||
// AddDeploymentFlag adds a --deployment flag to a cobra command
|
||||
func AddDeploymentFlag(cmd *cobra.Command) *string {
|
||||
v := ""
|
||||
cmd.Flags().StringVar(&v, "deployment", DefaultIngressDeploymentName, "The name of the ingress-nginx deployment")
|
||||
return &v
|
||||
}
|
||||
|
||||
// GetNamespace takes a set of kubectl flag values and returns the namespace we should be operating in
|
||||
func GetNamespace(flags *genericclioptions.ConfigFlags) string {
|
||||
namespace, _, err := flags.ToRawKubeConfigLoader().Namespace()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue