Skip to content
Merged
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
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ COPY . .
RUN NO_DOCKER=1 make build

FROM registry.svc.ci.openshift.org/openshift/origin-v4.0:base
COPY --from=builder /go/src/github.com/openshift/machine-api-operator/owned-manifests owned-manifests
COPY --from=builder /go/src/github.com/openshift/machine-api-operator/install manifests
COPY --from=builder /go/src/github.com/openshift/machine-api-operator/bin/machine-api-operator .
COPY --from=builder /go/src/github.com/openshift/machine-api-operator/bin/nodelink-controller .
Expand Down
1 change: 0 additions & 1 deletion Dockerfile.rhel7
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ COPY . .
RUN NO_DOCKER=1 make build

FROM registry.svc.ci.openshift.org/ocp/4.0:base
COPY --from=builder /go/src/github.com/openshift/machine-api-operator/owned-manifests owned-manifests
COPY --from=builder /go/src/github.com/openshift/machine-api-operator/install manifests
COPY --from=builder /go/src/github.com/openshift/machine-api-operator/bin/machine-api-operator .
COPY --from=builder /go/src/github.com/openshift/machine-api-operator/bin/nodelink-controller .
Expand Down
88 changes: 0 additions & 88 deletions owned-manifests/machine-api-controllers.yaml

This file was deleted.

37 changes: 3 additions & 34 deletions pkg/operator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"fmt"
"io/ioutil"

"bytes"
"text/template"

configv1 "github.com/openshift/api/config/v1"
)

Expand All @@ -27,10 +24,9 @@ type OperatorConfig struct {
}

type Controllers struct {
Provider string
NodeLink string
MachineHealthCheck string
MachineHealthCheckEnabled bool
Provider string
NodeLink string
MachineHealthCheck string
}

// Images allows build systems to inject images for MAO components
Expand Down Expand Up @@ -88,30 +84,3 @@ func getMachineAPIOperatorFromImages(images Images) (string, error) {
}
return images.MachineAPIOperator, nil
}

// PopulateTemplate receives a template file path and renders its content populated with the config
func PopulateTemplate(config *OperatorConfig, path string) ([]byte, error) {

data, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed reading file, %v", err)
}

buf := &bytes.Buffer{}
tmpl, err := template.New("").Option("missingkey=error").Parse(string(data))
if err != nil {
return nil, err
}

tmplData := struct {
OperatorConfig
}{
OperatorConfig: *config,
}

if err := tmpl.Execute(buf, tmplData); err != nil {
return nil, err
}

return buf.Bytes(), nil
}
63 changes: 0 additions & 63 deletions pkg/operator/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/cluster-version-operator/lib/resourceread"
)

var (
Expand Down Expand Up @@ -182,65 +181,3 @@ func TestGetMachineAPIOperatorFromImages(t *testing.T) {
t.Errorf("failed getMachineAPIOperatorFromImages. Expected: %s, got: %s", expectedMachineAPIOperatorImage, res)
}
}

func TestPopulateTemplateMachineHealthCheckControllerEnabled(t *testing.T) {
oc := &OperatorConfig{
TargetNamespace: "test-namespace",
Controllers: Controllers{
Provider: "controllers-provider",
NodeLink: "controllers-nodelink",
MachineHealthCheck: "controllers-machinehealthcheck",
MachineHealthCheckEnabled: true,
},
}
controllerBytes, err := PopulateTemplate(oc, "../../owned-manifests/machine-api-controllers.yaml")
if err != nil {
t.Errorf("failed to populate template: %v", err)
}

controller := resourceread.ReadDeploymentV1OrDie(controllerBytes)
hcControllerFound := false
hcControllerName := "machine-healthcheck-controller"
for _, container := range controller.Spec.Template.Spec.Containers {
if container.Name == hcControllerName {
hcControllerFound = true
break
}
}
if !hcControllerFound {
t.Errorf("failed to find %q container in %q deployment", hcControllerName, controller.Name)
} else {
t.Logf("found %q container in %q deployment", hcControllerName, controller.Name)
}
}

func TestPopulateTemplateMachineHealthCheckControllerDisabled(t *testing.T) {
oc := &OperatorConfig{
TargetNamespace: "test-namespace",
Controllers: Controllers{
Provider: "controllers-provider",
NodeLink: "controllers-nodelink",
MachineHealthCheck: "controllers-machinehealthcheck",
MachineHealthCheckEnabled: false,
},
}
controllerBytes, err := PopulateTemplate(oc, "../../owned-manifests/machine-api-controllers.yaml")
if err != nil {
t.Errorf("failed to populate template: %v", err)
}

controller := resourceread.ReadDeploymentV1OrDie(controllerBytes)
hcControllerFound := false
hcControllerName := "machine-healthcheck-controller"
for _, container := range controller.Spec.Template.Spec.Containers {
if container.Name == hcControllerName {
hcControllerFound = true
break
}
}
if hcControllerFound {
t.Errorf("did not expect to find %q container in %q deployment", hcControllerName, controller.Name)
} else {
t.Logf("did not found %q container in %q deployment", hcControllerName, controller.Name)
}
}
27 changes: 12 additions & 15 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ const (
// a machineconfig pool is going to be requeued:
//
// 5ms, 10ms, 20ms, 40ms, 80ms, 160ms, 320ms, 640ms, 1.3s, 2.6s, 5.1s, 10.2s, 20.4s, 41s, 82s
maxRetries = 15
ownedManifestsDir = "owned-manifests"
maxRetries = 15
)

// Operator defines machine api operator.
type Operator struct {
namespace, name string

imagesFile string
config string
ownedManifestsDir string
imagesFile string
config string

kubeClient kubernetes.Interface
osClient osclientset.Interface
Expand Down Expand Up @@ -79,15 +77,14 @@ func New(
}

optr := &Operator{
namespace: namespace,
name: name,
imagesFile: imagesFile,
ownedManifestsDir: ownedManifestsDir,
kubeClient: kubeClient,
osClient: osClient,
eventRecorder: recorder,
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "machineapioperator"),
operandVersions: operandVersions,
namespace: namespace,
name: name,
imagesFile: imagesFile,
kubeClient: kubeClient,
osClient: osClient,
eventRecorder: recorder,
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "machineapioperator"),
operandVersions: operandVersions,
}

deployInformer.Informer().AddEventHandler(optr.eventHandler())
Expand Down Expand Up @@ -184,7 +181,7 @@ func (optr *Operator) sync(key string) error {
glog.Errorf("Failed getting operator config: %v", err)
return err
}
return optr.syncAll(*operatorConfig)
return optr.syncAll(operatorConfig)
}

func (optr *Operator) maoConfigFromInfrastructure() (*OperatorConfig, error) {
Expand Down
Loading