forked from kubernetes-sigs/cluster-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A mostly-functional prototype for having the KCP controller identify Machines that belong to the control plane of an existing cluster and adopt them.
- Loading branch information
Showing
5 changed files
with
237 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ import ( | |
"github.com/pkg/errors" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/apimachinery/pkg/types" | ||
kerrors "k8s.io/apimachinery/pkg/util/errors" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
|
@@ -52,8 +53,8 @@ type ManagementCluster struct { | |
} | ||
|
||
// OwnedControlPlaneMachines returns a MachineFilter function to find all owned control plane machines. | ||
// Usage: managementCluster.GetMachinesForCluster(ctx, cluster, OwnedControlPlaneMachines(controlPlane.Name)) | ||
func OwnedControlPlaneMachines(controlPlaneName string) func(machine *clusterv1.Machine) bool { | ||
// Usage: managementCluster.GetMachinesForCluster(ctx, cluster, OwnedControlPlaneMachines(controlPlane)) | ||
func OwnedControlPlaneMachines(owner metav1.Object) func(machine *clusterv1.Machine) bool { | ||
return func(machine *clusterv1.Machine) bool { | ||
if machine == nil { | ||
return false | ||
|
@@ -62,10 +63,46 @@ func OwnedControlPlaneMachines(controlPlaneName string) func(machine *clusterv1. | |
if controllerRef == nil { | ||
return false | ||
} | ||
return controllerRef.Kind == "KubeadmControlPlane" && controllerRef.Name == controlPlaneName | ||
return controllerRef.Kind == "KubeadmControlPlane" && controllerRef.Name == owner.GetName() && controllerRef.UID == owner.GetUID() | ||
} | ||
} | ||
|
||
func ControlPlaneMachines(clusterName string) func(machine *clusterv1.Machine) bool { | ||
selector := ControlPlaneSelectorForCluster(clusterName) | ||
return func(machine *clusterv1.Machine) bool { | ||
if machine == nil { | ||
return false | ||
} | ||
return selector.Matches(labels.Set(machine.Labels)) | ||
} | ||
} | ||
|
||
// AdoptableControlPlaneMachines returns a MachineFilter function to find all un-controlled control plane machines. | ||
// Usage: managementCluster.GetMachinesForCluster(ctx, cluster, AdoptableControlPlaneMachines(cluster.Name, controlPlane)) | ||
func AdoptableControlPlaneMachines(clusterName string) func(machine *clusterv1.Machine) bool { | ||
type ftype func(*clusterv1.Machine) bool | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sethp-nr
Author
|
||
and := func(fs ...ftype) ftype { | ||
return func(machine *clusterv1.Machine) bool { | ||
for _, f := range fs { | ||
if !f(machine) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
} | ||
notNil := func(machine *clusterv1.Machine) bool { | ||
return machine != nil | ||
} | ||
return and( | ||
notNil, | ||
ControlPlaneMachines(clusterName), | ||
func(machine *clusterv1.Machine) bool { | ||
return metav1.GetControllerOf(machine) == nil | ||
}, | ||
) | ||
} | ||
|
||
// HasDeletionTimestamp returns a MachineFilter function to find all machines | ||
// that have a deletion timestamp. | ||
func HasDeletionTimestamp() func(machine *clusterv1.Machine) bool { | ||
|
@@ -219,7 +256,7 @@ func (m *ManagementCluster) healthCheck(ctx context.Context, check healthCheck, | |
} | ||
|
||
// Make sure Cluster API is aware of all the nodes. | ||
machines, err := m.GetMachinesForCluster(ctx, clusterKey, OwnedControlPlaneMachines(controlPlaneName)) | ||
machines, err := m.GetMachinesForCluster(ctx, clusterKey, ControlPlaneMachines(clusterKey.Name)) | ||
if err != nil { | ||
return err | ||
} | ||
|
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
Oops, something went wrong.
i know this is beside the point, but there are some new functions to help you out here.
https://github.com/kubernetes-sigs/cluster-api/blob/master/controlplane/kubeadm/internal/machine_filters.go#L29