Skip to content

Commit 2610a35

Browse files
authored
Merge pull request #124 from HoustonPutman/helm-ns
Adding ability to deploy helm chart to a namespace.
2 parents fbee27f + 78c1f06 commit 2610a35

File tree

12 files changed

+215
-44
lines changed

12 files changed

+215
-44
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ deploy: manifests
6666
# Generate manifests e.g. CRD, RBAC etc.
6767
manifests: mod-tidy controller-gen
6868
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=solr-operator-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
69-
kustomize build config/crd > helm/solr-operator/crds/crds.yaml
70-
cp config/rbac/role.yaml helm/solr-operator/templates/role.yaml
69+
./hack/helm/copy_crds_roles_helm.sh
7170

7271
# Run go fmt against code
7372
fmt:

config/manager/manager.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ spec:
2222
- -etcd-operator=false
2323
- -ingress-base-domain=ing.local.domain
2424
image: bloomberg/solr-operator:latest
25-
imagePullPolicy: Always
25+
imagePullPolicy: IfNotPresent
2626
name: solr-operator
2727
env:
2828
- name: POD_NAMESPACE
2929
valueFrom:
3030
fieldRef:
3131
fieldPath: metadata.namespace
32+
- name: POD_NAME
33+
valueFrom:
34+
fieldRef:
35+
fieldPath: metadata.name
3236
resources:
3337
limits:
3438
cpu: 200m

hack/helm/copy_crds_roles_helm.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
# exit immediately when a command fails
3+
set -e
4+
# only exit with zero if all commands of the pipeline exit successfully
5+
set -o pipefail
6+
# error on unset variables
7+
set -u
8+
9+
echo "Copying CRDs and Role to helm repo"
10+
11+
# Build and package CRDs
12+
kustomize build config/crd > helm/solr-operator/crds/crds.yaml
13+
14+
# Copy Kube Role for Solr Operator permissions to Helm
15+
rm helm/solr-operator/templates/role.yaml
16+
printf '{{- if .Values.rbac.create }}\n{{- range $namespace := (split "," (include "solr-operator.watchNamespaces" $)) }}\n' > helm/solr-operator/templates/role.yaml
17+
cat config/rbac/role.yaml >> helm/solr-operator/templates/role.yaml
18+
printf '\n{{- end }}\n{{- end }}' >> helm/solr-operator/templates/role.yaml
19+
gawk -i inplace '/^rules:$/{print " namespace: {{ $namespace }}"}1' helm/solr-operator/templates/role.yaml
20+
21+
# Template the Solr Operator role as needed
22+
sed -i.bak -E 's/^kind: ClusterRole$/kind: {{ include "solr-operator\.roleType" \$ }}/' helm/solr-operator/templates/role.yaml
23+
sed -i.bak -E 's/name: solr-operator-role$/name: {{ include "solr-operator\.fullname" \$ }}-role/' helm/solr-operator/templates/role.yaml
24+
rm helm/solr-operator/templates/role.yaml.bak

hack/release/update_versions.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ tag && $1 == "tag:"{$1 = " " $1; $2 = "'"${VERSION}"'"} 1' helm/solr-operator/v
1414

1515
gawk -i inplace '$1 == "version:"{$1 = $1; $2 = "'"${VERSION#v}"'"} 1' helm/solr-operator/Chart.yaml
1616
gawk -i inplace '$1 == "appVersion:"{$1 = $1; $2 = "'"${VERSION}"'"} 1' helm/solr-operator/Chart.yaml
17+
sed -i.bak -E 's/^\| image.tag \| string \| `".*"` \|/\| image.tag \| string \| `"'${VERSION}'"` \|/g' helm/solr-operator/README.md && rm helm/solr-operator/README.md.bak

helm/solr-operator/README.md

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,54 @@ $ helm install solr-operator solr-operator/solr-operator
4646
$ helm install solr-operator solr-operator/solr-operator --version 0.2.5
4747
```
4848

49-
The command deploys the solr-operator on the Kubernetes cluster with the default configuration. The [configuration](#chart-values) section lists the parameters that can be configured during installation.
49+
The command deploys the solr-operator on the Kubernetes cluster with the default configuration.
50+
The [configuration](#chart-values) section lists the parameters that can be configured during installation.
5051

51-
### Helm Version Differences
52+
#### Namespaces
5253

53-
#### Helm 2
54+
If you want to specify the namespace for the installation, use the `--namespace` flag.
55+
All resources will be deployed to the given namespace.
5456

55-
If you are using Helm 2, CRDs are installed using the crd-install hook. Prior to installing, you'll need to uncomment the last two lines in [kustomization.yaml](../../config/crd/kustomization.yaml), and run `make manifests`
57+
```console
58+
$ helm install solr-operator solr-operator/solr-operator --namespace solr
59+
```
5660

57-
You will also need to update the install command to use the name flag, as shown below.
61+
If you want to only watch that namespace, or others, then you will have to provide the `watchNamespaces` option.
5862

5963
```console
60-
$ helm install --name solr-operator solr-operator/solr-operator
64+
// Watch the namespace where the operator is deployed to (just pass the boolean true)
65+
$ helm install solr-operator solr-operator/solr-operator --namespace solr --set watchNamespaces=true
66+
// Watch a single namespace different than the one being deployed to
67+
$ helm install solr-operator solr-operator/solr-operator --namespace solr --set watchNamespaces=other
68+
// Watch multiple namespaces (commmas must be escaped in the set string)
69+
$ helm install solr-operator solr-operator/solr-operator --namespace solr --set watchNamespaces="team1\,team2\,team3"
6170
```
6271

72+
Note: Passing `false` and `""` to the `watchNamespaces` variable will both result in the operator watchting all namespaces in the Kube cluster.
73+
74+
### Managing CRDs
75+
6376
#### Helm 3
6477

6578
Helm 3 automatically runs CRDs in the /crds directory, no further action is needed.
6679

80+
If have solr operator installations in multiple namespaces that are managed separately, you will likely want to skip installing CRDs when installing the chart.
81+
This can be done with the `--skip-crds` helm option.
82+
83+
```console
84+
$ helm install solr-operator solr-operator/solr-operator --skip-crds --namespace solr
85+
```
86+
87+
#### Helm 2
88+
89+
If you are using Helm 2, CRDs are installed using the crd-install hook. Prior to installing, you'll need to uncomment the last two lines in [kustomization.yaml](../../config/crd/kustomization.yaml), and run `make manifests`
90+
91+
You will also need to update the install command to use the name flag, as shown below.
92+
93+
```console
94+
$ helm install --name solr-operator solr-operator/solr-operator
95+
```
96+
6797
### Uninstalling the Chart
6898

6999
To uninstall/delete the `solr-operator` deployment:
@@ -85,12 +115,21 @@ The command removes all the Kubernetes components associated with the chart and
85115

86116
## Chart Values
87117

118+
### Configuring the Solr Operator
119+
120+
| Key | Type | Default | Description |
121+
|-----|------|---------|-------------|
122+
| watchNamespaces | string | `""` | A comma-separated list of namespaces that the solr operator should watch. If empty, the solr operator will watch all namespaces in the cluster. If set to `true`, this will be populated with the namespace that the operator is deployed to. |
123+
| ingressBaseDomain | string | `""` | If you have a base domain that points to your ingress controllers for this kubernetes cluster, you can provide this. SolrClouds will then begin to use ingresses that utilize this base domain. E.g. `solrcloud-test.<base.domain>` |
124+
| useZkOperator | string | `"true"` | This option enables the use of provided Zookeeper instances for SolrClouds |
125+
| useEtcdOperator | string | `"false"` | This option enables the use of provided Zetcd instances for SolrClouds |
126+
88127
### Running the Solr Operator
89128

90129
| Key | Type | Default | Description |
91130
|-----|------|---------|-------------|
92131
| image.repository | string | `"bloomberg/solr-operator"` | The repository of the Solr Operator image |
93-
| image.tag | string | `"v0.2.1"` | The tag/version of the Solr Operator to run |
132+
| image.tag | string | `"v0.2.5"` | The tag/version of the Solr Operator to run |
94133
| image.pullPolicy | string | `"Always"` | |
95134
| fullnameOverride | string | `""` | A custom name for the Solr Operator Deployment |
96135
| nameOverride | string | `""` | |
@@ -99,11 +138,6 @@ The command removes all the Kubernetes components associated with the chart and
99138
| resources.limits.memory | string | `"500Mi"` | |
100139
| resources.requests.cpu | string | `"100m"` | |
101140
| resources.requests.memory | string | `"100Mi"` | |
102-
103-
### Configuring the Solr Operator
104-
105-
| Key | Type | Default | Description |
106-
|-----|------|---------|-------------|
107-
| ingressBaseDomain | string | `""` | If you have a base domain that points to your ingress controllers for this kubernetes cluster, you can provide this. SolrClouds will then begin to use ingresses that utilize this base domain. E.g. `solrcloud-test.<base.domain>` |
108-
| useZkOperator | string | `"true"` | This option enables the use of provided Zookeeper instances for SolrClouds |
109-
| useEtcdOperator | string | `"false"` | This option enables the use of provided Zetcd instances for SolrClouds |
141+
| rbac.create | boolean | true | Create the necessary RBAC rules, whether cluster-wide or namespaced, for the Solr Operator. |
142+
| serviceAccount.create | boolean | true | Create a serviceAccount to be used for this operator. This serviceAccount will be given the permissions specified in the operator's RBAC rules. |
143+
| serviceAccount.name | string | "" | If `serviceAccount.create` is set to `false`, the name of an existing serviceAccount in the target namespace **must** be provided to run the Solr Operator with. This serviceAccount with be given the operator's RBAC rules. |

helm/solr-operator/templates/_helpers.tpl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,42 @@ Create chart name and version as used by the chart label.
2929
*/}}
3030
{{- define "solr-operator.chart" -}}
3131
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32+
{{- end -}}
33+
34+
{{/*
35+
Create the name of the service account to use
36+
*/}}
37+
{{- define "solr-operator.serviceAccountName" -}}
38+
{{- if .Values.serviceAccount.create -}}
39+
{{ default (include "solr-operator.fullname" .) .Values.serviceAccount.name }}
40+
{{- else -}}
41+
{{ required "Must provide a serviceAccount.name if serviceAccount.create is set to false" .Values.serviceAccount.name }}
42+
{{- end -}}
43+
{{- end -}}
44+
45+
{{/*
46+
Get the namespaces to watch (empty if the operator should watch the entire cluster).
47+
If .Values.watchNamespaces = true, then use the release namespace.
48+
If .Values.watchNamespaces is a string, use it.
49+
If .Values.watchNamespaces is empty or false, return empty.
50+
*/}}
51+
{{- define "solr-operator.watchNamespaces" -}}
52+
{{- if .Values.watchNamespaces -}}
53+
{{- if kindIs "bool" .Values.watchNamespaces -}}
54+
{{ .Release.Namespace }}
55+
{{- else -}}
56+
{{ .Values.watchNamespaces }}
57+
{{- end -}}
58+
{{- end -}}
59+
{{- end -}}
60+
61+
{{/*
62+
Determine whether to use ClusterRoles or Roles
63+
*/}}
64+
{{- define "solr-operator.roleType" -}}
65+
{{- if .Values.watchNamespaces -}}
66+
Role
67+
{{- else -}}
68+
ClusterRole
69+
{{- end -}}
3270
{{- end -}}

helm/solr-operator/templates/deployment.yaml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ apiVersion: apps/v1
22
kind: Deployment
33
metadata:
44
name: {{ include "solr-operator.fullname" . }}
5-
namespace: {{ .Release.Namespace }}
65
labels:
76
control-plane: solr-operator
87
controller-tools.k8s.io: "1.0"
@@ -20,20 +19,32 @@ spec:
2019
control-plane: solr-operator
2120
controller-tools.k8s.io: "1.0"
2221
spec:
23-
serviceAccountName: solr-operator
22+
serviceAccountName: {{ include "solr-operator.serviceAccountName" . }}
2423
containers:
2524
- name: {{ .Chart.Name }}
2625
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
2726
imagePullPolicy: {{ .Values.image.pullPolicy }}
2827
args:
2928
- -zk-operator={{ .Values.useZkOperator }}
3029
- -etcd-operator={{ .Values.useEtcdOperator }}
31-
- -ingress-base-domain={{ .Values.ingressBaseDomain }}
30+
{{- if .Values.ingressBaseDomain }}
31+
- --ingress-base-domain={{ .Values.ingressBaseDomain }}
32+
{{- end }}
33+
{{- if .Values.watchNamespaces }}
34+
- --watch-namespaces={{- include "solr-operator.watchNamespaces" . -}}
35+
{{- end }}
3236
env:
33-
- name: POD_NAMESPACE
34-
valueFrom:
35-
fieldRef:
36-
fieldPath: metadata.namespace
37+
- name: POD_NAMESPACE
38+
valueFrom:
39+
fieldRef:
40+
fieldPath: metadata.namespace
41+
- name: POD_NAME
42+
valueFrom:
43+
fieldRef:
44+
fieldPath: metadata.name
45+
{{- if .Values.envVars }}
46+
{{- toYaml .Values.envVars | nindent 10 }}
47+
{{- end }}
3748
resources:
38-
{{- toYaml .Values.resources | nindent 12 }}
39-
terminationGracePeriodSeconds: 10
49+
{{- toYaml .Values.resources | nindent 10 }}
50+
terminationGracePeriodSeconds: 10

helm/solr-operator/templates/role.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
{{- if .Values.rbac.create }}
2+
{{- range $namespace := (split "," (include "solr-operator.watchNamespaces" $)) }}
13

24
---
35
apiVersion: rbac.authorization.k8s.io/v1
4-
kind: ClusterRole
6+
kind: {{ include "solr-operator.roleType" $ }}
57
metadata:
68
creationTimestamp: null
7-
name: solr-operator-role
9+
name: {{ include "solr-operator.fullname" $ }}-role
10+
namespace: {{ $namespace }}
811
rules:
912
- apiGroups:
1013
- ""
@@ -300,3 +303,6 @@ rules:
300303
- get
301304
- patch
302305
- update
306+
307+
{{- end }}
308+
{{- end }}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
{{- if .Values.rbac.create }}
2+
{{- range $namespace := (split "," (include "solr-operator.watchNamespaces" $)) }}
3+
---
14
apiVersion: rbac.authorization.k8s.io/v1
2-
kind: ClusterRoleBinding
5+
kind: {{ include "solr-operator.roleType" $ }}Binding
36
metadata:
4-
name: solr-operator-rolebinding
7+
name: {{ include "solr-operator.fullname" $ }}-rolebinding
8+
namespace: {{ $namespace }}
59
roleRef:
610
apiGroup: rbac.authorization.k8s.io
7-
kind: ClusterRole
8-
name: solr-operator-role
11+
kind: {{ include "solr-operator.roleType" $ }}
12+
name: {{ include "solr-operator.fullname" $ }}-role
913
subjects:
10-
- kind: ServiceAccount
11-
name: solr-operator
12-
namespace: {{ .Release.Namespace }}
14+
- kind: ServiceAccount
15+
name: {{ include "solr-operator.serviceAccountName" $ }}
16+
namespace: {{ $.Release.Namespace }}
17+
{{- end }}
18+
{{- end }}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
{{- if .Values.serviceAccount.create }}
12
apiVersion: v1
23
kind: ServiceAccount
34
metadata:
4-
name: solr-operator
5-
namespace: {{ .Release.Namespace }}
5+
name: {{ include "solr-operator.serviceAccountName" . }}
6+
{{- end }}

helm/solr-operator/values.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,32 @@ image:
1212
nameOverride: ""
1313
fullnameOverride: ""
1414

15-
1615
useZkOperator: "true"
1716
useEtcdOperator: "false"
1817
ingressBaseDomain: ""
1918

19+
# A comma-separated list of namespaces that the operator should watch.
20+
# If empty, the solr operator will watch all namespaces in the cluster.
21+
watchNamespaces: ""
22+
23+
rbac:
24+
# Specifies whether RBAC resources should be created
25+
create: true
26+
27+
serviceAccount:
28+
# Specifies whether a ServiceAccount should be created
29+
create: true
30+
# The name of the ServiceAccount to use.
31+
# Required if create is false.
32+
# If not set and create is true, a name is generated using the fullname template
33+
name:
34+
2035
resources:
2136
limits:
2237
cpu: 400m
2338
memory: 500Mi
2439
requests:
2540
cpu: 100m
2641
memory: 100Mi
42+
43+
envVars: []

0 commit comments

Comments
 (0)