Skip to content

Commit

Permalink
Merge pull request #335 from covexo/up-overwrite
Browse files Browse the repository at this point in the history
Up overwrite
  • Loading branch information
Lukas Gentele authored Oct 30, 2018
2 parents 3177a1b + 79e1036 commit cd245af
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 22 deletions.
2 changes: 1 addition & 1 deletion PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**What issue type does this pull request address?** (keep at least one, remove the others)
/kind bug
/king enhancement
/kind enhancement
/kind feature
/kind documentation

Expand Down
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (cmd *DeployCmd) Run(cobraCmd *cobra.Command, args []string) {
}

// Force deployment of all defined deployments
err = deploy.All(client, generatedConfig, true, log.GetInstance())
err = deploy.All(client, generatedConfig, true, false, log.GetInstance())
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
Name: configutil.String(configutil.DefaultDevspaceDeploymentName),
Namespace: configutil.String(""),
Helm: &v1.HelmConfig{
ChartPath: configutil.String("./chart"),
ChartPath: configutil.String("./chart"),
DevOverwrite: configutil.String("./chart/dev-overwrite.yaml"),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (cmd *UpCmd) buildAndDeploy() {
// Deploy all defined deployments
if config.DevSpace.Deployments != nil {
// Deploy all
err = deploy.All(cmd.kubectl, generatedConfig, mustRedeploy || cmd.flags.deploy, log.GetInstance())
err = deploy.All(cmd.kubectl, generatedConfig, mustRedeploy || cmd.flags.deploy, true, log.GetInstance())
if err != nil {
log.Fatal(err)
}
Expand Down
12 changes: 11 additions & 1 deletion docs/docs/configuration/config.yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ devSpace:
# For this deployment we use helm as deployment method (kubectl would be also an option)
helm:
chartPath: ./chart
devOverwrite: ./chart/dev-overwrite.yaml
sync:
- containerPath: /app
labelSelector:
release: devspace-default
localSubPath: ./
uploadExcludePaths:
- .devspace/
portForwarding:
- labelSelector:
release: devspace-default
portMappings:
- localPort: 3000
remotePort: 3000
images:
default:
name: mydockername/devspace
Expand All @@ -45,6 +52,7 @@ In this section, so called deployments are defined, which will be deployed to th
### devspace.deployments[].helm
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.
- `chartPath` *string* the path where the helm chart is laying
- `devOverwrite` *string* the path to a files that overwrites the values.yaml when using `devspace up`

### devspace.deployments[].kubectl
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.
Expand Down Expand Up @@ -186,7 +194,9 @@ devSpace:
- name: devspace-default # this is also the release name, when using helm as deployment method
helm:
# Use helm to deploy this chart
chartPath: chart/
chartPath: ./chart
# Overwrite the values.yaml with dev-values.yaml when running devspace up
devOverwrite: ./chart/dev-overwrite.yaml
- name: devspace-kubectl
kubectl:
manifests:
Expand Down
3 changes: 2 additions & 1 deletion pkg/devspace/config/v1/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ type DeploymentConfig struct {

// HelmConfig defines the specific helm options used during deployment
type HelmConfig struct {
ChartPath *string `yaml:"chartPath,omitempty"`
ChartPath *string `yaml:"chartPath,omitempty"`
DevOverwrite *string `yaml:"devOverwrite,omitempty"`
}

// KubectlConfig defines the specific kubectl options used during deployment
Expand Down
55 changes: 43 additions & 12 deletions pkg/devspace/deploy/helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helm

import (
"fmt"
"os"
"path/filepath"

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

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

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

err := yamlutil.ReadYamlFromFile(filepath.Join(chartPath, "values.yaml"), values)
valuesPath := filepath.Join(chartPath, "values.yaml")
err := yamlutil.ReadYamlFromFile(valuesPath, values)
if err != nil {
return fmt.Errorf("Couldn't deploy chart, error reading from chart values %s: %v", chartPath+"values.yaml", err)
return fmt.Errorf("Couldn't deploy chart, error reading from chart values %s: %v", valuesPath, err)
}

if useDevOverwrite && d.DeploymentConfig.Helm.DevOverwrite != nil {
workdir, workdirErr := os.Getwd()
if workdirErr != nil {
log.Fatalf("Unable to determine current workdir: %s", workdirErr.Error())
}

overwriteValuesPath := filepath.Join(workdir, *d.DeploymentConfig.Helm.DevOverwrite)
err := yamlutil.ReadYamlFromFile(overwriteValuesPath, overwriteValues)
if err != nil {
return fmt.Errorf("Couldn't deploy chart, error reading from chart dev overwrite values %s: %v", overwriteValuesPath, err)
}
}

overwriteContainerValues := map[interface{}]interface{}{}
overwriteContainerValuesFromFile, containerValuesExisting := overwriteValues["containers"]
if containerValuesExisting {
overwriteContainerValues = overwriteContainerValuesFromFile.(map[interface{}]interface{})
}

containerValues := map[string]interface{}{}
for imageName, imageConf := range *config.Images {
container := map[string]interface{}{}
container := map[interface{}]interface{}{}
existingContainer, containerExists := overwriteContainerValues[imageName]

if containerExists {
container = existingContainer.(map[interface{}]interface{})
}
container["image"] = registry.GetImageURL(generatedConfig, imageConf, true)

containerValues[imageName] = container
overwriteContainerValues[imageName] = container
}

overwritePullSecrets := []interface{}{}
overwritePullSecretsFromFile, overwritePullSecretsExisting := overwriteValues["pullSecrets"]
if overwritePullSecretsExisting {
overwritePullSecrets = overwritePullSecretsFromFile.([]interface{})
}

pullSecrets := []interface{}{}
existingPullSecrets, pullSecretsExisting := values["pullSecrets"]
pullSecretsFromFile, pullSecretsExisting := values["pullSecrets"]

if pullSecretsExisting {
pullSecrets = existingPullSecrets.([]interface{})
existingPullSecrets := pullSecretsFromFile.([]interface{})
overwritePullSecrets = append(overwritePullSecrets, existingPullSecrets...)
}

for _, registryConf := range *config.Registries {
if registryConf.URL != nil {
registrySecretName := registry.GetRegistryAuthSecretName(*registryConf.URL)
pullSecrets = append(pullSecrets, registrySecretName)
overwritePullSecrets = append(overwritePullSecrets, registrySecretName)
}
}

overwriteValues["containers"] = containerValues
overwriteValues["pullSecrets"] = pullSecrets
overwriteValues["containers"] = overwriteContainerValues
overwriteValues["pullSecrets"] = overwritePullSecrets

appRelease, err := helmClient.InstallChartByPath(releaseName, releaseNamespace, chartPath, &overwriteValues)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/devspace/deploy/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
type Interface interface {
Delete() error
Status() ([][]string, error)
Deploy(generatedConfig *generated.Config, forceDeploy bool) error
Deploy(generatedConfig *generated.Config, forceDeploy, useDevOverwrite bool) error
}
2 changes: 1 addition & 1 deletion pkg/devspace/deploy/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (d *DeployConfig) Delete() error {
}

// Deploy deploys all specified manifests via kubectl apply and adds to the specified image names the corresponding tags
func (d *DeployConfig) Deploy(generatedConfig *generated.Config, forceDeploy bool) error {
func (d *DeployConfig) Deploy(generatedConfig *generated.Config, forceDeploy, useDevOverwrite bool) error {
d.Log.StartWait("Loading manifests")
manifests, err := loadManifests(d.Manifests, d.Log)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/devspace/deploy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

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

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

err = deployClient.Deploy(generatedConfig, forceDeploy)
err = deployClient.Deploy(generatedConfig, forceDeploy, useDevOverwrite)
if err != nil {
return fmt.Errorf("Error deploying %s: %v", *deployConfig.Name, err)
}
Expand Down

0 comments on commit cd245af

Please sign in to comment.