diff --git a/Makefile b/Makefile index c2c50ec28..16cee6c6d 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ test: test-unit test-e2e test-unit: ifndef JUNITFILE - go test $(GOFLAGS) -race ./... + go test $(GOFLAGS) -race ./pkg/... ./cmd/... else ifeq (, $(shell which gotest2junit 2>/dev/null)) $(error gotest2junit not found! Get it by `go get -u github.com/openshift/release/tools/gotest2junit`.) diff --git a/pkg/operator/configobservation/deployimages/observe_deployimages.go b/pkg/operator/configobservation/deployimages/observe_deployimages.go index 21c047fd4..44f7bd68a 100644 --- a/pkg/operator/configobservation/deployimages/observe_deployimages.go +++ b/pkg/operator/configobservation/deployimages/observe_deployimages.go @@ -45,7 +45,7 @@ func ObserveControllerManagerImagesConfig(genericListers configobserver.Listers, // now gather the cluster config and turn it into the observed config observedConfig := map[string]interface{}{} - controllerManagerImagesConfigMap, err := listers.ConfigMapLister.ConfigMaps(util.OperatorNamespaceName).Get("openshift-controller-manager-images") + controllerManagerImagesConfigMap, err := listers.ConfigMapLister.ConfigMaps(util.OperatorNamespace).Get("openshift-controller-manager-images") if errors.IsNotFound(err) { glog.V(2).Infof("configmap/openshift-controller-manager-images: not found") return observedConfig, errs diff --git a/pkg/operator/configobservation/deployimages/observe_deployimages_test.go b/pkg/operator/configobservation/deployimages/observe_deployimages_test.go index e56f485b0..e9e83f675 100644 --- a/pkg/operator/configobservation/deployimages/observe_deployimages_test.go +++ b/pkg/operator/configobservation/deployimages/observe_deployimages_test.go @@ -25,7 +25,7 @@ func TestObserveClusterConfig(t *testing.T) { cm: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: "openshift-controller-manager-images", - Namespace: util.OperatorNamespaceName, + Namespace: util.OperatorNamespace, }, Data: map[string]string{ "builderImage": "quay.io/sample/origin-builder:v4.0", @@ -50,7 +50,7 @@ func TestObserveClusterConfig(t *testing.T) { cm: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: "openshift-controller-manager-images", - Namespace: util.OperatorNamespaceName, + Namespace: util.OperatorNamespace, }, Data: map[string]string{ "builderImage": "quay.io/sample/origin-builder:v4.0", @@ -70,7 +70,7 @@ func TestObserveClusterConfig(t *testing.T) { cm: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: "openshift-controller-manager-images", - Namespace: util.OperatorNamespaceName, + Namespace: util.OperatorNamespace, }, Data: map[string]string{ "unknownField": "quay.io/sample/origin-builder:v4.0", @@ -84,7 +84,7 @@ func TestObserveClusterConfig(t *testing.T) { cm: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: "shall-not-be-found", - Namespace: util.OperatorNamespaceName, + Namespace: util.OperatorNamespace, }, Data: map[string]string{ "builderImage": "quay.io/sample/origin-builder:v4.0", diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 01d461e24..90e4625e1 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -22,15 +22,14 @@ import ( operatorapiv1 "github.com/openshift/api/operator/v1" operatorclientv1 "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1" operatorinformersv1 "github.com/openshift/client-go/operator/informers/externalversions/operator/v1" + "github.com/openshift/cluster-openshift-controller-manager-operator/pkg/util" "github.com/openshift/library-go/pkg/operator/events" "github.com/openshift/library-go/pkg/operator/v1helpers" ) const ( - kubeAPIServerNamespaceName = "openshift-kube-apiserver" - targetNamespaceName = "openshift-controller-manager" - workQueueKey = "key" - workloadFailingCondition = "WorkloadFailing" + workQueueKey = "key" + workloadFailingCondition = "WorkloadFailing" ) type OpenShiftControllerManagerOperator struct { @@ -112,7 +111,7 @@ func (c OpenShiftControllerManagerOperator) sync() error { case operatorapiv1.Removed: // TODO probably need to watch until the NS is really gone - if err := c.kubeClient.CoreV1().Namespaces().Delete(targetNamespaceName, nil); err != nil && !apierrors.IsNotFound(err) { + if err := c.kubeClient.CoreV1().Namespaces().Delete(util.TargetNamespace, nil); err != nil && !apierrors.IsNotFound(err) { return err } // TODO report that we are removing? @@ -178,7 +177,7 @@ func (c *OpenShiftControllerManagerOperator) eventHandler() cache.ResourceEventH } // this set of namespaces will include things like logging and metrics which are used to drive -var interestingNamespaces = sets.NewString(targetNamespaceName) +var interestingNamespaces = sets.NewString(util.TargetNamespace) func (c *OpenShiftControllerManagerOperator) namespaceEventHandler() cache.ResourceEventHandler { return cache.ResourceEventHandlerFuncs{ @@ -187,7 +186,7 @@ func (c *OpenShiftControllerManagerOperator) namespaceEventHandler() cache.Resou if !ok { c.queue.Add(workQueueKey) } - if ns.Name == targetNamespaceName { + if ns.Name == util.TargetNamespace { c.queue.Add(workQueueKey) } }, @@ -196,7 +195,7 @@ func (c *OpenShiftControllerManagerOperator) namespaceEventHandler() cache.Resou if !ok { c.queue.Add(workQueueKey) } - if ns.Name == targetNamespaceName { + if ns.Name == util.TargetNamespace { c.queue.Add(workQueueKey) } }, @@ -214,7 +213,7 @@ func (c *OpenShiftControllerManagerOperator) namespaceEventHandler() cache.Resou return } } - if ns.Name == targetNamespaceName { + if ns.Name == util.TargetNamespace { c.queue.Add(workQueueKey) } }, diff --git a/pkg/operator/starter.go b/pkg/operator/starter.go index 7e403f0d2..fe4cbfc05 100644 --- a/pkg/operator/starter.go +++ b/pkg/operator/starter.go @@ -52,8 +52,8 @@ func RunOperator(ctx *controllercmd.ControllerContext) error { ) operatorConfigInformers := operatorinformers.NewSharedInformerFactory(operatorclient, 10*time.Minute) - kubeInformersForOpenshiftControllerManagerNamespace := informers.NewSharedInformerFactoryWithOptions(kubeClient, 10*time.Minute, informers.WithNamespace(targetNamespaceName)) - kubeInformersForOperatorNamespace := informers.NewSharedInformerFactoryWithOptions(kubeClient, 10*time.Minute, informers.WithNamespace(util.OperatorNamespaceName)) + kubeInformersForOpenshiftControllerManagerNamespace := informers.NewSharedInformerFactoryWithOptions(kubeClient, 10*time.Minute, informers.WithNamespace(util.TargetNamespace)) + kubeInformersForOperatorNamespace := informers.NewSharedInformerFactoryWithOptions(kubeClient, 10*time.Minute, informers.WithNamespace(util.OperatorNamespace)) configInformers := configinformers.NewSharedInformerFactory(configClient, 10*time.Minute) operator := NewOpenShiftControllerManagerOperator( @@ -79,7 +79,13 @@ func RunOperator(ctx *controllercmd.ControllerContext) error { clusterOperatorStatus := status.NewClusterOperatorStatusController( "openshift-controller-manager", - []configv1.ObjectReference{}, + []configv1.ObjectReference{ + {Group: "operator.openshift.io", Resource: "openshiftcontrollermanagers", Name: "cluster"}, + {Resource: "namespaces", Name: util.UserSpecifiedGlobalConfigNamespace}, + {Resource: "namespaces", Name: util.MachineSpecifiedGlobalConfigNamespace}, + {Resource: "namespaces", Name: util.OperatorNamespace}, + {Resource: "namespaces", Name: util.TargetNamespace}, + }, configClient.ConfigV1(), opClient, status.NewVersionGetter(), diff --git a/pkg/operator/sync_openshiftcontrollermanager_v311_00.go b/pkg/operator/sync_openshiftcontrollermanager_v311_00.go index c966f8edb..42bf8a76b 100644 --- a/pkg/operator/sync_openshiftcontrollermanager_v311_00.go +++ b/pkg/operator/sync_openshiftcontrollermanager_v311_00.go @@ -22,6 +22,7 @@ import ( "github.com/openshift/library-go/pkg/operator/v1helpers" "github.com/openshift/cluster-openshift-controller-manager-operator/pkg/operator/v311_00_assets" + "github.com/openshift/cluster-openshift-controller-manager-operator/pkg/util" ) // syncOpenShiftControllerManager_v311_00_to_latest takes care of synchronizing (not upgrading) the thing we're managing. @@ -149,7 +150,7 @@ func syncOpenShiftControllerManager_v311_00_to_latest(c OpenShiftControllerManag func manageOpenShiftControllerManagerClientCA_v311_00_to_latest(client coreclientv1.CoreV1Interface, recorder events.Recorder) (bool, error) { const apiserverClientCA = "client-ca" - _, caChanged, err := resourceapply.SyncConfigMap(client, recorder, kubeAPIServerNamespaceName, apiserverClientCA, targetNamespaceName, apiserverClientCA, []metav1.OwnerReference{}) + _, caChanged, err := resourceapply.SyncConfigMap(client, recorder, util.KubeAPIServerNamespace, apiserverClientCA, util.TargetNamespace, apiserverClientCA, []metav1.OwnerReference{}) if err != nil { return false, err } @@ -167,8 +168,8 @@ func manageOpenShiftControllerManagerConfigMap_v311_00_to_latest(kubeClient kube // we can embed input hashes on our main configmap to drive rollouts when they change. inputHashes, err := resourcehash.MultipleObjectHashStringMapForObjectReferences( kubeClient, - resourcehash.NewObjectRef().ForConfigMap().InNamespace(targetNamespaceName).Named("client-ca"), - resourcehash.NewObjectRef().ForSecret().InNamespace(targetNamespaceName).Named("serving-cert"), + resourcehash.NewObjectRef().ForConfigMap().InNamespace(util.TargetNamespace).Named("client-ca"), + resourcehash.NewObjectRef().ForSecret().InNamespace(util.TargetNamespace).Named("serving-cert"), ) if err != nil { return nil, false, err diff --git a/pkg/util/consts.go b/pkg/util/consts.go index 385c057c8..12379b034 100644 --- a/pkg/util/consts.go +++ b/pkg/util/consts.go @@ -1,5 +1,9 @@ package util const ( - OperatorNamespaceName = "openshift-controller-manager-operator" + KubeAPIServerNamespace = "openshift-kube-apiserver" + UserSpecifiedGlobalConfigNamespace = "openshift-config" + MachineSpecifiedGlobalConfigNamespace = "openshift-config-managed" + TargetNamespace = "openshift-controller-manager" + OperatorNamespace = "openshift-controller-manager-operator" )