Skip to content

Commit 1b7c062

Browse files
authored
Merge pull request #41 from novas0x2a/namespace-aware
add namespace to deduplication tuple
2 parents d2916ae + 8fa52bb commit 1b7c062

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

cmd/revision.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ func (d *revision) differentiate() error {
9191
return prettyError(err)
9292
}
9393

94-
diff.DiffManifests(manifest.Parse(revisionResponse.Release.Manifest), manifest.Parse(releaseResponse.Release.Manifest), d.suppressedKinds, d.outputContext, os.Stdout)
94+
diff.DiffManifests(
95+
manifest.Parse(revisionResponse.Release.Manifest, revisionResponse.Release.Namespace),
96+
manifest.Parse(releaseResponse.Release.Manifest, releaseResponse.Release.Namespace),
97+
d.suppressedKinds,
98+
d.outputContext,
99+
os.Stdout)
95100

96101
case 2:
97102
revision1, _ := strconv.Atoi(d.revisions[0])
@@ -110,7 +115,12 @@ func (d *revision) differentiate() error {
110115
return prettyError(err)
111116
}
112117

113-
diff.DiffManifests(manifest.Parse(revisionResponse1.Release.Manifest), manifest.Parse(revisionResponse2.Release.Manifest), d.suppressedKinds, d.outputContext, os.Stdout)
118+
diff.DiffManifests(
119+
manifest.Parse(revisionResponse1.Release.Manifest, revisionResponse1.Release.Namespace),
120+
manifest.Parse(revisionResponse2.Release.Manifest, revisionResponse2.Release.Namespace),
121+
d.suppressedKinds,
122+
d.outputContext,
123+
os.Stdout)
114124

115125
default:
116126
return errors.New("Invalid Arguments")

cmd/rollback.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ func (d *rollback) backcast() error {
8282
}
8383

8484
// create a diff between the current manifest and the version of the manifest that a user is intended to rollback
85-
diff.DiffManifests(manifest.Parse(releaseResponse.Release.Manifest), manifest.Parse(revisionResponse.Release.Manifest), d.suppressedKinds, d.outputContext, os.Stdout)
85+
diff.DiffManifests(
86+
manifest.Parse(releaseResponse.Release.Manifest, releaseResponse.Release.Namespace),
87+
manifest.Parse(revisionResponse.Release.Manifest, revisionResponse.Release.Namespace),
88+
d.suppressedKinds,
89+
d.outputContext,
90+
os.Stdout)
8691

8792
return nil
8893
}

cmd/upgrade.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (d *diffCmd) run() error {
121121
}
122122

123123
currentSpecs = make(map[string]*manifest.MappingResult)
124-
newSpecs = manifest.Parse(installResponse.Release.Manifest)
124+
newSpecs = manifest.Parse(installResponse.Release.Manifest, installResponse.Release.Namespace)
125125
} else {
126126
upgradeResponse, err := d.client.UpdateRelease(
127127
d.release,
@@ -135,8 +135,8 @@ func (d *diffCmd) run() error {
135135
return prettyError(err)
136136
}
137137

138-
currentSpecs = manifest.Parse(releaseResponse.Release.Manifest)
139-
newSpecs = manifest.Parse(upgradeResponse.Release.Manifest)
138+
currentSpecs = manifest.Parse(releaseResponse.Release.Manifest, releaseResponse.Release.Namespace)
139+
newSpecs = manifest.Parse(upgradeResponse.Release.Manifest, upgradeResponse.Release.Namespace)
140140
}
141141

142142
diff.DiffManifests(currentSpecs, newSpecs, d.suppressedKinds, d.outputContext, os.Stdout)

manifest/parse.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ type metadata struct {
2222
ApiVersion string `yaml:"apiVersion"`
2323
Kind string
2424
Metadata struct {
25-
Name string
25+
Namespace string
26+
Name string
2627
}
2728
}
2829

2930
func (m metadata) String() string {
30-
return fmt.Sprintf("%s, %s (%s)", m.Metadata.Name, m.Kind, m.ApiVersion)
31+
return fmt.Sprintf("%s, %s, %s (%s)", m.Metadata.Namespace, m.Metadata.Name, m.Kind, m.ApiVersion)
3132
}
3233

3334
func scanYamlSpecs(data []byte, atEOF bool) (advance int, token []byte, err error) {
@@ -53,7 +54,7 @@ func splitSpec(token string) (string, string) {
5354
return "", ""
5455
}
5556

56-
func Parse(manifest string) map[string]*MappingResult {
57+
func Parse(manifest string, defaultNamespace string) map[string]*MappingResult {
5758
scanner := bufio.NewScanner(strings.NewReader(manifest))
5859
scanner.Split(scanYamlSpecs)
5960
//Allow for tokens (specs) up to 1M in size
@@ -72,6 +73,9 @@ func Parse(manifest string) map[string]*MappingResult {
7273
if err := yaml.Unmarshal([]byte(content), &metadata); err != nil {
7374
log.Fatalf("YAML unmarshal error: %s\nCan't unmarshal %s", err, content)
7475
}
76+
if metadata.Metadata.Namespace == "" {
77+
metadata.Metadata.Namespace = defaultNamespace
78+
}
7579
name := metadata.String()
7680
if _, ok := result[name]; ok {
7781
log.Printf("Error: Found duplicate key %#v in manifest", name)

0 commit comments

Comments
 (0)