Skip to content

Commit

Permalink
fix the issues with namespaces for cluster scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerxxx committed Jan 31, 2022
1 parent 7d4fe0a commit 6316144
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,20 +384,25 @@ func newOperatorConfigAndDeps(id, namespace, name string) (operator.Config, oper
if err != nil {
return operator.Config{}, operator.Dependencies{}, maskAny(fmt.Errorf("Failed to created versioned client: %s", err))
}
eventRecorder := createRecorder(cliLog, kubecli, name, namespace)

scope, ok := scope.AsScope(operatorOptions.scope)
if !ok {
return operator.Config{}, operator.Dependencies{}, maskAny(fmt.Errorf("Scope %s is not known by Operator", operatorOptions.scope))
}

var watchNamespace string
if scope.IsCluster() {
namespace = metav1.NamespaceAll
watchNamespace = metav1.NamespaceAll
} else {
watchNamespace = namespace
}

eventRecorder := createRecorder(cliLog, kubecli, name, watchNamespace)

cfg := operator.Config{
ID: id,
Namespace: namespace,
WatchNamespace: watchNamespace,
PodName: name,
ServiceAccount: serviceAccount,
OperatorImage: image,
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type Operator struct {
type Config struct {
ID string
Namespace string
WatchNamespace string
PodName string
ServiceAccount string
OperatorImage string
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/operator_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (o *Operator) runDeployments(stop <-chan struct{}) {
o.log,
o.Dependencies.CRCli.DatabaseV1().RESTClient(),
deploymentType.ArangoDeploymentResourcePlural,
o.Config.Namespace,
o.Config.WatchNamespace,
&api.ArangoDeployment{},
cache.ResourceEventHandlerFuncs{
AddFunc: o.onAddArangoDeployment,
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/operator_deployment_relication.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (o *Operator) runDeploymentReplications(stop <-chan struct{}) {
o.log,
o.Dependencies.CRCli.ReplicationV1().RESTClient(),
replication2.ArangoDeploymentReplicationResourcePlural,
o.Config.Namespace,
o.Config.WatchNamespace,
&api.ArangoDeploymentReplication{},
cache.ResourceEventHandlerFuncs{
AddFunc: o.onAddArangoDeploymentReplication,
Expand Down Expand Up @@ -201,7 +201,7 @@ func (o *Operator) handleDeploymentReplicationEvent(event *Event) error {
// makeDeploymentReplicationConfigAndDeps creates a Config & Dependencies object for a new DeploymentReplication.
func (o *Operator) makeDeploymentReplicationConfigAndDeps(apiObject *api.ArangoDeploymentReplication) (replication.Config, replication.Dependencies) {
cfg := replication.Config{
Namespace: o.Config.Namespace,
Namespace: o.Config.WatchNamespace,
}
deps := replication.Dependencies{
Log: o.Dependencies.LogService.MustGetLogger(logging.LoggerNameDeploymentReplication).With().
Expand Down

0 comments on commit 6316144

Please sign in to comment.