From 910ada176ebad3bb1e435bbaf5171a164f7a35d7 Mon Sep 17 00:00:00 2001 From: Chris O'Haver Date: Tue, 14 May 2019 09:59:18 -0400 Subject: [PATCH] k8s migration: include add notifications in deprecation result (#165) * fix * ensure newdefaults already present in corefile are not reported --- kubernetes/migration/migrate.go | 33 +++++++++++++++++++++++++--- kubernetes/migration/migrate_test.go | 7 +++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/kubernetes/migration/migrate.go b/kubernetes/migration/migrate.go index 54ca6b0..3700295 100644 --- a/kubernetes/migration/migrate.go +++ b/kubernetes/migration/migrate.go @@ -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 { diff --git a/kubernetes/migration/migrate_test.go b/kubernetes/migration/migrate_test.go index 3ef1bef..ec0bd60 100644 --- a/kubernetes/migration/migrate_test.go +++ b/kubernetes/migration/migrate_test.go @@ -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 {