Skip to content

Commit

Permalink
Merge pull request #28 from appuio/feat/manage-subscription
Browse files Browse the repository at this point in the history
Add new component parameter for managing a subscription
  • Loading branch information
simu authored Mar 14, 2023
2 parents 645b243 + 51d1c0b commit 1f38ae3
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"template": "https://github.com/projectsyn/commodore-component-template.git",
"commit": "804e9c72df5f0507e18de8a374fc35b694b6fb08",
"commit": "73f964d1a9b834a772169d1ffe2b4406f90b2472",
"checkout": "main",
"context": {
"cookiecutter": {
"name": "openshift4-operators",
"slug": "openshift4-operators",
"parameter_key": "openshift4_operators",
"test_cases": "openshift-operators-redhat openshift-operators",
"test_cases": "openshift-operators-redhat openshift-operators openshift-operators-custom operator-subscription",
"add_lib": "y",
"add_pp": "n",
"add_golden": "y",
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- openshift-operators-redhat
- openshift-operators
- openshift-operators-custom
- operator-subscription
defaults:
run:
working-directory: ${{ env.COMPONENT_NAME }}
Expand All @@ -52,6 +53,7 @@ jobs:
- openshift-operators-redhat
- openshift-operators
- openshift-operators-custom
- operator-subscription
defaults:
run:
working-directory: ${{ env.COMPONENT_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile.vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 tests/openshift-operators-custom.yml
test_instances = tests/openshift-operators-redhat.yml tests/openshift-operators.yml tests/openshift-operators-custom.yml tests/operator-subscription.yml
6 changes: 6 additions & 0 deletions class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ parameters:
openshift.io/node-selector: node-role.kubernetes.io/infra=
defaultInstallPlanApproval: Automatic
defaultSourceNamespace: openshift-marketplace
defaultSource: certified-operators
useCustomNamespace: false

subscription:
name: null
channel: null
spec: {}

openshift_operators:
defaultSource: certified-operators

Expand Down
30 changes: 24 additions & 6 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// main template for openshift4-operators
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';
Expand Down Expand Up @@ -35,11 +36,28 @@ local operatorgroup =

local nspatch = po.Patch(ns, nsmeta);

local subscription = params.subscription;
local sub =
// Create subscription, if name is given
if subscription.name != null then
operatorlib.managedSubscription(
params.namespace,
subscription.name,
subscription.channel
) + {
spec+: subscription.spec,
}
else null;

{
[namespace]:
if namespace != 'openshift-operators' then [
ns,
operatorgroup,
]
else nspatch,
[namespace]: std.filter(
function(it) it != null,
(
if namespace != 'openshift-operators' then [
ns,
operatorgroup,
]
else nspatch
) + [ sub ]
),
}
33 changes: 33 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,36 @@ 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`.

== `subscription`

This parameter allows users of the component to configure one subscription per instance.
The component explicitly doesn't allow configuring multiple instances in the same namespace, since we've seen various issues with conflicting upgrades when multiple subscriptions are created in the same namespace, especially when `installPlanApproval=Manual` is required for some reason.

=== `subscription.name`

[horizontal]
type:: string
default:: `null`

The name of the operator to create a subscription for.
If this field isn't `null`, the component will create a `Subscription` object.

=== `subscription.channel`

[horizontal]
type:: string
default:: `null`

The name of the update channel to use for the subscription.

=== `subscription.spec`

[horizontal]
type:: object
default:: `{}`

This field is merged into the base `Subscription` object.
You can override any valid fields in the `Subscription` object's `spec` here.

IMPORTANT: The component doesn't validate the contents of this parameter.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: v1
kind: Namespace
metadata:
annotations:
openshift.io/node-selector: node-role.kubernetes.io/infra=
labels:
name: operator-subscription
openshift.io/cluster-monitoring: 'false'
openshift.io/user-monitoring: 'false'
name: operator-subscription
---
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
annotations: {}
labels:
name: operator-subscription
name: operator-subscription
namespace: operator-subscription
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
annotations: {}
labels:
name: foo
name: foo
namespace: operator-subscription
spec:
channel: stable
installPlanApproval: Manual
name: foo
source: certified-operators
sourceNamespace: openshift-marketplace
11 changes: 11 additions & 0 deletions tests/operator-subscription.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
applications:
- openshift4-operators as operator-subscription

parameters:
operator_subscription:
useCustomNamespace: true
subscription:
name: foo
channel: stable
spec:
installPlanApproval: Manual

0 comments on commit 1f38ae3

Please sign in to comment.