Skip to content

Commit

Permalink
Make ctrlcommon the canonical name for importing `pkg/controller/co…
Browse files Browse the repository at this point in the history
…mmon`
  • Loading branch information
LorbusChris committed Feb 13, 2020
1 parent 106b436 commit 65c5038
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 36 deletions.
10 changes: 5 additions & 5 deletions cmd/machine-config-controller/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/golang/glog"
"github.com/openshift/machine-config-operator/cmd/common"
"github.com/openshift/machine-config-operator/internal/clients"
controllercommon "github.com/openshift/machine-config-operator/pkg/controller/common"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
containerruntimeconfig "github.com/openshift/machine-config-operator/pkg/controller/container-runtime-config"
kubeletconfig "github.com/openshift/machine-config-operator/pkg/controller/kubelet-config"
"github.com/openshift/machine-config-operator/pkg/controller/node"
Expand Down Expand Up @@ -51,10 +51,10 @@ func runStartCmd(cmd *cobra.Command, args []string) {

cb, err := clients.NewBuilder(startOpts.kubeconfig)
if err != nil {
controllercommon.WriteTerminationError(errors.Wrapf(err, "Creating clients"))
ctrlcommon.WriteTerminationError(errors.Wrapf(err, "Creating clients"))
}
run := func(ctx context.Context) {
ctrlctx := controllercommon.CreateControllerContext(cb, ctx.Done(), componentName)
ctrlctx := ctrlcommon.CreateControllerContext(cb, ctx.Done(), componentName)

controllers := createControllers(ctrlctx)

Expand Down Expand Up @@ -89,8 +89,8 @@ func runStartCmd(cmd *cobra.Command, args []string) {
panic("unreachable")
}

func createControllers(ctx *controllercommon.ControllerContext) []controllercommon.Controller {
var controllers []controllercommon.Controller
func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controller {
var controllers []ctrlcommon.Controller

controllers = append(controllers,
// Our primary MCs come from here
Expand Down
6 changes: 3 additions & 3 deletions cmd/machine-config-daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/golang/glog"
"github.com/openshift/machine-config-operator/internal/clients"
controllercommon "github.com/openshift/machine-config-operator/pkg/controller/common"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/openshift/machine-config-operator/pkg/daemon"
"github.com/openshift/machine-config-operator/pkg/version"
errors "github.com/pkg/errors"
Expand Down Expand Up @@ -140,7 +140,7 @@ func runStartCmd(cmd *cobra.Command, args []string) {
// Start local metrics listener
go daemon.StartMetricsListener(startOpts.promMetricsURL, stopCh)

ctx := controllercommon.CreateControllerContext(cb, stopCh, componentName)
ctx := ctrlcommon.CreateControllerContext(cb, stopCh, componentName)
// create the daemon instance. this also initializes kube client items
// which need to come from the container and not the chroot.
dn.ClusterConnect(
Expand All @@ -160,6 +160,6 @@ func runStartCmd(cmd *cobra.Command, args []string) {
close(ctx.InformersStarted)

if err := dn.Run(stopCh, exitCh); err != nil {
controllercommon.WriteTerminationError(err)
ctrlcommon.WriteTerminationError(err)
}
}
6 changes: 3 additions & 3 deletions cmd/machine-config-operator/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
operatorv1 "github.com/openshift/client-go/operator/informers/externalversions/operator/v1"
"github.com/openshift/machine-config-operator/cmd/common"
"github.com/openshift/machine-config-operator/internal/clients"
controllercommon "github.com/openshift/machine-config-operator/pkg/controller/common"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/openshift/machine-config-operator/pkg/operator"
"github.com/openshift/machine-config-operator/pkg/version"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -53,14 +53,14 @@ func runStartCmd(cmd *cobra.Command, args []string) {
glog.Fatalf("error creating clients: %v", err)
}
run := func(ctx context.Context) {
ctrlctx := controllercommon.CreateControllerContext(cb, ctx.Done(), componentNamespace)
ctrlctx := ctrlcommon.CreateControllerContext(cb, ctx.Done(), componentNamespace)
operatorClient := cb.OperatorClientOrDie("operator-shared-informer")

etcdInformer, err := getEtcdInformer(operatorClient, ctrlctx.OperatorInformerFactory)
if err != nil {
// MCO pod needs to restart for transient apiserver errors
glog.Errorf("unable to query discovery API %#v", err)
controllercommon.WriteTerminationError(err)
ctrlcommon.WriteTerminationError(err)
}

controller := operator.New(
Expand Down
4 changes: 2 additions & 2 deletions cmd/machine-config-server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"flag"

"github.com/golang/glog"
controllercommon "github.com/openshift/machine-config-operator/pkg/controller/common"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/openshift/machine-config-operator/pkg/server"
"github.com/openshift/machine-config-operator/pkg/version"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -43,7 +43,7 @@ func runStartCmd(cmd *cobra.Command, args []string) {

cs, err := server.NewClusterServer(startOpts.kubeconfig, startOpts.apiserverURL)
if err != nil {
controllercommon.WriteTerminationError(err)
ctrlcommon.WriteTerminationError(err)
}

apiHandler := server.NewServerAPIHandler(cs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
fakeoperatorclient "github.com/openshift/client-go/operator/clientset/versioned/fake"
operatorinformer "github.com/openshift/client-go/operator/informers/externalversions"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/openshift/machine-config-operator/pkg/controller/common"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/fake"
informers "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions"
"github.com/openshift/machine-config-operator/test/helpers"
Expand Down Expand Up @@ -392,7 +392,7 @@ func TestContainerRuntimeConfigCreate(t *testing.T) {
t.Run(platform, func(t *testing.T) {
f := newFixture(t)

cc := newControllerConfig(common.ControllerConfigName, platform)
cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0")
mcp.ObjectMeta.Labels["custom-crio"] = "my-config"
mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0")
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestContainerRuntimeConfigUpdate(t *testing.T) {
t.Run(platform, func(t *testing.T) {
f := newFixture(t)

cc := newControllerConfig(common.ControllerConfigName, platform)
cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0")
mcp.ObjectMeta.Labels["custom-crio"] = "my-config"
mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0")
Expand Down Expand Up @@ -502,7 +502,7 @@ func TestImageConfigCreate(t *testing.T) {
t.Run(platform, func(t *testing.T) {
f := newFixture(t)

cc := newControllerConfig(common.ControllerConfigName, platform)
cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0")
mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0")
imgcfg1 := newImageConfig("cluster", &apicfgv1.RegistrySources{InsecureRegistries: []string{"blah.io"}, AllowedRegistries: []string{"allow.io"}})
Expand Down Expand Up @@ -538,7 +538,7 @@ func TestImageConfigUpdate(t *testing.T) {
t.Run(platform, func(t *testing.T) {
f := newFixture(t)

cc := newControllerConfig(common.ControllerConfigName, platform)
cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0")
mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0")
imgcfg1 := newImageConfig("cluster", &apicfgv1.RegistrySources{InsecureRegistries: []string{"blah.io"}, AllowedRegistries: []string{"allow.io"}})
Expand Down Expand Up @@ -622,7 +622,7 @@ func TestICSPUpdate(t *testing.T) {
t.Run(platform, func(t *testing.T) {
f := newFixture(t)

cc := newControllerConfig(common.ControllerConfigName, platform)
cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0")
mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0")
imgcfg1 := newImageConfig("cluster", &apicfgv1.RegistrySources{InsecureRegistries: []string{"blah.io"}})
Expand Down Expand Up @@ -713,7 +713,7 @@ func TestRunImageBootstrap(t *testing.T) {

for _, platform := range []string{"aws", "none", "unrecognized"} {
t.Run(platform, func(t *testing.T) {
cc := newControllerConfig(common.ControllerConfigName, platform)
cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
pools := []*mcfgv1.MachineConfigPool{
helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0"),
helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
igntypes "github.com/coreos/ignition/config/v2_2/types"
oseconfigfake "github.com/openshift/client-go/config/clientset/versioned/fake"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/openshift/machine-config-operator/pkg/controller/common"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/fake"
informers "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions"
"github.com/openshift/machine-config-operator/test/helpers"
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestKubeletConfigCreate(t *testing.T) {
t.Run(platform, func(t *testing.T) {
f := newFixture(t)

cc := newControllerConfig(common.ControllerConfigName, platform)
cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0")
mcp.ObjectMeta.Labels["kubeletType"] = "small-pods"
mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0")
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestKubeletConfigUpdates(t *testing.T) {
t.Run(platform, func(t *testing.T) {
f := newFixture(t)

cc := newControllerConfig(common.ControllerConfigName, platform)
cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0")
mcp.ObjectMeta.Labels["kubeletType"] = "small-pods"
mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0")
Expand Down Expand Up @@ -499,7 +499,7 @@ func TestKubeletFeatureExists(t *testing.T) {
t.Run(platform, func(t *testing.T) {
f := newFixture(t)

cc := newControllerConfig(common.ControllerConfigName, platform)
cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0")
mcp.ObjectMeta.Labels["kubeletType"] = "small-pods"
mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0")
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/kubelet-config/kubelet_config_features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
igntypes "github.com/coreos/ignition/config/v2_2/types"
"github.com/vincent-petithory/dataurl"

"github.com/openshift/machine-config-operator/pkg/controller/common"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/openshift/machine-config-operator/test/helpers"
)

func TestFeatureGateDrift(t *testing.T) {
for _, platform := range []string{"aws", "none", "unrecognized"} {
t.Run(platform, func(t *testing.T) {
f := newFixture(t)
cc := newControllerConfig(common.ControllerConfigName, platform)
cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
f.ccLister = append(f.ccLister, cc)

ctrl := f.newController()
Expand All @@ -41,7 +41,7 @@ func TestFeaturesDefault(t *testing.T) {
t.Run(platform, func(t *testing.T) {
f := newFixture(t)

cc := newControllerConfig(common.ControllerConfigName, platform)
cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0")
mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0")
mcs := helpers.NewMachineConfig(getManagedKubeletConfigKey(mcp), map[string]string{"node-role/master": ""}, "dummy://", []igntypes.File{{}})
Expand Down
7 changes: 3 additions & 4 deletions pkg/controller/render/render_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/golang/glog"
"github.com/openshift/machine-config-operator/lib/resourceapply"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/openshift/machine-config-operator/pkg/controller/common"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
mcfgclientset "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned"
"github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/scheme"
Expand Down Expand Up @@ -421,7 +420,7 @@ func (ctrl *Controller) syncMachineConfigPool(key string) error {
}

// TODO(runcom): add tests in render_controller_test.go for this condition
if err := mcfgv1.IsControllerConfigCompleted(common.ControllerConfigName, ctrl.ccLister.Get); err != nil {
if err := mcfgv1.IsControllerConfigCompleted(ctrlcommon.ControllerConfigName, ctrl.ccLister.Get); err != nil {
return err
}

Expand Down Expand Up @@ -476,7 +475,7 @@ func (ctrl *Controller) syncGeneratedMachineConfig(pool *mcfgv1.MachineConfigPoo
return nil
}

cc, err := ctrl.ccLister.Get(common.ControllerConfigName)
cc, err := ctrl.ccLister.Get(ctrlcommon.ControllerConfigName)
if err != nil {
return err
}
Expand Down Expand Up @@ -542,7 +541,7 @@ func generateRenderedMachineConfig(pool *mcfgv1.MachineConfigPool, configs []*mc
if merged.Annotations == nil {
merged.Annotations = map[string]string{}
}
merged.Annotations[common.GeneratedByControllerVersionAnnotationKey] = version.Hash
merged.Annotations[ctrlcommon.GeneratedByControllerVersionAnnotationKey] = version.Hash

return merged, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/template/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/ghodss/yaml"
"github.com/golang/glog"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/openshift/machine-config-operator/pkg/controller/common"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/openshift/machine-config-operator/pkg/version"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -90,7 +90,7 @@ func generateTemplateMachineConfigs(config *RenderConfig, templateDir string) ([
if cfg.Annotations == nil {
cfg.Annotations = map[string]string{}
}
cfg.Annotations[common.GeneratedByControllerVersionAnnotationKey] = version.Hash
cfg.Annotations[ctrlcommon.GeneratedByControllerVersionAnnotationKey] = version.Hash
}

return cfgs, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/template/template_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/golang/glog"
"github.com/openshift/machine-config-operator/lib/resourceapply"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/openshift/machine-config-operator/pkg/controller/common"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
mcfgclientset "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned"
"github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/scheme"
mcfginformersv1 "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1"
Expand Down Expand Up @@ -115,7 +115,7 @@ func New(

func (ctrl *Controller) filterSecret(secret *corev1.Secret) {
if secret.Name == "pull-secret" {
cfg, err := ctrl.ccLister.Get(common.ControllerConfigName)
cfg, err := ctrl.ccLister.Get(ctrlcommon.ControllerConfigName)
if err != nil {
utilruntime.HandleError(fmt.Errorf("couldn't get ControllerConfig on secret callback %#v", err))
return
Expand Down Expand Up @@ -159,7 +159,7 @@ func (ctrl *Controller) deleteSecret(obj interface{}) {
}

if secret.Name == "pull-secret" {
cfg, err := ctrl.ccLister.Get(common.ControllerConfigName)
cfg, err := ctrl.ccLister.Get(ctrlcommon.ControllerConfigName)
if err != nil {
utilruntime.HandleError(fmt.Errorf("Couldn't get ControllerConfig on secret callback %#v", err))
return
Expand Down

0 comments on commit 65c5038

Please sign in to comment.