From 167705a021c55a54aa26447ae2feb77e35730d03 Mon Sep 17 00:00:00 2001 From: Enxebre Date: Wed, 27 Nov 2019 20:05:38 +0100 Subject: [PATCH] Drop openshift/cluster-api in favour of machine-api-operator --- Makefile | 2 +- cmd/aws-actuator/main.go | 8 +- cmd/aws-actuator/utils.go | 2 +- cmd/manager/main.go | 6 +- pkg/actuators/machine/actuator.go | 42 +++-- pkg/actuators/machine/actuator_test.go | 160 +++++++++--------- pkg/actuators/machine/awsclient.go | 9 +- pkg/actuators/machine/instances.go | 4 +- pkg/actuators/machine/stubs.go | 14 +- pkg/actuators/machine/utils.go | 2 +- pkg/actuators/machine/utils_test.go | 2 +- .../awsproviderconfig/v1beta1/register.go | 2 +- pkg/client/client.go | 2 +- 13 files changed, 117 insertions(+), 138 deletions(-) diff --git a/Makefile b/Makefile index 3000f97702..4acb37f2c5 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ build: ## build binaries $(DOCKER_CMD) go build $(GOGCFLAGS) -o "bin/machine-controller-manager" \ -ldflags "$(LD_FLAGS)" "$(REPO_PATH)/cmd/manager" $(DOCKER_CMD) go build $(GOGCFLAGS) -o bin/manager -ldflags '-extldflags "-static"' \ - "$(REPO_PATH)/vendor/github.com/openshift/cluster-api/cmd/manager" + "$(REPO_PATH)/vendor/github.com/openshift/machine-api-operator/cmd/machineset" aws-actuator: diff --git a/cmd/aws-actuator/main.go b/cmd/aws-actuator/main.go index cbf04fe886..bce657bc75 100644 --- a/cmd/aws-actuator/main.go +++ b/cmd/aws-actuator/main.go @@ -32,7 +32,7 @@ import ( "k8s.io/client-go/kubernetes/scheme" - machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" + machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" ) const ( @@ -106,7 +106,7 @@ func createCommand() *cobra.Command { if err != nil { return fmt.Errorf("unable to create actuator: %v", err) } - result, err := actuator.CreateMachine(nil, machine) + result, err := actuator.CreateMachine(machine) if err != nil { return fmt.Errorf("unable to create machine: %v", err) } @@ -144,7 +144,7 @@ func deleteCommand() *cobra.Command { if err != nil { return fmt.Errorf("unable to create actuator: %v", err) } - if err = actuator.DeleteMachine(nil, machine); err != nil { + if err = actuator.DeleteMachine(machine); err != nil { return fmt.Errorf("unable to delete machine: %v", err) } @@ -178,7 +178,7 @@ func existsCommand() *cobra.Command { if err != nil { return fmt.Errorf("unable to create actuator: %v", err) } - exists, err := actuator.Exists(context.TODO(), nil, machine) + exists, err := actuator.Exists(context.TODO(), machine) if err != nil { return fmt.Errorf("unable to check if machine exists: %v", err) } diff --git a/cmd/aws-actuator/utils.go b/cmd/aws-actuator/utils.go index 54eeeb6352..1563696749 100644 --- a/cmd/aws-actuator/utils.go +++ b/cmd/aws-actuator/utils.go @@ -14,7 +14,7 @@ import ( "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client/fake" - machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" + machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" machineactuator "sigs.k8s.io/cluster-api-provider-aws/pkg/actuators/machine" "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1" awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/client" diff --git a/cmd/manager/main.go b/cmd/manager/main.go index df6b952c5a..b8c6252be5 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -20,8 +20,8 @@ import ( "time" "github.com/golang/glog" - clusterapis "github.com/openshift/cluster-api/pkg/apis" - "github.com/openshift/cluster-api/pkg/controller/machine" + mapiv1beta1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" + "github.com/openshift/machine-api-operator/pkg/controller/machine" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" "k8s.io/klog" machineactuator "sigs.k8s.io/cluster-api-provider-aws/pkg/actuators/machine" @@ -79,7 +79,7 @@ func main() { } // Setup Scheme for all resources - if err := clusterapis.AddToScheme(mgr.GetScheme()); err != nil { + if err := mapiv1beta1.AddToScheme(mgr.GetScheme()); err != nil { glog.Fatalf("Error setting up scheme: %v", err) } diff --git a/pkg/actuators/machine/actuator.go b/pkg/actuators/machine/actuator.go index 3066ea221f..7cbd05e393 100644 --- a/pkg/actuators/machine/actuator.go +++ b/pkg/actuators/machine/actuator.go @@ -24,11 +24,9 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/golang/glog" - clusterv1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1" - machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" - clustererror "github.com/openshift/cluster-api/pkg/controller/error" - machinecontroller "github.com/openshift/cluster-api/pkg/controller/machine" - mapierrors "github.com/openshift/cluster-api/pkg/errors" + machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" + machinecontroller "github.com/openshift/machine-api-operator/pkg/controller/machine" + mapierrors "github.com/openshift/machine-api-operator/pkg/controller/machine" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" apimachineryerrors "k8s.io/apimachinery/pkg/api/errors" @@ -105,9 +103,9 @@ func (a *Actuator) handleMachineError(machine *machinev1.Machine, err error, eve } // Create runs a new EC2 instance -func (a *Actuator) Create(context context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) error { +func (a *Actuator) Create(context context.Context, machine *machinev1.Machine) error { glog.Infof("%s: creating machine", machine.Name) - instance, err := a.CreateMachine(cluster, machine) + instance, err := a.CreateMachine(machine) if err != nil { glog.Errorf("%s: error creating machine: %v", machine.Name, err) updateConditionError := a.updateMachineProviderConditions(machine, providerconfigv1.MachineCreation, MachineCreationFailed, err.Error()) @@ -259,7 +257,7 @@ func (a *Actuator) updateMachineProviderConditions(machine *machinev1.Machine, c } // CreateMachine starts a new AWS instance as described by the cluster and machine resources -func (a *Actuator) CreateMachine(cluster *clusterv1.Cluster, machine *machinev1.Machine) (*ec2.Instance, error) { +func (a *Actuator) CreateMachine(machine *machinev1.Machine) (*ec2.Instance, error) { machineProviderConfig, err := providerConfigFromMachine(machine, a.codec) if err != nil { return nil, a.handleMachineError(machine, mapierrors.InvalidMachineConfiguration("error decoding MachineProviderConfig: %v", err), createEventAction) @@ -334,9 +332,9 @@ func (a *Actuator) getUserData(machine *machinev1.Machine, machineProviderConfig } // Delete deletes a machine and updates its finalizer -func (a *Actuator) Delete(context context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) error { +func (a *Actuator) Delete(context context.Context, machine *machinev1.Machine) error { glog.Infof("%s: deleting machine", machine.Name) - if err := a.DeleteMachine(cluster, machine); err != nil { + if err := a.DeleteMachine(machine); err != nil { glog.Errorf("%s: error deleting machine: %v", machine.Name, err) return err } @@ -354,7 +352,7 @@ func (gl *glogLogger) Logf(format string, v ...interface{}) { } // DeleteMachine deletes an AWS instance -func (a *Actuator) DeleteMachine(cluster *clusterv1.Cluster, machine *machinev1.Machine) error { +func (a *Actuator) DeleteMachine(machine *machinev1.Machine) error { machineProviderConfig, err := providerConfigFromMachine(machine, a.codec) if err != nil { return a.handleMachineError(machine, mapierrors.InvalidMachineConfiguration("error decoding MachineProviderConfig: %v", err), deleteEventAction) @@ -401,7 +399,7 @@ func (a *Actuator) DeleteMachine(cluster *clusterv1.Cluster, machine *machinev1. // Update attempts to sync machine state with an existing instance. Today this just updates status // for details that may have changed. (IPs and hostnames) We do not currently support making any // changes to actual machines in AWS. Instead these will be replaced via MachineDeployments. -func (a *Actuator) Update(context context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) error { +func (a *Actuator) Update(context context.Context, machine *machinev1.Machine) error { glog.Infof("%s: updating machine", machine.Name) machineProviderConfig, err := providerConfigFromMachine(machine, a.codec) @@ -420,7 +418,7 @@ func (a *Actuator) Update(context context.Context, cluster *clusterv1.Cluster, m return a.handleMachineError(machine, err, updateEventAction) } // Get all instances not terminated. - existingInstances, err := a.getMachineInstances(cluster, machine) + existingInstances, err := a.getMachineInstances(machine) if err != nil { glog.Errorf("%s: error getting existing instances: %v", machine.Name, err) return err @@ -433,7 +431,7 @@ func (a *Actuator) Update(context context.Context, cluster *clusterv1.Cluster, m if existingLen == 0 { if machine.Spec.ProviderID != nil && (machine.Status.LastUpdated == nil || machine.Status.LastUpdated.Add(requeueAfterSeconds*time.Second).After(time.Now())) { glog.Infof("%s: Possible eventual-consistency discrepancy; returning an error to requeue", machine.Name) - return &clustererror.RequeueAfterError{RequeueAfter: requeueAfterSeconds * time.Second} + return &machinecontroller.RequeueAfterError{RequeueAfter: requeueAfterSeconds * time.Second} } glog.Warningf("%s: attempted to update machine but no instances found", machine.Name) @@ -446,7 +444,7 @@ func (a *Actuator) Update(context context.Context, cluster *clusterv1.Cluster, m } // This is an unrecoverable error condition. We should delay to // minimize unnecessary API calls. - return &clustererror.RequeueAfterError{RequeueAfter: requeueAfterFatalSeconds * time.Second} + return &machinecontroller.RequeueAfterError{RequeueAfter: requeueAfterFatalSeconds * time.Second} } sortInstances(existingInstances) runningInstances := getRunningFromInstances(existingInstances) @@ -489,16 +487,16 @@ func (a *Actuator) Update(context context.Context, cluster *clusterv1.Cluster, m // Exists determines if the given machine currently exists. // A machine which is not terminated is considered as existing. -func (a *Actuator) Exists(context context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) (bool, error) { - instance, err := a.Describe(cluster, machine) +func (a *Actuator) Exists(context context.Context, machine *machinev1.Machine) (bool, error) { + instance, err := a.Describe(machine) return instance != nil, err } // Describe provides information about machine's instance(s) -func (a *Actuator) Describe(cluster *clusterv1.Cluster, machine *machinev1.Machine) (*ec2.Instance, error) { +func (a *Actuator) Describe(machine *machinev1.Machine) (*ec2.Instance, error) { glog.Infof("%s: Checking if machine exists", machine.Name) - instances, err := a.getMachineInstances(cluster, machine) + instances, err := a.getMachineInstances(machine) if err != nil { glog.Errorf("%s: Error getting existing instances: %v", machine.Name, err) return nil, err @@ -506,7 +504,7 @@ func (a *Actuator) Describe(cluster *clusterv1.Cluster, machine *machinev1.Machi if len(instances) == 0 { if machine.Spec.ProviderID != nil && (machine.Status.LastUpdated == nil || machine.Status.LastUpdated.Add(requeueAfterSeconds*time.Second).After(time.Now())) { glog.Infof("%s: Possible eventual-consistency discrepancy; returning an error to requeue", machine.Name) - return nil, &clustererror.RequeueAfterError{RequeueAfter: requeueAfterSeconds * time.Second} + return nil, &machinecontroller.RequeueAfterError{RequeueAfter: requeueAfterSeconds * time.Second} } glog.Infof("%s: Instance does not exist", machine.Name) @@ -516,7 +514,7 @@ func (a *Actuator) Describe(cluster *clusterv1.Cluster, machine *machinev1.Machi return instances[0], nil } -func (a *Actuator) getMachineInstances(cluster *clusterv1.Cluster, machine *machinev1.Machine) ([]*ec2.Instance, error) { +func (a *Actuator) getMachineInstances(machine *machinev1.Machine) ([]*ec2.Instance, error) { machineProviderConfig, err := providerConfigFromMachine(machine, a.codec) if err != nil { glog.Errorf("%s: Error decoding MachineProviderConfig: %v", machine.Name, err) @@ -658,7 +656,7 @@ func (a *Actuator) updateStatus(machine *machinev1.Machine, instance *ec2.Instan // we get a public IP populated more quickly. if awsStatus.InstanceState != nil && *awsStatus.InstanceState == ec2.InstanceStateNamePending { glog.Infof("%s: Instance state still pending, returning an error to requeue", machine.Name) - return &clustererror.RequeueAfterError{RequeueAfter: requeueAfterSeconds * time.Second} + return &machinecontroller.RequeueAfterError{RequeueAfter: requeueAfterSeconds * time.Second} } return nil } diff --git a/pkg/actuators/machine/actuator_test.go b/pkg/actuators/machine/actuator_test.go index 0c75396504..786061f173 100644 --- a/pkg/actuators/machine/actuator_test.go +++ b/pkg/actuators/machine/actuator_test.go @@ -13,9 +13,8 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/golang/mock/gomock" - clusterv1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1" - machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" - machineapierrors "github.com/openshift/cluster-api/pkg/errors" + machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" + machineapierrors "github.com/openshift/machine-api-operator/pkg/controller/machine" "github.com/stretchr/testify/assert" apiv1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1" @@ -52,7 +51,6 @@ func TestMachineEvents(t *testing.T) { t.Fatal(err) } - cluster := stubCluster() awsCredentialsSecret := stubAwsCredentialsSecret() userDataSecret := stubUserDataSecret() @@ -66,7 +64,7 @@ func TestMachineEvents(t *testing.T) { name string machine *machinev1.Machine error string - operation func(actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) + operation func(actuator *Actuator, machine *machinev1.Machine) event string describeInstancesOutput *ec2.DescribeInstancesOutput describeInstancesErr error @@ -78,8 +76,8 @@ func TestMachineEvents(t *testing.T) { { name: "Create machine event failed (invalid configuration)", machine: machineInvalidProviderConfig, - operation: func(actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.CreateMachine(cluster, machine) + operation: func(actuator *Actuator, machine *machinev1.Machine) { + actuator.CreateMachine(machine) }, event: "Warning FailedCreate error decoding MachineProviderConfig: unable to find machine provider config: Spec.ProviderSpec.Value is not set", }, @@ -87,8 +85,8 @@ func TestMachineEvents(t *testing.T) { name: "Create machine event failed (error creating aws service)", machine: machine, error: awsServiceError, - operation: func(actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.CreateMachine(cluster, machine) + operation: func(actuator *Actuator, machine *machinev1.Machine) { + actuator.CreateMachine(machine) }, event: "Warning FailedCreate error creating aws service", }, @@ -96,8 +94,8 @@ func TestMachineEvents(t *testing.T) { name: "Create machine event failed (error launching instance)", machine: machine, runInstancesErr: fmt.Errorf("error"), - operation: func(actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.CreateMachine(cluster, machine) + operation: func(actuator *Actuator, machine *machinev1.Machine) { + actuator.CreateMachine(machine) }, event: "Warning FailedCreate error creating EC2 instance: error", }, @@ -105,40 +103,40 @@ func TestMachineEvents(t *testing.T) { name: "Create machine event failed (error updating load balancers)", machine: machine, lbErr: fmt.Errorf("lb error"), - operation: func(actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.CreateMachine(cluster, machine) + operation: func(actuator *Actuator, machine *machinev1.Machine) { + actuator.CreateMachine(machine) }, event: "Warning FailedCreate lb error", }, { name: "Create machine event succeed", machine: machine, - operation: func(actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.CreateMachine(cluster, machine) + operation: func(actuator *Actuator, machine *machinev1.Machine) { + actuator.CreateMachine(machine) }, event: "Normal Created Created Machine aws-actuator-testing-machine", }, { name: "Create worker machine event succeed", machine: workerMachine, - operation: func(actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.CreateMachine(cluster, machine) + operation: func(actuator *Actuator, machine *machinev1.Machine) { + actuator.CreateMachine(machine) }, event: "Normal Created Created Machine aws-actuator-testing-machine", }, { name: "Delete machine event failed", machine: machineInvalidProviderConfig, - operation: func(actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.DeleteMachine(cluster, machine) + operation: func(actuator *Actuator, machine *machinev1.Machine) { + actuator.DeleteMachine(machine) }, event: "Warning FailedDelete error decoding MachineProviderConfig: unable to find machine provider config: Spec.ProviderSpec.Value is not set", }, { name: "Delete machine event succeed", machine: machine, - operation: func(actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.DeleteMachine(cluster, machine) + operation: func(actuator *Actuator, machine *machinev1.Machine) { + actuator.DeleteMachine(machine) }, event: "Normal Deleted Deleted machine aws-actuator-testing-machine", }, @@ -187,7 +185,7 @@ func TestMachineEvents(t *testing.T) { t.Fatalf("Could not create AWS machine actuator: %v", err) } - tc.operation(actuator, cluster, tc.machine) + tc.operation(actuator, tc.machine) select { case event := <-eventsChannel: if event != tc.event { @@ -206,7 +204,6 @@ func TestActuator(t *testing.T) { t.Fatal(err) } - cluster := stubCluster() awsCredentialsSecret := stubAwsCredentialsSecret() userDataSecret := stubUserDataSecret() @@ -249,7 +246,7 @@ func TestActuator(t *testing.T) { name string machine *machinev1.Machine error string - operation func(client client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) + operation func(client client.Client, actuator *Actuator, machine *machinev1.Machine) describeInstancesOutput *ec2.DescribeInstancesOutput runInstancesErr error describeInstancesErr error @@ -259,8 +256,8 @@ func TestActuator(t *testing.T) { { name: "Create machine with success", machine: machine, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - createErr := actuator.Create(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + createErr := actuator.Create(context.TODO(), machine) assert.NoError(t, createErr) machineStatus, err := getMachineStatus(objectClient, machine) @@ -271,26 +268,26 @@ func TestActuator(t *testing.T) { assert.Equal(t, machineStatus.Conditions[0].Reason, MachineCreationSucceeded) // Get the machine - if exists, err := actuator.Exists(context.TODO(), cluster, machine); err != nil || !exists { + if exists, err := actuator.Exists(context.TODO(), machine); err != nil || !exists { t.Errorf("Instance for %v does not exists: %v", strings.Join([]string{machine.Namespace, machine.Name}, "/"), err) } else { t.Logf("Instance for %v exists", strings.Join([]string{machine.Namespace, machine.Name}, "/")) } // Update a machine - if err := actuator.Update(context.TODO(), cluster, machine); err != nil { + if err := actuator.Update(context.TODO(), machine); err != nil { t.Errorf("Unable to create instance for machine: %v", err) } // Get the machine - if exists, err := actuator.Exists(context.TODO(), cluster, machine); err != nil || !exists { + if exists, err := actuator.Exists(context.TODO(), machine); err != nil || !exists { t.Errorf("Instance for %v does not exists: %v", strings.Join([]string{machine.Namespace, machine.Name}, "/"), err) } else { t.Logf("Instance for %v exists", strings.Join([]string{machine.Namespace, machine.Name}, "/")) } // Delete a machine - if err := actuator.Delete(context.TODO(), cluster, machine); err != nil { + if err := actuator.Delete(context.TODO(), machine); err != nil { t.Errorf("Unable to delete instance for machine: %v", err) } }, @@ -299,8 +296,8 @@ func TestActuator(t *testing.T) { name: "Create machine with failure", machine: machine, runInstancesErr: fmt.Errorf("error"), - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - createErr := actuator.Create(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + createErr := actuator.Create(context.TODO(), machine) assert.Error(t, createErr) machineStatus, err := getMachineStatus(objectClient, machine) @@ -314,29 +311,29 @@ func TestActuator(t *testing.T) { { name: "Update machine with success", machine: machine, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Update(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Update(context.TODO(), machine) }, }, { name: "Update machine failed (invalid configuration)", machine: machineInvalidProviderConfig, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Update(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Update(context.TODO(), machine) }, }, { name: "Update machine failed (error creating aws service)", error: awsServiceError, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Update(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Update(context.TODO(), machine) }, }, { name: "Update machine failed (error getting running instances)", describeInstancesErr: fmt.Errorf("error"), - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Update(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Update(context.TODO(), machine) }, }, { @@ -348,8 +345,8 @@ func TestActuator(t *testing.T) { }, }, }, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Update(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Update(context.TODO(), machine) }, }, { @@ -364,8 +361,8 @@ func TestActuator(t *testing.T) { }, }, }, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Update(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Update(context.TODO(), machine) }, }, { @@ -379,8 +376,8 @@ func TestActuator(t *testing.T) { }, }, }, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Update(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Update(context.TODO(), machine) }, }, { @@ -396,43 +393,43 @@ func TestActuator(t *testing.T) { }, }, terminateInstancesErr: fmt.Errorf("error"), - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Update(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Update(context.TODO(), machine) }, }, { name: "Update machine with failure (cluster ID missing)", machine: machineNoClusterID, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Update(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Update(context.TODO(), machine) }, }, { name: "Update machine failed (error updating load balancers)", lbErr: fmt.Errorf("error"), - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Update(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Update(context.TODO(), machine) }, }, { name: "Describe machine fails (error getting running instance)", describeInstancesErr: fmt.Errorf("error"), - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Describe(cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Describe(machine) }, }, { name: "Describe machine failed (invalid configuration)", machine: machineInvalidProviderConfig, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Describe(cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Exists(context.TODO(), machine) }, }, { name: "Describe machine failed (error creating aws service)", error: awsServiceError, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Describe(cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Exists(context.TODO(), machine) }, }, { @@ -444,21 +441,21 @@ func TestActuator(t *testing.T) { }, }, }, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Describe(cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Exists(context.TODO(), machine) }, }, { name: "Describe machine succeeds", - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Describe(cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Exists(context.TODO(), machine) }, }, { name: "Exists machine failed (invalid configuration)", machine: machineInvalidProviderConfig, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Exists(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Exists(context.TODO(), machine) }, }, { @@ -470,29 +467,29 @@ func TestActuator(t *testing.T) { }, }, }, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Exists(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Exists(context.TODO(), machine) }, }, { name: "Delete machine failed (invalid configuration)", machine: machineInvalidProviderConfig, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Delete(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Delete(context.TODO(), machine) }, }, { name: "Delete machine failed (error creating aws service)", error: awsServiceError, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Delete(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Delete(context.TODO(), machine) }, }, { name: "Delete machine failed (error getting running instances)", describeInstancesErr: fmt.Errorf("error"), - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Delete(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Delete(context.TODO(), machine) }, }, { @@ -505,16 +502,16 @@ func TestActuator(t *testing.T) { }, }, }, - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Delete(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Delete(context.TODO(), machine) }, }, { name: "Delete machine failed (error terminating instances)", terminateInstancesErr: fmt.Errorf("error"), - operation: func(objectClient client.Client, actuator *Actuator, cluster *clusterv1.Cluster, machine *machinev1.Machine) { - actuator.Delete(context.TODO(), cluster, machine) + operation: func(objectClient client.Client, actuator *Actuator, machine *machinev1.Machine) { + actuator.Delete(context.TODO(), machine) }, }, } @@ -558,9 +555,9 @@ func TestActuator(t *testing.T) { mockAWSClient.EXPECT().ELBv2RegisterTargets(gomock.Any()).Return(nil, nil).AnyTimes() if tc.machine == nil { - tc.operation(fakeClient, actuator, cluster, machine) + tc.operation(fakeClient, actuator, machine) } else { - tc.operation(fakeClient, actuator, cluster, tc.machine) + tc.operation(fakeClient, actuator, tc.machine) } }) } @@ -592,7 +589,6 @@ func TestAvailabilityZone(t *testing.T) { t.Fatalf("unable to build codec: %v", err) } - cluster := stubCluster() awsCredentialsSecret := stubAwsCredentialsSecret() userDataSecret := stubUserDataSecret() @@ -690,7 +686,7 @@ func TestAvailabilityZone(t *testing.T) { mockAWSClient.EXPECT().DescribeAvailabilityZones(gomock.Any()).Return(nil, nil).AnyTimes() mockAWSClient.EXPECT().DescribeSubnets(gomock.Any()).Return(&ec2.DescribeSubnetsOutput{}, nil) - actuator.Create(context.TODO(), cluster, machine) + actuator.Create(context.TODO(), machine) }) } } @@ -1120,7 +1116,7 @@ func TestCreate(t *testing.T) { } // test create - err = actuator.Create(context.TODO(), nil, machine) + err = actuator.Create(context.TODO(), machine) if tc.error != nil { if err == nil { t.Fatalf("Expected error") @@ -1263,7 +1259,7 @@ func TestGetMachineInstances(t *testing.T) { t.Errorf("Error creating Actuator: %v", err) } - instances, err := actuator.getMachineInstances(nil, machineCopy) + instances, err := actuator.getMachineInstances(machineCopy) if err != nil { t.Errorf("Unexpected error from getMachineInstances: %v", err) } diff --git a/pkg/actuators/machine/awsclient.go b/pkg/actuators/machine/awsclient.go index 2061dcf788..96547d914b 100644 --- a/pkg/actuators/machine/awsclient.go +++ b/pkg/actuators/machine/awsclient.go @@ -3,9 +3,7 @@ package machine import ( "fmt" - "github.com/openshift/cluster-api-actuator-pkg/pkg/types" - - machinev1beta1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" + machinev1beta1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/client" ) @@ -14,10 +12,7 @@ type AwsClientWrapper struct { client awsclient.Client } -var _ types.CloudProviderClient = &AwsClientWrapper{} - -// NewAwsClientWrapper returns aws client implementaton of CloudProviderClient -// used for testing in CI environmet +// NewAwsClientWrapper returns aws client implementation func NewAwsClientWrapper(client awsclient.Client) *AwsClientWrapper { return &AwsClientWrapper{client: client} } diff --git a/pkg/actuators/machine/instances.go b/pkg/actuators/machine/instances.go index 4309cf4831..9006469a27 100644 --- a/pkg/actuators/machine/instances.go +++ b/pkg/actuators/machine/instances.go @@ -10,8 +10,8 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/golang/glog" - machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" - mapierrors "github.com/openshift/cluster-api/pkg/errors" + machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" + mapierrors "github.com/openshift/machine-api-operator/pkg/controller/machine" providerconfigv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1" "github.com/aws/aws-sdk-go/aws" diff --git a/pkg/actuators/machine/stubs.go b/pkg/actuators/machine/stubs.go index f4e28396ca..f491607e7d 100644 --- a/pkg/actuators/machine/stubs.go +++ b/pkg/actuators/machine/stubs.go @@ -8,9 +8,8 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/elbv2" - clusterv1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1" - machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" - machinecontroller "github.com/openshift/cluster-api/pkg/controller/machine" + machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" + machinecontroller "github.com/openshift/machine-api-operator/pkg/controller/machine" apiv1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -136,15 +135,6 @@ func stubMachine() (*machinev1.Machine, error) { return machine, nil } -func stubCluster() *clusterv1.Cluster { - return &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: clusterID, - Namespace: defaultNamespace, - }, - } -} - func stubUserDataSecret() *corev1.Secret { return &apiv1.Secret{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/actuators/machine/utils.go b/pkg/actuators/machine/utils.go index ec1a8b11d0..6205123334 100644 --- a/pkg/actuators/machine/utils.go +++ b/pkg/actuators/machine/utils.go @@ -27,7 +27,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" - machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" + machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" "golang.org/x/net/context" "k8s.io/apimachinery/pkg/types" providerconfigv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1" diff --git a/pkg/actuators/machine/utils_test.go b/pkg/actuators/machine/utils_test.go index 7fd7e93cb5..782f0f8f18 100644 --- a/pkg/actuators/machine/utils_test.go +++ b/pkg/actuators/machine/utils_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" + machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" diff --git a/pkg/apis/awsproviderconfig/v1beta1/register.go b/pkg/apis/awsproviderconfig/v1beta1/register.go index 7ce25cb566..1f348d0f3f 100644 --- a/pkg/apis/awsproviderconfig/v1beta1/register.go +++ b/pkg/apis/awsproviderconfig/v1beta1/register.go @@ -28,7 +28,7 @@ import ( "bytes" "fmt" - machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" + machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer" diff --git a/pkg/client/client.go b/pkg/client/client.go index e55504a4d7..6246365da6 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -33,7 +33,7 @@ import ( "github.com/aws/aws-sdk-go/service/elb/elbiface" "github.com/aws/aws-sdk-go/service/elbv2" "github.com/aws/aws-sdk-go/service/elbv2/elbv2iface" - machineapiapierrors "github.com/openshift/cluster-api/pkg/errors" + machineapiapierrors "github.com/openshift/machine-api-operator/pkg/controller/machine" apimachineryerrors "k8s.io/apimachinery/pkg/api/errors" )