Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding required annotations check and necessary tests #1086

Merged
merged 1 commit into from
Dec 12, 2023
Merged

adding required annotations check and necessary tests #1086

merged 1 commit into from
Dec 12, 2023

Conversation

acornett21
Copy link
Contributor

Adding a new check that checks for newly required annotations. At first we will only warn partners about this, then after sometime we will move to enforce this check.

  • Relates: JIRA: EET-3540

Note: There are backend changes being made to support Warning being in the results

@acornett21 acornett21 requested review from bcrochet and komish October 19, 2023 20:12
@openshift-ci
Copy link

openshift-ci bot commented Oct 19, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 19, 2023
@tkrishtop
Copy link
Contributor

tkrishtop commented Oct 19, 2023

Hi @acornett21 the DCI job failed because of a new test you've added

TASK [redhatci.ocp.verify_tests : Fail if not all test results are as expected for preflight_operator_simple-demo-operator_results-junit.xml]
0s
task path: /usr/share/ansible/collections/ansible_collections/redhatci/ocp/roles/verify_tests/tasks/parse_junit_file.yml:35
fatal: [jumphost]: FAILED! => 
{"changed": false, "msg": "The following expectations failed: 
[{'failed_expectation': {'testcase': '[a-zA-Z]+', 'passed': True}, 
'actual_result': {'testcase': 'RequiredAnnotations', 'passed': False}}]"}

I'll change the expectations for simple-demo-operator tomorrow - for the moment we simply expect all tests to be green.

Copy link
Contributor

@bcrochet bcrochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments.

internal/formatters/util.go Outdated Show resolved Hide resolved
internal/formatters/util.go Outdated Show resolved Hide resolved
internal/policy/operator/required_annotations.go Outdated Show resolved Hide resolved
internal/formatters/util.go Outdated Show resolved Hide resolved
internal/formatters/util.go Outdated Show resolved Hide resolved
internal/formatters/junitxml_test.go Outdated Show resolved Hide resolved
@acornett21
Copy link
Contributor Author

I'll change the expectations for simple-demo-operator tomorrow - for the moment we simply expect all tests to be green.

@tkrishtop Are you saying the new check showed up as failed? If so that's incorrect. This is still WIP, and I'll be working to update simple-demo-operator and simple-disconnected-operator accordingly, once this feature is fully hashed out.

internal/csv/csv.go Outdated Show resolved Hide resolved
Comment on lines +19 to +21
TokenAuthAWSAnnotation = "features.operators.openshift.io/token-auth-aws"
TokenAuthAzureAnnotation = "features.operators.openshift.io/token-auth-azure"
TokenAuthGCPAnnotation = "features.operators.openshift.io/token-auth-gcp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a potentially unrelated question.. but why are these becoming required? Are we installing operators on all providers all at once?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if a given operator would/could support token auth for all cloud providers or not. My guess would be that is unlikely, just based on our dealings with STS in the ACK project. IMO It's more so for the below:

The current format of the infrastructure annotations is unsuited for robust checks and effective enforcement. We need a new format that allows to cleanly differentiate between mere absence of a data or actual lack of support for a certain infrastructure feature.

@tkrishtop
Copy link
Contributor

I adjusted the pinned tests on our side, to ignore the new test failing for simple-demo. For the future, it would be nice to fix the simple-demo as well.

@tkrishtop
Copy link
Contributor

check workload preflight-green

@tkrishtop
Copy link
Contributor

I'll change the expectations for simple-demo-operator tomorrow - for the moment we simply expect all tests to be green.

@tkrishtop Are you saying the new check showed up as failed? If so that's incorrect. This is still WIP, and I'll be working to update simple-demo-operator and simple-disconnected-operator accordingly, once this feature is fully hashed out.

Sorry @acornett21 , I just saw your comment. Would you prefer me to fallback the fix on our side and pin all the tests for the simple-demo to be green, as before?

With the old setup, the DCI job for your PR will be failing because it automatically auto-discovers all the tests and expects them to be green:

      - filename: 'preflight_operator_simple-demo-operator_results-junit.xml'
        expected_results:
          - testcase: '[a-zA-Z]+'
            passed: True

@acornett21
Copy link
Contributor Author

@tkrishtop I've updated the the junit code to add another level/tag (not sure what to call this for junit). But the output will look like this for checks that are at a warn level.

<testsuites>
	<testsuite tests="5" failures="0" warnings="1" time="35.215827" name="Red Hat Certification">
		<properties></properties>
		<testcase classname="quay.io/opdev/simple-demo-operator-bundle:v0.0.6" name="ScorecardBasicSpecCheck" time="3.516921">Check to make sure that all CRs have a spec block.</testcase>
		<testcase classname="quay.io/opdev/simple-demo-operator-bundle:v0.0.6" name="ScorecardOlmSuiteCheck" time="3.530103">Operator-sdk scorecard OLM Test Suite Check</testcase>
		<testcase classname="quay.io/opdev/simple-demo-operator-bundle:v0.0.6" name="DeployableByOLM" time="28.148170">Checking if the operator could be deployed by OLM</testcase>
		<testcase classname="quay.io/opdev/simple-demo-operator-bundle:v0.0.6" name="ValidateOperatorBundle" time="0.010793">Validating Bundle image that checks if it can validate the content and format of the operator bundle</testcase>
		<testcase classname="quay.io/opdev/simple-demo-operator-bundle:v0.0.6" name="RequiredAnnotations" time="9.839866ms">
			<warning message="Warn" type="">Check that the CSV has all of the required feature annotations.: Suggested Fix: Add all of the required annotations, and make sure the value is set to either &#39;true&#39; or &#39;false&#39;</warning>
		</testcase>
	</testsuite>
</testsuites>

The idea of introducing a new check at level warn is so that partners can see the check in their results, but not be penalized if it fails. Then at a later date the check will be moved to level best where the check is enforced. I hope this clears up what we are trying to accomplish. Let me know if we need to adjust the XML, or if you see any issue in how the XML works, since I think DCI is the only consumer of this.

@acornett21
Copy link
Contributor Author

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Nov 15, 2023
@acornett21
Copy link
Contributor Author

/ok-to-test

@acornett21
Copy link
Contributor Author

acornett21 commented Nov 20, 2023

Tested locally as well now that the operators are updated...

{
    "image": "quay.io/opdev/simple-demo-operator-bundle:v0.0.7",
    "passed": true,
    "certification_hash": "d41d8cd98f00b204e9800998ecf8427e",
    "test_library": {
        "name": "github.com/redhat-openshift-ecosystem/openshift-preflight",
        "version": "0.0.0",
        "commit": "ebe3811bfac4353f96a706e9dd30329946b4f07b"
    },
    "results": {
        "passed": [
            {
                "name": "ScorecardBasicSpecCheck",
                "elapsed_time": 2666,
                "description": "Check to make sure that all CRs have a spec block."
            },
            {
                "name": "ScorecardOlmSuiteCheck",
                "elapsed_time": 3548,
                "description": "Operator-sdk scorecard OLM Test Suite Check"
            },
            {
                "name": "DeployableByOLM",
                "elapsed_time": 42394,
                "description": "Checking if the operator could be deployed by OLM"
            },
            {
                "name": "ValidateOperatorBundle",
                "elapsed_time": 51,
                "description": "Validating Bundle image that checks if it can validate the content and format of the operator bundle"
            },
            {
                "name": "RequiredAnnotations",
                "elapsed_time": 12,
                "description": "Checks that the CSV has all of the required feature annotations."
            }
        ],
        "failed": [],
        "errors": []
    }
}

@acornett21 acornett21 marked this pull request as ready for review December 11, 2023 14:40
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 11, 2023
Copy link
Contributor

@bcrochet bcrochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few requests.

@@ -236,6 +236,12 @@ func (c *craneEngine) ExecuteChecks(ctx context.Context) error {
}

if !checkPassed {
// if a test doesn't pass but is of level warn include it in warning results, instead of failed results
if check.Metadata().Level == "warn" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different... You use "warning" on 223, but "warn" here. Perhaps time for a constant for these levels?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this to a constant, though I'm not sure the package is the ideal place. I put it in check.certification which defines the Check interface.

internal/engine/engine_test.go Outdated Show resolved Hide resolved
internal/engine/engine_test.go Outdated Show resolved Hide resolved
internal/policy/operator/required_annotations_test.go Outdated Show resolved Hide resolved
internal/policy/operator/restricted_network_aware.go Outdated Show resolved Hide resolved
internal/engine/engine.go Outdated Show resolved Hide resolved
Copy link
Contributor

@bcrochet bcrochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes about the import name

@@ -220,7 +220,7 @@ func (c *craneEngine) ExecuteChecks(ctx context.Context) error {
c.results.TestedImage = c.image

logger.V(log.DBG).Info("running check", "check", check.Name())
if check.Metadata().Level == "optional" {
if check.Metadata().Level == "optional" || check.Metadata().Level == certcheck.LevelWarn {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the Optional const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep this PR focused on the required annotations, I was planning a follow up PR to switch all other checks to the constants. I assumed that would be preference then introducing here. But maybe it's fine to just introduce for this one line since it is already changing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched this one line, but as mentioned another pr will follow to update all the things.

internal/engine/engine.go Outdated Show resolved Hide resolved
internal/engine/engine.go Show resolved Hide resolved
internal/engine/engine.go Outdated Show resolved Hide resolved
Copy link
Contributor

@komish komish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Barring E2E, LGTM.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 12, 2023
Copy link
Contributor

@bcrochet bcrochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

internal/engine/engine.go Show resolved Hide resolved
Copy link

openshift-ci bot commented Dec 12, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: acornett21, bcrochet, komish

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [acornett21,bcrochet,komish]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@acornett21 acornett21 merged commit 147224e into redhat-openshift-ecosystem:main Dec 12, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants