-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
pkg/asset: remove asset stocks. store asset state in asset itself. #344
pkg/asset: remove asset stocks. store asset state in asset itself. #344
Conversation
/hold Waiting on CI to actually test this code. |
/hold cancel |
/test all |
The router didn't come up in time:
Sometimes that happens as a flake. /retest |
/approve |
This might have been because the workers didn't come up. And the router is deployed on workers. |
@staebler Can you fix the format of your commit title and add a description to the body? It helps the reviewer understand why things are being changed and it helps our future selves remember why we made the change. |
pkg/asset/parents.go
Outdated
type Parents map[reflect.Type]*State | ||
|
||
// Get gets the state of the specified asset. | ||
func (p Parents) Get(asset Asset) (*State, bool) { |
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.
Why is there a distinction between Asset
and State
? Is it possible for each asset to implement its own special logic and the Asset
interface, allowing us to drop State
? I had imagined this method would look as follows:
func (p Parents) Get(asset &Asset) { // this isn't quite right because Asset is an interface
*asset, ok := p[reflect.TypeOf(asset)]
if !ok {
panic("Asset %s was requested, but was not available", asset.Name())
}
}
We could then pass in the subset of assets that have been declared by each assets' Dependencies()
method to ensure that every asset is properly declaring its dependencies.
@yifan-gu I am working through some minor bugs. I'll push up an update with its current rough state. |
@abhinavdahiya I can break into a commit per package, but they will not be atomic commits. Is that sufficient? It makes it more cumbersome to resolve merge conflicts when there are multiple commits .If it makes the review easier, then I'll do it. |
pkg/asset/tls/BUILD.bazel
Outdated
@@ -0,0 +1,52 @@ | |||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") |
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.
*.bazel
no bazel files required. can you remove this.
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.
Yep, this got left in accidentally in one of the merges. I will remove it.
@staebler this looks good, just some small not importants. |
And sorry for the rebase around #400 :( |
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.
/approve
@crawford Wanna take another look on this? |
/approve |
operator-framework/operator-lifecycle-manager#500 /retest |
pkg/asset/asset.go
Outdated
// PersistToFile writes all of the files of the specified asset into the specified | ||
// directory. If the asset is not a WritableAsset, then no files will be written. | ||
func PersistToFile(asset Asset, directory string) error { | ||
writableAsset, ok := asset.(WritableAsset) |
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.
Why not just change the signature of PersistToFile
? Targets shouldn't include non-writable assets.
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 is fine, too. I'll make that change.
/approve This looks fantastic! |
pkg/asset/asset_test.go
Outdated
|
||
asset := &persistAsset{} | ||
expectedFiles := map[string][]byte{} | ||
err = PersistToFile(asset, dir) |
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.
# github.com/openshift/installer/pkg/asset
pkg/asset/asset_test.go:45:21: cannot use asset (type *persistAsset) as type WritableAsset in argument to PersistToFile:
*persistAsset does not implement WritableAsset (missing Files method)
/lgtm |
This improves the code surrounding accessing state for dependent assets. It reduces the amount of casting and de-serialization of state data. Every asset is now associated with a unique type. The asset store retains at most a single instance of a given asset type.
…asset state Assets have been changed to store their state internally.
If PersistToFile only accepts WritableAsset instances, then PersistToFile does not have to case to WritableAsset or deal with assets that do not generate any files.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: abhinavdahiya, crawford, staebler, yifan-gu 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:
Approvers can indicate their approval by writing |
This improves the code surrounding accessing state for dependent assets. It reduces the amount of casting and de-serialization of state data.
Every asset is now associated with a unique type. The asset store retains at most a single instance of a given asset type.