@@ -20,12 +20,10 @@ import (
20
20
"context"
21
21
22
22
"github.com/pkg/errors"
23
- corev1 "k8s.io/api/core/v1"
24
23
apierrors "k8s.io/apimachinery/pkg/api/errors"
25
24
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
25
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
27
26
kerrors "k8s.io/apimachinery/pkg/util/errors"
28
- "k8s.io/apiserver/pkg/storage/names"
29
27
"sigs.k8s.io/controller-runtime/pkg/client"
30
28
31
29
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -93,35 +91,6 @@ func (c *ControlPlane) FailureDomains() clusterv1.FailureDomains {
93
91
return c .Cluster .Status .FailureDomains
94
92
}
95
93
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
-
125
94
// MachineInFailureDomainWithMostMachines returns the first matching failure domain with machines that has the most control-plane machines on it.
126
95
func (c * ControlPlane ) MachineInFailureDomainWithMostMachines (machines collections.Machines ) (* clusterv1.Machine , error ) {
127
96
fd := c .FailureDomainWithMostMachines (machines )
@@ -182,63 +151,6 @@ func (c *ControlPlane) JoinControlPlaneConfig() *bootstrapv1.KubeadmConfigSpec {
182
151
return bootstrapSpec
183
152
}
184
153
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
-
242
154
// HasDeletingMachine returns true if any machine in the control plane is in the process of being deleted.
243
155
func (c * ControlPlane ) HasDeletingMachine () bool {
244
156
return len (c .Machines .Filter (collections .HasDeletionTimestamp )) > 0
0 commit comments