From f83a7a743bed582b0440ebaf182e5bbd0ed32c7d Mon Sep 17 00:00:00 2001 From: wawa0210 Date: Sat, 6 Jun 2020 17:31:04 +0800 Subject: [PATCH] update corefile-migration library to 1.0.8 --- go.mod | 4 +-- go.sum | 4 +-- .../migration/corefile/corefile.go | 22 +++++++++++-- .../corefile-migration/migration/migrate.go | 31 +++++++++++++------ vendor/modules.txt | 2 +- 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 9aedd33e64c..f52f8565406 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/codegangsta/negroni v1.0.0 // indirect github.com/container-storage-interface/spec v1.2.0 github.com/containernetworking/cni v0.7.1 - github.com/coredns/corefile-migration v1.0.6 + github.com/coredns/corefile-migration v1.0.8 github.com/coreos/go-oidc v2.1.0+incompatible github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f @@ -211,7 +211,7 @@ replace ( github.com/containerd/ttrpc => github.com/containerd/ttrpc v1.0.0 github.com/containerd/typeurl => github.com/containerd/typeurl v1.0.0 github.com/containernetworking/cni => github.com/containernetworking/cni v0.7.1 - github.com/coredns/corefile-migration => github.com/coredns/corefile-migration v1.0.6 + github.com/coredns/corefile-migration => github.com/coredns/corefile-migration v1.0.8 github.com/coreos/bbolt => github.com/coreos/bbolt v1.3.2 github.com/coreos/etcd => github.com/coreos/etcd v3.3.10+incompatible github.com/coreos/go-oidc => github.com/coreos/go-oidc v2.1.0+incompatible diff --git a/go.sum b/go.sum index a0dbcafb2a3..c9c9ce0bc36 100644 --- a/go.sum +++ b/go.sum @@ -108,8 +108,8 @@ github.com/containerd/typeurl v1.0.0 h1:7LMH7LfEmpWeCkGcIputvd4P0Rnd0LrIv1Jk2s5o github.com/containerd/typeurl v1.0.0/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= github.com/containernetworking/cni v0.7.1 h1:fE3r16wpSEyaqY4Z4oFrLMmIGfBYIKpPrHK31EJ9FzE= github.com/containernetworking/cni v0.7.1/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY= -github.com/coredns/corefile-migration v1.0.6 h1:hB6vclp2g/KeXe9n1oz/PafgieUahsOYeHMQA+RJ4Hg= -github.com/coredns/corefile-migration v1.0.6/go.mod h1:OFwBp/Wc9dJt5cAZzHWMNhK1r5L0p0jDwIBc6j8NC8E= +github.com/coredns/corefile-migration v1.0.8 h1:y/DSRGlmrLPTMUGWR81MgFC2ITLiaTGkbth0BqW3wvc= +github.com/coredns/corefile-migration v1.0.8/go.mod h1:OFwBp/Wc9dJt5cAZzHWMNhK1r5L0p0jDwIBc6j8NC8E= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible h1:jFneRYjIvLMLhDLCzuTuU4rSJUjRplcJQ7pD7MnhC04= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= diff --git a/vendor/github.com/coredns/corefile-migration/migration/corefile/corefile.go b/vendor/github.com/coredns/corefile-migration/migration/corefile/corefile.go index 9e6d8397b7d..3c66828d9ed 100644 --- a/vendor/github.com/coredns/corefile-migration/migration/corefile/corefile.go +++ b/vendor/github.com/coredns/corefile-migration/migration/corefile/corefile.go @@ -76,7 +76,7 @@ func (c *Corefile) ToString() (out string) { } func (s *Server) ToString() (out string) { - str := strings.Join(s.DomPorts, " ") + str := strings.Join(escapeArgs(s.DomPorts), " ") strs := []string{} for _, p := range s.Plugins { strs = append(strs, strings.Repeat(" ", indent)+p.ToString()) @@ -88,7 +88,7 @@ func (s *Server) ToString() (out string) { } func (p *Plugin) ToString() (out string) { - str := strings.Join(append([]string{p.Name}, p.Args...), " ") + str := strings.Join(append([]string{p.Name}, escapeArgs(p.Args)...), " ") strs := []string{} for _, o := range p.Options { strs = append(strs, strings.Repeat(" ", indent*2)+o.ToString()) @@ -100,10 +100,26 @@ func (p *Plugin) ToString() (out string) { } func (o *Option) ToString() (out string) { - str := strings.Join(append([]string{o.Name}, o.Args...), " ") + str := strings.Join(append([]string{o.Name}, escapeArgs(o.Args)...), " ") return str } +// escapeArgs returns the arguments list escaping and wrapping any argument containing whitespace in quotes +func escapeArgs(args []string) []string { + var escapedArgs []string + for _, a := range args { + // if there is white space, wrap argument with quotes + if len(strings.Fields(a)) > 1 { + // escape quotes + a = strings.Replace(a, "\"", "\\\"", -1) + // wrap with quotes + a = "\"" + a + "\"" + } + escapedArgs = append(escapedArgs, a) + } + return escapedArgs +} + func (s *Server) FindMatch(def []*Server) (*Server, bool) { NextServer: for _, sDef := range def { diff --git a/vendor/github.com/coredns/corefile-migration/migration/migrate.go b/vendor/github.com/coredns/corefile-migration/migration/migrate.go index e7a97a26916..ee5c5e081b2 100644 --- a/vendor/github.com/coredns/corefile-migration/migration/migrate.go +++ b/vendor/github.com/coredns/corefile-migration/migration/migrate.go @@ -6,6 +6,7 @@ package migration // helper functions that make this easier to implement. import ( + "errors" "fmt" "regexp" "sort" @@ -27,7 +28,7 @@ func Unsupported(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string) ([]No } func getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, status string) ([]Notice, error) { - err := validUpMigration(fromCoreDNSVersion, toCoreDNSVersion) + err := ValidUpMigration(fromCoreDNSVersion, toCoreDNSVersion) if err != nil { return nil, err } @@ -128,7 +129,7 @@ func Migrate(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string, deprecati if fromCoreDNSVersion == toCoreDNSVersion { return corefileStr, nil } - err := validUpMigration(fromCoreDNSVersion, toCoreDNSVersion) + err := ValidUpMigration(fromCoreDNSVersion, toCoreDNSVersion) if err != nil { return "", err } @@ -394,6 +395,16 @@ func Released(dockerImageSHA string) bool { return false } +// VersionFromSHA returns the version string matching the dockerImageSHA. +func VersionFromSHA(dockerImageSHA string) (string, error) { + for vStr, v := range Versions { + if v.dockerImageSHA == dockerImageSHA { + return vStr, nil + } + } + return "", errors.New("sha unsupported") +} + // ValidVersions returns a list of all versions defined func ValidVersions() []string { var vStrs []string @@ -404,14 +415,7 @@ func ValidVersions() []string { return vStrs } -func validateVersion(fromCoreDNSVersion string) error { - if _, ok := Versions[fromCoreDNSVersion]; !ok { - return fmt.Errorf("start version '%v' not supported", fromCoreDNSVersion) - } - return nil -} - -func validUpMigration(fromCoreDNSVersion, toCoreDNSVersion string) error { +func ValidUpMigration(fromCoreDNSVersion, toCoreDNSVersion string) error { err := validateVersion(fromCoreDNSVersion) if err != nil { @@ -429,6 +433,13 @@ func validUpMigration(fromCoreDNSVersion, toCoreDNSVersion string) error { return fmt.Errorf("cannot migrate up to '%v' from '%v'", toCoreDNSVersion, fromCoreDNSVersion) } +func validateVersion(fromCoreDNSVersion string) error { + if _, ok := Versions[fromCoreDNSVersion]; !ok { + return fmt.Errorf("start version '%v' not supported", fromCoreDNSVersion) + } + return nil +} + func validDownMigration(fromCoreDNSVersion, toCoreDNSVersion string) error { err := validateVersion(fromCoreDNSVersion) if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 0b6521d7a44..46425d41897 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -164,7 +164,7 @@ github.com/containernetworking/cni/pkg/types github.com/containernetworking/cni/pkg/types/020 github.com/containernetworking/cni/pkg/types/current github.com/containernetworking/cni/pkg/version -# github.com/coredns/corefile-migration v1.0.6 => github.com/coredns/corefile-migration v1.0.6 +# github.com/coredns/corefile-migration v1.0.8 => github.com/coredns/corefile-migration v1.0.8 github.com/coredns/corefile-migration/migration github.com/coredns/corefile-migration/migration/corefile # github.com/coreos/go-oidc v2.1.0+incompatible => github.com/coreos/go-oidc v2.1.0+incompatible