generated from siderolabs/project-template-kubernetes-controller
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
TalosControlPlane
rolling upgrade
Track Kubernetes version changes in `TalosControlPlane` resource. When changed recreate nodes one by one until all nodes have the desired Kubernetes version. The same happens when `infrastructureTemplate` is updated. Added new parameters to the `TalosControlPlane` resource which specify controlplanes rollout strategy and strategy configuration. Enable `Defaulter` webhook to populate all created/updated `TalosControlPlane` resources rollout strategy. Signed-off-by: Artem Chernyshev <[email protected]>
- Loading branch information
Showing
19 changed files
with
723 additions
and
222 deletions.
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 |
---|---|---|
@@ -1,11 +1,61 @@ | ||
package v1alpha3 | ||
|
||
import ( | ||
"strings" | ||
|
||
"k8s.io/apimachinery/pkg/util/intstr" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
) | ||
|
||
// SetupWebhookWithManager implements webhook methods. | ||
func (r *TalosControlPlane) SetupWebhookWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(r). | ||
Complete() | ||
} | ||
|
||
// +kubebuilder:webhook:verbs=create;update,path=/mutate-controlplane-cluster-x-k8s-io-v1beta1-kubeadmcontrolplane,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=controlplane.cluster.x-k8s.io,resources=kubeadmcontrolplanes,versions=v1beta1,name=default.kubeadmcontrolplane.controlplane.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 | ||
|
||
var _ webhook.Defaulter = &TalosControlPlane{} | ||
|
||
// Default implements webhook.Defaulter so a webhook will be registered for the type. | ||
func (r *TalosControlPlane) Default() { | ||
defaultTalosControlPlaneSpec(&r.Spec, r.Namespace) | ||
} | ||
|
||
func defaultTalosControlPlaneSpec(s *TalosControlPlaneSpec, namespace string) { | ||
if s.Replicas == nil { | ||
replicas := int32(1) | ||
s.Replicas = &replicas | ||
} | ||
|
||
if !strings.HasPrefix(s.Version, "v") { | ||
s.Version = "v" + s.Version | ||
} | ||
|
||
s.RolloutStrategy = defaultRolloutStrategy(s.RolloutStrategy) | ||
} | ||
|
||
func defaultRolloutStrategy(rolloutStrategy *RolloutStrategy) *RolloutStrategy { | ||
ios1 := intstr.FromInt(1) | ||
|
||
if rolloutStrategy == nil { | ||
rolloutStrategy = &RolloutStrategy{} | ||
} | ||
|
||
// Enforce RollingUpdate strategy and default MaxSurge if not set. | ||
if rolloutStrategy != nil { | ||
if len(rolloutStrategy.Type) == 0 { | ||
rolloutStrategy.Type = RollingUpdateStrategyType | ||
} | ||
if rolloutStrategy.Type == RollingUpdateStrategyType { | ||
if rolloutStrategy.RollingUpdate == nil { | ||
rolloutStrategy.RollingUpdate = &RollingUpdate{} | ||
} | ||
rolloutStrategy.RollingUpdate.MaxSurge = intstr.ValueOrDefault(rolloutStrategy.RollingUpdate.MaxSurge, ios1) | ||
} | ||
} | ||
|
||
return rolloutStrategy | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,15 +1,8 @@ | ||
# This patch add annotation to admission webhook config and | ||
# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize. | ||
apiVersion: admissionregistration.k8s.io/v1beta1 | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: MutatingWebhookConfiguration | ||
metadata: | ||
name: mutating-webhook-configuration | ||
annotations: | ||
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) | ||
--- | ||
apiVersion: admissionregistration.k8s.io/v1beta1 | ||
kind: ValidatingWebhookConfiguration | ||
metadata: | ||
name: validating-webhook-configuration | ||
annotations: | ||
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) |
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,29 @@ | ||
--- | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: MutatingWebhookConfiguration | ||
metadata: | ||
creationTimestamp: null | ||
name: mutating-webhook-configuration | ||
webhooks: | ||
- admissionReviewVersions: | ||
- v1 | ||
- v1beta1 | ||
clientConfig: | ||
service: | ||
name: webhook-service | ||
namespace: system | ||
path: /mutate-controlplane-cluster-x-k8s-io-v1beta1-kubeadmcontrolplane | ||
failurePolicy: Fail | ||
matchPolicy: Equivalent | ||
name: default.kubeadmcontrolplane.controlplane.cluster.x-k8s.io | ||
rules: | ||
- apiGroups: | ||
- controlplane.cluster.x-k8s.io | ||
apiVersions: | ||
- v1beta1 | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
resources: | ||
- kubeadmcontrolplanes | ||
sideEffects: None |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
|
Oops, something went wrong.