Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
1105 Внедрение механизмов обеспечения безопасности цепочки поставки программных проектов
Legacy
scanned-projects
helm
Commits
9e1e26f0
Unverified
Commit
9e1e26f0
authored
6 years ago
by
Adam Reese
Browse files
Options
Download
Patches
Plain Diff
ref(pkg/chartutil): attempt to make requirements processing readable
Signed-off-by:
Adam Reese
<
adam@reese.io
>
parent
f5b6ff28
main
Release
add-codeql
dependabot/go_modules/github.com/docker/distribution-2.8.2incompatible
dependabot/go_modules/github.com/lib/pq-1.10.9
dependabot/go_modules/github.com/rubenv/sql-migrate-1.4.0
dependabot/go_modules/golang.org/x/crypto-0.9.0
dependabot/go_modules/golang.org/x/term-0.8.0
dependabot/go_modules/k8s.io/klog/v2-2.100.1
release-3.0
release-3.1
release-3.10
release-3.11
release-3.12
release-3.2
release-3.3
release-3.4
release-3.5
release-3.6
release-3.6.1
release-3.6.2
release-3.7
release-3.8
release-3.9
release-v3.0.0-beta.4
v3.12.0
v3.12.0-rc.1
v3.12.0-dev.1
v3.11.3
v3.11.2
v3.11.1
v3.11.0
v3.11.0-rc.2
v3.11.0-rc.1
v3.10.3
v3.10.2
v3.10.1
v3.10.0
v3.10.0-rc.1
v3.9.4
v3.9.3
v3.9.2
v3.9.1
v3.9.0
v3.9.0-rc.1
v3.8.2
v3.8.1
v3.8.0
v3.8.0-rc.2
v3.8.0-rc.1
v3.7.2
v3.7.1
v3.7.0
v3.7.0-rc.3
v3.7.0-rc.2
v3.7.0-rc.1
v3.6.3
v3.6.2
v3.6.1
v3.6.0
v3.6.0-rc.1
v3.5.4
v3.5.3
v3.5.2
v3.5.1
v3.5.0
v3.5.0-rc.2
v3.5.0-rc.1
v3.4.2
v3.4.1
v3.4.0
v3.4.0-rc.1
v3.3.4
v3.3.3
v3.3.2
v3.3.1
v3.3.0
v3.3.0-rc.2
v3.3.0-rc.1
v3.2.4
v3.2.3
v3.2.2
v3.2.1
v3.2.0
v3.2.0-rc.1
v3.1.3
v3.1.2
v3.1.1
v3.1.0
v3.1.0-rc.3
v3.1.0-rc.2
v3.1.0-rc.1
v3.0.3
v3.0.2
v3.0.1
v3.0.0
v3.0.0-rc.4
v3.0.0-rc.3
v3.0.0-rc.2
v3.0.0-rc.1
v3.0.0-beta.5
v3.0.0-beta.4
v3.0.0-beta.3
v3.0.0-beta.2
v3.0.0-beta.1
v3.0.0-alpha.2
v3.0.0-alpha.1
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/chartutil/requirements.go
+24
-33
pkg/chartutil/requirements.go
pkg/chartutil/values.go
+26
-31
pkg/chartutil/values.go
with
50 additions
and
64 deletions
+50
-64
pkg/chartutil/requirements.go
+
24
−
33
View file @
9e1e26f0
...
...
@@ -205,29 +205,18 @@ func pathToMap(path string, data map[string]interface{}) map[string]interface{}
if
path
==
"."
{
return
data
}
ap
:=
strings
.
Split
(
path
,
"."
)
if
len
(
ap
)
==
0
{
return
set
(
parsePath
(
path
),
data
)
}
func
set
(
path
[]
string
,
data
map
[
string
]
interface
{})
map
[
string
]
interface
{}
{
if
len
(
path
)
==
0
{
return
nil
}
n
:=
[]
map
[
string
]
interface
{}{}
// created nested map for each key, adding to slice
for
_
,
v
:=
range
ap
{
nm
:=
make
(
map
[
string
]
interface
{})
nm
[
v
]
=
make
(
map
[
string
]
interface
{})
n
=
append
(
n
,
nm
)
}
// find the last key (map) and set our data
for
i
,
d
:=
range
n
{
for
k
:=
range
d
{
z
:=
i
+
1
if
z
==
len
(
n
)
{
n
[
i
][
k
]
=
data
break
}
n
[
i
][
k
]
=
n
[
z
]
}
cur
:=
data
for
i
:=
len
(
path
)
-
1
;
i
>=
0
;
i
--
{
cur
=
map
[
string
]
interface
{}{
path
[
i
]
:
cur
}
}
return
n
[
0
]
return
cur
}
// processImportValues merges values from child to parent based on the chart's dependencies' ImportValues field.
...
...
@@ -247,27 +236,29 @@ func processImportValues(c *chart.Chart) error {
for
_
,
riv
:=
range
r
.
ImportValues
{
switch
iv
:=
riv
.
(
type
)
{
case
map
[
string
]
interface
{}
:
nm
:=
map
[
string
]
string
{
"child"
:
iv
[
"child"
]
.
(
string
),
"parent"
:
iv
[
"parent"
]
.
(
string
),
}
outiv
=
append
(
outiv
,
nm
)
child
:=
iv
[
"child"
]
.
(
string
)
parent
:=
iv
[
"parent"
]
.
(
string
)
outiv
=
append
(
outiv
,
map
[
string
]
string
{
"child"
:
child
,
"parent"
:
parent
,
})
// get child table
vv
,
err
:=
cvals
.
Table
(
r
.
Name
+
"."
+
nm
[
"
child
"
]
)
vv
,
err
:=
cvals
.
Table
(
r
.
Name
+
"."
+
child
)
if
err
!=
nil
{
log
.
Printf
(
"Warning: ImportValues missing table: %v"
,
err
)
continue
}
// create value map from child to be merged into parent
vm
:=
pathToMap
(
nm
[
"parent"
],
vv
.
AsMap
())
b
=
coalesceTables
(
cvals
,
vm
)
b
=
coalesceTables
(
cvals
,
pathToMap
(
parent
,
vv
.
AsMap
()))
case
string
:
nm
:=
map
[
string
]
string
{
"child"
:
"exports."
+
iv
,
child
:=
"exports."
+
iv
outiv
=
append
(
outiv
,
map
[
string
]
string
{
"child"
:
child
,
"parent"
:
"."
,
}
outiv
=
append
(
outiv
,
nm
)
vm
,
err
:=
cvals
.
Table
(
r
.
Name
+
"."
+
nm
[
"child"
])
})
vm
,
err
:=
cvals
.
Table
(
r
.
Name
+
"."
+
child
)
if
err
!=
nil
{
log
.
Printf
(
"Warning: ImportValues missing table: %v"
,
err
)
continue
...
...
This diff is collapsed.
Click to expand it.
pkg/chartutil/values.go
+
26
−
31
View file @
9e1e26f0
...
...
@@ -62,7 +62,7 @@ func (v Values) Table(name string) (Values, error) {
table
:=
v
var
err
error
for
_
,
n
:=
range
strings
.
Split
(
name
,
"."
)
{
for
_
,
n
:=
range
parsePath
(
name
)
{
table
,
err
=
tableLookup
(
table
,
n
)
if
err
!=
nil
{
return
table
,
err
...
...
@@ -118,7 +118,7 @@ func ReadValues(data []byte) (vals Values, err error) {
if
len
(
vals
)
==
0
{
vals
=
Values
{}
}
return
return
vals
,
err
}
// ReadValuesFile will parse a YAML file into a map of values.
...
...
@@ -240,11 +240,11 @@ func coalesceGlobals(dest, src map[string]interface{}) {
}
func
copyMap
(
src
map
[
string
]
interface
{})
map
[
string
]
interface
{}
{
dest
:=
make
(
map
[
string
]
interface
{},
len
(
src
))
m
:=
make
(
map
[
string
]
interface
{},
len
(
src
))
for
k
,
v
:=
range
src
{
dest
[
k
]
=
v
m
[
k
]
=
v
}
return
dest
return
m
}
// coalesceValues builds up a values map for a particular chart.
...
...
@@ -350,40 +350,35 @@ func istable(v interface{}) bool {
// chapter:
// one:
// title: "Loomings"
func
(
v
Values
)
PathValue
(
y
path
string
)
(
interface
{},
error
)
{
if
len
(
y
path
)
==
0
{
return
nil
,
errors
.
New
(
"YAML path
string
cannot be
zero length
"
)
func
(
v
Values
)
PathValue
(
path
string
)
(
interface
{},
error
)
{
if
path
==
""
{
return
nil
,
errors
.
New
(
"YAML path cannot be
empty
"
)
}
yps
:=
strings
.
Split
(
ypath
,
"."
)
if
len
(
yps
)
==
1
{
return
v
.
pathValue
(
parsePath
(
path
))
}
func
(
v
Values
)
pathValue
(
path
[]
string
)
(
interface
{},
error
)
{
if
len
(
path
)
==
1
{
// if exists must be root key not table
vals
:=
v
.
AsMap
()
k
:=
yps
[
0
]
if
_
,
ok
:=
vals
[
k
];
ok
&&
!
istable
(
vals
[
k
])
{
// key found
return
vals
[
yps
[
0
]],
nil
if
_
,
ok
:=
v
[
path
[
0
]];
ok
&&
!
istable
(
v
[
path
[
0
]])
{
return
v
[
path
[
0
]],
nil
}
// key not found
return
nil
,
ErrNoValue
(
errors
.
Errorf
(
"%v is not a value"
,
k
))
return
nil
,
ErrNoValue
(
errors
.
Errorf
(
"%v is not a value"
,
path
[
0
]))
}
// join all elements of YAML path except last to get string table path
ypsLen
:=
len
(
yps
)
table
:=
yps
[
:
ypsLen
-
1
]
st
:=
strings
.
Join
(
table
,
"."
)
// get the last element as a string key
sk
:=
yps
[
ypsLen
-
1
:
][
0
]
key
,
path
:=
path
[
len
(
path
)
-
1
],
path
[
:
len
(
path
)
-
1
]
// get our table for table path
t
,
err
:=
v
.
Table
(
st
)
t
,
err
:=
v
.
Table
(
joinPath
(
path
...
)
)
if
err
!=
nil
{
//no table
return
nil
,
ErrNoValue
(
errors
.
Errorf
(
"%v is not a value"
,
sk
))
return
nil
,
ErrNoValue
(
errors
.
Errorf
(
"%v is not a value"
,
key
))
}
// check table for key and ensure value is not a table
if
k
,
ok
:=
t
[
sk
];
ok
&&
!
istable
(
k
)
{
// key found
if
k
,
ok
:=
t
[
key
];
ok
&&
!
istable
(
k
)
{
return
k
,
nil
}
// key not found
return
nil
,
ErrNoValue
(
errors
.
Errorf
(
"key not found: %s"
,
sk
))
return
nil
,
ErrNoValue
(
errors
.
Errorf
(
"key not found: %s"
,
key
))
}
func
parsePath
(
key
string
)
[]
string
{
return
strings
.
Split
(
key
,
"."
)
}
func
joinPath
(
path
...
string
)
string
{
return
strings
.
Join
(
path
,
"."
)
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets