Skip to content

Commit

Permalink
Merge pull request #593 from vmware-tanzu/cli-integration
Browse files Browse the repository at this point in the history
Make minor changes to kctrl for integration with tanzu-framework
  • Loading branch information
cppforlife authored Apr 11, 2022
2 parents 3bcf463 + 76cc59c commit c57b457
Show file tree
Hide file tree
Showing 99 changed files with 17,734 additions and 84 deletions.
12 changes: 10 additions & 2 deletions cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/vmware-tanzu/carvel-kapp-controller/cli
go 1.17

require (
github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72
github.com/cppforlife/cobrautil v0.0.0-20220411122935-c28a9f274a4e
github.com/cppforlife/go-cli-ui v0.0.0-20200716203538-1e47f820817f
github.com/getkin/kin-openapi v0.81.0
github.com/google/go-containerregistry v0.1.2
Expand All @@ -18,6 +18,11 @@ require (
k8s.io/client-go v0.22.1 // kubernetes-1.22.1
)

require (
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/apiextensions-apiserver v0.19.2
)

require (
cloud.google.com/go v0.65.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
Expand All @@ -26,12 +31,16 @@ require (
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.3 // indirect
github.com/go-openapi/spec v0.19.3 // indirect
github.com/go-openapi/swag v0.19.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
Expand Down Expand Up @@ -60,7 +69,6 @@ require (
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/klog/v2 v2.9.0 // indirect
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
Expand Down
8 changes: 7 additions & 1 deletion cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
github.com/OpenPeeDeeP/depguard v1.0.1/go.mod h1:xsIw86fROiiwelg+jB2uM9PiKihMMmUx/1V+TNhjQvM=
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
Expand Down Expand Up @@ -178,8 +180,9 @@ github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a/go.mod h1:F5haX7
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72 h1:rPWcUBgMb1ox2eCohCuZ8gsZVe0aB5qBbYaBpdoxfCE=
github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72/go.mod h1:2w+qxVu2KSGW78Ex/XaIqfh/OvBgjEsmN53S4T8vEyA=
github.com/cppforlife/cobrautil v0.0.0-20220411122935-c28a9f274a4e h1:4AxO89dwbgA957M8DX5AV/KsOmxDyAB1BES0INY+A/0=
github.com/cppforlife/cobrautil v0.0.0-20220411122935-c28a9f274a4e/go.mod h1:2w+qxVu2KSGW78Ex/XaIqfh/OvBgjEsmN53S4T8vEyA=
github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835 h1:mYQweUIBD+TBRjIeQnJmXr0GSVMpI6O0takyb/aaOgo=
github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835/go.mod h1:dYeVsKp1vvK8XjdTPR1gF+uk+9doxKeO3hqQTOCr7T4=
github.com/cppforlife/go-cli-ui v0.0.0-20200716203538-1e47f820817f h1:yVW0v4zDXzJo1i8G9G3vtvNpyzhvtLalO34BsN/K88E=
Expand Down Expand Up @@ -276,6 +279,7 @@ github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1
github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
github.com/go-openapi/jsonreference v0.18.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
github.com/go-openapi/jsonreference v0.19.3 h1:5cxNfTy0UVC3X8JL5ymxzyoUZmo8iZb+jeTWn7tUa8o=
github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8=
github.com/go-openapi/loads v0.17.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU=
github.com/go-openapi/loads v0.18.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU=
Expand All @@ -289,6 +293,7 @@ github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nA
github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
github.com/go-openapi/spec v0.18.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY=
github.com/go-openapi/spec v0.19.3 h1:0XRyw8kguri6Yw4SxhsQA/atC88yqrk0+G4YhI2wabc=
github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
github.com/go-openapi/strfmt v0.18.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
Expand Down Expand Up @@ -1271,6 +1276,7 @@ k8s.io/api v0.19.15/go.mod h1:rMRWjnIJQmurd/FdLobht6dCSbJQ+UDpyOwPaoFS7lI=
k8s.io/api v0.22.1 h1:ISu3tD/jRhYfSW8jI/Q1e+lRxkR7w9UwQEZ7FgslrwY=
k8s.io/api v0.22.1/go.mod h1:bh13rkTp3F1XEaLGykbyRD2QaTTzPm0e/BMd8ptFONY=
k8s.io/apiextensions-apiserver v0.18.2/go.mod h1:q3faSnRGmYimiocj6cHQ1I3WpLqmDgJFlKL37fC4ZvY=
k8s.io/apiextensions-apiserver v0.19.2 h1:oG84UwiDsVDu7dlsGQs5GySmQHCzMhknfhFExJMz9tA=
k8s.io/apiextensions-apiserver v0.19.2/go.mod h1:EYNjpqIAvNZe+svXVx9j4uBaVhTB4C94HkY3w058qcg=
k8s.io/apimachinery v0.17.2/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
k8s.io/apimachinery v0.17.4/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g=
Expand Down
4 changes: 2 additions & 2 deletions cli/pkg/kctrl/cmd/core/flags_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ func NewFlagsFactory(configFactory ConfigFactory, depsFactory DepsFactory) Flags
return FlagsFactory{configFactory, depsFactory}
}

func (f FlagsFactory) NewNamespaceNameFlag(str *string) *NamespaceNameFlag {
return NewNamespaceNameFlag(str, f.configFactory)
func (f FlagsFactory) NewNamespaceNameFlag(str *string, envVariableKey string) *NamespaceNameFlag {
return NewNamespaceNameFlag(str, f.configFactory, envVariableKey)
}
46 changes: 27 additions & 19 deletions cli/pkg/kctrl/cmd/core/kubeconfig_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
package core

import (
"fmt"
"os"
"strings"

"github.com/cppforlife/cobrautil"
"github.com/spf13/cobra"
Expand All @@ -17,26 +19,30 @@ type KubeconfigFlags struct {
YAML *KubeconfigYAMLFlag
}

func (f *KubeconfigFlags) Set(cmd *cobra.Command, flagsFactory FlagsFactory) {
f.Path = NewKubeconfigPathFlag()
cmd.PersistentFlags().Var(f.Path, "kubeconfig", "Path to the kubeconfig file ($KCTRL_KUBECONFIG)")
func (f *KubeconfigFlags) Set(cmd *cobra.Command, flagsFactory FlagsFactory, opts PackageCommandTreeOpts) {
kubeconfigEnvVariableKey := fmt.Sprintf("%s_KUBECONFIG", strings.ToUpper(opts.BinaryName))
f.Path = NewKubeconfigPathFlag(kubeconfigEnvVariableKey)
cmd.PersistentFlags().Var(f.Path, "kubeconfig", fmt.Sprintf("Path to the kubeconfig file ($%s)", kubeconfigEnvVariableKey))

f.Context = NewKubeconfigContextFlag()
cmd.PersistentFlags().Var(f.Context, "kubeconfig-context", "Kubeconfig context override ($KCTRL_KUBECONFIG_CONTEXT)")
kubeconfigContextEnvVariableKey := fmt.Sprintf("%s_KUBECONFIG_CONTEXT", strings.ToUpper(opts.BinaryName))
f.Context = NewKubeconfigContextFlag(kubeconfigContextEnvVariableKey)
cmd.PersistentFlags().Var(f.Context, "kubeconfig-context", fmt.Sprintf("Kubeconfig context override ($%s)", kubeconfigContextEnvVariableKey))

f.YAML = NewKubeconfigYAMLFlag()
cmd.PersistentFlags().Var(f.YAML, "kubeconfig-yaml", "Kubeconfig contents as YAML ($KCTRL_KUBECONFIG_YAML)")
kubeconfigYamlEnvVariableKey := fmt.Sprintf("%s_KUBECONFIG_YAML", strings.ToUpper(opts.BinaryName))
f.YAML = NewKubeconfigYAMLFlag(kubeconfigYamlEnvVariableKey)
cmd.PersistentFlags().Var(f.YAML, "kubeconfig-yaml", fmt.Sprintf("Kubeconfig contents as YAML ($%s)", kubeconfigYamlEnvVariableKey))
}

type KubeconfigPathFlag struct {
value string
value string
envVariableKey string
}

var _ pflag.Value = &KubeconfigPathFlag{}
var _ cobrautil.ResolvableFlag = &KubeconfigPathFlag{}

func NewKubeconfigPathFlag() *KubeconfigPathFlag {
return &KubeconfigPathFlag{}
func NewKubeconfigPathFlag(envVariableKey string) *KubeconfigPathFlag {
return &KubeconfigPathFlag{envVariableKey: envVariableKey}
}

func (s *KubeconfigPathFlag) Set(val string) error {
Expand Down Expand Up @@ -67,7 +73,7 @@ func (s *KubeconfigPathFlag) Resolve() error {
}

func (s *KubeconfigPathFlag) resolveValue() string {
path := os.Getenv("KCTRL_KUBECONFIG")
path := os.Getenv(s.envVariableKey)
if len(path) > 0 {
return path
}
Expand All @@ -76,14 +82,15 @@ func (s *KubeconfigPathFlag) resolveValue() string {
}

type KubeconfigContextFlag struct {
value string
value string
envVariableKey string
}

var _ pflag.Value = &KubeconfigContextFlag{}
var _ cobrautil.ResolvableFlag = &KubeconfigPathFlag{}

func NewKubeconfigContextFlag() *KubeconfigContextFlag {
return &KubeconfigContextFlag{}
func NewKubeconfigContextFlag(envVariableKey string) *KubeconfigContextFlag {
return &KubeconfigContextFlag{envVariableKey: envVariableKey}
}

func (s *KubeconfigContextFlag) Set(val string) error {
Expand All @@ -108,20 +115,21 @@ func (s *KubeconfigContextFlag) Resolve() error {
return nil
}

s.value = os.Getenv("KCTRL_KUBECONFIG_CONTEXT")
s.value = os.Getenv(s.envVariableKey)

return nil
}

type KubeconfigYAMLFlag struct {
value string
value string
envVariableKey string
}

var _ pflag.Value = &KubeconfigYAMLFlag{}
var _ cobrautil.ResolvableFlag = &KubeconfigPathFlag{}

func NewKubeconfigYAMLFlag() *KubeconfigYAMLFlag {
return &KubeconfigYAMLFlag{}
func NewKubeconfigYAMLFlag(envVariableKey string) *KubeconfigYAMLFlag {
return &KubeconfigYAMLFlag{envVariableKey: envVariableKey}
}

func (s *KubeconfigYAMLFlag) Set(val string) error {
Expand All @@ -146,7 +154,7 @@ func (s *KubeconfigYAMLFlag) Resolve() error {
return nil
}

s.value = os.Getenv("KCTRL_KUBECONFIG_YAML")
s.value = os.Getenv(s.envVariableKey)

return nil
}
20 changes: 12 additions & 8 deletions cli/pkg/kctrl/cmd/core/namespace_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package core
import (
"fmt"
"os"
"strings"

"github.com/cppforlife/cobrautil"
"github.com/spf13/cobra"
Expand All @@ -16,21 +17,24 @@ type NamespaceFlags struct {
Name string
}

func (s *NamespaceFlags) Set(cmd *cobra.Command, flagsFactory FlagsFactory) {
name := flagsFactory.NewNamespaceNameFlag(&s.Name)
cmd.Flags().VarP(name, "namespace", "n", "Specified namespace ($KCTRL_NAMESPACE or default from kubeconfig)")
func (s *NamespaceFlags) Set(cmd *cobra.Command, flagsFactory FlagsFactory, opts PackageCommandTreeOpts) {
namespaceEnvVariableKey := fmt.Sprintf("%s_NAMESPACE", strings.ToUpper(opts.BinaryName))
name := flagsFactory.NewNamespaceNameFlag(&s.Name, namespaceEnvVariableKey)

cmd.Flags().VarP(name, "namespace", "n", fmt.Sprintf("Specified namespace ($%s or default from kubeconfig)", namespaceEnvVariableKey))
}

type NamespaceNameFlag struct {
value *string
configFactory ConfigFactory
value *string
configFactory ConfigFactory
envVariableKey string
}

var _ pflag.Value = &NamespaceNameFlag{}
var _ cobrautil.ResolvableFlag = &NamespaceNameFlag{}

func NewNamespaceNameFlag(value *string, configFactory ConfigFactory) *NamespaceNameFlag {
return &NamespaceNameFlag{value, configFactory}
func NewNamespaceNameFlag(value *string, configFactory ConfigFactory, envVariableKey string) *NamespaceNameFlag {
return &NamespaceNameFlag{value, configFactory, envVariableKey}
}

func (s *NamespaceNameFlag) Set(val string) error {
Expand All @@ -57,7 +61,7 @@ func (s *NamespaceNameFlag) resolveValue() (string, error) {
return *s.value, nil
}

envVal := os.Getenv("KCTRL_NAMESPACE")
envVal := os.Getenv(s.envVariableKey)
if len(envVal) > 0 {
return envVal, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cli/pkg/kctrl/cmd/kctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func SetGlobalFlags(o *KctrlOptions, cmd *cobra.Command, flagsFactory cmdcore.Fl
o.UIFlags.Set(cmd, flagsFactory, opts)
o.LoggerFlags.Set(cmd, flagsFactory)
o.KubeAPIFlags.Set(cmd, flagsFactory)
o.KubeconfigFlags.Set(cmd, flagsFactory)
o.KubeconfigFlags.Set(cmd, flagsFactory, opts)
}

func ConfigurePathResolvers(o *KctrlOptions, cmd *cobra.Command, flagsFactory cmdcore.FlagsFactory) {
Expand Down
2 changes: 1 addition & 1 deletion cli/pkg/kctrl/cmd/package/available/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "available",
Aliases: []string{"a"},
Short: "Available packages",
Short: "Manage available packages",
}
return cmd
}
Loading

0 comments on commit c57b457

Please sign in to comment.