Skip to content

Commit

Permalink
Fix the override logic from old to new to allow continuous mirroring. (
Browse files Browse the repository at this point in the history
  • Loading branch information
markusthoemmes committed Feb 3, 2020
1 parent 5200b03 commit a383cdc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Expand Up @@ -147,11 +147,16 @@ func (r *ReconcileKnativeServingObsolete) reconcileNewResource(old *obsolete.Kna
return nil, err
} else {
changed := false
if len(old.Spec.Config) > 0 && new.Spec.Config == nil {
new.Spec.Config = map[string]map[string]string{}
}
for cm, m := range old.Spec.Config {
if new.Spec.Config[cm] == nil {
new.Spec.Config[cm] = map[string]string{}
}
for k, v := range m {
x := common.Configure(new, cm, k, v)
if !changed {
changed = x
if oldV := new.Spec.Config[cm][k]; oldV != v {
changed = true
}
new.Spec.Config[cm][k] = v
}
Expand Down
Expand Up @@ -161,10 +161,31 @@ func TestKnativeServingMigrationMirrorsConfigDown(t *testing.T) {
}

// Update the config of the old resource and verify it's updated downstream.
old.Spec.Config["foo"]["bar"] = "baz3"
if err := cl.Update(ctx, old); err != nil {
t.Fatalf("Failed to update status initially: %v", err)
}

if _, err := r.Reconcile(reconcile.Request{NamespacedName: key}); err != nil {
t.Fatalf("Reconcile failed: %v", err)
}

// The new resource should be updated.
if err := cl.Get(ctx, key, created); err != nil {
t.Fatalf("Failed to get new object: %v", err)
}
if created.Spec.Config["foo"]["bar"] != "baz3" {
t.Fatalf("Spec.Config was not as expected: %v", created.Spec.Config)
}
// Verify the status didn't get thrown away.
if created.Status.Version != "v0.11.1" {
t.Fatalf("Spec.Status got thrown away unexpectedly")
}

// Add a new field upstream.
old.Spec.Config["foo2"] = map[string]string{
"bar2": "baz2",
}
old.Spec.Config["foo"]["bar"] = "baz3"
if err := cl.Update(ctx, old); err != nil {
t.Fatalf("Failed to update status initially: %v", err)
}
Expand All @@ -177,7 +198,7 @@ func TestKnativeServingMigrationMirrorsConfigDown(t *testing.T) {
if err := cl.Get(ctx, key, created); err != nil {
t.Fatalf("Failed to get new object: %v", err)
}
if created.Spec.Config["foo2"]["bar2"] != "baz2" || created.Spec.Config["foo"]["bar"] != "baz3" {
if created.Spec.Config["foo"]["bar"] != "baz3" || created.Spec.Config["foo2"]["bar2"] != "baz2" {
t.Fatalf("Spec.Config was not as expected: %v", created.Spec.Config)
}
// Verify the status didn't get thrown away.
Expand Down

0 comments on commit a383cdc

Please sign in to comment.