Skip to content

Commit

Permalink
Merge pull request #2143 from FabianKramm/print-feat
Browse files Browse the repository at this point in the history
feat: allow profiles & hooks in imports
  • Loading branch information
FabianKramm authored Jun 29, 2022
2 parents 7880d00 + 38b0cb8 commit 0ba1640
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions e2e/tests/imports/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var _ = DevSpaceDescribe("imports", func() {
GlobalFlags: &flags.GlobalFlags{
NoWarn: true,
Namespace: ns,
Profiles: []string{"my-profile"},
},
Pipeline: "deploy",
}
Expand All @@ -69,6 +70,7 @@ var _ = DevSpaceDescribe("imports", func() {
framework.ExpectLocalFileContentsWithoutSpaces("import3.txt", "import3")
framework.ExpectLocalFileContentsWithoutSpaces("import4.txt", "import4")
framework.ExpectLocalFileContentsWithoutSpaces("import5.txt", "import5")
framework.ExpectLocalFileContentsWithoutSpaces("profile_import.txt", "PROFILE_TEST")
framework.ExpectLocalFileContentsWithoutSpaces("vars.txt", ns+"-"+ns+"-base-import1-import2-import3")
framework.ExpectLocalFileContentsWithoutSpaces("top.txt", "top")

Expand Down
2 changes: 2 additions & 0 deletions e2e/tests/imports/testdata/local/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: base

imports:
- path: import1.yaml
- path: profile_import.yaml
- enabled: $(is_equal ${BASE} "base")
path: import2.yaml
- enabled: $(is_equal ${IMPORT1} "import1")
Expand Down Expand Up @@ -33,4 +34,5 @@ pipelines:
run_pipelines import4 > import4.txt
run_pipelines import5 > import5.txt
echo ${PROFILE_TEST} > profile_import.txt
echo ${DEVSPACE_NAMESPACE}-${devspace.namespace}-${BASE}-${IMPORT1}-${IMPORT2}-${IMPORT3} > vars.txt
8 changes: 8 additions & 0 deletions e2e/tests/imports/testdata/local/profile_import.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: v2beta1
name: profile-import

profiles:
- name: my-profile
merge:
vars:
PROFILE_TEST: "PROFILE_TEST"
15 changes: 15 additions & 0 deletions pkg/devspace/config/loader/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var ImportSections = []string{
"functions",
"pullSecrets",
"dependencies",
"profiles",
"hooks",
}

func ResolveImports(ctx context.Context, resolver variable.Resolver, basePath string, rawData map[string]interface{}, log log.Logger) (map[string]interface{}, error) {
Expand Down Expand Up @@ -94,6 +96,19 @@ func ResolveImports(ctx context.Context, resolver variable.Resolver, basePath st
for _, section := range ImportSections {
sectionMap, ok := importData[section].(map[string]interface{})
if !ok {
// no map, is it a slice?
sectionSlice, ok := importData[section].([]interface{})
if !ok {
continue
}

// make sure the section exists
if mergedMap[section] == nil {
mergedMap[section] = []interface{}{}
}
for _, value := range sectionSlice {
mergedMap[section] = append(mergedMap[section].([]interface{}), value)
}
continue
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/devspace/deploy/deployer/kubectl/kubectl.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kubectl

import (
"bytes"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -179,9 +180,11 @@ func (d *DeployConfig) Deploy(ctx devspacecontext.Context, _ bool) (bool, error)
if shouldRedeploy || forceDeploy {
args := d.getCmdArgs("apply", "--force")
args = append(args, d.DeploymentConfig.Kubectl.ApplyArgs...)
err = command.Command(ctx.Context(), ctx.WorkingDir(), writer, writer, strings.NewReader(replacedManifest), d.CmdPath, args...)

stdErrBuffer := &bytes.Buffer{}
err = command.Command(ctx.Context(), ctx.WorkingDir(), writer, io.MultiWriter(writer, stdErrBuffer), strings.NewReader(replacedManifest), d.CmdPath, args...)
if err != nil {
return false, errors.Errorf("%v\nPlease make sure the command `kubectl apply` does work locally with manifest `%s`", err, manifest)
return false, errors.Errorf("%v %v\nPlease make sure the command `kubectl apply` does work locally with manifest `%s`", stdErrBuffer.String(), err, manifest)
}

wasDeployed = true
Expand Down

0 comments on commit 0ba1640

Please sign in to comment.