Skip to content

Commit

Permalink
Update depends_on and atmos describe dependents (#471)
Browse files Browse the repository at this point in the history
* Add `overrides` section to Atmos stack manifests

* Update `atmos describe dependents`

* Update `atmos describe dependents`

* Update `atmos describe dependents`
  • Loading branch information
aknysh authored Nov 3, 2023
1 parent b982c11 commit fc5357b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 152 deletions.
89 changes: 0 additions & 89 deletions .github/workflows/auto-format.yml

This file was deleted.

51 changes: 13 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
---

This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps.
[<img align="right" title="Share via Email" src="https://docs.cloudposse.com/images/ionicons/ios-email-outline-2.0.1-16x16-999999.svg"/>][share_email]
[<img align="right" title="Share on Google+" src="https://docs.cloudposse.com/images/ionicons/social-googleplus-outline-2.0.1-16x16-999999.svg" />][share_googleplus]
[<img align="right" title="Share on Facebook" src="https://docs.cloudposse.com/images/ionicons/social-facebook-outline-2.0.1-16x16-999999.svg" />][share_facebook]
[<img align="right" title="Share on Reddit" src="https://docs.cloudposse.com/images/ionicons/social-reddit-outline-2.0.1-16x16-999999.svg" />][share_reddit]
[<img align="right" title="Share on LinkedIn" src="https://docs.cloudposse.com/images/ionicons/social-linkedin-outline-2.0.1-16x16-999999.svg" />][share_linkedin]
[<img align="right" title="Share on Twitter" src="https://docs.cloudposse.com/images/ionicons/social-twitter-outline-2.0.1-16x16-999999.svg" />][share_twitter]



Expand Down Expand Up @@ -149,10 +143,6 @@ We deliver 10x the value for a fraction of the cost of a full-time engineer. Our

Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure.

## Discourse Forums

Participate in our [Discourse Forums][discourse]. Here you'll find answers to commonly asked questions. Most questions will be related to the enormous number of projects we support on our GitHub. Come here to collaborate on answers, find solutions, and get ideas about the products and services we value. It only takes a minute to get started! Just sign in with SSO using your GitHub account.

## Newsletter

Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
Expand All @@ -163,7 +153,18 @@ Sign up for [our newsletter][newsletter] that covers everything on our technolog

[![zoom](https://img.cloudposse.com/fit-in/200x200/https://cloudposse.com/wp-content/uploads/2019/08/Powered-by-Zoom.png")][office_hours]

## Contributing
## ✨ Contributing



This project is under active development, and we encourage contributions from our community.
Many thanks to our outstanding contributors:

<a href="https://github.com/cloudposse/atmos/graphs/contributors">
<img src="https://contrib.rocks/image?repo=cloudposse/atmos&max=24" />
</a>



### Bug Reports & Feature Requests

Expand Down Expand Up @@ -237,25 +238,7 @@ We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. W

We offer [paid support][commercial_support] on all of our projects.

Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation.



### Contributors

<!-- markdownlint-disable -->
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![RB][nitrocode_avatar]][nitrocode_homepage]<br/>[RB][nitrocode_homepage] |
|---|---|---|
<!-- markdownlint-restore -->

[osterman_homepage]: https://github.com/osterman
[osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png
[aknysh_homepage]: https://github.com/aknysh
[aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png
[nitrocode_homepage]: https://github.com/nitrocode
[nitrocode_avatar]: https://img.cloudposse.com/150x150/https://github.com/nitrocode.png

[![README Footer][readme_footer_img]][readme_footer_link]
Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation.[![README Footer][readme_footer_img]][readme_footer_link]
[![Beacon][beacon]][website]
<!-- markdownlint-disable -->
[logo]: https://cloudposse.com/logo-300x69.svg
Expand All @@ -265,12 +248,10 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
[jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=jobs
[hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=hire
[slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=slack
[linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=linkedin
[twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=twitter
[testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=testimonial
[office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=office_hours
[newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=newsletter
[discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=discourse
[email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=email
[commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=commercial_support
[we_love_open_source]: https://cpco.io/we-love-open-source?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=we_love_open_source
Expand All @@ -281,11 +262,5 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
[readme_footer_link]: https://cloudposse.com/readme/footer/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=readme_footer_link
[readme_commercial_support_img]: https://cloudposse.com/readme/commercial-support/img
[readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/atmos&utm_content=readme_commercial_support_link
[share_twitter]: https://twitter.com/intent/tweet/?text=atmos&url=https://github.com/cloudposse/atmos
[share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=atmos&url=https://github.com/cloudposse/atmos
[share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/atmos
[share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/atmos
[share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/atmos
[share_email]: mailto:?subject=atmos&body=https://github.com/cloudposse/atmos
[beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/atmos?pixel&cs=github&cm=readme&an=atmos
<!-- markdownlint-restore -->
58 changes: 35 additions & 23 deletions internal/exec/describe_dependents.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ func ExecuteDescribeDependents(
return nil, err
}

currentComponentSection, err := ExecuteDescribeComponent(component, stack)
providedComponentSection, err := ExecuteDescribeComponent(component, stack)
if err != nil {
return nil, err
}

// Get the current component `vars`
var currentComponentVarsSection map[any]any
if currentComponentVarsSection, ok = currentComponentSection["vars"].(map[any]any); !ok {
// Get the provided component `vars`
var providedComponentVarsSection map[any]any
if providedComponentVarsSection, ok = providedComponentSection["vars"].(map[any]any); !ok {
return dependents, nil
}

// Convert the current component `vars` section to the `Context` structure
var currentComponentVars schema.Context
err = mapstructure.Decode(currentComponentVarsSection, &currentComponentVars)
// Convert the provided component `vars` section to the `Context` structure
var providedComponentVars schema.Context
err = mapstructure.Decode(providedComponentVarsSection, &providedComponentVars)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func ExecuteDescribeDependents(
continue
}

// Skip the stack component if it's the same as the current component
// Skip the stack component if it's the same as the provided component
if stackComponentName == component {
continue
}
Expand Down Expand Up @@ -166,41 +166,53 @@ func ExecuteDescribeDependents(
continue
}

// Check if the stack component is a dependent of the current component
for _, stackComponentSettingsContext := range stackComponentSettings.DependsOn {
if stackComponentSettingsContext.Component != component {
// Check if the stack component is a dependent of the provided component
for _, dependsOn := range stackComponentSettings.DependsOn {
if dependsOn.Component != component {
continue
}

if stackComponentSettingsContext.Namespace != "" {
if stackComponentSettingsContext.Namespace != stackComponentVars.Namespace {
// Include the component from the stack if any of the following is true:
// - `namespace` is specified in `depends_on` and the provided component's namespace is equal to the namespace in `depends_on`
// - `namespace` is not specified in `depends_on` and the provided component is from the same namespace as the component in `depends_on`
if dependsOn.Namespace != "" {
if providedComponentVars.Namespace != dependsOn.Namespace {
continue
}
} else if currentComponentVars.Namespace != stackComponentVars.Namespace {
} else if providedComponentVars.Namespace != stackComponentVars.Namespace {
continue
}

if stackComponentSettingsContext.Tenant != "" {
if stackComponentSettingsContext.Tenant != stackComponentVars.Tenant {
// Include the component from the stack if any of the following is true:
// - `tenant` is specified in `depends_on` and the provided component's tenant is equal to the tenant in `depends_on`
// - `tenant` is not specified in `depends_on` and the provided component is from the same tenant as the component in `depends_on`
if dependsOn.Tenant != "" {
if providedComponentVars.Tenant != dependsOn.Tenant {
continue
}
} else if currentComponentVars.Tenant != stackComponentVars.Tenant {
} else if providedComponentVars.Tenant != stackComponentVars.Tenant {
continue
}

if stackComponentSettingsContext.Environment != "" {
if stackComponentSettingsContext.Environment != stackComponentVars.Environment {
// Include the component from the stack if any of the following is true:
// - `environment` is specified in `depends_on` and the component's environment is equal to the environment in `depends_on`
// - `environment` is not specified in `depends_on` and the provided component is from the same environment as the component in `depends_on`
if dependsOn.Environment != "" {
if providedComponentVars.Environment != dependsOn.Environment {
continue
}
} else if currentComponentVars.Environment != stackComponentVars.Environment {
} else if providedComponentVars.Environment != stackComponentVars.Environment {
continue
}

if stackComponentSettingsContext.Stage != "" {
if stackComponentSettingsContext.Stage != stackComponentVars.Stage {
// Include the component from the stack if any of the following is true:
// - `stage` is specified in `depends_on` and the provided component's stage is equal to the stage in `depends_on`
// - `stage` is not specified in `depends_on` and the provided component is from the same stage as the component in `depends_on`
if dependsOn.Stage != "" {
if providedComponentVars.Stage != dependsOn.Stage {
continue
}
} else if currentComponentVars.Stage != stackComponentVars.Stage {
} else if providedComponentVars.Stage != stackComponentVars.Stage {
continue
}

Expand Down
20 changes: 19 additions & 1 deletion pkg/describe/describe_dependents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,25 @@ func TestDescribeDependents(t *testing.T) {

dependents, err := e.ExecuteDescribeDependents(cliConfig, component, stack)
assert.Nil(t, err)
assert.Equal(t, 2, len(dependents))
assert.Equal(t, 1, len(dependents))

dependentsYaml, err := yaml.Marshal(dependents)
assert.Nil(t, err)
t.Log(string(dependentsYaml))
}

func TestDescribeDependents2(t *testing.T) {
configAndStacksInfo := schema.ConfigAndStacksInfo{}

cliConfig, err := cfg.InitCliConfig(configAndStacksInfo, true)
assert.Nil(t, err)

component := "test/test-component"
stack := "tenant1-ue2-dev"

dependents, err := e.ExecuteDescribeDependents(cliConfig, component, stack)
assert.Nil(t, err)
assert.Equal(t, 4, len(dependents))

dependentsYaml, err := yaml.Marshal(dependents)
assert.Nil(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/stack/stack_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func ProcessYAMLConfigFile(
}

// Process `Go` templates in the stack manifest using the provided context
if !skipTemplatesProcessingInImports {
if !skipTemplatesProcessingInImports && len(context) > 0 {
stackYamlConfig, err = u.ProcessTmpl(relativeFilePath, stackYamlConfig, context, ignoreMissingTemplateValues)
if err != nil {
return nil, nil, nil, err
Expand Down

0 comments on commit fc5357b

Please sign in to comment.