mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
fix: fix bugs
This commit is contained in:
11
vendor/github.com/lithammer/dedent/.travis.yml
generated
vendored
Normal file
11
vendor/github.com/lithammer/dedent/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- "1.6"
|
||||
- "1.7"
|
||||
- "1.8"
|
||||
- "1.9"
|
||||
- "1.10"
|
||||
- "1.11"
|
||||
|
||||
sudo: false
|
||||
21
vendor/github.com/lithammer/dedent/LICENSE
generated
vendored
Normal file
21
vendor/github.com/lithammer/dedent/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 Peter Lithammer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
52
vendor/github.com/lithammer/dedent/README.md
generated
vendored
Normal file
52
vendor/github.com/lithammer/dedent/README.md
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
# Dedent
|
||||
|
||||
[](https://travis-ci.org/lithammer/dedent)
|
||||
[](https://godoc.org/github.com/lithammer/dedent)
|
||||
|
||||
Removes common leading whitespace from multiline strings. Inspired by [`textwrap.dedent`](https://docs.python.org/3/library/textwrap.html#textwrap.dedent) in Python.
|
||||
|
||||
## Usage / example
|
||||
|
||||
Imagine the following snippet that prints a multiline string. You want the indentation to both look nice in the code as well as in the actual output.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lithammer/dedent"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := `
|
||||
Lorem ipsum dolor sit amet,
|
||||
consectetur adipiscing elit.
|
||||
Curabitur justo tellus, facilisis nec efficitur dictum,
|
||||
fermentum vitae ligula. Sed eu convallis sapien.`
|
||||
fmt.Println(Dedent(s))
|
||||
fmt.Println("-------------")
|
||||
fmt.Println(s)
|
||||
}
|
||||
```
|
||||
|
||||
To illustrate the difference, here's the output:
|
||||
|
||||
|
||||
```bash
|
||||
$ go run main.go
|
||||
Lorem ipsum dolor sit amet,
|
||||
consectetur adipiscing elit.
|
||||
Curabitur justo tellus, facilisis nec efficitur dictum,
|
||||
fermentum vitae ligula. Sed eu convallis sapien.
|
||||
-------------
|
||||
|
||||
Lorem ipsum dolor sit amet,
|
||||
consectetur adipiscing elit.
|
||||
Curabitur justo tellus, facilisis nec efficitur dictum,
|
||||
fermentum vitae ligula. Sed eu convallis sapien.
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
49
vendor/github.com/lithammer/dedent/dedent.go
generated
vendored
Normal file
49
vendor/github.com/lithammer/dedent/dedent.go
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
package dedent
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
whitespaceOnly = regexp.MustCompile("(?m)^[ \t]+$")
|
||||
leadingWhitespace = regexp.MustCompile("(?m)(^[ \t]*)(?:[^ \t\n])")
|
||||
)
|
||||
|
||||
// Dedent removes any common leading whitespace from every line in text.
|
||||
//
|
||||
// This can be used to make multiline strings to line up with the left edge of
|
||||
// the display, while still presenting them in the source code in indented
|
||||
// form.
|
||||
func Dedent(text string) string {
|
||||
var margin string
|
||||
|
||||
text = whitespaceOnly.ReplaceAllString(text, "")
|
||||
indents := leadingWhitespace.FindAllStringSubmatch(text, -1)
|
||||
|
||||
// Look for the longest leading string of spaces and tabs common to all
|
||||
// lines.
|
||||
for i, indent := range indents {
|
||||
if i == 0 {
|
||||
margin = indent[1]
|
||||
} else if strings.HasPrefix(indent[1], margin) {
|
||||
// Current line more deeply indented than previous winner:
|
||||
// no change (previous winner is still on top).
|
||||
continue
|
||||
} else if strings.HasPrefix(margin, indent[1]) {
|
||||
// Current line consistent with and no deeper than previous winner:
|
||||
// it's the new winner.
|
||||
margin = indent[1]
|
||||
} else {
|
||||
// Current line and previous winner have no common whitespace:
|
||||
// there is no margin.
|
||||
margin = ""
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if margin != "" {
|
||||
text = regexp.MustCompile("(?m)^"+margin).ReplaceAllString(text, "")
|
||||
}
|
||||
return text
|
||||
}
|
||||
75
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout.go
generated
vendored
Normal file
75
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout.go
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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 rollout
|
||||
|
||||
import (
|
||||
"github.com/lithammer/dedent"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/cli-runtime/pkg/genericiooptions"
|
||||
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
)
|
||||
|
||||
var (
|
||||
rolloutLong = templates.LongDesc(i18n.T(`
|
||||
Manage the rollout of one or many resources.`) + rolloutValidResources)
|
||||
|
||||
rolloutExample = templates.Examples(`
|
||||
# Rollback to the previous deployment
|
||||
kubectl rollout undo deployment/abc
|
||||
|
||||
# Check the rollout status of a daemonset
|
||||
kubectl rollout status daemonset/foo
|
||||
|
||||
# Restart a deployment
|
||||
kubectl rollout restart deployment/abc
|
||||
|
||||
# Restart deployments with the 'app=nginx' label
|
||||
kubectl rollout restart deployment --selector=app=nginx`)
|
||||
|
||||
rolloutValidResources = dedent.Dedent(`
|
||||
Valid resource types include:
|
||||
|
||||
* deployments
|
||||
* daemonsets
|
||||
* statefulsets
|
||||
`)
|
||||
)
|
||||
|
||||
// NewCmdRollout returns a Command instance for 'rollout' sub command
|
||||
func NewCmdRollout(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "rollout SUBCOMMAND",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: i18n.T("Manage the rollout of a resource"),
|
||||
Long: rolloutLong,
|
||||
Example: rolloutExample,
|
||||
Run: cmdutil.DefaultSubCommandRun(streams.Out),
|
||||
}
|
||||
// subcommands
|
||||
cmd.AddCommand(NewCmdRolloutHistory(f, streams))
|
||||
cmd.AddCommand(NewCmdRolloutPause(f, streams))
|
||||
cmd.AddCommand(NewCmdRolloutResume(f, streams))
|
||||
cmd.AddCommand(NewCmdRolloutUndo(f, streams))
|
||||
cmd.AddCommand(NewCmdRolloutStatus(f, streams))
|
||||
cmd.AddCommand(NewCmdRolloutRestart(f, streams))
|
||||
|
||||
return cmd
|
||||
}
|
||||
223
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_history.go
generated
vendored
Normal file
223
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_history.go
generated
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
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 rollout
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"k8s.io/cli-runtime/pkg/genericiooptions"
|
||||
"k8s.io/cli-runtime/pkg/printers"
|
||||
"k8s.io/cli-runtime/pkg/resource"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/polymorphichelpers"
|
||||
"k8s.io/kubectl/pkg/scheme"
|
||||
"k8s.io/kubectl/pkg/util/completion"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
)
|
||||
|
||||
var (
|
||||
historyLong = templates.LongDesc(i18n.T(`
|
||||
View previous rollout revisions and configurations.`))
|
||||
|
||||
historyExample = templates.Examples(`
|
||||
# View the rollout history of a deployment
|
||||
kubectl rollout history deployment/abc
|
||||
|
||||
# View the details of daemonset revision 3
|
||||
kubectl rollout history daemonset/abc --revision=3`)
|
||||
)
|
||||
|
||||
// RolloutHistoryOptions holds the options for 'rollout history' sub command
|
||||
type RolloutHistoryOptions struct {
|
||||
PrintFlags *genericclioptions.PrintFlags
|
||||
ToPrinter func(string) (printers.ResourcePrinter, error)
|
||||
|
||||
Revision int64
|
||||
|
||||
Builder func() *resource.Builder
|
||||
Resources []string
|
||||
Namespace string
|
||||
EnforceNamespace bool
|
||||
LabelSelector string
|
||||
|
||||
HistoryViewer polymorphichelpers.HistoryViewerFunc
|
||||
RESTClientGetter genericclioptions.RESTClientGetter
|
||||
|
||||
resource.FilenameOptions
|
||||
genericiooptions.IOStreams
|
||||
}
|
||||
|
||||
// NewRolloutHistoryOptions returns an initialized RolloutHistoryOptions instance
|
||||
func NewRolloutHistoryOptions(streams genericiooptions.IOStreams) *RolloutHistoryOptions {
|
||||
return &RolloutHistoryOptions{
|
||||
PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme),
|
||||
IOStreams: streams,
|
||||
}
|
||||
}
|
||||
|
||||
// NewCmdRolloutHistory returns a Command instance for RolloutHistory sub command
|
||||
func NewCmdRolloutHistory(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
|
||||
o := NewRolloutHistoryOptions(streams)
|
||||
|
||||
validArgs := []string{"deployment", "daemonset", "statefulset"}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "history (TYPE NAME | TYPE/NAME) [flags]",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: i18n.T("View rollout history"),
|
||||
Long: historyLong,
|
||||
Example: historyExample,
|
||||
ValidArgsFunction: completion.SpecifiedResourceTypeAndNameCompletionFunc(f, validArgs),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.Run())
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().Int64Var(&o.Revision, "revision", o.Revision, "See the details, including podTemplate of the revision specified")
|
||||
cmdutil.AddLabelSelectorFlagVar(cmd, &o.LabelSelector)
|
||||
|
||||
usage := "identifying the resource to get from a server."
|
||||
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
||||
|
||||
o.PrintFlags.AddFlags(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Complete completes al the required options
|
||||
func (o *RolloutHistoryOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||
o.Resources = args
|
||||
|
||||
var err error
|
||||
if o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.ToPrinter = func(operation string) (printers.ResourcePrinter, error) {
|
||||
o.PrintFlags.NamePrintFlags.Operation = operation
|
||||
return o.PrintFlags.ToPrinter()
|
||||
}
|
||||
|
||||
o.HistoryViewer = polymorphichelpers.HistoryViewerFn
|
||||
o.RESTClientGetter = f
|
||||
o.Builder = f.NewBuilder
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate makes sure all the provided values for command-line options are valid
|
||||
func (o *RolloutHistoryOptions) Validate() error {
|
||||
if len(o.Resources) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames, o.Kustomize) {
|
||||
return fmt.Errorf("required resource not specified")
|
||||
}
|
||||
if o.Revision < 0 {
|
||||
return fmt.Errorf("revision must be a positive integer: %v", o.Revision)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run performs the execution of 'rollout history' sub command
|
||||
func (o *RolloutHistoryOptions) Run() error {
|
||||
|
||||
r := o.Builder().
|
||||
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||
FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
|
||||
LabelSelectorParam(o.LabelSelector).
|
||||
ResourceTypeOrNameArgs(true, o.Resources...).
|
||||
ContinueOnError().
|
||||
Latest().
|
||||
Flatten().
|
||||
Do()
|
||||
if err := r.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if o.PrintFlags.OutputFlagSpecified() {
|
||||
printer, err := o.PrintFlags.ToPrinter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return r.Visit(func(info *resource.Info, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mapping := info.ResourceMapping()
|
||||
historyViewer, err := o.HistoryViewer(o.RESTClientGetter, mapping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
historyInfo, err := historyViewer.GetHistory(info.Namespace, info.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if o.Revision > 0 {
|
||||
printer.PrintObj(historyInfo[o.Revision], o.Out)
|
||||
} else {
|
||||
sortedKeys := make([]int64, 0, len(historyInfo))
|
||||
for k := range historyInfo {
|
||||
sortedKeys = append(sortedKeys, k)
|
||||
}
|
||||
sort.Slice(sortedKeys, func(i, j int) bool { return sortedKeys[i] < sortedKeys[j] })
|
||||
for _, k := range sortedKeys {
|
||||
printer.PrintObj(historyInfo[k], o.Out)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
return r.Visit(func(info *resource.Info, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mapping := info.ResourceMapping()
|
||||
historyViewer, err := o.HistoryViewer(o.RESTClientGetter, mapping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
historyInfo, err := historyViewer.ViewHistory(info.Namespace, info.Name, o.Revision)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
withRevision := ""
|
||||
if o.Revision > 0 {
|
||||
withRevision = fmt.Sprintf("with revision #%d", o.Revision)
|
||||
}
|
||||
|
||||
printer, err := o.ToPrinter(fmt.Sprintf("%s\n%s", withRevision, historyInfo))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return printer.PrintObj(info.Object, o.Out)
|
||||
})
|
||||
}
|
||||
211
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_pause.go
generated
vendored
Normal file
211
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_pause.go
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
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 rollout
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"k8s.io/cli-runtime/pkg/genericiooptions"
|
||||
"k8s.io/cli-runtime/pkg/printers"
|
||||
"k8s.io/cli-runtime/pkg/resource"
|
||||
"k8s.io/kubectl/pkg/cmd/set"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/polymorphichelpers"
|
||||
"k8s.io/kubectl/pkg/scheme"
|
||||
"k8s.io/kubectl/pkg/util/completion"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
)
|
||||
|
||||
// PauseOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
|
||||
// referencing the cmd.Flags()
|
||||
type PauseOptions struct {
|
||||
PrintFlags *genericclioptions.PrintFlags
|
||||
ToPrinter func(string) (printers.ResourcePrinter, error)
|
||||
|
||||
Pauser polymorphichelpers.ObjectPauserFunc
|
||||
Builder func() *resource.Builder
|
||||
Namespace string
|
||||
EnforceNamespace bool
|
||||
Resources []string
|
||||
LabelSelector string
|
||||
|
||||
resource.FilenameOptions
|
||||
genericiooptions.IOStreams
|
||||
|
||||
fieldManager string
|
||||
}
|
||||
|
||||
var (
|
||||
pauseLong = templates.LongDesc(i18n.T(`
|
||||
Mark the provided resource as paused.
|
||||
|
||||
Paused resources will not be reconciled by a controller.
|
||||
Use "kubectl rollout resume" to resume a paused resource.
|
||||
Currently only deployments support being paused.`))
|
||||
|
||||
pauseExample = templates.Examples(`
|
||||
# Mark the nginx deployment as paused
|
||||
# Any current state of the deployment will continue its function; new updates
|
||||
# to the deployment will not have an effect as long as the deployment is paused
|
||||
kubectl rollout pause deployment/nginx`)
|
||||
)
|
||||
|
||||
// NewCmdRolloutPause returns a Command instance for 'rollout pause' sub command
|
||||
func NewCmdRolloutPause(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
|
||||
o := &PauseOptions{
|
||||
PrintFlags: genericclioptions.NewPrintFlags("paused").WithTypeSetter(scheme.Scheme),
|
||||
IOStreams: streams,
|
||||
}
|
||||
|
||||
validArgs := []string{"deployment"}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "pause RESOURCE",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: i18n.T("Mark the provided resource as paused"),
|
||||
Long: pauseLong,
|
||||
Example: pauseExample,
|
||||
ValidArgsFunction: completion.SpecifiedResourceTypeAndNameCompletionFunc(f, validArgs),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.RunPause())
|
||||
},
|
||||
}
|
||||
|
||||
o.PrintFlags.AddFlags(cmd)
|
||||
|
||||
usage := "identifying the resource to get from a server."
|
||||
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
||||
cmdutil.AddFieldManagerFlagVar(cmd, &o.fieldManager, "kubectl-rollout")
|
||||
cmdutil.AddLabelSelectorFlagVar(cmd, &o.LabelSelector)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Complete completes all the required options
|
||||
func (o *PauseOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||
o.Pauser = polymorphichelpers.ObjectPauserFn
|
||||
|
||||
var err error
|
||||
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.Resources = args
|
||||
o.Builder = f.NewBuilder
|
||||
|
||||
o.ToPrinter = func(operation string) (printers.ResourcePrinter, error) {
|
||||
o.PrintFlags.NamePrintFlags.Operation = operation
|
||||
return o.PrintFlags.ToPrinter()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *PauseOptions) Validate() error {
|
||||
if len(o.Resources) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames, o.Kustomize) {
|
||||
return fmt.Errorf("required resource not specified")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RunPause performs the execution of 'rollout pause' sub command
|
||||
func (o *PauseOptions) RunPause() error {
|
||||
r := o.Builder().
|
||||
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||
LabelSelectorParam(o.LabelSelector).
|
||||
FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
|
||||
ResourceTypeOrNameArgs(true, o.Resources...).
|
||||
ContinueOnError().
|
||||
Latest().
|
||||
Flatten().
|
||||
Do()
|
||||
if err := r.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allErrs := []error{}
|
||||
infos, err := r.Infos()
|
||||
if err != nil {
|
||||
// restore previous command behavior where
|
||||
// an error caused by retrieving infos due to
|
||||
// at least a single broken object did not result
|
||||
// in an immediate return, but rather an overall
|
||||
// aggregation of errors.
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
|
||||
patches := set.CalculatePatches(infos, scheme.DefaultJSONEncoder(), set.PatchFn(o.Pauser))
|
||||
|
||||
if len(patches) == 0 && len(allErrs) == 0 {
|
||||
fmt.Fprintf(o.ErrOut, "No resources found in %s namespace.\n", o.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, patch := range patches {
|
||||
info := patch.Info
|
||||
|
||||
if patch.Err != nil {
|
||||
resourceString := info.Mapping.Resource.Resource
|
||||
if len(info.Mapping.Resource.Group) > 0 {
|
||||
resourceString = resourceString + "." + info.Mapping.Resource.Group
|
||||
}
|
||||
allErrs = append(allErrs, fmt.Errorf("error: %s %q %v", resourceString, info.Name, patch.Err))
|
||||
continue
|
||||
}
|
||||
|
||||
if string(patch.Patch) == "{}" || len(patch.Patch) == 0 {
|
||||
printer, err := o.ToPrinter("already paused")
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
continue
|
||||
}
|
||||
if err = printer.PrintObj(info.Object, o.Out); err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
obj, err := resource.NewHelper(info.Client, info.Mapping).
|
||||
WithFieldManager(o.fieldManager).
|
||||
Patch(info.Namespace, info.Name, types.StrategicMergePatchType, patch.Patch, nil)
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, fmt.Errorf("failed to patch: %v", err))
|
||||
continue
|
||||
}
|
||||
|
||||
info.Refresh(obj, true)
|
||||
printer, err := o.ToPrinter("paused")
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
continue
|
||||
}
|
||||
if err = printer.PrintObj(info.Object, o.Out); err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
}
|
||||
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
}
|
||||
215
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_restart.go
generated
vendored
Normal file
215
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_restart.go
generated
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
Copyright 2019 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 rollout
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"k8s.io/cli-runtime/pkg/genericiooptions"
|
||||
"k8s.io/cli-runtime/pkg/printers"
|
||||
"k8s.io/cli-runtime/pkg/resource"
|
||||
"k8s.io/kubectl/pkg/cmd/set"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/polymorphichelpers"
|
||||
"k8s.io/kubectl/pkg/scheme"
|
||||
"k8s.io/kubectl/pkg/util/completion"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
)
|
||||
|
||||
// RestartOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
|
||||
// referencing the cmd.Flags()
|
||||
type RestartOptions struct {
|
||||
PrintFlags *genericclioptions.PrintFlags
|
||||
ToPrinter func(string) (printers.ResourcePrinter, error)
|
||||
|
||||
Resources []string
|
||||
|
||||
Builder func() *resource.Builder
|
||||
Restarter polymorphichelpers.ObjectRestarterFunc
|
||||
Namespace string
|
||||
EnforceNamespace bool
|
||||
LabelSelector string
|
||||
|
||||
resource.FilenameOptions
|
||||
genericiooptions.IOStreams
|
||||
|
||||
fieldManager string
|
||||
}
|
||||
|
||||
var (
|
||||
restartLong = templates.LongDesc(i18n.T(`
|
||||
Restart a resource.
|
||||
|
||||
Resource rollout will be restarted.`))
|
||||
|
||||
restartExample = templates.Examples(`
|
||||
# Restart all deployments in the test-namespace namespace
|
||||
kubectl rollout restart deployment -n test-namespace
|
||||
|
||||
# Restart a deployment
|
||||
kubectl rollout restart deployment/nginx
|
||||
|
||||
# Restart a daemon set
|
||||
kubectl rollout restart daemonset/abc
|
||||
|
||||
# Restart deployments with the app=nginx label
|
||||
kubectl rollout restart deployment --selector=app=nginx`)
|
||||
)
|
||||
|
||||
// NewRolloutRestartOptions returns an initialized RestartOptions instance
|
||||
func NewRolloutRestartOptions(streams genericiooptions.IOStreams) *RestartOptions {
|
||||
return &RestartOptions{
|
||||
PrintFlags: genericclioptions.NewPrintFlags("restarted").WithTypeSetter(scheme.Scheme),
|
||||
IOStreams: streams,
|
||||
}
|
||||
}
|
||||
|
||||
// NewCmdRolloutRestart returns a Command instance for 'rollout restart' sub command
|
||||
func NewCmdRolloutRestart(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
|
||||
o := NewRolloutRestartOptions(streams)
|
||||
|
||||
validArgs := []string{"deployment", "daemonset", "statefulset"}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "restart RESOURCE",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: i18n.T("Restart a resource"),
|
||||
Long: restartLong,
|
||||
Example: restartExample,
|
||||
ValidArgsFunction: completion.SpecifiedResourceTypeAndNameCompletionFunc(f, validArgs),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.RunRestart())
|
||||
},
|
||||
}
|
||||
|
||||
usage := "identifying the resource to get from a server."
|
||||
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
||||
cmdutil.AddFieldManagerFlagVar(cmd, &o.fieldManager, "kubectl-rollout")
|
||||
cmdutil.AddLabelSelectorFlagVar(cmd, &o.LabelSelector)
|
||||
o.PrintFlags.AddFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Complete completes all the required options
|
||||
func (o *RestartOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||
o.Resources = args
|
||||
|
||||
o.Restarter = polymorphichelpers.ObjectRestarterFn
|
||||
|
||||
var err error
|
||||
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.ToPrinter = func(operation string) (printers.ResourcePrinter, error) {
|
||||
o.PrintFlags.NamePrintFlags.Operation = operation
|
||||
return o.PrintFlags.ToPrinter()
|
||||
}
|
||||
|
||||
o.Builder = f.NewBuilder
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *RestartOptions) Validate() error {
|
||||
if len(o.Resources) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames, o.Kustomize) {
|
||||
return fmt.Errorf("required resource not specified")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RunRestart performs the execution of 'rollout restart' sub command
|
||||
func (o RestartOptions) RunRestart() error {
|
||||
r := o.Builder().
|
||||
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||
FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
|
||||
LabelSelectorParam(o.LabelSelector).
|
||||
ResourceTypeOrNameArgs(true, o.Resources...).
|
||||
ContinueOnError().
|
||||
Latest().
|
||||
Flatten().
|
||||
Do()
|
||||
if err := r.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allErrs := []error{}
|
||||
infos, err := r.Infos()
|
||||
if err != nil {
|
||||
// restore previous command behavior where
|
||||
// an error caused by retrieving infos due to
|
||||
// at least a single broken object did not result
|
||||
// in an immediate return, but rather an overall
|
||||
// aggregation of errors.
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
|
||||
patches := set.CalculatePatches(infos, scheme.DefaultJSONEncoder(), set.PatchFn(o.Restarter))
|
||||
|
||||
if len(patches) == 0 && len(allErrs) == 0 {
|
||||
fmt.Fprintf(o.ErrOut, "No resources found in %s namespace.\n", o.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, patch := range patches {
|
||||
info := patch.Info
|
||||
|
||||
if patch.Err != nil {
|
||||
resourceString := info.Mapping.Resource.Resource
|
||||
if len(info.Mapping.Resource.Group) > 0 {
|
||||
resourceString = resourceString + "." + info.Mapping.Resource.Group
|
||||
}
|
||||
allErrs = append(allErrs, fmt.Errorf("error: %s %q %v", resourceString, info.Name, patch.Err))
|
||||
continue
|
||||
}
|
||||
|
||||
if string(patch.Patch) == "{}" || len(patch.Patch) == 0 {
|
||||
allErrs = append(allErrs, fmt.Errorf("failed to create patch for %v: if restart has already been triggered within the past second, please wait before attempting to trigger another", info.Name))
|
||||
continue
|
||||
}
|
||||
|
||||
obj, err := resource.NewHelper(info.Client, info.Mapping).
|
||||
WithFieldManager(o.fieldManager).
|
||||
Patch(info.Namespace, info.Name, types.StrategicMergePatchType, patch.Patch, nil)
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, fmt.Errorf("failed to patch: %v", err))
|
||||
continue
|
||||
}
|
||||
|
||||
info.Refresh(obj, true)
|
||||
printer, err := o.ToPrinter("restarted")
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
continue
|
||||
}
|
||||
if err = printer.PrintObj(info.Object, o.Out); err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
}
|
||||
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
}
|
||||
215
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_resume.go
generated
vendored
Normal file
215
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_resume.go
generated
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
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 rollout
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"k8s.io/cli-runtime/pkg/genericiooptions"
|
||||
"k8s.io/cli-runtime/pkg/printers"
|
||||
"k8s.io/cli-runtime/pkg/resource"
|
||||
"k8s.io/kubectl/pkg/cmd/set"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/polymorphichelpers"
|
||||
"k8s.io/kubectl/pkg/scheme"
|
||||
"k8s.io/kubectl/pkg/util/completion"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
)
|
||||
|
||||
// ResumeOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
|
||||
// referencing the cmd.Flags()
|
||||
type ResumeOptions struct {
|
||||
PrintFlags *genericclioptions.PrintFlags
|
||||
ToPrinter func(string) (printers.ResourcePrinter, error)
|
||||
|
||||
Resources []string
|
||||
|
||||
Builder func() *resource.Builder
|
||||
Resumer polymorphichelpers.ObjectResumerFunc
|
||||
Namespace string
|
||||
EnforceNamespace bool
|
||||
LabelSelector string
|
||||
|
||||
resource.FilenameOptions
|
||||
genericiooptions.IOStreams
|
||||
|
||||
fieldManager string
|
||||
}
|
||||
|
||||
var (
|
||||
resumeLong = templates.LongDesc(i18n.T(`
|
||||
Resume a paused resource.
|
||||
|
||||
Paused resources will not be reconciled by a controller. By resuming a
|
||||
resource, we allow it to be reconciled again.
|
||||
Currently only deployments support being resumed.`))
|
||||
|
||||
resumeExample = templates.Examples(`
|
||||
# Resume an already paused deployment
|
||||
kubectl rollout resume deployment/nginx`)
|
||||
)
|
||||
|
||||
// NewRolloutResumeOptions returns an initialized ResumeOptions instance
|
||||
func NewRolloutResumeOptions(streams genericiooptions.IOStreams) *ResumeOptions {
|
||||
return &ResumeOptions{
|
||||
PrintFlags: genericclioptions.NewPrintFlags("resumed").WithTypeSetter(scheme.Scheme),
|
||||
IOStreams: streams,
|
||||
}
|
||||
}
|
||||
|
||||
// NewCmdRolloutResume returns a Command instance for 'rollout resume' sub command
|
||||
func NewCmdRolloutResume(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
|
||||
o := NewRolloutResumeOptions(streams)
|
||||
|
||||
validArgs := []string{"deployment"}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "resume RESOURCE",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: i18n.T("Resume a paused resource"),
|
||||
Long: resumeLong,
|
||||
Example: resumeExample,
|
||||
ValidArgsFunction: completion.SpecifiedResourceTypeAndNameCompletionFunc(f, validArgs),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.RunResume())
|
||||
},
|
||||
}
|
||||
|
||||
usage := "identifying the resource to get from a server."
|
||||
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
||||
cmdutil.AddFieldManagerFlagVar(cmd, &o.fieldManager, "kubectl-rollout")
|
||||
cmdutil.AddLabelSelectorFlagVar(cmd, &o.LabelSelector)
|
||||
o.PrintFlags.AddFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Complete completes all the required options
|
||||
func (o *ResumeOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||
o.Resources = args
|
||||
|
||||
o.Resumer = polymorphichelpers.ObjectResumerFn
|
||||
|
||||
var err error
|
||||
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.ToPrinter = func(operation string) (printers.ResourcePrinter, error) {
|
||||
o.PrintFlags.NamePrintFlags.Operation = operation
|
||||
return o.PrintFlags.ToPrinter()
|
||||
}
|
||||
|
||||
o.Builder = f.NewBuilder
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *ResumeOptions) Validate() error {
|
||||
if len(o.Resources) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames, o.Kustomize) {
|
||||
return fmt.Errorf("required resource not specified")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RunResume performs the execution of 'rollout resume' sub command
|
||||
func (o ResumeOptions) RunResume() error {
|
||||
r := o.Builder().
|
||||
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||
LabelSelectorParam(o.LabelSelector).
|
||||
FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
|
||||
ResourceTypeOrNameArgs(true, o.Resources...).
|
||||
ContinueOnError().
|
||||
Latest().
|
||||
Flatten().
|
||||
Do()
|
||||
if err := r.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allErrs := []error{}
|
||||
infos, err := r.Infos()
|
||||
if err != nil {
|
||||
// restore previous command behavior where
|
||||
// an error caused by retrieving infos due to
|
||||
// at least a single broken object did not result
|
||||
// in an immediate return, but rather an overall
|
||||
// aggregation of errors.
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
|
||||
patches := set.CalculatePatches(infos, scheme.DefaultJSONEncoder(), set.PatchFn(o.Resumer))
|
||||
|
||||
if len(patches) == 0 && len(allErrs) == 0 {
|
||||
fmt.Fprintf(o.ErrOut, "No resources found in %s namespace.\n", o.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, patch := range patches {
|
||||
info := patch.Info
|
||||
|
||||
if patch.Err != nil {
|
||||
resourceString := info.Mapping.Resource.Resource
|
||||
if len(info.Mapping.Resource.Group) > 0 {
|
||||
resourceString = resourceString + "." + info.Mapping.Resource.Group
|
||||
}
|
||||
allErrs = append(allErrs, fmt.Errorf("error: %s %q %v", resourceString, info.Name, patch.Err))
|
||||
continue
|
||||
}
|
||||
|
||||
if string(patch.Patch) == "{}" || len(patch.Patch) == 0 {
|
||||
printer, err := o.ToPrinter("already resumed")
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
continue
|
||||
}
|
||||
if err = printer.PrintObj(info.Object, o.Out); err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
obj, err := resource.NewHelper(info.Client, info.Mapping).
|
||||
WithFieldManager(o.fieldManager).
|
||||
Patch(info.Namespace, info.Name, types.StrategicMergePatchType, patch.Patch, nil)
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, fmt.Errorf("failed to patch: %v", err))
|
||||
continue
|
||||
}
|
||||
|
||||
info.Refresh(obj, true)
|
||||
printer, err := o.ToPrinter("resumed")
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
continue
|
||||
}
|
||||
if err = printer.PrintObj(info.Object, o.Out); err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
}
|
||||
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
}
|
||||
243
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_status.go
generated
vendored
Normal file
243
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_status.go
generated
vendored
Normal file
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
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 rollout
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"k8s.io/cli-runtime/pkg/genericiooptions"
|
||||
"k8s.io/cli-runtime/pkg/resource"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
watchtools "k8s.io/client-go/tools/watch"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/polymorphichelpers"
|
||||
"k8s.io/kubectl/pkg/scheme"
|
||||
"k8s.io/kubectl/pkg/util/completion"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/interrupt"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
)
|
||||
|
||||
var (
|
||||
statusLong = templates.LongDesc(i18n.T(`
|
||||
Show the status of the rollout.
|
||||
|
||||
By default 'rollout status' will watch the status of the latest rollout
|
||||
until it's done. If you don't want to wait for the rollout to finish then
|
||||
you can use --watch=false. Note that if a new rollout starts in-between, then
|
||||
'rollout status' will continue watching the latest revision. If you want to
|
||||
pin to a specific revision and abort if it is rolled over by another revision,
|
||||
use --revision=N where N is the revision you need to watch for.`))
|
||||
|
||||
statusExample = templates.Examples(`
|
||||
# Watch the rollout status of a deployment
|
||||
kubectl rollout status deployment/nginx`)
|
||||
)
|
||||
|
||||
// RolloutStatusOptions holds the command-line options for 'rollout status' sub command
|
||||
type RolloutStatusOptions struct {
|
||||
PrintFlags *genericclioptions.PrintFlags
|
||||
|
||||
Namespace string
|
||||
EnforceNamespace bool
|
||||
BuilderArgs []string
|
||||
LabelSelector string
|
||||
|
||||
Watch bool
|
||||
Revision int64
|
||||
Timeout time.Duration
|
||||
|
||||
StatusViewerFn func(*meta.RESTMapping) (polymorphichelpers.StatusViewer, error)
|
||||
Builder func() *resource.Builder
|
||||
DynamicClient dynamic.Interface
|
||||
|
||||
FilenameOptions *resource.FilenameOptions
|
||||
genericiooptions.IOStreams
|
||||
}
|
||||
|
||||
// NewRolloutStatusOptions returns an initialized RolloutStatusOptions instance
|
||||
func NewRolloutStatusOptions(streams genericiooptions.IOStreams) *RolloutStatusOptions {
|
||||
return &RolloutStatusOptions{
|
||||
PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme),
|
||||
FilenameOptions: &resource.FilenameOptions{},
|
||||
IOStreams: streams,
|
||||
Watch: true,
|
||||
Timeout: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// NewCmdRolloutStatus returns a Command instance for the 'rollout status' sub command
|
||||
func NewCmdRolloutStatus(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
|
||||
o := NewRolloutStatusOptions(streams)
|
||||
|
||||
validArgs := []string{"deployment", "daemonset", "statefulset"}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "status (TYPE NAME | TYPE/NAME) [flags]",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: i18n.T("Show the status of the rollout"),
|
||||
Long: statusLong,
|
||||
Example: statusExample,
|
||||
ValidArgsFunction: completion.SpecifiedResourceTypeAndNameNoRepeatCompletionFunc(f, validArgs),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Complete(f, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.Run())
|
||||
},
|
||||
}
|
||||
|
||||
usage := "identifying the resource to get from a server."
|
||||
cmdutil.AddFilenameOptionFlags(cmd, o.FilenameOptions, usage)
|
||||
cmd.Flags().BoolVarP(&o.Watch, "watch", "w", o.Watch, "Watch the status of the rollout until it's done.")
|
||||
cmd.Flags().Int64Var(&o.Revision, "revision", o.Revision, "Pin to a specific revision for showing its status. Defaults to 0 (last revision).")
|
||||
cmd.Flags().DurationVar(&o.Timeout, "timeout", o.Timeout, "The length of time to wait before ending watch, zero means never. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h).")
|
||||
cmdutil.AddLabelSelectorFlagVar(cmd, &o.LabelSelector)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Complete completes all the required options
|
||||
func (o *RolloutStatusOptions) Complete(f cmdutil.Factory, args []string) error {
|
||||
o.Builder = f.NewBuilder
|
||||
|
||||
var err error
|
||||
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.BuilderArgs = args
|
||||
o.StatusViewerFn = polymorphichelpers.StatusViewerFn
|
||||
|
||||
o.DynamicClient, err = f.DynamicClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate makes sure all the provided values for command-line options are valid
|
||||
func (o *RolloutStatusOptions) Validate() error {
|
||||
if len(o.BuilderArgs) == 0 && cmdutil.IsFilenameSliceEmpty(o.FilenameOptions.Filenames, o.FilenameOptions.Kustomize) {
|
||||
return fmt.Errorf("required resource not specified")
|
||||
}
|
||||
|
||||
if o.Revision < 0 {
|
||||
return fmt.Errorf("revision must be a positive integer: %v", o.Revision)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run performs the execution of 'rollout status' sub command
|
||||
func (o *RolloutStatusOptions) Run() error {
|
||||
r := o.Builder().
|
||||
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||
LabelSelectorParam(o.LabelSelector).
|
||||
FilenameParam(o.EnforceNamespace, o.FilenameOptions).
|
||||
ResourceTypeOrNameArgs(true, o.BuilderArgs...).
|
||||
ContinueOnError().
|
||||
Latest().
|
||||
Flatten().
|
||||
Do()
|
||||
|
||||
err := r.Err()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resourceFound := false
|
||||
err = r.Visit(func(info *resource.Info, _ error) error {
|
||||
resourceFound = true
|
||||
mapping := info.ResourceMapping()
|
||||
statusViewer, err := o.StatusViewerFn(mapping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldSelector := fields.OneTermEqualSelector("metadata.name", info.Name).String()
|
||||
lw := &cache.ListWatch{
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
options.FieldSelector = fieldSelector
|
||||
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(context.TODO(), options)
|
||||
},
|
||||
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
||||
options.FieldSelector = fieldSelector
|
||||
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(context.TODO(), options)
|
||||
},
|
||||
}
|
||||
|
||||
// if the rollout isn't done yet, keep watching deployment status
|
||||
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), o.Timeout)
|
||||
intr := interrupt.New(nil, cancel)
|
||||
return intr.Run(func() error {
|
||||
_, err = watchtools.UntilWithSync(ctx, lw, &unstructured.Unstructured{}, nil, func(e watch.Event) (bool, error) {
|
||||
switch t := e.Type; t {
|
||||
case watch.Added, watch.Modified:
|
||||
status, done, err := statusViewer.Status(e.Object.(runtime.Unstructured), o.Revision)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
fmt.Fprintf(o.Out, "%s", status)
|
||||
// Quit waiting if the rollout is done
|
||||
if done {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
shouldWatch := o.Watch
|
||||
if !shouldWatch {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
|
||||
case watch.Deleted:
|
||||
// We need to abort to avoid cases of recreation and not to silently watch the wrong (new) object
|
||||
return true, fmt.Errorf("object has been deleted")
|
||||
|
||||
default:
|
||||
return true, fmt.Errorf("internal error: unexpected event %#v", e)
|
||||
}
|
||||
})
|
||||
return err
|
||||
})
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !resourceFound {
|
||||
fmt.Fprintf(o.ErrOut, "No resources found in %s namespace.\n", o.Namespace)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
179
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_undo.go
generated
vendored
Normal file
179
vendor/k8s.io/kubectl/pkg/cmd/rollout/rollout_undo.go
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
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 rollout
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"k8s.io/cli-runtime/pkg/genericiooptions"
|
||||
"k8s.io/cli-runtime/pkg/printers"
|
||||
"k8s.io/cli-runtime/pkg/resource"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/polymorphichelpers"
|
||||
"k8s.io/kubectl/pkg/scheme"
|
||||
"k8s.io/kubectl/pkg/util/completion"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
)
|
||||
|
||||
// UndoOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
|
||||
// referencing the cmd.Flags()
|
||||
type UndoOptions struct {
|
||||
PrintFlags *genericclioptions.PrintFlags
|
||||
ToPrinter func(string) (printers.ResourcePrinter, error)
|
||||
|
||||
Builder func() *resource.Builder
|
||||
ToRevision int64
|
||||
DryRunStrategy cmdutil.DryRunStrategy
|
||||
Resources []string
|
||||
Namespace string
|
||||
LabelSelector string
|
||||
EnforceNamespace bool
|
||||
RESTClientGetter genericclioptions.RESTClientGetter
|
||||
|
||||
resource.FilenameOptions
|
||||
genericiooptions.IOStreams
|
||||
}
|
||||
|
||||
var (
|
||||
undoLong = templates.LongDesc(i18n.T(`
|
||||
Roll back to a previous rollout.`))
|
||||
|
||||
undoExample = templates.Examples(`
|
||||
# Roll back to the previous deployment
|
||||
kubectl rollout undo deployment/abc
|
||||
|
||||
# Roll back to daemonset revision 3
|
||||
kubectl rollout undo daemonset/abc --to-revision=3
|
||||
|
||||
# Roll back to the previous deployment with dry-run
|
||||
kubectl rollout undo --dry-run=server deployment/abc`)
|
||||
)
|
||||
|
||||
// NewRolloutUndoOptions returns an initialized UndoOptions instance
|
||||
func NewRolloutUndoOptions(streams genericiooptions.IOStreams) *UndoOptions {
|
||||
return &UndoOptions{
|
||||
PrintFlags: genericclioptions.NewPrintFlags("rolled back").WithTypeSetter(scheme.Scheme),
|
||||
IOStreams: streams,
|
||||
ToRevision: int64(0),
|
||||
}
|
||||
}
|
||||
|
||||
// NewCmdRolloutUndo returns a Command instance for the 'rollout undo' sub command
|
||||
func NewCmdRolloutUndo(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
|
||||
o := NewRolloutUndoOptions(streams)
|
||||
|
||||
validArgs := []string{"deployment", "daemonset", "statefulset"}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "undo (TYPE NAME | TYPE/NAME) [flags]",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: i18n.T("Undo a previous rollout"),
|
||||
Long: undoLong,
|
||||
Example: undoExample,
|
||||
ValidArgsFunction: completion.SpecifiedResourceTypeAndNameCompletionFunc(f, validArgs),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.RunUndo())
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().Int64Var(&o.ToRevision, "to-revision", o.ToRevision, "The revision to rollback to. Default to 0 (last revision).")
|
||||
usage := "identifying the resource to get from a server."
|
||||
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
||||
cmdutil.AddDryRunFlag(cmd)
|
||||
cmdutil.AddLabelSelectorFlagVar(cmd, &o.LabelSelector)
|
||||
o.PrintFlags.AddFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Complete completes all the required options
|
||||
func (o *UndoOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||
o.Resources = args
|
||||
var err error
|
||||
o.DryRunStrategy, err = cmdutil.GetDryRunStrategy(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.ToPrinter = func(operation string) (printers.ResourcePrinter, error) {
|
||||
o.PrintFlags.NamePrintFlags.Operation = operation
|
||||
cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy)
|
||||
return o.PrintFlags.ToPrinter()
|
||||
}
|
||||
|
||||
o.RESTClientGetter = f
|
||||
o.Builder = f.NewBuilder
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o *UndoOptions) Validate() error {
|
||||
if len(o.Resources) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames, o.Kustomize) {
|
||||
return fmt.Errorf("required resource not specified")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RunUndo performs the execution of 'rollout undo' sub command
|
||||
func (o *UndoOptions) RunUndo() error {
|
||||
r := o.Builder().
|
||||
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||
LabelSelectorParam(o.LabelSelector).
|
||||
FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
|
||||
ResourceTypeOrNameArgs(true, o.Resources...).
|
||||
ContinueOnError().
|
||||
Latest().
|
||||
Flatten().
|
||||
Do()
|
||||
if err := r.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := r.Visit(func(info *resource.Info, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollbacker, err := polymorphichelpers.RollbackerFn(o.RESTClientGetter, info.ResourceMapping())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result, err := rollbacker.Rollback(info.Object, nil, o.ToRevision, o.DryRunStrategy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printer, err := o.ToPrinter(result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return printer.PrintObj(info.Object, o.Out)
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@@ -631,6 +631,9 @@ github.com/libp2p/go-netroute
|
||||
# github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
|
||||
## explicit
|
||||
github.com/liggitt/tabwriter
|
||||
# github.com/lithammer/dedent v1.1.0
|
||||
## explicit
|
||||
github.com/lithammer/dedent
|
||||
# github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683
|
||||
## explicit; go 1.16
|
||||
github.com/lufia/plan9stats
|
||||
@@ -1984,6 +1987,7 @@ k8s.io/kubectl/pkg/apps
|
||||
k8s.io/kubectl/pkg/cmd/apiresources
|
||||
k8s.io/kubectl/pkg/cmd/exec
|
||||
k8s.io/kubectl/pkg/cmd/get
|
||||
k8s.io/kubectl/pkg/cmd/rollout
|
||||
k8s.io/kubectl/pkg/cmd/set
|
||||
k8s.io/kubectl/pkg/cmd/set/env
|
||||
k8s.io/kubectl/pkg/cmd/util
|
||||
|
||||
Reference in New Issue
Block a user