Skip to content

Commit fc4ef4e

Browse files
committed
feat: update to Talos 1.5, latest CAPI
Bump Talos, update with new machinery config generation APIs. Bump CAPI and adjust accordingly. Signed-off-by: Andrey Smirnov <[email protected]>
1 parent 1151fc8 commit fc4ef4e

15 files changed

+279
-335
lines changed

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ NAME := cluster-api-talos-controller
99
ARTIFACTS := _out
1010
TEST_RUN ?= ./...
1111

12-
TOOLS ?= ghcr.io/siderolabs/tools:v1.4.0-1-g955aabc
13-
PKGS ?= v1.4.1-5-ga333a84
14-
TALOS_VERSION ?= v1.4.0
15-
K8S_VERSION ?= 1.27.1
12+
TOOLS ?= ghcr.io/siderolabs/tools:v1.5.0
13+
PKGS ?= v1.5.0
14+
TALOS_VERSION ?= v1.5.0
15+
K8S_VERSION ?= 1.27.4
1616

17-
CONTROLLER_GEN_VERSION ?= v0.11.3
18-
CONVERSION_GEN_VERSION ?= v0.26.0
17+
CONTROLLER_GEN_VERSION ?= v0.12.0
18+
CONVERSION_GEN_VERSION ?= v0.27.2
1919

2020
BUILD := docker buildx build
2121
PLATFORM ?= linux/amd64

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ This provider's versions are compatible with the following versions of Cluster A
5454

5555
This provider's versions are able to install and manage the following versions of Kubernetes:
5656
57-
| | v1.19 | v1.20 | v1.21 | v1.22 | v1.23 | v1.24 | v1.25 | v1.26 | v1.27 |
58-
| -------------- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- |
59-
| CABPT (v0.5.x) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
60-
| CABPT (v0.6.x) | | | | | | ✓ | ✓ | ✓ | ✓ |
57+
| | v1.19 | v1.20 | v1.21 | v1.22 | v1.23 | v1.24 | v1.25 | v1.26 | v1.27 | v1.28 |
58+
| -------------- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- |
59+
| CABPT (v0.5.x) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | |
60+
| CABPT (v0.6.x) | | | | | | ✓ | ✓ | ✓ | ✓ | ✓ |
6161
6262
This provider's versions are compatible with the following versions of Talos:
6363

64-
| | v1.0 | v1.1 | v1.2 | v1.3 | v1.4 |
65-
| ---------------- | ----- | ----- | ----- | ----- | ----- |
66-
| CABPT (v0.5.x) ||||| |
67-
| CABPT (v0.6.x) | | ||||
64+
| | v1.0 | v1.1 | v1.2 | v1.3 | v1.4 | v1.5 |
65+
| ---------------- | ----- | ----- | ----- | ----- | ----- | ----- |
66+
| CABPT (v0.5.x) ||||| | |
67+
| CABPT (v0.6.x) | | |||||
6868

6969
CABPT generates machine configuration compatible with Talos version specified in the `talosVersion:` field (see below).
7070

@@ -118,7 +118,7 @@ Machine configuration generated is compatible with the Talos version set in the
118118
```yaml
119119
spec:
120120
generateType: controlplane
121-
talosVersion: v1.1
121+
talosVersion: v1.5
122122
```
123123

124124
### User-supplied Machine Configuration
@@ -148,7 +148,7 @@ The format of these patches is based on [JSON 6902](http://jsonpatch.com/) that
148148
```yaml
149149
spec:
150150
generateType: controlplane
151-
talosVersion: v1.0
151+
talosVersion: v1.5
152152
configPatches:
153153
- op: replace
154154
path: /machine/install

api/v1alpha3/talosconfig_webhook.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"k8s.io/apimachinery/pkg/util/validation/field"
1515
ctrl "sigs.k8s.io/controller-runtime"
1616
"sigs.k8s.io/controller-runtime/pkg/webhook"
17+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1718
)
1819

1920
func (r *TalosConfig) SetupWebhookWithManager(mgr ctrl.Manager) error {
@@ -27,24 +28,24 @@ func (r *TalosConfig) SetupWebhookWithManager(mgr ctrl.Manager) error {
2728
var _ webhook.Validator = &TalosConfig{}
2829

2930
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
30-
func (r *TalosConfig) ValidateCreate() error {
31-
return r.validate()
31+
func (r *TalosConfig) ValidateCreate() (admission.Warnings, error) {
32+
return nil, r.validate()
3233
}
3334

3435
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
35-
func (r *TalosConfig) ValidateUpdate(oldRaw runtime.Object) error {
36+
func (r *TalosConfig) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
3637
old := oldRaw.(*TalosConfig)
3738

3839
if !cmp.Equal(r.Spec, old.Spec) {
39-
return apierrors.NewBadRequest("TalosConfig.Spec is immutable")
40+
return nil, apierrors.NewBadRequest("TalosConfig.Spec is immutable")
4041
}
4142

42-
return r.validate()
43+
return nil, r.validate()
4344
}
4445

4546
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
46-
func (r *TalosConfig) ValidateDelete() error {
47-
return nil
47+
func (r *TalosConfig) ValidateDelete() (admission.Warnings, error) {
48+
return nil, nil
4849
}
4950

5051
func (r *TalosConfig) validate() error {

api/v1alpha3/talosconfigtemplate_webhook.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
runtime "k8s.io/apimachinery/pkg/runtime"
1111
ctrl "sigs.k8s.io/controller-runtime"
1212
"sigs.k8s.io/controller-runtime/pkg/webhook"
13+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1314
)
1415

1516
func (r *TalosConfigTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
@@ -23,22 +24,22 @@ func (r *TalosConfigTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
2324
var _ webhook.Validator = &TalosConfigTemplate{}
2425

2526
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
26-
func (r *TalosConfigTemplate) ValidateCreate() error {
27-
return nil
27+
func (r *TalosConfigTemplate) ValidateCreate() (admission.Warnings, error) {
28+
return nil, nil
2829
}
2930

3031
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
31-
func (r *TalosConfigTemplate) ValidateUpdate(oldRaw runtime.Object) error {
32+
func (r *TalosConfigTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
3233
old := oldRaw.(*TalosConfigTemplate)
3334

3435
if !cmp.Equal(r.Spec, old.Spec) {
35-
return apierrors.NewBadRequest("TalosConfigTemplate.Spec is immutable")
36+
return nil, apierrors.NewBadRequest("TalosConfigTemplate.Spec is immutable")
3637
}
3738

38-
return nil
39+
return nil, nil
3940
}
4041

4142
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
42-
func (r *TalosConfigTemplate) ValidateDelete() error {
43-
return nil
43+
func (r *TalosConfigTemplate) ValidateDelete() (admission.Warnings, error) {
44+
return nil, nil
4445
}

config/crd/bases/bootstrap.cluster.x-k8s.io_talosconfigs.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.11.3
7-
creationTimestamp: null
6+
controller-gen.kubebuilder.io/version: v0.12.0
87
name: talosconfigs.bootstrap.cluster.x-k8s.io
98
spec:
109
group: bootstrap.cluster.x-k8s.io

config/crd/bases/bootstrap.cluster.x-k8s.io_talosconfigtemplates.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.11.3
7-
creationTimestamp: null
6+
controller-gen.kubebuilder.io/version: v0.12.0
87
name: talosconfigtemplates.bootstrap.cluster.x-k8s.io
98
spec:
109
group: bootstrap.cluster.x-k8s.io

config/rbac/role.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
apiVersion: rbac.authorization.k8s.io/v1
33
kind: ClusterRole
44
metadata:
5-
creationTimestamp: null
65
name: manager-role
76
rules:
87
- apiGroups:

config/webhook/manifests.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
apiVersion: admissionregistration.k8s.io/v1
33
kind: ValidatingWebhookConfiguration
44
metadata:
5-
creationTimestamp: null
65
name: validating-webhook-configuration
76
webhooks:
87
- admissionReviewVersions:

controllers/secrets.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
"context"
99
"fmt"
1010
"sort"
11+
"time"
1112

1213
"github.com/go-logr/logr"
1314
"github.com/siderolabs/crypto/x509"
14-
"github.com/siderolabs/talos/pkg/machinery/config/types/v1alpha1/generate"
15-
talosmachine "github.com/siderolabs/talos/pkg/machinery/config/types/v1alpha1/machine"
15+
"github.com/siderolabs/talos/pkg/machinery/config"
16+
"github.com/siderolabs/talos/pkg/machinery/config/generate/secrets"
17+
talosmachine "github.com/siderolabs/talos/pkg/machinery/config/machine"
1618
"gopkg.in/yaml.v2"
1719
corev1 "k8s.io/api/core/v1"
1820
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -26,7 +28,7 @@ import (
2628

2729
func (r *TalosConfigReconciler) fetchSecret(ctx context.Context, config *bootstrapv1alpha3.TalosConfig, secretName string) (*corev1.Secret, error) {
2830
retSecret := &corev1.Secret{}
29-
err := r.Client.Get(context.Background(), client.ObjectKey{
31+
err := r.Client.Get(ctx, client.ObjectKey{
3032
Namespace: config.GetNamespace(),
3133
Name: secretName,
3234
}, retSecret)
@@ -39,8 +41,8 @@ func (r *TalosConfigReconciler) fetchSecret(ctx context.Context, config *bootstr
3941
}
4042

4143
// getSecretsBundle either generates or loads existing secret.
42-
func (r *TalosConfigReconciler) getSecretsBundle(ctx context.Context, scope *TalosConfigScope, allowGenerate bool, opts ...generate.GenOption) (*generate.SecretsBundle, error) {
43-
var secretsBundle *generate.SecretsBundle
44+
func (r *TalosConfigReconciler) getSecretsBundle(ctx context.Context, scope *TalosConfigScope, allowGenerate bool, versionContract *config.VersionContract) (*secrets.Bundle, error) {
45+
var secretsBundle *secrets.Bundle
4446

4547
secretName := scope.Cluster.Name + "-talos"
4648

@@ -54,7 +56,7 @@ retry:
5456
}
5557

5658
// no cluster secret yet, generate new one
57-
secretsBundle, err = generate.NewSecretsBundle(generate.NewClock(), opts...)
59+
secretsBundle, err = secrets.NewBundle(secrets.NewFixedClock(time.Now()), versionContract)
5860
if err != nil {
5961
return nil, fmt.Errorf("error generating new secrets bundle: %w", err)
6062
}
@@ -71,8 +73,8 @@ retry:
7173
return nil, fmt.Errorf("error reading secrets bundle: %w", err)
7274
default:
7375
// successfully loaded secret, initialize secretsBundle from it
74-
secretsBundle = &generate.SecretsBundle{
75-
Clock: generate.NewClock(),
76+
secretsBundle = &secrets.Bundle{
77+
Clock: secrets.NewFixedClock(time.Now()),
7678
}
7779

7880
if _, ok := secret.Data["bundle"]; ok {
@@ -95,14 +97,14 @@ retry:
9597
}
9698

9799
// not stored in legacy format, use empty values
98-
secretsBundle.Cluster = &generate.Cluster{}
100+
secretsBundle.Cluster = &secrets.Cluster{}
99101
}
100102
}
101103

102104
return secretsBundle, nil
103105
}
104106

105-
func (r *TalosConfigReconciler) writeSecretsBundleSecret(ctx context.Context, scope *TalosConfigScope, secretName string, secretsBundle *generate.SecretsBundle) error {
107+
func (r *TalosConfigReconciler) writeSecretsBundleSecret(ctx context.Context, scope *TalosConfigScope, secretName string, secretsBundle *secrets.Bundle) error {
106108
bundle, err := yaml.Marshal(secretsBundle)
107109
if err != nil {
108110
return fmt.Errorf("error marshaling secrets bundle: %w", err)
@@ -225,7 +227,7 @@ func (r *TalosConfigReconciler) reconcileClientConfig(ctx context.Context, log l
225227

226228
sort.Strings(endpoints)
227229

228-
secretBundle, err := r.getSecretsBundle(ctx, scope, false)
230+
secretBundle, err := r.getSecretsBundle(ctx, scope, false, defaultVersionContract) // version contract doesn't matter, as we're getting the secrets
229231
if err != nil {
230232
return err
231233
}

0 commit comments

Comments
 (0)