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

Refactor decouple #188

Merged
merged 18 commits into from
Sep 1, 2022
Merged

Conversation

acmenezes
Copy link
Contributor

This refactor is supposed to revert the potential risk for redundant circular reference caused by importing from operator package options or flags that belong to the command level. At the same time avoid the risk of having a tight coupling trying to pass all options to the operator package that doesn't care about most of them.

Now new functionality like adding CRs from the command line are very hard to implement. It's definitely a no go having to change the package on the bottom of the stack to implement a new flag that will be used on middle of the stack.

The flow of opcap packages is designed to be check --> consumes --> capability --> that consumes --> operator. It is still not perfect. But we should avoid as much as possible trying to pass parameters across the packages to the bottom of the stack or importing in reverse order which may lead to circular reference when we need to add new functionality in the future.

I've also took the opportunity to eliminate some unnecessary code a make the interfaces mode clear by not exporting a bunch of things that were unnecessarily exported on the capability package.

Here is what's being removed from the operator package:

type OperatorCheckOptions struct {
	// AuditPlan is an ordered list of tests to be run
	// during an operator audit
	AuditPlan []string
	// CatalogSource provides target catalog source
	// from which to list package manifests
	CatalogSource string
	// CatalogSourceNamespace specifies the namespace of the
	// catalog source to be used
	CatalogSourceNamespace string
	// ListPackages operation lists packages in the catalog source
	ListPackages bool
	// FilterPackages provides a list of packages to find
	FilterPackages []string
	// AllInstallModes is passed to test all install modes
	AllInstallModes bool
}

The flags should be processed on the top of the stack and not on the bottom.

We still need to redo the all install mode strategy though.

This change eliminates redundancy and tight coupling.

This reverts commit 96948d8, reversing
changes made to 67291a4.
On this commit all capAudit objects and methods were changed to lower
case in order to be non exported. The capAudit interface was removed
also to prevent confusion once the only interface to this package is
CapAuditor and not capAudit. CapAuditor now should be upper case and
exported. More on the documentation commit.

Signed-off-by: acmenezes <[email protected]>
We don't need a builder for this simple object and buildWorkQueue can be
run as the first step of an audit. That makes the code simpler and
easier to understand. All flag data interesting to capability package
can be passed by using the CapAuditor object and add to it as needed. It
makes CapAuditor the single entry point of flag data to the capabiltiy
package.

Signed-off-by: acmenezes <[email protected]>
@exe-prow-github-app exe-prow-github-app bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 30, 2022
@acmenezes acmenezes added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 30, 2022
@mrhillsman mrhillsman removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 30, 2022
Copy link
Contributor

@skattoju skattoju left a comment

Choose a reason for hiding this comment

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

looks good other than some cosmetic nits

@exe-prow-github-app exe-prow-github-app bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 30, 2022
@@ -90,5 +100,4 @@ func init() {
flags.StringSliceVar(&checkflags.AuditPlan, "auditplan", defaultAuditPlan, "audit plan is the ordered list of operator test functions to be called during a capability audit.")
flags.BoolVar(&checkflags.ListPackages, "list-packages", false, "list packages in the catalog")
flags.StringSliceVar(&checkflags.FilterPackages, "filter-packages", []string{}, "a list of package(s) which limits audits and/or other flag(s) output")
flags.BoolVar(&checkflags.AllInstallModes, "all-installmodes", false, "when set, all install modes supported by an operator will be tested")
Copy link
Contributor

Choose a reason for hiding this comment

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

Take note of any functionality removed. Here I can see the functionality to test all install modes has been removed.

Create a new issue if you want this reworked at a future time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree. Here is the new issue: Enable all supported install modes testing #189

Copy link
Contributor

Choose a reason for hiding this comment

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

@acmenezes , regarding the name convention for parameters, should we create them with the - (i.e --list-packages) or not like --auditplan?

Copy link
Contributor

Choose a reason for hiding this comment

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

My vote would be to include the '-'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There we go 9929e85 - dash included.

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.

Just a few comments.

cmd/check.go Outdated Show resolved Hide resolved
cmd/check.go Outdated Show resolved Hide resolved
internal/capability/auditor.go Outdated Show resolved Hide resolved
internal/capability/operand_cleanup.go Outdated Show resolved Hide resolved
internal/capability/operator_cleanup.go Outdated Show resolved Hide resolved
internal/capability/operator_install.go Outdated Show resolved Hide resolved
internal/capability/report.go Outdated Show resolved Hide resolved
internal/capability/report.go Outdated Show resolved Hide resolved
internal/capability/report.go Outdated Show resolved Hide resolved
internal/capability/report.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@yashoza19 yashoza19 left a comment

Choose a reason for hiding this comment

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

Everything else looks great. Tested.

cmd/check.go Outdated Show resolved Hide resolved
@exe-prow-github-app exe-prow-github-app bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 30, 2022
This allow for testing as well as other implementations of writers such
as writing to databases when we develop a more solid reporting
mechanism.

- Reports now are simpler functions taking io.writer
- operand and operator install will handle file creation and where to
  write reports to

Signed-off-by: acmenezes <[email protected]>
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 changes and general comments.

internal/capability/auditor.go Outdated Show resolved Hide resolved
@@ -90,5 +100,4 @@ func init() {
flags.StringSliceVar(&checkflags.AuditPlan, "auditplan", defaultAuditPlan, "audit plan is the ordered list of operator test functions to be called during a capability audit.")
flags.BoolVar(&checkflags.ListPackages, "list-packages", false, "list packages in the catalog")
flags.StringSliceVar(&checkflags.FilterPackages, "filter-packages", []string{}, "a list of package(s) which limits audits and/or other flag(s) output")
flags.BoolVar(&checkflags.AllInstallModes, "all-installmodes", false, "when set, all install modes supported by an operator will be tested")
Copy link
Contributor

Choose a reason for hiding this comment

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

My vote would be to include the '-'.

internal/capability/auditor.go Show resolved Hide resolved
internal/capability/auditor.go Outdated Show resolved Hide resolved
internal/capability/operand_cleanup.go Outdated Show resolved Hide resolved
internal/capability/operand_install.go Outdated Show resolved Hide resolved
@@ -105,7 +106,15 @@ func (ca *CapAudit) OperandInstall() error {
logger.Debug("exiting OperandInstall since no ALM_Examples found in CSV")
}

ca.Report(OperandInstallRptOptionFile{FilePath: "operand_install_report.json"}, OperandInstallRptOptionPrint{})
file, err := os.OpenFile("operand_install_report.json", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
Copy link
Contributor

Choose a reason for hiding this comment

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

Creating a report doesn't seem to be the job of this function. It should either be passed in an io.Reader, or return the data for someone else to log/report.

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 not a blocker. Just wanted to point this out for future discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @bcrochet the ca or capAudit object contains the data. And the method. And it's lifecycle ends with this install function. What do you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't have a suggestion just yet. I need to get a fuller understanding of the flow here.

logger.Debugf("Error creating subscriptions: %w", err)
return err
}

// Get a Succeeded or Failed CSV with one minute timeout
ca.Csv, err = ca.Client.GetCompletedCsvWithTimeout(ca.Namespace, ca.CsvWaitTime)
var err error
ca.csv, err = ca.client.GetCompletedCsvWithTimeout(ca.namespace, ca.csvWaitTime)
Copy link
Contributor

Choose a reason for hiding this comment

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

These two lines can be collaped, and just have 'ca.csv, err := ...'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @bcrochet apparently VSCode doesn't like that way. That's what happens when we remove and try to collapse the lines. **
image
**
Didn't have time to troubleshoot this. Do you have any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Leave it for now. Not a blocker.

internal/capability/operator_install.go Show resolved Hide resolved
internal/capability/report.go Show resolved Hide resolved
@bcrochet bcrochet mentioned this pull request Sep 1, 2022
4 tasks
@exe-prow-github-app exe-prow-github-app bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 1, 2022
@acmenezes acmenezes force-pushed the refactor_decouple branch 2 times, most recently from 9218f0b to 8d227c2 Compare September 1, 2022 16:20
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

@exe-prow-github-app exe-prow-github-app bot added the lgtm Indicates that a PR is ready to be merged. label Sep 1, 2022
@exe-prow-github-app
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: acmenezes, bcrochet, skattoju, yashoza19

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 [acmenezes,yashoza19]

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

1 similar comment
@exe-prow-github-app
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: acmenezes, bcrochet, skattoju, yashoza19

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 [acmenezes,yashoza19]

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

@yashoza19 yashoza19 removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 1, 2022
@exe-prow-github-app exe-prow-github-app bot merged commit 31757cd into opdev:main Sep 1, 2022
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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants