mirror of https://github.com/kubernetes/kops.git
Cleaner dryrun output
This commit is contained in:
parent
aa51cfa967
commit
50159fe47d
|
@ -8,6 +8,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"k8s.io/kops/upup/pkg/fi/utils"
|
"k8s.io/kops/upup/pkg/fi/utils"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DryRunTarget is a special Target that does not execute anything, but instead tracks all changes.
|
// DryRunTarget is a special Target that does not execute anything, but instead tracks all changes.
|
||||||
|
@ -62,21 +63,29 @@ func (t *DryRunTarget) PrintReport(taskMap map[string]Task, out io.Writer) error
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
|
|
||||||
if len(t.changes) != 0 {
|
if len(t.changes) != 0 {
|
||||||
fmt.Fprintf(b, "Will create resources:\n")
|
var creates []*render
|
||||||
for _, r := range t.changes {
|
var updates []*render
|
||||||
if !r.aIsNil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(b, " %T\t%s\n", r.changes, IdForTask(taskMap, r.e))
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(b, "Will modify resources:\n")
|
|
||||||
// We can't use our reflection helpers here - we want corresponding values from a,e,c
|
|
||||||
for _, r := range t.changes {
|
for _, r := range t.changes {
|
||||||
if r.aIsNil {
|
if r.aIsNil {
|
||||||
continue
|
creates = append(creates, r)
|
||||||
|
} else {
|
||||||
|
updates = append(updates, r)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(creates) != 0 {
|
||||||
|
fmt.Fprintf(b, "Will create resources:\n")
|
||||||
|
for _, r := range creates {
|
||||||
|
taskName := getTaskName(r.changes)
|
||||||
|
fmt.Fprintf(b, " %s\t%s\n", taskName, IdForTask(taskMap, r.e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(updates) != 0 {
|
||||||
|
fmt.Fprintf(b, "Will modify resources:\n")
|
||||||
|
// We can't use our reflection helpers here - we want corresponding values from a,e,c
|
||||||
|
for _, r := range updates {
|
||||||
var changeList []string
|
var changeList []string
|
||||||
|
|
||||||
valC := reflect.ValueOf(r.changes)
|
valC := reflect.ValueOf(r.changes)
|
||||||
|
@ -139,18 +148,29 @@ func (t *DryRunTarget) PrintReport(taskMap map[string]Task, out io.Writer) error
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(b, " %T\t%s\n", r.changes, IdForTask(taskMap, r.e))
|
taskName := getTaskName(r.changes)
|
||||||
|
fmt.Fprintf(b, " %s\t%s\n", taskName, IdForTask(taskMap, r.e))
|
||||||
for _, f := range changeList {
|
for _, f := range changeList {
|
||||||
fmt.Fprintf(b, " %s\n", f)
|
fmt.Fprintf(b, " %s\n", f)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(b, "\n")
|
fmt.Fprintf(b, "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_, err := out.Write(b.Bytes())
|
_, err := out.Write(b.Bytes())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTaskName(t Task) string {
|
||||||
|
s := fmt.Sprintf("%T", t)
|
||||||
|
lastDot := strings.LastIndexByte(s, '.')
|
||||||
|
if lastDot != -1 {
|
||||||
|
s = s[lastDot+1:]
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// asString returns a human-readable string representation of the passed value
|
// asString returns a human-readable string representation of the passed value
|
||||||
func ValueAsString(value reflect.Value) string {
|
func ValueAsString(value reflect.Value) string {
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
|
|
Loading…
Reference in New Issue