update dependencies
This commit is contained in:
201
vendor/github.com/coredns/corefile-migration/LICENSE
generated
vendored
Normal file
201
vendor/github.com/coredns/corefile-migration/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
31
vendor/github.com/coredns/corefile-migration/migration/BUILD
generated
vendored
Normal file
31
vendor/github.com/coredns/corefile-migration/migration/BUILD
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"migrate.go",
|
||||
"notice.go",
|
||||
"versions.go",
|
||||
],
|
||||
importmap = "k8s.io/kubernetes/vendor/github.com/coredns/corefile-migration/migration",
|
||||
importpath = "github.com/coredns/corefile-migration/migration",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//vendor/github.com/coredns/corefile-migration/migration/corefile:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//vendor/github.com/coredns/corefile-migration/migration/corefile:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
24
vendor/github.com/coredns/corefile-migration/migration/corefile/BUILD
generated
vendored
Normal file
24
vendor/github.com/coredns/corefile-migration/migration/corefile/BUILD
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["corefile.go"],
|
||||
importmap = "k8s.io/kubernetes/vendor/github.com/coredns/corefile-migration/migration/corefile",
|
||||
importpath = "github.com/coredns/corefile-migration/migration/corefile",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//vendor/github.com/caddyserver/caddy/caddyfile:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
179
vendor/github.com/coredns/corefile-migration/migration/corefile/corefile.go
generated
vendored
Normal file
179
vendor/github.com/coredns/corefile-migration/migration/corefile/corefile.go
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
package corefile
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/caddyserver/caddy/caddyfile"
|
||||
)
|
||||
|
||||
type Corefile struct {
|
||||
Servers []*Server
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
DomPorts []string
|
||||
Plugins []*Plugin
|
||||
}
|
||||
|
||||
type Plugin struct {
|
||||
Name string
|
||||
Args []string
|
||||
Options []*Option
|
||||
}
|
||||
|
||||
type Option struct {
|
||||
Name string
|
||||
Args []string
|
||||
}
|
||||
|
||||
func New(s string) (*Corefile, error) {
|
||||
c := Corefile{}
|
||||
cc := caddyfile.NewDispenser("migration", strings.NewReader(s))
|
||||
depth := 0
|
||||
var cSvr *Server
|
||||
var cPlg *Plugin
|
||||
for cc.Next() {
|
||||
if cc.Val() == "{" {
|
||||
depth += 1
|
||||
continue
|
||||
} else if cc.Val() == "}" {
|
||||
depth -= 1
|
||||
continue
|
||||
}
|
||||
val := cc.Val()
|
||||
args := cc.RemainingArgs()
|
||||
switch depth {
|
||||
case 0:
|
||||
c.Servers = append(c.Servers,
|
||||
&Server{
|
||||
DomPorts: append([]string{val}, args...),
|
||||
})
|
||||
cSvr = c.Servers[len(c.Servers)-1]
|
||||
case 1:
|
||||
cSvr.Plugins = append(cSvr.Plugins,
|
||||
&Plugin{
|
||||
Name: val,
|
||||
Args: args,
|
||||
})
|
||||
cPlg = cSvr.Plugins[len(cSvr.Plugins)-1]
|
||||
case 2:
|
||||
cPlg.Options = append(cPlg.Options,
|
||||
&Option{
|
||||
Name: val,
|
||||
Args: args,
|
||||
})
|
||||
}
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
func (c *Corefile) ToString() (out string) {
|
||||
strs := []string{}
|
||||
for _, s := range c.Servers {
|
||||
strs = append(strs, s.ToString())
|
||||
}
|
||||
return strings.Join(strs, "\n")
|
||||
}
|
||||
|
||||
func (s *Server) ToString() (out string) {
|
||||
str := strings.Join(s.DomPorts, " ")
|
||||
strs := []string{}
|
||||
for _, p := range s.Plugins {
|
||||
strs = append(strs, strings.Repeat(" ", indent)+p.ToString())
|
||||
}
|
||||
if len(strs) > 0 {
|
||||
str += " {\n" + strings.Join(strs, "\n") + "\n}\n"
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
func (p *Plugin) ToString() (out string) {
|
||||
str := strings.Join(append([]string{p.Name}, p.Args...), " ")
|
||||
strs := []string{}
|
||||
for _, o := range p.Options {
|
||||
strs = append(strs, strings.Repeat(" ", indent*2)+o.ToString())
|
||||
}
|
||||
if len(strs) > 0 {
|
||||
str += " {\n" + strings.Join(strs, "\n") + "\n" + strings.Repeat(" ", indent*1) + "}"
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
func (o *Option) ToString() (out string) {
|
||||
str := strings.Join(append([]string{o.Name}, o.Args...), " ")
|
||||
return str
|
||||
}
|
||||
|
||||
func (s *Server) FindMatch(def []*Server) (*Server, bool) {
|
||||
NextServer:
|
||||
for _, sDef := range def {
|
||||
for i, dp := range sDef.DomPorts {
|
||||
if dp == "*" {
|
||||
continue
|
||||
}
|
||||
if dp == "***" {
|
||||
return sDef, true
|
||||
}
|
||||
if i >= len(s.DomPorts) || dp != s.DomPorts[i] {
|
||||
continue NextServer
|
||||
}
|
||||
}
|
||||
if len(sDef.DomPorts) != len(s.DomPorts) {
|
||||
continue
|
||||
}
|
||||
return sDef, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (p *Plugin) FindMatch(def []*Plugin) (*Plugin, bool) {
|
||||
NextPlugin:
|
||||
for _, pDef := range def {
|
||||
if pDef.Name != p.Name {
|
||||
continue
|
||||
}
|
||||
for i, arg := range pDef.Args {
|
||||
if arg == "*" {
|
||||
continue
|
||||
}
|
||||
if arg == "***" {
|
||||
return pDef, true
|
||||
}
|
||||
if i >= len(p.Args) || arg != p.Args[i] {
|
||||
continue NextPlugin
|
||||
}
|
||||
}
|
||||
if len(pDef.Args) != len(p.Args) {
|
||||
continue
|
||||
}
|
||||
return pDef, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (o *Option) FindMatch(def []*Option) (*Option, bool) {
|
||||
NextPlugin:
|
||||
for _, oDef := range def {
|
||||
if oDef.Name != o.Name {
|
||||
continue
|
||||
}
|
||||
for i, arg := range oDef.Args {
|
||||
if arg == "*" {
|
||||
continue
|
||||
}
|
||||
if arg == "***" {
|
||||
return oDef, true
|
||||
}
|
||||
if i >= len(o.Args) || arg != o.Args[i] {
|
||||
continue NextPlugin
|
||||
}
|
||||
}
|
||||
if len(oDef.Args) != len(o.Args) {
|
||||
continue
|
||||
}
|
||||
return oDef, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
const indent = 4
|
445
vendor/github.com/coredns/corefile-migration/migration/migrate.go
generated
vendored
Normal file
445
vendor/github.com/coredns/corefile-migration/migration/migrate.go
generated
vendored
Normal file
@@ -0,0 +1,445 @@
|
||||
package migration
|
||||
|
||||
// This package provides a set of functions to help handle migrations of CoreDNS Corefiles to be compatible with new
|
||||
// versions of CoreDNS. The task of upgrading CoreDNS is the responsibility of a variety of Kubernetes management tools
|
||||
// (e.g. kubeadm and others), and the precise behavior may be different for each one. This library abstracts some basic
|
||||
// helper functions that make this easier to implement.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/coredns/corefile-migration/migration/corefile"
|
||||
)
|
||||
|
||||
// Deprecated returns a list of deprecation notifications affecting the guven Corefile. Notifications are returned for
|
||||
// any deprecated, removed, or ignored plugins/directives present in the Corefile. Notifications are also returned for
|
||||
// any new default plugins that would be added in a migration.
|
||||
func Deprecated(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string) ([]Notice, error) {
|
||||
return getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, all)
|
||||
}
|
||||
|
||||
// Unsupported returns a list notifications of plugins/options that are not handled supported by this migration tool,
|
||||
// but may still be valid in CoreDNS.
|
||||
func Unsupported(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string) ([]Notice, error) {
|
||||
return getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, unsupported)
|
||||
}
|
||||
|
||||
func getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, status string) ([]Notice, error) {
|
||||
if fromCoreDNSVersion == toCoreDNSVersion {
|
||||
return nil, nil
|
||||
}
|
||||
err := validUpMigration(fromCoreDNSVersion, toCoreDNSVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cf, err := corefile.New(corefileStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
notices := []Notice{}
|
||||
v := fromCoreDNSVersion
|
||||
for {
|
||||
v = Versions[v].nextVersion
|
||||
for _, s := range cf.Servers {
|
||||
for _, p := range s.Plugins {
|
||||
vp, present := Versions[v].plugins[p.Name]
|
||||
if status == unsupported {
|
||||
if present {
|
||||
continue
|
||||
}
|
||||
notices = append(notices, Notice{Plugin: p.Name, Severity: status, Version: v})
|
||||
continue
|
||||
}
|
||||
if !present {
|
||||
continue
|
||||
}
|
||||
if vp.status != "" && vp.status != newdefault {
|
||||
notices = append(notices, Notice{
|
||||
Plugin: p.Name,
|
||||
Severity: vp.status,
|
||||
Version: v,
|
||||
ReplacedBy: vp.replacedBy,
|
||||
Additional: vp.additional,
|
||||
})
|
||||
continue
|
||||
}
|
||||
for _, o := range p.Options {
|
||||
vo, present := Versions[v].plugins[p.Name].options[o.Name]
|
||||
if status == unsupported {
|
||||
if present {
|
||||
continue
|
||||
}
|
||||
notices = append(notices, Notice{
|
||||
Plugin: p.Name,
|
||||
Option: o.Name,
|
||||
Severity: status,
|
||||
Version: v,
|
||||
ReplacedBy: vo.replacedBy,
|
||||
Additional: vo.additional,
|
||||
})
|
||||
continue
|
||||
}
|
||||
if !present {
|
||||
continue
|
||||
}
|
||||
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 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return notices, nil
|
||||
}
|
||||
|
||||
// Migrate returns the Corefile converted to toCoreDNSVersion, or an error if it cannot. This function only accepts
|
||||
// a forward migration, where the destination version is => the start version.
|
||||
// If deprecations is true, deprecated plugins/options will be migrated as soon as they are deprecated.
|
||||
// If deprecations is false, deprecated plugins/options will be migrated only once they become removed or ignored.
|
||||
func Migrate(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string, deprecations bool) (string, error) {
|
||||
if fromCoreDNSVersion == toCoreDNSVersion {
|
||||
return corefileStr, nil
|
||||
}
|
||||
err := validUpMigration(fromCoreDNSVersion, toCoreDNSVersion)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
cf, err := corefile.New(corefileStr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
v := fromCoreDNSVersion
|
||||
for {
|
||||
v = Versions[v].nextVersion
|
||||
newSrvs := []*corefile.Server{}
|
||||
for _, s := range cf.Servers {
|
||||
newPlugs := []*corefile.Plugin{}
|
||||
for _, p := range s.Plugins {
|
||||
vp, present := Versions[v].plugins[p.Name]
|
||||
if !present {
|
||||
newPlugs = append(newPlugs, p)
|
||||
continue
|
||||
}
|
||||
if !deprecations && vp.status == deprecated {
|
||||
newPlugs = append(newPlugs, p)
|
||||
continue
|
||||
}
|
||||
if vp.action != nil {
|
||||
p, err := vp.action(p)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if p == nil {
|
||||
// remove plugin, skip options processing
|
||||
continue
|
||||
}
|
||||
}
|
||||
newOpts := []*corefile.Option{}
|
||||
for _, o := range p.Options {
|
||||
vo, present := Versions[v].plugins[p.Name].options[o.Name]
|
||||
if !present {
|
||||
newOpts = append(newOpts, o)
|
||||
continue
|
||||
}
|
||||
if !deprecations && vo.status == deprecated {
|
||||
newOpts = append(newOpts, o)
|
||||
continue
|
||||
}
|
||||
if vo.action == nil {
|
||||
newOpts = append(newOpts, o)
|
||||
continue
|
||||
}
|
||||
o, err := vo.action(o)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if o == nil {
|
||||
// remove option
|
||||
continue
|
||||
}
|
||||
newOpts = append(newOpts, o)
|
||||
}
|
||||
newPlug := &corefile.Plugin{
|
||||
Name: p.Name,
|
||||
Args: p.Args,
|
||||
Options: newOpts,
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
newPlug, err = vo.add(newPlug)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
newPlugs = append(newPlugs, newPlug)
|
||||
}
|
||||
newSrv := &corefile.Server{
|
||||
DomPorts: s.DomPorts,
|
||||
Plugins: newPlugs,
|
||||
}
|
||||
CheckForNewPlugins:
|
||||
for name, vp := range Versions[v].plugins {
|
||||
if vp.status != newdefault {
|
||||
continue
|
||||
}
|
||||
for _, p := range s.Plugins {
|
||||
if name == p.Name {
|
||||
continue CheckForNewPlugins
|
||||
}
|
||||
}
|
||||
newSrv, err = vp.add(newSrv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
newSrvs = append(newSrvs, newSrv)
|
||||
}
|
||||
|
||||
cf = &corefile.Corefile{Servers: newSrvs}
|
||||
|
||||
// apply any global corefile level post processing
|
||||
if Versions[v].postProcess != nil {
|
||||
cf, err = Versions[v].postProcess(cf)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
if v == toCoreDNSVersion {
|
||||
break
|
||||
}
|
||||
}
|
||||
return cf.ToString(), nil
|
||||
}
|
||||
|
||||
// MigrateDown returns the Corefile converted to toCoreDNSVersion, or an error if it cannot. This function only accepts
|
||||
// a downward migration, where the destination version is <= the start version.
|
||||
func MigrateDown(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string) (string, error) {
|
||||
if fromCoreDNSVersion == toCoreDNSVersion {
|
||||
return corefileStr, nil
|
||||
}
|
||||
err := validDownMigration(fromCoreDNSVersion, toCoreDNSVersion)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
cf, err := corefile.New(corefileStr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
v := fromCoreDNSVersion
|
||||
for {
|
||||
newSrvs := []*corefile.Server{}
|
||||
for _, s := range cf.Servers {
|
||||
newPlugs := []*corefile.Plugin{}
|
||||
for _, p := range s.Plugins {
|
||||
vp, present := Versions[v].plugins[p.Name]
|
||||
if !present {
|
||||
newPlugs = append(newPlugs, p)
|
||||
continue
|
||||
}
|
||||
if vp.downAction == nil {
|
||||
newPlugs = append(newPlugs, p)
|
||||
continue
|
||||
}
|
||||
p, err := vp.downAction(p)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if p == nil {
|
||||
// remove plugin, skip options processing
|
||||
continue
|
||||
}
|
||||
|
||||
newOpts := []*corefile.Option{}
|
||||
for _, o := range p.Options {
|
||||
vo, present := Versions[v].plugins[p.Name].options[o.Name]
|
||||
if !present {
|
||||
newOpts = append(newOpts, o)
|
||||
continue
|
||||
}
|
||||
if vo.downAction == nil {
|
||||
newOpts = append(newOpts, o)
|
||||
continue
|
||||
}
|
||||
o, err := vo.downAction(o)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if o == nil {
|
||||
// remove option
|
||||
continue
|
||||
}
|
||||
newOpts = append(newOpts, o)
|
||||
}
|
||||
newPlug := &corefile.Plugin{
|
||||
Name: p.Name,
|
||||
Args: p.Args,
|
||||
Options: newOpts,
|
||||
}
|
||||
newPlugs = append(newPlugs, newPlug)
|
||||
}
|
||||
newSrv := &corefile.Server{
|
||||
DomPorts: s.DomPorts,
|
||||
Plugins: newPlugs,
|
||||
}
|
||||
newSrvs = append(newSrvs, newSrv)
|
||||
}
|
||||
|
||||
cf = &corefile.Corefile{Servers: newSrvs}
|
||||
|
||||
if v == toCoreDNSVersion {
|
||||
break
|
||||
}
|
||||
v = Versions[v].priorVersion
|
||||
}
|
||||
return cf.ToString(), nil
|
||||
}
|
||||
|
||||
// Default returns true if the Corefile is the default for a given version of Kubernetes.
|
||||
// Or, if k8sVersion is empty, Default returns true if the Corefile is the default for any version of Kubernetes.
|
||||
func Default(k8sVersion, corefileStr string) bool {
|
||||
cf, err := corefile.New(corefileStr)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
NextVersion:
|
||||
for _, v := range Versions {
|
||||
for _, release := range v.k8sReleases {
|
||||
if k8sVersion != "" && k8sVersion != release {
|
||||
continue
|
||||
}
|
||||
}
|
||||
defCf, err := corefile.New(v.defaultConf)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// check corefile against k8s release default
|
||||
if len(cf.Servers) != len(defCf.Servers) {
|
||||
continue NextVersion
|
||||
}
|
||||
for _, s := range cf.Servers {
|
||||
defS, found := s.FindMatch(defCf.Servers)
|
||||
if !found {
|
||||
continue NextVersion
|
||||
}
|
||||
if len(s.Plugins) != len(defS.Plugins) {
|
||||
continue NextVersion
|
||||
}
|
||||
for _, p := range s.Plugins {
|
||||
defP, found := p.FindMatch(defS.Plugins)
|
||||
if !found {
|
||||
continue NextVersion
|
||||
}
|
||||
if len(p.Options) != len(defP.Options) {
|
||||
continue NextVersion
|
||||
}
|
||||
for _, o := range p.Options {
|
||||
_, found := o.FindMatch(defP.Options)
|
||||
if !found {
|
||||
continue NextVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Released returns true if dockerImageSHA matches any released image of CoreDNS.
|
||||
func Released(dockerImageSHA string) bool {
|
||||
for _, v := range Versions {
|
||||
if v.dockerImageSHA == dockerImageSHA {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ValidVersions returns a list of all versions defined
|
||||
func ValidVersions() []string {
|
||||
var vStrs []string
|
||||
for vStr := range Versions {
|
||||
vStrs = append(vStrs, vStr)
|
||||
}
|
||||
sort.Strings(vStrs)
|
||||
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 {
|
||||
err := validateVersion(fromCoreDNSVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for next := Versions[fromCoreDNSVersion].nextVersion; next != ""; next = Versions[next].nextVersion {
|
||||
if next != toCoreDNSVersion {
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("cannot migrate up to '%v' from '%v'", toCoreDNSVersion, fromCoreDNSVersion)
|
||||
}
|
||||
|
||||
func validDownMigration(fromCoreDNSVersion, toCoreDNSVersion string) error {
|
||||
err := validateVersion(fromCoreDNSVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for prior := Versions[fromCoreDNSVersion].priorVersion; prior != ""; prior = Versions[prior].priorVersion {
|
||||
if prior != toCoreDNSVersion {
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("cannot migrate down to '%v' from '%v'", toCoreDNSVersion, fromCoreDNSVersion)
|
||||
}
|
48
vendor/github.com/coredns/corefile-migration/migration/notice.go
generated
vendored
Normal file
48
vendor/github.com/coredns/corefile-migration/migration/notice.go
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
package migration
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Notice is a migration warning
|
||||
type Notice struct {
|
||||
Plugin string
|
||||
Option string
|
||||
Severity string // 'deprecated', 'removed', or 'unsupported'
|
||||
ReplacedBy string
|
||||
Additional string
|
||||
Version string
|
||||
}
|
||||
|
||||
func (n *Notice) ToString() string {
|
||||
s := ""
|
||||
if n.Option == "" {
|
||||
s += fmt.Sprintf(`Plugin "%v" `, n.Plugin)
|
||||
} else {
|
||||
s += fmt.Sprintf(`Option "%v" in plugin "%v" `, n.Option, n.Plugin)
|
||||
}
|
||||
if n.Severity == unsupported {
|
||||
s += "is unsupported by this migration tool in " + n.Version + "."
|
||||
} else if n.Severity == newdefault {
|
||||
s += "is added as a default in " + n.Version + "."
|
||||
} else {
|
||||
s += "is " + n.Severity + " in " + n.Version + "."
|
||||
}
|
||||
if n.ReplacedBy != "" {
|
||||
s += fmt.Sprintf(` It is replaced by "%v".`, n.ReplacedBy)
|
||||
}
|
||||
if n.Additional != "" {
|
||||
s += " " + n.Additional
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
const (
|
||||
// The following statuses are used to indicate the state of support/deprecation in a given release.
|
||||
deprecated = "deprecated" // deprecated, but still completely functional
|
||||
ignored = "ignored" // if included in the corefile, it will be ignored by CoreDNS
|
||||
removed = "removed" // completely removed from CoreDNS, and would cause CoreDNS to exit if present in the Corefile
|
||||
newdefault = "newdefault" // added to the default corefile. CoreDNS may not function properly if it is not present in the corefile.
|
||||
unsupported = "unsupported" // the plugin/option is not supported by the migration tool
|
||||
|
||||
// The following statuses are used for selecting/filtering notifications
|
||||
all = "all" // show all statuses
|
||||
)
|
1504
vendor/github.com/coredns/corefile-migration/migration/versions.go
generated
vendored
Normal file
1504
vendor/github.com/coredns/corefile-migration/migration/versions.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user