Include resource type headers in diff report

This commit is contained in:
Jeff Grafton 2016-12-05 15:38:48 -08:00
parent 2c61d2f80c
commit 0be9b81319

View File

@ -29,6 +29,7 @@ import (
"os/signal" "os/signal"
"os/user" "os/user"
"path/filepath" "path/filepath"
"regexp"
"strconv" "strconv"
"strings" "strings"
"text/template" "text/template"
@ -424,14 +425,19 @@ func DiffResources(before, clusterUp, clusterDown, after []byte, location string
} }
lines = lines[2:] lines = lines[2:]
var added []string var added, report []string
resourceTypeRE := regexp.MustCompile(`^@@.+\s(\[\s\S+\s\])$`)
for _, l := range lines { for _, l := range lines {
if matches := resourceTypeRE.FindStringSubmatch(l); matches != nil {
report = append(report, matches[1])
}
if strings.HasPrefix(l, "+") && len(strings.TrimPrefix(l, "+")) > 0 { if strings.HasPrefix(l, "+") && len(strings.TrimPrefix(l, "+")) > 0 {
added = append(added, l) added = append(added, l)
report = append(report, l)
} }
} }
if len(added) > 0 { if len(added) > 0 {
return fmt.Errorf("Error: %d leaked resources\n%v", len(added), strings.Join(added, "\n")) return fmt.Errorf("Error: %d leaked resources\n%v", len(added), strings.Join(report, "\n"))
} }
return nil return nil
} }