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

Alias replace -> apply and add deprecation notice to replace #2618

Closed
wants to merge 1 commit into from
Closed
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
63 changes: 63 additions & 0 deletions cmd/kops/apply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2016 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"io"

"github.com/spf13/cobra"
"k8s.io/kops/cmd/kops/util"

"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/util/i18n"
)

var (
apply_long = templates.LongDesc(i18n.T(`
Apply a cluster resource specification by filename or stdin.`))

apply_example = templates.Examples(i18n.T(`
# Apply a cluster resource specification using a file.
kops apply -f my-cluster.yaml
`))

apply_short = i18n.T(`Apply a cluster resource specification.`)
)

func NewCmdApply(f *util.Factory, out io.Writer) *cobra.Command {
options := &ReplaceOptions{}

cmd := &cobra.Command{
Use: "apply -f FILENAME",
Short: apply_short,
Long: apply_long,
Example: apply_example,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add an alias here for replace and then remove the replace code. There is no need to have duplicate code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented your suggestion, does my current PR look better to you?

Run: func(cmd *cobra.Command, args []string) {
if cmdutil.IsFilenameEmpty(options.Filenames) {
cmd.Help()
return
}

cmdutil.CheckErr(RunReplace(f, cmd, out, options))
},
}

ConfigureReplaceCmd(cmd, options)

return cmd
}
16 changes: 12 additions & 4 deletions cmd/kops/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ import (

var (
replace_long = templates.LongDesc(i18n.T(`
Replace a resource specification by filename or stdin.`))
DEPRECATED - Replace a resource specification by filename or stdin.`))

replace_example = templates.Examples(i18n.T(`
# THIS COMMAND HAS BEEN DEPRECATED.
# Please use kops apply instead.

# Replace a cluster specification using a file
kops replace -f my-cluster.yaml
`))
Expand All @@ -54,7 +57,7 @@ func NewCmdReplace(f *util.Factory, out io.Writer) *cobra.Command {
options := &ReplaceOptions{}

cmd := &cobra.Command{
Use: "replace -f FILENAME",
Use: "replace -f FILENAME (DEPRECATED in favor of apply)",
Short: replace_short,
Long: replace_long,
Example: replace_example,
Expand All @@ -68,12 +71,17 @@ func NewCmdReplace(f *util.Factory, out io.Writer) *cobra.Command {
},
}

cmd.Flags().StringSliceVarP(&options.Filenames, "filename", "f", options.Filenames, "A list of one or more files separated by a comma.")
cmd.MarkFlagRequired("filename")
ConfigureReplaceCmd(cmd, options)

return cmd
}

func ConfigureReplaceCmd(cmd *cobra.Command, options *ReplaceOptions) {
// Shared with the apply command
cmd.Flags().StringSliceVarP(&options.Filenames, "filename", "f", options.Filenames, "A list of one or more files separated by a comma.")
cmd.MarkFlagRequired("filename")
}

func RunReplace(f *util.Factory, cmd *cobra.Command, out io.Writer, c *ReplaceOptions) error {
clientset, err := f.Clientset()
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions docs/cli/kops_replace.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ Replace cluster resources.
### Synopsis


Replace a resource specification by filename or stdin.
DEPRECATED - Replace a resource specification by filename or stdin.

```
kops replace -f FILENAME
kops replace -f FILENAME (DEPRECATED in favor of apply)
```

### Examples

```
# THIS COMMAND HAS BEEN DEPRECATED.
# Please use kops apply instead.

# Replace a cluster specification using a file
kops replace -f my-cluster.yaml
```
Expand Down