Skip to content

Commit

Permalink
Merge pull request #9 from appuio/switch-to-more-configurable-deployment
Browse files Browse the repository at this point in the history
Make deployment more configurable
  • Loading branch information
bastjan authored Nov 4, 2021
2 parents 13a9c09 + 2a4448e commit c3499a2
Show file tree
Hide file tree
Showing 26 changed files with 1,805 additions and 96 deletions.
17 changes: 10 additions & 7 deletions class/defaults.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
parameters:
group_sync_operator:
=_metadata: {}
namespace: syn-group-sync-operator
subscription:
channel: 'alpha'
installPlanApproval: 'Automatic'
name: 'group-sync-operator'
source: 'community-operators'
sourceNamespace: 'openshift-marketplace'

images:
operator:
registry: quay.io
repository: redhat-cop/group-sync-operator
tag: v0.0.14

manifest_version: ${group_sync_operator:images:operator:tag}
manifest_url: https://raw.githubusercontent.com/redhat-cop/group-sync-operator/${group_sync_operator:manifest_version}/config

sync: {}
secrets: {}
30 changes: 29 additions & 1 deletion class/group-sync-operator.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
parameters:
kapitan:
dependencies:
- type: https
source: ${group_sync_operator:manifest_url}/crd/bases/redhatcop.redhat.io_groupsyncs.yaml
output_path: dependencies/group-sync-operator/manifests/crds/${group_sync_operator:manifest_version}/redhatcop.redhat.io_groupsyncs.yaml

- type: https
source: ${group_sync_operator:manifest_url}/manager/manager.yaml
output_path: dependencies/group-sync-operator/manifests/controller/${group_sync_operator:manifest_version}/deployment.yaml
- type: https
source: ${group_sync_operator:manifest_url}/rbac/role.yaml
output_path: dependencies/group-sync-operator/manifests/controller/${group_sync_operator:manifest_version}/role.yaml
- type: https
source: ${group_sync_operator:manifest_url}/rbac/role_binding.yaml
output_path: dependencies/group-sync-operator/manifests/controller/${group_sync_operator:manifest_version}/role_binding.yaml
- type: https
source: ${group_sync_operator:manifest_url}/rbac/leader_election_role.yaml
output_path: dependencies/group-sync-operator/manifests/controller/${group_sync_operator:manifest_version}/leader_election_role.yaml
- type: https
source: ${group_sync_operator:manifest_url}/rbac/leader_election_role_binding.yaml
output_path: dependencies/group-sync-operator/manifests/controller/${group_sync_operator:manifest_version}/leader_election_role_binding.yaml
- type: https
source: ${group_sync_operator:manifest_url}/rbac/service_account.yaml
output_path: dependencies/group-sync-operator/manifests/controller/${group_sync_operator:manifest_version}/service_account.yaml

compile:
- input_paths:
- group-sync-operator/manifests/crds/${group_sync_operator:manifest_version}/
input_type: copy
output_path: group-sync-operator/00_crds/

- input_paths:
- group-sync-operator/component/app.jsonnet
input_type: jsonnet
output_path: apps/
- input_paths:
- group-sync-operator/component/main.jsonnet
- group-sync-operator/component/operator.jsonnet
- group-sync-operator/component/config.jsonnet
input_type: jsonnet
output_path: group-sync-operator/
16 changes: 16 additions & 0 deletions component/common.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local CommonLabels = {
'app.kubernetes.io/managed-by': 'commodore',
'app.kubernetes.io/part-of': 'syn',
'app.kubernetes.io/name': 'group-sync-operator',
};

local AddCommonLabels = function(object) object {
metadata+: {
labels+: CommonLabels,
},
};

{
CommonLabels: CommonLabels,
AddCommonLabels: AddCommonLabels,
}
90 changes: 89 additions & 1 deletion component/main.jsonnet
Original file line number Diff line number Diff line change
@@ -1,10 +1,98 @@
// main template for group-sync-operator
local common = import 'common.libsonnet';
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';
local inv = kap.inventory();
// The hiera parameters for the component
local params = inv.parameters.group_sync_operator;

local prefix = 'group-sync-';

local role = std.parseJson(kap.yaml_load('group-sync-operator/manifests/controller/' + params.manifest_version + '/role.yaml'));
local service_account = std.parseJson(kap.yaml_load('group-sync-operator/manifests/controller/' + params.manifest_version + '/service_account.yaml'));
local role_binding = std.parseJson(kap.yaml_load('group-sync-operator/manifests/controller/' + params.manifest_version + '/role_binding.yaml'));
local leader_election_role = std.parseJson(kap.yaml_load('group-sync-operator/manifests/controller/' + params.manifest_version + '/leader_election_role.yaml'));
local leader_election_role_binding = std.parseJson(kap.yaml_load('group-sync-operator/manifests/controller/' + params.manifest_version + '/leader_election_role_binding.yaml'));
local deployment = std.filter(
function(o) o.kind == 'Deployment',
std.parseJson(kap.yaml_load_stream('group-sync-operator/manifests/controller/' + params.manifest_version + '/deployment.yaml'))
)[0];

local image = '%(registry)s/%(repository)s:%(tag)s' % params.images.operator;

local objects = [
leader_election_role {
metadata+: {
name: prefix + super.name,
},
},
leader_election_role_binding {
metadata+: {
name: prefix + super.name,
},
roleRef+: {
name: prefix + super.name,
},
subjects: std.map(function(s) s {
name: prefix + super.name,
namespace: params.namespace,
}, super.subjects),
},
role {
metadata+: {
name: prefix + super.name,
},
},
role_binding {
metadata+: {
name: prefix + super.name,
},
roleRef+: {
name: prefix + super.name,
},
subjects: std.map(function(s) s {
name: prefix + super.name,
namespace: params.namespace,
}, super.subjects),
},
service_account {
metadata+: {
name: prefix + super.name,
},
},
deployment {
metadata+: {
name: prefix + super.name,
},
spec+: {
template+: {
spec+: {
serviceAccountName: prefix + super.serviceAccountName,
containers: [
if c.name == 'manager' then
c {
image: image,
args: [],
}
else
c
for c in super.containers
],
},
},
},
},
];

{
'10_namespace': kube.Namespace(params.namespace),
}
+
{
'00_namespace': kube.Namespace(params.namespace),
['20_' + std.asciiLower(obj.kind) + '_' + std.asciiLower(obj.metadata.name)]: common.AddCommonLabels(obj) {
metadata+: {
namespace: params.namespace,
},
}
for obj in objects
}
43 changes: 0 additions & 43 deletions component/operator.jsonnet

This file was deleted.

19 changes: 13 additions & 6 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ default:: `syn-group-sync-operator`

The namespace in which to deploy this component.


== `subscription`
== `images`

[horizontal]
type:: dict
type:: dictionary
default::
+
[source,yaml]
----
operator:
registry: quay.io
repository: redhat-cop/group-sync-operator
tag: v0.0.14
----

Dictionary containing the container images used by this component.

The operator subscription details.
The `group-sync-operator` is installed through the OperatorHub.
This field gives you the option to directly modify the operator subscription specification.

== `sync`

Expand Down
Loading

0 comments on commit c3499a2

Please sign in to comment.