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

chore: Adds DependsOn converters and logic #2421

Merged
merged 14 commits into from
Jun 10, 2021

Conversation

xar-tol
Copy link
Contributor

@xar-tol xar-tol commented Jun 4, 2021

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.

@xar-tol xar-tol self-assigned this Jun 4, 2021
@xar-tol xar-tol requested a review from a team as a code owner June 4, 2021 17:10
@xar-tol xar-tol requested a review from huanjani June 4, 2021 17:10
@xar-tol xar-tol changed the title Xar tol/sidecar dependency converters Chore: Adds DependsOn converters and logic Jun 4, 2021
@xar-tol xar-tol changed the title Chore: Adds DependsOn converters and logic chore: Adds DependsOn converters and logic Jun 4, 2021
Copy link
Contributor

@huanjani huanjani left a 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
@bvtujo bvtujo added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jun 4, 2021
Copy link
Contributor

@iamhopaul123 iamhopaul123 left a 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"}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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
@xar-tol xar-tol requested a review from iamhopaul123 June 7, 2021 20:05
@iamhopaul123 iamhopaul123 assigned iamhopaul123 and unassigned xar-tol Jun 7, 2021
adjusts functions to use convertSidecarOpts instead of individual parameters
Copy link
Contributor

@bvtujo bvtujo left a 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
@xar-tol xar-tol requested review from iamhopaul123 and bvtujo June 8, 2021 19:44
@@ -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) {
Copy link
Contributor

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?

Copy link
Contributor Author

@xar-tol xar-tol Jun 10, 2021

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Adjusted.

xar-tol added 2 commits June 10, 2021 11:26
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
@xar-tol xar-tol requested review from iamhopaul123 and bvtujo June 10, 2021 15:53
Copy link
Contributor

@iamhopaul123 iamhopaul123 left a comment

Choose a reason for hiding this comment

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

ship it :shipit: feel free to remove the label whenever the PR is ready

Copy link
Contributor

@bvtujo bvtujo left a 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 {
Copy link
Contributor

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`

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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

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:

Suggested change
if _, ok := c.sidecarConfig[container]; ok {
if isSidecar(container, c.sidecarConfig) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better modularized.

xar-tol added 2 commits June 10, 2021 17:25
@xar-tol xar-tol removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jun 10, 2021
@mergify mergify bot merged commit bd2c70f into aws:mainline Jun 10, 2021
@xar-tol xar-tol deleted the xar-tol/sidecar-dependency-converters branch August 5, 2021 18:19
thrau pushed a commit to localstack/copilot-cli-local that referenced this pull request Dec 9, 2022
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.
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