Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OCPCLOUD-815] Use MachineSet controller from MAO image #546

Merged
merged 2 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/google/uuid v1.1.1
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/onsi/gomega v1.8.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:face_with_raised_eyebrow:

github.com/openshift/api v0.0.0-20200323095748-e7041f8762a3
github.com/openshift/client-go v0.0.0-20200320150128-a906f3d8e723
github.com/openshift/library-go v0.0.0-20200324092245-db2a8546af81
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/baremetal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func newOperatorWithBaremetalConfig() *OperatorConfig {
"docker.io/openshift/origin-aws-machine-controllers:v4.0.0",
"docker.io/openshift/origin-machine-api-operator:v4.0.0",
"docker.io/openshift/origin-machine-api-operator:v4.0.0",
"docker.io/openshift/origin-machine-api-operator:v4.0.0",
"docker.io/openshift/origin-aws-machine-controllers:v4.0.0",
},
BaremetalControllers{
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type OperatorConfig struct {

type Controllers struct {
Provider string
MachineSet string
NodeLink string
MachineHealthCheck string
TerminationHandler string
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func (optr *Operator) maoConfigFromInfrastructure() (*OperatorConfig, error) {
TargetNamespace: optr.namespace,
Controllers: Controllers{
Provider: providerControllerImage,
MachineSet: machineAPIOperatorImage,
NodeLink: machineAPIOperatorImage,
MachineHealthCheck: machineAPIOperatorImage,
TerminationHandler: terminationHandlerImage,
Expand Down
265 changes: 265 additions & 0 deletions pkg/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ package operator

import (
"context"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"syscall"
"testing"
"time"

. "github.com/onsi/gomega"
openshiftv1 "github.com/openshift/api/config/v1"
fakeos "github.com/openshift/client-go/config/clientset/versioned/fake"
configinformersv1 "github.com/openshift/client-go/config/informers/externalversions"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
fakedynamic "k8s.io/client-go/dynamic/fake"
"k8s.io/client-go/informers"
Expand Down Expand Up @@ -235,3 +243,260 @@ func TestIsOwned(t *testing.T) {
})
}
}

// TestMAOConfigFromInfrastructure tests that the expected config comes back
// for the given infrastructure
func TestMAOConfigFromInfrastructure(t *testing.T) {
g := NewWithT(t)
file, err := ioutil.ReadFile("fixtures/images.json")
g.Expect(err).ToNot(HaveOccurred())
images := &Images{}
g.Expect(json.Unmarshal(file, images)).To(Succeed())
// Make sure the images struct has been populated
g.Expect(images.MachineAPIOperator).ToNot(BeEmpty())

infra := &openshiftv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster",
},
}

testCases := []struct {
name string
platform openshiftv1.PlatformType
infra *openshiftv1.Infrastructure
imagesFile string
expectedConfig *OperatorConfig
expectedError error
}{
{
name: string(openshiftv1.AWSPlatformType),
platform: openshiftv1.AWSPlatformType,
infra: infra,
expectedConfig: &OperatorConfig{
TargetNamespace: targetNamespace,
Controllers: Controllers{
Provider: images.ClusterAPIControllerAWS,
MachineSet: images.MachineAPIOperator,
NodeLink: images.MachineAPIOperator,
MachineHealthCheck: images.MachineAPIOperator,
TerminationHandler: images.ClusterAPIControllerAWS,
},
},
},
{
name: string(openshiftv1.LibvirtPlatformType),
platform: openshiftv1.LibvirtPlatformType,
infra: infra,
expectedConfig: &OperatorConfig{
TargetNamespace: targetNamespace,
Controllers: Controllers{
Provider: images.ClusterAPIControllerLibvirt,
MachineSet: images.MachineAPIOperator,
NodeLink: images.MachineAPIOperator,
MachineHealthCheck: images.MachineAPIOperator,
TerminationHandler: clusterAPIControllerNoOp,
},
},
},
{
name: string(openshiftv1.OpenStackPlatformType),
platform: openshiftv1.OpenStackPlatformType,
infra: infra,
expectedConfig: &OperatorConfig{
TargetNamespace: targetNamespace,
Controllers: Controllers{
Provider: images.ClusterAPIControllerOpenStack,
MachineSet: images.MachineAPIOperator,
NodeLink: images.MachineAPIOperator,
MachineHealthCheck: images.MachineAPIOperator,
TerminationHandler: clusterAPIControllerNoOp,
},
},
},
{
name: string(openshiftv1.AzurePlatformType),
platform: openshiftv1.AzurePlatformType,
infra: infra,
expectedConfig: &OperatorConfig{
TargetNamespace: targetNamespace,
Controllers: Controllers{
Provider: images.ClusterAPIControllerAzure,
MachineSet: images.MachineAPIOperator,
NodeLink: images.MachineAPIOperator,
MachineHealthCheck: images.MachineAPIOperator,
TerminationHandler: clusterAPIControllerNoOp,
},
},
},
{
name: string(openshiftv1.BareMetalPlatformType),
platform: openshiftv1.BareMetalPlatformType,
infra: infra,
expectedConfig: &OperatorConfig{
TargetNamespace: targetNamespace,
Controllers: Controllers{
Provider: images.ClusterAPIControllerBareMetal,
MachineSet: images.MachineAPIOperator,
NodeLink: images.MachineAPIOperator,
MachineHealthCheck: images.MachineAPIOperator,
TerminationHandler: clusterAPIControllerNoOp,
},
BaremetalControllers: BaremetalControllers{
BaremetalOperator: images.BaremetalOperator,
Ironic: images.BaremetalIronic,
IronicInspector: images.BaremetalIronicInspector,
IronicIpaDownloader: images.BaremetalIpaDownloader,
IronicMachineOsDownloader: images.BaremetalMachineOsDownloader,
IronicStaticIpManager: images.BaremetalStaticIpManager,
},
},
},
{
name: string(openshiftv1.GCPPlatformType),
platform: openshiftv1.GCPPlatformType,
infra: infra,
expectedConfig: &OperatorConfig{
TargetNamespace: targetNamespace,
Controllers: Controllers{
Provider: images.ClusterAPIControllerGCP,
MachineSet: images.MachineAPIOperator,
NodeLink: images.MachineAPIOperator,
MachineHealthCheck: images.MachineAPIOperator,
TerminationHandler: clusterAPIControllerNoOp,
},
},
},
{
name: string(kubemarkPlatform),
platform: kubemarkPlatform,
infra: infra,
expectedConfig: &OperatorConfig{
TargetNamespace: targetNamespace,
Controllers: Controllers{
Provider: clusterAPIControllerKubemark,
MachineSet: images.MachineAPIOperator,
NodeLink: images.MachineAPIOperator,
MachineHealthCheck: images.MachineAPIOperator,
TerminationHandler: clusterAPIControllerNoOp,
},
},
},
{
name: string(openshiftv1.VSpherePlatformType),
platform: openshiftv1.VSpherePlatformType,
infra: infra,
expectedConfig: &OperatorConfig{
TargetNamespace: targetNamespace,
Controllers: Controllers{
Provider: images.ClusterAPIControllerVSphere,
MachineSet: images.MachineAPIOperator,
NodeLink: images.MachineAPIOperator,
MachineHealthCheck: images.MachineAPIOperator,
TerminationHandler: clusterAPIControllerNoOp,
},
},
},
{
name: string(openshiftv1.OvirtPlatformType),
platform: openshiftv1.OvirtPlatformType,
infra: infra,
expectedConfig: &OperatorConfig{
TargetNamespace: targetNamespace,
Controllers: Controllers{
Provider: images.ClusterAPIControllerOvirt,
MachineSet: images.MachineAPIOperator,
NodeLink: images.MachineAPIOperator,
MachineHealthCheck: images.MachineAPIOperator,
TerminationHandler: clusterAPIControllerNoOp,
},
},
},
{
name: string(openshiftv1.NonePlatformType),
platform: openshiftv1.NonePlatformType,
infra: infra,
expectedConfig: &OperatorConfig{
TargetNamespace: targetNamespace,
Controllers: Controllers{
Provider: clusterAPIControllerNoOp,
MachineSet: images.MachineAPIOperator,
NodeLink: images.MachineAPIOperator,
MachineHealthCheck: images.MachineAPIOperator,
TerminationHandler: clusterAPIControllerNoOp,
},
},
},
{
name: "bad-platform",
platform: "bad-platform",
infra: infra,
expectedConfig: &OperatorConfig{
TargetNamespace: targetNamespace,
Controllers: Controllers{
Provider: clusterAPIControllerNoOp,
MachineSet: images.MachineAPIOperator,
NodeLink: images.MachineAPIOperator,
MachineHealthCheck: images.MachineAPIOperator,
TerminationHandler: clusterAPIControllerNoOp,
},
},
},
{
name: "no-infra",
platform: "no-infra",
infra: nil,
expectedConfig: nil,
expectedError: kerrors.NewNotFound(schema.GroupResource{Group: "config.openshift.io", Resource: "infrastructures"}, "cluster"),
},
{
name: "no-platform",
platform: "",
infra: infra,
expectedConfig: nil,
expectedError: errors.New("no platform provider found on install config"),
},
{
name: "no-images-file",
platform: openshiftv1.NonePlatformType,
infra: infra,
imagesFile: "fixtures/not-found.json",
expectedConfig: nil,
expectedError: &os.PathError{Op: "open", Path: "fixtures/not-found.json", Err: syscall.ENOENT},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)

objects := []runtime.Object{}
if tc.infra != nil {
inf := tc.infra.DeepCopy()
// Ensure platform is correct on infrastructure
inf.Status.Platform = tc.platform
objects = append(objects, inf)
}

stopCh := make(<-chan struct{})
optr := newFakeOperator(nil, objects, stopCh)
optr.queue.Add("trigger")

if tc.imagesFile != "" {
optr.imagesFile = tc.imagesFile
}

go optr.Run(1, stopCh)

config, err := optr.maoConfigFromInfrastructure()

if tc.expectedError != nil {
g.Expect(err).To(MatchError(tc.expectedError))
} else {
g.Expect(err).To(BeNil())
}

g.Expect(config).To(Equal(tc.expectedConfig))
})
}
}
2 changes: 1 addition & 1 deletion pkg/operator/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func newContainers(config *OperatorConfig, features map[string]bool) []corev1.Co
containers := []corev1.Container{
{
Name: "controller-manager",
Image: config.Controllers.Provider,
Image: config.Controllers.MachineSet,
Command: []string{"/manager"},
Args: args,
Resources: resources,
Expand Down