k8s migration: include add notifications in deprecation result (#165)

* fix

* ensure newdefaults already present in corefile are not reported
This commit is contained in:
Chris O'Haver 2019-05-14 09:59:18 -04:00 committed by GitHub
parent d7f87ddf2a
commit 910ada176e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 7 deletions

View file

@ -50,7 +50,7 @@ func getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, status string)
if !present {
continue
}
if vp.status != "" {
if vp.status != "" && vp.status != newdefault {
notices = append(notices, Notice{
Plugin: p.Name,
Severity: vp.status,
@ -79,11 +79,39 @@ func getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, status string)
if !present {
continue
}
if vo.status != "" {
if vo.status != "" && vo.status != newdefault {
notices = append(notices, Notice{Plugin: p.Name, Option: o.Name, Severity: vo.status, Version: v})
continue
}
}
if status != unsupported {
CheckForNewOptions:
for name, vo := range Versions[v].plugins[p.Name].options {
if vo.status != newdefault {
continue
}
for _, o := range p.Options {
if name == o.Name {
continue CheckForNewOptions
}
}
notices = append(notices, Notice{Plugin: p.Name, Option: name, Severity: newdefault, Version: v})
}
}
}
if status != unsupported {
CheckForNewPlugins:
for name, vp := range Versions[v].plugins {
if vp.status != newdefault {
continue
}
for _, p := range s.Plugins {
if name == p.Name {
continue CheckForNewPlugins
}
}
notices = append(notices, Notice{Plugin: name, Option: "", Severity: newdefault, Version: v})
}
}
}
if v == toCoreDNSVersion {
@ -94,7 +122,6 @@ func getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, status string)
}
// Migrate returns version of the Corefile migrated to toCoreDNSVersion, or an error if it cannot.
// TODO: add newdefault bool parameter?
func Migrate(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string, deprecations bool) (string, error) {
err := validateVersions(fromCoreDNSVersion, toCoreDNSVersion)
if err != nil {

View file

@ -208,7 +208,6 @@ func TestDeprecated(t *testing.T) {
startCorefile := `.:53 {
errors
health
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
upstream
@ -226,19 +225,19 @@ func TestDeprecated(t *testing.T) {
expected := []Notice{
{Plugin: "kubernetes", Option: "upstream", Severity: deprecated, Version: "1.4.0"},
{Plugin: "proxy", Severity: deprecated, ReplacedBy: "forward", Version: "1.4.0"},
{Plugin: "ready", Severity: newdefault, Version: "1.5.0"},
{Option: "upstream", Plugin: "kubernetes", Severity: ignored, Version: "1.5.0"},
{Plugin: "proxy", Severity: removed, ReplacedBy: "forward", Version: "1.5.0"},
{Plugin: "ready", Severity: newdefault, Version: "1.5.0"},
}
result, err := Deprecated("1.3.1", "1.5.0", startCorefile)
result, err := Deprecated("1.2.0", "1.5.0", startCorefile)
if err != nil {
t.Fatal(err)
}
if len(result) != len(expected) {
t.Fatalf("expected to find %v deprecations; got %v", len(expected), len(result))
t.Fatalf("expected to find %v notifications; got %v", len(expected), len(result))
}
for i, dep := range expected {