Skip to content

Commit bb404b6

Browse files
committed
feat: update for Talos 1.5.0
Bump CAPI base version, regen, update the tests. Signed-off-by: Andrey Smirnov <[email protected]>
1 parent 210c95c commit bb404b6

File tree

15 files changed

+289
-302
lines changed

15 files changed

+289
-302
lines changed

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ NAME := cluster-api-control-plane-talos-controller
88
WITH_RACE ?= false
99
CGO_ENABLED = 0
1010
TESTPKGS ?= ./controllers/...
11-
CONTROLLER_GEN_VERSION ?= v0.11.3
12-
CONVERSION_GEN_VERSION ?= v0.26.0
11+
12+
CONTROLLER_GEN_VERSION ?= v0.12.0
13+
CONVERSION_GEN_VERSION ?= v0.27.2
1314

1415
ifneq (, $(filter $(WITH_RACE), t true TRUE y yes 1))
1516
GO_BUILDFLAGS += -race
@@ -21,8 +22,8 @@ GO_LDFLAGS += -s -w
2122

2223
ARTIFACTS := _out
2324

24-
TOOLS ?= ghcr.io/siderolabs/tools:v1.4.0-1-g955aabc
25-
PKGS ?= v1.4.1-5-ga333a84
25+
TOOLS ?= ghcr.io/siderolabs/tools:v1.5.0
26+
PKGS ?= v1.5.0
2627

2728
BUILD := docker buildx build
2829
PLATFORM ?= linux/amd64
@@ -143,4 +144,4 @@ unit-tests: ## Performs unit tests
143144
@$(MAKE) local-$@ DEST=$(ARTIFACTS)
144145

145146
check-dirty: ## Verifies that source tree is not dirty
146-
@if test -n "`git status --porcelain`"; then echo "Source tree is dirty"; git status; exit 1 ; fi
147+
@if test -n "`git status --porcelain`"; then echo "Source tree is dirty"; git status; exit 1 ; fi

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ This provider's versions are compatible with the following versions of Cluster A
2727

2828
This provider's versions are able to install and manage the following versions of Kubernetes:
2929

30-
| | v1.16 | v 1.17 | v1.18 | v1.19 | v1.20 | v1.21 | v1.22 | v1.23 | v1.24 | v1.25 | v1.26 | v1.27 |
31-
| ------------------------------------------- | ----- | ------ | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- |
32-
| Control Plane Provider Talos v1alpha3 (v0.2) ||||||| | | | | | |
33-
| Control Plane Provider Talos v1alpha3 (v0.3) ||||||| | | | | | |
34-
| Control Plane Provider Talos v1alpha3 (v0.4) | | | ||||||||| |
35-
| Control Plane Provider Talos v1alpha3 (v0.5) | | | | | | | | | ||||
30+
| | v1.16 | v 1.17 | v1.18 | v1.19 | v1.20 | v1.21 | v1.22 | v1.23 | v1.24 | v1.25 | v1.26 | v1.27 | v1.28 |
31+
| ------------------------------------------- | ----- | ------ | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- |
32+
| Control Plane Provider Talos v1alpha3 (v0.2) ||||||| | | | | | | |
33+
| Control Plane Provider Talos v1alpha3 (v0.3) ||||||| | | | | | | |
34+
| Control Plane Provider Talos v1alpha3 (v0.4) | | | ||||||||| | |
35+
| Control Plane Provider Talos v1alpha3 (v0.5) | | | | | | | | | |||||
3636

3737
This provider's versions are compatible with the following versions of Talos:
3838

39-
| | v0.11 | v0.12 | v0.13 | v0.14 | v1.0 | v1.1 | v1.2 | v1.3 | v1.4 |
40-
| -------------------------------------------- | ----- | ------ | ----- | ----- | ----- | ----- | ----- | ----- | ----- |
41-
| Control Plane Provider Talos v1alpha3 (v0.3) ||| | | | | | | |
42-
| Control Plane Provider Talos v1alpha3 (v0.3) |||| | | | | | |
43-
| Control Plane Provider Talos v1alpha3 (v0.4) ||||||||| |
44-
| Control Plane Provider Talos v1alpha3 (v0.5) | | | | | | | |||
39+
| | v0.11 | v0.12 | v0.13 | v0.14 | v1.0 | v1.1 | v1.2 | v1.3 | v1.4 | v1.5 |
40+
| -------------------------------------------- | ----- | ------ | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- |
41+
| Control Plane Provider Talos v1alpha3 (v0.3) ||| | | | | | | | |
42+
| Control Plane Provider Talos v1alpha3 (v0.3) |||| | | | | | | |
43+
| Control Plane Provider Talos v1alpha3 (v0.4) ||||||||| | |
44+
| Control Plane Provider Talos v1alpha3 (v0.5) | | | | | | | ||||
4545

4646
## Building and Installing
4747

api/v1alpha3/taloscontrolplane_webhook.go

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

2021
// SetupWebhookWithManager implements webhook methods.
@@ -74,25 +75,25 @@ func defaultRolloutStrategy(rolloutStrategy *RolloutStrategy) *RolloutStrategy {
7475
}
7576

7677
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
77-
func (r *TalosControlPlane) ValidateCreate() error {
78+
func (r *TalosControlPlane) ValidateCreate() (admission.Warnings, error) {
7879
return r.validate()
7980
}
8081

8182
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
82-
func (r *TalosControlPlane) ValidateUpdate(old runtime.Object) error {
83+
func (r *TalosControlPlane) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
8384
return r.validate()
8485
}
8586

8687
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
87-
func (r *TalosControlPlane) ValidateDelete() error {
88-
return nil
88+
func (r *TalosControlPlane) ValidateDelete() (admission.Warnings, error) {
89+
return nil, nil
8990
}
9091

91-
func (r *TalosControlPlane) validate() error {
92+
func (r *TalosControlPlane) validate() (admission.Warnings, error) {
9293
var allErrs field.ErrorList
9394

9495
if r.Spec.RolloutStrategy == nil {
95-
return nil
96+
return nil, nil
9697
}
9798

9899
switch r.Spec.RolloutStrategy.Type {
@@ -108,10 +109,10 @@ func (r *TalosControlPlane) validate() error {
108109
}
109110

110111
if len(allErrs) == 0 {
111-
return nil
112+
return nil, nil
112113
}
113114

114-
return apierrors.NewInvalid(
115+
return nil, apierrors.NewInvalid(
115116
schema.GroupKind{Group: GroupVersion.Group, Kind: "TalosControlPlane"},
116117
r.Name, allErrs)
117118
}

config/crd/bases/controlplane.cluster.x-k8s.io_taloscontrolplanes.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: taloscontrolplanes.controlplane.cluster.x-k8s.io
98
spec:
109
group: controlplane.cluster.x-k8s.io

config/rbac/role.yaml

Lines changed: 0 additions & 2 deletions
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:
@@ -66,7 +65,6 @@ rules:
6665
apiVersion: rbac.authorization.k8s.io/v1
6766
kind: Role
6867
metadata:
69-
creationTimestamp: null
7068
name: manager-role
7169
namespace: kube-system
7270
rules:

config/webhook/manifests.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
apiVersion: admissionregistration.k8s.io/v1
33
kind: MutatingWebhookConfiguration
44
metadata:
5-
creationTimestamp: null
65
name: mutating-webhook-configuration
76
webhooks:
87
- admissionReviewVersions:
@@ -31,7 +30,6 @@ webhooks:
3130
apiVersion: admissionregistration.k8s.io/v1
3231
kind: ValidatingWebhookConfiguration
3332
metadata:
34-
creationTimestamp: null
3533
name: validating-webhook-configuration
3634
webhooks:
3735
- admissionReviewVersions:

controllers/controllers_test.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
bootstrapv1alpha3 "github.com/siderolabs/cluster-api-bootstrap-provider-talos/api/v1alpha3"
1414
"github.com/siderolabs/talos/pkg/machinery/api/common"
1515
"github.com/siderolabs/talos/pkg/machinery/api/machine"
16-
"github.com/siderolabs/talos/pkg/machinery/config/types/v1alpha1/generate"
16+
"github.com/siderolabs/talos/pkg/machinery/config"
17+
"github.com/siderolabs/talos/pkg/machinery/config/generate/secrets"
1718
"github.com/stretchr/testify/suite"
1819
"golang.org/x/sync/errgroup"
1920
corev1 "k8s.io/api/core/v1"
@@ -38,7 +39,7 @@ type ControllersSuite struct {
3839
suite.Suite
3940

4041
machineServices map[string]*machineService
41-
secretsBundle *generate.SecretsBundle
42+
secretsBundle *secrets.Bundle
4243
ctx context.Context
4344
cancel context.CancelFunc
4445
}
@@ -48,7 +49,7 @@ func (suite *ControllersSuite) SetupSuite() {
4849

4950
suite.ctx, suite.cancel = context.WithTimeout(context.Background(), time.Minute*10)
5051

51-
suite.secretsBundle, err = generate.NewSecretsBundle(generate.NewClock(), generate.WithEndpointList([]string{"127.0.0.1"}))
52+
suite.secretsBundle, err = secrets.NewBundle(secrets.NewFixedClock(time.Now()), config.TalosVersionCurrent)
5253
suite.Require().NoError(err)
5354

5455
suite.machineServices = map[string]*machineService{}
@@ -91,7 +92,7 @@ func (suite *ControllersSuite) TestClusterToTalosControlPlane() {
9192

9293
r := newReconciler(fakeClient)
9394

94-
got := r.ClusterToTalosControlPlane(cluster)
95+
got := r.ClusterToTalosControlPlane(context.Background(), cluster)
9596
g.Expect(got).To(Equal(expectedResult))
9697
}
9798

@@ -103,7 +104,7 @@ func (suite *ControllersSuite) TestClusterToTalosControlPlaneNoControlPlane() {
103104

104105
cluster := newCluster(&types.NamespacedName{Name: "foo", Namespace: metav1.NamespaceDefault})
105106

106-
got := r.ClusterToTalosControlPlane(cluster)
107+
got := r.ClusterToTalosControlPlane(context.Background(), cluster)
107108
g.Expect(got).To(BeNil())
108109
}
109110

@@ -122,10 +123,11 @@ func (suite *ControllersSuite) TestClusterToTalosControlPlaneOtherControlPlane()
122123
}
123124

124125
r := &controllers.TalosControlPlaneReconciler{
125-
Client: fakeClient,
126+
Client: fakeClient,
127+
APIReader: fakeClient,
126128
}
127129

128-
got := r.ClusterToTalosControlPlane(cluster)
130+
got := r.ClusterToTalosControlPlane(context.Background(), cluster)
129131
g.Expect(got).To(BeNil())
130132
}
131133

@@ -154,11 +156,12 @@ func (suite *ControllersSuite) TestReconcilePaused() {
154156
},
155157
}
156158
tcp.Default()
157-
g.Expect(tcp.ValidateCreate()).To(Succeed())
159+
_, err := tcp.ValidateCreate()
160+
g.Expect(err).To(Succeed())
158161
fakeClient := newFakeClient(tcp.DeepCopy(), cluster.DeepCopy())
159162
r := newReconciler(fakeClient)
160163

161-
_, err := r.Reconcile(suite.ctx, ctrl.Request{NamespacedName: util.ObjectKey(tcp)})
164+
_, err = r.Reconcile(suite.ctx, ctrl.Request{NamespacedName: util.ObjectKey(tcp)})
162165
g.Expect(err).NotTo(HaveOccurred())
163166

164167
machineList := &clusterv1.MachineList{}
@@ -203,7 +206,8 @@ func (suite *ControllersSuite) TestReconcileClusterNoEndpoints() {
203206
}
204207

205208
tcp.Default()
206-
g.Expect(tcp.ValidateCreate()).To(Succeed())
209+
_, err := tcp.ValidateCreate()
210+
g.Expect(err).To(Succeed())
207211

208212
ca := corev1.Secret{
209213
TypeMeta: metav1.TypeMeta{

controllers/helpers_test.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ import (
1414
"os"
1515
"strings"
1616
"sync"
17-
"time"
1817

1918
"github.com/gobuffalo/flect"
2019
"github.com/pkg/errors"
2120
bootstrapv1alpha3 "github.com/siderolabs/cluster-api-bootstrap-provider-talos/api/v1alpha3"
2221
"github.com/siderolabs/crypto/tls"
2322
"github.com/siderolabs/crypto/x509"
24-
"github.com/siderolabs/talos/pkg/grpc/gen"
23+
"github.com/siderolabs/gen/slices"
2524
"github.com/siderolabs/talos/pkg/machinery/api/common"
2625
"github.com/siderolabs/talos/pkg/machinery/api/machine"
2726
"github.com/siderolabs/talos/pkg/machinery/api/storage"
28-
"github.com/siderolabs/talos/pkg/machinery/config/types/v1alpha1/generate"
27+
"github.com/siderolabs/talos/pkg/machinery/config/generate"
28+
"github.com/siderolabs/talos/pkg/machinery/config/generate/secrets"
2929
"github.com/siderolabs/talos/pkg/machinery/constants"
3030
"github.com/siderolabs/talos/pkg/machinery/proto"
3131
"google.golang.org/grpc"
@@ -34,7 +34,6 @@ import (
3434
"google.golang.org/grpc/status"
3535
"google.golang.org/protobuf/types/known/anypb"
3636
"google.golang.org/protobuf/types/known/emptypb"
37-
"gopkg.in/typ.v4/slices"
3837
appsv1 "k8s.io/api/apps/v1"
3938
corev1 "k8s.io/api/core/v1"
4039
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -95,19 +94,18 @@ func newReconciler(client client.Client, opts ...reconcilerOption) *controllers.
9594
}
9695

9796
func newFakeClient(initObjs ...client.Object) client.Client {
98-
return &fakeClient{
99-
startTime: time.Now(),
100-
Client: fake.NewClientBuilder().WithObjects(initObjs...).WithScheme(fakeScheme).Build(),
101-
}
102-
}
103-
104-
type fakeClient struct {
105-
startTime time.Time
106-
mux sync.Mutex
107-
client.Client
97+
return fake.NewClientBuilder().
98+
WithObjects(initObjs...).
99+
WithScheme(fakeScheme).
100+
WithStatusSubresource(
101+
&clusterv1.Cluster{},
102+
&clusterv1.Machine{},
103+
&controlplanev1.TalosControlPlane{},
104+
).
105+
Build()
108106
}
109107

110-
func createSecrets(ctx context.Context, obj client.Client, cluster *clusterv1.Cluster, secretsBundle *generate.SecretsBundle, machineAddress string) error {
108+
func createSecrets(ctx context.Context, obj client.Client, cluster *clusterv1.Cluster, secretsBundle *secrets.Bundle, machineAddress string) error {
111109
ca := &corev1.Secret{
112110
TypeMeta: metav1.TypeMeta{
113111
Kind: "Secret",
@@ -123,12 +121,12 @@ func createSecrets(ctx context.Context, obj client.Client, cluster *clusterv1.Cl
123121
return err
124122
}
125123

126-
input, err := generate.NewInput(cluster.Name, "https://localhost:6443", constants.DefaultKubernetesVersion, secretsBundle)
124+
input, err := generate.NewInput(cluster.Name, "https://localhost:6443", constants.DefaultKubernetesVersion, generate.WithSecretsBundle(secretsBundle))
127125
if err != nil {
128126
return err
129127
}
130128

131-
config, err := generate.Talosconfig(input)
129+
config, err := input.Talosconfig()
132130
if err != nil {
133131
return err
134132
}
@@ -330,7 +328,7 @@ func generateCRD(gvk schema.GroupVersionKind, properties map[string]apiextension
330328
}
331329
}
332330

333-
func startMachineServer(ctx context.Context, secretsBundle *generate.SecretsBundle) (*machineService, string, error) {
331+
func startMachineServer(ctx context.Context, secretsBundle *secrets.Bundle) (*machineService, string, error) {
334332
listener, err := net.Listen("tcp", "localhost:0")
335333
if err != nil {
336334
return nil, "", err
@@ -344,7 +342,7 @@ func startMachineServer(ctx context.Context, secretsBundle *generate.SecretsBund
344342

345343
var generator tls.Generator
346344

347-
generator, err = gen.NewLocalGenerator(ca.Key, ca.Crt)
345+
generator, err = NewLocalGenerator(ca.Key, ca.Crt)
348346
if err != nil {
349347
return nil, "", err
350348
}

controllers/taloscontrolplane_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import (
4848
"sigs.k8s.io/controller-runtime/pkg/controller"
4949
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
5050
"sigs.k8s.io/controller-runtime/pkg/handler"
51-
"sigs.k8s.io/controller-runtime/pkg/source"
5251

5352
controlplanev1 "github.com/siderolabs/cluster-api-control-plane-provider-talos/api/v1alpha3"
5453
)
@@ -69,7 +68,7 @@ func (r *TalosControlPlaneReconciler) SetupWithManager(mgr ctrl.Manager, options
6968
For(&controlplanev1.TalosControlPlane{}).
7069
Owns(&clusterv1.Machine{}).
7170
Watches(
72-
&source.Kind{Type: &clusterv1.Cluster{}},
71+
&clusterv1.Cluster{},
7372
handler.EnqueueRequestsFromMapFunc(r.ClusterToTalosControlPlane),
7473
).
7574
WithOptions(options).
@@ -174,7 +173,7 @@ func (r *TalosControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Re
174173
}
175174
}
176175

177-
r.Log.Info("successfully updated control plane status")
176+
logger.Info("successfully updated control plane status")
178177
}()
179178

180179
if !tcp.ObjectMeta.DeletionTimestamp.IsZero() {
@@ -252,7 +251,7 @@ func (r *TalosControlPlaneReconciler) reconcile(ctx context.Context, cluster *cl
252251

253252
// ClusterToTalosControlPlane is a handler.ToRequestsFunc to be used to enqueue requests for reconciliation
254253
// for TalosControlPlane based on updates to a Cluster.
255-
func (r *TalosControlPlaneReconciler) ClusterToTalosControlPlane(o client.Object) []ctrl.Request {
254+
func (r *TalosControlPlaneReconciler) ClusterToTalosControlPlane(_ context.Context, o client.Object) []ctrl.Request {
256255
c, ok := o.(*clusterv1.Cluster)
257256
if !ok {
258257
r.Log.Error(nil, fmt.Sprintf("expected a Cluster but got a %T", o))

0 commit comments

Comments
 (0)