-
Notifications
You must be signed in to change notification settings - Fork 233
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
Deploy external CCMs #364
Merged
Merged
Deploy external CCMs #364
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
Copyright 2019 The KubeOne 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 externalccm | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/Masterminds/semver" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/kubermatic/kubeone/pkg/config" | ||
"github.com/kubermatic/kubeone/pkg/util" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
dynclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
// Ensure external CCM deployen if Provider.External | ||
func Ensure(ctx *util.Context) error { | ||
if !ctx.Cluster.Provider.External { | ||
return nil | ||
} | ||
|
||
ctx.Logger.Info("Ensure external CCM is up to date") | ||
|
||
switch ctx.Cluster.Provider.Name { | ||
case config.ProviderNameHetzner: | ||
return ensureHetzner(ctx) | ||
case config.ProviderNameDigitalOcean: | ||
return ensureDigitalOcean(ctx) | ||
default: | ||
ctx.Logger.Infof("External CCM for %q not yet supported, skipping", ctx.Cluster.Provider.Name) | ||
return nil | ||
} | ||
} | ||
|
||
func simpleCreateOrUpdate(ctx context.Context, client dynclient.Client, obj runtime.Object) error { | ||
okFunc := func(runtime.Object) error { return nil } | ||
_, err := controllerutil.CreateOrUpdate(ctx, client, obj, okFunc) | ||
return err | ||
} | ||
|
||
func mutateDeploymentWithVersionCheck(want *semver.Constraints) func(obj runtime.Object) error { | ||
return func(obj runtime.Object) error { | ||
dep, ok := obj.(*appsv1.Deployment) | ||
if !ok { | ||
return errors.Errorf("unknown object type %T passed", obj) | ||
} | ||
|
||
if dep.ObjectMeta.CreationTimestamp.IsZero() { | ||
// let it create deployment | ||
return nil | ||
} | ||
|
||
if len(dep.Spec.Template.Spec.Containers) != 1 { | ||
return errors.New("unable to choose a CCM container, as number of containers > 1") | ||
} | ||
|
||
imageSpec := strings.SplitN(dep.Spec.Template.Spec.Containers[0].Image, ":", 2) | ||
if len(imageSpec) != 2 { | ||
return errors.New("unable to grab CCM image version") | ||
} | ||
|
||
existing, err := semver.NewVersion(imageSpec[1]) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to parse deployed CCM version") | ||
} | ||
|
||
if !want.Check(existing) { | ||
return errors.New("newer version deployed, skipping") | ||
xmudrii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// OK to update the deployment | ||
return nil | ||
} | ||
} |
Oops, something went wrong.
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.
I'd add a message that the user should deploy it manually, e.g.
External CCM for %q not yet supported, please deploy CCM manually
.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.
please deploy CCM manually
is implied, since we can't install them 🤷♂️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.
I prefer being explicit in the user-facing error messages.
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.
I don't want to run pipeline again just for "notice", as then it easily can take days to stabilize because everything is flaky.
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.
Considering you have to rebase the PR, you can fix this. 😉
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.
too late, already rebased :P