feat: kubesphere 4.0 (#6115)
* feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> * feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> --------- Signed-off-by: ci-bot <ci-bot@kubesphere.io> Co-authored-by: ks-ci-bot <ks-ci-bot@example.com> Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
committed by
GitHub
parent
b5015ec7b9
commit
447a51f08b
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package chartutil
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -29,7 +28,7 @@ import (
|
||||
|
||||
// LoadChartfile loads a Chart.yaml file into a *chart.Metadata.
|
||||
func LoadChartfile(filename string) (*chart.Metadata, error) {
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
b, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -55,7 +54,7 @@ func SaveChartfile(filename string, cf *chart.Metadata) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(filename, out, 0644)
|
||||
return os.WriteFile(filename, out, 0644)
|
||||
}
|
||||
|
||||
// IsChartDir validate a chart directory.
|
||||
@@ -73,7 +72,7 @@ func IsChartDir(dirName string) (bool, error) {
|
||||
return false, errors.Errorf("no %s exists in directory %q", ChartfileName, dirName)
|
||||
}
|
||||
|
||||
chartYamlContent, err := ioutil.ReadFile(chartYaml)
|
||||
chartYamlContent, err := os.ReadFile(chartYaml)
|
||||
if err != nil {
|
||||
return false, errors.Errorf("cannot read %s in directory %q", ChartfileName, dirName)
|
||||
}
|
||||
|
||||
118
vendor/helm.sh/helm/v3/pkg/chartutil/coalesce.go
vendored
118
vendor/helm.sh/helm/v3/pkg/chartutil/coalesce.go
vendored
@@ -37,12 +37,42 @@ func concatPrefix(a, b string) string {
|
||||
//
|
||||
// Values are coalesced together using the following rules:
|
||||
//
|
||||
// - Values in a higher level chart always override values in a lower-level
|
||||
// dependency chart
|
||||
// - Scalar values and arrays are replaced, maps are merged
|
||||
// - A chart has access to all of the variables for it, as well as all of
|
||||
// the values destined for its dependencies.
|
||||
// - Values in a higher level chart always override values in a lower-level
|
||||
// dependency chart
|
||||
// - Scalar values and arrays are replaced, maps are merged
|
||||
// - A chart has access to all of the variables for it, as well as all of
|
||||
// the values destined for its dependencies.
|
||||
func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) {
|
||||
valsCopy, err := copyValues(vals)
|
||||
if err != nil {
|
||||
return vals, err
|
||||
}
|
||||
return coalesce(log.Printf, chrt, valsCopy, "", false)
|
||||
}
|
||||
|
||||
// MergeValues is used to merge the values in a chart and its subcharts. This
|
||||
// is different from Coalescing as nil/null values are preserved.
|
||||
//
|
||||
// Values are coalesced together using the following rules:
|
||||
//
|
||||
// - Values in a higher level chart always override values in a lower-level
|
||||
// dependency chart
|
||||
// - Scalar values and arrays are replaced, maps are merged
|
||||
// - A chart has access to all of the variables for it, as well as all of
|
||||
// the values destined for its dependencies.
|
||||
//
|
||||
// Retaining Nils is useful when processes early in a Helm action or business
|
||||
// logic need to retain them for when Coalescing will happen again later in the
|
||||
// business logic.
|
||||
func MergeValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) {
|
||||
valsCopy, err := copyValues(vals)
|
||||
if err != nil {
|
||||
return vals, err
|
||||
}
|
||||
return coalesce(log.Printf, chrt, valsCopy, "", true)
|
||||
}
|
||||
|
||||
func copyValues(vals map[string]interface{}) (Values, error) {
|
||||
v, err := copystructure.Copy(vals)
|
||||
if err != nil {
|
||||
return vals, err
|
||||
@@ -53,21 +83,26 @@ func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, err
|
||||
if valsCopy == nil {
|
||||
valsCopy = make(map[string]interface{})
|
||||
}
|
||||
return coalesce(log.Printf, chrt, valsCopy, "")
|
||||
|
||||
return valsCopy, nil
|
||||
}
|
||||
|
||||
type printFn func(format string, v ...interface{})
|
||||
|
||||
// coalesce coalesces the dest values and the chart values, giving priority to the dest values.
|
||||
//
|
||||
// This is a helper function for CoalesceValues.
|
||||
func coalesce(printf printFn, ch *chart.Chart, dest map[string]interface{}, prefix string) (map[string]interface{}, error) {
|
||||
coalesceValues(printf, ch, dest, prefix)
|
||||
return coalesceDeps(printf, ch, dest, prefix)
|
||||
// This is a helper function for CoalesceValues and MergeValues.
|
||||
//
|
||||
// Note, the merge argument specifies whether this is being used by MergeValues
|
||||
// or CoalesceValues. Coalescing removes null values and their keys in some
|
||||
// situations while merging keeps the null values.
|
||||
func coalesce(printf printFn, ch *chart.Chart, dest map[string]interface{}, prefix string, merge bool) (map[string]interface{}, error) {
|
||||
coalesceValues(printf, ch, dest, prefix, merge)
|
||||
return coalesceDeps(printf, ch, dest, prefix, merge)
|
||||
}
|
||||
|
||||
// coalesceDeps coalesces the dependencies of the given chart.
|
||||
func coalesceDeps(printf printFn, chrt *chart.Chart, dest map[string]interface{}, prefix string) (map[string]interface{}, error) {
|
||||
func coalesceDeps(printf printFn, chrt *chart.Chart, dest map[string]interface{}, prefix string, merge bool) (map[string]interface{}, error) {
|
||||
for _, subchart := range chrt.Dependencies() {
|
||||
if c, ok := dest[subchart.Name()]; !ok {
|
||||
// If dest doesn't already have the key, create it.
|
||||
@@ -78,13 +113,11 @@ func coalesceDeps(printf printFn, chrt *chart.Chart, dest map[string]interface{}
|
||||
if dv, ok := dest[subchart.Name()]; ok {
|
||||
dvmap := dv.(map[string]interface{})
|
||||
subPrefix := concatPrefix(prefix, chrt.Metadata.Name)
|
||||
|
||||
// Get globals out of dest and merge them into dvmap.
|
||||
coalesceGlobals(printf, dvmap, dest, subPrefix)
|
||||
|
||||
coalesceGlobals(printf, dvmap, dest, subPrefix, merge)
|
||||
// Now coalesce the rest of the values.
|
||||
var err error
|
||||
dest[subchart.Name()], err = coalesce(printf, subchart, dvmap, subPrefix)
|
||||
dest[subchart.Name()], err = coalesce(printf, subchart, dvmap, subPrefix, merge)
|
||||
if err != nil {
|
||||
return dest, err
|
||||
}
|
||||
@@ -96,7 +129,7 @@ func coalesceDeps(printf printFn, chrt *chart.Chart, dest map[string]interface{}
|
||||
// coalesceGlobals copies the globals out of src and merges them into dest.
|
||||
//
|
||||
// For convenience, returns dest.
|
||||
func coalesceGlobals(printf printFn, dest, src map[string]interface{}, prefix string) {
|
||||
func coalesceGlobals(printf printFn, dest, src map[string]interface{}, prefix string, _ bool) {
|
||||
var dg, sg map[string]interface{}
|
||||
|
||||
if destglob, ok := dest[GlobalKey]; !ok {
|
||||
@@ -130,7 +163,10 @@ func coalesceGlobals(printf printFn, dest, src map[string]interface{}, prefix st
|
||||
// Basically, we reverse order of coalesce here to merge
|
||||
// top-down.
|
||||
subPrefix := concatPrefix(prefix, key)
|
||||
coalesceTablesFullKey(printf, vv, destvmap, subPrefix)
|
||||
// In this location coalesceTablesFullKey should always have
|
||||
// merge set to true. The output of coalesceGlobals is run
|
||||
// through coalesce where any nils will be removed.
|
||||
coalesceTablesFullKey(printf, vv, destvmap, subPrefix, true)
|
||||
dg[key] = vv
|
||||
}
|
||||
}
|
||||
@@ -156,12 +192,38 @@ func copyMap(src map[string]interface{}) map[string]interface{} {
|
||||
// coalesceValues builds up a values map for a particular chart.
|
||||
//
|
||||
// Values in v will override the values in the chart.
|
||||
func coalesceValues(printf printFn, c *chart.Chart, v map[string]interface{}, prefix string) {
|
||||
func coalesceValues(printf printFn, c *chart.Chart, v map[string]interface{}, prefix string, merge bool) {
|
||||
subPrefix := concatPrefix(prefix, c.Metadata.Name)
|
||||
for key, val := range c.Values {
|
||||
|
||||
// Using c.Values directly when coalescing a table can cause problems where
|
||||
// the original c.Values is altered. Creating a deep copy stops the problem.
|
||||
// This section is fault-tolerant as there is no ability to return an error.
|
||||
valuesCopy, err := copystructure.Copy(c.Values)
|
||||
var vc map[string]interface{}
|
||||
var ok bool
|
||||
if err != nil {
|
||||
// If there is an error something is wrong with copying c.Values it
|
||||
// means there is a problem in the deep copying package or something
|
||||
// wrong with c.Values. In this case we will use c.Values and report
|
||||
// an error.
|
||||
printf("warning: unable to copy values, err: %s", err)
|
||||
vc = c.Values
|
||||
} else {
|
||||
vc, ok = valuesCopy.(map[string]interface{})
|
||||
if !ok {
|
||||
// c.Values has a map[string]interface{} structure. If the copy of
|
||||
// it cannot be treated as map[string]interface{} there is something
|
||||
// strangely wrong. Log it and use c.Values
|
||||
printf("warning: unable to convert values copy to values type")
|
||||
vc = c.Values
|
||||
}
|
||||
}
|
||||
|
||||
for key, val := range vc {
|
||||
if value, ok := v[key]; ok {
|
||||
if value == nil {
|
||||
// When the YAML value is null, we remove the value's key.
|
||||
if value == nil && !merge {
|
||||
// When the YAML value is null and we are coalescing instead of
|
||||
// merging, we remove the value's key.
|
||||
// This allows Helm's various sources of values (value files or --set) to
|
||||
// remove incompatible keys from any previous chart, file, or set values.
|
||||
delete(v, key)
|
||||
@@ -177,7 +239,7 @@ func coalesceValues(printf printFn, c *chart.Chart, v map[string]interface{}, pr
|
||||
} else {
|
||||
// Because v has higher precedence than nv, dest values override src
|
||||
// values.
|
||||
coalesceTablesFullKey(printf, dest, src, concatPrefix(subPrefix, key))
|
||||
coalesceTablesFullKey(printf, dest, src, concatPrefix(subPrefix, key), merge)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -191,13 +253,17 @@ func coalesceValues(printf printFn, c *chart.Chart, v map[string]interface{}, pr
|
||||
//
|
||||
// dest is considered authoritative.
|
||||
func CoalesceTables(dst, src map[string]interface{}) map[string]interface{} {
|
||||
return coalesceTablesFullKey(log.Printf, dst, src, "")
|
||||
return coalesceTablesFullKey(log.Printf, dst, src, "", false)
|
||||
}
|
||||
|
||||
func MergeTables(dst, src map[string]interface{}) map[string]interface{} {
|
||||
return coalesceTablesFullKey(log.Printf, dst, src, "", true)
|
||||
}
|
||||
|
||||
// coalesceTablesFullKey merges a source map into a destination map.
|
||||
//
|
||||
// dest is considered authoritative.
|
||||
func coalesceTablesFullKey(printf printFn, dst, src map[string]interface{}, prefix string) map[string]interface{} {
|
||||
func coalesceTablesFullKey(printf printFn, dst, src map[string]interface{}, prefix string, merge bool) map[string]interface{} {
|
||||
// When --reuse-values is set but there are no modifications yet, return new values
|
||||
if src == nil {
|
||||
return dst
|
||||
@@ -209,13 +275,13 @@ func coalesceTablesFullKey(printf printFn, dst, src map[string]interface{}, pref
|
||||
// values.
|
||||
for key, val := range src {
|
||||
fullkey := concatPrefix(prefix, key)
|
||||
if dv, ok := dst[key]; ok && dv == nil {
|
||||
if dv, ok := dst[key]; ok && !merge && dv == nil {
|
||||
delete(dst, key)
|
||||
} else if !ok {
|
||||
dst[key] = val
|
||||
} else if istable(val) {
|
||||
if istable(dv) {
|
||||
coalesceTablesFullKey(printf, dv.(map[string]interface{}), val.(map[string]interface{}), fullkey)
|
||||
coalesceTablesFullKey(printf, dv.(map[string]interface{}), val.(map[string]interface{}), fullkey, merge)
|
||||
} else {
|
||||
printf("warning: cannot overwrite table with non table for %s (%v)", fullkey, val)
|
||||
}
|
||||
|
||||
60
vendor/helm.sh/helm/v3/pkg/chartutil/create.go
vendored
60
vendor/helm.sh/helm/v3/pkg/chartutil/create.go
vendored
@@ -19,7 +19,6 @@ package chartutil
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@@ -122,6 +121,8 @@ fullnameOverride: ""
|
||||
serviceAccount:
|
||||
# Specifies whether a service account should be created
|
||||
create: true
|
||||
# Automatically mount a ServiceAccount's API credentials?
|
||||
automount: true
|
||||
# Annotations to add to the service account
|
||||
annotations: {}
|
||||
# The name of the service account to use.
|
||||
@@ -129,6 +130,7 @@ serviceAccount:
|
||||
name: ""
|
||||
|
||||
podAnnotations: {}
|
||||
podLabels: {}
|
||||
|
||||
podSecurityContext: {}
|
||||
# fsGroup: 2000
|
||||
@@ -173,6 +175,15 @@ resources: {}
|
||||
# cpu: 100m
|
||||
# memory: 128Mi
|
||||
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: http
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: http
|
||||
|
||||
autoscaling:
|
||||
enabled: false
|
||||
minReplicas: 1
|
||||
@@ -180,6 +191,19 @@ autoscaling:
|
||||
targetCPUUtilizationPercentage: 80
|
||||
# targetMemoryUtilizationPercentage: 80
|
||||
|
||||
# Additional volumes on the output Deployment definition.
|
||||
volumes: []
|
||||
# - name: foo
|
||||
# secret:
|
||||
# secretName: mysecret
|
||||
# optional: false
|
||||
|
||||
# Additional volumeMounts on the output Deployment definition.
|
||||
volumeMounts: []
|
||||
# - name: foo
|
||||
# mountPath: "/etc/foo"
|
||||
# readOnly: true
|
||||
|
||||
nodeSelector: {}
|
||||
|
||||
tolerations: []
|
||||
@@ -295,7 +319,10 @@ spec:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
labels:
|
||||
{{- include "<CHARTNAME>.selectorLabels" . | nindent 8 }}
|
||||
{{- include "<CHARTNAME>.labels" . | nindent 8 }}
|
||||
{{- with .Values.podLabels }}
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- with .Values.imagePullSecrets }}
|
||||
imagePullSecrets:
|
||||
@@ -315,15 +342,19 @@ spec:
|
||||
containerPort: {{ .Values.service.port }}
|
||||
protocol: TCP
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: http
|
||||
{{- toYaml .Values.livenessProbe | nindent 12 }}
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: http
|
||||
{{- toYaml .Values.readinessProbe | nindent 12 }}
|
||||
resources:
|
||||
{{- toYaml .Values.resources | nindent 12 }}
|
||||
{{- with .Values.volumeMounts }}
|
||||
volumeMounts:
|
||||
{{- toYaml . | nindent 12 }}
|
||||
{{- end }}
|
||||
{{- with .Values.volumes }}
|
||||
volumes:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
@@ -366,11 +397,12 @@ metadata:
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
|
||||
{{- end }}
|
||||
`
|
||||
|
||||
const defaultHorizontalPodAutoscaler = `{{- if .Values.autoscaling.enabled }}
|
||||
apiVersion: autoscaling/v2beta1
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: {{ include "<CHARTNAME>.fullname" . }}
|
||||
@@ -388,13 +420,17 @@ spec:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
|
||||
{{- end }}
|
||||
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
|
||||
- type: Resource
|
||||
resource:
|
||||
name: memory
|
||||
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
`
|
||||
@@ -673,7 +709,7 @@ func writeFile(name string, content []byte) error {
|
||||
if err := os.MkdirAll(filepath.Dir(name), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(name, content, 0644)
|
||||
return os.WriteFile(name, content, 0644)
|
||||
}
|
||||
|
||||
func validateChartName(name string) error {
|
||||
|
||||
@@ -19,15 +19,29 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/mitchellh/copystructure"
|
||||
|
||||
"helm.sh/helm/v3/pkg/chart"
|
||||
)
|
||||
|
||||
// ProcessDependencies checks through this chart's dependencies, processing accordingly.
|
||||
//
|
||||
// TODO: For Helm v4 this can be combined with or turned into ProcessDependenciesWithMerge
|
||||
func ProcessDependencies(c *chart.Chart, v Values) error {
|
||||
if err := processDependencyEnabled(c, v, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
return processDependencyImportValues(c)
|
||||
return processDependencyImportValues(c, false)
|
||||
}
|
||||
|
||||
// ProcessDependenciesWithMerge checks through this chart's dependencies, processing accordingly.
|
||||
// It is similar to ProcessDependencies but it does not remove nil values during
|
||||
// the import/export handling process.
|
||||
func ProcessDependenciesWithMerge(c *chart.Chart, v Values) error {
|
||||
if err := processDependencyEnabled(c, v, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
return processDependencyImportValues(c, true)
|
||||
}
|
||||
|
||||
// processDependencyConditions disables charts based on condition path value in values
|
||||
@@ -45,9 +59,8 @@ func processDependencyConditions(reqs []*chart.Dependency, cvals Values, cpath s
|
||||
if bv, ok := vv.(bool); ok {
|
||||
r.Enabled = bv
|
||||
break
|
||||
} else {
|
||||
log.Printf("Warning: Condition path '%s' for chart %s returned non-bool value", c, r.Name)
|
||||
}
|
||||
log.Printf("Warning: Condition path '%s' for chart %s returned non-bool value", c, r.Name)
|
||||
} else if _, ok := err.(ErrNoValue); !ok {
|
||||
// this is a real error
|
||||
log.Printf("Warning: PathValue returned error %v", err)
|
||||
@@ -137,6 +150,9 @@ Loop:
|
||||
}
|
||||
|
||||
for _, req := range c.Metadata.Dependencies {
|
||||
if req == nil {
|
||||
continue
|
||||
}
|
||||
if chartDependency := getAliasDependency(c.Dependencies(), req); chartDependency != nil {
|
||||
chartDependencies = append(chartDependencies, chartDependency)
|
||||
}
|
||||
@@ -217,12 +233,18 @@ func set(path []string, data map[string]interface{}) map[string]interface{} {
|
||||
}
|
||||
|
||||
// processImportValues merges values from child to parent based on the chart's dependencies' ImportValues field.
|
||||
func processImportValues(c *chart.Chart) error {
|
||||
func processImportValues(c *chart.Chart, merge bool) error {
|
||||
if c.Metadata.Dependencies == nil {
|
||||
return nil
|
||||
}
|
||||
// combine chart values and empty config to get Values
|
||||
cvals, err := CoalesceValues(c, nil)
|
||||
var cvals Values
|
||||
var err error
|
||||
if merge {
|
||||
cvals, err = MergeValues(c, nil)
|
||||
} else {
|
||||
cvals, err = CoalesceValues(c, nil)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -248,7 +270,11 @@ func processImportValues(c *chart.Chart) error {
|
||||
continue
|
||||
}
|
||||
// create value map from child to be merged into parent
|
||||
b = CoalesceTables(cvals, pathToMap(parent, vv.AsMap()))
|
||||
if merge {
|
||||
b = MergeTables(b, pathToMap(parent, vv.AsMap()))
|
||||
} else {
|
||||
b = CoalesceTables(b, pathToMap(parent, vv.AsMap()))
|
||||
}
|
||||
case string:
|
||||
child := "exports." + iv
|
||||
outiv = append(outiv, map[string]string{
|
||||
@@ -260,26 +286,71 @@ func processImportValues(c *chart.Chart) error {
|
||||
log.Printf("Warning: ImportValues missing table: %v", err)
|
||||
continue
|
||||
}
|
||||
b = CoalesceTables(b, vm.AsMap())
|
||||
if merge {
|
||||
b = MergeTables(b, vm.AsMap())
|
||||
} else {
|
||||
b = CoalesceTables(b, vm.AsMap())
|
||||
}
|
||||
}
|
||||
}
|
||||
// set our formatted import values
|
||||
r.ImportValues = outiv
|
||||
}
|
||||
|
||||
// set the new values
|
||||
c.Values = CoalesceTables(cvals, b)
|
||||
// Imported values from a child to a parent chart have a lower priority than
|
||||
// the parents values. This enables parent charts to import a large section
|
||||
// from a child and then override select parts. This is why b is merged into
|
||||
// cvals in the code below and not the other way around.
|
||||
if merge {
|
||||
// deep copying the cvals as there are cases where pointers can end
|
||||
// up in the cvals when they are copied onto b in ways that break things.
|
||||
cvals = deepCopyMap(cvals)
|
||||
c.Values = MergeTables(cvals, b)
|
||||
} else {
|
||||
// Trimming the nil values from cvals is needed for backwards compatibility.
|
||||
// Previously, the b value had been populated with cvals along with some
|
||||
// overrides. This caused the coalescing functionality to remove the
|
||||
// nil/null values. This trimming is for backwards compat.
|
||||
cvals = trimNilValues(cvals)
|
||||
c.Values = CoalesceTables(cvals, b)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopyMap(vals map[string]interface{}) map[string]interface{} {
|
||||
valsCopy, err := copystructure.Copy(vals)
|
||||
if err != nil {
|
||||
return vals
|
||||
}
|
||||
return valsCopy.(map[string]interface{})
|
||||
}
|
||||
|
||||
func trimNilValues(vals map[string]interface{}) map[string]interface{} {
|
||||
valsCopy, err := copystructure.Copy(vals)
|
||||
if err != nil {
|
||||
return vals
|
||||
}
|
||||
valsCopyMap := valsCopy.(map[string]interface{})
|
||||
for key, val := range valsCopyMap {
|
||||
if val == nil {
|
||||
// Iterate over the values and remove nil keys
|
||||
delete(valsCopyMap, key)
|
||||
} else if istable(val) {
|
||||
// Recursively call into ourselves to remove keys from inner tables
|
||||
valsCopyMap[key] = trimNilValues(val.(map[string]interface{}))
|
||||
}
|
||||
}
|
||||
|
||||
return valsCopyMap
|
||||
}
|
||||
|
||||
// processDependencyImportValues imports specified chart values from child to parent.
|
||||
func processDependencyImportValues(c *chart.Chart) error {
|
||||
func processDependencyImportValues(c *chart.Chart, merge bool) error {
|
||||
for _, d := range c.Dependencies() {
|
||||
// recurse
|
||||
if err := processDependencyImportValues(d); err != nil {
|
||||
if err := processDependencyImportValues(d, merge); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return processImportValues(c)
|
||||
return processImportValues(c, merge)
|
||||
}
|
||||
|
||||
9
vendor/helm.sh/helm/v3/pkg/chartutil/doc.go
vendored
9
vendor/helm.sh/helm/v3/pkg/chartutil/doc.go
vendored
@@ -14,16 +14,17 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*Package chartutil contains tools for working with charts.
|
||||
/*
|
||||
Package chartutil contains tools for working with charts.
|
||||
|
||||
Charts are described in the chart package (pkg/chart).
|
||||
This package provides utilities for serializing and deserializing charts.
|
||||
|
||||
A chart can be represented on the file system in one of two ways:
|
||||
|
||||
- As a directory that contains a Chart.yaml file and other chart things.
|
||||
- As a tarred gzipped file containing a directory that then contains a
|
||||
Chart.yaml file.
|
||||
- As a directory that contains a Chart.yaml file and other chart things.
|
||||
- As a tarred gzipped file containing a directory that then contains a
|
||||
Chart.yaml file.
|
||||
|
||||
This package provides utilities for working with those file formats.
|
||||
|
||||
|
||||
@@ -33,3 +33,11 @@ type ErrNoValue struct {
|
||||
}
|
||||
|
||||
func (e ErrNoValue) Error() string { return fmt.Sprintf("%q is not a value", e.Key) }
|
||||
|
||||
type ErrInvalidChartName struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (e ErrInvalidChartName) Error() string {
|
||||
return fmt.Sprintf("%q is not a valid chart name", e.Name)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package chartutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -72,7 +71,7 @@ func Expand(dir string, r io.Reader) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(outpath, file.Data, 0644); err != nil {
|
||||
if err := os.WriteFile(outpath, file.Data, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
20
vendor/helm.sh/helm/v3/pkg/chartutil/save.go
vendored
20
vendor/helm.sh/helm/v3/pkg/chartutil/save.go
vendored
@@ -39,6 +39,10 @@ var headerBytes = []byte("+aHR0cHM6Ly95b3V0dS5iZS96OVV6MWljandyTQo=")
|
||||
// directory, writing the chart's contents to that subdirectory.
|
||||
func SaveDir(c *chart.Chart, dest string) error {
|
||||
// Create the chart directory
|
||||
err := validateName(c.Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outdir := filepath.Join(dest, c.Name())
|
||||
if fi, err := os.Stat(outdir); err == nil && !fi.IsDir() {
|
||||
return errors.Errorf("file %s already exists and is not a directory", outdir)
|
||||
@@ -149,6 +153,10 @@ func Save(c *chart.Chart, outDir string) (string, error) {
|
||||
}
|
||||
|
||||
func writeTarContents(out *tar.Writer, c *chart.Chart, prefix string) error {
|
||||
err := validateName(c.Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
base := filepath.Join(prefix, c.Name())
|
||||
|
||||
// Pull out the dependencies of a v1 Chart, since there's no way
|
||||
@@ -242,3 +250,15 @@ func writeToTar(out *tar.Writer, name string, body []byte) error {
|
||||
_, err := out.Write(body)
|
||||
return err
|
||||
}
|
||||
|
||||
// If the name has directory name has characters which would change the location
|
||||
// they need to be removed.
|
||||
func validateName(name string) error {
|
||||
nname := filepath.Base(name)
|
||||
|
||||
if nname != name {
|
||||
return ErrInvalidChartName{name}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package chartutil
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -114,7 +114,7 @@ func ReadValues(data []byte) (vals Values, err error) {
|
||||
|
||||
// ReadValuesFile will parse a YAML file into a map of values.
|
||||
func ReadValuesFile(filename string) (Values, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return map[string]interface{}{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user