kubernetes/migration: dont error out on no-op same-verison upgrades (#171)

* dont error out on no-op same-verison upgrades

* test case fixes
This commit is contained in:
Chris O'Haver 2019-05-20 11:22:18 -04:00 committed by GitHub
parent 9fd69a4c0b
commit 487cb8878d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 3 deletions

View file

@ -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

View file

@ -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},