Commit c54355f2
c54355f22ecbMerged
Svyatoslav Dumchenko <[email protected]> ยท 4 years ago ยท 1 file ยท ~1 modified
Description
Support skipping resources diff
Details
- Commit
- c54355f22ecb
- Parent
- fa64b921a6a5
pkg/plan/diff.gomodifiedView file
@@ -11,12 +11,21 @@
1111
"github.com/helmwave/helmwave/pkg/release"1212
"github.com/helmwave/helmwave/pkg/release/uniqname"1313
log "github.com/sirupsen/logrus"14+
"gopkg.in/yaml.v3"1415
live "helm.sh/helm/v3/pkg/release"1516
)1617
17-
// ErrPlansAreTheSame is returned when trying to compare plan with itself.18-
var ErrPlansAreTheSame = errors.New("plan1 and plan2 are the same")18+
var (19+
// ErrPlansAreTheSame is returned when trying to compare plan with itself.20+
ErrPlansAreTheSame = errors.New("plan1 and plan2 are the same")1921
22+
// SkippedAnnotations is a map with all annotations to be skipped by differ.23+
SkippedAnnotations = map[string]string{24+
live.HookAnnotation: string(live.HookTest),25+
"helmwave.dev/skip-diff": "true",26+
}27+
)28+
2029
// DiffPlan show diff between 2 plans.2130
func (p *Plan) DiffPlan(b *Plan, showSecret bool, diffWide int) {2231
visited := make(map[uniqname.UniqName]bool)@@ -28,8 +37,8 @@
2837
}2938
visited[rel.Uniq()] = true3039
31-
oldSpecs := manifest.Parse(b.manifests[rel.Uniq()], rel.Namespace())32-
newSpecs := manifest.Parse(p.manifests[rel.Uniq()], rel.Namespace())40+
oldSpecs := parseManifests(b.manifests[rel.Uniq()], rel.Namespace())41+
newSpecs := parseManifests(p.manifests[rel.Uniq()], rel.Namespace())3342
3443
change := diff.Manifests(oldSpecs, newSpecs, []string{}, showSecret, diffWide, log.StandardLogger().Out)3544
if !change {@@ -60,8 +69,8 @@
6069
if active, ok := alive[rel.Uniq()]; ok {6170
// I dont use manifest.ParseRelease6271
// Because Structs are different.63-
oldSpecs := manifest.Parse(active.Manifest, rel.Namespace())64-
newSpecs := manifest.Parse(p.manifests[rel.Uniq()], rel.Namespace())72+
oldSpecs := parseManifests(active.Manifest, rel.Namespace())73+
newSpecs := parseManifests(p.manifests[rel.Uniq()], rel.Namespace())6574
6675
change := diff.Manifests(oldSpecs, newSpecs, []string{}, showSecret, diffWide, log.StandardLogger().Out)6776
if !change {@@ -74,6 +83,44 @@
7483
showChangesReport(p.body.Releases, visited, k)7584
}7685
86+
func parseManifests(m, ns string) map[string]*manifest.MappingResult {87+
manifests := manifest.Parse(m, ns)88+
89+
type annotationManifest struct {90+
Metadata struct {91+
Annotations map[string]string92+
}93+
}94+
95+
for k := range manifests {96+
parsed := annotationManifest{}97+
98+
if err := yaml.Unmarshal([]byte(manifests[k].Content), &parsed); err != nil {99+
log.WithError(err).WithField("content", manifests[k].Content).Debug("failed to decode manifest")100+
101+
continue102+
}103+
104+
if parsed.Metadata.Annotations == nil {105+
continue106+
}107+
108+
for anno := range SkippedAnnotations {109+
if SkippedAnnotations[anno] == parsed.Metadata.Annotations[anno] {110+
log.WithFields(log.Fields{111+
"resource": manifests[k].Name,112+
"annotation": anno,113+
}).Debug("resource diff is skipped due to annotation")114+
delete(manifests, k)115+
116+
continue117+
}118+
}119+
}120+
121+
return manifests122+
}123+
77124
// showChangesReport help function for reporting helm-diff.78125
func showChangesReport(releases []release.Config, visited []uniqname.UniqName, k int) {79126
previous := false