Skip to content

Commit cd245af

Browse files
author
Lukas Gentele
authored
Merge pull request #335 from covexo/up-overwrite
Up overwrite
2 parents 3177a1b + 79e1036 commit cd245af

File tree

10 files changed

+65
-22
lines changed

10 files changed

+65
-22
lines changed

PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
**What issue type does this pull request address?** (keep at least one, remove the others)
22
/kind bug
3-
/king enhancement
3+
/kind enhancement
44
/kind feature
55
/kind documentation
66

cmd/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (cmd *DeployCmd) Run(cobraCmd *cobra.Command, args []string) {
107107
}
108108

109109
// Force deployment of all defined deployments
110-
err = deploy.All(client, generatedConfig, true, log.GetInstance())
110+
err = deploy.All(client, generatedConfig, true, false, log.GetInstance())
111111
if err != nil {
112112
log.Fatal(err)
113113
}

cmd/init.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
128128
Name: configutil.String(configutil.DefaultDevspaceDeploymentName),
129129
Namespace: configutil.String(""),
130130
Helm: &v1.HelmConfig{
131-
ChartPath: configutil.String("./chart"),
131+
ChartPath: configutil.String("./chart"),
132+
DevOverwrite: configutil.String("./chart/dev-overwrite.yaml"),
132133
},
133134
},
134135
}

cmd/up.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (cmd *UpCmd) buildAndDeploy() {
182182
// Deploy all defined deployments
183183
if config.DevSpace.Deployments != nil {
184184
// Deploy all
185-
err = deploy.All(cmd.kubectl, generatedConfig, mustRedeploy || cmd.flags.deploy, log.GetInstance())
185+
err = deploy.All(cmd.kubectl, generatedConfig, mustRedeploy || cmd.flags.deploy, true, log.GetInstance())
186186
if err != nil {
187187
log.Fatal(err)
188188
}

docs/docs/configuration/config.yaml.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ devSpace:
1414
# For this deployment we use helm as deployment method (kubectl would be also an option)
1515
helm:
1616
chartPath: ./chart
17+
devOverwrite: ./chart/dev-overwrite.yaml
1718
sync:
1819
- containerPath: /app
1920
labelSelector:
2021
release: devspace-default
2122
localSubPath: ./
2223
uploadExcludePaths:
2324
- .devspace/
25+
portForwarding:
26+
- labelSelector:
27+
release: devspace-default
28+
portMappings:
29+
- localPort: 3000
30+
remotePort: 3000
2431
images:
2532
default:
2633
name: mydockername/devspace
@@ -45,6 +52,7 @@ In this section, so called deployments are defined, which will be deployed to th
4552
### devspace.deployments[].helm
4653
When specifying helm as deployment method, `devspace up` will deploy the specified chart in the target cluster. If no tiller server is found, it will also attempt to deploy a tiller server.
4754
- `chartPath` *string* the path where the helm chart is laying
55+
- `devOverwrite` *string* the path to a files that overwrites the values.yaml when using `devspace up`
4856

4957
### devspace.deployments[].kubectl
5058
When using kubectl as deployment method, `devspace up` will use kubectl apply on the specified manifests to deploy them to the target cluster. [Kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl) is needed in order for this option to work.
@@ -186,7 +194,9 @@ devSpace:
186194
- name: devspace-default # this is also the release name, when using helm as deployment method
187195
helm:
188196
# Use helm to deploy this chart
189-
chartPath: chart/
197+
chartPath: ./chart
198+
# Overwrite the values.yaml with dev-values.yaml when running devspace up
199+
devOverwrite: ./chart/dev-overwrite.yaml
190200
- name: devspace-kubectl
191201
kubectl:
192202
manifests:

pkg/devspace/config/v1/deployments.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ type DeploymentConfig struct {
1010

1111
// HelmConfig defines the specific helm options used during deployment
1212
type HelmConfig struct {
13-
ChartPath *string `yaml:"chartPath,omitempty"`
13+
ChartPath *string `yaml:"chartPath,omitempty"`
14+
DevOverwrite *string `yaml:"devOverwrite,omitempty"`
1415
}
1516

1617
// KubectlConfig defines the specific kubectl options used during deployment

pkg/devspace/deploy/helm/client.go

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package helm
22

33
import (
44
"fmt"
5+
"os"
56
"path/filepath"
67

78
"github.com/covexo/devspace/pkg/devspace/config/configutil"
@@ -124,7 +125,7 @@ func (d *DeployConfig) Status() ([][]string, error) {
124125
}
125126

126127
// Deploy deploys the given deployment with helm
127-
func (d *DeployConfig) Deploy(generatedConfig *generated.Config, forceDeploy bool) error {
128+
func (d *DeployConfig) Deploy(generatedConfig *generated.Config, forceDeploy, useDevOverwrite bool) error {
128129
config := configutil.GetConfig()
129130

130131
releaseName := *d.DeploymentConfig.Name
@@ -170,35 +171,65 @@ func (d *DeployConfig) Deploy(generatedConfig *generated.Config, forceDeploy boo
170171
values := map[interface{}]interface{}{}
171172
overwriteValues := map[interface{}]interface{}{}
172173

173-
err := yamlutil.ReadYamlFromFile(filepath.Join(chartPath, "values.yaml"), values)
174+
valuesPath := filepath.Join(chartPath, "values.yaml")
175+
err := yamlutil.ReadYamlFromFile(valuesPath, values)
174176
if err != nil {
175-
return fmt.Errorf("Couldn't deploy chart, error reading from chart values %s: %v", chartPath+"values.yaml", err)
177+
return fmt.Errorf("Couldn't deploy chart, error reading from chart values %s: %v", valuesPath, err)
178+
}
179+
180+
if useDevOverwrite && d.DeploymentConfig.Helm.DevOverwrite != nil {
181+
workdir, workdirErr := os.Getwd()
182+
if workdirErr != nil {
183+
log.Fatalf("Unable to determine current workdir: %s", workdirErr.Error())
184+
}
185+
186+
overwriteValuesPath := filepath.Join(workdir, *d.DeploymentConfig.Helm.DevOverwrite)
187+
err := yamlutil.ReadYamlFromFile(overwriteValuesPath, overwriteValues)
188+
if err != nil {
189+
return fmt.Errorf("Couldn't deploy chart, error reading from chart dev overwrite values %s: %v", overwriteValuesPath, err)
190+
}
191+
}
192+
193+
overwriteContainerValues := map[interface{}]interface{}{}
194+
overwriteContainerValuesFromFile, containerValuesExisting := overwriteValues["containers"]
195+
if containerValuesExisting {
196+
overwriteContainerValues = overwriteContainerValuesFromFile.(map[interface{}]interface{})
176197
}
177198

178-
containerValues := map[string]interface{}{}
179199
for imageName, imageConf := range *config.Images {
180-
container := map[string]interface{}{}
200+
container := map[interface{}]interface{}{}
201+
existingContainer, containerExists := overwriteContainerValues[imageName]
202+
203+
if containerExists {
204+
container = existingContainer.(map[interface{}]interface{})
205+
}
181206
container["image"] = registry.GetImageURL(generatedConfig, imageConf, true)
182207

183-
containerValues[imageName] = container
208+
overwriteContainerValues[imageName] = container
209+
}
210+
211+
overwritePullSecrets := []interface{}{}
212+
overwritePullSecretsFromFile, overwritePullSecretsExisting := overwriteValues["pullSecrets"]
213+
if overwritePullSecretsExisting {
214+
overwritePullSecrets = overwritePullSecretsFromFile.([]interface{})
184215
}
185216

186-
pullSecrets := []interface{}{}
187-
existingPullSecrets, pullSecretsExisting := values["pullSecrets"]
217+
pullSecretsFromFile, pullSecretsExisting := values["pullSecrets"]
188218

189219
if pullSecretsExisting {
190-
pullSecrets = existingPullSecrets.([]interface{})
220+
existingPullSecrets := pullSecretsFromFile.([]interface{})
221+
overwritePullSecrets = append(overwritePullSecrets, existingPullSecrets...)
191222
}
192223

193224
for _, registryConf := range *config.Registries {
194225
if registryConf.URL != nil {
195226
registrySecretName := registry.GetRegistryAuthSecretName(*registryConf.URL)
196-
pullSecrets = append(pullSecrets, registrySecretName)
227+
overwritePullSecrets = append(overwritePullSecrets, registrySecretName)
197228
}
198229
}
199230

200-
overwriteValues["containers"] = containerValues
201-
overwriteValues["pullSecrets"] = pullSecrets
231+
overwriteValues["containers"] = overwriteContainerValues
232+
overwriteValues["pullSecrets"] = overwritePullSecrets
202233

203234
appRelease, err := helmClient.InstallChartByPath(releaseName, releaseNamespace, chartPath, &overwriteValues)
204235
if err != nil {

pkg/devspace/deploy/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ import (
88
type Interface interface {
99
Delete() error
1010
Status() ([][]string, error)
11-
Deploy(generatedConfig *generated.Config, forceDeploy bool) error
11+
Deploy(generatedConfig *generated.Config, forceDeploy, useDevOverwrite bool) error
1212
}

pkg/devspace/deploy/kubectl/kubectl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (d *DeployConfig) Delete() error {
102102
}
103103

104104
// Deploy deploys all specified manifests via kubectl apply and adds to the specified image names the corresponding tags
105-
func (d *DeployConfig) Deploy(generatedConfig *generated.Config, forceDeploy bool) error {
105+
func (d *DeployConfig) Deploy(generatedConfig *generated.Config, forceDeploy, useDevOverwrite bool) error {
106106
d.Log.StartWait("Loading manifests")
107107
manifests, err := loadManifests(d.Manifests, d.Log)
108108
if err != nil {

pkg/devspace/deploy/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
// All deploys all deployments in the config
15-
func All(client *kubernetes.Clientset, generatedConfig *generated.Config, forceDeploy bool, log log.Logger) error {
15+
func All(client *kubernetes.Clientset, generatedConfig *generated.Config, forceDeploy, useDevOverwrite bool, log log.Logger) error {
1616
config := configutil.GetConfig()
1717

1818
for _, deployConfig := range *config.DevSpace.Deployments {
@@ -37,7 +37,7 @@ func All(client *kubernetes.Clientset, generatedConfig *generated.Config, forceD
3737
return fmt.Errorf("Error deploying devspace: deployment %s has no deployment method", *deployConfig.Name)
3838
}
3939

40-
err = deployClient.Deploy(generatedConfig, forceDeploy)
40+
err = deployClient.Deploy(generatedConfig, forceDeploy, useDevOverwrite)
4141
if err != nil {
4242
return fmt.Errorf("Error deploying %s: %v", *deployConfig.Name, err)
4343
}

0 commit comments

Comments
 (0)