From a45653f44b6e5dd7b83f7c741e2a5d354f2f28c1 Mon Sep 17 00:00:00 2001 From: Stephan Feurer Date: Wed, 6 Sep 2023 08:22:54 +0000 Subject: [PATCH] Add test for nodeAffinity override --- .cruft.json | 4 +- .github/workflows/release.yaml | 2 +- .github/workflows/test.yaml | 10 +++-- Makefile.vars.mk | 2 +- class/defaults.yml | 2 +- component/main.jsonnet | 17 -------- lib/openshift4-operators.libsonnet | 14 +++++++ renovate.json | 3 ++ tests/affinity-override.yml | 19 +++++++++ .../apps/openshift4-operators.yaml | 0 .../affinity-override.yaml | 42 +++++++++++++++++++ .../openshift-operators-custom.yaml | 2 +- .../openshift-operators-redhat.yaml | 2 +- .../openshift-operators.yaml | 2 +- .../operator-subscription.yaml | 2 +- 15 files changed, 93 insertions(+), 30 deletions(-) create mode 100644 tests/affinity-override.yml create mode 100644 tests/golden/affinity-override/affinity-override/apps/openshift4-operators.yaml create mode 100644 tests/golden/affinity-override/affinity-override/openshift4-operators/affinity-override.yaml diff --git a/.cruft.json b/.cruft.json index af13115..68d5d98 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,13 +1,13 @@ { "template": "https://github.com/projectsyn/commodore-component-template.git", - "commit": "fc8ae18a6798d5b232442630883e5ec9b8636d09", + "commit": "1062a6134febddc4e4b5479b41afe4ab0f6face0", "checkout": "main", "context": { "cookiecutter": { "name": "openshift4-operators", "slug": "openshift4-operators", "parameter_key": "openshift4_operators", - "test_cases": "openshift-operators-redhat openshift-operators openshift-operators-custom operator-subscription", + "test_cases": "openshift-operators-redhat openshift-operators openshift-operators-custom operator-subscription affinity-override", "add_lib": "y", "add_pp": "n", "add_golden": "y", diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 45762a9..9d1527d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -8,7 +8,7 @@ jobs: dist: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: "0" - name: Build changelog from PRs with labels diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 93034f6..ab83469 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,13 +17,13 @@ jobs: - lint_yaml - lint_adoc steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Run ${{ matrix.command }} run: make ${{ matrix.command }} editorconfig: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: snow-actions/eclint@v1.0.1 with: args: 'check' @@ -36,11 +36,12 @@ jobs: - openshift-operators - openshift-operators-custom - operator-subscription + - affinity-override defaults: run: working-directory: ${{ env.COMPONENT_NAME }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: path: ${{ env.COMPONENT_NAME }} - name: Compile component @@ -54,11 +55,12 @@ jobs: - openshift-operators - openshift-operators-custom - operator-subscription + - affinity-override defaults: run: working-directory: ${{ env.COMPONENT_NAME }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: path: ${{ env.COMPONENT_NAME }} - name: Golden diff diff --git a/Makefile.vars.mk b/Makefile.vars.mk index 0acad2a..77f34ae 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 tests/openshift-operators-custom.yml tests/operator-subscription.yml +test_instances = tests/openshift-operators-redhat.yml tests/openshift-operators.yml tests/openshift-operators-custom.yml tests/operator-subscription.yml tests/affinity-override.yml diff --git a/class/defaults.yml b/class/defaults.yml index 4ab6654..186a033 100644 --- a/class/defaults.yml +++ b/class/defaults.yml @@ -4,7 +4,7 @@ parameters: multi_instance: true namespace: ${_instance} namespaceAnnotations: - openshift.io/node-selector: node-role.kubernetes.io/infra= + openshift.io/node-selector: '' defaultInstallPlanApproval: Automatic defaultSourceNamespace: openshift-marketplace defaultSource: certified-operators diff --git a/component/main.jsonnet b/component/main.jsonnet index be06b8a..cf7c5b1 100644 --- a/component/main.jsonnet +++ b/component/main.jsonnet @@ -45,23 +45,6 @@ local sub = subscription.name, subscription.channel ) + { - spec+: { - config: { - affinity: { - nodeAffinity: { - requiredDuringSchedulingIgnoredDuringExecution: { - nodeSelectorTerms: [{ - matchExpressions: [{ - key: 'node-role.kubernetes.io/infra', - operator: 'Exists', - }], - }], - }, - }, - }, - }, - }, - } + { spec+: subscription.spec, } else null; diff --git a/lib/openshift4-operators.libsonnet b/lib/openshift4-operators.libsonnet index d5639c6..c73e549 100644 --- a/lib/openshift4-operators.libsonnet +++ b/lib/openshift4-operators.libsonnet @@ -66,6 +66,20 @@ local subscription(name) = kube._Object(apigroup + '/v1alpha1', 'Subscription', name) { spec: { name: name, + config: { + affinity: { + nodeAffinity: { + requiredDuringSchedulingIgnoredDuringExecution: { + nodeSelectorTerms: [ { + matchExpressions: [ { + key: 'node-role.kubernetes.io/infra', + operator: 'Exists', + } ], + } ], + }, + }, + }, + }, }, }; diff --git a/renovate.json b/renovate.json index 9f6db80..0cdde1a 100644 --- a/renovate.json +++ b/renovate.json @@ -4,6 +4,9 @@ ":gitSignOff", ":disableDependencyDashboard" ], + "ignorePaths": [ + ".github/**" + ], "postUpgradeTasks": { "commands": [ "make gen-golden-all" diff --git a/tests/affinity-override.yml b/tests/affinity-override.yml new file mode 100644 index 0000000..667dddc --- /dev/null +++ b/tests/affinity-override.yml @@ -0,0 +1,19 @@ +applications: + - openshift4-operators as affinity-override + +parameters: + affinity_override: + useCustomNamespace: true + subscription: + name: foo + channel: stable + spec: + installPlanApproval: Manual + config: + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/master + operator: Exists diff --git a/tests/golden/affinity-override/affinity-override/apps/openshift4-operators.yaml b/tests/golden/affinity-override/affinity-override/apps/openshift4-operators.yaml new file mode 100644 index 0000000..e69de29 diff --git a/tests/golden/affinity-override/affinity-override/openshift4-operators/affinity-override.yaml b/tests/golden/affinity-override/affinity-override/openshift4-operators/affinity-override.yaml new file mode 100644 index 0000000..a1a8d3d --- /dev/null +++ b/tests/golden/affinity-override/affinity-override/openshift4-operators/affinity-override.yaml @@ -0,0 +1,42 @@ +apiVersion: v1 +kind: Namespace +metadata: + annotations: + openshift.io/node-selector: '' + labels: + name: affinity-override + openshift.io/cluster-monitoring: 'false' + openshift.io/user-monitoring: 'false' + name: affinity-override +--- +apiVersion: operators.coreos.com/v1 +kind: OperatorGroup +metadata: + annotations: {} + labels: + name: affinity-override + name: affinity-override + namespace: affinity-override +--- +apiVersion: operators.coreos.com/v1alpha1 +kind: Subscription +metadata: + annotations: {} + labels: + name: foo + name: foo + namespace: affinity-override +spec: + channel: stable + config: + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/master + operator: Exists + installPlanApproval: Manual + name: foo + source: certified-operators + sourceNamespace: openshift-marketplace 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 index 256bcfb..40dca5b 100644 --- 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 @@ -2,7 +2,7 @@ apiVersion: v1 kind: Namespace metadata: annotations: - openshift.io/node-selector: node-role.kubernetes.io/infra= + openshift.io/node-selector: '' labels: name: openshift-operators-custom openshift.io/cluster-monitoring: 'false' diff --git a/tests/golden/openshift-operators-redhat/openshift-operators-redhat/openshift4-operators/openshift-operators-redhat.yaml b/tests/golden/openshift-operators-redhat/openshift-operators-redhat/openshift4-operators/openshift-operators-redhat.yaml index 6b8a72d..2b6b5e4 100644 --- a/tests/golden/openshift-operators-redhat/openshift-operators-redhat/openshift4-operators/openshift-operators-redhat.yaml +++ b/tests/golden/openshift-operators-redhat/openshift-operators-redhat/openshift4-operators/openshift-operators-redhat.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Namespace metadata: annotations: - openshift.io/node-selector: node-role.kubernetes.io/infra= + openshift.io/node-selector: '' labels: name: openshift-operators-redhat openshift.io/cluster-monitoring: 'true' diff --git a/tests/golden/openshift-operators/openshift-operators/openshift4-operators/openshift-operators.yaml b/tests/golden/openshift-operators/openshift-operators/openshift4-operators/openshift-operators.yaml index 9ee6fd1..0869469 100644 --- a/tests/golden/openshift-operators/openshift-operators/openshift4-operators/openshift-operators.yaml +++ b/tests/golden/openshift-operators/openshift-operators/openshift4-operators/openshift-operators.yaml @@ -13,7 +13,7 @@ spec: patchTemplate: |- "metadata": "annotations": - "openshift.io/node-selector": "node-role.kubernetes.io/infra=" + "openshift.io/node-selector": "" "labels": "openshift.io/cluster-monitoring": "false" "openshift.io/user-monitoring": "false" diff --git a/tests/golden/operator-subscription/operator-subscription/openshift4-operators/operator-subscription.yaml b/tests/golden/operator-subscription/operator-subscription/openshift4-operators/operator-subscription.yaml index 61860c2..18c1ade 100644 --- a/tests/golden/operator-subscription/operator-subscription/openshift4-operators/operator-subscription.yaml +++ b/tests/golden/operator-subscription/operator-subscription/openshift4-operators/operator-subscription.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Namespace metadata: annotations: - openshift.io/node-selector: node-role.kubernetes.io/infra= + openshift.io/node-selector: '' labels: name: operator-subscription openshift.io/cluster-monitoring: 'false'