Skip to content

Commit 043e382

Browse files
authored
Update CAPI v1alpha2 to v1alpha3 for TKGS life cycle operations (vmware-tanzu#620)
Signed-off-by: PremKumar Kalle <pkalle@vmware.com>
1 parent 1f6773d commit 043e382

File tree

6 files changed

+26
-53
lines changed

6 files changed

+26
-53
lines changed

pkg/v1/tkg/client/client_suite_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
capav1alpha3 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3"
3737
capzv1alpha3 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3"
3838
capvv1alpha3 "sigs.k8s.io/cluster-api-provider-vsphere/api/v1alpha3"
39-
capiv1alpha2 "sigs.k8s.io/cluster-api/api/v1alpha2"
4039
capi "sigs.k8s.io/cluster-api/api/v1alpha3"
4140
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1alpha3"
4241

@@ -67,7 +66,6 @@ var scheme = runtime.NewScheme()
6766

6867
func init() {
6968
_ = capi.AddToScheme(scheme)
70-
_ = capiv1alpha2.AddToScheme(scheme)
7169
_ = corev1.AddToScheme(scheme)
7270
_ = appsv1.AddToScheme(scheme)
7371
_ = controlplanev1.AddToScheme(scheme)

pkg/v1/tkg/client/get_cluster_helper.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/pkg/errors"
1313
"github.com/yalp/jsonpath"
14-
capiv1alpha2 "sigs.k8s.io/cluster-api/api/v1alpha2"
1514
capi "sigs.k8s.io/cluster-api/api/v1alpha3"
1615
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1alpha3"
1716
crtclient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -34,16 +33,16 @@ type clusterObjects struct {
3433

3534
type clusterObjectsForPacific struct {
3635
cluster interface{}
37-
md capiv1alpha2.MachineDeployment
38-
machines []capiv1alpha2.Machine
36+
md capi.MachineDeployment
37+
machines []capi.Machine
3938
}
4039

4140
// ################### Helpers for Pacific ##################
4241

4342
func getRunningCPMachineCountForPacific(clusterInfo *clusterObjectsForPacific) int {
4443
cpMachineCount := 0
4544
for i := range clusterInfo.machines {
46-
if _, labelExists := clusterInfo.machines[i].GetLabels()[capiv1alpha2.MachineControlPlaneLabelName]; labelExists && strings.EqualFold(clusterInfo.machines[i].Status.Phase, "running") {
45+
if _, labelExists := clusterInfo.machines[i].GetLabels()[capi.MachineControlPlaneLabelName]; labelExists && strings.EqualFold(clusterInfo.machines[i].Status.Phase, "running") {
4746
cpMachineCount++
4847
}
4948
}
@@ -57,13 +56,13 @@ func getClusterObjectsMapForPacific(clusterClient clusterclient.Client, apiVersi
5756
return nil, errors.Wrap(err, "unable to get list of clusters")
5857
}
5958

60-
var mdList capiv1alpha2.MachineDeploymentList
59+
var mdList capi.MachineDeploymentList
6160
err = clusterClient.ListResources(&mdList, listOptions)
6261
if err != nil {
6362
return nil, errors.Wrap(err, "unable to get list of MachineDeployment objects")
6463
}
6564

66-
var machineList capiv1alpha2.MachineList
65+
var machineList capi.MachineList
6766
err = clusterClient.ListResources(&machineList, listOptions)
6867
if err != nil {
6968
return nil, errors.Wrap(err, "unable to get list of Machine objects")

pkg/v1/tkg/clusterclient/clusterclient.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
capav1alpha3 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3"
4141
capzv1alpha3 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3"
4242
capvv1alpha3 "sigs.k8s.io/cluster-api-provider-vsphere/api/v1alpha3"
43-
capiv1alpha2 "sigs.k8s.io/cluster-api/api/v1alpha2"
4443
capi "sigs.k8s.io/cluster-api/api/v1alpha3"
4544
bootstrapv1alpha3 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3"
4645
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
@@ -378,7 +377,6 @@ var (
378377

379378
func init() {
380379
_ = capi.AddToScheme(scheme)
381-
_ = capiv1alpha2.AddToScheme(scheme)
382380
_ = corev1.AddToScheme(scheme)
383381
_ = appsv1.AddToScheme(scheme)
384382
_ = clusterctlv1.AddToScheme(scheme)
@@ -1683,13 +1681,13 @@ func (c *client) verifyPacificK8sVersionUpdate(clusterName, namespace, newK8sVer
16831681
return nil
16841682
}
16851683

1686-
func (c *client) getWorkerMachineObjectsForPacificCluster(clusterName, namespace string) ([]capiv1alpha2.Machine, error) {
1687-
mdList := &capiv1alpha2.MachineList{}
1684+
func (c *client) getWorkerMachineObjectsForPacificCluster(clusterName, namespace string) ([]capi.Machine, error) {
1685+
mdList := &capi.MachineList{}
16881686
if err := c.GetResourceList(mdList, clusterName, namespace, nil, nil); err != nil {
16891687
return nil, err
16901688
}
16911689

1692-
workerMachines := []capiv1alpha2.Machine{}
1690+
workerMachines := []capi.Machine{}
16931691
for i := range mdList.Items {
16941692
if _, labelFound := mdList.Items[i].Labels[capi.MachineControlPlaneLabelName]; !labelFound {
16951693
workerMachines = append(workerMachines, mdList.Items[i])

pkg/v1/tkg/clusterclient/clusterclient_test.go

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"k8s.io/client-go/tools/clientcmd"
3434
"k8s.io/utils/pointer"
3535
capav1alpha3 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3"
36-
capiv1alpha2 "sigs.k8s.io/cluster-api/api/v1alpha2"
3736
capi "sigs.k8s.io/cluster-api/api/v1alpha3"
3837
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1alpha3"
3938
crtclient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -71,7 +70,6 @@ var imageRepository = "registry.tkg.vmware.new"
7170

7271
func init() {
7372
_ = capi.AddToScheme(scheme)
74-
_ = capiv1alpha2.AddToScheme(scheme)
7573
_ = capav1alpha3.AddToScheme(scheme)
7674
_ = corev1.AddToScheme(scheme)
7775
_ = controlplanev1.AddToScheme(scheme)
@@ -126,11 +124,10 @@ var _ = Describe("Cluster Client", func() {
126124
currentKubeCtx string
127125
clusterClientOptions Options
128126

129-
tkcPhase string
130-
mdReplicas Replicas
131-
kcpReplicas Replicas
132-
machineObjects []capi.Machine
133-
v1a2machineObjects []capiv1alpha2.Machine
127+
tkcPhase string
128+
mdReplicas Replicas
129+
kcpReplicas Replicas
130+
machineObjects []capi.Machine
134131
)
135132

136133
BeforeSuite(createTempDirectory)
@@ -1262,13 +1259,13 @@ var _ = Describe("Cluster Client", func() {
12621259
clstClient, err = NewClient(kubeConfigPath, "", clusterClientOptions)
12631260
Expect(err).NotTo(HaveOccurred())
12641261

1265-
v1a2machineObjects = []capiv1alpha2.Machine{}
1262+
machineObjects = []capi.Machine{}
12661263
})
12671264
JustBeforeEach(func() {
12681265
clientset.ListCalls(func(ctx context.Context, o runtime.Object, opts ...crtclient.ListOption) error {
12691266
switch o := o.(type) {
1270-
case *capiv1alpha2.MachineList:
1271-
o.Items = append(o.Items, v1a2machineObjects...)
1267+
case *capi.MachineList:
1268+
o.Items = append(o.Items, machineObjects...)
12721269
default:
12731270
return errors.New("invalid object type")
12741271
}
@@ -1316,8 +1313,8 @@ var _ = Describe("Cluster Client", func() {
13161313
Context("When some worker machine objects has old k8s version", func() {
13171314
BeforeEach(func() {
13181315
tkcPhase = statusRunning
1319-
v1a2machineObjects = append(v1a2machineObjects, getv1alpha2DummyMachine("fake-machine-1", "fake-new-version", false))
1320-
v1a2machineObjects = append(v1a2machineObjects, getv1alpha2DummyMachine("fake-machine-2", "fake-old-version", false))
1316+
machineObjects = append(machineObjects, getDummyMachine("fake-machine-1", "fake-new-version", false))
1317+
machineObjects = append(machineObjects, getDummyMachine("fake-machine-2", "fake-old-version", false))
13211318
})
13221319
It("should not return error", func() {
13231320
Expect(err).To(HaveOccurred())
@@ -1327,8 +1324,8 @@ var _ = Describe("Cluster Client", func() {
13271324
Context("When all worker machine objects has new k8s version", func() {
13281325
BeforeEach(func() {
13291326
tkcPhase = statusRunning
1330-
v1a2machineObjects = append(v1a2machineObjects, getv1alpha2DummyMachine("fake-machine-1", "fake-new-version", false))
1331-
v1a2machineObjects = append(v1a2machineObjects, getv1alpha2DummyMachine("fake-machine-1", "fake-new-version", false))
1327+
machineObjects = append(machineObjects, getDummyMachine("fake-machine-1", "fake-new-version", false))
1328+
machineObjects = append(machineObjects, getDummyMachine("fake-machine-1", "fake-new-version", false))
13321329
})
13331330
It("should not return error", func() {
13341331
Expect(err).ToNot(HaveOccurred())
@@ -2280,19 +2277,6 @@ func getDummyMachine(name, currentK8sVersion string, isCP bool) capi.Machine {
22802277
return machine
22812278
}
22822279

2283-
func getv1alpha2DummyMachine(name, currentK8sVersion string, isCP bool) capiv1alpha2.Machine { //nolint:unparam
2284-
// TODO: Add test cases where isCP is true, currently there are no such tests
2285-
machine := capiv1alpha2.Machine{}
2286-
machine.Name = name
2287-
machine.Namespace = fakeMdNameSpace
2288-
machine.Spec.Version = &currentK8sVersion
2289-
machine.Labels = map[string]string{}
2290-
if isCP {
2291-
machine.Labels["cluster.x-k8s.io/control-plane"] = ""
2292-
}
2293-
return machine
2294-
}
2295-
22962280
func getKubeadmConfigConfigMap(filename string) (*corev1.ConfigMap, error) {
22972281
configMapBytes := getConfigMapFileData(filename)
22982282
configMap := &corev1.ConfigMap{}

pkg/v1/tkg/clusterclient/resource.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
capav1alpha3 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3"
2222
capzv1alpha3 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3"
2323
capvv1alpha3 "sigs.k8s.io/cluster-api-provider-vsphere/api/v1alpha3"
24-
capiv1alpha2 "sigs.k8s.io/cluster-api/api/v1alpha2"
2524
capi "sigs.k8s.io/cluster-api/api/v1alpha3"
2625
bootstrapv1alpha3 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3"
2726
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
@@ -189,8 +188,6 @@ func (c *client) getRuntimeObject(o interface{}) (runtime.Object, error) { //nol
189188
return obj, nil
190189
case *capi.MachineHealthCheckList:
191190
return obj, nil
192-
case *capiv1alpha2.MachineList:
193-
return obj, nil
194191
case *capi.MachineList:
195192
return obj, nil
196193
case *capi.MachineDeploymentList:
@@ -219,8 +216,6 @@ func (c *client) getRuntimeObject(o interface{}) (runtime.Object, error) { //nol
219216
return obj, nil
220217
case *capav1alpha3.AWSCluster:
221218
return obj, nil
222-
case *capiv1alpha2.MachineDeploymentList:
223-
return obj, nil
224219
case *appsv1.DaemonSet:
225220
return obj, nil
226221
case *corev1.ConfigMap:

pkg/v1/tkg/fakes/helper/fakeobjectcreater.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
capav1alpha3 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3"
2323
capzv1alpha3 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3"
2424
capvv1alpha3 "sigs.k8s.io/cluster-api-provider-vsphere/api/v1alpha3"
25-
capiv1alpha2 "sigs.k8s.io/cluster-api/api/v1alpha2"
2625
capi "sigs.k8s.io/cluster-api/api/v1alpha3"
2726
cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3"
2827
"sigs.k8s.io/cluster-api/bootstrap/kubeadm/types/v1beta1"
@@ -400,16 +399,16 @@ func NewPacificCluster(options TestAllClusterComponentOptions) runtime.Object {
400399

401400
// NewMDForPacific returns new v1aplha2.MachineDeployment object
402401
func NewMDForPacific(options TestAllClusterComponentOptions) runtime.Object {
403-
md := &capiv1alpha2.MachineDeployment{
402+
md := &capi.MachineDeployment{
404403
ObjectMeta: metav1.ObjectMeta{
405404
Name: "md-" + options.ClusterName,
406405
Namespace: options.Namespace,
407-
Labels: map[string]string{capiv1alpha2.MachineClusterLabelName: options.ClusterName},
406+
Labels: map[string]string{capi.ClusterLabelName: options.ClusterName},
408407
},
409-
Spec: capiv1alpha2.MachineDeploymentSpec{
408+
Spec: capi.MachineDeploymentSpec{
410409
Replicas: &options.ListMDOptions[0].SpecReplicas,
411410
},
412-
Status: capiv1alpha2.MachineDeploymentStatus{
411+
Status: capi.MachineDeploymentStatus{
413412
Replicas: options.ListMDOptions[0].Replicas,
414413
ReadyReplicas: options.ListMDOptions[0].ReadyReplicas,
415414
UpdatedReplicas: options.ListMDOptions[0].UpdatedReplicas,
@@ -422,16 +421,16 @@ func NewMDForPacific(options TestAllClusterComponentOptions) runtime.Object {
422421
func NewMachinesForPacific(options TestAllClusterComponentOptions) []runtime.Object {
423422
machines := []runtime.Object{}
424423
for i, machineOption := range options.MachineOptions {
425-
machine := &capiv1alpha2.Machine{
424+
machine := &capi.Machine{
426425
ObjectMeta: metav1.ObjectMeta{
427426
Namespace: options.Namespace,
428427
Name: "machine-" + strconv.Itoa(i) + options.ClusterName,
429428
Labels: map[string]string{capi.ClusterLabelName: options.ClusterName},
430429
},
431-
Spec: capiv1alpha2.MachineSpec{
430+
Spec: capi.MachineSpec{
432431
Version: &machineOption.K8sVersion,
433432
},
434-
Status: capiv1alpha2.MachineStatus{
433+
Status: capi.MachineStatus{
435434
Phase: machineOption.Phase,
436435
},
437436
}

0 commit comments

Comments
 (0)