Files
my-rook-config/pkg/operator/ceph/cluster/operator_watchers.go
T
Travis Nielsen e56c68c9e9 ceph: remove unused operator namespace parameter
The operator namespace is not used in the StartOperatorSettingsWatch()
method. Instead, the method looks up the namespace from the
POD_NAMESPACE env var.

Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
2020-12-18 11:45:14 -07:00

69 lines
2.0 KiB
Go

/*
Copyright 2020 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package cluster to manage a Ceph cluster.
package cluster
import (
"os"
"reflect"
opcontroller "github.com/rook/rook/pkg/operator/ceph/controller"
"github.com/rook/rook/pkg/operator/k8sutil"
v1 "k8s.io/api/core/v1"
)
// StartOperatorSettingsWatch starts the operator settings watcher
func (c *ClusterController) StartOperatorSettingsWatch(stopCh chan struct{}) {
operatorNamespace := os.Getenv(k8sutil.PodNamespaceEnvVar)
// watch for "rook-ceph-operator-config" ConfigMap
k8sutil.StartOperatorSettingsWatch(c.context, operatorNamespace, opcontroller.OperatorSettingConfigMapName,
c.operatorConfigChange,
func(oldObj, newObj interface{}) {
if reflect.DeepEqual(oldObj, newObj) {
return
}
c.operatorConfigChange(newObj)
}, nil, stopCh)
}
// StopWatch stop watchers
func (c *ClusterController) StopWatch() {
for _, cluster := range c.clusterMap {
// check channel is open before closing
if !cluster.closedStopCh {
close(cluster.stopCh)
cluster.closedStopCh = true
}
}
c.clusterMap = make(map[string]*cluster)
}
func (c *ClusterController) operatorConfigChange(obj interface{}) {
cm, ok := obj.(*v1.ConfigMap)
if !ok {
logger.Warningf("Expected ConfigMap but handler received %T. %#v", obj, obj)
return
}
logger.Infof("ConfigMap %q changes detected. Updating configurations", cm.Name)
for _, callback := range c.operatorConfigCallbacks {
if err := callback(); err != nil {
logger.Errorf("%v", err)
}
}
}