mirror of
https://github.com/notherealmarco/coredns-deployment.git
synced 2025-05-05 12:32:34 +02:00
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:
parent
9fd69a4c0b
commit
487cb8878d
2 changed files with 57 additions and 3 deletions
|
@ -26,15 +26,18 @@ func Unsupported(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string) ([]No
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, status string) ([]Notice, error) {
|
func getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, status string) ([]Notice, error) {
|
||||||
notices := []Notice{}
|
if fromCoreDNSVersion == toCoreDNSVersion {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
err := validateVersions(fromCoreDNSVersion, toCoreDNSVersion)
|
err := validateVersions(fromCoreDNSVersion, toCoreDNSVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return notices, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cf, err := corefile.New(corefileStr)
|
cf, err := corefile.New(corefileStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return notices, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
notices := []Notice{}
|
||||||
v := fromCoreDNSVersion
|
v := fromCoreDNSVersion
|
||||||
for {
|
for {
|
||||||
v = Versions[v].nextVersion
|
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 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.
|
// 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) {
|
func Migrate(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string, deprecations bool) (string, error) {
|
||||||
|
if fromCoreDNSVersion == toCoreDNSVersion {
|
||||||
|
return corefileStr, nil
|
||||||
|
}
|
||||||
err := validateVersions(fromCoreDNSVersion, toCoreDNSVersion)
|
err := validateVersions(fromCoreDNSVersion, toCoreDNSVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
|
@ -184,6 +184,44 @@ mystub-2.example.org {
|
||||||
errors
|
errors
|
||||||
cache 30
|
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())
|
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) {
|
func TestUnsupported(t *testing.T) {
|
||||||
|
@ -377,6 +424,7 @@ func TestValidateVersions(t *testing.T) {
|
||||||
to string
|
to string
|
||||||
shouldErr bool
|
shouldErr bool
|
||||||
}{
|
}{
|
||||||
|
{"1.3.1", "1.3.1", true},
|
||||||
{"1.3.1", "1.5.0", false},
|
{"1.3.1", "1.5.0", false},
|
||||||
{"1.5.0", "1.3.1", true},
|
{"1.5.0", "1.3.1", true},
|
||||||
{"banana", "1.5.0", true},
|
{"banana", "1.5.0", true},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue