Skip to content

[chore] make Config a struct with config fields, but no logic #3958

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

atoulme
Copy link
Contributor

@atoulme atoulme commented Apr 30, 2025

By moving the logic out of Config, we make its lifecycle simple as a struct. We can then start to simplify how it is initialized and load it from a file, CLI flags, env vars and so on.

@atoulme atoulme requested a review from a team as a code owner April 30, 2025 06:26
@atoulme atoulme force-pushed the move_logic_out_of_config branch 3 times, most recently from 4b82974 to 2c00d6a Compare May 1, 2025 04:45
@atoulme atoulme force-pushed the move_logic_out_of_config branch from 2c00d6a to 8f1ac44 Compare May 1, 2025 05:20
@@ -185,3 +187,45 @@ func (a *autoDetect) TargetAllocatorAvailability() (targetallocator.Availability
func (a *autoDetect) FIPSEnabled(_ context.Context) bool {
return fips.IsFipsEnabled()
}

// ApplyAutoDetect attempts to automatically detect relevant information for this operator.
func ApplyAutoDetect(autoDetect AutoDetect, c *config.Config, logger logr.Logger) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason not to make this a method on AutoDetect?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, though this is a more impactful change since we need all mocks to implement it. That might also change the way the interface works.

@@ -185,3 +187,45 @@ func (a *autoDetect) TargetAllocatorAvailability() (targetallocator.Availability
func (a *autoDetect) FIPSEnabled(_ context.Context) bool {
return fips.IsFipsEnabled()
}

// ApplyAutoDetect attempts to automatically detect relevant information for this operator.
func ApplyAutoDetect(autoDetect AutoDetect, c *config.Config, logger logr.Logger) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

func ApplyAutoDetect(autoDetect AutoDetect, c *config.Config, logger logr.Logger) error {
logger.V(2).Info("auto-detecting the configuration based on the environment")

ora, err := autoDetect.OpenShiftRoutesAvailability()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should make this use something like the options pattern for when we instantiate the auto detect resource that we can just pass a list of options for the auto detect struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't quite understand why we use Options, these are internal structs with no external APIs. Do we have to watch for something in particular?

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.

4 participants