mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
kubeadm-upgrade: small improvements to diff
1) Store the io.Writer and pass it to sub-commands in upgrade.go 2) Check if the manifest path is an empty string in diff.go:runDiff() 3) Use the io.Writer that upgrade.go defines instead of writing to os.Stdout directly.
This commit is contained in:
parent
bf790f4467
commit
5adee74000
@ -17,8 +17,8 @@ limitations under the License.
|
|||||||
package upgrade
|
package upgrade
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/pmezard/go-difflib/difflib"
|
"github.com/pmezard/go-difflib/difflib"
|
||||||
@ -119,6 +119,9 @@ func runDiff(flags *diffFlags, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if path == "" {
|
||||||
|
return fmt.Errorf("empty manifest path")
|
||||||
|
}
|
||||||
existingManifest, err := ioutil.ReadFile(path)
|
existingManifest, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -133,7 +136,7 @@ func runDiff(flags *diffFlags, args []string) error {
|
|||||||
Context: flags.contextLines,
|
Context: flags.contextLines,
|
||||||
}
|
}
|
||||||
|
|
||||||
difflib.WriteUnifiedDiff(os.Stdout, diff)
|
difflib.WriteUnifiedDiff(flags.parent.out, diff)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ type cmdUpgradeFlags struct {
|
|||||||
skipPreFlight bool
|
skipPreFlight bool
|
||||||
ignorePreflightErrors []string
|
ignorePreflightErrors []string
|
||||||
ignorePreflightErrorsSet sets.String
|
ignorePreflightErrorsSet sets.String
|
||||||
|
out io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdUpgrade returns the cobra command for `kubeadm upgrade`
|
// NewCmdUpgrade returns the cobra command for `kubeadm upgrade`
|
||||||
@ -50,6 +51,7 @@ func NewCmdUpgrade(out io.Writer) *cobra.Command {
|
|||||||
printConfig: false,
|
printConfig: false,
|
||||||
skipPreFlight: false,
|
skipPreFlight: false,
|
||||||
ignorePreflightErrorsSet: sets.NewString(),
|
ignorePreflightErrorsSet: sets.NewString(),
|
||||||
|
out: out,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
|
Loading…
Reference in New Issue
Block a user