Skip to content

Commit

Permalink
Refactor: remove unnecessary intermediate vars
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Kulikauskas <[email protected]>
  • Loading branch information
JustinKuli committed Oct 21, 2022
1 parent 534e11d commit 9688c83
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ func getManifests(policyConf *types.PolicyConfig) ([][]map[string]interface{}, e
_, filename := path.Split(f.Name())
if filename == "kustomization.yml" || filename == "kustomization.yaml" {
hasKustomize = true
manifestDocs, err := processKustomizeDir(manifest.Path)
manifestFiles, err = processKustomizeDir(manifest.Path)
if err != nil {
return nil, err
}

manifestFiles = manifestDocs

break
}
}
Expand Down Expand Up @@ -81,19 +79,16 @@ func getManifests(policyConf *types.PolicyConfig) ([][]map[string]interface{}, e
}
} else {
// Unmarshal the manifest in order to check for metadata patch replacement
manifestFile, err := unmarshalManifestFile(manifest.Path)
manifestFiles, err = unmarshalManifestFile(manifest.Path)
if err != nil {
return nil, err
}

if len(manifestFile) == 0 {
continue
}
// Allowing replace the original manifest metadata.name and/or metadata.namespace if it is a single
// yaml structure in the manifest path
if len(manifestFile) == 1 && len(manifest.Patches) == 1 {
if len(manifestFiles) == 1 && len(manifest.Patches) == 1 {
if patchMetadata, ok := manifest.Patches[0]["metadata"].(map[string]interface{}); ok {
if metadata, ok := manifestFile[0]["metadata"].(map[string]interface{}); ok {
if metadata, ok := manifestFiles[0]["metadata"].(map[string]interface{}); ok {
name, ok := patchMetadata["name"].(string)
if ok && name != "" {
metadata["name"] = name
Expand All @@ -102,12 +97,10 @@ func getManifests(policyConf *types.PolicyConfig) ([][]map[string]interface{}, e
if ok && namespace != "" {
metadata["namespace"] = namespace
}
manifestFile[0]["metadata"] = metadata
manifestFiles[0]["metadata"] = metadata
}
}
}

manifestFiles = append(manifestFiles, manifestFile...)
}

if len(manifest.Patches) > 0 {
Expand Down

0 comments on commit 9688c83

Please sign in to comment.