Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/v1alpha3/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// +groupName=controlplane.cluster.x-k8s.io
package v1alpha3

import clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
import clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"

// Conditions and condition Reasons for the TalosControlPlane object

Expand Down
7 changes: 3 additions & 4 deletions api/v1alpha3/taloscontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

const (
Expand Down Expand Up @@ -162,7 +161,7 @@ type TalosControlPlaneStatus struct {

// Conditions defines current service state of the KubeadmControlPlane.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`

// version represents the minimum Kubernetes version for the control plane machines
// in the cluster.
Expand Down Expand Up @@ -191,12 +190,12 @@ type TalosControlPlane struct {
}

// GetConditions returns the set of conditions for this object.
func (r *TalosControlPlane) GetConditions() clusterv1.Conditions {
func (r *TalosControlPlane) GetConditions() []metav1.Condition {
return r.Status.Conditions
}

// SetConditions sets the conditions on this object.
func (r *TalosControlPlane) SetConditions(conditions clusterv1.Conditions) {
func (r *TalosControlPlane) SetConditions(conditions []metav1.Condition) {
r.Status.Conditions = conditions
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions controllers/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -105,7 +105,7 @@ func (r *TalosControlPlaneReconciler) talosconfigFromWorkloadCluster(ctx context
return nil, fmt.Errorf("at least one machine should be provided")
}

c, err := r.Tracker.GetClient(ctx, cluster)
c, err := r.ClusterCache.GetClient(ctx, cluster)
if err != nil {
return nil, err
}
Expand All @@ -115,14 +115,14 @@ func (r *TalosControlPlaneReconciler) talosconfigFromWorkloadCluster(ctx context
var t *talosconfig.Config

for _, machine := range machines {
if machine.Status.NodeRef == nil {
if !machine.Status.NodeRef.IsDefined() {
return nil, fmt.Errorf("%q machine does not have a nodeRef", machine.Name)
}

var node v1.Node

// grab all addresses as endpoints
err := c.Get(ctx, types.NamespacedName{Name: machine.Status.NodeRef.Name, Namespace: machine.Status.NodeRef.Namespace}, &node)
err := c.Get(ctx, types.NamespacedName{Name: machine.Status.NodeRef.Name}, &node)
if err != nil {
return nil, err
}
Expand Down
65 changes: 37 additions & 28 deletions controllers/controllers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/patch"
Expand Down Expand Up @@ -75,19 +75,16 @@ func (suite *ControllersSuite) TestClusterToTalosControlPlane() {

cluster := newCluster(&types.NamespacedName{Name: "foo", Namespace: metav1.NamespaceDefault})
cluster.Spec = clusterv1.ClusterSpec{
ControlPlaneRef: &corev1.ObjectReference{
Kind: "TalosControlPlane",
Namespace: metav1.NamespaceDefault,
Name: "tcp-foo",
APIVersion: controlplanev1.GroupVersion.String(),
ControlPlaneRef: clusterv1.ContractVersionedObjectReference{
Kind: "TalosControlPlane",
Name: "tcp-foo",
APIGroup: controlplanev1.GroupVersion.Group,
},
}

expectedResult := []ctrl.Request{
{
NamespacedName: client.ObjectKey{
Namespace: cluster.Spec.ControlPlaneRef.Namespace,
Name: cluster.Spec.ControlPlaneRef.Name},
NamespacedName: client.ObjectKey{Name: cluster.Spec.ControlPlaneRef.Name},
},
}

Expand Down Expand Up @@ -115,11 +112,10 @@ func (suite *ControllersSuite) TestClusterToTalosControlPlaneOtherControlPlane()

cluster := newCluster(&types.NamespacedName{Name: "foo", Namespace: metav1.NamespaceDefault})
cluster.Spec = clusterv1.ClusterSpec{
ControlPlaneRef: &corev1.ObjectReference{
Kind: "OtherControlPlane",
Namespace: metav1.NamespaceDefault,
Name: "other-foo",
APIVersion: controlplanev1.GroupVersion.String(),
ControlPlaneRef: clusterv1.ContractVersionedObjectReference{
Kind: "OtherControlPlane",
Name: "other-foo",
APIGroup: controlplanev1.GroupVersion.Group,
},
}

Expand All @@ -139,7 +135,10 @@ func (suite *ControllersSuite) TestReconcilePaused() {

// Test: cluster is paused and tcp is not
cluster := newCluster(&types.NamespacedName{Namespace: metav1.NamespaceDefault, Name: clusterName})
cluster.Spec.Paused = true

var paused = false
cluster.Spec.Paused = &paused

tcp := &controlplanev1.TalosControlPlane{
ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceDefault,
Expand Down Expand Up @@ -170,7 +169,7 @@ func (suite *ControllersSuite) TestReconcilePaused() {
g.Expect(machineList.Items).To(BeEmpty())

// Test: tcp is paused and cluster is not
cluster.Spec.Paused = false
cluster.Spec.Paused = &paused
tcp.ObjectMeta.Annotations = map[string]string{}
tcp.ObjectMeta.Annotations[clusterv1.PausedAnnotation] = "paused"
_, err = r.Reconcile(suite.ctx, ctrl.Request{NamespacedName: util.ObjectKey(tcp)})
Expand All @@ -181,7 +180,13 @@ func (suite *ControllersSuite) TestReconcileClusterNoEndpoints() {
g := NewWithT(suite.T())

cluster := newCluster(&types.NamespacedName{Name: "foo", Namespace: metav1.NamespaceDefault})
cluster.Status = clusterv1.ClusterStatus{InfrastructureReady: true}
cluster.Status = clusterv1.ClusterStatus{
Conditions: []metav1.Condition{
{
Type: string(clusterv1.InfrastructureReadyV1Beta1Condition),
},
},
}

tcp := &controlplanev1.TalosControlPlane{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -340,7 +345,7 @@ func (suite *ControllersSuite) TestReconcileInitializeControlPlane() {

g.Expect(tcp.Status.Selector).NotTo(BeEmpty())
g.Expect(tcp.Status.Replicas).To(BeEquivalentTo(1))
g.Expect(conditions.IsTrue(tcp, controlplanev1.AvailableCondition)).To(BeTrue())
g.Expect(conditions.IsTrue(tcp, string(controlplanev1.AvailableCondition))).To(BeTrue())
g.Expect(tcp.Status.ReadyReplicas).To(BeEquivalentTo(1))

machineList := &clusterv1.MachineList{}
Expand Down Expand Up @@ -399,7 +404,7 @@ func (suite *ControllersSuite) TestRollingUpdate() {

g.Expect(tcp.Status.Selector).NotTo(BeEmpty())
g.Expect(tcp.Status.Replicas).To(BeEquivalentTo(2))
g.Expect(conditions.IsTrue(tcp, controlplanev1.AvailableCondition)).To(BeTrue())
g.Expect(conditions.IsTrue(tcp, string(controlplanev1.AvailableCondition))).To(BeTrue())
g.Expect(tcp.Status.ReadyReplicas).To(BeEquivalentTo(2))

machineList := &clusterv1.MachineList{}
Expand All @@ -425,14 +430,14 @@ func (suite *ControllersSuite) TestRollingUpdate() {
machines := suite.getMachines(fakeClient, cluster)
for _, machine := range machines {
g.Expect(machine.Spec.Version).ToNot(BeNil())
g.Expect(*machine.Spec.Version).To(BeEquivalentTo(tcp.Spec.Version))
g.Expect(machine.Spec.Version).To(BeEquivalentTo(tcp.Spec.Version))
}
}, time.Minute).Should(Succeed())

for _, machine := range suite.getMachines(fakeClient, cluster) {
talosconfig := &bootstrapv1alpha3.TalosConfig{}

g.Expect(fakeClient.Get(suite.ctx, client.ObjectKey{Name: machine.Spec.Bootstrap.ConfigRef.Name, Namespace: machine.Spec.Bootstrap.ConfigRef.Namespace}, talosconfig)).NotTo(HaveOccurred())
g.Expect(fakeClient.Get(suite.ctx, client.ObjectKey{Name: machine.Spec.Bootstrap.ConfigRef.Name, Namespace: cluster.Namespace}, talosconfig)).NotTo(HaveOccurred())

patchHelper, err := patch.NewHelper(talosconfig, fakeClient)
talosconfig.Spec.TalosVersion = "v1.5.0"
Expand All @@ -450,7 +455,7 @@ func (suite *ControllersSuite) TestRollingUpdate() {
machines := suite.getMachines(fakeClient, cluster)
for _, machine := range machines {
g.Expect(machine.Spec.Version).ToNot(BeNil())
g.Expect(*machine.Spec.Version).To(BeEquivalentTo(tcp.Spec.Version))
g.Expect(machine.Spec.Version).To(BeEquivalentTo(tcp.Spec.Version))
}
}, time.Minute).Should(Succeed())

Expand Down Expand Up @@ -505,7 +510,7 @@ func (suite *ControllersSuite) TestUppercaseHostnames() {

g.Expect(tcp.Status.Selector).NotTo(BeEmpty())
g.Expect(tcp.Status.Replicas).To(BeEquivalentTo(3))
g.Expect(conditions.IsTrue(tcp, controlplanev1.AvailableCondition)).To(BeTrue())
g.Expect(conditions.IsTrue(tcp, string(controlplanev1.AvailableCondition))).To(BeTrue())
g.Expect(tcp.Status.ReadyReplicas).To(BeEquivalentTo(3))

machineList := &clusterv1.MachineList{}
Expand Down Expand Up @@ -560,10 +565,8 @@ func (suite *ControllersSuite) runUpdater(ctx context.Context, fakeClient client
Type: clusterv1.MachineInternalIP,
},
}
machine.Status.NodeRef = &corev1.ObjectReference{
Kind: "Node",
APIVersion: corev1.SchemeGroupVersion.String(),
Name: machine.Name,
machine.Status.NodeRef = clusterv1.MachineNodeReference{
Name: machine.Name,
}

g.Expect(err).To(BeNil())
Expand Down Expand Up @@ -733,7 +736,13 @@ func (suite *ControllersSuite) setupCluster(fakeClient client.Client, ns string,
g.Expect(fakeClient.Create(suite.ctx, cluster)).To(Succeed())
patchHelper, err := patch.NewHelper(cluster, fakeClient)
g.Expect(err).To(BeNil())
cluster.Status = clusterv1.ClusterStatus{InfrastructureReady: true}
cluster.Status = clusterv1.ClusterStatus{
Conditions: []metav1.Condition{
{
Type: string(clusterv1.InfrastructureReadyV1Beta1Condition),
},
},
}
g.Expect(patchHelper.Patch(suite.ctx, cluster)).To(Succeed())

genericInfrastructureMachineTemplate := &unstructured.Unstructured{
Expand Down
10 changes: 5 additions & 5 deletions controllers/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/klog/v2/klogr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/cluster-api/controllers/external"
"sigs.k8s.io/cluster-api/util/collections"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -38,7 +38,7 @@ type ControlPlane struct {

// newControlPlane returns an instantiated ControlPlane.
func newControlPlane(ctx context.Context, client client.Client, cluster *clusterv1.Cluster, tcp *controlplanev1.TalosControlPlane, machines collections.Machines) (*ControlPlane, error) {
infraObjects, err := getInfraResources(ctx, client, machines)
infraObjects, err := getInfraResources(ctx, client, machines, cluster.Namespace)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -93,10 +93,10 @@ func (c *ControlPlane) MachinesNeedingRollout() collections.Machines {
}

// getInfraResources fetches the external infrastructure resource for each machine in the collection and returns a map of machine.Name -> infraResource.
func getInfraResources(ctx context.Context, cl client.Client, machines collections.Machines) (map[string]*unstructured.Unstructured, error) {
func getInfraResources(ctx context.Context, cl client.Client, machines collections.Machines, namespace string) (map[string]*unstructured.Unstructured, error) {
result := map[string]*unstructured.Unstructured{}
for _, m := range machines {
infraObj, err := external.Get(ctx, cl, &m.Spec.InfrastructureRef)
infraObj, err := external.GetObjectFromContractVersionedRef(ctx, cl, m.Spec.InfrastructureRef, namespace)
if err != nil {
if apierrors.IsNotFound(errors.Cause(err)) {
continue
Expand All @@ -114,7 +114,7 @@ func getTalosConfigs(ctx context.Context, cl client.Client, machines collections

for _, m := range machines {
bootstrapRef := m.Spec.Bootstrap.ConfigRef
if bootstrapRef == nil {
if !bootstrapRef.IsDefined() {
continue
}

Expand Down
6 changes: 3 additions & 3 deletions controllers/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
controlplanev1 "github.com/siderolabs/cluster-api-control-plane-provider-talos/api/v1alpha3"
machineapi "github.com/siderolabs/talos/pkg/machinery/api/machine"
talosclient "github.com/siderolabs/talos/pkg/machinery/client"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -180,15 +180,15 @@ func (r *TalosControlPlaneReconciler) auditEtcd(ctx context.Context, tcp *contro
for _, machine := range machines.Items {
// nb: we'll assume any machine that doesn't have a noderef is new and we can audit later because
// otherwise a new etcd member can get removed before even getting the noderef set by the CAPI controllers.
if machine.Status.NodeRef == nil {
if !machine.Status.NodeRef.IsDefined() {
return fmt.Errorf("some CP machines do not have a noderef")
}
}
// Select the first CP machine that's not being deleted and has a noderef
var designatedCPMachine clusterv1.Machine

for _, machine := range machines.Items {
if !machine.ObjectMeta.DeletionTimestamp.IsZero() || machine.Status.NodeRef == nil {
if !machine.ObjectMeta.DeletionTimestamp.IsZero() || !machine.Status.NodeRef.IsDefined() {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
machineapi "github.com/siderolabs/talos/pkg/machinery/api/machine"
talosclient "github.com/siderolabs/talos/pkg/machinery/client"
"google.golang.org/grpc/codes"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
)

type errServiceUnhealthy struct {
Expand Down
Loading