From c5cfbd5d0a4c478be7a005e6a068d18f5f00fca9 Mon Sep 17 00:00:00 2001 From: Enxebre Date: Fri, 3 May 2019 10:09:26 +0200 Subject: [PATCH] Adapt actuator to use cluster from cluster.k8s.io https://github.com/openshift/cluster-api/pull/35 dropped the cluster object from machine.openshift.io as the cluster object is still required programatically via actuator interface this uses the one under cluster.k8s.io --- cmd/libvirt-actuator/main.go | 12 ++++----- cmd/libvirt-actuator/utils/utils.go | 5 ++-- .../libvirt/actuators/machine/actuator.go | 9 ++++--- .../actuators/machine/actuator_test.go | 27 ++++++++++--------- pkg/cloud/libvirt/actuators/machine/stubs.go | 5 ++-- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/cmd/libvirt-actuator/main.go b/cmd/libvirt-actuator/main.go index 816bb333e..c3fc8e453 100644 --- a/cmd/libvirt-actuator/main.go +++ b/cmd/libvirt-actuator/main.go @@ -25,7 +25,7 @@ import ( apiv1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" + clusterv1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1" "k8s.io/apimachinery/pkg/util/wait" "github.com/openshift/cluster-api-actuator-pkg/pkg/e2e/framework" @@ -212,17 +212,17 @@ func bootstrapCommand() *cobra.Command { machinePrefix := cmd.Flag("environment-id").Value.String() - testCluster := &machinev1.Cluster{ + testCluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: machinePrefix, Namespace: testNamespace.Name, }, - Spec: machinev1.ClusterSpec{ - ClusterNetwork: machinev1.ClusterNetworkingConfig{ - Services: machinev1.NetworkRanges{ + Spec: clusterv1.ClusterSpec{ + ClusterNetwork: clusterv1.ClusterNetworkingConfig{ + Services: clusterv1.NetworkRanges{ CIDRBlocks: []string{"10.0.0.1/24"}, }, - Pods: machinev1.NetworkRanges{ + Pods: clusterv1.NetworkRanges{ CIDRBlocks: []string{"10.0.0.1/24"}, }, ServiceDomain: "example.com", diff --git a/cmd/libvirt-actuator/utils/utils.go b/cmd/libvirt-actuator/utils/utils.go index 041f29095..2c0068171 100644 --- a/cmd/libvirt-actuator/utils/utils.go +++ b/cmd/libvirt-actuator/utils/utils.go @@ -13,12 +13,13 @@ import ( machineactuator "github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine" libvirtclient "github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/client" "github.com/openshift/cluster-api-provider-libvirt/test" + clusterv1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1" machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" kubernetesfake "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/tools/record" ) -func ReadClusterResources(clusterLoc, machineLoc, userDataLoc string) (*machinev1.Cluster, *machinev1.Machine, *apiv1.Secret, error) { +func ReadClusterResources(clusterLoc, machineLoc, userDataLoc string) (*clusterv1.Cluster, *machinev1.Machine, *apiv1.Secret, error) { machine := &machinev1.Machine{} { bytes, err := ioutil.ReadFile(machineLoc) @@ -31,7 +32,7 @@ func ReadClusterResources(clusterLoc, machineLoc, userDataLoc string) (*machinev } } - cluster := &machinev1.Cluster{} + cluster := &clusterv1.Cluster{} { bytes, err := ioutil.ReadFile(clusterLoc) if err != nil { diff --git a/pkg/cloud/libvirt/actuators/machine/actuator.go b/pkg/cloud/libvirt/actuators/machine/actuator.go index 9c023c111..8c3f03a94 100644 --- a/pkg/cloud/libvirt/actuators/machine/actuator.go +++ b/pkg/cloud/libvirt/actuators/machine/actuator.go @@ -30,6 +30,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/record" + clusterv1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1" machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" clusterclient "github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset" apierrors "github.com/openshift/cluster-api/pkg/errors" @@ -109,7 +110,7 @@ func (a *Actuator) handleMachineError(machine *machinev1.Machine, err *apierrors } // Create creates a machine and is invoked by the Machine Controller -func (a *Actuator) Create(context context.Context, cluster *machinev1.Cluster, machine *machinev1.Machine) error { +func (a *Actuator) Create(context context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) error { glog.Infof("Creating machine %q", machine.Name) errWrapper := errorWrapper{machine: machine} @@ -149,7 +150,7 @@ func (a *Actuator) Create(context context.Context, cluster *machinev1.Cluster, m } // Delete deletes a machine and is invoked by the Machine Controller -func (a *Actuator) Delete(context context.Context, cluster *machinev1.Cluster, machine *machinev1.Machine) error { +func (a *Actuator) Delete(context context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) error { glog.Infof("Deleting machine %q", machine.Name) machineProviderConfig, err := ProviderConfigMachine(a.codec, &machine.Spec) @@ -176,7 +177,7 @@ func (a *Actuator) Delete(context context.Context, cluster *machinev1.Cluster, m } // Update updates a machine and is invoked by the Machine Controller -func (a *Actuator) Update(context context.Context, cluster *machinev1.Cluster, machine *machinev1.Machine) error { +func (a *Actuator) Update(context context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) error { glog.Infof("Updating machine %v", machine.Name) errWrapper := errorWrapper{machine: machine} @@ -209,7 +210,7 @@ func (a *Actuator) Update(context context.Context, cluster *machinev1.Cluster, m } // Exists test for the existance of a machine and is invoked by the Machine Controller -func (a *Actuator) Exists(context context.Context, cluster *machinev1.Cluster, machine *machinev1.Machine) (bool, error) { +func (a *Actuator) Exists(context context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) (bool, error) { glog.Infof("Checking if machine %v exists.", machine.Name) errWrapper := errorWrapper{machine: machine} diff --git a/pkg/cloud/libvirt/actuators/machine/actuator_test.go b/pkg/cloud/libvirt/actuators/machine/actuator_test.go index 60b2458f1..47eb16f0c 100644 --- a/pkg/cloud/libvirt/actuators/machine/actuator_test.go +++ b/pkg/cloud/libvirt/actuators/machine/actuator_test.go @@ -11,6 +11,7 @@ import ( libvirtclient "github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/client" mocklibvirt "github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/client/mock" fakeclusterclientset "github.com/openshift/cluster-api-provider-libvirt/test" + clusterv1beta1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1" machinev1beta1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" kubernetesfake "k8s.io/client-go/kubernetes/fake" @@ -48,7 +49,7 @@ func TestMachineEvents(t *testing.T) { name string machine *machinev1beta1.Machine error string - operation func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) + operation func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) event string createVolumeErr error deleteVolumeErr error @@ -62,7 +63,7 @@ func TestMachineEvents(t *testing.T) { { name: "Create machine event failed (invalid configuration)", machine: machineInvalidProviderConfig, - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Create(context.TODO(), cluster, machine) }, event: "Warning FailedCreate InvalidConfiguration", @@ -71,7 +72,7 @@ func TestMachineEvents(t *testing.T) { name: "Create machine event failed (error creating libvirt client)", machine: machine, error: libvirtClientError, - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Create(context.TODO(), cluster, machine) }, event: "Warning FailedCreate CreateError", @@ -80,7 +81,7 @@ func TestMachineEvents(t *testing.T) { name: "Create machine event failed (error creating volume)", machine: machine, createVolumeErr: fmt.Errorf("error"), - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Create(context.TODO(), cluster, machine) }, event: "Warning FailedCreate CreateError", @@ -89,7 +90,7 @@ func TestMachineEvents(t *testing.T) { name: "Create machine event failed (error creating domain)", machine: machine, createDomainErr: fmt.Errorf("error"), - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Create(context.TODO(), cluster, machine) }, event: "Warning FailedCreate CreateError", @@ -98,7 +99,7 @@ func TestMachineEvents(t *testing.T) { name: "Create machine event failed (error looking up domain)", machine: machine, lookupDomainErr: fmt.Errorf("error"), - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Create(context.TODO(), cluster, machine) }, event: "Warning FailedCreate CreateError", @@ -106,7 +107,7 @@ func TestMachineEvents(t *testing.T) { { name: "Create machine event succeed", machine: machine, - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Create(context.TODO(), cluster, machine) }, event: "Normal Created Created Machine libvirt-actuator-testing-machine", @@ -114,7 +115,7 @@ func TestMachineEvents(t *testing.T) { { name: "Delete machine event failed (invalid configuration)", machine: machineInvalidProviderConfig, - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Delete(context.TODO(), cluster, machine) }, event: "Warning FailedDelete InvalidConfiguration", @@ -123,7 +124,7 @@ func TestMachineEvents(t *testing.T) { name: "Delete machine event failed (error creating libvirt client)", machine: machine, error: libvirtClientError, - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Delete(context.TODO(), cluster, machine) }, event: "Warning FailedDelete DeleteError", @@ -132,7 +133,7 @@ func TestMachineEvents(t *testing.T) { name: "Delete machine event failed (error getting domain)", machine: machine, domainExistsErr: fmt.Errorf("error"), - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Delete(context.TODO(), cluster, machine) }, event: "Warning FailedDelete DeleteError", @@ -142,7 +143,7 @@ func TestMachineEvents(t *testing.T) { machine: machine, domainExists: true, deleteDomainErr: fmt.Errorf("error"), - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Delete(context.TODO(), cluster, machine) }, event: "Warning FailedDelete DeleteError", @@ -152,7 +153,7 @@ func TestMachineEvents(t *testing.T) { machine: machine, domainExists: true, deleteVolumeErr: fmt.Errorf("error"), - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Delete(context.TODO(), cluster, machine) }, event: "Warning FailedDelete DeleteError", @@ -161,7 +162,7 @@ func TestMachineEvents(t *testing.T) { name: "Delete machine event succeeds", machine: machine, domainExists: true, - operation: func(actuator *Actuator, cluster *machinev1beta1.Cluster, machine *machinev1beta1.Machine) { + operation: func(actuator *Actuator, cluster *clusterv1beta1.Cluster, machine *machinev1beta1.Machine) { actuator.Delete(context.TODO(), cluster, machine) }, event: "Normal Deleted Deleted Machine libvirt-actuator-testing-machine", diff --git a/pkg/cloud/libvirt/actuators/machine/stubs.go b/pkg/cloud/libvirt/actuators/machine/stubs.go index 6ca529233..c9603588d 100644 --- a/pkg/cloud/libvirt/actuators/machine/stubs.go +++ b/pkg/cloud/libvirt/actuators/machine/stubs.go @@ -6,6 +6,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" providerconfigv1 "github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1beta1" + clusterv1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1" machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" ) @@ -65,8 +66,8 @@ func stubMachine() (*machinev1.Machine, error) { return machine, nil } -func stubCluster() *machinev1.Cluster { - return &machinev1.Cluster{ +func stubCluster() *clusterv1.Cluster { + return &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: clusterID, Namespace: defaultNamespace,