Skip to content

Commit

Permalink
Revert "updates"
Browse files Browse the repository at this point in the history
This reverts commit b7abc41.
  • Loading branch information
aknysh committed Dec 8, 2024
1 parent 0c21c76 commit 1dce45d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 38 deletions.
68 changes: 33 additions & 35 deletions internal/exec/stack_processor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func ProcessYAMLConfigFiles(
".yml",
)

deepMergedStackConfig, importsConfig, stackConfig, _, _, err := ProcessYAMLConfigFile(
deepMergedStackConfig, importsConfig, stackConfig, err := ProcessYAMLConfigFile(
cliConfig,
stackBasePath,
p,
Expand Down Expand Up @@ -167,8 +167,6 @@ func ProcessYAMLConfigFile(
map[string]any,
map[string]map[string]any,
map[string]any,
map[string]any,
map[string]any,
error,
) {

Expand Down Expand Up @@ -196,13 +194,13 @@ func ProcessYAMLConfigFile(
// This is useful when generating Atmos manifests using other tools, but the imported files are not present yet at the generation time.
if err != nil {
if ignoreMissingFiles || skipIfMissing {
return map[string]any{}, map[string]map[string]any{}, map[string]any{}, map[string]any{}, map[string]any{}, nil
return map[string]any{}, map[string]map[string]any{}, map[string]any{}, nil
} else {
return nil, nil, nil, nil, nil, err
return nil, nil, nil, err
}
}
if stackYamlConfig == "" {
return map[string]any{}, map[string]map[string]any{}, map[string]any{}, map[string]any{}, map[string]any{}, nil
return map[string]any{}, map[string]map[string]any{}, map[string]any{}, nil
}

stackManifestTemplatesProcessed := stackYamlConfig
Expand All @@ -217,7 +215,7 @@ func ProcessYAMLConfigFile(
stackManifestTemplatesErrorMessage = fmt.Sprintf("\n\n%s", stackYamlConfig)
}
e := fmt.Errorf("invalid stack manifest '%s'\n%v%s", relativeFilePath, err, stackManifestTemplatesErrorMessage)
return nil, nil, nil, nil, nil, e
return nil, nil, nil, e
}
}

Expand All @@ -227,7 +225,7 @@ func ProcessYAMLConfigFile(
stackManifestTemplatesErrorMessage = fmt.Sprintf("\n\n%s", stackYamlConfig)
}
e := fmt.Errorf("invalid stack manifest '%s'\n%v%s", relativeFilePath, err, stackManifestTemplatesErrorMessage)
return nil, nil, nil, nil, nil, e
return nil, nil, nil, e
}

// If the path to the Atmos manifest JSON Schema is provided, validate the stack manifest against it
Expand All @@ -236,12 +234,12 @@ func ProcessYAMLConfigFile(
// jsonschema: invalid jsonType: map[interface {}]interface {}
dataJson, err := u.ConvertToJSONFast(stackConfigMap)
if err != nil {
return nil, nil, nil, nil, nil, err
return nil, nil, nil, err
}

dataFromJson, err := u.ConvertFromJSON(dataJson)
if err != nil {
return nil, nil, nil, nil, nil, err
return nil, nil, nil, err
}

compiler := jsonschema.NewCompiler()
Expand All @@ -250,30 +248,30 @@ func ProcessYAMLConfigFile(

atmosManifestJsonSchemaFileReader, err := os.Open(atmosManifestJsonSchemaFilePath)
if err != nil {
return nil, nil, nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, err)
return nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, err)
}

if err := compiler.AddResource(atmosManifestJsonSchemaFilePath, atmosManifestJsonSchemaFileReader); err != nil {
return nil, nil, nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, err)
return nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, err)
}

compiler.Draft = jsonschema.Draft2020

compiledSchema, err := compiler.Compile(atmosManifestJsonSchemaFilePath)
if err != nil {
return nil, nil, nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, err)
return nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, err)
}

if err = compiledSchema.Validate(dataFromJson); err != nil {
switch e := err.(type) {
case *jsonschema.ValidationError:
b, err2 := json.MarshalIndent(e.BasicOutput(), "", " ")
if err2 != nil {
return nil, nil, nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, err2)
return nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, err2)
}
return nil, nil, nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, string(b))
return nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, string(b))
default:
return nil, nil, nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, err)
return nil, nil, nil, errors.Errorf(atmosManifestJsonSchemaValidationErrorFormat, relativeFilePath, err)
}
}
}
Expand All @@ -283,32 +281,32 @@ func ProcessYAMLConfigFile(
// Global overrides
if i, ok := stackConfigMap[cfg.OverridesSectionName]; ok {
if globalOverrides, ok = i.(map[string]any); !ok {
return nil, nil, nil, nil, nil, fmt.Errorf("invalid 'overrides' section in the stack manifest '%s'", relativeFilePath)
return nil, nil, nil, fmt.Errorf("invalid 'overrides' section in the stack manifest '%s'", relativeFilePath)
}
}

// Terraform overrides in this stack manifest
if o, ok := stackConfigMap["terraform"]; ok {
if globalTerraformSection, ok = o.(map[string]any); !ok {
return nil, nil, nil, nil, nil, fmt.Errorf("invalid 'terraform' section in the stack manifest '%s'", relativeFilePath)
return nil, nil, nil, fmt.Errorf("invalid 'terraform' section in the stack manifest '%s'", relativeFilePath)
}

if i, ok := globalTerraformSection[cfg.OverridesSectionName]; ok {
if terraformOverrides, ok = i.(map[string]any); !ok {
return nil, nil, nil, nil, nil, fmt.Errorf("invalid 'terraform.overrides' section in the stack manifest '%s'", relativeFilePath)
return nil, nil, nil, fmt.Errorf("invalid 'terraform.overrides' section in the stack manifest '%s'", relativeFilePath)
}
}
}

// Helmfile overrides in this stack manifest
if o, ok := stackConfigMap["helmfile"]; ok {
if globalHelmfileSection, ok = o.(map[string]any); !ok {
return nil, nil, nil, nil, nil, fmt.Errorf("invalid 'helmfile' section in the stack manifest '%s'", relativeFilePath)
return nil, nil, nil, fmt.Errorf("invalid 'helmfile' section in the stack manifest '%s'", relativeFilePath)
}

if i, ok := globalHelmfileSection[cfg.OverridesSectionName]; ok {
if helmfileOverrides, ok = i.(map[string]any); !ok {
return nil, nil, nil, nil, nil, fmt.Errorf("invalid 'terraform.overrides' section in the stack manifest '%s'", relativeFilePath)
return nil, nil, nil, fmt.Errorf("invalid 'terraform.overrides' section in the stack manifest '%s'", relativeFilePath)
}
}
}
Expand All @@ -319,7 +317,7 @@ func ProcessYAMLConfigFile(
[]map[string]any{globalOverrides, terraformOverrides, parentTerraformOverrides},
)
if err != nil {
return nil, nil, nil, nil, nil, err
return nil, nil, nil, err
}

// Final Helmfile `overrides`
Expand All @@ -328,20 +326,20 @@ func ProcessYAMLConfigFile(
[]map[string]any{globalOverrides, helmfileOverrides, parentHelmfileOverrides},
)
if err != nil {
return nil, nil, nil, nil, nil, err
return nil, nil, nil, err
}

// Find and process all imports
importStructs, err := ProcessImportSection(stackConfigMap, relativeFilePath)
if err != nil {
return nil, nil, nil, nil, nil, err
return nil, nil, nil, err
}

for _, importStruct := range importStructs {
imp := importStruct.Path

if imp == "" {
return nil, nil, nil, nil, nil, fmt.Errorf("invalid empty import in the manifest '%s'", relativeFilePath)
return nil, nil, nil, fmt.Errorf("invalid empty import in the manifest '%s'", relativeFilePath)
}

// If the import file is specified without extension, use `.yaml` as default
Expand Down Expand Up @@ -383,7 +381,7 @@ func ProcessYAMLConfigFile(
errorMessage := fmt.Sprintf("invalid import in the manifest '%s'\nThe file imports itself in '%s'",
relativeFilePath,
imp)
return nil, nil, nil, nil, nil, errors.New(errorMessage)
return nil, nil, nil, errors.New(errorMessage)
}

// Find all import matches in the glob
Expand All @@ -397,7 +395,7 @@ func ProcessYAMLConfigFile(
// The import was not found -> check if the import is a Go template; if not, return the error
isGolangTemplate, err2 := IsGolangTemplate(imp)
if err2 != nil {
return nil, nil, nil, nil, nil, err2
return nil, nil, nil, err2
}

// If the import is not a Go template and SkipIfMissing is false, return the error
Expand All @@ -408,13 +406,13 @@ func ProcessYAMLConfigFile(
relativeFilePath,
err,
)
return nil, nil, nil, nil, nil, errors.New(errorMessage)
return nil, nil, nil, errors.New(errorMessage)
} else if importMatches == nil {
errorMessage := fmt.Sprintf("no matches found for the import '%s' in the file '%s'",
imp,
relativeFilePath,
)
return nil, nil, nil, nil, nil, errors.New(errorMessage)
return nil, nil, nil, errors.New(errorMessage)
}
}
}
Expand All @@ -427,12 +425,12 @@ func ProcessYAMLConfigFile(
listOfMaps := []map[string]any{importStruct.Context, context}
mergedContext, err := m.Merge(cliConfig, listOfMaps)
if err != nil {
return nil, nil, nil, nil, nil, err
return nil, nil, nil, err
}

// Process the imports in the current manifest
for _, importFile := range importMatches {
yamlConfig, _, yamlConfigRaw, _, _, err2 := ProcessYAMLConfigFile(
yamlConfig, _, yamlConfigRaw, err2 := ProcessYAMLConfigFile(
cliConfig,
basePath,
importFile,
Expand All @@ -447,7 +445,7 @@ func ProcessYAMLConfigFile(
"",
)
if err2 != nil {
return nil, nil, nil, nil, nil, err2
return nil, nil, nil, err2
}

stackConfigs = append(stackConfigs, yamlConfig)
Expand Down Expand Up @@ -496,10 +494,10 @@ func ProcessYAMLConfigFile(
stackConfigsDeepMerged, err := m.Merge(cliConfig, stackConfigs)
if err != nil {
err2 := fmt.Errorf("ProcessYAMLConfigFile: Merge: Deep-merge the stack manifest and all the imports: Error: %v", err)
return nil, nil, nil, nil, nil, err2
return nil, nil, nil, err2
}

return stackConfigsDeepMerged, importsConfig, stackConfigMap, finalTerraformOverrides, finalHelmfileOverrides, nil
return stackConfigsDeepMerged, importsConfig, stackConfigMap, nil
}

// ProcessStackConfig takes a stack manifest, deep-merges all variables, settings, environments and backends,
Expand Down Expand Up @@ -1822,7 +1820,7 @@ func CreateComponentStackMap(
isYaml := u.IsYaml(p)

if !isDirectory && isYaml {
config, _, _, _, _, err := ProcessYAMLConfigFile(
config, _, _, err := ProcessYAMLConfigFile(
cliConfig,
stacksBasePath,
p,
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/validate_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func ValidateStacks(cliConfig schema.CliConfiguration) error {
path.Join(cliConfig.BasePath, cliConfig.Stacks.BasePath)))

for _, filePath := range stackConfigFilesAbsolutePaths {
stackConfig, importsConfig, _, _, _, err := ProcessYAMLConfigFile(
stackConfig, importsConfig, _, err := ProcessYAMLConfigFile(
cliConfig,
cliConfig.StacksBaseAbsolutePath,
filePath,
Expand Down
2 changes: 0 additions & 2 deletions pkg/stack/stack_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ func ProcessYAMLConfigFile(
map[string]any,
map[string]map[string]any,
map[string]any,
map[string]any,
map[string]any,
error,
) {
return exec.ProcessYAMLConfigFile(
Expand Down

0 comments on commit 1dce45d

Please sign in to comment.