clean up docs (#166)

This commit is contained in:
Chris O'Haver 2019-05-14 12:05:29 -04:00 committed by GitHub
parent 910ada176e
commit f1dac88b86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 45 deletions

View file

@ -1,54 +1,86 @@
# K8s/CoreDNS Corefile Migration Tools
This Go library 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.
This Go library 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.
## Proposed functions:
## Notifications
`Deprecated(fromCoreDNSVersion, toCoreDNSVersion, corefile string) []string`: returns a list of deprecated plugins or directives present in the Corefile. Each string returned is a warning, e.g. "plugin 'foo' is deprecated." An empty list returned means there are no deprecated plugins/options present in the Corefile.
Several functions in the library return a list of Notices. Each Notice is a warning of a feature deprecation,
an unsupported plugin/option, or a new required plugin/option added to the Corefile. A Notice has a `ToString()`
For display to an end user. e.g.
`Removed(fromCoreDNSVersion, toCoreDNSVersion, corefile string) []string`: returns a list of removed plugins or directives present in the Corefile. Each string returned is a warning, e.g. "plugin 'foo' is no longer supported." An empty list returned means there are no removed plugins/options present in the Corefile.
```
Plugin "foo" is deprecated in <version>. It is replaced by "bar".
Plugin "bar" is removed in <version>. It is replaced by "qux".
Option "foo" in plugin "bar" is added as a default in <version>.
Plugin "baz" is unsupported by this migration tool in <version>.
```
`Migrate(fromCoreDNSVersion, toCoreDNSVersion, corefile string, deprecations boolean) (string, error)`: returns an automatically migrated version of the Corefile, or an error if it cannot. It should:
## Functions
`Deprecated(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string) ([]Notice, error)`
Deprecated returns a list of deprecation notices affecting the given Corefile. Notices are returned for
any deprecated, removed, or ignored plugins/directives present in the Corefile. Notices are also returned for
any new default plugins that would be added in a migration. Notices
`Migrate(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string, deprecations bool) (string, error)`
Migrate returns a migrated version of the Corefile, or an error if it cannot. It will:
* replace/convert any plugins/directives that have replacements (e.g. _proxy_ -> _forward_)
* return an error if replacable plugins/directives cannot be converted (e.g. proxy _options_ not available in _forward_)
* remove plugins/directives that do not have replacements (e.g. kubernetes `upstream`)
* add in any new default plugins where applicable if they are not already present (e.g. adding _loop_ plugin when it was added). This will have to be case by case, and could potentially get complicated.
* if _deprecations_ is set to true, also migrate deprecated plugins/directives.
`Unsupported(fromCoreDNSVersion, toCoreDNSVersion, corefile string) []string`: returns a list of plugins that are not recognized/supported by the migration tool (but may still be valid in CoreDNS). We must handle all the default plugins, and we should make an effort to handle the most common non-default plugins. Each string returned is a warning, e.g. "plugin 'foo' is not supported by the migration tool." An empty list returned means there are no unsupported plugins/options present in the Corefile.
`Default(fromK8sVersion, corefile string) bool`: returns `true` if the Corefile is the default for a that version of Kubernetes. If `fromK8sVersion` is omitted, returns `true` if the Corefile is the default for any version. Some degree of safe fuzzy matching should be employed here to accept custom cluster domain names and IP addresses, as well as white space.
`CheckCorefile(coreDNSVersion, corefile string) bool`: returns true if the configuration is valid for the given version. This is intended as a sanity checks to make sure a Corefile can be loaded by CoreDNS, e.g. by calling `setup()` for each plugin used. This won't work for custom compilations CoreDNS - e.g. one compiled with external plugins are used.
`Released(dockerImageID string) bool`: returns `true` if `dockerImageID` matches any _released_ image of CoreDNS. This includes all released verisons of CoreDNS, not just those associted with Kubernetes releases.
Globally, `toCoreDNSVersion` must always be higher than `fromCoreDNSVersion`. Supporting downward migrations may be possible, but I don't think necessary to support at this time, so we should expressly forbid downward migrations for now. That said, if a Corefile is at default then a downgrade is very easy (since no migration is required). It's up to the K8s installer to decide if they want to support that.
* add in any new default plugins where applicable if they are not already present (e.g. adding _loop_ plugin when it was added).
This will have to be case by case, and could potentially get complicated.
* 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.
## Command Line Converter
`Unsupported(fromCoreDNSVersion, toCoreDNSVersion, corefileStr string) ([]Notice, error)`
We should also write a simple command line tool that allows someone to use these functions via the command line.
Unsupported returns a list Notices for plugins/options that are unhandled by this migration tool,
but may still be valid in CoreDNS. Currently, only a subset of plugins included by default in CoreDNS are supported
by this tool.
E.g.
```
Usage:
corefile-tool deprecated --from <coredns-version> --to <coredns-version> --corefile <path>
corefile-tool removed --from <coredns-version> --to <coredns-version> --corefile <path> [--deprecations]
corefile-tool migrate --from <coredns-version> --to <coredns-version> --corefile <path>
etc ...
```
`Default(k8sVersion, corefileStr string) bool`
## Example of Usage
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.
This is an example of how these tools could be used by an installer/upgrader...
0. Check `Default()`, if the Corefile is a default, simply re-deploy the new default over top the old one. No migration needed. If the Corefile is not a default, continue...
1. Check `Deprecated()`, if anything is deprecated, warn user, but continue install.
2. Check `Unsupported()`, if anything is unsupported, abort and warn user (allow user to override to pass this).
3. Call `Migrate()`, if there is an error, abort and warn user.
4. If there is no error, pause and ask user if they want to continue with the migration. If the starting Corefile was at defaults, proceed use the migrated corefile.
`Released(dockerImageSHA string) bool`
Released returns true if dockerImageSHA matches any released image of CoreDNS.
`ValidVersions() []string`
ValidVersions returns a list of all versions supported by this tool.
## Command Line Converter Example
An example use of this library is provided [here](../corefile-tool/).
## Kubernetes Cluster Managemnt Tool Usage
This is an example flow of how this library could be used by a Kubernetes cluster management tool to perform a
Corefile migration during an upgrade...
0. Check `Released()` to verify that the installed version of CoreDNS is an official release.
1. Check `Default()`, if the Corefile is a default, simply re-deploy the new default over top the old one. No migration needed.
If the Corefile is not a default, continue...
2. Check `Deprecated()`, if anything is deprecated, warn user, but continue install.
3. Check `Unsupported()`, if anything is unsupported, abort and warn user (allow user to override to pass this).
4. Call `Migrate()`, if there is an error, abort and warn user.
5. If there is no error, pause and ask user if they want to continue with the migration. If the starting Corefile was at defaults,
proceed use the migrated Corefile.

View file

@ -12,14 +12,15 @@ import (
"github.com/coredns/deployment/kubernetes/migration/corefile"
)
// Deprecated returns a list of deprecated, removed, ignored and new default plugins or directives present in the Corefile.
// Each Notice returned is a warning, e.g. "plugin 'foo' is deprecated." An empty list returned means there are no
// deprecated, removed, ignored or new default plugins/options present in the 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 of plugins that are not recognized/supported by the migration tool (but may still be valid in CoreDNS).
// 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)
}
@ -121,7 +122,9 @@ func getStatus(fromCoreDNSVersion, toCoreDNSVersion, corefileStr, status string)
return notices, nil
}
// Migrate returns version of the Corefile migrated to toCoreDNSVersion, or an error if it cannot.
// Migrate returns the Corefile converted to toCoreDNSVersion, or an error if it cannot.
// 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) {
err := validateVersions(fromCoreDNSVersion, toCoreDNSVersion)
if err != nil {

View file

@ -36,10 +36,13 @@ func (n *Notice) ToString() string {
}
const (
deprecated = "deprecated" // plugin/option is deprecated in CoreDNS
ignored = "ignored" // plugin/option is ignored by CoreDNS
removed = "removed" // plugin/option has been removed from CoreDNS
unsupported = "unsupported" // plugin/option is not supported by the migration tool
newdefault = "newdefault" // plugin/option was added to the default corefile
all = "all" // all plugin/option that are deprecated, ignored, removed and new defaults.
// 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
)