Skip to content

Commit

Permalink
Rename [Encode|Decode]ProviderConfig to [Encode|Decode]ProviderSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
ingvagabund committed Jan 10, 2019
1 parent a1ad91d commit 79fc4a4
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions pkg/actuators/machine/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func TestAvailabiltyZone(t *testing.T) {
}

machinePc := &providerconfigv1.AWSMachineProviderConfig{}
if err = codec.DecodeProviderConfig(&machine.Spec.ProviderSpec, machinePc); err != nil {
if err = codec.DecodeProviderSpec(&machine.Spec.ProviderSpec, machinePc); err != nil {
t.Fatal(err)
}

Expand All @@ -613,7 +613,7 @@ func TestAvailabiltyZone(t *testing.T) {
machinePc.Subnet.ID = aws.String(tc.subnet)
}

config, err := codec.EncodeProviderConfig(machinePc)
config, err := codec.EncodeProviderSpec(machinePc)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/actuators/machine/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ func stubMachine() (*clusterv1.Machine, error) {
if err != nil {
return nil, fmt.Errorf("failed creating codec: %v", err)
}
config, err := codec.EncodeProviderConfig(machinePc)
providerSpec, err := codec.EncodeProviderSpec(machinePc)
if err != nil {
return nil, fmt.Errorf("codec.EncodeProviderConfig failed: %v", err)
return nil, fmt.Errorf("codec.EncodeProviderSpec failed: %v", err)
}

machine := &clusterv1.Machine{
Expand All @@ -120,7 +120,7 @@ func stubMachine() (*clusterv1.Machine, error) {
},

Spec: clusterv1.MachineSpec{
ProviderSpec: *config,
ProviderSpec: *providerSpec,
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/actuators/machine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func providerConfigFromMachine(client client.Client, machine *clusterv1.Machine,
}

var config providerconfigv1.AWSMachineProviderConfig
if err := codec.DecodeProviderConfig(&clusterv1.ProviderSpec{Value: &providerSpecRawExtention}, &config); err != nil {
if err := codec.DecodeProviderSpec(&clusterv1.ProviderSpec{Value: &providerSpecRawExtention}, &config); err != nil {
return nil, err
}
return &config, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/actuators/machine/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestProviderConfigFromMachine(t *testing.T) {
if err != nil {
t.Error(err)
}
encodedProviderConfig, err := codec.EncodeProviderConfig(providerConfig)
encodedProviderSpec, err := codec.EncodeProviderSpec(providerConfig)
if err != nil {
t.Error(err)
}
Expand All @@ -60,7 +60,7 @@ func TestProviderConfigFromMachine(t *testing.T) {
Namespace: "openshift-cluster-api",
Name: "testClass",
},
ProviderSpec: *encodedProviderConfig.Value,
ProviderSpec: *encodedProviderSpec.Value,
}

testCases := []struct {
Expand All @@ -79,7 +79,7 @@ func TestProviderConfigFromMachine(t *testing.T) {
Kind: "Machine",
},
Spec: clusterv1.MachineSpec{
ProviderSpec: *encodedProviderConfig,
ProviderSpec: *encodedProviderSpec,
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/awsproviderconfig/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func NewCodec() (*AWSProviderConfigCodec, error) {
return &codec, nil
}

// DecodeProviderConfig deserialises an object from the provider config
func (codec *AWSProviderConfigCodec) DecodeProviderConfig(providerSpec *clusterv1.ProviderSpec, out runtime.Object) error {
// DecodeProviderSpec deserialises an object from the provider config
func (codec *AWSProviderConfigCodec) DecodeProviderSpec(providerSpec *clusterv1.ProviderSpec, out runtime.Object) error {
if providerSpec.Value != nil {
_, _, err := codec.decoder.Decode(providerSpec.Value.Raw, nil, out)
if err != nil {
Expand All @@ -84,8 +84,8 @@ func (codec *AWSProviderConfigCodec) DecodeProviderConfig(providerSpec *clusterv
return nil
}

// EncodeProviderConfig serialises an object to the provider config
func (codec *AWSProviderConfigCodec) EncodeProviderConfig(in runtime.Object) (*clusterv1.ProviderSpec, error) {
// EncodeProviderSpec serialises an object to the provider config
func (codec *AWSProviderConfigCodec) EncodeProviderSpec(in runtime.Object) (*clusterv1.ProviderSpec, error) {
var buf bytes.Buffer
if err := codec.encoder.Encode(in, &buf); err != nil {
return nil, fmt.Errorf("encoding failed: %v", err)
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/awsproviderconfig/v1alpha1/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestEncodeAndDecodeProviderStatus(t *testing.T) {
}
}

func TestEncodeAndDecodeProviderConfig(t *testing.T) {
func TestEncodeAndDecodeProviderSpec(t *testing.T) {
codec, err := NewCodec()
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -155,28 +155,28 @@ func TestEncodeAndDecodeProviderConfig(t *testing.T) {
},
}

providerConfigEncoded, err := codec.EncodeProviderConfig(providerConfig)
providerConfigEncoded, err := codec.EncodeProviderSpec(providerConfig)
if err != nil {
t.Fatal(err)
}

// Without deep copy
{
providerConfigDecoded := &AWSMachineProviderConfig{}
codec.DecodeProviderConfig(providerConfigEncoded, providerConfigDecoded)
codec.DecodeProviderSpec(providerConfigEncoded, providerConfigDecoded)

if !reflect.DeepEqual(providerConfig, providerConfigDecoded) {
t.Errorf("failed EncodeProviderConfig/DecodeProviderConfig. Expected: %+v, got: %+v", providerConfig, providerConfigDecoded)
t.Errorf("failed EncodeProviderSpec/DecodeProviderSpec. Expected: %+v, got: %+v", providerConfig, providerConfigDecoded)
}
}

// With deep copy
{
providerConfigDecoded := &AWSMachineProviderConfig{}
codec.DecodeProviderConfig(providerConfigEncoded, providerConfigDecoded)
codec.DecodeProviderSpec(providerConfigEncoded, providerConfigDecoded)

if !reflect.DeepEqual(providerConfig.DeepCopy(), providerConfigDecoded) {
t.Errorf("failed EncodeProviderConfig/DecodeProviderConfig. Expected: %+v, got: %+v", providerConfig, providerConfigDecoded)
t.Errorf("failed EncodeProviderSpec/DecodeProviderSpec. Expected: %+v, got: %+v", providerConfig, providerConfigDecoded)
}
}
}
18 changes: 9 additions & 9 deletions test/utils/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ func TestingMachineProviderSpec(awsCredentialsSecretName string, clusterID strin
if err != nil {
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("failed creating codec: %v", err)
}
config, err := codec.EncodeProviderConfig(machinePc)
providerSpec, err := codec.EncodeProviderSpec(machinePc)
if err != nil {
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("EncodeToProviderConfig failed: %v", err)
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("codec.EncodeProviderSpec failed: %v", err)
}
return *config, nil
return *providerSpec, nil
}

func MasterMachineProviderSpec(awsCredentialsSecretName, masterUserDataSecretName, clusterID string) (clusterv1alpha1.ProviderSpec, error) {
Expand Down Expand Up @@ -153,11 +153,11 @@ func MasterMachineProviderSpec(awsCredentialsSecretName, masterUserDataSecretNam
if err != nil {
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("failed creating codec: %v", err)
}
config, err := codec.EncodeProviderConfig(machinePc)
providerSpec, err := codec.EncodeProviderSpec(machinePc)
if err != nil {
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("EncodeToProviderConfig failed: %v", err)
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("codec.EncodeProviderSpec failed: %v", err)
}
return *config, nil
return *providerSpec, nil
}

func WorkerMachineSetProviderSpec(awsCredentialsSecretName, workerUserDataSecretName, clusterID string) (clusterv1alpha1.ProviderSpec, error) {
Expand Down Expand Up @@ -215,9 +215,9 @@ func WorkerMachineSetProviderSpec(awsCredentialsSecretName, workerUserDataSecret
if err != nil {
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("failed creating codec: %v", err)
}
config, err := codec.EncodeProviderConfig(machinePc)
providerSpec, err := codec.EncodeProviderSpec(machinePc)
if err != nil {
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("EncodeToProviderConfig failed: %v", err)
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("codec.EncodeProviderSpec failed: %v", err)
}
return *config, nil
return *providerSpec, nil
}

0 comments on commit 79fc4a4

Please sign in to comment.