Skip to content

Commit

Permalink
Merge pull request #206 from enxebre/revendor-cluster-api
Browse files Browse the repository at this point in the history
Revendor cluster api
  • Loading branch information
openshift-merge-robot authored Apr 30, 2019
2 parents 626e07a + ad204d3 commit 4bd68c6
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 445 deletions.
12 changes: 8 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,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 *machinev1.Cluster, machine *machinev1.Machine) (*ec2.Instance, error) {
machineProviderConfig, err := providerConfigFromMachine(a.client, machine, a.codec)
machineProviderConfig, err := providerConfigFromMachine(machine, a.codec)
if err != nil {
return nil, a.handleMachineError(machine, apierrors.InvalidMachineConfiguration("error decoding MachineProviderConfig: %v", err), createEventAction)
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func (gl *glogLogger) Logf(format string, v ...interface{}) {

// DeleteMachine deletes an AWS instance
func (a *Actuator) DeleteMachine(cluster *machinev1.Cluster, machine *machinev1.Machine) error {
machineProviderConfig, err := providerConfigFromMachine(a.client, machine, a.codec)
machineProviderConfig, err := providerConfigFromMachine(machine, a.codec)
if err != nil {
return a.handleMachineError(machine, apierrors.InvalidMachineConfiguration("error decoding MachineProviderConfig: %v", err), deleteEventAction)
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func (a *Actuator) DeleteMachine(cluster *machinev1.Cluster, machine *machinev1.
func (a *Actuator) Update(context context.Context, cluster *machinev1.Cluster, machine *machinev1.Machine) error {
glog.Info("updating machine")

machineProviderConfig, err := providerConfigFromMachine(a.client, machine, a.codec)
machineProviderConfig, err := providerConfigFromMachine(machine, a.codec)
if err != nil {
return a.handleMachineError(machine, apierrors.InvalidMachineConfiguration("error decoding MachineProviderConfig: %v", err), updateEventAction)
}
Expand Down Expand Up @@ -409,7 +409,7 @@ func (a *Actuator) Describe(cluster *machinev1.Cluster, machine *machinev1.Machi
}

func (a *Actuator) getMachineInstances(cluster *machinev1.Cluster, machine *machinev1.Machine) ([]*ec2.Instance, error) {
machineProviderConfig, err := providerConfigFromMachine(a.client, machine, a.codec)
machineProviderConfig, err := providerConfigFromMachine(machine, a.codec)
if err != nil {
glog.Errorf("Error decoding MachineProviderConfig: %v", err)
return nil, err
Expand Down
2 changes: 0 additions & 2 deletions pkg/actuators/machine/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func TestMachineEvents(t *testing.T) {

machineInvalidProviderConfig := machine.DeepCopy()
machineInvalidProviderConfig.Spec.ProviderSpec.Value = nil
machineInvalidProviderConfig.Spec.ProviderSpec.ValueFrom = nil

workerMachine := machine.DeepCopy()
workerMachine.Spec.Labels["node-role.kubernetes.io/worker"] = ""
Expand Down Expand Up @@ -232,7 +231,6 @@ func TestActuator(t *testing.T) {

machineInvalidProviderConfig := machine.DeepCopy()
machineInvalidProviderConfig.Spec.ProviderSpec.Value = nil
machineInvalidProviderConfig.Spec.ProviderSpec.ValueFrom = nil

machineNoClusterID := machine.DeepCopy()
delete(machineNoClusterID.Labels, providerconfigv1.ClusterIDLabel)
Expand Down
31 changes: 4 additions & 27 deletions pkg/actuators/machine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
Expand All @@ -32,7 +31,6 @@ import (
"k8s.io/apimachinery/pkg/types"
providerconfigv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1"
awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// getRunningInstance returns the AWS instance for a given machine. If multiple instances match our machine,
Expand Down Expand Up @@ -149,34 +147,13 @@ func terminateInstances(client awsclient.Client, instances []*ec2.Instance) erro

// providerConfigFromMachine gets the machine provider config MachineSetSpec from the
// specified cluster-api MachineSpec.
func providerConfigFromMachine(client client.Client, machine *machinev1.Machine, codec *providerconfigv1.AWSProviderConfigCodec) (*providerconfigv1.AWSMachineProviderConfig, error) {
var providerSpecRawExtention runtime.RawExtension

providerSpec := machine.Spec.ProviderSpec
if providerSpec.Value == nil && providerSpec.ValueFrom == nil {
return nil, fmt.Errorf("unable to find machine provider config: neither Spec.ProviderSpec.Value nor Spec.ProviderSpec.ValueFrom set")
}

// If no providerSpec.Value then we lookup for machineClass
if providerSpec.Value != nil {
providerSpecRawExtention = *providerSpec.Value
} else {
if providerSpec.ValueFrom.MachineClass == nil {
return nil, fmt.Errorf("unable to find MachineClass on Spec.ProviderSpec.ValueFrom")
}
machineClass := &machinev1.MachineClass{}
key := types.NamespacedName{
Namespace: providerSpec.ValueFrom.MachineClass.Namespace,
Name: providerSpec.ValueFrom.MachineClass.Name,
}
if err := client.Get(context.Background(), key, machineClass); err != nil {
return nil, err
}
providerSpecRawExtention = machineClass.ProviderSpec
func providerConfigFromMachine(machine *machinev1.Machine, codec *providerconfigv1.AWSProviderConfigCodec) (*providerconfigv1.AWSMachineProviderConfig, error) {
if machine.Spec.ProviderSpec.Value == nil {
return nil, fmt.Errorf("unable to find machine provider config: Spec.ProviderSpec.Value is not set")
}

var config providerconfigv1.AWSMachineProviderConfig
if err := codec.DecodeProviderSpec(&machinev1.ProviderSpec{Value: &providerSpecRawExtention}, &config); err != nil {
if err := codec.DecodeProviderSpec(&machine.Spec.ProviderSpec, &config); err != nil {
return nil, err
}
return &config, nil
Expand Down
39 changes: 1 addition & 38 deletions pkg/actuators/machine/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
providerconfigv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func init() {
Expand Down Expand Up @@ -55,14 +54,6 @@ func TestProviderConfigFromMachine(t *testing.T) {
t.Error(err)
}

machineClass := &machinev1.MachineClass{
ObjectMeta: metav1.ObjectMeta{
Namespace: "openshift-cluster-api",
Name: "testClass",
},
ProviderSpec: *encodedProviderSpec.Value,
}

testCases := []struct {
machine *machinev1.Machine
}{
Expand All @@ -83,38 +74,10 @@ func TestProviderConfigFromMachine(t *testing.T) {
},
},
},
{
machine: &machinev1.Machine{
ObjectMeta: metav1.ObjectMeta{
Name: "configFromClass",
Namespace: "",
Labels: map[string]string{
"foo": "a",
},
},
TypeMeta: metav1.TypeMeta{
Kind: "Machine",
},
Spec: machinev1.MachineSpec{
ProviderSpec: machinev1.ProviderSpec{
ValueFrom: &machinev1.ProviderSpecSource{
MachineClass: &machinev1.MachineClassRef{
ObjectReference: &corev1.ObjectReference{
Kind: "MachineClass",
Name: "testClass",
Namespace: "openshift-cluster-api",
},
},
},
},
},
},
},
}

client := fake.NewFakeClient(machineClass)
for _, tc := range testCases {
decodedProviderConfig, err := providerConfigFromMachine(client, tc.machine, codec)
decodedProviderConfig, err := providerConfigFromMachine(tc.machine, codec)
if err != nil {
t.Error(err)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4bd68c6

Please sign in to comment.