diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e845c07..00b6a37 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -34,6 +34,7 @@ jobs: instance: - openshift-operators-redhat - openshift-operators + - openshift-operators-custom defaults: run: working-directory: ${{ env.COMPONENT_NAME }} @@ -50,6 +51,7 @@ jobs: instance: - openshift-operators-redhat - openshift-operators + - openshift-operators-custom defaults: run: working-directory: ${{ env.COMPONENT_NAME }} diff --git a/Makefile.vars.mk b/Makefile.vars.mk index 8041d06..5631b7b 100644 --- a/Makefile.vars.mk +++ b/Makefile.vars.mk @@ -57,4 +57,4 @@ KUBENT_IMAGE ?= ghcr.io/doitintl/kube-no-trouble:latest KUBENT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --entrypoint=/app/kubent $(KUBENT_IMAGE) instance ?= openshift-operators-redhat -test_instances = tests/openshift-operators-redhat.yml tests/openshift-operators.yml +test_instances = tests/openshift-operators-redhat.yml tests/openshift-operators.yml tests/openshift-operators-custom.yml diff --git a/class/defaults.yml b/class/defaults.yml index 7266b01..4176156 100644 --- a/class/defaults.yml +++ b/class/defaults.yml @@ -7,6 +7,7 @@ parameters: openshift.io/node-selector: node-role.kubernetes.io/infra= defaultInstallPlanApproval: Automatic defaultSourceNamespace: openshift-marketplace + useCustomNamespace: false monitoring: enabled: true diff --git a/docs/modules/ROOT/pages/references/parameters.adoc b/docs/modules/ROOT/pages/references/parameters.adoc index 98eaccc..2eda811 100644 --- a/docs/modules/ROOT/pages/references/parameters.adoc +++ b/docs/modules/ROOT/pages/references/parameters.adoc @@ -9,7 +9,7 @@ type:: string default:: `${_instance}` The namespace to create for the component instance. -The component is implemented in such a way that only instances (and therefore namespaces) `openshift-operators` and `openshift-operators-redhat` can be created. +The component is implemented in such a way that only instances (and therefore namespaces) `openshift-operators` and `openshift-operators-redhat` can be created, unless `useCustomNamespace` is set to `true`. Generally, it shouldn't be necessary to override this parameter. == `namespaceAnnotations` @@ -63,6 +63,15 @@ The component defaults to `certified-operators` for instance `openshift-operator This source provides community-maintained operators which are certified by RedHat. Alternatively, you can use `community-operators` for other community-maintained operators. +== `useCustomNamespace` + +[horizontal] +type:: boolean +default:: `false` + +Whether to allow non-standard namespace names for the OperatorGroup. +If this parameter is set to `true`, the component will allow using namespace names other than `openshift-operators` and `openshift-operators-redhat`. + == `monitoring` This parameter allows users to enable the component's monitoring configuration. diff --git a/lib/openshift4-operators.libsonnet b/lib/openshift4-operators.libsonnet index fc59bd7..d5639c6 100644 --- a/lib/openshift4-operators.libsonnet +++ b/lib/openshift4-operators.libsonnet @@ -37,8 +37,10 @@ local validateInstance(instance, checkTargets=false, checkSource='') = 'openshift-operators-redhat', ]); + local use_custom_namespace = instanceParams(instance).useCustomNamespace; + assert - std.setMember(instance, supported_instances) : + use_custom_namespace || std.setMember(instance, supported_instances) : "\n Invalid instance '%s' for component openshift4-operators." % [ instance, ] + diff --git a/tests/golden/openshift-operators-custom/openshift-operators-custom/apps/openshift4-operators.yaml b/tests/golden/openshift-operators-custom/openshift-operators-custom/apps/openshift4-operators.yaml new file mode 100644 index 0000000..e69de29 diff --git a/tests/golden/openshift-operators-custom/openshift-operators-custom/openshift4-operators/monitoring.yaml b/tests/golden/openshift-operators-custom/openshift-operators-custom/openshift4-operators/monitoring.yaml new file mode 100644 index 0000000..c23b865 --- /dev/null +++ b/tests/golden/openshift-operators-custom/openshift-operators-custom/openshift4-operators/monitoring.yaml @@ -0,0 +1,107 @@ +apiVersion: v1 +kind: Namespace +metadata: + annotations: {} + labels: + monitoring.syn.tools/infra: 'true' + name: syn-monitoring-openshift4-operators + name: syn-monitoring-openshift4-operators +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + annotations: {} + labels: + name: openshift-marketplace-operator + name: openshift-marketplace-operator + namespace: syn-monitoring-openshift4-operators +spec: + endpoints: + - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + interval: 30s + metricRelabelings: + - action: drop + regex: etcd_(debugging|disk|request|server).* + sourceLabels: + - __name__ + - action: drop + regex: (go_.*|process_.*|promhttp_.*) + sourceLabels: + - __name__ + port: https-metrics + scheme: https + tlsConfig: + caFile: /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt + serverName: marketplace-operator-metrics.openshift-marketplace.svc + namespaceSelector: + matchNames: + - openshift-marketplace + selector: + matchLabels: + name: marketplace-operator +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + annotations: {} + labels: + name: openshift-catalog-operator + name: openshift-catalog-operator + namespace: syn-monitoring-openshift4-operators +spec: + endpoints: + - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + interval: 30s + metricRelabelings: + - action: drop + regex: etcd_(debugging|disk|request|server).* + sourceLabels: + - __name__ + - action: drop + regex: (go_.*|process_.*|promhttp_.*) + sourceLabels: + - __name__ + port: https-metrics + scheme: https + tlsConfig: + caFile: /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt + serverName: catalog-operator-metrics.openshift-operator-lifecycle-manager.svc + namespaceSelector: + matchNames: + - openshift-operator-lifecycle-manager + selector: + matchLabels: + app: catalog-operator +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + annotations: {} + labels: + name: openshift-olm-operator + name: openshift-olm-operator + namespace: syn-monitoring-openshift4-operators +spec: + endpoints: + - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + interval: 30s + metricRelabelings: + - action: drop + regex: etcd_(debugging|disk|request|server).* + sourceLabels: + - __name__ + - action: drop + regex: (go_.*|process_.*|promhttp_.*) + sourceLabels: + - __name__ + port: https-metrics + scheme: https + tlsConfig: + caFile: /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt + serverName: olm-operator-metrics.openshift-operator-lifecycle-manager.svc + namespaceSelector: + matchNames: + - openshift-operator-lifecycle-manager + selector: + matchLabels: + app: olm-operator diff --git a/tests/golden/openshift-operators-custom/openshift-operators-custom/openshift4-operators/openshift-operators-custom.yaml b/tests/golden/openshift-operators-custom/openshift-operators-custom/openshift4-operators/openshift-operators-custom.yaml new file mode 100644 index 0000000..256bcfb --- /dev/null +++ b/tests/golden/openshift-operators-custom/openshift-operators-custom/openshift4-operators/openshift-operators-custom.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Namespace +metadata: + annotations: + openshift.io/node-selector: node-role.kubernetes.io/infra= + labels: + name: openshift-operators-custom + openshift.io/cluster-monitoring: 'false' + openshift.io/user-monitoring: 'false' + name: openshift-operators-custom +--- +apiVersion: operators.coreos.com/v1 +kind: OperatorGroup +metadata: + annotations: {} + labels: + name: openshift-operators-custom + name: openshift-operators-custom + namespace: openshift-operators-custom diff --git a/tests/openshift-operators-custom.yml b/tests/openshift-operators-custom.yml new file mode 100644 index 0000000..e9ddde2 --- /dev/null +++ b/tests/openshift-operators-custom.yml @@ -0,0 +1,15 @@ +applications: + - prometheus + +parameters: + kapitan: + dependencies: + - type: https + source: https://raw.githubusercontent.com/projectsyn/component-prometheus/master/lib/prometheus.libsonnet + output_path: vendor/lib/prometheus.libsonnet + + prometheus: + defaultInstance: infra + + openshift_operators_custom: + useCustomNamespace: true