-
Notifications
You must be signed in to change notification settings - Fork 428
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
chore: Adds DependsOn converters and logic #2421
chore: Adds DependsOn converters and logic #2421
Conversation
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.
This looks really great! Very thorough unit tests!
clarifies convertDependsOn adjusts errors to be lowercase
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.
Wow this looks amazing!
|
||
var ( | ||
// Container dependency status options | ||
DependsOnStatus = []string{"start", "complete", "success"} |
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.
Can we make "start"... constants? Also how about "healthy"? #2419 should be able to unblock it.
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.
Is container health check in scheduled job? I believe the blocker was both the LB web service and the scheduled job.
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.
good point. i'll adjust the PR to add schedule job as well. maybe ignore this comment until they are all fixed
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.
Since you added it to your PR, I added healthy.
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.
Does this mean that we need to add some extra validation to stop main containers from depending on sidecar: healthy
conditions? Since sidecars don't have container health checks there's no way to determine sidecar health.
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.
Adjusted methods for finding essential containers and valid status to consider that sidecars can't have healthy condition.
adjusts graph to custom version adds datastructure for convert sidecar adds convertImageDependsOn to jobs Adjusts essential check to use aws.bool Removes unecessary circular dependency check Makes invalid container errors return themselves and not nil
adjusts functions to use convertSidecarOpts instead of individual parameters
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.
Alexandra. This is so good. I just have some small comments and questions about the logic
adjusts errors to state dependencies for circular dependencies, adds error for dependsny on itself adjusts comments adjusts status to allow healthy and adds function to ensure uppercase better modularizes cyclic dependency detection better modularizes essential status Please enter the commit message for your changes. Lines starting
Lines starting
@@ -120,49 +121,88 @@ func validateSidecarDependsOn(in manifest.SidecarConfig, sidecarName string, s c | |||
} | |||
|
|||
for name, status := range in.DependsOn { | |||
// status must be one of < start | complete | success > | |||
if !isValidStatus(status) { |
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.
Can we add a conversion to lowercase here, so that Healthy
in the manifest can get converted here to healthy
, register as valid, then get coverted to HEALTHY
in the CFN template?
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.
All statuses are converted to uppercase before it gets into validate through the transformations, (sidecar use) (image use) so I don't think it's necessary, unless things can bypass that check?
} | ||
|
||
func (graph *Graph) Add(fromNode, toNode string) { | ||
func (g *graph) Add(fromNode, toNode string) { |
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.
Can we make this function private too, since we aren't reusing this struct elsewhere?
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.
Good point! Adjusted.
adjusts essential status check and valid status check to consider that sidecars can never be "HEALTHY" adds errors for the above for sidecars adjusts errors to be less deeply nested for circular dependencies makes graph function private refactors acyclic to return early
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.
ship it feel free to remove the label whenever the PR is ready
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.
Extremely nice refactor. This is such a cool little piece of code! I'm approving this because my comments are just naming nits and small readability refactors and don't reflect any major changes. Feel free to remove the do-not-merge label when you've addressed them!
} | ||
if isEssential(name, s) && !isEssentialStatus(status) { | ||
return errEssentialContainerStatus | ||
if ok, err := isEssentialStatus(status, name, s); isEssential(name, s) && !ok { |
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.
Can we add a quick comment here explaining this bit of logic?
// Container cannot depend on essential containers having status `complete` or `success`
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.
Added a clarifying comment.
for _, allowed := range dependsOnStatus { | ||
if s == allowed { | ||
return true | ||
func isValidStatus(status string, container string, c convertSidecarOpts) (bool, error) { |
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.
Can we rename this to isValidStatusForContainer
? It might be a bit more transparent what we're checking that way.
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.
Adjusted naming.
return true | ||
func isValidStatus(status string, container string, c convertSidecarOpts) (bool, error) { | ||
if _, ok := c.sidecarConfig[container]; ok { | ||
for _, allowed := range sidecarDependsOnStatus { |
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.
can we rename this const to sidecarDependsOnValidStatuses
or sth similar for clarity?
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.
Adjusted.
if s == allowed { | ||
return true | ||
func isEssentialStatus(status string, container string, c convertSidecarOpts) (bool, error) { | ||
if _, ok := c.sidecarConfig[container]; ok { |
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.
since this bit of code is used pretty often, we might want to refactor it into a function:
func isSidecar(container string, sidecarConfig map[string]*manifest.SidecarConfig) bool
and this line can be replaced by:
if _, ok := c.sidecarConfig[container]; ok { | |
if isSidecar(container, c.sidecarConfig) { |
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.
Better modularized.
adjusts sidecar check to be its own function adjusts naming
Adds dependency logic and conversion functions. Addresses logic/conversions for aws#2175 . By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Adds dependency logic and conversion functions.
Addresses logic/conversions for #2175 .
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.