From 70add17e0865a2ef8516697e5abd90aaa5d1b310 Mon Sep 17 00:00:00 2001 From: Sandeep Rajan Date: Thu, 18 Apr 2019 13:29:35 -0400 Subject: [PATCH 1/5] Initial commit for the corefile-tool cli for the migration tool --- kubernetes/corefile-tool/.gitignore | 3 + kubernetes/corefile-tool/README.md | 62 ++++++++++++++++++ kubernetes/corefile-tool/cmd/default.go | 54 ++++++++++++++++ kubernetes/corefile-tool/cmd/deprecated.go | 59 +++++++++++++++++ kubernetes/corefile-tool/cmd/migrate.go | 63 +++++++++++++++++++ kubernetes/corefile-tool/cmd/removed.go | 58 +++++++++++++++++ kubernetes/corefile-tool/cmd/root.go | 34 ++++++++++ kubernetes/corefile-tool/cmd/unsupported.go | 57 +++++++++++++++++ kubernetes/corefile-tool/cmd/validversions.go | 24 +++++++ kubernetes/corefile-tool/main.go | 7 +++ kubernetes/migration/migrate.go | 9 ++- 11 files changed, 427 insertions(+), 3 deletions(-) create mode 100644 kubernetes/corefile-tool/.gitignore create mode 100644 kubernetes/corefile-tool/README.md create mode 100644 kubernetes/corefile-tool/cmd/default.go create mode 100644 kubernetes/corefile-tool/cmd/deprecated.go create mode 100644 kubernetes/corefile-tool/cmd/migrate.go create mode 100644 kubernetes/corefile-tool/cmd/removed.go create mode 100644 kubernetes/corefile-tool/cmd/root.go create mode 100644 kubernetes/corefile-tool/cmd/unsupported.go create mode 100644 kubernetes/corefile-tool/cmd/validversions.go create mode 100644 kubernetes/corefile-tool/main.go diff --git a/kubernetes/corefile-tool/.gitignore b/kubernetes/corefile-tool/.gitignore new file mode 100644 index 0000000..adefe92 --- /dev/null +++ b/kubernetes/corefile-tool/.gitignore @@ -0,0 +1,3 @@ +Corefile +corefile-tool +*.yaml \ No newline at end of file diff --git a/kubernetes/corefile-tool/README.md b/kubernetes/corefile-tool/README.md new file mode 100644 index 0000000..9d488ac --- /dev/null +++ b/kubernetes/corefile-tool/README.md @@ -0,0 +1,62 @@ +## Corefile-tool + +Corefile-tool is a simple command line tool which helps you to evaluate and migrate your CoreDNS Corefile Configuration. +It is based on the [CoreDNS migration tool library](https://github.com/coredns/deployment/tree/master/kubernetes/migration). + +## Usage + +Use the following syntax to run the `corefile-tool` command: + +`corefile-tool [command] [flags]` + +where `command`, `flags` are: + +- `command`: The operation you want to perform. +- `flags` : Specifies flags required to carry out the operations. + + +### Operations + +The following operations are supported: +- `default`: Default returns true if the Corefile is the default for a that version of Kubernetes. +If the Kubernetes version is omitted, returns true if the Corefile is the default for any version. + +- `deprecated` : Deprecated returns a list of deprecated plugins or directives present in the Corefile. +- `migrate` : Migrate your CoreDNS corefile. +- `removed` : Removed returns a list of removed plugins or directives present in the Corefile. +- `unsupported` : Unsupported returns a list of plugins that are not recognized/supported by the migration tool (but may still be valid in CoreDNS). +- `validversions` : Shows valid versions of CoreDNS. + + +### Examples + +The following examples will help you understand the basic usage of the migration tool. + +```bash +# See if the Corefile is the default in CoreDNS v1.4.0. +corefile-tool default --k8sversion 1.4.0 --corefile /path/to/Corefile +``` + +```bash +# See deprecated plugins CoreDNS from v1.4.0 to v1.5.0. +corefile-tool deprecated --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile +``` + +```bash +# See unsupported plugins CoreDNS from v1.4.0 to v1.5.0. +corefile-tool unsupported --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile +``` + +```bash +# See removed plugins CoreDNS from v1.4.0 to v1.5.0. +corefile-tool removed --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile +``` + +```bash +# Migrate CoreDNS from v1.4.0 to v1.5.0 and handle deprecations . +corefile-tool migrate --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile --deprecations true + +# Migrate CoreDNS from v1.2.2 to v1.3.1 and do not handle deprecations . +corefile-tool migrate --from 1.2.2 --to 1.3.1 --corefile /path/to/Corefile --deprecations false +``` + diff --git a/kubernetes/corefile-tool/cmd/default.go b/kubernetes/corefile-tool/cmd/default.go new file mode 100644 index 0000000..ea97321 --- /dev/null +++ b/kubernetes/corefile-tool/cmd/default.go @@ -0,0 +1,54 @@ +package cmd + +import ( + "fmt" + "io/ioutil" + "os" + + "github.com/coredns/deployment/kubernetes/migration" + + "github.com/spf13/cobra" +) + +// defaultCmd represents the default command +var defaultCmd = &cobra.Command{ + Use: "default", + Short: "default returns true if the Corefile is the default for a that version of Kubernetes. If the Kubernetes version is omitted, returns true if the Corefile is the default for any version.", + Example: `# See if the Corefile is the default in CoreDNS v1.4.0. +corefile-tool default --k8sversion 1.4.0 --corefile /path/to/Corefile`, + RunE: func(cmd *cobra.Command, args []string) error { + k8sversion, _ := cmd.Flags().GetString("k8sversion") + corefile, _ := cmd.Flags().GetString("corefile") + + isDefault, err := defaultCorefileFromPath(k8sversion, corefile) + if err != nil { + return fmt.Errorf("error while checking if the Corefile is the default: %v \n", err) + } + fmt.Println(isDefault) + + return nil + }, +} + +func init() { + rootCmd.AddCommand(defaultCmd) + + defaultCmd.Flags().String("k8sversion", "", "The Kuberenetes version for which you are checking the default.") + defaultCmd.Flags().String("corefile", "", "Required: The path where your Corefile is located.") + defaultCmd.MarkFlagRequired("corefile") +} + +// defaultCorefileFromPath takes the path where the Corefile is located and checks +// if the Corefile is the default for a that version of Kubernetes. +func defaultCorefileFromPath(k8sVersion, corefilePath string) (bool, error) { + if _, err := os.Stat(corefilePath); os.IsNotExist(err) { + return false, err + } + + fileBytes, err := ioutil.ReadFile(corefilePath) + if err != nil { + return false, err + } + corefileStr := string(fileBytes) + return migration.Default(k8sVersion, corefileStr), nil +} diff --git a/kubernetes/corefile-tool/cmd/deprecated.go b/kubernetes/corefile-tool/cmd/deprecated.go new file mode 100644 index 0000000..535bc0c --- /dev/null +++ b/kubernetes/corefile-tool/cmd/deprecated.go @@ -0,0 +1,59 @@ +package cmd + +import ( + "fmt" + "io/ioutil" + "os" + + "github.com/coredns/deployment/kubernetes/migration" + + "github.com/spf13/cobra" +) + +// deprecatedCmd represents the deprecated command +var deprecatedCmd = &cobra.Command{ + Use: "deprecated", + Short: "Deprecated returns a list of deprecated plugins or directives present in the Corefile.", + Example: `# See deprecated plugins CoreDNS from v1.4.0 to v1.5.0. +corefile-tool deprecated --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile`, + RunE: func(cmd *cobra.Command, args []string) error { + from, _ := cmd.Flags().GetString("from") + to, _ := cmd.Flags().GetString("to") + corefile, _ := cmd.Flags().GetString("corefile") + deprecated, err := deprecatedCorefileFromPath(from, to, corefile) + if err != nil { + return fmt.Errorf("error while listing deprecated plugins: %v \n", err) + } + for _, dep := range deprecated { + fmt.Println(dep.ToString()) + } + return nil + }, +} + +func init() { + + rootCmd.AddCommand(deprecatedCmd) + + deprecatedCmd.Flags().String("from", "", "Required: The version you are migrating from. ") + deprecatedCmd.MarkFlagRequired("from") + deprecatedCmd.Flags().String("to", "", "Required: The version you are migrating to.") + deprecatedCmd.MarkFlagRequired("to") + deprecatedCmd.Flags().String("corefile", "", "Required: The path where your Corefile is located.") + deprecatedCmd.MarkFlagRequired("corefile") +} + +// deprecatedCorefileFromPath takes the path where the Corefile is located and returns the deprecated plugins or directives +// present in the Corefile. +func deprecatedCorefileFromPath(fromCoreDNSVersion, toCoreDNSVersion, corefilePath string) ([]migration.Notice, error) { + if _, err := os.Stat(corefilePath); os.IsNotExist(err) { + return nil, err + } + + fileBytes, err := ioutil.ReadFile(corefilePath) + if err != nil { + return nil, err + } + corefileStr := string(fileBytes) + return migration.Deprecated(fromCoreDNSVersion, toCoreDNSVersion, corefileStr) +} diff --git a/kubernetes/corefile-tool/cmd/migrate.go b/kubernetes/corefile-tool/cmd/migrate.go new file mode 100644 index 0000000..2213d23 --- /dev/null +++ b/kubernetes/corefile-tool/cmd/migrate.go @@ -0,0 +1,63 @@ +package cmd + +import ( + "fmt" + "io/ioutil" + "os" + + "github.com/coredns/deployment/kubernetes/migration" + + "github.com/spf13/cobra" +) + +// migrateCmd represents the migrate command +var migrateCmd = &cobra.Command{ + Use: "migrate", + Short: "Migrate your CoreDNS corefile", + Example: `# Migrate CoreDNS from v1.4.0 to v1.5.0 and handle deprecations . +corefile-tool migrate --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile --deprecations true + +# Migrate CoreDNS from v1.2.2 to v1.3.1 and do not handle deprecations . +corefile-tool migrate --from 1.2.2 --to 1.3.1 --corefile /path/to/Corefile --deprecations false`, + RunE: func(cmd *cobra.Command, args []string) error { + from, _ := cmd.Flags().GetString("from") + to, _ := cmd.Flags().GetString("to") + corefile, _ := cmd.Flags().GetString("corefile") + deprecations, _ := cmd.Flags().GetBool("deprecations") + + migrated, err := migrateCorefileFromPath(from, to, corefile, deprecations) + if err != nil { + return fmt.Errorf("error while migration: %v \n", err) + } + fmt.Println(migrated) + return nil + }, +} + +func init() { + rootCmd.AddCommand(migrateCmd) + + migrateCmd.Flags().String("from", "", "Required: The version you are migrating from. ") + migrateCmd.MarkFlagRequired("from") + migrateCmd.Flags().String("to", "", "Required: The version you are migrating to.") + migrateCmd.MarkFlagRequired("to") + migrateCmd.Flags().String("corefile", "", "Required: The path where your Corefile is located.") + migrateCmd.MarkFlagRequired("corefile") + migrateCmd.Flags().Bool("deprecations", false, "Required: Specify whether you want to handle plugin deprecations. [True | False] ") + migrateCmd.MarkFlagRequired("deprecations") +} + +// migrateCorefileFromPath takes the path where the Corefile is located and returns the deprecated plugins or directives +// present in the Corefile. +func migrateCorefileFromPath(fromCoreDNSVersion, toCoreDNSVersion, corefilePath string, deprecations bool) (string, error) { + if _, err := os.Stat(corefilePath); os.IsNotExist(err) { + return "", err + } + + fileBytes, err := ioutil.ReadFile(corefilePath) + if err != nil { + return "", err + } + corefileStr := string(fileBytes) + return migration.Migrate(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, deprecations) +} diff --git a/kubernetes/corefile-tool/cmd/removed.go b/kubernetes/corefile-tool/cmd/removed.go new file mode 100644 index 0000000..b1178f1 --- /dev/null +++ b/kubernetes/corefile-tool/cmd/removed.go @@ -0,0 +1,58 @@ +package cmd + +import ( + "fmt" + "io/ioutil" + "os" + + "github.com/coredns/deployment/kubernetes/migration" + + "github.com/spf13/cobra" +) + +// removedCmd represents the removed command +var removedCmd = &cobra.Command{ + Use: "removed", + Short: "Removed returns a list of removed plugins or directives present in the Corefile.", + Example: `# See removed plugins CoreDNS from v1.4.0 to v1.5.0. +corefile-tool removed --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile`, + RunE: func(cmd *cobra.Command, args []string) error { + from, _ := cmd.Flags().GetString("from") + to, _ := cmd.Flags().GetString("to") + corefile, _ := cmd.Flags().GetString("corefile") + removed, err := removedCorefileFromPath(from, to, corefile) + if err != nil { + return fmt.Errorf("error while listing deprecated plugins: %v \n", err) + } + for _, rem := range removed { + fmt.Println(rem.ToString()) + } + return nil + }, +} + +func init() { + rootCmd.AddCommand(removedCmd) + + removedCmd.Flags().String("from", "", "Required: The version you are migrating from. ") + removedCmd.MarkFlagRequired("from") + removedCmd.Flags().String("to", "", "Required: The version you are migrating to.") + removedCmd.MarkFlagRequired("to") + removedCmd.Flags().String("corefile", "", "Required: The path where your Corefile is located.") + removedCmd.MarkFlagRequired("corefile") +} + +// removedCorefileFromPath takes the path where the Corefile is located and returns the plugins or directives +// that have been removed. +func removedCorefileFromPath(fromCoreDNSVersion, toCoreDNSVersion, corefilePath string) ([]migration.Notice, error) { + if _, err := os.Stat(corefilePath); os.IsNotExist(err) { + return nil, err + } + + fileBytes, err := ioutil.ReadFile(corefilePath) + if err != nil { + return nil, err + } + corefileStr := string(fileBytes) + return migration.Removed(fromCoreDNSVersion, toCoreDNSVersion, corefileStr) +} diff --git a/kubernetes/corefile-tool/cmd/root.go b/kubernetes/corefile-tool/cmd/root.go new file mode 100644 index 0000000..7ebf69f --- /dev/null +++ b/kubernetes/corefile-tool/cmd/root.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/lithammer/dedent" + "github.com/spf13/cobra" +) + +// rootCmd represents the base command for the corefile-tool. +var rootCmd = &cobra.Command{ + Use: "corefile-tool", + Short: "A brief description of your application", + Long: dedent.Dedent(` + + ┌──────────────────────────────────────────────────────────┐ + │ CoreDNS Migration Tool │ + │ Easily Migrate your Corefile │ + │ │ + │ Please give us feedback at: │ + │ https://github.com/coredns/deployment/issues │ + └──────────────────────────────────────────────────────────┘ + + `), +} + +// Execute adds all child commands to the root command and sets flags appropriately. +func Execute() { + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/kubernetes/corefile-tool/cmd/unsupported.go b/kubernetes/corefile-tool/cmd/unsupported.go new file mode 100644 index 0000000..eb94e41 --- /dev/null +++ b/kubernetes/corefile-tool/cmd/unsupported.go @@ -0,0 +1,57 @@ +package cmd + +import ( + "fmt" + "github.com/coredns/deployment/kubernetes/migration" + "io/ioutil" + "os" + + "github.com/spf13/cobra" +) + +// unsupportedCmd represents the unsupported command +var unsupportedCmd = &cobra.Command{ + Use: "unsupported", + Short: "Unsupported returns a list of plugins that are not recognized/supported by the migration tool (but may still be valid in CoreDNS).", + Example: `# See unsupported plugins CoreDNS from v1.4.0 to v1.5.0. +corefile-tool unsupported --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile`, + RunE: func(cmd *cobra.Command, args []string) error { + from, _ := cmd.Flags().GetString("from") + to, _ := cmd.Flags().GetString("to") + corefile, _ := cmd.Flags().GetString("corefile") + unsupported, err := unsupportedCorefileFromPath(from, to, corefile) + if err != nil { + return fmt.Errorf("error while listing deprecated plugins: %v \n", err) + } + for _, unsup := range unsupported { + fmt.Println(unsup.ToString()) + } + return nil + }, +} + +func init() { + rootCmd.AddCommand(unsupportedCmd) + + unsupportedCmd.Flags().String("from", "", "Required: The version you are migrating from. ") + unsupportedCmd.MarkFlagRequired("from") + unsupportedCmd.Flags().String("to", "", "Required: The version you are migrating to.") + unsupportedCmd.MarkFlagRequired("to") + unsupportedCmd.Flags().String("corefile", "", "Required: The path where your Corefile is located.") + unsupportedCmd.MarkFlagRequired("corefile") +} + +// unsupportedCorefileFromPath takes the path where the Corefile is located and returns a list of plugins +// that have been removed. +func unsupportedCorefileFromPath(fromCoreDNSVersion, toCoreDNSVersion, corefilePath string) ([]migration.Notice, error) { + if _, err := os.Stat(corefilePath); os.IsNotExist(err) { + return nil, err + } + + fileBytes, err := ioutil.ReadFile(corefilePath) + if err != nil { + return nil, err + } + corefileStr := string(fileBytes) + return migration.Unsupported(fromCoreDNSVersion, toCoreDNSVersion, corefileStr) +} diff --git a/kubernetes/corefile-tool/cmd/validversions.go b/kubernetes/corefile-tool/cmd/validversions.go new file mode 100644 index 0000000..61b3720 --- /dev/null +++ b/kubernetes/corefile-tool/cmd/validversions.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "fmt" + "strings" + + "github.com/coredns/deployment/kubernetes/migration" + + "github.com/spf13/cobra" +) + +// validversionsCmd represents the validversions command +var validversionsCmd = &cobra.Command{ + Use: "validversions", + Short: "Shows valid versions of CoreDNS", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("The following are valid CoreDNS versions:") + fmt.Println(strings.Join(migration.ValidVersions(), ", ")) + }, +} + +func init() { + rootCmd.AddCommand(validversionsCmd) +} diff --git a/kubernetes/corefile-tool/main.go b/kubernetes/corefile-tool/main.go new file mode 100644 index 0000000..af58c90 --- /dev/null +++ b/kubernetes/corefile-tool/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/coredns/deployment/kubernetes/corefile-tool/cmd" + +func main() { + cmd.Execute() +} diff --git a/kubernetes/migration/migrate.go b/kubernetes/migration/migrate.go index 7459b72..6c59ce5 100644 --- a/kubernetes/migration/migrate.go +++ b/kubernetes/migration/migrate.go @@ -7,6 +7,8 @@ package migration import ( "fmt" + "sort" + "github.com/coredns/deployment/kubernetes/migration/corefile" ) @@ -243,9 +245,10 @@ func Released(dockerImageID string) bool { // ValidVersions returns a list of all versions defined func ValidVersions() []string { var vStrs []string - for vStr, _ := range Versions { + for vStr := range Versions { vStrs = append(vStrs, vStr) } + sort.Strings(vStrs) return vStrs } @@ -261,11 +264,11 @@ func validateVersions(fromCoreDNSVersion, toCoreDNSVersion string) error { if err != nil { return err } - for next := Versions[fromCoreDNSVersion].nextVersion; next != ""; next = Versions[next].nextVersion { + for next := Versions[fromCoreDNSVersion].nextVersion; next != ""; next = Versions[next].nextVersion { if next != toCoreDNSVersion { continue } return nil } return fmt.Errorf("cannot migrate to '%v' from '%v'", toCoreDNSVersion, fromCoreDNSVersion) -} \ No newline at end of file +} From f961ffff751c88a7d5ffab16e9f3645467bec61b Mon Sep 17 00:00:00 2001 From: Sandeep Rajan Date: Thu, 18 Apr 2019 16:01:09 -0400 Subject: [PATCH 2/5] cleanup implementation --- kubernetes/corefile-tool/cmd/default.go | 43 +++++++++-------- kubernetes/corefile-tool/cmd/deprecated.go | 46 +++++++++---------- kubernetes/corefile-tool/cmd/migrate.go | 43 +++++++++-------- kubernetes/corefile-tool/cmd/removed.go | 44 +++++++++--------- kubernetes/corefile-tool/cmd/root.go | 20 ++++++-- kubernetes/corefile-tool/cmd/unsupported.go | 42 ++++++++--------- kubernetes/corefile-tool/cmd/validversions.go | 23 +++++----- 7 files changed, 133 insertions(+), 128 deletions(-) diff --git a/kubernetes/corefile-tool/cmd/default.go b/kubernetes/corefile-tool/cmd/default.go index ea97321..a9d2173 100644 --- a/kubernetes/corefile-tool/cmd/default.go +++ b/kubernetes/corefile-tool/cmd/default.go @@ -10,32 +10,31 @@ import ( "github.com/spf13/cobra" ) -// defaultCmd represents the default command -var defaultCmd = &cobra.Command{ - Use: "default", - Short: "default returns true if the Corefile is the default for a that version of Kubernetes. If the Kubernetes version is omitted, returns true if the Corefile is the default for any version.", - Example: `# See if the Corefile is the default in CoreDNS v1.4.0. +// NewDefaultCmd represents the default command +func NewDefaultCmd() *cobra.Command { + defaultCmd := &cobra.Command{ + Use: "default", + Short: "default returns true if the Corefile is the default for a that version of Kubernetes. If the Kubernetes version is omitted, returns true if the Corefile is the default for any version.", + Example: `# See if the Corefile is the default in CoreDNS v1.4.0. corefile-tool default --k8sversion 1.4.0 --corefile /path/to/Corefile`, - RunE: func(cmd *cobra.Command, args []string) error { - k8sversion, _ := cmd.Flags().GetString("k8sversion") - corefile, _ := cmd.Flags().GetString("corefile") - - isDefault, err := defaultCorefileFromPath(k8sversion, corefile) - if err != nil { - return fmt.Errorf("error while checking if the Corefile is the default: %v \n", err) - } - fmt.Println(isDefault) - - return nil - }, -} - -func init() { - rootCmd.AddCommand(defaultCmd) - + RunE: func(cmd *cobra.Command, args []string) error { + k8sversion, _ := cmd.Flags().GetString("k8sversion") + corefile, _ := cmd.Flags().GetString("corefile") + + isDefault, err := defaultCorefileFromPath(k8sversion, corefile) + if err != nil { + return fmt.Errorf("error while checking if the Corefile is the default: %v \n", err) + } + fmt.Println(isDefault) + + return nil + }, + } defaultCmd.Flags().String("k8sversion", "", "The Kuberenetes version for which you are checking the default.") defaultCmd.Flags().String("corefile", "", "Required: The path where your Corefile is located.") defaultCmd.MarkFlagRequired("corefile") + + return defaultCmd } // defaultCorefileFromPath takes the path where the Corefile is located and checks diff --git a/kubernetes/corefile-tool/cmd/deprecated.go b/kubernetes/corefile-tool/cmd/deprecated.go index 535bc0c..3f03fd5 100644 --- a/kubernetes/corefile-tool/cmd/deprecated.go +++ b/kubernetes/corefile-tool/cmd/deprecated.go @@ -10,37 +10,35 @@ import ( "github.com/spf13/cobra" ) -// deprecatedCmd represents the deprecated command -var deprecatedCmd = &cobra.Command{ - Use: "deprecated", - Short: "Deprecated returns a list of deprecated plugins or directives present in the Corefile.", - Example: `# See deprecated plugins CoreDNS from v1.4.0 to v1.5.0. +// NewDeprecatedCmd represents the deprecated command +func NewDeprecatedCmd() *cobra.Command { + deprecatedCmd := &cobra.Command{ + Use: "deprecated", + Short: "Deprecated returns a list of deprecated plugins or directives present in the Corefile.", + Example: `# See deprecated plugins CoreDNS from v1.4.0 to v1.5.0. corefile-tool deprecated --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile`, - RunE: func(cmd *cobra.Command, args []string) error { - from, _ := cmd.Flags().GetString("from") - to, _ := cmd.Flags().GetString("to") - corefile, _ := cmd.Flags().GetString("corefile") - deprecated, err := deprecatedCorefileFromPath(from, to, corefile) - if err != nil { - return fmt.Errorf("error while listing deprecated plugins: %v \n", err) - } - for _, dep := range deprecated { - fmt.Println(dep.ToString()) - } - return nil - }, -} - -func init() { - - rootCmd.AddCommand(deprecatedCmd) - + RunE: func(cmd *cobra.Command, args []string) error { + from, _ := cmd.Flags().GetString("from") + to, _ := cmd.Flags().GetString("to") + corefile, _ := cmd.Flags().GetString("corefile") + deprecated, err := deprecatedCorefileFromPath(from, to, corefile) + if err != nil { + return fmt.Errorf("error while listing deprecated plugins: %v \n", err) + } + for _, dep := range deprecated { + fmt.Println(dep.ToString()) + } + return nil + }, + } deprecatedCmd.Flags().String("from", "", "Required: The version you are migrating from. ") deprecatedCmd.MarkFlagRequired("from") deprecatedCmd.Flags().String("to", "", "Required: The version you are migrating to.") deprecatedCmd.MarkFlagRequired("to") deprecatedCmd.Flags().String("corefile", "", "Required: The path where your Corefile is located.") deprecatedCmd.MarkFlagRequired("corefile") + + return deprecatedCmd } // deprecatedCorefileFromPath takes the path where the Corefile is located and returns the deprecated plugins or directives diff --git a/kubernetes/corefile-tool/cmd/migrate.go b/kubernetes/corefile-tool/cmd/migrate.go index 2213d23..83e0b40 100644 --- a/kubernetes/corefile-tool/cmd/migrate.go +++ b/kubernetes/corefile-tool/cmd/migrate.go @@ -11,32 +11,29 @@ import ( ) // migrateCmd represents the migrate command -var migrateCmd = &cobra.Command{ - Use: "migrate", - Short: "Migrate your CoreDNS corefile", - Example: `# Migrate CoreDNS from v1.4.0 to v1.5.0 and handle deprecations . +func NewMigrateCmd() *cobra.Command { + var migrateCmd = &cobra.Command{ + Use: "migrate", + Short: "Migrate your CoreDNS corefile", + Example: `# Migrate CoreDNS from v1.4.0 to v1.5.0 and handle deprecations . corefile-tool migrate --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile --deprecations true # Migrate CoreDNS from v1.2.2 to v1.3.1 and do not handle deprecations . corefile-tool migrate --from 1.2.2 --to 1.3.1 --corefile /path/to/Corefile --deprecations false`, - RunE: func(cmd *cobra.Command, args []string) error { - from, _ := cmd.Flags().GetString("from") - to, _ := cmd.Flags().GetString("to") - corefile, _ := cmd.Flags().GetString("corefile") - deprecations, _ := cmd.Flags().GetBool("deprecations") - - migrated, err := migrateCorefileFromPath(from, to, corefile, deprecations) - if err != nil { - return fmt.Errorf("error while migration: %v \n", err) - } - fmt.Println(migrated) - return nil - }, -} - -func init() { - rootCmd.AddCommand(migrateCmd) - + RunE: func(cmd *cobra.Command, args []string) error { + from, _ := cmd.Flags().GetString("from") + to, _ := cmd.Flags().GetString("to") + corefile, _ := cmd.Flags().GetString("corefile") + deprecations, _ := cmd.Flags().GetBool("deprecations") + + migrated, err := migrateCorefileFromPath(from, to, corefile, deprecations) + if err != nil { + return fmt.Errorf("error while migration: %v \n", err) + } + fmt.Println(migrated) + return nil + }, + } migrateCmd.Flags().String("from", "", "Required: The version you are migrating from. ") migrateCmd.MarkFlagRequired("from") migrateCmd.Flags().String("to", "", "Required: The version you are migrating to.") @@ -45,6 +42,8 @@ func init() { migrateCmd.MarkFlagRequired("corefile") migrateCmd.Flags().Bool("deprecations", false, "Required: Specify whether you want to handle plugin deprecations. [True | False] ") migrateCmd.MarkFlagRequired("deprecations") + + return migrateCmd } // migrateCorefileFromPath takes the path where the Corefile is located and returns the deprecated plugins or directives diff --git a/kubernetes/corefile-tool/cmd/removed.go b/kubernetes/corefile-tool/cmd/removed.go index b1178f1..d77efc8 100644 --- a/kubernetes/corefile-tool/cmd/removed.go +++ b/kubernetes/corefile-tool/cmd/removed.go @@ -10,36 +10,36 @@ import ( "github.com/spf13/cobra" ) -// removedCmd represents the removed command -var removedCmd = &cobra.Command{ - Use: "removed", - Short: "Removed returns a list of removed plugins or directives present in the Corefile.", - Example: `# See removed plugins CoreDNS from v1.4.0 to v1.5.0. +// NewRemovedCmd represents the removed command +func NewRemovedCmd() *cobra.Command { + removedCmd := &cobra.Command{ + Use: "removed", + Short: "Removed returns a list of removed plugins or directives present in the Corefile.", + Example: `# See removed plugins CoreDNS from v1.4.0 to v1.5.0. corefile-tool removed --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile`, - RunE: func(cmd *cobra.Command, args []string) error { - from, _ := cmd.Flags().GetString("from") - to, _ := cmd.Flags().GetString("to") - corefile, _ := cmd.Flags().GetString("corefile") - removed, err := removedCorefileFromPath(from, to, corefile) - if err != nil { - return fmt.Errorf("error while listing deprecated plugins: %v \n", err) - } - for _, rem := range removed { - fmt.Println(rem.ToString()) - } - return nil - }, -} - -func init() { - rootCmd.AddCommand(removedCmd) + RunE: func(cmd *cobra.Command, args []string) error { + from, _ := cmd.Flags().GetString("from") + to, _ := cmd.Flags().GetString("to") + corefile, _ := cmd.Flags().GetString("corefile") + removed, err := removedCorefileFromPath(from, to, corefile) + if err != nil { + return fmt.Errorf("error while listing deprecated plugins: %v \n", err) + } + for _, rem := range removed { + fmt.Println(rem.ToString()) + } + return nil + }, + } removedCmd.Flags().String("from", "", "Required: The version you are migrating from. ") removedCmd.MarkFlagRequired("from") removedCmd.Flags().String("to", "", "Required: The version you are migrating to.") removedCmd.MarkFlagRequired("to") removedCmd.Flags().String("corefile", "", "Required: The path where your Corefile is located.") removedCmd.MarkFlagRequired("corefile") + + return removedCmd } // removedCorefileFromPath takes the path where the Corefile is located and returns the plugins or directives diff --git a/kubernetes/corefile-tool/cmd/root.go b/kubernetes/corefile-tool/cmd/root.go index 7ebf69f..2c85b28 100644 --- a/kubernetes/corefile-tool/cmd/root.go +++ b/kubernetes/corefile-tool/cmd/root.go @@ -9,10 +9,11 @@ import ( ) // rootCmd represents the base command for the corefile-tool. -var rootCmd = &cobra.Command{ - Use: "corefile-tool", - Short: "A brief description of your application", - Long: dedent.Dedent(` +func CorefileTool() *cobra.Command { + rootCmd := &cobra.Command{ + Use: "corefile-tool", + Short: "A brief description of your application", + Long: dedent.Dedent(` ┌──────────────────────────────────────────────────────────┐ │ CoreDNS Migration Tool │ @@ -23,11 +24,20 @@ var rootCmd = &cobra.Command{ └──────────────────────────────────────────────────────────┘ `), + } + rootCmd.AddCommand(NewRemovedCmd()) + rootCmd.AddCommand(NewMigrateCmd()) + rootCmd.AddCommand(NewDefaultCmd()) + rootCmd.AddCommand(NewDeprecatedCmd()) + rootCmd.AddCommand(NewUnsupportedCmd()) + rootCmd.AddCommand(NewValidVersionsCmd()) + + return rootCmd } // Execute adds all child commands to the root command and sets flags appropriately. func Execute() { - if err := rootCmd.Execute(); err != nil { + if err := CorefileTool().Execute(); err != nil { fmt.Println(err) os.Exit(1) } diff --git a/kubernetes/corefile-tool/cmd/unsupported.go b/kubernetes/corefile-tool/cmd/unsupported.go index eb94e41..39d8204 100644 --- a/kubernetes/corefile-tool/cmd/unsupported.go +++ b/kubernetes/corefile-tool/cmd/unsupported.go @@ -10,28 +10,26 @@ import ( ) // unsupportedCmd represents the unsupported command -var unsupportedCmd = &cobra.Command{ - Use: "unsupported", - Short: "Unsupported returns a list of plugins that are not recognized/supported by the migration tool (but may still be valid in CoreDNS).", - Example: `# See unsupported plugins CoreDNS from v1.4.0 to v1.5.0. +func NewUnsupportedCmd() *cobra.Command { + unsupportedCmd := &cobra.Command{ + Use: "unsupported", + Short: "Unsupported returns a list of plugins that are not recognized/supported by the migration tool (but may still be valid in CoreDNS).", + Example: `# See unsupported plugins CoreDNS from v1.4.0 to v1.5.0. corefile-tool unsupported --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile`, - RunE: func(cmd *cobra.Command, args []string) error { - from, _ := cmd.Flags().GetString("from") - to, _ := cmd.Flags().GetString("to") - corefile, _ := cmd.Flags().GetString("corefile") - unsupported, err := unsupportedCorefileFromPath(from, to, corefile) - if err != nil { - return fmt.Errorf("error while listing deprecated plugins: %v \n", err) - } - for _, unsup := range unsupported { - fmt.Println(unsup.ToString()) - } - return nil - }, -} - -func init() { - rootCmd.AddCommand(unsupportedCmd) + RunE: func(cmd *cobra.Command, args []string) error { + from, _ := cmd.Flags().GetString("from") + to, _ := cmd.Flags().GetString("to") + corefile, _ := cmd.Flags().GetString("corefile") + unsupported, err := unsupportedCorefileFromPath(from, to, corefile) + if err != nil { + return fmt.Errorf("error while listing deprecated plugins: %v \n", err) + } + for _, unsup := range unsupported { + fmt.Println(unsup.ToString()) + } + return nil + }, + } unsupportedCmd.Flags().String("from", "", "Required: The version you are migrating from. ") unsupportedCmd.MarkFlagRequired("from") @@ -39,6 +37,8 @@ func init() { unsupportedCmd.MarkFlagRequired("to") unsupportedCmd.Flags().String("corefile", "", "Required: The path where your Corefile is located.") unsupportedCmd.MarkFlagRequired("corefile") + + return unsupportedCmd } // unsupportedCorefileFromPath takes the path where the Corefile is located and returns a list of plugins diff --git a/kubernetes/corefile-tool/cmd/validversions.go b/kubernetes/corefile-tool/cmd/validversions.go index 61b3720..e411d8c 100644 --- a/kubernetes/corefile-tool/cmd/validversions.go +++ b/kubernetes/corefile-tool/cmd/validversions.go @@ -9,16 +9,15 @@ import ( "github.com/spf13/cobra" ) -// validversionsCmd represents the validversions command -var validversionsCmd = &cobra.Command{ - Use: "validversions", - Short: "Shows valid versions of CoreDNS", - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("The following are valid CoreDNS versions:") - fmt.Println(strings.Join(migration.ValidVersions(), ", ")) - }, -} - -func init() { - rootCmd.AddCommand(validversionsCmd) +// NewValidVersionsCmd represents the validversions command +func NewValidVersionsCmd() *cobra.Command { + validversionsCmd := &cobra.Command{ + Use: "validversions", + Short: "Shows valid versions of CoreDNS", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("The following are valid CoreDNS versions:") + fmt.Println(strings.Join(migration.ValidVersions(), ", ")) + }, + } + return validversionsCmd } From 2d739f10a54653a1b177da9f9466be1d1c893b50 Mon Sep 17 00:00:00 2001 From: Sandeep Rajan Date: Thu, 18 Apr 2019 16:02:48 -0400 Subject: [PATCH 3/5] nit --- kubernetes/corefile-tool/cmd/migrate.go | 2 +- kubernetes/corefile-tool/cmd/root.go | 2 +- kubernetes/corefile-tool/cmd/unsupported.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kubernetes/corefile-tool/cmd/migrate.go b/kubernetes/corefile-tool/cmd/migrate.go index 83e0b40..2f09f28 100644 --- a/kubernetes/corefile-tool/cmd/migrate.go +++ b/kubernetes/corefile-tool/cmd/migrate.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -// migrateCmd represents the migrate command +// NewMigrateCmd represents the migrate command func NewMigrateCmd() *cobra.Command { var migrateCmd = &cobra.Command{ Use: "migrate", diff --git a/kubernetes/corefile-tool/cmd/root.go b/kubernetes/corefile-tool/cmd/root.go index 2c85b28..f6cc268 100644 --- a/kubernetes/corefile-tool/cmd/root.go +++ b/kubernetes/corefile-tool/cmd/root.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" ) -// rootCmd represents the base command for the corefile-tool. +// CorefileTool represents the base command for the corefile-tool. func CorefileTool() *cobra.Command { rootCmd := &cobra.Command{ Use: "corefile-tool", diff --git a/kubernetes/corefile-tool/cmd/unsupported.go b/kubernetes/corefile-tool/cmd/unsupported.go index 39d8204..ccd60d2 100644 --- a/kubernetes/corefile-tool/cmd/unsupported.go +++ b/kubernetes/corefile-tool/cmd/unsupported.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" ) -// unsupportedCmd represents the unsupported command +// NewUnsupportedCmd represents the unsupported command func NewUnsupportedCmd() *cobra.Command { unsupportedCmd := &cobra.Command{ Use: "unsupported", From d7c652ee2d562ff110ccd4c73eca915557b75269 Mon Sep 17 00:00:00 2001 From: Sandeep Rajan Date: Tue, 23 Apr 2019 10:50:42 -0400 Subject: [PATCH 4/5] add fn to get corefile path --- kubernetes/corefile-tool/.gitignore | 2 +- kubernetes/corefile-tool/cmd/default.go | 10 ++-------- kubernetes/corefile-tool/cmd/deprecated.go | 8 +------- kubernetes/corefile-tool/cmd/migrate.go | 8 +------- kubernetes/corefile-tool/cmd/removed.go | 8 +------- kubernetes/corefile-tool/cmd/root.go | 14 ++++++++++++++ kubernetes/corefile-tool/cmd/unsupported.go | 9 ++------- 7 files changed, 22 insertions(+), 37 deletions(-) diff --git a/kubernetes/corefile-tool/.gitignore b/kubernetes/corefile-tool/.gitignore index adefe92..50d0b69 100644 --- a/kubernetes/corefile-tool/.gitignore +++ b/kubernetes/corefile-tool/.gitignore @@ -1,3 +1,3 @@ Corefile corefile-tool -*.yaml \ No newline at end of file +*.yaml diff --git a/kubernetes/corefile-tool/cmd/default.go b/kubernetes/corefile-tool/cmd/default.go index a9d2173..da20ec4 100644 --- a/kubernetes/corefile-tool/cmd/default.go +++ b/kubernetes/corefile-tool/cmd/default.go @@ -2,8 +2,6 @@ package cmd import ( "fmt" - "io/ioutil" - "os" "github.com/coredns/deployment/kubernetes/migration" @@ -38,13 +36,9 @@ corefile-tool default --k8sversion 1.4.0 --corefile /path/to/Corefile`, } // defaultCorefileFromPath takes the path where the Corefile is located and checks -// if the Corefile is the default for a that version of Kubernetes. +// if the Corefile is the default for that version of Kubernetes. func defaultCorefileFromPath(k8sVersion, corefilePath string) (bool, error) { - if _, err := os.Stat(corefilePath); os.IsNotExist(err) { - return false, err - } - - fileBytes, err := ioutil.ReadFile(corefilePath) + fileBytes, err := getCorefileFromPath(corefilePath) if err != nil { return false, err } diff --git a/kubernetes/corefile-tool/cmd/deprecated.go b/kubernetes/corefile-tool/cmd/deprecated.go index 3f03fd5..00a59e3 100644 --- a/kubernetes/corefile-tool/cmd/deprecated.go +++ b/kubernetes/corefile-tool/cmd/deprecated.go @@ -2,8 +2,6 @@ package cmd import ( "fmt" - "io/ioutil" - "os" "github.com/coredns/deployment/kubernetes/migration" @@ -44,11 +42,7 @@ corefile-tool deprecated --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile`, // deprecatedCorefileFromPath takes the path where the Corefile is located and returns the deprecated plugins or directives // present in the Corefile. func deprecatedCorefileFromPath(fromCoreDNSVersion, toCoreDNSVersion, corefilePath string) ([]migration.Notice, error) { - if _, err := os.Stat(corefilePath); os.IsNotExist(err) { - return nil, err - } - - fileBytes, err := ioutil.ReadFile(corefilePath) + fileBytes, err := getCorefileFromPath(corefilePath) if err != nil { return nil, err } diff --git a/kubernetes/corefile-tool/cmd/migrate.go b/kubernetes/corefile-tool/cmd/migrate.go index 2f09f28..eeba020 100644 --- a/kubernetes/corefile-tool/cmd/migrate.go +++ b/kubernetes/corefile-tool/cmd/migrate.go @@ -2,8 +2,6 @@ package cmd import ( "fmt" - "io/ioutil" - "os" "github.com/coredns/deployment/kubernetes/migration" @@ -49,11 +47,7 @@ corefile-tool migrate --from 1.2.2 --to 1.3.1 --corefile /path/to/Corefile --de // migrateCorefileFromPath takes the path where the Corefile is located and returns the deprecated plugins or directives // present in the Corefile. func migrateCorefileFromPath(fromCoreDNSVersion, toCoreDNSVersion, corefilePath string, deprecations bool) (string, error) { - if _, err := os.Stat(corefilePath); os.IsNotExist(err) { - return "", err - } - - fileBytes, err := ioutil.ReadFile(corefilePath) + fileBytes, err := getCorefileFromPath(corefilePath) if err != nil { return "", err } diff --git a/kubernetes/corefile-tool/cmd/removed.go b/kubernetes/corefile-tool/cmd/removed.go index d77efc8..ab19c37 100644 --- a/kubernetes/corefile-tool/cmd/removed.go +++ b/kubernetes/corefile-tool/cmd/removed.go @@ -2,8 +2,6 @@ package cmd import ( "fmt" - "io/ioutil" - "os" "github.com/coredns/deployment/kubernetes/migration" @@ -45,11 +43,7 @@ corefile-tool removed --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile`, // removedCorefileFromPath takes the path where the Corefile is located and returns the plugins or directives // that have been removed. func removedCorefileFromPath(fromCoreDNSVersion, toCoreDNSVersion, corefilePath string) ([]migration.Notice, error) { - if _, err := os.Stat(corefilePath); os.IsNotExist(err) { - return nil, err - } - - fileBytes, err := ioutil.ReadFile(corefilePath) + fileBytes, err := getCorefileFromPath(corefilePath) if err != nil { return nil, err } diff --git a/kubernetes/corefile-tool/cmd/root.go b/kubernetes/corefile-tool/cmd/root.go index f6cc268..cd884f4 100644 --- a/kubernetes/corefile-tool/cmd/root.go +++ b/kubernetes/corefile-tool/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "io/ioutil" "os" "github.com/lithammer/dedent" @@ -42,3 +43,16 @@ func Execute() { os.Exit(1) } } + +func getCorefileFromPath(corefilePath string) ([]byte, error) { + if _, err := os.Stat(corefilePath); os.IsNotExist(err) { + return nil, err + } + + fileBytes, err := ioutil.ReadFile(corefilePath) + if err != nil { + return nil, err + } + + return fileBytes, nil +} diff --git a/kubernetes/corefile-tool/cmd/unsupported.go b/kubernetes/corefile-tool/cmd/unsupported.go index ccd60d2..f82fbe6 100644 --- a/kubernetes/corefile-tool/cmd/unsupported.go +++ b/kubernetes/corefile-tool/cmd/unsupported.go @@ -2,9 +2,8 @@ package cmd import ( "fmt" + "github.com/coredns/deployment/kubernetes/migration" - "io/ioutil" - "os" "github.com/spf13/cobra" ) @@ -44,11 +43,7 @@ corefile-tool unsupported --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile`, // unsupportedCorefileFromPath takes the path where the Corefile is located and returns a list of plugins // that have been removed. func unsupportedCorefileFromPath(fromCoreDNSVersion, toCoreDNSVersion, corefilePath string) ([]migration.Notice, error) { - if _, err := os.Stat(corefilePath); os.IsNotExist(err) { - return nil, err - } - - fileBytes, err := ioutil.ReadFile(corefilePath) + fileBytes, err := getCorefileFromPath(corefilePath) if err != nil { return nil, err } From 54235738e77883ec23918d3a8e5f0f3930f91135 Mon Sep 17 00:00:00 2001 From: Sandeep Rajan Date: Wed, 24 Apr 2019 11:16:26 -0400 Subject: [PATCH 5/5] add released command and improve readme --- kubernetes/corefile-tool/README.md | 51 ++++++++++++++++++++++-- kubernetes/corefile-tool/cmd/default.go | 2 +- kubernetes/corefile-tool/cmd/released.go | 32 +++++++++++++++ kubernetes/corefile-tool/cmd/root.go | 1 + 4 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 kubernetes/corefile-tool/cmd/released.go diff --git a/kubernetes/corefile-tool/README.md b/kubernetes/corefile-tool/README.md index 9d488ac..d93dd4c 100644 --- a/kubernetes/corefile-tool/README.md +++ b/kubernetes/corefile-tool/README.md @@ -17,14 +17,57 @@ where `command`, `flags` are: ### Operations -The following operations are supported: +The following commands are supported: + - `default`: Default returns true if the Corefile is the default for a that version of Kubernetes. If the Kubernetes version is omitted, returns true if the Corefile is the default for any version. + The following flags are accepted by the `default` command: + + - `k8sversion`: The Kubernetes version for which you are checking the default. + If the Kubernetes version is omitted, returns true if the Corefile is the default for any version. + - `corefile` : The path where your Corefile is located. This flag is mandatory. + - `deprecated` : Deprecated returns a list of deprecated plugins or directives present in the Corefile. + + The following flags are accepted and mandatory for the `deprecated` command: + + - `from`: The CoreDNS version you are migrating from. + - `to` : The CoreDNS version you are migrating to. + - `corefile` : The path where your Corefile is located. + - `migrate` : Migrate your CoreDNS corefile. + + The following flags are accepted and mandatory for the `migrate` command: + + - `from` : The CoreDNS version you are migrating from. + - `to` : The CoreDNS version you are migrating to. This flag is mandatory. + - `corefile` : The path where your Corefile is located. This flag is mandatory. + - `deprecations`: Specify whether you want to migrate all the deprecations that are present in the current Corefile. + Specifying `false` will result in the `migrate` command not migrating the deprecated plugins present in the Corefile. + +- `released` : Released determines whether your Docker Image ID of a CoreDNS release is valid or not. + + The following flags are accepted and mandatory for the `released` command: + + - `dockerImageID` : The docker image ID you want to check. + - `removed` : Removed returns a list of removed plugins or directives present in the Corefile. + + The following flags are accepted and mandatory for the `removed` command: + + - `from` : The CoreDNS version you are migrating from. + - `to` : The CoreDNS version you are migrating to. This flag is mandatory. + - `corefile` : The path where your Corefile is located. This flag is mandatory. + - `unsupported` : Unsupported returns a list of plugins that are not recognized/supported by the migration tool (but may still be valid in CoreDNS). + + The following flags are accepted and mandatory for the `unsupported` command: + + - `from` : The CoreDNS version you are migrating from. + - `to` : The CoreDNS version you are migrating to. This flag is mandatory. + - `corefile` : The path where your Corefile is located. This flag is mandatory. + - `validversions` : Shows valid versions of CoreDNS. @@ -53,10 +96,12 @@ corefile-tool removed --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile ``` ```bash -# Migrate CoreDNS from v1.4.0 to v1.5.0 and handle deprecations . +# Migrate CoreDNS from v1.4.0 to v1.5.0 and also migrate all the deprecations +# that are present in the current Corefile. corefile-tool migrate --from 1.4.0 --to 1.5.0 --corefile /path/to/Corefile --deprecations true -# Migrate CoreDNS from v1.2.2 to v1.3.1 and do not handle deprecations . +# Migrate CoreDNS from v1.2.2 to v1.3.1 and do not also migrate all the deprecations +# that are present in the current Corefile. corefile-tool migrate --from 1.2.2 --to 1.3.1 --corefile /path/to/Corefile --deprecations false ``` diff --git a/kubernetes/corefile-tool/cmd/default.go b/kubernetes/corefile-tool/cmd/default.go index da20ec4..c719ac7 100644 --- a/kubernetes/corefile-tool/cmd/default.go +++ b/kubernetes/corefile-tool/cmd/default.go @@ -28,7 +28,7 @@ corefile-tool default --k8sversion 1.4.0 --corefile /path/to/Corefile`, return nil }, } - defaultCmd.Flags().String("k8sversion", "", "The Kuberenetes version for which you are checking the default.") + defaultCmd.Flags().String("k8sversion", "", "The Kubernetes version for which you are checking the default.") defaultCmd.Flags().String("corefile", "", "Required: The path where your Corefile is located.") defaultCmd.MarkFlagRequired("corefile") diff --git a/kubernetes/corefile-tool/cmd/released.go b/kubernetes/corefile-tool/cmd/released.go new file mode 100644 index 0000000..d8db04c --- /dev/null +++ b/kubernetes/corefile-tool/cmd/released.go @@ -0,0 +1,32 @@ +package cmd + +import ( + "fmt" + + "github.com/coredns/deployment/kubernetes/migration" + + "github.com/spf13/cobra" +) + +// NewReleasedCmd represents the released command +func NewReleasedCmd() *cobra.Command { + releasedCmd := &cobra.Command{ + Use: "released", + Short: "Determines whether your Docker Image ID of a CoreDNS release is valid or not", + Run: func(cmd *cobra.Command, args []string) { + image, _ := cmd.Flags().GetString("dockerImageID") + result := migration.Released(image) + + if result { + fmt.Println("The docker image ID is valid") + } else { + fmt.Println("The docker image ID is invalid") + } + }, + } + + releasedCmd.Flags().String("dockerImageID", "", "Required: The docker image ID you want to check. ") + releasedCmd.MarkFlagRequired("dockerImageID") + + return releasedCmd +} diff --git a/kubernetes/corefile-tool/cmd/root.go b/kubernetes/corefile-tool/cmd/root.go index cd884f4..64dbb04 100644 --- a/kubernetes/corefile-tool/cmd/root.go +++ b/kubernetes/corefile-tool/cmd/root.go @@ -32,6 +32,7 @@ func CorefileTool() *cobra.Command { rootCmd.AddCommand(NewDeprecatedCmd()) rootCmd.AddCommand(NewUnsupportedCmd()) rootCmd.AddCommand(NewValidVersionsCmd()) + rootCmd.AddCommand(NewReleasedCmd()) return rootCmd }