Skip to content

Commit

Permalink
deprecate some fn commands
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Sep 10, 2021
1 parent 3ebdb3f commit 6157600
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
8 changes: 8 additions & 0 deletions cmd/config/internal/commands/cmdwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package commands

import (
"bytes"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -47,6 +48,7 @@ Environment Variables:
`,
RunE: r.runE,
PreRunE: r.preRunE,
SilenceUsage: true,
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
Args: cobra.MinimumNArgs(1),
Expand Down Expand Up @@ -78,6 +80,12 @@ func WrapCommand() *cobra.Command {
return GetWrapRunner().Command
}

func (r *WrapRunner) preRunE(_ *cobra.Command, _ []string) error {
_, err := fmt.Fprintln(os.Stderr, `Command "wrap" is deprecated, this will no longer be available in kustomize v5.
See discussion in https://github.com/kubernetes-sigs/kustomize/issues/3953.`)
return err
}

func (r *WrapRunner) runE(c *cobra.Command, args []string) error {
if r.getEnv == nil {
r.getEnv = os.Getenv
Expand Down
7 changes: 7 additions & 0 deletions cmd/config/internal/commands/cmdxargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ $ kyaml cat pkg/ --function-config config.yaml --wrap-kind ResourceList | kyaml
`,
RunE: r.runE,
PreRunE: r.preRunE,
SilenceUsage: true,
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
Args: cobra.MinimumNArgs(1),
Expand All @@ -84,6 +85,12 @@ func XArgsCommand() *cobra.Command {
return GetXArgsRunner().Command
}

func (r *XArgsRunner) preRunE(_ *cobra.Command, _ []string) error {
_, err := fmt.Fprintln(os.Stderr, `Command "xargs" is deprecated, this will no longer be available in kustomize v5.
See discussion in https://github.com/kubernetes-sigs/kustomize/issues/3953.`)
return err
}

func (r *XArgsRunner) runE(c *cobra.Command, _ []string) error {
if len(r.Args) == 0 {
r.Args = os.Args
Expand Down
2 changes: 2 additions & 0 deletions cmd/config/internal/commands/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func GetSinkRunner(name string) *SinkRunner {
Example: commands.SinkExamples,
RunE: r.runE,
Args: cobra.MaximumNArgs(1),
Deprecated: "this will no longer be available in kustomize v5.\n" +
"See discussion in https://github.com/kubernetes-sigs/kustomize/issues/3953.",
}
runner.FixDocs(name, c)
r.Command = c
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/internal/commands/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ metadata:
spec:
replicas: 3
`
if !assert.Equal(t, expected, out.String()) {
if !assert.Contains(t, out.String(), expected) {
t.FailNow()
}
}
Expand Down Expand Up @@ -335,7 +335,7 @@ items:
}
}
`
if !assert.Equal(t, expected, out.String()) {
if !assert.Contains(t, out.String(), expected) {
println(out.String())
t.FailNow()
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/config/internal/commands/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func GetSourceRunner(name string) *SourceRunner {
Long: commands.SourceLong,
Example: commands.SourceExamples,
RunE: r.runE,
Deprecated: "this will no longer be available in kustomize v5.\n" +
"See discussion in https://github.com/kubernetes-sigs/kustomize/issues/3953.",
}
runner.FixDocs(name, c)
c.Flags().StringVar(&r.WrapKind, "wrap-kind", kio.ResourceListKind,
Expand Down
16 changes: 8 additions & 8 deletions cmd/config/internal/commands/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ spec:
return
}

if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1
if !assert.Contains(t, b.String(), `apiVersion: config.kubernetes.io/v1alpha1
kind: ResourceList
items:
- kind: Deployment
Expand Down Expand Up @@ -130,7 +130,7 @@ items:
config.kubernetes.io/path: 'f2.yaml'
spec:
replicas: 3
`, b.String()) {
`) {
return
}
}
Expand Down Expand Up @@ -191,12 +191,12 @@ func TestSourceCommandJSON(t *testing.T) {
return
}

if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1
if !assert.Contains(t, b.String(), `apiVersion: config.kubernetes.io/v1alpha1
kind: ResourceList
items:
- {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", "annotations": {"app": "nginx2", config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f1.json'}}, "spec": {"replicas": 1}}
- {"apiVersion": "v1", "kind": "Abstraction", "metadata": {"name": "foo", "annotations": {"config.kubernetes.io/function": "container:\n image: gcr.io/example/reconciler:v1\n", "config.kubernetes.io/local-config": "true", config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f2.json'}}, "spec": {"replicas": 3}}
`, b.String()) {
`) {
return
}
}
Expand Down Expand Up @@ -238,7 +238,7 @@ spec:
return
}

if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1
if !assert.Contains(t, out.String(), `apiVersion: config.kubernetes.io/v1alpha1
kind: ResourceList
items:
- kind: Deployment
Expand All @@ -260,7 +260,7 @@ items:
spec:
selector:
app: nginx
`, out.String()) {
`) {
return
}
}
Expand Down Expand Up @@ -299,11 +299,11 @@ func TestSourceCommandJSON_Stdin(t *testing.T) {
return
}

if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1
if !assert.Contains(t, out.String(), `apiVersion: config.kubernetes.io/v1alpha1
kind: ResourceList
items:
- {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", "annotations": {"app": "nginx2", config.kubernetes.io/index: '0'}}, "spec": {"replicas": 1}}
`, out.String()) {
`) {
return
}
}

0 comments on commit 6157600

Please sign in to comment.