Skip to content

Commit

Permalink
Adapt actuator to use cluster from cluster.k8s.io
Browse files Browse the repository at this point in the history
openshift/cluster-api#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
  • Loading branch information
enxebre committed May 3, 2019
1 parent 4b04803 commit ebf0154
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
12 changes: 6 additions & 6 deletions cmd/libvirt-actuator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions cmd/libvirt-actuator/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
libvirtclient "github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/client"
"github.com/openshift/cluster-api-provider-libvirt/test"
machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
clusterv1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1"
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)
Expand All @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions pkg/cloud/libvirt/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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)
Expand All @@ -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}

Expand Down Expand Up @@ -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}

Expand Down
27 changes: 14 additions & 13 deletions pkg/cloud/libvirt/actuators/machine/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -98,23 +99,23 @@ 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",
},
{
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",
},
{
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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions pkg/cloud/libvirt/actuators/machine/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ebf0154

Please sign in to comment.