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

[Feature] Cluster scope #735

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
{{ if .Values.operator.features.deployment -}}

apiVersion: rbac.authorization.k8s.io/v1
{{ if not (eq .Values.operator.scope "cluster") }}
kind: RoleBinding
{{ else }}
kind: ClusterRoleBinding
{{ end }}
metadata:
name: {{ template "kube-arangodb.rbac" . }}-deployment
{{ if not (eq .Values.operator.scope "cluster") }}
namespace: {{ .Release.Namespace }}
{{ end }}
labels:
app.kubernetes.io/name: {{ template "kube-arangodb.name" . }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
Expand All @@ -14,7 +20,11 @@ metadata:
release: {{ .Release.Name }}
roleRef:
apiGroup: rbac.authorization.k8s.io
{{ if not (eq .Values.operator.scope "cluster") }}
kind: Role
{{ else }}
kind: ClusterRole
{{ end }}
name: {{ template "kube-arangodb.rbac" . }}-deployment
subjects:
- kind: ServiceAccount
Expand Down
6 changes: 6 additions & 0 deletions chart/kube-arangodb/templates/deployment-operator/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
{{ if .Values.operator.features.deployment -}}

apiVersion: rbac.authorization.k8s.io/v1
{{ if not (eq .Values.operator.scope "cluster") }}
kind: Role
{{ else }}
kind: ClusterRole
{{ end }}
metadata:
name: {{ template "kube-arangodb.rbac" . }}-deployment
{{ if not (eq .Values.operator.scope "cluster") }}
namespace: {{ .Release.Namespace }}
{{ end }}
labels:
app.kubernetes.io/name: {{ template "kube-arangodb.name" . }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
{{ if .Values.operator.features.deploymentReplications -}}

apiVersion: rbac.authorization.k8s.io/v1
{{ if not (eq .Values.operator.scope "cluster") }}
kind: RoleBinding
{{ else }}
kind: ClusterRoleBinding
{{ end }}
metadata:
name: {{ template "kube-arangodb.rbac" . }}-deployment-replication
{{ if not (eq .Values.operator.scope "cluster") }}
namespace: {{ .Release.Namespace }}
{{ end }}
labels:
app.kubernetes.io/name: {{ template "kube-arangodb.name" . }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
Expand All @@ -14,7 +20,11 @@ metadata:
release: {{ .Release.Name }}
roleRef:
apiGroup: rbac.authorization.k8s.io
{{ if not (eq .Values.operator.scope "cluster") }}
kind: Role
{{ else }}
kind: ClusterRole
{{ end }}
name: {{ template "kube-arangodb.rbac" . }}-deployment-replication
subjects:
- kind: ServiceAccount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
{{ if .Values.operator.features.deploymentReplications -}}

apiVersion: rbac.authorization.k8s.io/v1
{{ if not (eq .Values.operator.scope "cluster") }}
kind: Role
{{ else }}
kind: ClusterRole
{{ end }}
metadata:
name: {{ template "kube-arangodb.rbac" . }}-deployment-replication
{{ if not (eq .Values.operator.scope "cluster") }}
namespace: {{ .Release.Namespace }}
{{ end }}
labels:
app.kubernetes.io/name: {{ template "kube-arangodb.name" . }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
Expand Down
2 changes: 1 addition & 1 deletion chart/kube-arangodb/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ if eq .Values.operator.scope "legacy" -}}
# Scope "legacy" selected
{{ else if eq .Values.operator.scope "namespaced" -}}
{{ else if or (eq .Values.operator.scope "namespaced") (eq .Values.operator.scope "cluster") -}}
# Scope "namespaced" selected
{{ if .Values.operator.features.storage -}}
{{ fail (printf "Storage Operator not supported in %s scope!" .Values.operator.scope) -}}
Expand Down
4 changes: 2 additions & 2 deletions chart/kube-arangodb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ operator:
imagePullSecrets: []

scope: legacy

architectures:
- amd64

Expand Down Expand Up @@ -38,7 +38,7 @@ operator:
allowChaos: false

nodeSelector: {}

enableCRDManagement: true

features:
Expand Down
12 changes: 10 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,24 @@ func newOperatorConfigAndDeps(id, namespace, name string) (operator.Config, oper
return operator.Config{}, operator.Dependencies{}, errors.WithStack(fmt.Errorf("Failed to get my pod's service account: %s", err))
}

eventRecorder := createRecorder(cliLog, client.Kubernetes(), name, namespace)

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

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

eventRecorder := createRecorder(cliLog, client.Kubernetes(), 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 @@ -92,6 +92,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.Client.Arango().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.Client.Arango().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
9 changes: 8 additions & 1 deletion pkg/operator/scope/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func AsScope(s string) (Scope, bool) {
return LegacyScope, true
case NamespacedScope.String():
return NamespacedScope, true
case ClusterScope.String():
return ClusterScope, true
}

return "", false
Expand All @@ -37,13 +39,18 @@ func (s Scope) String() string {
return string(s)
}

func (s Scope) IsCluster() bool {
return s == ClusterScope
}

func (s Scope) IsNamespaced() bool {
return s == NamespacedScope
return s.IsCluster() || s == NamespacedScope
}

const (
LegacyScope Scope = "legacy"
NamespacedScope Scope = "namespaced"
ClusterScope Scope = "cluster"

DefaultScope = LegacyScope
)