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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lib to preflight #809

Merged
merged 1 commit into from
Oct 25, 2022

Conversation

sebrandon1
Copy link
Contributor

@sebrandon1 sebrandon1 commented Oct 20, 2022

Work in progress!

Related to:

This PR provides some changes needed to implement the lib. (Name is subject to change 馃槃)

I want to go through some of the files to describe my notable changes:

  • certification/runtime/config.go
    In this file, I added NewManualContainerConfig and NewManualOperatorConfig for being able to create config objects geared towards their individual purposes.

  • cmd/check_container.go and cmd/check_operator.go
    These files have had their "NewOperator/Container" funcs moved to the lib.

  • fakes.go and types.go
    Moved to the lib folder, because it contains funcs like NewFakePyxisClientNoop and NewNoopSubmitter.
    The NoopSubmitter has had appropriate setters added.

  • lib/check_container_test.go and cmd/check_container_test.go
    I split these two files into files more geared towards their testing purposes. The cmd package one tests stuff that has to do with the cmd package, for example.

@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 20, 2022
@openshift-ci
Copy link

openshift-ci bot commented Oct 20, 2022

Hi @sebrandon1. Thanks for your PR.

I'm waiting for a redhat-openshift-ecosystem member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@bcrochet
Copy link
Contributor

/ok-to-test

@openshift-ci openshift-ci bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 21, 2022
cmd/check_test.go Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
lib/fakes.go Outdated Show resolved Hide resolved
komish
komish previously requested changes Oct 21, 2022
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.

@sebrandon1 Thanks a ton for the work on pushing this forward! I've added a few review comments, but I'll definitely need to take another pass. Before I do - discussion points 猬囷笍

We briefly discussed this when we met, but I wanted to go ahead and capture it here publicly so that we can have folks comment/provide feedback.

I think what I'm looking to see here out of the gate is the ability to run CheckContainer(...) and CheckOperator(...) for starters.

The inputs are up for debate (my ideal would be just a context and maybe your image string), but the outputs here would be results, and somehow, log files where relevant (TBD, but I'm putting that aside for now).

The goal here would be to make sure that folks starting to consume preflight as a library don't have to go through the hurdles to set up the PreflightCheck configurations, etc.

To that end, I'm thinking (sorry @bcrochet) that we start by moving most of this lib work into a top-level internal package, accessible by both cmd and everything else, wire up CheckOperator and CheckContainer as callable functions/methods, and then if we need to pull more things out of this internal library, for your use case (and the use case of others), then we'd do that as well.

If we did that, though, we want to make sure that the exported functions are actually what you need to benefit from calling the Preflight library in your use cases. Does that sound like something that would work for you?

@sebrandon1 @acornett21 @bcrochet WDYT?

lib/lib.go Outdated Show resolved Hide resolved
lib/lib.go Outdated Show resolved Hide resolved
lib/lib.go Outdated Show resolved Hide resolved
lib/lib.go Outdated Show resolved Hide resolved
lib/types.go Outdated Show resolved Hide resolved
lib/types.go Outdated Show resolved Hide resolved
lib/types.go Outdated Show resolved Hide resolved
lib/types.go Outdated Show resolved Hide resolved
@sebrandon1
Copy link
Contributor Author

@komish Thanks for the review! Yes, actually what you propose makes a lot of sense by pushing some of that logic farther into the code and only getting two functions CheckContainer(...) and CheckOperator(...) with appropriate parameters exposed that would make things much easier. Those two functions could return your runtime.Results structs and handle everything internally versus me interpreting a JSON blob and unmarshalling it back into your structs. Removes a lot of complexity on the whoever "consumes" the lib so I'm fine with that.

With my initial PoC approach I didn't want to change too much to get this working but this makes more sense for future-proofing the effort. Very exciting!

@komish
Copy link
Contributor

komish commented Oct 21, 2022

@sebrandon1 for sure. I鈥檒l give some folks time to look and then we can chart the path to get this merged!

@komish
Copy link
Contributor

komish commented Oct 24, 2022

@sebrandon1 I'll have you move lib to internal/lib, and then rewire the import statements to use that new path. From there, we'll expose hooks for you to be able to run the checks. This temporarily breaks your use case, but we'll fast-follow this on our end and I'll ping you into the PR that adds the exported functionality for your use case.

@sebrandon1
Copy link
Contributor Author

@komish Sounds excellent! I'll do that right now.

@sebrandon1
Copy link
Contributor Author

Okay in 7a84034 I moved the lib into a new "internal" folder in the top level and changed the references.

@komish
Copy link
Contributor

komish commented Oct 24, 2022

@sebrandon1

The CI failure reports:

internal/lib/lib.go:10                goimports  File is not `goimports`-ed with -local github.com/redhat-openshift-ecosystem/openshift-preflight
internal/lib/types.go:12              goimports  File is not `goimports`-ed with -local github.com/redhat-openshift-ecosystem/openshift-preflight
certification/internal/lib/lib.go:10  goimports  File is not `goimports`-ed with -local github.com/redhat-openshift-ecosystem/openshift-preflight

Given that's the only failure I see right at this moment, I think running this and committing the changes should fix the issue:

./bin/golangci-lint run --fix

@sebrandon1
Copy link
Contributor Author

Okay fixed. I ran ./bin/golangci-lint run --fix.

@coveralls
Copy link

coveralls commented Oct 24, 2022

Coverage Status

Coverage decreased (-0.02%) to 84.48% when pulling 1bc39fc on sebrandon1:rename_lib into 2108a28 on redhat-openshift-ecosystem:main.

@komish
Copy link
Contributor

komish commented Oct 25, 2022

Added on two commits to fix the coverage issues and fix a couple of case issues in comments for exported functions.

Coverage issues were fixed by:

  • adding suite_test.go to the internal/lib. They were being skipped.
  • moving NewCheckOperatorRunner-related tests to internal/lib where that function now lives
  • moving fakes.go to fakes_test.go which excludes it in coverage evaluation.

@komish
Copy link
Contributor

komish commented Oct 25, 2022

0d08e68 removes a duplicate bit of code and moves the test to the correct location.

@komish
Copy link
Contributor

komish commented Oct 25, 2022

@sebrandon1 @bcrochet @acornett21 as I've made changes here, PTAL.

@komish
Copy link
Contributor

komish commented Oct 25, 2022

@tkrishtop Just a heads up that it seems like this is a problem in the infrastructure's ability to RW files on the filesystem (permission denied) and doesn't seem related to the PR's changes at first glance.

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.

I've made changes so I'm removing my request for change and requesting reviews

@komish komish dismissed their stale review October 25, 2022 18:23

contributed changes

@acornett21
Copy link
Contributor

@komish I think this addresses everything, the only thing we'd need is the commits squashed.

@openshift-ci openshift-ci bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 25, 2022
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Oct 25, 2022
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

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 25, 2022
@openshift-ci
Copy link

openshift-ci bot commented Oct 25, 2022

[APPROVALNOTIFIER] This PR is APPROVED

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

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]

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

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.

None yet

6 participants