-
Notifications
You must be signed in to change notification settings - Fork 75
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: dedicated struct for building source data #442
base: main
Are you sure you want to change the base?
Conversation
Skipping CI for Draft Pull Request. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
9e0af14
to
d8ceefb
Compare
d8ceefb
to
adea484
Compare
adea484
to
473857c
Compare
473857c
to
dd35bc9
Compare
/cc @inteon @SgtCoDFish |
4e6bd3c
to
1fcb3c3
Compare
1fcb3c3
to
f485127
Compare
f485127
to
e4adb6e
Compare
e4adb6e
to
022049b
Compare
022049b
to
dc9adf9
Compare
dc9adf9
to
136cb45
Compare
@SgtCoDFish Would it be possible for you to review this PR? It's been open for "a while", and I am a bit tired of rebasing it. 😅 So I would like to know if this refactoring might be acceptable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got a couple of suggestions, what do you think?
pkg/bundle/bundle.go
Outdated
@@ -35,51 +34,28 @@ import ( | |||
ctrl "sigs.k8s.io/controller-runtime" | |||
"sigs.k8s.io/controller-runtime/pkg/client" | |||
|
|||
"github.com/cert-manager/trust-manager/cmd/trust-manager/app/options" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I don't love the idea of depending on ./cmd
from ./pkg
. I think that'll end in a circular dependency down the road - I'd expect cmd
to depend on pkg
but not the other way round.
I would vote to keep the options struct where it is in pkg
.
(I totally accept that package structuring is a bit arbitrary but I do think it's better for the long term to not risk this kind of circular dependency creeping in)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was actually a circular dependency that made me move Options
, but I agree with your comment. Will fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be ok with moving the options package to ./pkg
? I cannot leave the Bundle options where it currently is located under ./pkg
- as that will create a circular dependency.
pkg/bundle/internal/target/source.go
Outdated
type BundleBuilder struct { | ||
// a cache-backed Kubernetes Client | ||
Client client.Client | ||
|
||
// DefaultPackage holds the loaded 'default' certificate package, if one was specified | ||
// at startup. | ||
DefaultPackage *fspkg.Package | ||
|
||
// Options holds options for the Bundle controller. | ||
Options options.Bundle | ||
} | ||
|
||
func (b *BundleBuilder) Init() error { | ||
if b.Options.DefaultPackageLocation != "" { | ||
pkg, err := fspkg.LoadPackageFromFile(b.Options.DefaultPackageLocation) | ||
if err != nil { | ||
return fmt.Errorf("must load default package successfully when default package location is set: %w", err) | ||
} | ||
|
||
b.DefaultPackage = &pkg | ||
|
||
b.Options.Log.Info("successfully loaded default package from filesystem", "id", pkg.StringID(), "path", b.Options.DefaultPackageLocation) | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I think having an Init
function introduces the risk of an uninitialized BundleBuilder
struct being used somewhere and blowing things up.
A pattern I really like is to have a func NewBundleBuilder(client, defaultPackage, options) (*BundleBuilder, error)
- that way, a user can't forget to call Init
because creating the object and the init checks are done in NewBundleBuilder
.
(That pattern is more useful when the type is unexported because then it's impossible to create a bundleBuilder
which hasn't been initialized/validated, but it's not a requirement)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That pattern is more useful when the type is unexported because then it's impossible to create a bundleBuilder which hasn't been initialized/validated
That will require a new interface, right? I am ok with creating a new interface, but are you?
136cb45
to
f40e5ef
Compare
/test all |
f40e5ef
to
df6b8c4
Compare
Signed-off-by: Erik Godding Boye <egboye@gmail.com>
df6b8c4
to
8d44585
Compare
PR needs rebase. 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-sigs/prow repository. |
The main motivation for this PR, is to get closer to a solution to #58, as the bundle controller cannot be used directly for this use case.
But I can identify a few more improvements in this: