Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions pkg/controller/machinepool/ibmcloudactuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import (
"github.com/stretchr/testify/require"

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

configv1 "github.com/openshift/api/config/v1"
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
ibmcloudprovider "github.com/openshift/machine-api-provider-ibmcloud/pkg/apis/ibmcloudprovider/v1"

hivev1 "github.com/openshift/hive/apis/hive/v1"
Expand Down Expand Up @@ -168,6 +172,94 @@ func TestIBMCloudActuator(t *testing.T) {
}
}

func TestIBMCloudMatchMachineSets(t *testing.T) {
tests := []struct {
name string
generated *machinev1beta1.MachineSet
remote *machinev1beta1.MachineSet
expectMatch bool
expectErr bool
}{
{
name: "Zones match",
generated: testIBMCloudMachineSet("1"),
remote: testIBMCloudMachineSet("1"),
expectMatch: true,
},
{
name: "Zones do not match",
generated: testIBMCloudMachineSet("1"),
remote: testIBMCloudMachineSet("2"),
},
{
name: "bogus generated mset",
generated: &machinev1beta1.MachineSet{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
machinePoolNameLabel: "a-pool",
},
},
},
remote: testIBMCloudMachineSet("2"),
expectErr: true,
},
{
name: "bogus remote mset",
generated: testIBMCloudMachineSet("2"),
remote: &machinev1beta1.MachineSet{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
machinePoolNameLabel: "a-pool",
},
},
},
expectErr: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
infra := &configv1.Infrastructure{
Spec: configv1.InfrastructureSpec{
PlatformSpec: configv1.PlatformSpec{
Type: configv1.IBMCloudPlatformType,
},
},
}
match, err := matchMachineSets(test.generated, *test.remote, infra, log.New())
if test.expectErr {
assert.Error(t, err, "expected error for test case")
} else {
assert.NoError(t, err, "unexpected error for test case")
assert.Equal(t, test.expectMatch, match, "unexpected match result")
}
})
}
}

// This is super simple and fit-for-purpose right now.
func testIBMCloudMachineSet(zone string) *machinev1beta1.MachineSet {
return &machinev1beta1.MachineSet{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
machinePoolNameLabel: "a-pool",
},
},
Spec: machinev1beta1.MachineSetSpec{
Template: machinev1beta1.MachineTemplateSpec{
Spec: machinev1beta1.MachineSpec{
ProviderSpec: machinev1beta1.ProviderSpec{
Value: &runtime.RawExtension{
Object: &ibmcloudprovider.IBMCloudMachineProviderSpec{
Zone: zone,
},
},
},
},
},
},
}
}

func testIBMCloudPool() *hivev1.MachinePool {
p := testMachinePool()
p.Spec.Platform = hivev1.MachinePoolPlatform{
Expand Down
17 changes: 16 additions & 1 deletion pkg/controller/machinepool/machinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
cpms "github.com/openshift/cluster-control-plane-machine-set-operator/pkg/machineproviders/providers/openshift/machine/v1beta1/providerconfig"
installertypes "github.com/openshift/installer/pkg/types"
"github.com/openshift/library-go/pkg/operator/resource/resourcemerge"
ibmcloudprovider "github.com/openshift/machine-api-provider-ibmcloud/pkg/apis/ibmcloudprovider/v1"

hivev1 "github.com/openshift/hive/apis/hive/v1"
"github.com/openshift/hive/pkg/awsclient"
Expand Down Expand Up @@ -685,11 +686,25 @@ func matchFailureDomains(gMS *machineapi.MachineSet, rMS machineapi.MachineSet,
if gSpec.ProviderSpec.Value.Raw == nil {
gSpec.ProviderSpec.Value.Raw, err = json.Marshal(gMS.Spec.Template.Spec.ProviderSpec.Value.Object)
if err != nil {
logger.WithError(err).Error("unable to marshal generate ms provider spec object to raw value")
logger.WithError(err).Error("unable to marshal generated ms provider spec object to raw value")
return false, err
}
}

// SNOWFLAKE! CPMS does not support IBMCloud, so we have to roll our own matcher. HIVE-3002.
if infrastructure.Spec.PlatformSpec.Type == configv1.IBMCloudPlatformType {
rPS := &ibmcloudprovider.IBMCloudMachineProviderSpec{}
gPS := &ibmcloudprovider.IBMCloudMachineProviderSpec{}
// Non-strict
if err := json.Unmarshal(rSpec.ProviderSpec.Value.Raw, rPS); err != nil {
return false, errors.Wrap(err, "failed to unmarshal providerSpec for remote MachineSet")
}
if err := json.Unmarshal(gSpec.ProviderSpec.Value.Raw, gPS); err != nil {
return false, errors.Wrap(err, "failed to unmarshal providerSpec for generated MachineSet")
}
return rPS.Zone == gPS.Zone, nil
}

// - The provider config funcs take a different kind of logger. Convert.
logr := logrus.NewLogr(logger)
rMS_providerconfig, err := cpms.NewProviderConfigFromMachineSpec(logr, rSpec, infrastructure)
Expand Down