Skip to content

Commit e909b4f

Browse files
authored
Merge pull request #2244 from lizardruss/fix-dependency-redeploy
fix: use chart directory to detect chart changes
2 parents ff15f7e + 9aca70f commit e909b4f

6 files changed

Lines changed: 63 additions & 11 deletions

File tree

pkg/devspace/dependency/util/util.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ func init() {
3636
// downloadMutex makes sure we only download a single dependency at a time
3737
var downloadMutex = sync.Mutex{}
3838

39+
func GetDependencyPath(workingDirectory string, source *latest.SourceConfig) (configPath string, err error) {
40+
ID, err := GetDependencyID(source)
41+
if err != nil {
42+
return "", err
43+
}
44+
45+
// Resolve source
46+
var localPath string
47+
if source.Git != "" {
48+
localPath = filepath.Join(DependencyFolderPath, ID)
49+
} else if source.Path != "" {
50+
if isURL(source.Path) {
51+
localPath = filepath.Join(DependencyFolderPath, ID)
52+
} else {
53+
if filepath.IsAbs(source.Path) {
54+
localPath = source.Path
55+
} else {
56+
localPath, err = filepath.Abs(filepath.Join(workingDirectory, filepath.FromSlash(source.Path)))
57+
if err != nil {
58+
return "", errors.Wrap(err, "filepath absolute")
59+
}
60+
}
61+
}
62+
}
63+
64+
return getDependencyConfigPath(localPath, source)
65+
}
66+
3967
func DownloadDependency(ctx context.Context, workingDirectory string, source *latest.SourceConfig, log log.Logger) (configPath string, err error) {
4068
downloadMutex.Lock()
4169
defer downloadMutex.Unlock()

pkg/devspace/deploy/deployer/helm/deploy.go

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

33
import (
44
"fmt"
5-
"github.com/loft-sh/devspace/pkg/devspace/config/versions"
65
"io"
76
"os"
87
"path/filepath"
98

9+
"github.com/loft-sh/devspace/pkg/devspace/config/versions"
10+
1011
"github.com/loft-sh/devspace/pkg/devspace/config/loader/variable/legacy"
1112
runtimevar "github.com/loft-sh/devspace/pkg/devspace/config/loader/variable/runtime"
1213
"github.com/loft-sh/devspace/pkg/devspace/config/remotecache"
@@ -44,13 +45,24 @@ func (d *DeployConfig) Deploy(ctx devspacecontext.Context, forceDeploy bool) (bo
4445
releaseNamespace = d.DeploymentConfig.Namespace
4546
}
4647

48+
if d.DeploymentConfig.Helm.Chart.Source != nil {
49+
downloadPath, err := d.Helm.DownloadChart(ctx, d.DeploymentConfig.Helm)
50+
if err != nil {
51+
return false, errors.Wrap(err, "download chart")
52+
}
53+
chartPath = downloadPath
54+
}
55+
4756
// Hash the chart directory if there is any
4857
_, err := os.Stat(ctx.ResolvePath(chartPath))
4958
if err == nil {
5059
chartPath = ctx.ResolvePath(chartPath)
5160

5261
// Check if the chart directory has changed
53-
hash, err = hashpkg.Directory(chartPath)
62+
hash, err = hashpkg.DirectoryExcludes(chartPath, []string{
63+
".git/",
64+
".devspace/",
65+
}, true)
5466
if err != nil {
5567
return false, errors.Errorf("Error hashing chart directory: %v", err)
5668
}

pkg/devspace/helm/testing/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ type Client struct {
1515
Releases []*types.Release
1616
}
1717

18+
func (f *Client) DownloadChart(ctx devspacecontext.Context, helmConfig *latest.HelmConfig) (string, error) {
19+
return "", nil
20+
}
21+
1822
// UpdateRepos implements interface
1923
func (f *Client) UpdateRepos() error {
2024
return nil

pkg/devspace/helm/types/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
// Client is the client interface for helm
99
type Client interface {
10+
DownloadChart(ctx devspacecontext.Context, helmConfig *latest.HelmConfig) (string, error)
1011
InstallChart(ctx devspacecontext.Context, releaseName string, releaseNamespace string, values map[string]interface{}, helmConfig *latest.HelmConfig) (*Release, error)
1112
Template(ctx devspacecontext.Context, releaseName, releaseNamespace string, values map[string]interface{}, helmConfig *latest.HelmConfig) (string, error)
1213
DeleteRelease(ctx devspacecontext.Context, releaseName string, releaseNamespace string) error

pkg/devspace/helm/v3/client.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package v3
22

33
import (
4-
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
5-
dependencyutil "github.com/loft-sh/devspace/pkg/devspace/dependency/util"
6-
"github.com/pkg/errors"
7-
"github.com/sirupsen/logrus"
4+
"net/url"
85
"os"
96
"path/filepath"
107
"strconv"
118
"strings"
12-
"net/url"
9+
10+
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
11+
dependencyutil "github.com/loft-sh/devspace/pkg/devspace/dependency/util"
12+
"github.com/pkg/errors"
13+
"github.com/sirupsen/logrus"
1314

1415
"github.com/ghodss/yaml"
1516
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
@@ -30,6 +31,14 @@ func NewClient(log log.Logger) (types.Client, error) {
3031
return c, nil
3132
}
3233

34+
func (c *client) DownloadChart(ctx devspacecontext.Context, helmConfig *latest.HelmConfig) (string, error) {
35+
chartName, err := dependencyutil.DownloadDependency(ctx.Context(), ctx.WorkingDir(), helmConfig.Chart.Source, ctx.Log())
36+
if err != nil {
37+
return "", err
38+
}
39+
return filepath.Dir(chartName), nil
40+
}
41+
3342
// InstallChart installs the given chart via helm v3
3443
func (c *client) InstallChart(ctx devspacecontext.Context, releaseName string, releaseNamespace string, values map[string]interface{}, helmConfig *latest.HelmConfig) (*types.Release, error) {
3544
valuesFile, err := c.genericHelm.WriteValues(values)
@@ -56,7 +65,7 @@ func (c *client) InstallChart(ctx devspacecontext.Context, releaseName string, r
5665
// Chart settings
5766
chartName := ""
5867
if helmConfig.Chart.Source != nil {
59-
chartName, err = dependencyutil.DownloadDependency(ctx.Context(), ctx.WorkingDir(), helmConfig.Chart.Source, ctx.Log())
68+
chartName, err = dependencyutil.GetDependencyPath(ctx.WorkingDir(), helmConfig.Chart.Source)
6069
if err != nil {
6170
return nil, err
6271
}
@@ -157,12 +166,11 @@ func (c *client) Template(ctx devspacecontext.Context, releaseName, releaseNames
157166
// Chart settings
158167
chartName := ""
159168
if helmConfig.Chart.Source != nil {
160-
chartName, err = dependencyutil.DownloadDependency(ctx.Context(), ctx.WorkingDir(), helmConfig.Chart.Source, ctx.Log())
169+
chartName, err = c.DownloadChart(ctx, helmConfig)
161170
if err != nil {
162171
return "", err
163172
}
164173

165-
chartName = filepath.Dir(chartName)
166174
args = append(args, chartName)
167175
} else {
168176
var chartRepo string

pkg/util/hash/hash.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ func Directory(path string) (string, error) {
7373

7474
return nil
7575
})
76-
7776
if err != nil {
7877
return "", err
7978
}

0 commit comments

Comments
 (0)