Skip to content

Commit ee4dd4d

Browse files
committed
readded builder value parser
1 parent 9fc29e2 commit ee4dd4d

File tree

4 files changed

+69
-6
lines changed

4 files changed

+69
-6
lines changed

cli/cmd/lint.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ func (r *runners) lintPreflightSpecs(cmd *cobra.Command, preflights []lint2.Pref
385385
cmd.Context(),
386386
pf.SpecPath,
387387
pf.ValuesPath,
388+
pf.ChartName,
389+
pf.ChartVersion,
388390
helmChartManifests,
389391
preflightVersion,
390392
)

examples/support-bundles/helmchart-sample-app.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,12 @@ spec:
66
chart:
77
name: sample-app
88
chartVersion: 1.0.0
9-
# Optional builder values that can be used by v1beta3 preflights
10-
builder: {}
9+
# Builder values override chart values for v1beta3 preflights
10+
builder:
11+
testMode: true
12+
environment: production
13+
replicas: 3
14+
database:
15+
enabled: true
16+
host: db.example.com
17+
port: 5432

pkg/lint2/config.go

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

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

67
"github.com/replicatedhq/replicated/pkg/tools"
78
)
@@ -88,8 +89,8 @@ func GetPreflightPathsFromConfig(config *tools.Config) ([]string, error) {
8889
type PreflightWithValues struct {
8990
SpecPath string // Path to the preflight spec file
9091
ValuesPath string // Path to values.yaml (optional - passed to preflight lint if provided)
91-
ChartName string // Deprecated: no longer used
92-
ChartVersion string // Deprecated: no longer used
92+
ChartName string // Chart name from Chart.yaml (used to look up HelmChart manifest for builder values)
93+
ChartVersion string // Chart version from Chart.yaml (used to look up HelmChart manifest for builder values)
9394
}
9495

9596
// GetPreflightWithValuesFromConfig extracts preflight paths with associated chart/values information
@@ -117,6 +118,24 @@ func GetPreflightWithValuesFromConfig(config *tools.Config) ([]PreflightWithValu
117118
ValuesPath: preflightConfig.ValuesPath, // Optional - can be empty
118119
}
119120

121+
// Extract chart metadata if valuesPath is provided
122+
// This is needed to look up the matching HelmChart manifest for builder values
123+
if preflightConfig.ValuesPath != "" {
124+
// Get the chart directory from the values path
125+
// valuesPath is expected to be like "./helm-chart/values.yaml"
126+
chartDir := filepath.Dir(preflightConfig.ValuesPath)
127+
128+
chartMetadata, err := GetChartMetadata(chartDir)
129+
if err != nil {
130+
// If we can't read Chart.yaml, it's OK - builder values just won't be applied
131+
// This allows preflights without associated charts to work
132+
// Don't fail the whole operation, just skip this preflight's metadata
133+
} else {
134+
result.ChartName = chartMetadata.Name
135+
result.ChartVersion = chartMetadata.Version
136+
}
137+
}
138+
120139
results = append(results, result)
121140
}
122141
}

pkg/lint2/preflight.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212

1313
"github.com/replicatedhq/replicated/pkg/tools"
14+
"gopkg.in/yaml.v3"
1415
)
1516

1617
// PreflightLintResult represents the JSON output from preflight lint
@@ -34,11 +35,13 @@ type PreflightLintIssue struct {
3435

3536
// LintPreflight executes preflight lint on the given spec path and returns structured results.
3637
// The preflight CLI tool handles template rendering and validation internally.
37-
// For v1beta3 specs, we validate that HelmChart manifests exist before linting.
38+
// For v1beta3 specs, we validate that HelmChart manifests exist and extract builder values.
3839
func LintPreflight(
3940
ctx context.Context,
4041
specPath string,
4142
valuesPath string,
43+
chartName string,
44+
chartVersion string,
4245
helmChartManifests map[string]*HelmChartManifest,
4346
preflightVersion string,
4447
) (*LintResult, error) {
@@ -72,11 +75,43 @@ func LintPreflight(
7275
// Build command arguments
7376
args := []string{"lint", "--format", "json"}
7477

75-
// Add values file if provided
78+
// Add chart values file if provided from config
7679
if valuesPath != "" {
7780
args = append(args, "--values", valuesPath)
7881
}
7982

83+
// Extract and add builder values if HelmChart manifest exists
84+
var builderValuesPath string
85+
if chartName != "" && chartVersion != "" {
86+
key := fmt.Sprintf("%s:%s", chartName, chartVersion)
87+
if helmChart, found := helmChartManifests[key]; found && helmChart.BuilderValues != nil {
88+
// Create temp file for builder values
89+
builderFile, err := os.CreateTemp("", "replicated-builder-*.yaml")
90+
if err != nil {
91+
return nil, fmt.Errorf("failed to create temp file for builder values: %w", err)
92+
}
93+
builderValuesPath = builderFile.Name()
94+
defer func() {
95+
if err := os.Remove(builderValuesPath); err != nil && !os.IsNotExist(err) {
96+
fmt.Fprintf(os.Stderr, "Warning: failed to cleanup builder values temp file %s: %v\n", builderValuesPath, err)
97+
}
98+
}()
99+
100+
// Write builder values as YAML
101+
builderYAML, err := yaml.Marshal(helmChart.BuilderValues)
102+
if err != nil {
103+
return nil, fmt.Errorf("failed to marshal builder values: %w", err)
104+
}
105+
if _, err := builderFile.Write(builderYAML); err != nil {
106+
return nil, fmt.Errorf("failed to write builder values: %w", err)
107+
}
108+
builderFile.Close()
109+
110+
// Add builder values to command
111+
args = append(args, "--values", builderValuesPath)
112+
}
113+
}
114+
80115
args = append(args, specPath)
81116

82117
// Execute preflight lint

0 commit comments

Comments
 (0)