diff --git a/kubernetes/migration/migrate.go b/kubernetes/migration/migrate.go index f20fd3e..9b11840 100644 --- a/kubernetes/migration/migrate.go +++ b/kubernetes/migration/migrate.go @@ -26,15 +26,18 @@ func Unsupported(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string) ([]No } func getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, status string) ([]Notice, error) { - notices := []Notice{} + if fromCoreDNSVersion == toCoreDNSVersion { + return nil, nil + } err := validateVersions(fromCoreDNSVersion, toCoreDNSVersion) if err != nil { - return notices, err + return nil, err } cf, err := corefile.New(corefileStr) if err != nil { - return notices, err + return nil, err } + notices := []Notice{} v := fromCoreDNSVersion for { v = Versions[v].nextVersion @@ -126,6 +129,9 @@ func getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, status string) // If deprecations is true, deprecated plugins/options will be migrated as soon as they are deprecated. // If deprecations is false, deprecated plugins/options will be migrated only once they become removed or ignored. func Migrate(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string, deprecations bool) (string, error) { + if fromCoreDNSVersion == toCoreDNSVersion { + return corefileStr, nil + } err := validateVersions(fromCoreDNSVersion, toCoreDNSVersion) if err != nil { return "", err diff --git a/kubernetes/migration/migrate_test.go b/kubernetes/migration/migrate_test.go index ec0bd60..f9b6cc9 100644 --- a/kubernetes/migration/migrate_test.go +++ b/kubernetes/migration/migrate_test.go @@ -184,6 +184,44 @@ mystub-2.example.org { errors cache 30 } +`, + }, + { + name: "no-op same version migration", + fromVersion: "1.3.1", + toVersion: "1.3.1", + deprecations: true, + startCorefile: `.:53 { + errors + health + kubernetes cluster.local in-addr.arpa ip6.arpa { + pods insecure + upstream + fallthrough in-addr.arpa ip6.arpa + } + prometheus :9153 + proxy . /etc/resolv.conf + cache 30 + loop + reload + loadbalance +} +`, + expectedCorefile: `.:53 { + errors + health + kubernetes cluster.local in-addr.arpa ip6.arpa { + pods insecure + upstream + fallthrough in-addr.arpa ip6.arpa + } + prometheus :9153 + proxy . /etc/resolv.conf + cache 30 + loop + reload + loadbalance +} `, }, } @@ -245,6 +283,15 @@ func TestDeprecated(t *testing.T) { t.Errorf("expected to get '%v'; got '%v'", dep.ToString(), result[i].ToString()) } } + + result, err = Deprecated("1.3.1", "1.3.1", startCorefile) + if err != nil { + t.Fatal(err) + } + expected = []Notice{} + if len(result) != len(expected) { + t.Fatalf("expected to find %v notifications in no-op upgrade; got %v", len(expected), len(result)) + } } func TestUnsupported(t *testing.T) { @@ -377,6 +424,7 @@ func TestValidateVersions(t *testing.T) { to string shouldErr bool }{ + {"1.3.1", "1.3.1", true}, {"1.3.1", "1.5.0", false}, {"1.5.0", "1.3.1", true}, {"banana", "1.5.0", true},