Skip to content

Commit

Permalink
Merge pull request #139 from appuio/refactor/operator-manifests
Browse files Browse the repository at this point in the history
Refactor OperatorGroup and Subscription generation code
  • Loading branch information
DebakelOrakel authored Jul 8, 2024
2 parents d665496 + 0970b62 commit f47ae20
Showing 1 changed file with 73 additions and 57 deletions.
130 changes: 73 additions & 57 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ local operatorlib = 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';

Expand Down Expand Up @@ -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 = operatorlib.OperatorGroup('cluster-logging') {
metadata+: {
namespace: params.namespace,
},
spec: {
targetNamespaces: [
params.namespace,
],
},
};

// Subscriptions

local logging = operatorlib.namespacedSubscription(
params.namespace,
'cluster-logging',
params.channel,
'redhat-operators'
) {
spec+: {
config+: {
resources: params.operatorResources.clusterLogging,
},
spec: {
targetNamespaces: [
params.namespace,
],
},
};

local lokistack = if deployLokistack then operatorlib.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 operatorlib.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,
]);

// Define outputs below
{
'00_namespace': namespace,
'10_operator_group': operatorGroup,
'20_subscriptions': subscriptions,
'30_cluster_logging': std.mergePatch(
// ClusterLogging resource from inventory
kube._Object(clusterLoggingGroupVersion, 'ClusterLogging', 'instance') {
Expand Down

0 comments on commit f47ae20

Please sign in to comment.