From abcabbf05e4bc8382adbe2fc449fc369e0c18af8 Mon Sep 17 00:00:00 2001 From: Stephan Feurer Date: Sun, 7 Jul 2024 17:14:55 +0200 Subject: [PATCH] Refactor OperatorGroup and Subscription generation code --- component/main.jsonnet | 132 +++++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 58 deletions(-) diff --git a/component/main.jsonnet b/component/main.jsonnet index 8d95afd..02fdcd8 100644 --- a/component/main.jsonnet +++ b/component/main.jsonnet @@ -1,11 +1,14 @@ local com = import 'lib/commodore.libjsonnet'; local kap = import 'lib/kapitan.libjsonnet'; local kube = import 'lib/kube.libjsonnet'; -local operatorlib = import 'lib/openshift4-operators.libsonnet'; +local operator = import 'lib/openshift4-operators.libsonnet'; local inv = kap.inventory(); local params = inv.parameters.openshift4_logging; +local deployLokistack = params.components.lokistack.enabled; +local deployElasticsearch = params.components.elasticsearch.enabled; + local group = 'operators.coreos.com/'; local clusterLoggingGroupVersion = 'logging.openshift.io/v1'; @@ -57,69 +60,82 @@ local pipelineOutputRefs(pipeline) = local default = if forwardingOnly then [] else [ 'default' ]; std.get(pipeline, 'forwarders', []) + default; -{ - '00_namespace': kube.Namespace(params.namespace) { - metadata+: { - annotations+: { - 'openshift.io/node-selector': '', - }, - labels+: { - 'openshift.io/cluster-monitoring': 'true', - }, +// Namespace + +local namespace = kube.Namespace(params.namespace) { + metadata+: { + annotations+: { + 'openshift.io/node-selector': '', + }, + labels+: { + 'openshift.io/cluster-monitoring': 'true', }, }, - '10_operator_group': operatorlib.OperatorGroup('cluster-logging') { - metadata+: { - namespace: params.namespace, +}; + +// OperatorGroup + +local operatorGroup = operator.OperatorGroup('cluster-logging') { + metadata+: { + namespace: params.namespace, + }, + spec: { + targetNamespaces: [ + params.namespace, + ], + }, +}; + +// Subscriptions + +local logging = operator.namespacedSubscription( + params.namespace, + 'cluster-logging', + params.channel, + 'redhat-operators' +) { + spec+: { + config+: { + resources: params.operatorResources.clusterLogging, }, - spec: { - targetNamespaces: [ - params.namespace, - ], + }, +}; + +local lokistack = if deployLokistack then operator.managedSubscription( + 'openshift-operators-redhat', + 'loki-operator', + params.channel +) { + spec+: { + config+: { + resources: params.operatorResources.lokistack, }, }, - '20_subscriptions': [ - operatorlib.namespacedSubscription( - params.namespace, - 'cluster-logging', - params.channel, - 'redhat-operators' - ) { - spec+: { - config+: { - resources: params.operatorResources.clusterLogging, - }, - }, +}; + +local elasticsearch = if deployElasticsearch then operator.managedSubscription( + 'openshift-operators-redhat', + 'elasticsearch-operator', + params.channel +) { + spec+: { + config+: { + resources: params.operatorResources.elasticsearch, }, - ] + ( - if params.components.lokistack.enabled then [ - operatorlib.managedSubscription( - 'openshift-operators-redhat', - 'loki-operator', - params.channel - ) { - spec+: { - config+: { - resources: params.operatorResources.lokistack, - }, - }, - }, - ] else [] - ) + ( - if params.components.elasticsearch.enabled then [ - operatorlib.managedSubscription( - 'openshift-operators-redhat', - 'elasticsearch-operator', - params.channel - ) { - spec+: { - config+: { - resources: params.operatorResources.elasticsearch, - }, - }, - }, - ] else [] - ), + }, +}; + +local subscriptions = std.filter(function(it) it != null, [ + logging, + lokistack, + elasticsearch, +]); + + +{ + '00_namespace': namespace, + '10_operator_group': operatorGroup, + '20_subscriptions': subscriptions, '30_cluster_logging': std.mergePatch( // ClusterLogging resource from inventory kube._Object(clusterLoggingGroupVersion, 'ClusterLogging', 'instance') {