Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow having one operator for all namespaces #551

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 22 additions & 56 deletions manifests/arango-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ rules:
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list"]
- apiGroups: ["database.arangodb.com"]
resources: ["arangodeployments"]
verbs: ["*"]
- apiGroups: [""]
resources: ["pods", "services", "endpoints", "persistentvolumeclaims", "events", "secrets", "serviceaccounts"]
verbs: ["*"]
- apiGroups: ["apps"]
resources: ["deployments", "replicasets"]
verbs: ["get"]
- apiGroups: ["policy"]
resources: ["poddisruptionbudgets"]
verbs: ["*"]
- apiGroups: ["backup.arangodb.com"]
resources: ["arangobackuppolicies", "arangobackups"]
verbs: ["get", "list", "watch"]
- apiGroups: ["monitoring.coreos.com"]
resources: ["servicemonitors"]
verbs: ["get", "create", "delete"]
---
# Source: kube-arangodb/templates/deployment-operator/cluster-role-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1
Expand All @@ -58,7 +76,7 @@ subjects:
---
# Source: kube-arangodb/templates/deployment-operator/default-role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
kind: ClusterRole
metadata:
name: arango-deployment-operator-rbac-default
namespace: default
Expand All @@ -73,41 +91,9 @@ rules:
resources: ["pods"]
verbs: ["get"]
---
# Source: kube-arangodb/templates/deployment-operator/role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: arango-deployment-operator-rbac-deployment
namespace: default
labels:
app.kubernetes.io/name: kube-arangodb
helm.sh/chart: kube-arangodb-1.0.3
app.kubernetes.io/managed-by: Tiller
app.kubernetes.io/instance: deployment
release: deployment
rules:
- apiGroups: ["database.arangodb.com"]
resources: ["arangodeployments"]
verbs: ["*"]
- apiGroups: [""]
resources: ["pods", "services", "endpoints", "persistentvolumeclaims", "events", "secrets", "serviceaccounts"]
verbs: ["*"]
- apiGroups: ["apps"]
resources: ["deployments", "replicasets"]
verbs: ["get"]
- apiGroups: ["policy"]
resources: ["poddisruptionbudgets"]
verbs: ["*"]
- apiGroups: ["backup.arangodb.com"]
resources: ["arangobackuppolicies", "arangobackups"]
verbs: ["get", "list", "watch"]
- apiGroups: ["monitoring.coreos.com"]
resources: ["servicemonitors"]
verbs: ["get", "create", "delete", "update"]
---
# Source: kube-arangodb/templates/deployment-operator/default-role-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
kind: ClusterRoleBinding
metadata:
name: arango-deployment-operator-rbac-default
namespace: default
Expand All @@ -119,34 +105,14 @@ metadata:
release: deployment
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
kind: ClusterRole
name: arango-deployment-operator-rbac-default
subjects:
- kind: ServiceAccount
name: default
namespace: default
---
# Source: kube-arangodb/templates/deployment-operator/role-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: arango-deployment-operator-rbac-deployment
namespace: default
labels:
app.kubernetes.io/name: kube-arangodb
helm.sh/chart: kube-arangodb-1.0.3
app.kubernetes.io/managed-by: Tiller
app.kubernetes.io/instance: deployment
release: deployment
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: arango-deployment-operator-rbac-deployment
subjects:
- kind: ServiceAccount
name: arango-deployment-operator
namespace: default
---

# Source: kube-arangodb/templates/service.yaml
apiVersion: v1
kind: Service
Expand Down
9 changes: 5 additions & 4 deletions pkg/deployment/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package deployment
import (
v1 "k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"

"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
Expand All @@ -49,7 +50,7 @@ func (d *Deployment) listenForPodEvents(stopCh <-chan struct{}) {
d.deps.Log,
d.deps.KubeCli.CoreV1().RESTClient(),
"pods",
d.apiObject.GetNamespace(),
metav1.NamespaceAll,
&v1.Pod{},
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down Expand Up @@ -91,7 +92,7 @@ func (d *Deployment) listenForPVCEvents(stopCh <-chan struct{}) {
d.deps.Log,
d.deps.KubeCli.CoreV1().RESTClient(),
"persistentvolumeclaims",
d.apiObject.GetNamespace(),
metav1.NamespaceAll,
&v1.PersistentVolumeClaim{},
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down Expand Up @@ -133,7 +134,7 @@ func (d *Deployment) listenForSecretEvents(stopCh <-chan struct{}) {
d.deps.Log,
d.deps.KubeCli.CoreV1().RESTClient(),
"secrets",
d.apiObject.GetNamespace(),
metav1.NamespaceAll,
&v1.Secret{},
cache.ResourceEventHandlerFuncs{
// Note: For secrets we look at all of them because they do not have to be owned by this deployment.
Expand Down Expand Up @@ -176,7 +177,7 @@ func (d *Deployment) listenForServiceEvents(stopCh <-chan struct{}) {
d.deps.Log,
d.deps.KubeCli.CoreV1().RESTClient(),
"services",
d.apiObject.GetNamespace(),
metav1.NamespaceAll,
&v1.Service{},
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/operator/operator_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
deploymentType "github.com/arangodb/kube-arangodb/pkg/apis/deployment"

"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kwatch "k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"

Expand All @@ -52,7 +53,7 @@ func (o *Operator) runDeployments(stop <-chan struct{}) {
o.log,
o.Dependencies.CRCli.DatabaseV1().RESTClient(),
deploymentType.ArangoDeploymentResourcePlural,
o.Config.Namespace,
metav1.NamespaceAll,
&api.ArangoDeployment{},
cache.ResourceEventHandlerFuncs{
AddFunc: o.onAddArangoDeployment,
Expand Down
3 changes: 2 additions & 1 deletion pkg/operator/operator_deployment_relication.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
replication2 "github.com/arangodb/kube-arangodb/pkg/apis/replication"

"github.com/pkg/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kwatch "k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"

Expand All @@ -52,7 +53,7 @@ func (o *Operator) runDeploymentReplications(stop <-chan struct{}) {
o.log,
o.Dependencies.CRCli.ReplicationV1().RESTClient(),
replication2.ArangoDeploymentReplicationResourcePlural,
o.Config.Namespace,
v1.NamespaceAll,
&api.ArangoDeploymentReplication{},
cache.ResourceEventHandlerFuncs{
AddFunc: o.onAddArangoDeploymentReplication,
Expand Down
1 change: 0 additions & 1 deletion pkg/util/k8sutil/informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func NewResourceWatcher(log zerolog.Logger, getter cache.Getter, resource, names
resource,
namespace,
fields.Everything())

_, informer := cache.NewIndexerInformer(source, objType, 0, cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
defer func() {
Expand Down