Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/npm_and_yarn/docs/plugins/gtag/ba…
Browse files Browse the repository at this point in the history
…bel/traverse-7.23.2
krancour authored Nov 21, 2023
2 parents c298fca + bb12522 commit 64c5e7e
Showing 36 changed files with 937 additions and 1,007 deletions.
2 changes: 1 addition & 1 deletion .github/governance.yml
Original file line number Diff line number Diff line change
@@ -39,4 +39,4 @@ issue:
- release-process
# kargo-render component areas
multiple: true
needs: true
needs: false
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -4,8 +4,10 @@
[![codecov](https://codecov.io/gh/akuity/kargo-render/branch/main/graph/badge.svg?token=MRKMA584M9)](https://codecov.io/gh/akuity/kargo-render)
[![Netlify Status](https://api.netlify.com/api/v1/badges/f5d7d99b-ca3a-4477-a10b-67fb7a8328a9/deploy-status)](https://app.netlify.com/sites/docs-kargo-render-akuity-io/deploys)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
[![Discord](https://img.shields.io/discord/1138942074998235187?logo=discord&logoColor=ffffff&label=discord
)](http://akuity.community)

<img width="80" align="left" src="logo.png" style="right-margin: 20px"/>
<img width="140" align="left" src="kargo-logo.png" style="margin-right: 20px"/>

Placeholder

234 changes: 234 additions & 0 deletions argocd-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "argocd-schema.json",
"definitions": {
"helm": {
"description": "Helm holds helm specific options",
"properties": {
"fileParameters": {
"description": "FileParameters are file parameters to the helm template",
"items": {
"description": "HelmFileParameter is a file parameter that's passed to helm template during manifest generation",
"properties": {
"name": {
"description": "Name is the name of the Helm parameter",
"type": "string"
},
"path": {
"description": "Path is the path to the file containing the values for the Helm parameter",
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"ignoreMissingValueFiles": {
"description": "IgnoreMissingValueFiles prevents helm template from failing when valueFiles do not exist locally by not appending them to helm template --values",
"type": "boolean"
},
"parameters": {
"description": "Parameters is a list of Helm parameters which are passed to the helm template command upon manifest generation",
"items": {
"description": "HelmParameter is a parameter that's passed to helm template during manifest generation",
"properties": {
"forceString": {
"description": "ForceString determines whether to tell Helm to interpret booleans and numbers as strings",
"type": "boolean"
},
"name": {
"description": "Name is the name of the Helm parameter",
"type": "string"
},
"value": {
"description": "Value is the value for the Helm parameter",
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"passCredentials": {
"description": "PassCredentials pass credentials to all domains (Helm's --pass-credentials)",
"type": "boolean"
},
"releaseName": {
"description": "ReleaseName is the Helm release name to use. If omitted it will use the application name",
"type": "string"
},
"skipCrds": {
"description": "SkipCrds skips custom resource definition installation step (Helm's --skip-crds)",
"type": "boolean"
},
"valueFiles": {
"description": "ValuesFiles is a list of Helm value files to use when generating a template",
"items": {
"type": "string"
},
"type": "array"
},
"values": {
"description": "Values specifies Helm values to be passed to helm template, typically defined as a block. ValuesObject takes precedence over Values, so use one or the other.",
"type": "string"
},
"valuesObject": {
"description": "ValuesObject specifies Helm values to be passed to helm template, defined as a map. This takes precedence over Values.",
"type": "object",
"x-kubernetes-preserve-unknown-fields": true
},
"version": {
"description": "Version is the Helm version to use for templating (\"3\")",
"type": "string"
}
},
"type": "object"
},
"kustomize": {
"description": "Kustomize holds kustomize specific options",
"properties": {
"commonAnnotations": {
"additionalProperties": {
"type": "string"
},
"description": "CommonAnnotations is a list of additional annotations to add to rendered manifests",
"type": "object"
},
"commonAnnotationsEnvsubst": {
"description": "CommonAnnotationsEnvsubst specifies whether to apply env variables substitution for annotation values",
"type": "boolean"
},
"commonLabels": {
"additionalProperties": {
"type": "string"
},
"description": "CommonLabels is a list of additional labels to add to rendered manifests",
"type": "object"
},
"forceCommonAnnotations": {
"description": "ForceCommonAnnotations specifies whether to force applying common annotations to resources for Kustomize apps",
"type": "boolean"
},
"forceCommonLabels": {
"description": "ForceCommonLabels specifies whether to force applying common labels to resources for Kustomize apps",
"type": "boolean"
},
"images": {
"description": "Images is a list of Kustomize image override specifications",
"items": {
"description": "KustomizeImage represents a Kustomize image definition in the format [old_image_name=]<image_name>:<image_tag>",
"type": "string"
},
"type": "array"
},
"namePrefix": {
"description": "NamePrefix is a prefix appended to resources for Kustomize apps",
"type": "string"
},
"nameSuffix": {
"description": "NameSuffix is a suffix appended to resources for Kustomize apps",
"type": "string"
},
"namespace": {
"description": "Namespace sets the namespace that Kustomize adds to all resources",
"type": "string"
},
"replicas": {
"description": "Replicas is a list of Kustomize Replicas override specifications",
"items": {
"properties": {
"count": {
"anyOf": [
{
"type": "integer"
},
{
"type": "string"
}
],
"description": "Number of replicas",
"x-kubernetes-int-or-string": true
},
"name": {
"description": "Name of Deployment or StatefulSet",
"type": "string"
}
},
"required": [
"count",
"name"
],
"type": "object"
},
"type": "array"
},
"version": {
"description": "Version controls which version of Kustomize to use for rendering manifests",
"type": "string"
}
},
"type": "object"
},
"plugin": {
"description": "Plugin holds config management plugin specific options",
"properties": {
"env": {
"description": "Env is a list of environment variable entries",
"items": {
"description": "EnvEntry represents an entry in the application's environment",
"properties": {
"name": {
"description": "Name is the name of the variable, usually expressed in uppercase",
"type": "string"
},
"value": {
"description": "Value is the value of the variable",
"type": "string"
}
},
"required": [
"name",
"value"
],
"type": "object"
},
"type": "array"
},
"name": {
"type": "string"
},
"parameters": {
"items": {
"properties": {
"array": {
"description": "Array is the value of an array type parameter.",
"items": {
"type": "string"
},
"type": "array"
},
"map": {
"additionalProperties": {
"type": "string"
},
"description": "Map is the value of a map type parameter.",
"type": "object"
},
"name": {
"description": "Name is the name identifying a parameter.",
"type": "string"
},
"string": {
"description": "String_ is the value of a string type parameter.",
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
}
}
94 changes: 83 additions & 11 deletions branches.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/ghodss/yaml"
"github.com/pkg/errors"
@@ -144,19 +145,90 @@ func switchToCommitBranch(rc requestContext) (string, error) {
}
}

// Clean existing output paths
for appName, appConfig := range rc.target.branchConfig.AppConfigs {
var outputDir string
if appConfig.OutputPath != "" {
outputDir = filepath.Join(rc.repo.WorkingDir(), appConfig.OutputPath)
} else {
outputDir = filepath.Join(rc.repo.WorkingDir(), appName)
}
if err := os.RemoveAll(outputDir); err != nil {
return "", errors.Wrapf(err, "error deleting %q", outputDir)
}
// Clean the branch so we can replace its contents wholesale
if err := cleanCommitBranch(
rc.repo.WorkingDir(),
rc.target.branchConfig.PreservedPaths,
); err != nil {
return "", errors.Wrap(err, "error cleaning commit branch")
}
logger.Debug("cleaned commit branch")

return commitBranch, nil
}

// cleanCommitBranch deletes the entire contents of the specified directory
// EXCEPT for the paths specified by preservedPaths.
func cleanCommitBranch(dir string, preservedPaths []string) error {
_, err := cleanDir(
dir,
normalizePreservedPaths(
dir,
append(preservedPaths, ".git", ".kargo-render"),
),
)
return err
}

// normalizePreservedPaths converts the relative paths in the preservedPaths
// argument to absolute paths relative to the workingDir argument. It also
// removes any trailing path separators from the paths.
func normalizePreservedPaths(
workingDir string,
preservedPaths []string,
) []string {
normalizedPreservedPaths := make([]string, len(preservedPaths))
for i, preservedPath := range preservedPaths {
if strings.HasSuffix(preservedPath, string(os.PathSeparator)) {
preservedPath = preservedPath[:len(preservedPath)-1]
}
normalizedPreservedPaths[i] = filepath.Join(workingDir, preservedPath)
}
return normalizedPreservedPaths
}

// cleanDir recursively deletes the entire contents of the directory specified
// by the absolute path dir EXCEPT for any paths specified by the preservedPaths
// argument. The function returns true if dir is left empty afterwards and false
// otherwise.
func cleanDir(dir string, preservedPaths []string) (bool, error) {
items, err := os.ReadDir(dir)
if err != nil {
return false, err
}
for _, item := range items {
path := filepath.Join(dir, item.Name())
if isPathPreserved(path, preservedPaths) {
continue
}
if item.IsDir() {
var isEmpty bool
if isEmpty, err = cleanDir(path, preservedPaths); err != nil {
return false, err
}
if isEmpty {
if err = os.Remove(path); err != nil {
return false, err
}
}
} else if err = os.Remove(path); err != nil {
return false, err
}
}
if items, err = os.ReadDir(dir); err != nil {
return false, err
}
return len(items) == 0, nil
}

// isPathPreserved returns true if the specified path is among those specified
// by the preservedPaths argument. Both path and preservedPaths MUST be absolute
// paths. Paths to directories MUST NOT end with a trailing path separator.
func isPathPreserved(path string, preservedPaths []string) bool {
for _, preservedPath := range preservedPaths {
if path == preservedPath {
return true
}
}
return false
}
Loading

0 comments on commit 64c5e7e

Please sign in to comment.