-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Fix CoreDNS upgrade from v1.20 to v1.21 #4476
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-sigs:master
from
fabriziopandini:fix-CoreDNS-1.20-1.21upgrade
Apr 14, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,9 @@ package internal | |
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/blang/semver" | ||
"sigs.k8s.io/cluster-api/util/version" | ||
|
||
"github.com/coredns/corefile-migration/migration" | ||
|
@@ -40,6 +42,10 @@ const ( | |
corefileBackupKey = "Corefile-backup" | ||
coreDNSKey = "coredns" | ||
coreDNSVolumeKey = "config-volume" | ||
|
||
kubernetesImageRepository = "k8s.gcr.io" | ||
oldCoreDNSImageName = "coredns" | ||
coreDNSImageName = "coredns/coredns" | ||
) | ||
|
||
type coreDNSMigrator interface { | ||
|
@@ -156,12 +162,12 @@ func (w *Workload) getCoreDNSInfo(ctx context.Context, clusterConfig *bootstrapv | |
} | ||
|
||
// Handle imageRepository. | ||
toImageRepository := fmt.Sprintf("%s/%s", parsedImage.Repository, parsedImage.Name) | ||
toImageRepository := parsedImage.Repository | ||
if clusterConfig.ImageRepository != "" { | ||
toImageRepository = fmt.Sprintf("%s/%s", clusterConfig.ImageRepository, coreDNSKey) | ||
toImageRepository = strings.TrimSuffix(clusterConfig.ImageRepository, "/") | ||
} | ||
if clusterConfig.DNS.ImageRepository != "" { | ||
toImageRepository = fmt.Sprintf("%s/%s", clusterConfig.DNS.ImageRepository, coreDNSKey) | ||
toImageRepository = strings.TrimSuffix(clusterConfig.DNS.ImageRepository, "/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the trim suffix here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (see comment above) |
||
} | ||
|
||
// Handle imageTag. | ||
|
@@ -181,15 +187,21 @@ func (w *Workload) getCoreDNSInfo(ctx context.Context, clusterConfig *bootstrapv | |
return nil, err | ||
} | ||
|
||
// Handle the renaming of the upstream image from "k8s.gcr.io/coredns" to "k8s.gcr.io/coredns/coredns" | ||
toImageName := parsedImage.Name | ||
if toImageRepository == kubernetesImageRepository && toImageName == oldCoreDNSImageName && targetMajorMinorPatch.GTE(semver.MustParse("1.8.0")) { | ||
toImageName = coreDNSImageName | ||
} | ||
|
||
return &coreDNSInfo{ | ||
Corefile: corefile, | ||
Deployment: deployment, | ||
CurrentMajorMinorPatch: currentMajorMinorPatch, | ||
TargetMajorMinorPatch: targetMajorMinorPatch, | ||
CurrentMajorMinorPatch: currentMajorMinorPatch.String(), | ||
TargetMajorMinorPatch: targetMajorMinorPatch.String(), | ||
FromImageTag: parsedImage.Tag, | ||
ToImageTag: toImageTag, | ||
FromImage: container.Image, | ||
ToImage: fmt.Sprintf("%s:%s", toImageRepository, toImageTag), | ||
ToImage: fmt.Sprintf("%s/%s:%s", toImageRepository, toImageName, toImageTag), | ||
}, nil | ||
} | ||
|
||
|
@@ -298,12 +310,12 @@ func patchCoreDNSDeploymentImage(deployment *appsv1.Deployment, image string) { | |
} | ||
} | ||
|
||
func extractImageVersion(tag string) (string, error) { | ||
func extractImageVersion(tag string) (semver.Version, error) { | ||
ver, err := version.ParseMajorMinorPatchTolerant(tag) | ||
if err != nil { | ||
return "", err | ||
return semver.Version{}, err | ||
} | ||
return fmt.Sprintf("%d.%d.%d", ver.Major, ver.Minor, ver.Patch), nil | ||
return ver, nil | ||
} | ||
|
||
// validateCoreDNSImageTag returns error if the versions don't meet requirements. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the trim suffix here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that the image repository is provider by the user, and that down we are concatenating it with image name and tag, I thought that removing the suffix makes the concat operation more robust (it will work with the user providing "k8s.gcr.io" but also "k8s.gcr.io/")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we instead validate input and provide guidance to users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add validation and documentation as well (in another PR)
Nevertheless, I don't think this extra caution will hurt, but if you prefer I can remove it; it is not core to the fix we are discussing here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know how kubeadm itself handles
/
suffixes? (depending on how they are doing it, consistency might be a factor)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK kubeadm is not doing any validation on ImageTag/ImageRepository, nor we are doing in CAPI
Also kubeadm, is not involved in immutable upgrades.
I just thought it making the operation more robust, but happy to remove it if it is blocking this PR...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was just an idea, it's fine for me either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we open a follow-up PR to add validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding validation could have some implications. I opened an issue to discuss them #4482