Skip to content

Commit

Permalink
Allow user-defined install namespace for operator (#122)
Browse files Browse the repository at this point in the history
* feature: replaced hardcoded namespace with chart release

This replaces the hardcoded namespace of "opentelemetry-operator-system" (under the
{{ template "opentelemetry-operator.namespace" . }} helper definition)
with the user-defined release namespace accessed through {{ .Release.Namespace }}
  • Loading branch information
julienvincent authored Feb 11, 2022
1 parent 633e62a commit 686a475
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 63 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ jobs:
until kubectl get ns opentelemetry-operator-system 2>&1 | grep "namespaces \"opentelemetry-operator-system\" not found"; do sleep 1; done
sudo curl -Lo /usr/local/bin/kubectl-kuttl https://github.com/kudobuilder/kuttl/releases/download/v0.11.1/kubectl-kuttl_0.11.1_linux_x86_64
sudo chmod +x /usr/local/bin/kubectl-kuttl
helm install my-opentelemetry-operator ./charts/opentelemetry-operator
kubectl create namespace opentelemetry-operator-system
helm install --namespace=opentelemetry-operator-system my-opentelemetry-operator ./charts/opentelemetry-operator
kubectl wait --timeout=5m --for=condition=available deployment opentelemetry-operator-controller-manager -n opentelemetry-operator-system
git clone https://github.com/open-telemetry/opentelemetry-operator.git
kubectl kuttl test ./opentelemetry-operator/tests/e2e --config ./charts/opentelemetry-operator/release/kuttl-test.yaml
Expand Down
2 changes: 1 addition & 1 deletion charts/opentelemetry-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: opentelemetry-operator
version: 0.5.4
version: 0.6.0
description: OpenTelemetry Operator Helm chart for Kubernetes
type: application
home: https://opentelemetry.io/
Expand Down
20 changes: 3 additions & 17 deletions charts/opentelemetry-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,18 @@ _See [helm repo](https://helm.sh/docs/helm/helm_repo/) for command documentation

## Install Chart

If you didn't create the namespace `opentelemetry-operator-system` before (steps in the third method to generate the TLS cert),
the OpenTelemetry Operator chart will be installed in the namespace automatically. The installation command example is as below.

```console
$ helm install \
my-opentelemetry-operator open-telemetry/opentelemetry-operator
```

However, if you create the namespace and place the TLS cert in the desired secret, you will need to set `createNamespace`
to `false` to make sure Helm won't try to create an existing namespace, which would cause an error. Installation command example is as below.
If you created a custom namespace, like in the TLS Certificate Requirement section above, you will need to specify the namespace with the `--namespace` helm option:

```console
$ helm install \
my-opentelemetry-operator open-telemetry/opentelemetry-operator \
--set createNamespace=false
$ helm install --namespace opentelemetry-operator-system \
my-opentelemetry-operator open-telemetry/opentelemetry-operator
```

Note that `--namespace` option here won't affect where the OpenTelemetry Operator and other resources this chart contains are installed.
It will only affect on where the Helm chart release info is stored, which is `default` namespace by default.

_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._

## Uninstall Chart
Expand All @@ -98,12 +90,6 @@ The OpenTelemetry Collector CRD created by this chart won't be removed by defaul
$ kubectl delete crd opentelemetrycollectors.opentelemetry.io
```

If the namespace wasn't created by the Helm chart, you'll need to manually remove it as well:

```console
$ kubectl delete ns opentelemetry-operator-system
```

## Upgrade Chart

```console
Expand Down
2 changes: 1 addition & 1 deletion charts/opentelemetry-operator/release/release-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- [ ] If you see any template files need to be updated, update them to maintain consistency with the ones in the manifest (especially be careful with `role.yaml` and `clusterrole.yaml`). \
Create a new YAML file under `templates` directory if it doesn't exist.
Use `{{ template "opentelemetry-operator.name" . }}` to represent the name of OTEL Operator which probably is `opentelemetry-operator` in the manifest.
Use `{{ template "opentelemetry-operator.namespace" . }}` to represent the namespace which probably is `opentelemetry-operator-system` in the manifest.
Use `{{ .Release.Namespace }}` to represent the namespace.
- [ ] Update `README` if there is a breaking change in the Operator Helm chart
- [ ] Bump chart version in `Chart.yaml`

Expand Down
7 changes: 0 additions & 7 deletions charts/opentelemetry-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,3 @@ Selector labels
app.kubernetes.io/name: {{ include "opentelemetry-operator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Define the namespace where the resources in the chart will be installed.
*/}}
{{- define "opentelemetry-operator.namespace" -}}
opentelemetry-operator-system
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
annotations:
cert-manager.io/inject-ca-from: {{ printf "%s/%s-serving-cert" (include "opentelemetry-operator.namespace" .) (include "opentelemetry-operator.name" .) }}
cert-manager.io/inject-ca-from: {{ printf "%s/%s-serving-cert" .Release.Namespace (include "opentelemetry-operator.name" .) }}
labels:
app.kubernetes.io/name: opentelemetry-operator
name: {{ template "opentelemetry-operator.name" . }}-mutating-webhook-configuration
Expand All @@ -13,7 +13,7 @@ webhooks:
clientConfig:
service:
name: {{ template "opentelemetry-operator.name" . }}-webhook-service
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
path: /mutate-opentelemetry-io-v1alpha1-instrumentation
failurePolicy: Fail
name: minstrumentation.kb.io
Expand All @@ -33,7 +33,7 @@ webhooks:
clientConfig:
service:
name: {{ template "opentelemetry-operator.name" . }}-webhook-service
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
path: /mutate-opentelemetry-io-v1alpha1-opentelemetrycollector
failurePolicy: {{ .Values.admissionWebhooks.failurePolicy }}
name: mopentelemetrycollector.kb.io
Expand All @@ -53,7 +53,7 @@ webhooks:
clientConfig:
service:
name: {{ template "opentelemetry-operator.name" . }}-webhook-service
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
path: /mutate-v1-pod
failurePolicy: Ignore
name: mpod.kb.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
annotations:
cert-manager.io/inject-ca-from: {{ printf "%s/%s-serving-cert" (include "opentelemetry-operator.namespace" .) (include "opentelemetry-operator.name" .) }}
cert-manager.io/inject-ca-from: {{ printf "%s/%s-serving-cert" .Release.Namespace (include "opentelemetry-operator.name" .) }}
labels:
app.kubernetes.io/name: opentelemetry-operator
name: {{ template "opentelemetry-operator.name" . }}-validating-webhook-configuration
Expand All @@ -13,7 +13,7 @@ webhooks:
clientConfig:
service:
name: {{ template "opentelemetry-operator.name" . }}-webhook-service
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
path: /validate-opentelemetry-io-v1alpha1-instrumentation
failurePolicy: Fail
name: vinstrumentationcreateupdate.kb.io
Expand All @@ -33,7 +33,7 @@ webhooks:
clientConfig:
service:
name: {{ template "opentelemetry-operator.name" . }}-webhook-service
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
path: /validate-opentelemetry-io-v1alpha1-instrumentation
failurePolicy: Ignore
name: vinstrumentationdelete.kb.io
Expand All @@ -52,7 +52,7 @@ webhooks:
clientConfig:
service:
name: {{ template "opentelemetry-operator.name" . }}-webhook-service
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
path: /validate-opentelemetry-io-v1alpha1-opentelemetrycollector
failurePolicy: {{ .Values.admissionWebhooks.failurePolicy }}
name: vopentelemetrycollectorcreateupdate.kb.io
Expand All @@ -72,7 +72,7 @@ webhooks:
clientConfig:
service:
name: {{ template "opentelemetry-operator.name" . }}-webhook-service
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
path: /validate-opentelemetry-io-v1alpha1-opentelemetrycollector
failurePolicy: Ignore
name: vopentelemetrycollectordelete.kb.io
Expand Down
8 changes: 4 additions & 4 deletions charts/opentelemetry-operator/templates/certmanager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ metadata:
labels:
app.kubernetes.io/name: opentelemetry-operator
name: {{ template "opentelemetry-operator.name" . }}-serving-cert
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
spec:
dnsNames:
- {{ template "opentelemetry-operator.name" . }}-webhook-service.{{ template "opentelemetry-operator.namespace" . }}.svc
- {{ template "opentelemetry-operator.name" . }}-webhook-service.{{ template "opentelemetry-operator.namespace" . }}.svc.cluster.local
- {{ template "opentelemetry-operator.name" . }}-webhook-service.{{ .Release.Namespace }}.svc
- {{ template "opentelemetry-operator.name" . }}-webhook-service.{{ .Release.Namespace }}.svc.cluster.local
issuerRef:
{{- if .Values.admissionWebhooks.certManager.issuerRef }}
{{- toYaml .Values.admissionWebhooks.certManager.issuerRef | nindent 4 }}
Expand All @@ -29,7 +29,7 @@ metadata:
labels:
app.kubernetes.io/name: opentelemetry-operator
name: {{ template "opentelemetry-operator.name" . }}-selfsigned-issuer
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
spec:
selfSigned: {}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ roleRef:
subjects:
- kind: ServiceAccount
name: {{ template "opentelemetry-operator.name" . }}-controller-manager
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand All @@ -26,4 +26,4 @@ roleRef:
subjects:
- kind: ServiceAccount
name: {{ template "opentelemetry-operator.name" . }}-controller-manager
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
2 changes: 1 addition & 1 deletion charts/opentelemetry-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
app.kubernetes.io/name: opentelemetry-operator
control-plane: controller-manager
name: {{ template "opentelemetry-operator.name" . }}-controller-manager
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
spec:
replicas: 1
selector:
Expand Down
9 changes: 0 additions & 9 deletions charts/opentelemetry-operator/templates/namespace.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion charts/opentelemetry-operator/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
labels:
app.kubernetes.io/name: opentelemetry-operator
name: {{ template "opentelemetry-operator.name" . }}-leader-election-role
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
rules:
- apiGroups:
- ""
Expand Down
4 changes: 2 additions & 2 deletions charts/opentelemetry-operator/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ metadata:
labels:
app.kubernetes.io/name: opentelemetry-operator
name: {{ template "opentelemetry-operator.name" . }}-leader-election-rolebinding
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ template "opentelemetry-operator.name" . }}-leader-election-role
subjects:
- kind: ServiceAccount
name: {{ template "opentelemetry-operator.name" . }}-controller-manager
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
4 changes: 2 additions & 2 deletions charts/opentelemetry-operator/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
app.kubernetes.io/name: opentelemetry-operator
control-plane: controller-manager
name: {{ template "opentelemetry-operator.name" . }}-controller-manager-metrics-service
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
spec:
ports:
- name: https
Expand All @@ -22,7 +22,7 @@ metadata:
labels:
app.kubernetes.io/name: opentelemetry-operator
name: {{ template "opentelemetry-operator.name" . }}-webhook-service
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
spec:
ports:
- port: 443
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ metadata:
labels:
app.kubernetes.io/name: opentelemetry-operator
name: {{ template "opentelemetry-operator.name" . }}-controller-manager
namespace: {{ template "opentelemetry-operator.namespace" . }}
namespace: {{ .Release.Namespace }}
5 changes: 0 additions & 5 deletions charts/opentelemetry-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
##
nameOverride: ""

## Create the opentelemetry-operator-system namespace where the operator will be installed to.
## Disable this if you have already created the namespace.
##
createNamespace: true

## Provide OpenTelemetry Operator manager container image and resources.
##
manager:
Expand Down

0 comments on commit 686a475

Please sign in to comment.