From 9501d221481acb223bb414c3b02942f0646fc4b5 Mon Sep 17 00:00:00 2001 From: Ryan VanGundy <85766511+rmvangun@users.noreply.github.com> Date: Tue, 25 Nov 2025 09:58:43 -0500 Subject: [PATCH] chore(blueprint): Remove unused substitutions file support We no longer support a `substitutions.yaml` file in the `_template` directory, leveraging Features exclusively. Signed-off-by: Ryan VanGundy <85766511+rmvangun@users.noreply.github.com> --- pkg/composer/blueprint/blueprint_handler.go | 19 +----- .../blueprint_handler_private_test.go | 19 +++--- .../blueprint_handler_public_test.go | 62 +++---------------- 3 files changed, 16 insertions(+), 84 deletions(-) diff --git a/pkg/composer/blueprint/blueprint_handler.go b/pkg/composer/blueprint/blueprint_handler.go index c00386f3e..d082c834b 100644 --- a/pkg/composer/blueprint/blueprint_handler.go +++ b/pkg/composer/blueprint/blueprint_handler.go @@ -441,17 +441,6 @@ func (b *BaseBlueprintHandler) GetLocalTemplateData() (map[string][]byte, error) } } - if existingValues, exists := templateData["substitutions"]; exists { - var ociSubstitutionValues map[string]any - if err := b.shims.YamlUnmarshal(existingValues, &ociSubstitutionValues); err == nil { - if substitutionValues == nil { - substitutionValues = ociSubstitutionValues - } else { - substitutionValues = b.deepMergeMaps(ociSubstitutionValues, substitutionValues) - } - } - } - if len(substitutionValues) > 0 { substitutionYAML, err := b.shims.YamlMarshal(substitutionValues) if err != nil { @@ -769,9 +758,8 @@ func (b *BaseBlueprintHandler) getKustomizations() []blueprintv1alpha1.Kustomiza // walkAndCollectTemplates recursively traverses the specified template directory and collects all files into the // templateData map. It adds the contents of each file by a normalized relative path key prefixed with "_template/". -// Special files "schema.yaml", "blueprint.yaml", and "substitutions" are also stored under canonical keys -// ("schema", "blueprint", "substitutions"). Directory entries are processed recursively. Any file or directory -// traversal errors are returned. +// Special files "schema.yaml" and "blueprint.yaml" are also stored under canonical keys ("schema", "blueprint"). +// Directory entries are processed recursively. Any file or directory traversal errors are returned. func (b *BaseBlueprintHandler) walkAndCollectTemplates(templateDir string, templateData map[string][]byte) error { entries, err := b.shims.ReadDir(templateDir) if err != nil { @@ -806,9 +794,6 @@ func (b *BaseBlueprintHandler) walkAndCollectTemplates(templateDir string, templ case "blueprint.yaml": templateData["blueprint"] = content templateData[key] = content - case "substitutions": - templateData["substitutions"] = content - templateData[key] = content default: templateData[key] = content } diff --git a/pkg/composer/blueprint/blueprint_handler_private_test.go b/pkg/composer/blueprint/blueprint_handler_private_test.go index d3415e6bd..ac91e4bec 100644 --- a/pkg/composer/blueprint/blueprint_handler_private_test.go +++ b/pkg/composer/blueprint/blueprint_handler_private_test.go @@ -334,9 +334,6 @@ func TestBaseBlueprintHandler_walkAndCollectTemplates(t *testing.T) { if _, exists := templateData["blueprint"]; !exists { t.Error("Expected 'blueprint' key to exist") } - if _, exists := templateData["substitutions"]; !exists { - t.Error("Expected 'substitutions' key to exist") - } if _, exists := templateData["_template/schema.yaml"]; !exists { t.Error("Expected '_template/schema.yaml' key to exist") @@ -2473,7 +2470,6 @@ kustomizations: } }) - t.Run("HandlesRepositoryField", func(t *testing.T) { handler := setup(t) blueprintData := []byte(`kind: Blueprint @@ -2660,7 +2656,7 @@ terraform: `) templateData := map[string][]byte{ - "blueprint.yaml": baseBlueprint, + "blueprint.yaml": baseBlueprint, "_template/features/generic.yaml": genericFeature, } @@ -3630,7 +3626,7 @@ terraform: key2: "value" `) templateData := map[string][]byte{ - "blueprint.yaml": baseBlueprint, + "blueprint.yaml": baseBlueprint, "_template/features/test.yaml": feature, } config := map[string]any{} @@ -3673,7 +3669,7 @@ terraform: new: "value" `) templateData := map[string][]byte{ - "blueprint.yaml": baseBlueprint, + "blueprint.yaml": baseBlueprint, "_template/features/test.yaml": feature, } config := map[string]any{} @@ -3716,7 +3712,7 @@ kustomize: - new-component `) templateData := map[string][]byte{ - "blueprint.yaml": baseBlueprint, + "blueprint.yaml": baseBlueprint, "_template/features/test.yaml": feature, } config := map[string]any{} @@ -3761,7 +3757,7 @@ kustomize: key: ${value} `) templateData := map[string][]byte{ - "blueprint.yaml": baseBlueprint, + "blueprint.yaml": baseBlueprint, "_template/features/test.yaml": feature, } config := map[string]any{ @@ -3790,7 +3786,6 @@ kustomize: } }) - t.Run("HandlesInterpolateStringError", func(t *testing.T) { handler := setup(t) baseBlueprint := []byte(`kind: Blueprint @@ -3808,7 +3803,7 @@ kustomize: - patch: ${invalid expression [[[ `) templateData := map[string][]byte{ - "blueprint.yaml": baseBlueprint, + "blueprint.yaml": baseBlueprint, "_template/features/test.yaml": feature, } config := map[string]any{} @@ -5611,7 +5606,7 @@ metadata: } templateData := map[string][]byte{ - "_metadata_name": []byte("custom-artifact"), + "_metadata_name": []byte("custom-artifact"), "_template/blueprint.yaml": []byte(`kind: Blueprint apiVersion: blueprints.windsorcli.dev/v1alpha1 metadata: diff --git a/pkg/composer/blueprint/blueprint_handler_public_test.go b/pkg/composer/blueprint/blueprint_handler_public_test.go index fd32f283f..b1ff5221c 100644 --- a/pkg/composer/blueprint/blueprint_handler_public_test.go +++ b/pkg/composer/blueprint/blueprint_handler_public_test.go @@ -3644,16 +3644,6 @@ terraform: t.Fatalf("Failed to create template directory: %v", err) } - substitutionsContent := []byte(`common: - key1: value1 - key2: value2 -kustomization1: - key3: value3 -`) - if err := os.WriteFile(filepath.Join(mocks.Runtime.TemplateRoot, "substitutions"), substitutionsContent, 0644); err != nil { - t.Fatalf("Failed to write substitutions file: %v", err) - } - handler.shims.Stat = os.Stat handler.shims.ReadDir = os.ReadDir handler.shims.ReadFile = os.ReadFile @@ -3664,69 +3654,31 @@ kustomization1: return map[string]any{ "substitutions": map[string]any{ "common": map[string]any{ - "key1": "merged-value1", + "key1": "value1", + "key2": "value2", }, "kustomization1": map[string]any{ - "key4": "value4", + "key3": "value3", }, }, }, nil } - templateData, err := handler.GetLocalTemplateData() - + _, err = handler.GetLocalTemplateData() if err != nil { t.Fatalf("Expected no error, got %v", err) } + if len(handler.commonSubstitutions) == 0 { t.Error("Expected common substitutions to be processed") } if len(handler.featureSubstitutions) == 0 { t.Error("Expected feature substitutions to be processed") } - if _, exists := templateData["substitutions"]; !exists { - t.Error("Expected substitutions to be in templateData") - } }) t.Run("HandlesSubstitutionUnmarshalError", func(t *testing.T) { - mocks := setupBlueprintMocks(t) - mockArtifactBuilder := artifact.NewMockArtifact() - handler, err := NewBlueprintHandler(mocks.Runtime, mockArtifactBuilder) - if err != nil { - t.Fatalf("NewBlueprintHandler() failed: %v", err) - } - handler.shims = mocks.Shims - - tmpDir := t.TempDir() - mocks.Runtime.ProjectRoot = tmpDir - mocks.Runtime.TemplateRoot = filepath.Join(tmpDir, "contexts", "_template") - mocks.Runtime.ConfigRoot = tmpDir - - if err := os.MkdirAll(mocks.Runtime.TemplateRoot, 0755); err != nil { - t.Fatalf("Failed to create template directory: %v", err) - } - - invalidSubstitutions := []byte("invalid: yaml: [") - if err := os.WriteFile(filepath.Join(mocks.Runtime.TemplateRoot, "substitutions"), invalidSubstitutions, 0644); err != nil { - t.Fatalf("Failed to write substitutions file: %v", err) - } - - handler.shims.Stat = os.Stat - handler.shims.ReadDir = os.ReadDir - handler.shims.ReadFile = os.ReadFile - handler.shims.YamlUnmarshal = yaml.Unmarshal - handler.shims.YamlMarshal = yaml.Marshal - - mocks.ConfigHandler.(*config.MockConfigHandler).GetContextValuesFunc = func() (map[string]any, error) { - return map[string]any{}, nil - } - - _, err = handler.GetLocalTemplateData() - - if err != nil { - t.Fatalf("Expected no error (unmarshal error should be ignored), got %v", err) - } + t.Skip("Substitutions are now only in values.yaml (contextValues) or Features, not in files") }) t.Run("HandlesSubstitutionMarshalError", func(t *testing.T) { @@ -3775,7 +3727,7 @@ kustomization1: t.Fatal("Expected error when YamlMarshal fails for substitutions") } if !strings.Contains(err.Error(), "failed to marshal substitution values") { - t.Errorf("Expected error about marshaling substitution values, got: %v", err) + t.Errorf("Expected error about marshaling substitutions, got: %v", err) } }) }