Skip to content

Commit 400ac56

Browse files
committed
KCP: remove unused code
Signed-off-by: Stefan Büringer [email protected]
1 parent 844eff2 commit 400ac56

File tree

2 files changed

+0
-120
lines changed

2 files changed

+0
-120
lines changed

controlplane/kubeadm/internal/control_plane.go

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ import (
2020
"context"
2121

2222
"github.com/pkg/errors"
23-
corev1 "k8s.io/api/core/v1"
2423
apierrors "k8s.io/apimachinery/pkg/api/errors"
2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2625
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2726
kerrors "k8s.io/apimachinery/pkg/util/errors"
28-
"k8s.io/apiserver/pkg/storage/names"
2927
"sigs.k8s.io/controller-runtime/pkg/client"
3028

3129
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -93,35 +91,6 @@ func (c *ControlPlane) FailureDomains() clusterv1.FailureDomains {
9391
return c.Cluster.Status.FailureDomains
9492
}
9593

96-
// Version returns the KubeadmControlPlane's version.
97-
func (c *ControlPlane) Version() *string {
98-
return &c.KCP.Spec.Version
99-
}
100-
101-
// MachineInfrastructureTemplateRef returns the KubeadmControlPlane's infrastructure template for Machines.
102-
func (c *ControlPlane) MachineInfrastructureTemplateRef() *corev1.ObjectReference {
103-
return &c.KCP.Spec.MachineTemplate.InfrastructureRef
104-
}
105-
106-
// AsOwnerReference returns an owner reference to the KubeadmControlPlane.
107-
func (c *ControlPlane) AsOwnerReference() *metav1.OwnerReference {
108-
return &metav1.OwnerReference{
109-
APIVersion: controlplanev1.GroupVersion.String(),
110-
Kind: "KubeadmControlPlane",
111-
Name: c.KCP.Name,
112-
UID: c.KCP.UID,
113-
}
114-
}
115-
116-
// EtcdImageData returns the etcd image data embedded in the ClusterConfiguration or empty strings if none are defined.
117-
func (c *ControlPlane) EtcdImageData() (string, string) {
118-
if c.KCP.Spec.KubeadmConfigSpec.ClusterConfiguration != nil && c.KCP.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.Local != nil {
119-
meta := c.KCP.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.Local.ImageMeta
120-
return meta.ImageRepository, meta.ImageTag
121-
}
122-
return "", ""
123-
}
124-
12594
// MachineInFailureDomainWithMostMachines returns the first matching failure domain with machines that has the most control-plane machines on it.
12695
func (c *ControlPlane) MachineInFailureDomainWithMostMachines(machines collections.Machines) (*clusterv1.Machine, error) {
12796
fd := c.FailureDomainWithMostMachines(machines)
@@ -182,63 +151,6 @@ func (c *ControlPlane) JoinControlPlaneConfig() *bootstrapv1.KubeadmConfigSpec {
182151
return bootstrapSpec
183152
}
184153

185-
// GenerateKubeadmConfig generates a new kubeadm config for creating new control plane nodes.
186-
func (c *ControlPlane) GenerateKubeadmConfig(spec *bootstrapv1.KubeadmConfigSpec) *bootstrapv1.KubeadmConfig {
187-
// Create an owner reference without a controller reference because the owning controller is the machine controller
188-
owner := metav1.OwnerReference{
189-
APIVersion: controlplanev1.GroupVersion.String(),
190-
Kind: "KubeadmControlPlane",
191-
Name: c.KCP.Name,
192-
UID: c.KCP.UID,
193-
}
194-
195-
bootstrapConfig := &bootstrapv1.KubeadmConfig{
196-
ObjectMeta: metav1.ObjectMeta{
197-
Name: names.SimpleNameGenerator.GenerateName(c.KCP.Name + "-"),
198-
Namespace: c.KCP.Namespace,
199-
Labels: ControlPlaneMachineLabelsForCluster(c.KCP, c.Cluster.Name),
200-
Annotations: c.KCP.Spec.MachineTemplate.ObjectMeta.Annotations,
201-
OwnerReferences: []metav1.OwnerReference{owner},
202-
},
203-
Spec: *spec,
204-
}
205-
return bootstrapConfig
206-
}
207-
208-
// NewMachine returns a machine configured to be a part of the control plane.
209-
func (c *ControlPlane) NewMachine(infraRef, bootstrapRef *corev1.ObjectReference, failureDomain *string) *clusterv1.Machine {
210-
return &clusterv1.Machine{
211-
ObjectMeta: metav1.ObjectMeta{
212-
Name: names.SimpleNameGenerator.GenerateName(c.KCP.Name + "-"),
213-
Namespace: c.KCP.Namespace,
214-
Labels: ControlPlaneMachineLabelsForCluster(c.KCP, c.Cluster.Name),
215-
Annotations: c.KCP.Spec.MachineTemplate.ObjectMeta.Annotations,
216-
OwnerReferences: []metav1.OwnerReference{
217-
*metav1.NewControllerRef(c.KCP, controlplanev1.GroupVersion.WithKind("KubeadmControlPlane")),
218-
},
219-
},
220-
Spec: clusterv1.MachineSpec{
221-
ClusterName: c.Cluster.Name,
222-
Version: c.Version(),
223-
InfrastructureRef: *infraRef,
224-
Bootstrap: clusterv1.Bootstrap{
225-
ConfigRef: bootstrapRef,
226-
},
227-
FailureDomain: failureDomain,
228-
},
229-
}
230-
}
231-
232-
// NeedsReplacementNode determines if the control plane needs to create a replacement node during upgrade.
233-
func (c *ControlPlane) NeedsReplacementNode() bool {
234-
// Can't do anything with an unknown number of desired replicas.
235-
if c.KCP.Spec.Replicas == nil {
236-
return false
237-
}
238-
// if the number of existing machines is exactly 1 > than the number of replicas.
239-
return len(c.Machines)+1 == int(*c.KCP.Spec.Replicas)
240-
}
241-
242154
// HasDeletingMachine returns true if any machine in the control plane is in the process of being deleted.
243155
func (c *ControlPlane) HasDeletingMachine() bool {
244156
return len(c.Machines.Filter(collections.HasDeletionTimestamp)) > 0

controlplane/kubeadm/internal/control_plane_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/gomega"
23-
corev1 "k8s.io/api/core/v1"
2423
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25-
"k8s.io/apimachinery/pkg/types"
26-
"k8s.io/utils/pointer"
2724

2825
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
29-
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
3026
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
3127
"sigs.k8s.io/cluster-api/util/collections"
3228
"sigs.k8s.io/cluster-api/util/conditions"
@@ -64,34 +60,6 @@ func TestControlPlane(t *testing.T) {
6460
g.Expect(*controlPlane.FailureDomainWithMostMachines(controlPlane.Machines)).To(Equal("unknown"))
6561
})
6662
})
67-
68-
t.Run("Generating components", func(t *testing.T) {
69-
controlPlane := &ControlPlane{
70-
KCP: &controlplanev1.KubeadmControlPlane{
71-
ObjectMeta: metav1.ObjectMeta{
72-
Name: "cp",
73-
UID: types.UID("test-uid"),
74-
},
75-
},
76-
Cluster: &clusterv1.Cluster{
77-
ObjectMeta: metav1.ObjectMeta{
78-
Name: "test-cluster",
79-
},
80-
},
81-
}
82-
83-
t.Run("Should generate KubeadmConfig without a controller reference", func(t *testing.T) {
84-
spec := &bootstrapv1.KubeadmConfigSpec{}
85-
kubeadmConfig := controlPlane.GenerateKubeadmConfig(spec)
86-
g.Expect(kubeadmConfig.Labels["cluster.x-k8s.io/cluster-name"]).To(Equal("test-cluster"))
87-
g.Expect(kubeadmConfig.OwnerReferences[0].Controller).To(BeNil())
88-
})
89-
90-
t.Run("Should generate a new machine with a controller reference", func(t *testing.T) {
91-
machine := controlPlane.NewMachine(&corev1.ObjectReference{Namespace: "foobar"}, &corev1.ObjectReference{Namespace: "foobar"}, pointer.String("failureDomain"))
92-
g.Expect(machine.OwnerReferences[0].Controller).ToNot(BeNil())
93-
})
94-
})
9563
}
9664

9765
func TestHasUnhealthyMachine(t *testing.T) {

0 commit comments

Comments
 (0)