Merge pull request #10110 from zegerius/main

Fix value precedence
pull/10855/head
Matt Farina 3 years ago committed by GitHub
commit 3fdb7cac01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -268,7 +268,7 @@ func processImportValues(c *chart.Chart) error {
}
// set the new values
c.Values = CoalesceTables(b, cvals)
c.Values = CoalesceTables(cvals, b)
return nil
}

@ -239,6 +239,37 @@ func TestProcessDependencyImportValues(t *testing.T) {
}
}
func TestProcessDependencyImportValuesMultiLevelPrecedence(t *testing.T) {
c := loadChart(t, "testdata/three-level-dependent-chart/umbrella")
e := make(map[string]string)
e["app1.service.port"] = "3456"
e["app2.service.port"] = "8080"
if err := processDependencyImportValues(c); err != nil {
t.Fatalf("processing import values dependencies %v", err)
}
cc := Values(c.Values)
for kk, vv := range e {
pv, err := cc.PathValue(kk)
if err != nil {
t.Fatalf("retrieving import values table %v %v", kk, err)
}
switch pv := pv.(type) {
case float64:
if s := strconv.FormatFloat(pv, 'f', -1, 64); s != vv {
t.Errorf("failed to match imported float value %v with expected %v", s, vv)
}
default:
if pv != vv {
t.Errorf("failed to match imported string value %q with expected %q", pv, vv)
}
}
}
}
func TestProcessDependencyImportValuesForEnabledCharts(t *testing.T) {
c := loadChart(t, "testdata/import-values-from-enabled-subchart/parent-chart")
nameOverride := "parent-chart-prod"

@ -0,0 +1,16 @@
# Three Level Dependent Chart
This chart is for testing the processing of multi-level dependencies.
Consists of the following charts:
- Library Chart
- App Chart (Uses Library Chart as dependecy, 2x: app1/app2)
- Umbrella Chart (Has all the app charts as dependencies)
The precendence is as follows: `library < app < umbrella`
Catches two use-cases:
- app overwriting library (app2)
- umbrella overwriting app and library (app1)

@ -0,0 +1,13 @@
apiVersion: v2
name: umbrella
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
dependencies:
- name: app1
version: 0.1.0
condition: app1.enabled
- name: app2
version: 0.1.0
condition: app2.enabled

@ -0,0 +1,11 @@
apiVersion: v2
name: app1
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
dependencies:
- name: library
version: 0.1.0
import-values:
- defaults

@ -0,0 +1,5 @@
apiVersion: v2
name: library
description: A Helm chart for Kubernetes
type: library
version: 0.1.0

@ -0,0 +1,9 @@
apiVersion: v1
kind: Service
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http

@ -0,0 +1,5 @@
exports:
defaults:
service:
type: ClusterIP
port: 9090

@ -0,0 +1,11 @@
apiVersion: v2
name: app2
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
dependencies:
- name: library
version: 0.1.0
import-values:
- defaults

@ -0,0 +1,5 @@
apiVersion: v2
name: library
description: A Helm chart for Kubernetes
type: library
version: 0.1.0

@ -0,0 +1,9 @@
apiVersion: v1
kind: Service
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http

@ -0,0 +1,5 @@
exports:
defaults:
service:
type: ClusterIP
port: 9090

@ -0,0 +1,8 @@
app1:
enabled: true
service:
type: ClusterIP
port: 3456
app2:
enabled: true
Loading…
Cancel
Save