diff --git a/cmd/skaffold/app/cmd/apply.go b/cmd/skaffold/app/cmd/apply.go index da9e6a6714d..3aad9aeab28 100644 --- a/cmd/skaffold/app/cmd/apply.go +++ b/cmd/skaffold/app/cmd/apply.go @@ -37,6 +37,14 @@ func NewCmdApply() *cobra.Command { WithExample("Hydrate Kubernetes pod manifest first", "render --output rendered-pod.yaml"). WithExample("Then create resources on your cluster from that hydrated manifest", "apply rendered-pod.yaml"). WithCommonFlags(). + WithFlags([]*Flag{ + {Value: &opts.InventoryNamespace, Name: "inventory-namespace", Hidden: true, DefValue: "", + Usage: " The namespace for the ResourceGroup resource that contains the inventory"}, + {Value: &opts.InventoryID, Name: "inventory-id", Hidden: true, DefValue: "", + Usage: "the inventory name, default to `.kpt-pipeline`"}, + {Value: &opts.InventoryName, Name: "inventory-name", Hidden: true, DefValue: "", + Usage: "Inventory identifier."}, + }). WithHouseKeepingMessages(). WithArgs(func(cmd *cobra.Command, args []string) error { if len(args) < 1 { diff --git a/pkg/skaffold/config/options.go b/pkg/skaffold/config/options.go index 77819217a61..ac273214e16 100644 --- a/pkg/skaffold/config/options.go +++ b/pkg/skaffold/config/options.go @@ -68,6 +68,9 @@ type SkaffoldOptions struct { ConfigurationFilter []string HydratedManifests []string HydrationDir string + InventoryNamespace string + InventoryID string + InventoryName string GlobalConfig string EventLogFile string RenderOutput string diff --git a/pkg/skaffold/deploy/v2/kpt/kpt.go b/pkg/skaffold/deploy/v2/kpt/kpt.go index b2be8252f24..bb4223686a3 100644 --- a/pkg/skaffold/deploy/v2/kpt/kpt.go +++ b/pkg/skaffold/deploy/v2/kpt/kpt.go @@ -31,6 +31,7 @@ import ( "sigs.k8s.io/kustomize/kyaml/yaml" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/access" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/debug" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/kubectl" @@ -87,8 +88,18 @@ type Config interface { } // NewDeployer generates a new Deployer object contains the kptDeploy schema. -func NewDeployer(cfg Config, labels map[string]string, provider deploy.ComponentProvider, d *latestV2.KptV2Deploy) *Deployer { +func NewDeployer(cfg Config, labels map[string]string, provider deploy.ComponentProvider, d *latestV2.KptV2Deploy, + opts config.SkaffoldOptions) *Deployer { podSelector := kubernetes.NewImageList() + if opts.InventoryNamespace != "" { + d.InventoryNamespace = opts.InventoryNamespace + } + if opts.InventoryID != "" { + d.InventoryID = opts.InventoryID + } + if opts.InventoryName != "" { + d.Name = opts.InventoryName + } return &Deployer{ KptV2Deploy: d, applyDir: d.Dir, diff --git a/pkg/skaffold/deploy/v2/kpt/kpt_test.go b/pkg/skaffold/deploy/v2/kpt/kpt_test.go index 4c362798770..fa5a3c83b2f 100644 --- a/pkg/skaffold/deploy/v2/kpt/kpt_test.go +++ b/pkg/skaffold/deploy/v2/kpt/kpt_test.go @@ -25,6 +25,7 @@ import ( "path/filepath" "testing" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" v2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext/v2" @@ -141,7 +142,8 @@ func TestKptfileInitIfNot(t *testing.T) { } tmpDir.Chdir() - k := NewDeployer(&kptConfig{}, nil, deploy.NoopComponentProvider, &latestV2.KptV2Deploy{Dir: "."}) + k := NewDeployer(&kptConfig{}, nil, deploy.NoopComponentProvider, &latestV2.KptV2Deploy{Dir: "."}, + config.SkaffoldOptions{}) err := kptfileInitIfNot(context.Background(), ioutil.Discard, k) if !test.shouldErr { t.CheckNoError(err) @@ -179,7 +181,7 @@ func TestDeploy(t *testing.T) { t.Override(&util.DefaultExecCommand, test.commands) kptInitFunc = func(context.Context, io.Writer, *Deployer) error { return nil } - k := NewDeployer(&kptConfig{}, nil, deploy.NoopComponentProvider, &test.kpt) + k := NewDeployer(&kptConfig{}, nil, deploy.NoopComponentProvider, &test.kpt, config.SkaffoldOptions{}) ns, err := k.Deploy(context.Background(), ioutil.Discard, test.builds) t.CheckNoError(err) t.CheckDeepEqual(ns, []string{"test-kptv2"}) diff --git a/pkg/skaffold/runner/deployer.go b/pkg/skaffold/runner/deployer.go index 8fd9df1b470..0d193307a19 100644 --- a/pkg/skaffold/runner/deployer.go +++ b/pkg/skaffold/runner/deployer.go @@ -90,7 +90,7 @@ func GetDeployer(runCtx *v2.RunContext, provider deploy.ComponentProvider, label logrus.Infof("manifests are deployed from render path %v\n", hydrationDir) p.Deploy.KptV2Deploy.Dir = hydrationDir } - deployer := kptV2.NewDeployer(dCtx, labels, provider, p.Deploy.KptV2Deploy) + deployer := kptV2.NewDeployer(dCtx, labels, provider, p.Deploy.KptV2Deploy, runCtx.Opts) deployers = append(deployers, deployer) } }