Skip to content

Commit

Permalink
Merge pull request #3025 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…3020-to-master

[master] Create MCONamespace constant
  • Loading branch information
openshift-merge-robot authored Apr 1, 2022
2 parents abceabc + 943350e commit 5f21537
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 13 deletions.
5 changes: 1 addition & 4 deletions cmd/machine-config-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions cmd/machine-config-operator/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/common/constants.go
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
5 changes: 3 additions & 2 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion test/e2e-single-node/sno_mcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/mcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/mco_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
}
Expand Down

0 comments on commit 5f21537

Please sign in to comment.