Skip to content

Commit 943c1bb

Browse files
committed
adding eol check
1 parent c296a1c commit 943c1bb

File tree

14 files changed

+385
-32
lines changed

14 files changed

+385
-32
lines changed

docs/helm-chart-checks.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,23 @@ The following table lists the set of checks for each profile version with detail
5252

5353
#### Table 2: Helm chart default checks
5454

55-
| Profile v1.3 | Profile v1.2 | Profile v1.1 | Profile v1.0 | Description |
56-
|---|---|---|---|---|
57-
| [is-helm-v3 v1.0](helm-chart-troubleshooting.md#is-helm-v3-v10) | [is-helm-v3 v1.0](helm-chart-troubleshooting.md#is-helm-v3-v10) | [is-helm-v3 v1.0](helm-chart-troubleshooting.md#is-helm-v3-v10) | [is-helm-v3 v1.0](helm-chart-troubleshooting.md#is-helm-v3-v10) | Checks that the given `uri` points to a Helm v3 chart. |
58-
| [has-readme v1.0](helm-chart-troubleshooting.md#has-readme-v10) | [has-readme v1.0](helm-chart-troubleshooting.md#has-readme-v10) | [has-readme v1.0](helm-chart-troubleshooting.md#has-readme-v10) | [has-readme v1.0](helm-chart-troubleshooting.md#has-readme-v10) | Checks that the Helm chart contains the `README.md` file. |
59-
| [contains-test V1.0](helm-chart-troubleshooting.md#contains-test-v10) | [contains-test V1.0](helm-chart-troubleshooting.md#contains-test-v10) | [contains-test V1.0](helm-chart-troubleshooting.md#contains-test-v10) | [contains-test v1.0](helm-chart-troubleshooting.md#contains-test-v10) | Checks that the Helm chart contains at least one test file. |
60-
| [has-kubeversion v1.1](helm-chart-troubleshooting.md#has-kubeversion-v11) | [has-kubeversion v1.1](helm-chart-troubleshooting.md#has-kubeversion-v11) | [has-kubeversion v1.1](helm-chart-troubleshooting.md#has-kubeversion-v11) | [has-kubeversion v1.0](helm-chart-troubleshooting.md#has-kubeversion-v10) | Checks that the `Chart.yaml` file of the Helm chart includes the `kubeVersion` field (v1.0) and is a valid semantic version (v1.1). |
61-
| [contains-values-schema v1.0](helm-chart-troubleshooting.md#contains-values-schema-v10) | [contains-values-schema v1.0](helm-chart-troubleshooting.md#contains-values-schema-v10) | [contains-values-schema v1.0](helm-chart-troubleshooting.md#contains-values-schema-v10) | [contains-values-schema v1.0](helm-chart-troubleshooting.md#contains-values-schema-v10) | Checks that the Helm chart contains a JSON schema file (`values.schema.json`) to validate the `values.yaml` file in the chart. |
62-
| [not-contains-crds v1.0](helm-chart-troubleshooting.md#not-contains-crds-v10) | [not-contains-crds v1.0](helm-chart-troubleshooting.md#not-contains-crds-v10) | [not-contains-crds v1.0](helm-chart-troubleshooting.md#not-contains-crds-v10) | [not-contains-crds v1.0](helm-chart-troubleshooting.md#not-contains-crds-v10) | Checks that the Helm chart does not include custom resource definitions (CRDs). |
63-
| [not-contain-csi-objects v1.0](helm-chart-troubleshooting.md#not-contain-csi-objects-v10) | [not-contain-csi-objects v1.0](helm-chart-troubleshooting.md#not-contain-csi-objects-v10) | [not-contain-csi-objects v1.0](helm-chart-troubleshooting.md#not-contain-csi-objects-v10) | [not-contain-csi-objects v1.0](helm-chart-troubleshooting.md#not-contain-csi-objects-v10) | Checks that the Helm chart does not include Container Storage Interface (CSI) objects. |
64-
| [images-are-certified v1.1](helm-chart-troubleshooting.md#images-are-certified-v10) | [images-are-certified v1.1](helm-chart-troubleshooting.md#images-are-certified-v10) | [images-are-certified v1.0](helm-chart-troubleshooting.md#images-are-certified-v10) | [images-are-certified v1.0](helm-chart-troubleshooting.md#images-are-certified-v10) | Checks that the images referenced by the Helm chart are Red Hat-certified. |
65-
| [helm-lint v1.0](helm-chart-troubleshooting.md#helm-lint-v10) | [helm-lint v1.0](helm-chart-troubleshooting.md#helm-lint-v10) | [helm-lint v1.0](helm-chart-troubleshooting.md#helm-lint-v10) | [helm-lint v1.0](helm-chart-troubleshooting.md#helm-lint-v10) | Checks that the chart is well formed by running the `helm lint` command. |
66-
| [chart-testing v1.0](helm-chart-troubleshooting.md#chart-testing-v10) | [chart-testing v1.0](helm-chart-troubleshooting.md#chart-testing-v10) | [chart-testing v1.0](helm-chart-troubleshooting.md#chart-testing-v10) | [chart-testing v1.0](helm-chart-troubleshooting.md#chart-testing-v10) | Installs the chart and verifies it on a Red Hat OpenShift Container Platform cluster. |
67-
| [contains-values v1.0](helm-chart-troubleshooting.md#contains-values-v10) | [contains-values v1.0](helm-chart-troubleshooting.md#contains-values-v10) | [contains-values v1.0](helm-chart-troubleshooting.md#contains-values-v10) | [contains-values v1.0](helm-chart-troubleshooting.md#contains-values-v10) | Checks that the Helm chart contains the `values`[¹](https://github.com/redhat-certification/chart-verifier/blob/main/docs/helm-chart-checks.md#-for-more-information-on-the-values-file-see-values-and-best-practices-for-using-values) file. |
68-
| [required-annotations-present v1.0](helm-chart-troubleshooting.md#required-annotations-present-v10) | [required-annotations-present v1.0](helm-chart-troubleshooting.md#required-annotations-present-v10) | [required-annotations-present v1.0](helm-chart-troubleshooting.md#required-annotations-present-v10) | - | Checks that the Helm chart contains the annotation: ```charts.openshift.io/name```. |
69-
| [signature-is-valid v1.0](helm-chart-troubleshooting.md#signature-is-valid-v10) | [signature-is-valid v1.0](helm-chart-troubleshooting.md#signature-is-valid-v10) | - | - | Verifies a signed chart based on a provided public key. |
70-
| [has-notes v1.0](helm-chart-troubleshooting.md#has-notes-v10) | - | - | - | Checks that the Helm chart contains the `NOTES.txt` file in the templates directory. |
55+
| Profile v1.4| Profile v1.3 | Profile v1.2 | Profile v1.1 | Profile v1.0 | Description |
56+
|---|---|---|---|---|---|
57+
| [is-helm-v3 v1.0](helm-chart-troubleshooting.md#is-helm-v3-v10) | [is-helm-v3 v1.0](helm-chart-troubleshooting.md#is-helm-v3-v10) | [is-helm-v3 v1.0](helm-chart-troubleshooting.md#is-helm-v3-v10) | [is-helm-v3 v1.0](helm-chart-troubleshooting.md#is-helm-v3-v10) | [is-helm-v3 v1.0](helm-chart-troubleshooting.md#is-helm-v3-v10) | Checks that the given `uri` points to a Helm v3 chart. |
58+
| [has-readme v1.0](helm-chart-troubleshooting.md#has-readme-v10) | [has-readme v1.0](helm-chart-troubleshooting.md#has-readme-v10) | [has-readme v1.0](helm-chart-troubleshooting.md#has-readme-v10) | [has-readme v1.0](helm-chart-troubleshooting.md#has-readme-v10) | [has-readme v1.0](helm-chart-troubleshooting.md#has-readme-v10) | Checks that the Helm chart contains the `README.md` file. |
59+
| [contains-test V1.0](helm-chart-troubleshooting.md#contains-test-v10) | [contains-test V1.0](helm-chart-troubleshooting.md#contains-test-v10) | [contains-test V1.0](helm-chart-troubleshooting.md#contains-test-v10) | [contains-test V1.0](helm-chart-troubleshooting.md#contains-test-v10) | [contains-test v1.0](helm-chart-troubleshooting.md#contains-test-v10) | Checks that the Helm chart contains at least one test file. |
60+
| [has-kubeversion v1.1](helm-chart-troubleshooting.md#has-kubeversion-v11) | [has-kubeversion v1.1](helm-chart-troubleshooting.md#has-kubeversion-v11) | [has-kubeversion v1.1](helm-chart-troubleshooting.md#has-kubeversion-v11) | [has-kubeversion v1.1](helm-chart-troubleshooting.md#has-kubeversion-v11) | [has-kubeversion v1.0](helm-chart-troubleshooting.md#has-kubeversion-v10) | Checks that the `Chart.yaml` file of the Helm chart includes the `kubeVersion` field (v1.0) and is a valid semantic version (v1.1). |
61+
| [contains-values-schema v1.0](helm-chart-troubleshooting.md#contains-values-schema-v10) | [contains-values-schema v1.0](helm-chart-troubleshooting.md#contains-values-schema-v10) | [contains-values-schema v1.0](helm-chart-troubleshooting.md#contains-values-schema-v10) | [contains-values-schema v1.0](helm-chart-troubleshooting.md#contains-values-schema-v10) | [contains-values-schema v1.0](helm-chart-troubleshooting.md#contains-values-schema-v10) | Checks that the Helm chart contains a JSON schema file (`values.schema.json`) to validate the `values.yaml` file in the chart. |
62+
| [not-contains-crds v1.0](helm-chart-troubleshooting.md#not-contains-crds-v10) | [not-contains-crds v1.0](helm-chart-troubleshooting.md#not-contains-crds-v10) | [not-contains-crds v1.0](helm-chart-troubleshooting.md#not-contains-crds-v10) | [not-contains-crds v1.0](helm-chart-troubleshooting.md#not-contains-crds-v10) | [not-contains-crds v1.0](helm-chart-troubleshooting.md#not-contains-crds-v10) | Checks that the Helm chart does not include custom resource definitions (CRDs). |
63+
| [not-contain-csi-objects v1.0](helm-chart-troubleshooting.md#not-contain-csi-objects-v10) | [not-contain-csi-objects v1.0](helm-chart-troubleshooting.md#not-contain-csi-objects-v10) | [not-contain-csi-objects v1.0](helm-chart-troubleshooting.md#not-contain-csi-objects-v10) | [not-contain-csi-objects v1.0](helm-chart-troubleshooting.md#not-contain-csi-objects-v10) | [not-contain-csi-objects v1.0](helm-chart-troubleshooting.md#not-contain-csi-objects-v10) | Checks that the Helm chart does not include Container Storage Interface (CSI) objects. |
64+
| [images-are-certified v1.1](helm-chart-troubleshooting.md#images-are-certified-v10) | [images-are-certified v1.1](helm-chart-troubleshooting.md#images-are-certified-v10) | [images-are-certified v1.1](helm-chart-troubleshooting.md#images-are-certified-v10) | [images-are-certified v1.0](helm-chart-troubleshooting.md#images-are-certified-v10) | [images-are-certified v1.0](helm-chart-troubleshooting.md#images-are-certified-v10) | Checks that the images referenced by the Helm chart are Red Hat-certified. |
65+
| [helm-lint v1.0](helm-chart-troubleshooting.md#helm-lint-v10) | [helm-lint v1.0](helm-chart-troubleshooting.md#helm-lint-v10) | [helm-lint v1.0](helm-chart-troubleshooting.md#helm-lint-v10) | [helm-lint v1.0](helm-chart-troubleshooting.md#helm-lint-v10) | [helm-lint v1.0](helm-chart-troubleshooting.md#helm-lint-v10) | Checks that the chart is well formed by running the `helm lint` command. |
66+
| [chart-testing v1.0](helm-chart-troubleshooting.md#chart-testing-v10) | [chart-testing v1.0](helm-chart-troubleshooting.md#chart-testing-v10) | [chart-testing v1.0](helm-chart-troubleshooting.md#chart-testing-v10) | [chart-testing v1.0](helm-chart-troubleshooting.md#chart-testing-v10) | [chart-testing v1.0](helm-chart-troubleshooting.md#chart-testing-v10) | Installs the chart and verifies it on a Red Hat OpenShift Container Platform cluster. |
67+
| [contains-values v1.0](helm-chart-troubleshooting.md#contains-values-v10) | [contains-values v1.0](helm-chart-troubleshooting.md#contains-values-v10) | [contains-values v1.0](helm-chart-troubleshooting.md#contains-values-v10) | [contains-values v1.0](helm-chart-troubleshooting.md#contains-values-v10) | [contains-values v1.0](helm-chart-troubleshooting.md#contains-values-v10) | Checks that the Helm chart contains the `values`[¹](https://github.com/redhat-certification/chart-verifier/blob/main/docs/helm-chart-checks.md#-for-more-information-on-the-values-file-see-values-and-best-practices-for-using-values) file. |
68+
| [required-annotations-present v1.0](helm-chart-troubleshooting.md#required-annotations-present-v10) | [required-annotations-present v1.0](helm-chart-troubleshooting.md#required-annotations-present-v10) | [required-annotations-present v1.0](helm-chart-troubleshooting.md#required-annotations-present-v10) | [required-annotations-present v1.0](helm-chart-troubleshooting.md#required-annotations-present-v10) | - | Checks that the Helm chart contains the annotation: ```charts.openshift.io/name```. |
69+
| [signature-is-valid v1.0](helm-chart-troubleshooting.md#signature-is-valid-v10) | [signature-is-valid v1.0](helm-chart-troubleshooting.md#signature-is-valid-v10) | [signature-is-valid v1.0](helm-chart-troubleshooting.md#signature-is-valid-v10) | - | - | Verifies a signed chart based on a provided public key. |
70+
| [has-notes v1.0](helm-chart-troubleshooting.md#has-notes-v10) | [has-notes v1.0](helm-chart-troubleshooting.md#has-notes-v10) | - | - | - | Checks that the Helm chart contains the `NOTES.txt` file in the templates directory. |
71+
| [cluster-is-not-eol v1.0](helm-chart-troubleshooting.md#cluster-is-not-eol-v10) | - | - | - | - | Checks that Helm chart was tested on a non EOL cluster. |
7172
#
7273
###### ¹ For more information on the `values` file, see [`values`](https://helm.sh/docs/chart_template_guide/values_files/) and [Best Practices for using values](https://helm.sh/docs/chart_best_practices/values/).
7374

@@ -321,7 +322,15 @@ A profile defines a set of checks to run and an indication of whether each check
321322
- The default is the same as the partner profile and is used if a specific one is not specified.
322323
- All checks are mandatory.
323324
324-
Each profile also has a version and currently there are four profile versions: v1.0, v1.1, v1.2, and v1.3. The `developer-console` just has one profile version v1.0.
325+
Each profile also has a version and currently there are five profile versions: v1.0, v1.1, v1.2, v1.3 and v1.4. The `developer-console` just has one profile version v1.0.
326+
327+
### Profile v1.4
328+
329+
Compared to profile v1.3, adds a new check:
330+
331+
| check | partner | RedHat | community | default |
332+
|---------------------------------------------------------------------------------|---------|--------|-----------|---------
333+
| [cluster-is-not-eol v1.0](helm-chart-troubleshooting.md#cluster-is-not-eol-v10) | optional | optional | optional | optional
325334
326335
### Profile v1.3
327336

docs/helm-chart-troubleshooting.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ This check requires that the public key provided to the chart verifier is from a
180180
Requires a "NOTES.txt" file to exist in the templates directory of the chart. Any other spelling or
181181
capitialisation of letters will result in the check failing.
182182

183+
### `cluster-is-not-eol` v1.0
184+
185+
Requires that helm charts be tested on a non EOL cluster. It will fail if the lifecycle status of the cluster is EOL.
186+
183187
## Report related submission failures
184188

185189
### One or more mandatory checks have failed or are missing from the report.

internal/chartverifier/checks/charttesting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
// Versioner provides OpenShift version
2727
type Versioner func(envSettings *cli.EnvSettings) (string, error)
2828

29-
func getVersion(envSettings *cli.EnvSettings) (string, error) {
29+
func GetVersion(envSettings *cli.EnvSettings) (string, error) {
3030
kubeConfig := tool.GetClientConfig(envSettings)
3131
kubectl, err := tool.NewKubectl(kubeConfig)
3232
if err != nil {
@@ -174,7 +174,7 @@ func ChartTesting(opts *CheckOptions) (Result, error) {
174174
}
175175
}
176176

177-
if versionError := setOCVersion(opts.AnnotationHolder, opts.HelmEnvSettings, getVersion); versionError != nil {
177+
if versionError := setOCVersion(opts.AnnotationHolder, opts.HelmEnvSettings, GetVersion); versionError != nil {
178178
if versionError != nil {
179179
utils.LogWarning(fmt.Sprintf("End chart install and test check with version error: %v", versionError))
180180
}

internal/chartverifier/checks/checks.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const (
6464
ImageCertified = "Image is Red Hat certified"
6565
ImageNotCertified = "Image is not Red Hat certified"
6666
ChartTestingSuccess = "Chart tests have passed"
67+
ClusterNotEOL = "Chart tests ran on a non EOL cluster"
68+
ClusterIsEOL = "Chart tests ran on an EOL cluster"
6769
MetadataFailure = "Empty metadata in chart"
6870
RequiredAnnotationsSuccess = "All required annotations present"
6971
RequiredAnnotationsFailure = "Missing required annotations"
@@ -529,3 +531,41 @@ func certifyImages(r Result, opts *CheckOptions, registry string) Result {
529531

530532
return r
531533
}
534+
535+
func ClusterIsNotEOL(opt *CheckOptions) (Result, error) {
536+
// Populating version client if not set
537+
if opt.versionClient == nil {
538+
opt.versionClient = GetVersion
539+
}
540+
// Populating lifecycle client if not set
541+
if opt.lifecycleClient == nil {
542+
lcd := LifecycleData{}
543+
opt.lifecycleClient = lcd.GetLifecycleStatus
544+
}
545+
// Get version
546+
version, err := opt.versionClient(opt.HelmEnvSettings)
547+
if err != nil {
548+
return Result{}, err
549+
}
550+
// Get lifecycle status for version
551+
lifecycleStatus, err := opt.lifecycleClient(version)
552+
if err != nil {
553+
return Result{}, err
554+
}
555+
556+
// Default to false
557+
result := NewResult(false, ClusterIsEOL)
558+
559+
// Supported
560+
if strings.Contains(lifecycleStatus, "Support") {
561+
result.SetResult(true, ClusterNotEOL)
562+
return result, nil
563+
}
564+
// End of life
565+
if lifecycleStatus == "End of life" {
566+
result.SetResult(false, ClusterIsEOL)
567+
return result, nil
568+
}
569+
570+
return result, nil
571+
}

internal/chartverifier/checks/checks_test.go

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ import (
2121
"strings"
2222
"testing"
2323

24+
"github.com/redhat-certification/chart-verifier/internal/chartverifier/pyxis"
25+
"github.com/redhat-certification/chart-verifier/internal/tool"
2426
"github.com/spf13/viper"
2527
"github.com/stretchr/testify/require"
2628
"helm.sh/helm/v3/pkg/cli"
27-
28-
"github.com/redhat-certification/chart-verifier/internal/chartverifier/pyxis"
29-
"github.com/redhat-certification/chart-verifier/internal/tool"
3029
)
3130

3231
func TestIsHelmV3(t *testing.T) {
@@ -290,6 +289,83 @@ func TestHasMinKubeVersion(t *testing.T) {
290289
}
291290
}
292291

292+
func GetVersionEOL(env *cli.EnvSettings) (string, error) {
293+
return "4.11", nil
294+
}
295+
296+
func GetVersionSupported(env *cli.EnvSettings) (string, error) {
297+
return "4.17", nil
298+
}
299+
300+
func GetVersionUnknown(env *cli.EnvSettings) (string, error) {
301+
return "99", nil
302+
}
303+
304+
func GetTestLifecycleStatus(clusterVersion string) (string, error) {
305+
if clusterVersion == "4.11" {
306+
return "End of life", nil
307+
}
308+
if clusterVersion == "4.17" {
309+
return "Full Support", nil
310+
}
311+
return "Unknown", nil
312+
}
313+
314+
func TestClusterIsNotEOL(t *testing.T) {
315+
type testCase struct {
316+
description string
317+
versionClient Versioner
318+
lifecycleClient LifecycleDataGetter
319+
}
320+
321+
positiveTestCases := []testCase{
322+
{
323+
description: "Cluster is not EOL",
324+
versionClient: GetVersionSupported,
325+
lifecycleClient: GetTestLifecycleStatus,
326+
},
327+
}
328+
329+
for _, tc := range positiveTestCases {
330+
t.Run(tc.description, func(t *testing.T) {
331+
options := &CheckOptions{}
332+
options.versionClient = tc.versionClient
333+
options.lifecycleClient = tc.lifecycleClient
334+
r, err := ClusterIsNotEOL(options)
335+
require.NoError(t, err)
336+
require.NotNil(t, r)
337+
require.True(t, r.Ok)
338+
require.Equal(t, ClusterNotEOL, r.Reason)
339+
})
340+
}
341+
342+
negativeTestCases := []testCase{
343+
{
344+
description: "Cluster is EOL",
345+
versionClient: GetVersionEOL,
346+
lifecycleClient: GetTestLifecycleStatus,
347+
},
348+
{
349+
description: "Cluster version is unknown",
350+
versionClient: GetVersionUnknown,
351+
lifecycleClient: GetTestLifecycleStatus,
352+
},
353+
}
354+
355+
for _, tc := range negativeTestCases {
356+
t.Run(tc.description, func(t *testing.T) {
357+
options := &CheckOptions{}
358+
options.versionClient = tc.versionClient
359+
options.lifecycleClient = tc.lifecycleClient
360+
r, err := ClusterIsNotEOL(options)
361+
require.NoError(t, err)
362+
require.NotNil(t, r)
363+
require.False(t, r.Ok)
364+
require.Equal(t, ClusterIsEOL, r.Reason)
365+
})
366+
}
367+
}
368+
293369
func TestNotContainCRDs(t *testing.T) {
294370
type testCase struct {
295371
description string

0 commit comments

Comments
 (0)