From 26c2e74caeb8b47aeaaf884b447e68eb857fe686 Mon Sep 17 00:00:00 2001 From: Roman Prohonnyi Date: Mon, 19 Aug 2024 15:17:21 +0200 Subject: [PATCH] fixes, new tests, remote kubernetes manifest --- .vscode/settings.json | 1 + internal/project/scanners.go | 1 + internal/project/state.go | 4 -- internal/project/templating.go | 6 +- internal/units/shell/common/files.go | 2 +- internal/units/shell/common/state.go | 3 +- internal/units/shell/common/unit.go | 26 +++----- internal/units/shell/k8s_manifest/unit.go | 7 ++- internal/units/shell/terraform/helm/state.go | 4 +- .../units/shell/terraform/kubernetes/main.go | 45 ++++++++------ .../units/shell/terraform/kubernetes/state.go | 13 ++++ pkg/utils/files.go | 29 +++++++++ pkg/utils/net.go | 19 ++++++ pkg/utils/yaml.go | 4 +- tests/k8s/kube-helm/template.yaml | 33 ---------- tests/k8s/kube-helm/values/redis.yaml | 6 -- tests/k8s/stack.yaml | 4 +- .../k8s/{ => templates}/kube-helm/.cdevignore | 0 .../{ => templates}/kube-helm/deployment.yaml | 2 +- .../kube-helm/manifests-list/deploy.yaml | 23 +++++++ .../kube-helm/manifests-list/deployment.yml | 23 +++++++ .../kube-helm/manifests-list/not_deploy.ymls | 23 +++++++ tests/k8s/templates/kube-helm/template.yaml | 61 +++++++++++++++++++ .../k8s/templates/kube-helm/values/redis.yaml | 6 ++ tests/k8s/templates/out_of_tmpl_dir.yaml | 23 +++++++ 25 files changed, 276 insertions(+), 92 deletions(-) delete mode 100644 tests/k8s/kube-helm/template.yaml delete mode 100644 tests/k8s/kube-helm/values/redis.yaml rename tests/k8s/{ => templates}/kube-helm/.cdevignore (100%) rename tests/k8s/{ => templates}/kube-helm/deployment.yaml (81%) create mode 100644 tests/k8s/templates/kube-helm/manifests-list/deploy.yaml create mode 100644 tests/k8s/templates/kube-helm/manifests-list/deployment.yml create mode 100644 tests/k8s/templates/kube-helm/manifests-list/not_deploy.ymls create mode 100644 tests/k8s/templates/kube-helm/template.yaml create mode 100644 tests/k8s/templates/kube-helm/values/redis.yaml create mode 100644 tests/k8s/templates/out_of_tmpl_dir.yaml diff --git a/.vscode/settings.json b/.vscode/settings.json index 07fa0bba..76a003e7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -120,6 +120,7 @@ "subcommand", "submodules", "sysctl", + "templating", "testrepo", "tfmodule", "tfplan", diff --git a/internal/project/scanners.go b/internal/project/scanners.go index 9e428c55..4793c855 100644 --- a/internal/project/scanners.go +++ b/internal/project/scanners.go @@ -86,6 +86,7 @@ func StateOutputsReplacer(data reflect.Value, unit Unit) (reflect.Value, error) resString := subVal.String() markersList := unit.Project().UnitLinks.ByLinkTypes(OutputLinkType).Map() for key, marker := range markersList { + // log.Warnf("StateOutputsReplacer: %v", key) if strings.Contains(resString, key) { resString = strings.ReplaceAll(resString, key, fmt.Sprintf("", marker.TargetStackName, marker.TargetUnitName, marker.OutputName)) } diff --git a/internal/project/state.go b/internal/project/state.go index 533b28b1..6f41c70e 100644 --- a/internal/project/state.go +++ b/internal/project/state.go @@ -236,10 +236,6 @@ func (p *Project) LoadState() (*StateProject, error) { if err != nil { return nil, err } - for key := range statePrj.Units { - log.Warnf("LoadState %v", key) - } - return statePrj, nil } diff --git a/internal/project/templating.go b/internal/project/templating.go index bbcce76d..19de1494 100644 --- a/internal/project/templating.go +++ b/internal/project/templating.go @@ -175,9 +175,9 @@ func (d *GlobalTemplateDriver) AddTemplateFunctions(mp template.FuncMap, p *Proj addOutputMarkerFunk := func(path string) (string, error) { splittedPath := strings.Split(path, ".") - // if len(splittedPath) != 3 { - // return "", fmt.Errorf("bad dependency path 2") - // } + if len(splittedPath) == 2 { + splittedPath = append([]string{"this"}, splittedPath...) + } dep := ULinkT{ Unit: nil, diff --git a/internal/units/shell/common/files.go b/internal/units/shell/common/files.go index 87e4b436..97402fef 100644 --- a/internal/units/shell/common/files.go +++ b/internal/units/shell/common/files.go @@ -12,7 +12,7 @@ import ( "github.com/apex/log" ) -var fileSizeLimit int64 = 102400 +var fileSizeLimit int64 = 1024000 var ignorePatterns []string = []string{ ".*\\.terraform/.*", ".*\\.git/.*", diff --git a/internal/units/shell/common/state.go b/internal/units/shell/common/state.go index 2313d232..f7ef6a4d 100644 --- a/internal/units/shell/common/state.go +++ b/internal/units/shell/common/state.go @@ -56,10 +56,9 @@ func (u *Unit) GetUnitDiff() UnitDiffSpec { for _, file := range *u.CreateFiles { fileLines := strings.Split(file.Content, "\n") if len(fileLines) < 2 { - filesListDiff[file.FileName][0] = file.Content + filesListDiff[file.FileName] = append(filesListDiff[file.FileName], file.Content) } else { for _, line := range fileLines { - //log.Warnf("filesListDiff %v", line) if line == "" { continue // Ignore empty lines } diff --git a/internal/units/shell/common/unit.go b/internal/units/shell/common/unit.go index fbff3973..1202d8ff 100644 --- a/internal/units/shell/common/unit.go +++ b/internal/units/shell/common/unit.go @@ -28,11 +28,7 @@ type OperationConfig struct { Commands []interface{} `yaml:"commands" json:"commands"` } -type OutputsT struct { - List map[string]*project.ULinkT `json:"outputs_list,omitempty"` -} - -// OutputsConfigSpec describe how to retrive parse unit outputs. +// OutputsConfigSpec describe how to retrieve parse unit outputs. type OutputsConfigSpec struct { Command string `yaml:"command,omitempty" json:"command,omitempty"` Type string `yaml:"type" json:"type"` @@ -105,7 +101,7 @@ func (u *Unit) ForceApply() bool { return u.FApply } -// WasApplied return true if unit's method Apply was runned. +// WasApplied return true if unit's method Apply was ran. func (u *Unit) WasApplied() bool { return u.AlreadyApplied } @@ -314,8 +310,6 @@ func (u *Unit) Apply() error { err = parser(string(u.OutputRaw), u.ProjectPtr.UnitLinks.ByTargetUnit(u).ByLinkTypes(project.OutputLinkType)) if err != nil { - //str := fmt.Sprintf("Outputs data: %s", string(u.OutputRaw)) - // log.Warnf("Len: %v", len(str)) u.SetTainted(true, err) return fmt.Errorf("parse outputs '%v': %w", u.GetOutputsConf.Type, err) } @@ -327,14 +321,6 @@ func (u *Unit) Apply() error { return err } -// func (u *Unit) MarkTainted(err error) { -// u.ExecErr = err -// if u.SavedState != nil { -// u.SavedState.SetTainted(true) -// log.Warnf("MarkTainted %v", u.SavedState.IsTainted()) -// } -// } - func (u *Unit) runCommands(commandsCnf OperationConfig, name string) ([]byte, error) { if len(commandsCnf.Commands) == 0 { log.Debugf("configuration for '%v' is empty for unit '%v'. Skip.", name, u.Key()) @@ -439,7 +425,6 @@ func (u *Unit) UpdateProjectRuntimeData(p *project.Project) error { } func (u *Unit) ScanData(scanner project.MarkerScanner) error { - // log.Warnf("Replacing markers...") if u.Env != nil { err := project.ScanMarkers(u.Env, scanner, u) if err != nil { @@ -547,7 +532,7 @@ func readHook(hookData interface{}, hookType string) (*HookSpec, error) { cmd, cmdExists := hook["command"].(string) if !cmdExists { - return nil, fmt.Errorf("error in %s config, use 'script' option", hookType) + return nil, fmt.Errorf("error in %s config, 'command' option is required", hookType) } ScriptData := HookSpec{ @@ -586,14 +571,19 @@ func (u *Unit) EnvSlice() []string { return res } +// SetExecStatus set unit execution status (backlog, in progress, etc). func (u *Unit) SetExecStatus(status project.ExecutionStatus) { if u.GetExecStatus() != status { u.ExecStatus = status } } + +// GetExecStatus get current execution status. func (u *Unit) GetExecStatus() project.ExecutionStatus { return u.ExecStatus } + +// ExecError return last execution error func (u *Unit) ExecError() error { return u.ExecErr } diff --git a/internal/units/shell/k8s_manifest/unit.go b/internal/units/shell/k8s_manifest/unit.go index 24adb1f0..4d06ff17 100644 --- a/internal/units/shell/k8s_manifest/unit.go +++ b/internal/units/shell/k8s_manifest/unit.go @@ -123,7 +123,7 @@ func (u *Unit) ReadManifestsPath(src string) error { } if isDir { u.ManifestsFiles.ReadDir(manifestsPath, baseDir, `.ya{0,1}ml$`) - // log.Debugf("List %v", u.ManifestsFiles.SPrintLs()) + log.Debugf("List %v", u.ManifestsFiles.SPrintLs()) if u.ManifestsFiles.IsEmpty() { return fmt.Errorf("read unit '%v': no manifests found in path %v", u.Name(), u.Path) } @@ -139,7 +139,7 @@ func (u *Unit) ReadManifestsPath(src string) error { } else { manifest, err := utils.GetFileByUrl(src) if err != nil { - return fmt.Errorf("get remote file: %w", err) + return fmt.Errorf("get remote file by url (%v): %w", src, err) } err = u.ManifestsFiles.AddOverride("./main.yaml", manifest, fs.ModePerm) if err != nil { @@ -215,6 +215,9 @@ func (u *Unit) GetManifestsMap() (res map[string]interface{}, namespaces []strin res = make(map[string]interface{}) namespaces = []string{} nsUniq := map[string]bool{} + if u == nil { + return + } for _, file := range *u.ManifestsFiles { mns, err := utils.ReadYAMLObjects([]byte(file.Content)) if err != nil { diff --git a/internal/units/shell/terraform/helm/state.go b/internal/units/shell/terraform/helm/state.go index 8eb06f40..49f27544 100644 --- a/internal/units/shell/terraform/helm/state.go +++ b/internal/units/shell/terraform/helm/state.go @@ -43,16 +43,15 @@ func (u *Unit) GetUnitDiff() UnitDiffSpec { Source: u.Source, HelmOpts: u.HelmOpts, Sets: u.Sets, - // Values: u.ValuesFilesList, } filesListDiff := make([]interface{}, len(u.ValuesFilesList)) + st.Outputs = nil for i, str := range u.ValuesFilesList { fileLines := strings.Split(str, "\n") if len(fileLines) < 2 { filesListDiff[i] = str } else { for _, line := range fileLines { - //log.Warnf("filesListDiff %v", line) if line == "" { continue // Ignore empty lines } @@ -69,6 +68,7 @@ func (u *Unit) GetDiffData() interface{} { res := map[string]interface{}{} utils.JSONCopy(st, &res) project.ScanMarkers(res, base.StringRemStScanner, u) + project.ScanMarkers(res, project.OutputsReplacer, u) return res } diff --git a/internal/units/shell/terraform/kubernetes/main.go b/internal/units/shell/terraform/kubernetes/main.go index 6b003ca7..442aa7ef 100644 --- a/internal/units/shell/terraform/kubernetes/main.go +++ b/internal/units/shell/terraform/kubernetes/main.go @@ -9,6 +9,7 @@ import ( "github.com/apex/log" "github.com/hashicorp/hcl/v2/hclwrite" + "github.com/shalb/cluster.dev/internal/config" "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" "github.com/shalb/cluster.dev/pkg/hcltools" @@ -71,30 +72,40 @@ func (u *Unit) ReadConfig(spec map[string]interface{}, stack *project.Stack) err if !ok { return fmt.Errorf("reading kubernetes unit '%v': malformed unit source", u.Key()) } - tmplDir := u.Stack().TemplateDir var absSource string - if source[1:2] == "/" { - absSource = filepath.Join(tmplDir, source) - } else { - absSource = source - } - fileInfo, err := os.Stat(absSource) - if err != nil { - return fmt.Errorf("reading kubernetes unit '%v': reading kubernetes manifests form source '%v': %v", u.Key(), source, err.Error()) - } var filesList []string - if fileInfo.IsDir() { - filesList, err = filepath.Glob(absSource + "/*.yaml") + if utils.IsLocalPath(source) { + if utils.IsAbsolutePath(source) { + absSource = source + } else { + absSource = filepath.Join(config.Global.ProjectConfigsPath, u.Stack().TemplateDir, source) + } + + fileInfo, err := os.Stat(absSource) if err != nil { - return fmt.Errorf("reading kubernetes unit '%v': reading kubernetes manifests form source '%v': %v", u.Key(), source, err.Error()) + return fmt.Errorf("reading kubernetes unit '%v': check file: '%v': %v", u.Key(), source, err.Error()) + } + if fileInfo.IsDir() { + filesList, err = utils.ListFilesByRegex(absSource, `\.ya{0,1}ml$`) //filepath.Glob(absSource + "/*.yaml") + if err != nil { + return fmt.Errorf("reading kubernetes unit '%v': list manifests in dir '%v': %v", u.Key(), source, err.Error()) + } + } else { + filesList = append(filesList, absSource) } } else { - filesList = append(filesList, absSource) + filesList = append(filesList, source) } for _, fileName := range filesList { - file, err := os.ReadFile(fileName) + var file []byte + var err error + if utils.IsLocalPath(fileName) { + file, err = os.ReadFile(fileName) + } else { + file, err = utils.GetFileByUrlByte(fileName) + } if err != nil { - return fmt.Errorf("reading kubernetes unit '%v': reading kubernetes manifests form source '%v': %v", u.Key(), source, err.Error()) + return fmt.Errorf("reading kubernetes unit '%v': read manifest from '%v': %v", u.Key(), source, err.Error()) } manifest, errIsWarn, err := u.Stack().TemplateTry(file, fileName) if err != nil { @@ -119,7 +130,7 @@ func (u *Unit) ReadConfig(spec map[string]interface{}, stack *project.Stack) err return fmt.Errorf("the kubernetes unit must contain at least one manifest") } - err = utils.YAMLInterfaceToType(spec, u) + err := utils.YAMLInterfaceToType(spec, u) if err != nil { return err } diff --git a/internal/units/shell/terraform/kubernetes/state.go b/internal/units/shell/terraform/kubernetes/state.go index 62322416..968260d2 100644 --- a/internal/units/shell/terraform/kubernetes/state.go +++ b/internal/units/shell/terraform/kubernetes/state.go @@ -18,13 +18,21 @@ func (u *Unit) GetStateUnit() *Unit { log.Fatalf("read unit '%v': create state: %w", u.Name(), err) } unitState.Unit = *u.Unit.GetStateUnit() + // unitState.GetOutputsConf = nil return &unitState } +func printStateDebug(state interface{}, comment string) { + js, _ := utils.JSONEncodeString(state) + log.Warnf("printStateDebug [%v]: %v", comment, js) +} + func (u *Unit) GetState() project.Unit { if u.StateData != nil { + // printStateDebug(u.StateData, "GetState") return u.StateData } + // printStateDebug(u.GetStateUnit(), "GetState") return u.GetStateUnit() } @@ -47,8 +55,10 @@ func (u *Unit) GetUnitDiff() UnitDiffSpec { func (u *Unit) GetDiffData() interface{} { st := u.GetUnitDiff() res := map[string]interface{}{} + st.Outputs = nil utils.JSONCopy(st, &res) project.ScanMarkers(res, base.StringRemStScanner, u) + // printStateDebug(res, "GetDiffData") return res } @@ -61,5 +71,8 @@ func (u *Unit) LoadState(stateData interface{}, modKey string, p *project.StateP if err != nil { return fmt.Errorf("load state: %v", err.Error()) } + // u.GetState() + // u.GetDiffData() + u.GetOutputsConf = nil return nil } diff --git a/pkg/utils/files.go b/pkg/utils/files.go index 171fb061..0db1b63d 100644 --- a/pkg/utils/files.go +++ b/pkg/utils/files.go @@ -240,3 +240,32 @@ func RemoveDirContent(dir string) error { } return nil } + +func ListFilesByRegex(dirPath, pattern string) ([]string, error) { + re, err := regexp.Compile(pattern) + if err != nil { + return nil, fmt.Errorf("invalid regex pattern: %s", err) + } + + var matches []string + err = filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if info.IsDir() { + return nil + } + + if re.MatchString(info.Name()) { + matches = append(matches, path) + } + return nil + }) + + if err != nil { + return nil, fmt.Errorf("error walking directory: %s", err) + } + + return matches, nil +} diff --git a/pkg/utils/net.go b/pkg/utils/net.go index dadb7fe8..20166cdc 100644 --- a/pkg/utils/net.go +++ b/pkg/utils/net.go @@ -1,6 +1,8 @@ package utils import ( + "bytes" + "errors" "fmt" "io" "math/big" @@ -60,3 +62,20 @@ func GetFileByUrl(srcUrl string) (string, error) { return buf.String(), nil } + +func GetFileByUrlByte(URL string) ([]byte, error) { + response, err := http.Get(URL) + if err != nil { + return nil, err + } + defer response.Body.Close() + if response.StatusCode != http.StatusOK { + return nil, errors.New(response.Status) + } + var data bytes.Buffer + _, err = io.Copy(&data, response.Body) + if err != nil { + return nil, err + } + return data.Bytes(), nil +} diff --git a/pkg/utils/yaml.go b/pkg/utils/yaml.go index ab097f59..b4d38b26 100644 --- a/pkg/utils/yaml.go +++ b/pkg/utils/yaml.go @@ -20,7 +20,9 @@ func ReadYAMLObjects(objData []byte) ([]map[string]interface{}, error) { // log.Debugf("can't decode config to yaml: %s", err.Error()) return nil, fmt.Errorf("can't decode config to yaml: %s", ResolveYamlError(objData, err)) } - objects = append(objects, parsedConf) + if len(parsedConf) > 0 { // Ignore empty yaml parts, like two '---' with only comment between. + objects = append(objects, parsedConf) + } } return objects, nil } diff --git a/tests/k8s/kube-helm/template.yaml b/tests/k8s/kube-helm/template.yaml deleted file mode 100644 index 08ebb680..00000000 --- a/tests/k8s/kube-helm/template.yaml +++ /dev/null @@ -1,33 +0,0 @@ -_p: &provider_aws -- aws: - region: {{ .variables.region }} - -name: k8s-helm -kind: StackTemplate -cliVersion: "~>0.9.2" -units: - - - name: redis - type: helm - source: - repository: "https://charts.bitnami.com/bitnami" - chart: "redis" - version: "19.5.5" - provider_conf: {{ insertYAML .variables.k8s_conf }} - additional_options: - namespace: default - create_namespace: true - values: - - file: ./values/redis.yaml - apply_template: true - - - name: cert-manager-issuer - type: kubernetes - source: ./deployment.yaml - provider_conf: {{ insertYAML .variables.k8s_conf }} - - - name: outputs - type: printer - outputs: - new_output: "test2" - diff --git a/tests/k8s/kube-helm/values/redis.yaml b/tests/k8s/kube-helm/values/redis.yaml deleted file mode 100644 index adf40ee8..00000000 --- a/tests/k8s/kube-helm/values/redis.yaml +++ /dev/null @@ -1,6 +0,0 @@ - -architecture: standalone -fullnameOverride: {{ .variables.consul.name_override | default "redis" }} -auth: - enabled: false - sentinel: false diff --git a/tests/k8s/stack.yaml b/tests/k8s/stack.yaml index a47c1cfb..bf3bb84c 100644 --- a/tests/k8s/stack.yaml +++ b/tests/k8s/stack.yaml @@ -1,12 +1,12 @@ name: kube-helm -template: ./kube-helm/ +template: ./templates/kube-helm/ kind: Stack disabled: false backend: default variables: k8s_conf: config_path: {{ reqEnv "KUBECONFIG" }} - config_context: {{ reqEnv "KUBE_CONTEXT" }} + config_context: default # {{ env "KUBE_CONTEXT" }} consul: name_override: renamed-redis nginx: diff --git a/tests/k8s/kube-helm/.cdevignore b/tests/k8s/templates/kube-helm/.cdevignore similarity index 100% rename from tests/k8s/kube-helm/.cdevignore rename to tests/k8s/templates/kube-helm/.cdevignore diff --git a/tests/k8s/kube-helm/deployment.yaml b/tests/k8s/templates/kube-helm/deployment.yaml similarity index 81% rename from tests/k8s/kube-helm/deployment.yaml rename to tests/k8s/templates/kube-helm/deployment.yaml index 3ae75af3..9ac5efae 100644 --- a/tests/k8s/kube-helm/deployment.yaml +++ b/tests/k8s/templates/kube-helm/deployment.yaml @@ -1,7 +1,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ .variables.nginx.name_override | default "nginx-deployment" }} + name: {{ .variables.nginx.name_override | default "nginx-depl" }} labels: app: nginx spec: diff --git a/tests/k8s/templates/kube-helm/manifests-list/deploy.yaml b/tests/k8s/templates/kube-helm/manifests-list/deploy.yaml new file mode 100644 index 00000000..b4c17f6a --- /dev/null +++ b/tests/k8s/templates/kube-helm/manifests-list/deploy.yaml @@ -0,0 +1,23 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: "nginx-deployment-tree" + namespace: default + annotations: + app: nginx-tree + remoteState: {{ remoteState "this.print-test-value.one" }} +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 diff --git a/tests/k8s/templates/kube-helm/manifests-list/deployment.yml b/tests/k8s/templates/kube-helm/manifests-list/deployment.yml new file mode 100644 index 00000000..a511205b --- /dev/null +++ b/tests/k8s/templates/kube-helm/manifests-list/deployment.yml @@ -0,0 +1,23 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: "nginx-deployment-two" + namespace: default + annotations: + app: nginx-two + remoteState: {{ remoteState "this.print-test-value.one" }} +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 diff --git a/tests/k8s/templates/kube-helm/manifests-list/not_deploy.ymls b/tests/k8s/templates/kube-helm/manifests-list/not_deploy.ymls new file mode 100644 index 00000000..b3ff359c --- /dev/null +++ b/tests/k8s/templates/kube-helm/manifests-list/not_deploy.ymls @@ -0,0 +1,23 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: "nginx-deployment-tree" + namespace: default + annotations: + app: nginx-tree + remoteState: {{ remoteState "this.print-test-value.one" }} +pec: # error, should nod be deployed + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 diff --git a/tests/k8s/templates/kube-helm/template.yaml b/tests/k8s/templates/kube-helm/template.yaml new file mode 100644 index 00000000..10b428a2 --- /dev/null +++ b/tests/k8s/templates/kube-helm/template.yaml @@ -0,0 +1,61 @@ +_p: &provider_aws +- aws: + region: {{ .variables.region }} + +name: k8s-helm +kind: StackTemplate +cliVersion: "~>0.9.2" +units: + - + name: print-test-value + type: printer + outputs: + one: "test2" + two: + two1: "foo" + two2: "bar" + - + name: redis + type: helm + source: + repository: "https://charts.bitnami.com/bitnami" + chart: "redis" + version: "19.5.5" + provider_conf: {{ insertYAML .variables.k8s_conf }} + additional_options: + namespace: default + create_namespace: true + values: + - file: ./values/redis.yaml + apply_template: true + - + name: test-deployment + type: kubernetes + source: ./deployment.yaml + provider_conf: {{ insertYAML .variables.k8s_conf }} + - + name: out-of-dir + type: kubernetes + source: ../out_of_tmpl_dir.yaml + provider_conf: {{ insertYAML .variables.k8s_conf }} + - + name: remote-manifest1 + type: kubernetes + source: https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/deployments/multus-daemonset-thick.yml + provider_conf: {{ insertYAML .variables.k8s_conf }} + - + name: list + type: kubernetes + source: ./manifests-list/ + post_hook: + command: | + sleep 5 + kubectl rollout status deployment/nginx-deployment-tree -n default --timeout 30s + kubectl rollout status deployment/nginx-deployment-two -n default --timeout 30s + provider_conf: {{ insertYAML .variables.k8s_conf }} + + - + name: outputs + type: printer + outputs: + new_output: "test2" diff --git a/tests/k8s/templates/kube-helm/values/redis.yaml b/tests/k8s/templates/kube-helm/values/redis.yaml new file mode 100644 index 00000000..a66fcc08 --- /dev/null +++ b/tests/k8s/templates/kube-helm/values/redis.yaml @@ -0,0 +1,6 @@ + +architecture: standalone +fullnameOverride: {{ .variables.redis.name_override | default "redis" }} +auth: + enabled: false + sentinel: false diff --git a/tests/k8s/templates/out_of_tmpl_dir.yaml b/tests/k8s/templates/out_of_tmpl_dir.yaml new file mode 100644 index 00000000..8f3f62a0 --- /dev/null +++ b/tests/k8s/templates/out_of_tmpl_dir.yaml @@ -0,0 +1,23 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: "nginx-deployment-four" + namespace: default + annotations: + app: nginx-tree + remoteState: {{ remoteState "this.print-test-value.one" }} +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80