
kubeadm uses image tags (such as `v3.4.3-0`) to specify the version of etcd. However, the upgrade code in kubeadm uses the etcd client API to fetch the currently deployed version. The result contains only the etcd version without the additional information (such as image revision) that is normally found in the tag. As a result it would refuse an upgrade where the etcd versions match and the only difference is the image revision number (`v3.4.3-0` to `v3.4.3-1`). To fix the above issue, the following changes are done: - Replace the existing etcd version querying code, that uses the etcd client library, with code that returns the etcd image tag from the local static pod manifest file. - If an etcd `imageTag` is specified in the ClusterConfiguration during upgrade, use that tag instead. This is done regardless if the tag was specified in the configuration stored in the cluster or with a new configuration supplied by the `--config` command line parameter. If no custom tag is specified, kubeadm will select one depending on the desired Kubernetes version. - `kubeadm upgrade plan` no longer prints upgrade information about external etcd. It's the user's responsibility to manage it in that case. Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
/*
|
|
Copyright 2020 The Kubernetes Authors.
|
|
|
|
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.
|
|
*/
|
|
|
|
package image
|
|
|
|
import "regexp"
|
|
|
|
var (
|
|
// tagMatcher is the regex used to match a tag.
|
|
// Basically we presume an image can be made of `[domain][:port][path]<name>[:tag][@sha256:digest]`
|
|
// We are obvously interested only in the tag, but for the purpose of properly matching it, we also match the digest
|
|
// (if present). All the parts before the tag we match in a single match everything (but not greedy) group.
|
|
// All matched sub-groups, except the tag one, get thrown away. Hence, in a result of FindStringSubmatch, if a tag
|
|
// matches, it's going to be the second returned element (after the full match).
|
|
tagMatcher = regexp.MustCompile(`^(?U:.*)(?::([[:word:]][[:word:].-]*))?(?:@sha256:[a-fA-F0-9]{64})?$`)
|
|
)
|
|
|
|
// TagFromImage extracts a tag from image. An empty string is returned if no tag is discovered.
|
|
func TagFromImage(image string) string {
|
|
matches := tagMatcher.FindStringSubmatch(image)
|
|
if len(matches) >= 2 {
|
|
return matches[1]
|
|
}
|
|
return ""
|
|
}
|