mirror of
https://github.com/notherealmarco/coredns-deployment.git
synced 2025-05-05 20:42:33 +02:00
Adding CLI for the migration tool (#154)
* Initial commit for the corefile-tool cli for the migration tool * cleanup implementation * nit * add fn to get corefile path * add released command and improve readme
This commit is contained in:
parent
631694b4e3
commit
37f5d0dad4
12 changed files with 495 additions and 3 deletions
52
kubernetes/corefile-tool/cmd/removed.go
Normal file
52
kubernetes/corefile-tool/cmd/removed.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coredns/deployment/kubernetes/migration"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// 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
|
||||
},
|
||||
|
||||
}
|
||||
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
|
||||
// that have been removed.
|
||||
func removedCorefileFromPath(fromCoreDNSVersion, toCoreDNSVersion, corefilePath string) ([]migration.Notice, error) {
|
||||
fileBytes, err := getCorefileFromPath(corefilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
corefileStr := string(fileBytes)
|
||||
return migration.Removed(fromCoreDNSVersion, toCoreDNSVersion, corefileStr)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue