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

[v2] Add inventory flags for skaffold apply #6406

Merged
merged 1 commit into from
Aug 10, 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
8 changes: 8 additions & 0 deletions cmd/skaffold/app/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion pkg/skaffold/deploy/v2/kpt/kpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions pkg/skaffold/deploy/v2/kpt/kpt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"})
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/runner/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down