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

Make a single constructor for lifecycle inputs #1009

Merged
merged 7 commits into from
Feb 28, 2023

Conversation

natalieparellano
Copy link
Member

  • 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
Copy link
Member Author

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

Copy link
Contributor

@joe-kimmel-vmw joe-kimmel-vmw left a comment

Choose a reason for hiding this comment

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

LGTM, fwiw :)

Copy link
Contributor

@jabrown85 jabrown85 left a comment

Choose a reason for hiding this comment

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

I like it!

Comment on lines 103 to 115
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"
)
Copy link
Member Author

@natalieparellano natalieparellano Feb 14, 2023

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

@natalieparellano natalieparellano marked this pull request as ready for review February 14, 2023 17:34
@natalieparellano natalieparellano requested a review from a team as a code owner February 14, 2023 17:34
@natalieparellano
Copy link
Member Author

Marking as ready, but @jjbustamante we can wait for the OCI layout PR to land first to avoid extra work on your side :)

@natalieparellano
Copy link
Member Author

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>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
@natalieparellano
Copy link
Member Author

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 <layers>/generated) we would need to remember to add it as a path to update later and failing to do this resulted in confusing errors.

Comment on lines -105 to -115
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"
)
Copy link
Member Author

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`)
})
})
})
})

Copy link
Member Author

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`)
})
})
})
})

Copy link
Member Author

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>
Copy link
Contributor

@joe-kimmel-vmw joe-kimmel-vmw left a 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]))
Copy link
Contributor

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 👏

cmd/lifecycle/main.go Show resolved Hide resolved
Copy link
Contributor

@jabrown85 jabrown85 left a 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>
@natalieparellano natalieparellano merged commit cad291f into main Feb 28, 2023
@natalieparellano natalieparellano deleted the refactor/lifecycle-inputs branch February 28, 2023 17:01
@natalieparellano natalieparellano mentioned this pull request Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants