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:
Lubomir I. Ivanov 2018-05-17 20:39:21 +03:00
parent bf790f4467
commit 5adee74000
2 changed files with 7 additions and 2 deletions

View File

@ -17,8 +17,8 @@ limitations under the License.
package upgrade
import (
"fmt"
"io/ioutil"
"os"
"github.com/golang/glog"
"github.com/pmezard/go-difflib/difflib"
@ -119,6 +119,9 @@ func runDiff(flags *diffFlags, args []string) error {
if err != nil {
return err
}
if path == "" {
return fmt.Errorf("empty manifest path")
}
existingManifest, err := ioutil.ReadFile(path)
if err != nil {
return err
@ -133,7 +136,7 @@ func runDiff(flags *diffFlags, args []string) error {
Context: flags.contextLines,
}
difflib.WriteUnifiedDiff(os.Stdout, diff)
difflib.WriteUnifiedDiff(flags.parent.out, diff)
}
return nil
}

View File

@ -37,6 +37,7 @@ type cmdUpgradeFlags struct {
skipPreFlight bool
ignorePreflightErrors []string
ignorePreflightErrorsSet sets.String
out io.Writer
}
// NewCmdUpgrade returns the cobra command for `kubeadm upgrade`
@ -50,6 +51,7 @@ func NewCmdUpgrade(out io.Writer) *cobra.Command {
printConfig: false,
skipPreFlight: false,
ignorePreflightErrorsSet: sets.NewString(),
out: out,
}
cmd := &cobra.Command{