Skip to content

add namespace to deduplication tuple #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions cmd/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ func (d *revision) differentiate() error {
return prettyError(err)
}

diff.DiffManifests(manifest.Parse(revisionResponse.Release.Manifest), manifest.Parse(releaseResponse.Release.Manifest), d.suppressedKinds, d.outputContext, os.Stdout)
diff.DiffManifests(
manifest.Parse(revisionResponse.Release.Manifest, revisionResponse.Release.Namespace),
manifest.Parse(releaseResponse.Release.Manifest, releaseResponse.Release.Namespace),
d.suppressedKinds,
d.outputContext,
os.Stdout)

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

diff.DiffManifests(manifest.Parse(revisionResponse1.Release.Manifest), manifest.Parse(revisionResponse2.Release.Manifest), d.suppressedKinds, d.outputContext, os.Stdout)
diff.DiffManifests(
manifest.Parse(revisionResponse1.Release.Manifest, revisionResponse1.Release.Namespace),
manifest.Parse(revisionResponse2.Release.Manifest, revisionResponse2.Release.Namespace),
d.suppressedKinds,
d.outputContext,
os.Stdout)

default:
return errors.New("Invalid Arguments")
Expand Down
7 changes: 6 additions & 1 deletion cmd/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ func (d *rollback) backcast() error {
}

// create a diff between the current manifest and the version of the manifest that a user is intended to rollback
diff.DiffManifests(manifest.Parse(releaseResponse.Release.Manifest), manifest.Parse(revisionResponse.Release.Manifest), d.suppressedKinds, d.outputContext, os.Stdout)
diff.DiffManifests(
manifest.Parse(releaseResponse.Release.Manifest, releaseResponse.Release.Namespace),
manifest.Parse(revisionResponse.Release.Manifest, revisionResponse.Release.Namespace),
d.suppressedKinds,
d.outputContext,
os.Stdout)

return nil
}
6 changes: 3 additions & 3 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (d *diffCmd) run() error {
}

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

currentSpecs = manifest.Parse(releaseResponse.Release.Manifest)
newSpecs = manifest.Parse(upgradeResponse.Release.Manifest)
currentSpecs = manifest.Parse(releaseResponse.Release.Manifest, releaseResponse.Release.Namespace)
newSpecs = manifest.Parse(upgradeResponse.Release.Manifest, upgradeResponse.Release.Namespace)
}

diff.DiffManifests(currentSpecs, newSpecs, d.suppressedKinds, d.outputContext, os.Stdout)
Expand Down
10 changes: 7 additions & 3 deletions manifest/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ type metadata struct {
ApiVersion string `yaml:"apiVersion"`
Kind string
Metadata struct {
Name string
Namespace string
Name string
}
}

func (m metadata) String() string {
return fmt.Sprintf("%s, %s (%s)", m.Metadata.Name, m.Kind, m.ApiVersion)
return fmt.Sprintf("%s, %s, %s (%s)", m.Metadata.Namespace, m.Metadata.Name, m.Kind, m.ApiVersion)
}

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

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