Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions internal/charts/chart_dependecies.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
package charts

import (
"os"
"path/filepath"

"go.lsp.dev/uri"
)

func (c *Chart) GetDependecyURI(dependencyName string) uri.URI {
unpackedPath := filepath.Join(c.RootURI.Filename(), "charts", dependencyName)
fileInfo, err := os.Stat(unpackedPath)

if err == nil && fileInfo.IsDir() {
return uri.File(unpackedPath)
}

return uri.File(filepath.Join(c.RootURI.Filename(), "charts", DependencyCacheFolder, dependencyName))
return uri.File(c.getDependencyDir(dependencyName))
}

func (c *Chart) GetDependeciesTemplates() []*DependencyTemplateFile {
Expand Down
17 changes: 17 additions & 0 deletions internal/charts/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,20 @@ func TestGetValueLocation(t *testing.T) {

assert.Equal(t, expected, valueLocation)
}

func TestLoadsHelmChartWithDependeciesAsFileURI(t *testing.T) {
chart := charts.NewChart(uri.File("../../testdata/dependencyFileURIExample/"), util.ValuesFilesConfig{})

dependecyTemplates := chart.GetDependeciesTemplates()
assert.Len(t, dependecyTemplates, 2)

filePaths := []string{}
for _, dependency := range dependecyTemplates {
filePaths = append(filePaths, dependency.Path)
}
path, _ := filepath.Abs("../../testdata/dependenciesExample/charts/subchartexample/templates/subchart.yaml")
assert.Contains(t, filePaths, path)

path, _ = filepath.Abs("../../testdata/dependenciesExample/charts/subchartexample/templates/_helpers_subchart.tpl")
assert.Contains(t, filePaths, path)
}
26 changes: 26 additions & 0 deletions internal/charts/dependency_files.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package charts

import (
"net/url"
"os"
"path/filepath"
"strings"
Expand All @@ -26,7 +27,32 @@ type PossibleDependencyFile interface {
GetPath() string
}

func (c *Chart) getDependencyPathFromMetadata(chartName string) string {
for _, dep := range c.ChartMetadata.Metadata.Dependencies {
if dep.Name == chartName {
return dep.Repository
}
}
return ""
}

func (c *Chart) getDependencyDir(chartName string) string {
dependencyURI := c.getDependencyPathFromMetadata(chartName)
fileURIPrefix := "file://"
if dependencyURI != "" && strings.HasPrefix(dependencyURI, fileURIPrefix) {
relativePath := dependencyURI[len(fileURIPrefix):]
relativePathClean, err := url.PathUnescape(relativePath)
if err != nil {
logger.Error("Could not unescape dependency file path", relativePath, err)
}
absolutePath := filepath.Join(c.RootURI.Filename(), relativePathClean)

_, err = os.Stat(absolutePath)
if err == nil {
return absolutePath
}
}

extractedPath := filepath.Join(c.RootURI.Filename(), "charts", chartName)
_, err := os.Stat(extractedPath)
if err == nil {
Expand Down
13 changes: 13 additions & 0 deletions internal/handler/yaml_handler/definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ func TestDefinition(t *testing.T) {
},
"",
},
{
"From chart to dependency defined by URI",
"../../../testdata/dependencyFileURIExample/values.yaml",
"^onlyInSubchartValues:",

[]testutil.ExpectedLocationsResult{
{
Filepath: "../../../testdata/dependenciesExample/charts/subchartexample/values.yaml",
MarkedLine: "§onlyInSubchartValues§: ",
},
},
"",
},
}

for _, tc := range testCases {
Expand Down
23 changes: 23 additions & 0 deletions testdata/dependencyFileURIExample/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions testdata/dependencyFileURIExample/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: subchartexample
repository: file://../dependenciesExample/charts/subchartexample
version: 0.1.0
digest: sha256:4ca6d785cb293110a14cfd230b21a1a420a5a3d817c9ebdf7d1ad8d77c139900
generated: "2025-08-03T13:33:39.788449204+02:00"
28 changes: 28 additions & 0 deletions testdata/dependencyFileURIExample/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: v2
name: dependencyFileURIExample
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
dependencies:
- name: subchartexample
version: x.x.x

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For dependencies on local fs, you would usually specify version: "*"

repository: "file://../dependenciesExample/charts/subchartexample"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
global:
subchart: works
globalFromSubchart: works
subchartWithoutGlobal: works
onlyInSubchartValues: hi
Binary file not shown.
2 changes: 2 additions & 0 deletions testdata/dependencyFileURIExample/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
subchartexample:
onlyInSubchartValues: hi
Loading