Skip to content

Complete more of the move from certification to internal #840

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

Merged
merged 1 commit into from
Dec 5, 2022

Conversation

bcrochet
Copy link
Contributor

@bcrochet bcrochet commented Nov 18, 2022

  • Moves certification/engine
  • Moves certification/formatters
  • Leaves the FormatterFunc type exported
  • Moves certification/pyxis
  • Moves certification/runtime
  • Moves certification/policy
  • Creates runtime top-level package

Signed-off-by: Brad P. Crochet [email protected]

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 18, 2022
@komish
Copy link
Contributor

komish commented Nov 18, 2022

As a library caller, this PR would not allow me to extract artifacts, such as the preflight.log, from my execution. The artifacts package needs to be made available so that a library caller can manipulate the context with the appropriate ArtifactWriter.

@bcrochet
Copy link
Contributor Author

bcrochet commented Nov 18, 2022

How would a library caller retrieve their artifacts if the artifact writer definitions are all internal

Should library users wish to retrieve the artifacts, I would propose that a (future) API could be added to reach internal and get a tar to get the artifacts. I currently view artifacts as a preflight-specific implementation detail, and not a general purpose thing for library users.

@komish
Copy link
Contributor

komish commented Nov 18, 2022

Should library users wish to retrieve the artifacts, I would propose that a (future) API could be added to reach internal and get a tar to get the artifacts. I currently view artifacts as a preflight-specific implementation detail, and not a general purpose thing for library users.

This doesn't work for me. If a library caller gets an error or failing result, (i.e. they don't pass), they have nothing they can do to troubleshoot the problem.

I don't see it as strictly internal functionality because of this. I also don't see it as a CLI-specific implementation detail.

@komish
Copy link
Contributor

komish commented Nov 18, 2022

I also don't see a reason to remove the formatters. The API isn't complicated, and it does a single thing - and guides developers on how they can implement their own.

With this said, I don't think it's strictly necessary. If you want it removed, you'll need to update doc/LIBRARY.md to remove the reference to it.

@bcrochet
Copy link
Contributor Author

Should library users wish to retrieve the artifacts, I would propose that a (future) API could be added to reach internal and get a tar to get the artifacts. I currently view artifacts as a preflight-specific implementation detail, and not a general purpose thing for library users.

This doesn't work for me. If a library caller gets an error or failing result, (i.e. they don't pass), they have nothing they can do to troubleshoot the problem.

I don't see it as strictly internal functionality because of this. I also don't see it as a CLI-specific implementation detail.

I think I can meet you halfway here. While I don't think the current implementation is necessary to be exposed, I do think that some mechanism to retrieve the artifacts would be useful to a library user. So, what I would propose is moving forward here, but then being thoughtful about what API we want to expose. Does that work for you? I do agree that the library user should have the opportunity to review them, I just don't think they necessarily need to write them, which is more what this artifacts implementation currently does.

@bcrochet
Copy link
Contributor Author

I also don't see a reason to remove the formatters. The API isn't complicated, and it does a single thing - and guides developers on how they can implement their own.

With this said, I don't think it's strictly necessary. If you want it removed, you'll need to update doc/LIBRARY.md to remove the reference to it.

I can come along with this. I'll pull them back out.

@komish
Copy link
Contributor

komish commented Nov 21, 2022

@bcrochet

Re: Artifacts

So, what I would propose is moving forward here, but then being thoughtful about what API we want to expose

This is fine - but we've got no roadmap planned on this. So, what do we do to bridge the gap until then?

I think I would have less of an issue with moving the artifacts into an internal package if executing Preflight (either policy) and having a failing or erroring result could be debugged without it. But as of today, the results for certain checks themselves tell the user top refer to the artifacts for information on how to troubleshoot.. Let alone the embedding of the preflight.log as an artifact for library callers.

I do agree that the library user should have the opportunity to review them, I just don't think they necessarily need to write them, which is more what this artifacts implementation currently does.

While some of the implementation makes reference to "Write", It's really just a semantic. We can call these methods anything we want. The FilesystemWriter "writes" to the fs, but the MapWriter is just building a map. The WriteFile method in the ArtifactWriter interface just maintains the verbiage used historically. IIRC, the previous artifacts directory had the same function.


Re: Formatters

I know you said you'd pull these back out. I'll propose an alternative path - realistically, we don't care what people do with the formatted results, but our ResponseFormatter gives describes extra functionality such as the extension that we don't necessary need to expose.

If we want to limit our API surface, maybe we just expose the FormatterFunc and a few functions such as FormatJUnitXML(...) FormatJSON(...) that effectively calls our internal type's FormatterFuncs? Or even just the DefaultFormatter.

The surface would be just that one type definition and the function(s) that we want to provide as, sort of, "defaults". That way, we encourage folks to write their own FormatterFunc, and we can keep our interface, implementations, internal to be modified.

ElapsedTime time.Duration
}

type Results struct {
TestedImage string
PassedOverall bool
TestedOn OpenshiftClusterVersion
TestedOn string
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why we changed this implementation detail, and added a String() method in runtime.go. Does this buy us something I'm not seeing?

Copy link
Contributor

@acornett21 acornett21 Nov 21, 2022

Choose a reason for hiding this comment

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

Also, this doesn't seem to work. This is always unknown/unknown in the json that gets written to disk and displayed to the user, even though internal results struct is correct internally pre-formatter call. I assume it's the genericFormatter that's causing the issue, but didn't look further.

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 why we changed this implementation detail, and added a String() method in runtime.go. Does this buy us something I'm not seeing?

There was no reason to expose the OpenshiftClusterVersion struct. I'll admit that where it stands right now is completely naive and may (probably?) doesn't work as it stands. I haven't looked at it further either.

Copy link
Contributor

Choose a reason for hiding this comment

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

We do 'expose' OpenshiftClusterVersion struct though, in the sense that it is written to disk, and written to the console. And as it stands that does not work for the reasons I stated above.

@bcrochet
Copy link
Contributor Author

@bcrochet

Re: Artifacts

So, what I would propose is moving forward here, but then being thoughtful about what API we want to expose

This is fine - but we've got no roadmap planned on this. So, what do we do to bridge the gap until then?

I think I would have less of an issue with moving the artifacts into an internal package if executing Preflight (either policy) and having a failing or erroring result could be debugged without it. But as of today, the results for certain checks themselves tell the user top refer to the artifacts for information on how to troubleshoot.. Let alone the embedding of the preflight.log as an artifact for library callers.

As I proposed elsewhere, I think the API to artifacts should just be a 'SaveXXX', like 'SaveTar', or 'SaveFs', 'SaveDir'. Or, 'Save(opt ArtifactOption)'. I don't think the writing of artifacts is something that the library user should be relying on the library to do. If a library user wants to add artifacts, they do so to their own artifacts payload without having to reach into the library to do it. Now, to GET the artifacts that the library generates, that makes sense.

I do agree that the library user should have the opportunity to review them, I just don't think they necessarily need to write them, which is more what this artifacts implementation currently does.

While some of the implementation makes reference to "Write", It's really just a semantic. We can call these methods anything we want. The FilesystemWriter "writes" to the fs, but the MapWriter is just building a map. The WriteFile method in the ArtifactWriter interface just maintains the verbiage used historically. IIRC, the previous artifacts directory had the same function.

I get that, however, I don't think it's necessary to expose that from the library. As I previously stated, I think the library should provide the capability to get to the artifacts generated, but not be responsible for writing to the library user's artifacts.

@bcrochet
Copy link
Contributor Author

Re: Formatters

I know you said you'd pull these back out. I'll propose an alternative path - realistically, we don't care what people do with the formatted results, but our ResponseFormatter gives describes extra functionality such as the extension that we don't necessary need to expose.

If we want to limit our API surface, maybe we just expose the FormatterFunc and a few functions such as FormatJUnitXML(...) FormatJSON(...) that effectively calls our internal type's FormatterFuncs? Or even just the DefaultFormatter.

The surface would be just that one type definition and the function(s) that we want to provide as, sort of, "defaults". That way, we encourage folks to write their own FormatterFunc, and we can keep our interface, implementations, internal to be modified.

I can get on board with this. Expose our current formatters that we've implemented, but still allow for creating your own formatter.

This tells me that these should probably be separate PRs.

@komish
Copy link
Contributor

komish commented Nov 22, 2022

I can get on board with this. Expose our current formatters that we've implemented, but still allow for creating your own formatter.

This tells me that these should probably be separate PRs.

However you want to do this is fine by me.

@komish
Copy link
Contributor

komish commented Nov 22, 2022

I get that, however, I don't think it's necessary to expose that from the library. As I previously stated, I think the library should provide the capability to get to the artifacts generated, but not be responsible for writing to the library user's artifacts.

Maybe we're not in the seeing each other regarding this point. The ArtifactWriter isn't something that the library caller consumes. It's effectively a choice the library caller makes, telling preflight how to write its artifacts in a way that the library caller can consume. "Write my artifacts here, and I'll retrieve them later".

As an example, if a library caller wanted to... say write an S3 Uploader ArtifactWriter - they could do that, then embed the artifact writer in the context and preflight would write its artifacts however the caller wishes.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2022
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2022
@bcrochet bcrochet changed the title Completely remove certification Complete more of the move from certification to internal Nov 22, 2022
* Moves certification/engine
* Moves certification/pyxis
* Moves certification/runtime
* Moves certification/policy
* Moves certification/artifacts -> artifacts
* Moves certification/formatters -> formatters and internal/formatters
* Leaves the FormatterFunc type exported
* Creates runtime top-level package

Signed-off-by: Brad P. Crochet <[email protected]>
@komish
Copy link
Contributor

komish commented Nov 29, 2022

Just to close the discussion loop here, I believe we landed on leaving the artifacts implementation on this branch as is for the moment, while @bcrochet reaches an alternative implementation that may be a bit more clearly defined for our use case.

The artifacts implementation as it exists in this branch would, therefore, move to the top level and outside of the certification module (as it is not needed).

Regarding logging, I believe we landed on exposing a few of our formatting functions as opposed to the internal formatter logic itself. Formatting, in itself, can be done however the user sees fit, and so we only intend to provide the execution our results formatting that we use as a baseline

@bcrochet please correct me if I've captured this incorrectly, it's been several days since our discussion!

"github.com/redhat-openshift-ecosystem/openshift-preflight/internal/runtime"
)

type openshiftClusterVersion = runtime.OpenshiftClusterVersion
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to ignore - does this still need to be here? It just looks like an alias, but I'm not sure why we would have used it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's an alias that reaches into internal so it can still be used as a type here, without having to duplicate it, and so that it isn't exposed as an actual part of the API.

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.

/lgtm

Thanks for this heavy lift!

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

openshift-ci bot commented Dec 5, 2022

[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

@bcrochet bcrochet merged commit b245d7b into redhat-openshift-ecosystem:lib Dec 5, 2022
@bcrochet bcrochet deleted the internal-move-4 branch June 6, 2023 17:00
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants