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

ADXT-89 feat(e2e): Introduce interface for environments and cross cloud-provi… #688

Merged
merged 11 commits into from
May 7, 2024

Conversation

KevinFairise2
Copy link
Contributor

@KevinFairise2 KevinFairise2 commented Mar 14, 2024

What does this PR do?

Create a new Env interface that must be implement by Environment struct specific for each Cloud Provider
It allows to have Cloud Agnostic function that can still access function that return values specific to a Cloud Provider. These methods should be described by the CloudEnv interface

Which scenarios this will impact?

Motivation

Additional Notes

@KevinFairise2 KevinFairise2 marked this pull request as ready for review March 14, 2024 15:59
@KevinFairise2 KevinFairise2 requested review from a team as code owners March 14, 2024 15:59
@KevinFairise2 KevinFairise2 marked this pull request as draft March 14, 2024 16:01
@KevinFairise2 KevinFairise2 marked this pull request as ready for review March 14, 2024 16:40
@KevinFairise2 KevinFairise2 changed the title feat(e2e): Introduce interface for environments and cross cloud-provi… ADXT-89 feat(e2e): Introduce interface for environments and cross cloud-provi… Mar 29, 2024
Comment on lines +107 to +111
GetBoolWithDefault(config *sdkconfig.Config, paramName string, defaultValue bool) bool
GetStringListWithDefault(config *sdkconfig.Config, paramName string, defaultValue []string) []string
GetStringWithDefault(config *sdkconfig.Config, paramName string, defaultValue string) string
GetObjectWithDefault(config *sdkconfig.Config, paramName string, outputValue, defaultValue interface{}) interface{}
GetIntWithDefault(config *sdkconfig.Config, paramName string, defaultValue int) int
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ question
What if these became static helpers taking Env as an argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not, I think both would work.
If we decide to keep it in the interface we'd need to have a BaseEnv struct that would implement these, because I do not think these methods depends on the cloud provider

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually all these methods are defined in CommonEnvironment that is embedded in Environment so we do not need to define these several times.
To me it is easier to use these functions directly as method of the environment. Did you have anything in mind that would make it better if we change it to static helpers?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about them, I ask how much they depend on the environment state.

Looking at one of the implementation, those functions use the environment only to log, and the logger is in the environment context.

func (e *CommonEnvironment) GetBoolWithDefault(config *sdkconfig.Config, paramName string, defaultValue bool) bool {
val, err := config.TryBool(paramName)
if err == nil {
return val
}
if !errors.Is(err, sdkconfig.ErrMissingVar) {
e.Ctx.Log.Error(fmt.Sprintf("Parameter %s not parsable, err: %v, will use default value: %v", paramName, err, defaultValue), nil)
}
return defaultValue
}

We could pass the context, and skip the strong dependency with the environment, so that we could get any value wherever from the configuration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually they do not depend on the environment. That's why they are method defined on CommonEnvironment, (here) and every environment should embed `CommonEnvironment

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 started to move from a method to a static function that would take the context as an argument:

func GetBoolWithDefault(ctx pulumi.Context, config *sdkconfig.Config, paramName string, defaultValue bool) bool {
 	val, err := config.TryBool(paramName) 
 	if err == nil { 
 		return val 
 	} 
  
 	if !errors.Is(err, sdkconfig.ErrMissingVar) { 
 		ctx.Log.Error(fmt.Sprintf("Parameter %s not parsable, err: %v, will use default value: %v", paramName, err, defaultValue), nil) 
}

But it would make a lot more changes in this PR and I feel like it make the function a bit less discoverable. Do you mind if we think about this other improvement in a follow-up PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure! Looks like they need an interface that implements a Log, ok for having it later

@KevinFairise2 KevinFairise2 requested a review from a team as a code owner April 23, 2024 11:49
@KevinFairise2 KevinFairise2 requested a review from a team as a code owner May 2, 2024 13:46
@KevinFairise2 KevinFairise2 enabled auto-merge (squash) May 7, 2024 07:17
@KevinFairise2 KevinFairise2 merged commit 3ef2a74 into main May 7, 2024
7 checks passed
@KevinFairise2 KevinFairise2 deleted the kfairise/refacto-e2e-interface-env branch May 7, 2024 07:21
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.

None yet

6 participants