-
Notifications
You must be signed in to change notification settings - Fork 112
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
Make a single constructor for lifecycle inputs #1009
Conversation
natalieparellano
commented
Feb 13, 2023
- The logic to update the default path for TOML files was repeated across phases
- In general it is safe to provide default values for inputs that might not be relevant to the current phase, as these will be ignored when constructing a new service for the phase; e.g., platform.LifecycleInputs.OrderPath will be ignored when constructing a lifecycle.Exporter
- As more inputs are shared across phases (e.g., analyzed.toml is now an input to the detect phase), duplicating the logic for providing default values is becoming more cumbersome
@@ -55,6 +55,82 @@ type LifecycleInputs struct { | |||
KanikoCacheTTL time.Duration | |||
} | |||
|
|||
func NewLifecycleInputs(platformAPI *api.Version) LifecycleInputs { | |||
inputs := LifecycleInputs{ | |||
// Operator config |
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.
Mirrored the organization in platform/defaults.go
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.
LGTM, fwiw :)
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.
I like it!
ea6509e
to
d88c8cf
Compare
platform/lifecycle_inputs.go
Outdated
var ( | ||
ErrOutputImageRequired = "image argument is required" | ||
ErrRunImageRequiredWhenNoStackMD = "-run-image is required when there is no stack metadata available" | ||
ErrRunImageRequiredWhenNoRunMD = "-run-image is required when there is no run metadata available" | ||
ErrSupplyOnlyOneRunImage = "supply only one of -run-image or (deprecated) -image" | ||
ErrRunImageUnsupported = "-run-image is unsupported" | ||
ErrImageUnsupported = "-image is unsupported" | ||
MsgIgnoringLaunchCache = "Ignoring -launch-cache, only intended for use with -daemon" | ||
) |
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.
Moved this (and other "resolve" related functionality) to other file for readability
Marking as ready, but @jjbustamante we can wait for the OCI layout PR to land first to avoid extra work on your side :) |
Look at all that deleted code! |
- The logic to update the default path for TOML files was repeated across phases - In general it is safe to provide default values for inputs that might not be relevant to the current phase, as these will be ignored when constructing a new service for the phase; e.g., platform.LifecycleInputs.OrderPath will be ignored when constructing a lifecycle.Exporter - As more inputs are shared across phases (e.g., analyzed.toml is now an input to the detect phase), duplicating the logic for providing default values is becoming more cumbersome Signed-off-by: Natalie Arellano <narellano@vmware.com>
d88c8cf
to
f22c4f9
Compare
Signed-off-by: Natalie Arellano <narellano@vmware.com>
…ut that will be updated later Signed-off-by: Natalie Arellano <narellano@vmware.com>
I brought this up to date with the latest main and made a couple other changes, chiefly requiring the desired value of layers directory to be read before a new "platform" can be instantiated. The old pattern was to provide a "placeholder" layers directory and then after-the-fact go back and update all the placeholder paths with the correct value now that the layers directory is known. This had the downside that when adding any new inputs that defaulted to a child of the layers directory (such as the newly added "generated" dir which defaults to |
var ( | ||
ErrOutputImageRequired = "image argument is required" | ||
ErrRunImageRequiredWhenNoStackMD = "-run-image is required when there is no stack metadata available" | ||
ErrRunImageRequiredWhenNoRunMD = "-run-image is required when there is no run metadata available" | ||
ErrSupplyOnlyOneRunImage = "supply only one of -run-image or (deprecated) -image" | ||
ErrRunImageUnsupported = "-run-image is unsupported" | ||
ErrImageUnsupported = "-image is unsupported" | ||
ErrMultipleTargetsUnsupported = "exporting to multiple targets is unsupported" | ||
ErrLayoutDirRequired = "defining a layout directory is required when OCI Layout feature is enabled. Use -layout-dir flag or CNB_LAYOUT_DIR environment variable" | ||
MsgIgnoringLaunchCache = "Ignoring -launch-cache, only intended for use with -daemon" | ||
) |
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.
Moved to resolve_inputs.go
h.AssertNil(t, err) | ||
h.AssertNoLogEntry(t, logHandler, `no stack metadata found at path ''`) | ||
h.AssertNoLogEntry(t, logHandler, `Previous image with name "" not found`) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
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.
These are now tested in lifecycle_inputs_test.go
h.AssertNil(t, err) | ||
h.AssertNoLogEntry(t, logHandler, `no stack metadata found at path ''`) | ||
h.AssertNoLogEntry(t, logHandler, `Previous image with name "" not found`) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
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.
These are now tested in lifecycle_inputs_test.go
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
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.
sorry i feel like i'm leaving comments on your sidequest and not the main change, feel free to ignore me
@@ -18,31 +18,41 @@ import ( | |||
) | |||
|
|||
func main() { | |||
switch strings.TrimSuffix(filepath.Base(os.Args[0]), filepath.Ext(os.Args[0])) { | |||
phase := strings.TrimSuffix(filepath.Base(os.Args[0]), filepath.Ext(os.Args[0])) |
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.
fwiw I'm a fan of explicitly naming this string phase
instead of leaving it anonymous 👏
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.
I love this type of work!
Signed-off-by: Natalie Arellano <narellano@vmware.com>