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

Move cluster-related flags to live subcommand #1891

Merged
merged 2 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"strings"

"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/cmd/util"
)

// NormalizeCommand will modify commands to be consistent, e.g. silencing errors
Expand All @@ -31,11 +30,11 @@ func NormalizeCommand(c ...*cobra.Command) {
}

// GetKptCommands returns the set of kpt commands to be registered
func GetKptCommands(ctx context.Context, name string, f util.Factory) []*cobra.Command {
func GetKptCommands(ctx context.Context, name, version string) []*cobra.Command {
var c []*cobra.Command
fnCmd := GetFnCommand(ctx, name)
pkgCmd := GetPkgCommand(ctx, name)
liveCmd := GetLiveCommand(name, f)
liveCmd := GetLiveCommand(name, version)

c = append(c, pkgCmd, fnCmd, liveCmd)

Expand Down
33 changes: 27 additions & 6 deletions commands/livecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package commands

import (
"flag"
"fmt"
"os"

"github.com/GoogleContainerTools/kpt/internal/cmdfetchk8sschema"
"github.com/GoogleContainerTools/kpt/internal/cmdliveinit"
"github.com/GoogleContainerTools/kpt/internal/docs/generated/livedocs"
"github.com/GoogleContainerTools/kpt/internal/util/cfgflags"
"github.com/GoogleContainerTools/kpt/pkg/live"
"github.com/GoogleContainerTools/kpt/thirdparty/cli-utils/destroy"
"github.com/GoogleContainerTools/kpt/thirdparty/cli-utils/diff"
Expand All @@ -28,12 +30,13 @@ import (
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/klog"
"k8s.io/kubectl/pkg/cmd/util"
cluster "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/provider"
"sigs.k8s.io/cli-utils/pkg/util/factory"
)

func GetLiveCommand(name string, f util.Factory) *cobra.Command {
func GetLiveCommand(_, version string) *cobra.Command {
liveCmd := &cobra.Command{
Use: "live",
Short: livedocs.LiveShort,
Expand All @@ -56,6 +59,8 @@ func GetLiveCommand(name string, f util.Factory) *cobra.Command {
ErrOut: os.Stderr,
}

f := newFactory(liveCmd, version)

// The provider handles both ConfigMap and ResourceGroup inventory objects.
// If a package has both inventory objects, then an error is thrown.
klog.V(2).Infoln("provider supports ResourceGroup and ConfigMap inventory")
Expand Down Expand Up @@ -95,10 +100,8 @@ func GetLiveCommand(name string, f util.Factory) *cobra.Command {
statusCmd.Long = livedocs.StatusLong
statusCmd.Example = livedocs.StatusExamples

fetchOpenAPICmd := cmdfetchk8sschema.NewCommand(name, f, ioStreams)

liveCmd.AddCommand(initCmd, applyCmd, previewCmd, diffCmd, destroyCmd,
fetchOpenAPICmd, statusCmd)
statusCmd)

// Add the migrate command to change from ConfigMap to ResourceGroup inventory
// object. Also add the install-resource-group command.
Expand All @@ -113,3 +116,21 @@ func GetLiveCommand(name string, f util.Factory) *cobra.Command {

return liveCmd
}

func newFactory(cmd *cobra.Command, version string) cluster.Factory {
flags := cmd.PersistentFlags()
kubeConfigFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag()
kubeConfigFlags.AddFlags(flags)
userAgentKubeConfigFlags := &cfgflags.UserAgentKubeConfigFlags{
Delegate: kubeConfigFlags,
UserAgent: fmt.Sprintf("kpt/%s", version),
}
matchVersionKubeConfigFlags := cluster.NewMatchVersionFlags(
&factory.CachingRESTClientGetter{
Delegate: userAgentKubeConfigFlags,
},
)
matchVersionKubeConfigFlags.AddFlags(cmd.PersistentFlags())
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
return cluster.NewFactory(matchVersionKubeConfigFlags)
}
92 changes: 0 additions & 92 deletions internal/cmdfetchk8sschema/cmdfetchk8sschema.go

This file was deleted.

8 changes: 0 additions & 8 deletions internal/util/cmdutil/cmdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ func PrintErrorStacktrace() bool {
// StackOnError if true, will print a stack trace on failure.
var StackOnError bool

// K8sSchemaSource defines where we should look for the kubernetes openAPI
// schema
var K8sSchemaSource string

// K8sSchemaPath defines the path to the openAPI schema if we are reading from
// a file
var K8sSchemaPath string

func ResolveAbsAndRelPaths(path string) (string, string, error) {
cwd, err := os.Getwd()
if err != nil {
Expand Down
90 changes: 0 additions & 90 deletions internal/util/openapi/openapi.go

This file was deleted.

Loading