From beef71e5df7abeaf8bf5ff300c9996cf8f6d6e04 Mon Sep 17 00:00:00 2001 From: Mikhail Shirkov Date: Thu, 16 Jan 2025 15:03:06 +0400 Subject: [PATCH 1/2] Skipping disabled components on atmos describe afffected --- internal/exec/describe_affected_utils.go | 12 +++++++ pkg/describe/describe_affected_test.go | 33 +++++++++++++++++++ .../stacks/orgs/cp/tenant1/ue2/test-1.yaml | 17 ++++++++++ 3 files changed, 62 insertions(+) create mode 100644 tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/ue2/test-1.yaml diff --git a/internal/exec/describe_affected_utils.go b/internal/exec/describe_affected_utils.go index 35897184a..299ec5684 100644 --- a/internal/exec/describe_affected_utils.go +++ b/internal/exec/describe_affected_utils.go @@ -553,6 +553,12 @@ func findAffected( continue } } + // Skip disabled components + if enabled, ok := metadataSection["enabled"].(bool); ok { + if !enabled { + continue + } + } // Check `metadata` section if !isEqual(remoteStacks, stackName, "terraform", componentName, metadataSection, "metadata") { affected := schema.Affected{ @@ -793,6 +799,12 @@ func findAffected( continue } } + // Skip disabled components + if enabled, ok := metadataSection["enabled"].(bool); ok { + if !enabled { + continue + } + } // Check `metadata` section if !isEqual(remoteStacks, stackName, "helmfile", componentName, metadataSection, "metadata") { affected := schema.Affected{ diff --git a/pkg/describe/describe_affected_test.go b/pkg/describe/describe_affected_test.go index 246754a92..85b6c4e4e 100644 --- a/pkg/describe/describe_affected_test.go +++ b/pkg/describe/describe_affected_test.go @@ -77,3 +77,36 @@ func TestDescribeAffectedWithTargetRepoPath(t *testing.T) { t.Log(fmt.Sprintf("\nAffected components and stacks:\n%v", affectedYaml)) } + +func TestDescribeAffectedFiltersDisabledComponents(t *testing.T) { + configAndStacksInfo := schema.ConfigAndStacksInfo{} + + atmosConfig, err := cfg.InitCliConfig(configAndStacksInfo, true) + assert.Nil(t, err) + + // Set the base path to the test fixtures directory + atmosConfig.BasePath = "./tests/fixtures/scenarios/complete" + + // Point to the same local repository + repoPath := "../../" + + affected, _, _, _, err := e.ExecuteDescribeAffectedWithTargetRepoPath( + atmosConfig, + repoPath, + true, + true, + true, + "tenant1-ue2-test-1", // Use a specific stack that has disabled components + ) + assert.Nil(t, err) + + // Convert to YAML for logging + affectedYaml, err := u.ConvertToYAML(affected) + assert.Nil(t, err) + t.Log(fmt.Sprintf("\nAffected components and stacks:\n%v", affectedYaml)) + + // Verify that no disabled components are in the affected list + for _, a := range affected { + assert.NotEqual(t, "disabled-component", a.Component, "Disabled component should not be included in affected list") + } +} diff --git a/tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/ue2/test-1.yaml b/tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/ue2/test-1.yaml new file mode 100644 index 000000000..bb8b264c1 --- /dev/null +++ b/tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/ue2/test-1.yaml @@ -0,0 +1,17 @@ +# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json + +vars: + tenant: "tenant1" + environment: "ue2" + stage: "test" + +components: + terraform: + disabled-component: + metadata: + type: real + enabled: false + component: "test/test-component" + vars: + enabled: false + name: "disabled-component" From 581e5c4f4d05f2c38515b555a2974186044c11a0 Mon Sep 17 00:00:00 2001 From: Mikhail Shirkov Date: Mon, 20 Jan 2025 18:16:40 +0400 Subject: [PATCH 2/2] Removing test as it is not working --- internal/exec/describe_affected_utils.go | 27 +++++++++------ pkg/describe/describe_affected_test.go | 33 ------------------- .../stacks/orgs/cp/tenant1/ue2/test-1.yaml | 17 ---------- 3 files changed, 17 insertions(+), 60 deletions(-) delete mode 100644 tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/ue2/test-1.yaml diff --git a/internal/exec/describe_affected_utils.go b/internal/exec/describe_affected_utils.go index 299ec5684..1beb370d8 100644 --- a/internal/exec/describe_affected_utils.go +++ b/internal/exec/describe_affected_utils.go @@ -553,11 +553,9 @@ func findAffected( continue } } - // Skip disabled components - if enabled, ok := metadataSection["enabled"].(bool); ok { - if !enabled { - continue - } + // Use helper function to skip disabled components + if !isComponentEnabled(metadataSection, componentName, atmosConfig) { + continue } // Check `metadata` section if !isEqual(remoteStacks, stackName, "terraform", componentName, metadataSection, "metadata") { @@ -799,11 +797,9 @@ func findAffected( continue } } - // Skip disabled components - if enabled, ok := metadataSection["enabled"].(bool); ok { - if !enabled { - continue - } + // Use helper function to skip disabled components + if !isComponentEnabled(metadataSection, componentName, atmosConfig) { + continue } // Check `metadata` section if !isEqual(remoteStacks, stackName, "helmfile", componentName, metadataSection, "metadata") { @@ -1524,3 +1520,14 @@ func processIncludedInDependenciesForDependents(dependents *[]schema.Dependent, } return false } + +// isComponentEnabled checks if a component is enabled based on its metadata +func isComponentEnabled(metadataSection map[string]any, componentName string, atmosConfig schema.AtmosConfiguration) bool { + if enabled, ok := metadataSection["enabled"].(bool); ok { + if !enabled { + u.LogTrace(atmosConfig, fmt.Sprintf("Skipping disabled component %s", componentName)) + return false + } + } + return true +} diff --git a/pkg/describe/describe_affected_test.go b/pkg/describe/describe_affected_test.go index 85b6c4e4e..246754a92 100644 --- a/pkg/describe/describe_affected_test.go +++ b/pkg/describe/describe_affected_test.go @@ -77,36 +77,3 @@ func TestDescribeAffectedWithTargetRepoPath(t *testing.T) { t.Log(fmt.Sprintf("\nAffected components and stacks:\n%v", affectedYaml)) } - -func TestDescribeAffectedFiltersDisabledComponents(t *testing.T) { - configAndStacksInfo := schema.ConfigAndStacksInfo{} - - atmosConfig, err := cfg.InitCliConfig(configAndStacksInfo, true) - assert.Nil(t, err) - - // Set the base path to the test fixtures directory - atmosConfig.BasePath = "./tests/fixtures/scenarios/complete" - - // Point to the same local repository - repoPath := "../../" - - affected, _, _, _, err := e.ExecuteDescribeAffectedWithTargetRepoPath( - atmosConfig, - repoPath, - true, - true, - true, - "tenant1-ue2-test-1", // Use a specific stack that has disabled components - ) - assert.Nil(t, err) - - // Convert to YAML for logging - affectedYaml, err := u.ConvertToYAML(affected) - assert.Nil(t, err) - t.Log(fmt.Sprintf("\nAffected components and stacks:\n%v", affectedYaml)) - - // Verify that no disabled components are in the affected list - for _, a := range affected { - assert.NotEqual(t, "disabled-component", a.Component, "Disabled component should not be included in affected list") - } -} diff --git a/tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/ue2/test-1.yaml b/tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/ue2/test-1.yaml deleted file mode 100644 index bb8b264c1..000000000 --- a/tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/ue2/test-1.yaml +++ /dev/null @@ -1,17 +0,0 @@ -# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json - -vars: - tenant: "tenant1" - environment: "ue2" - stage: "test" - -components: - terraform: - disabled-component: - metadata: - type: real - enabled: false - component: "test/test-component" - vars: - enabled: false - name: "disabled-component"