Skip to content

Commit

Permalink
fix(cluster-scanner): corrected parsing of onPremCompatibilityVersion…
Browse files Browse the repository at this point in the history
… param
  • Loading branch information
michele-mangili committed Aug 31, 2023
1 parent 45eb342 commit 43b847f
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 9 deletions.
4 changes: 2 additions & 2 deletions charts/cluster-scanner/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Define the proper imageRegistry to use for imageSbomExtractor
{{/*
Cluster scanner version compatibility check.
If .Values.onPremCompatibilityVersion is set to 6.2, it checks whether
If .Values.onPremCompatibilityVersion is set to 6.5.0 or below, it checks whether
the provided tag is < 1.0.0 .
Otherwise, it checks if the provided tag is >= 1.0.0 .
Expand All @@ -218,7 +218,7 @@ Version tags must be semver2-compatible otherwise no check will be performed.
{{- define "cluster-scanner.checkVersionCompatibility" -}}
{{- if regexMatch "^[0-9]+\\.[0-9]+\\.[0-9]+.*" .Tag -}}
{{- $version := semver .Tag -}}
{{- if and (hasKey (default .Values dict) "onPremCompatibilityVersion") (eq .Values.onPremCompatibilityVersion "6.2") -}}
{{- if and (hasKey (default .Values dict) "onPremCompatibilityVersion") (eq (semver .Values.onPremCompatibilityVersion | (semver "6.5.0").Compare) 1) -}}
{{- if ne ($version | (semver "1.0.0").Compare) 1 -}}
{{- fail (printf "incompatible version for %s, set %s expected < 1.0.0" .Component .Tag) -}}
{{- end -}}
Expand Down
88 changes: 81 additions & 7 deletions charts/cluster-scanner/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ tests:
- failedTemplate:
errorMessage: "incompatible version for runtimeStatusIntegrator.image.tag, set 4.3.4 expected < 1.0.0"

- it: "fails if the onPremCompatibilityVersion is not set to 6.2 the imageSbomExtractor version is incorrect"
- it: "fails if the onPremCompatibilityVersion is set to 6.2 and the imageSbomExtractor version is incorrect"
templates:
- ../templates/deployment.yaml
set:
Expand All @@ -230,17 +230,61 @@ tests:
- ../templates/deployment.yaml
set:
onPremCompatibilityVersion: "6.3"
runtimeStatusIntegrator.image.tag: "4.3.4"
imageSbomExtractor.image.tag: "0.3.4"
asserts:
- failedTemplate:
errorMessage: "incompatible version for runtimeStatusIntegrator.image.tag, set 4.3.4 expected < 1.0.0"

- it: "fails if the onPremCompatibilityVersion is set to 6.3 and the imageSbomExtractor version is incorrect"
templates:
- ../templates/deployment.yaml
set:
onPremCompatibilityVersion: "6.3"
runtimeStatusIntegrator.image.tag: "0.0.1"
imageSbomExtractor.image.tag: "6.1.0"
asserts:
- failedTemplate:
errorMessage: "incompatible version for imageSbomExtractor.image.tag, set 6.1.0 expected < 1.0.0"

- it: "fails if the onPremCompatibilityVersion is set to 6.5 and the runtimeStatusIntegrator version is incorrect"
templates:
- ../templates/deployment.yaml
set:
onPremCompatibilityVersion: "6.5"
runtimeStatusIntegrator.image.tag: "0.3.4"
imageSbomExtractor.image.tag: "1.3.4"
asserts:
- failedTemplate:
errorMessage: "incompatible version for runtimeStatusIntegrator.image.tag, set 0.3.4 expected >= 1.0.0"

- it: "fails if the onPremCompatibilityVersion is not set to 6.3 the imageSbomExtractor version is incorrect"
- it: "fails if the onPremCompatibilityVersion is set to 6.5 and the imageSbomExtractor version is incorrect"
templates:
- ../templates/deployment.yaml
set:
onPremCompatibilityVersion: "6.3"
onPremCompatibilityVersion: "6.5"
runtimeStatusIntegrator.image.tag: "1.3.4"
imageSbomExtractor.image.tag: "0.1.0"
asserts:
- failedTemplate:
errorMessage: "incompatible version for imageSbomExtractor.image.tag, set 0.1.0 expected >= 1.0.0"

- it: "fails if the onPremCompatibilityVersion is set to 6.6 and the runtimeStatusIntegrator version is incorrect"
templates:
- ../templates/deployment.yaml
set:
onPremCompatibilityVersion: "6.6"
runtimeStatusIntegrator.image.tag: "0.3.4"
imageSbomExtractor.image.tag: "1.3.4"
asserts:
- failedTemplate:
errorMessage: "incompatible version for runtimeStatusIntegrator.image.tag, set 0.3.4 expected >= 1.0.0"

- it: "fails if the onPremCompatibilityVersion is set to 6.6 and the imageSbomExtractor version is incorrect"
templates:
- ../templates/deployment.yaml
set:
onPremCompatibilityVersion: "6.6"
runtimeStatusIntegrator.image.tag: "1.3.4"
imageSbomExtractor.image.tag: "0.1.0"
asserts:
Expand Down Expand Up @@ -282,6 +326,21 @@ tests:
- ../templates/deployment.yaml
set:
onPremCompatibilityVersion: "6.3"
runtimeStatusIntegrator.image.tag: "0.3.4"
imageSbomExtractor.image.tag: "0.9.10"
asserts:
- equal:
path: spec.template.spec.containers[0].image
value: quay.io/sysdig/runtime-status-integrator:0.3.4
- equal:
path: spec.template.spec.containers[1].image
value: quay.io/sysdig/image-sbom-extractor:0.9.10

- it: "succeeds if the onPremCompatibilityVersion is set to 6.5 and the runtimeStatusIntegrator and imageSbomExtractor versions are correct"
templates:
- ../templates/deployment.yaml
set:
onPremCompatibilityVersion: "6.5"
runtimeStatusIntegrator.image.tag: "2.3.4"
imageSbomExtractor.image.tag: "1.0.0"
asserts:
Expand All @@ -292,11 +351,26 @@ tests:
path: spec.template.spec.containers[1].image
value: quay.io/sysdig/image-sbom-extractor:1.0.0

- it: "succeeds if the runtimeStatusIntegrator version is not a semver and the onPremCompatibilityVersion is 6.2"
- it: "succeeds if the onPremCompatibilityVersion is set to 6.6 and the runtimeStatusIntegrator and imageSbomExtractor versions are correct"
templates:
- ../templates/deployment.yaml
set:
onPremCompatibilityVersion: "6.2"
onPremCompatibilityVersion: "6.6"
runtimeStatusIntegrator.image.tag: "2.3.4"
imageSbomExtractor.image.tag: "1.0.0"
asserts:
- equal:
path: spec.template.spec.containers[0].image
value: quay.io/sysdig/runtime-status-integrator:2.3.4
- equal:
path: spec.template.spec.containers[1].image
value: quay.io/sysdig/image-sbom-extractor:1.0.0

- it: "succeeds if the runtimeStatusIntegrator version is not a semver and the onPremCompatibilityVersion is 6.4"
templates:
- ../templates/deployment.yaml
set:
onPremCompatibilityVersion: "6.4"
runtimeStatusIntegrator.image.tag: "unstable-rc"
imageSbomExtractor.image.tag: "0.9.0"
asserts:
Expand All @@ -307,11 +381,11 @@ tests:
path: spec.template.spec.containers[1].image
value: quay.io/sysdig/image-sbom-extractor:0.9.0

- it: "succeeds if the imageSbomExtractor version is not a semver and the onPremCompatibilityVersion is 6.3"
- it: "succeeds if the imageSbomExtractor version is not a semver and the onPremCompatibilityVersion is 6.5"
templates:
- ../templates/deployment.yaml
set:
onPremCompatibilityVersion: "6.3"
onPremCompatibilityVersion: "6.5"
runtimeStatusIntegrator.image.tag: "1.3.5"
imageSbomExtractor.image.tag: "3bc59a4958d15dfa6afed20dfd2459e268b4cda8"
asserts:
Expand Down

0 comments on commit 43b847f

Please sign in to comment.