diff --git a/cmd/machine-config-operator/main.go b/cmd/machine-config-operator/main.go index 3df8639cac..f7936ea654 100644 --- a/cmd/machine-config-operator/main.go +++ b/cmd/machine-config-operator/main.go @@ -8,10 +8,7 @@ import ( "k8s.io/component-base/cli" ) -const ( - componentName = "machine-config" - componentNamespace = "openshift-machine-config-operator" -) +const componentName = "machine-config" var ( rootCmd = &cobra.Command{ diff --git a/cmd/machine-config-operator/start.go b/cmd/machine-config-operator/start.go index e8ca8d83b8..c6da99e420 100644 --- a/cmd/machine-config-operator/start.go +++ b/cmd/machine-config-operator/start.go @@ -51,9 +51,9 @@ func runStartCmd(cmd *cobra.Command, args []string) { glog.Fatalf("error creating clients: %v", err) } run := func(ctx context.Context) { - ctrlctx := ctrlcommon.CreateControllerContext(cb, ctx.Done(), componentNamespace) + ctrlctx := ctrlcommon.CreateControllerContext(cb, ctx.Done(), ctrlcommon.MCONamespace) controller := operator.New( - componentNamespace, componentName, + ctrlcommon.MCONamespace, componentName, startOpts.imagesFile, ctrlctx.NamespacedInformerFactory.Machineconfiguration().V1().MachineConfigPools(), ctrlctx.NamespacedInformerFactory.Machineconfiguration().V1().MachineConfigs(), @@ -97,7 +97,7 @@ func runStartCmd(cmd *cobra.Command, args []string) { leaderElectionCfg := common.GetLeaderElectionConfig(cb.GetBuilderConfig()) leaderelection.RunOrDie(context.TODO(), leaderelection.LeaderElectionConfig{ - Lock: common.CreateResourceLock(cb, componentNamespace, componentName), + Lock: common.CreateResourceLock(cb, ctrlcommon.MCONamespace, componentName), LeaseDuration: leaderElectionCfg.LeaseDuration.Duration, RenewDeadline: leaderElectionCfg.RenewDeadline.Duration, RetryPeriod: leaderElectionCfg.RetryPeriod.Duration, diff --git a/pkg/controller/common/constants.go b/pkg/controller/common/constants.go index bce2f8e1d5..3a02cd7deb 100644 --- a/pkg/controller/common/constants.go +++ b/pkg/controller/common/constants.go @@ -1,6 +1,9 @@ package common const ( + // MCONamespace is the namespace that should be used for all API objects owned by the MCO by default + MCONamespace = "openshift-machine-config-operator" + // GeneratedByControllerVersionAnnotationKey is used to tag the machineconfigs generated by the controller with the version of the controller. GeneratedByControllerVersionAnnotationKey = "machineconfiguration.openshift.io/generated-by-controller-version" diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 5f697c478d..6a5743ff9f 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -9,6 +9,7 @@ import ( "github.com/golang/glog" configclientset "github.com/openshift/client-go/config/clientset/versioned" + ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" corev1 "k8s.io/api/core/v1" apiextclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" apiextinformersv1 "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions/apiextensions/v1" @@ -153,10 +154,10 @@ func New( apiExtClient: apiExtClient, configClient: configClient, eventRecorder: eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: "machineconfigoperator"}), - libgoRecorder: events.NewRecorder(kubeClient.CoreV1().Events("openshift-machine-config-operator"), "machine-config-operator", &corev1.ObjectReference{ + libgoRecorder: events.NewRecorder(kubeClient.CoreV1().Events(ctrlcommon.MCONamespace), "machine-config-operator", &corev1.ObjectReference{ Kind: "Deployment", Name: "machine-config-operator", - Namespace: "openshift-machine-config-operator", + Namespace: ctrlcommon.MCONamespace, APIVersion: "apps/v1", }), queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "machineconfigoperator"), diff --git a/test/e2e-single-node/sno_mcd_test.go b/test/e2e-single-node/sno_mcd_test.go index 8d3cf44c53..5b4045c065 100644 --- a/test/e2e-single-node/sno_mcd_test.go +++ b/test/e2e-single-node/sno_mcd_test.go @@ -35,7 +35,7 @@ func TestMCDToken(t *testing.T) { LabelSelector: labels.SelectorFromSet(labels.Set{"k8s-app": "machine-config-daemon"}).String(), } - mcdList, err := cs.Pods("openshift-machine-config-operator").List(context.TODO(), listOptions) + mcdList, err := cs.Pods(ctrlcommon.MCONamespace).List(context.TODO(), listOptions) require.Nil(t, err) for _, pod := range mcdList.Items { diff --git a/test/e2e/mcd_test.go b/test/e2e/mcd_test.go index 65cd265fa0..c52cb8cc38 100644 --- a/test/e2e/mcd_test.go +++ b/test/e2e/mcd_test.go @@ -35,7 +35,7 @@ func TestMCDToken(t *testing.T) { LabelSelector: labels.SelectorFromSet(labels.Set{"k8s-app": "machine-config-daemon"}).String(), } - mcdList, err := cs.Pods("openshift-machine-config-operator").List(context.TODO(), listOptions) + mcdList, err := cs.Pods(ctrlcommon.MCONamespace).List(context.TODO(), listOptions) require.Nil(t, err) for _, pod := range mcdList.Items { diff --git a/test/e2e/mco_test.go b/test/e2e/mco_test.go index 092fb43e88..4d02976f07 100644 --- a/test/e2e/mco_test.go +++ b/test/e2e/mco_test.go @@ -28,7 +28,7 @@ func TestClusterOperatorRelatedObjects(t *testing.T) { } var foundNS bool for _, ro := range co.Status.RelatedObjects { - if ro.Resource == "namespaces" && ro.Name == "openshift-machine-config-operator" { + if ro.Resource == "namespaces" && ro.Name == ctrlcommon.MCONamespace { foundNS = true } } diff --git a/test/e2e/sanity_test.go b/test/e2e/sanity_test.go index 3bc163a828..df819a6373 100644 --- a/test/e2e/sanity_test.go +++ b/test/e2e/sanity_test.go @@ -4,6 +4,8 @@ import ( "context" "testing" + ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" + "github.com/openshift/machine-config-operator/test/framework" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -12,7 +14,7 @@ import ( func TestOperatorLabel(t *testing.T) { cs := framework.NewClientSet("") - d, err := cs.DaemonSets("openshift-machine-config-operator").Get(context.TODO(), "machine-config-daemon", metav1.GetOptions{}) + d, err := cs.DaemonSets(ctrlcommon.MCONamespace).Get(context.TODO(), "machine-config-daemon", metav1.GetOptions{}) if err != nil { t.Errorf("%#v", err) }