Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Helm
Commits
58c8aca1
Commit
58c8aca1
authored
8 years ago
by
Justin Scott
Browse files
Options
Download
Email Patches
Plain Diff
feat(helm): fixup if/ele,remove extra string casts, add comments
parent
004c5bcc
No related merge requests found
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
pkg/chartutil/requirements.go
+64
-55
pkg/chartutil/requirements.go
pkg/chartutil/requirements_test.go
+11
-11
pkg/chartutil/requirements_test.go
pkg/chartutil/testdata/subpop/Chart.yaml
+1
-1
pkg/chartutil/testdata/subpop/Chart.yaml
pkg/chartutil/testdata/subpop/charts/subchart1/requirements.yaml
+1
-1
...rtutil/testdata/subpop/charts/subchart1/requirements.yaml
pkg/chartutil/testdata/subpop/charts/subchart2/requirements.yaml
+1
-1
...rtutil/testdata/subpop/charts/subchart2/requirements.yaml
pkg/chartutil/testdata/subpop/noreqs/Chart.yaml
+1
-1
pkg/chartutil/testdata/subpop/noreqs/Chart.yaml
pkg/chartutil/testdata/subpop/noreqs/values.yaml
+0
-1
pkg/chartutil/testdata/subpop/noreqs/values.yaml
pkg/chartutil/testdata/subpop/requirements.yaml
+1
-1
pkg/chartutil/testdata/subpop/requirements.yaml
pkg/chartutil/values.go
+8
-4
pkg/chartutil/values.go
with
88 additions
and
76 deletions
+88
-76
pkg/chartutil/requirements.go
+
64
-
55
View file @
58c8aca1
...
...
@@ -121,52 +121,55 @@ func LoadRequirementsLock(c *chart.Chart) (*RequirementsLock, error) {
func
ProcessRequirementsConditions
(
reqs
*
Requirements
,
cvals
Values
)
{
var
cond
string
var
conds
[]
string
if
reqs
!=
nil
&&
len
(
reqs
.
Dependencies
)
>
0
{
for
_
,
r
:=
range
reqs
.
Dependencies
{
var
hasTrue
,
hasFalse
bool
cond
=
string
(
r
.
Condition
)
// check for list
if
len
(
cond
)
>
0
{
if
strings
.
Contains
(
cond
,
","
)
{
conds
=
strings
.
Split
(
strings
.
TrimSpace
(
cond
),
","
)
}
else
{
conds
=
[]
string
{
strings
.
TrimSpace
(
cond
)}
}
for
_
,
c
:=
range
conds
{
if
len
(
c
)
>
0
{
// retrieve value
vv
,
err
:=
cvals
.
PathValue
(
c
)
if
err
==
nil
{
if
vv
.
(
bool
)
{
if
reqs
==
nil
||
len
(
reqs
.
Dependencies
)
==
0
{
return
}
for
_
,
r
:=
range
reqs
.
Dependencies
{
var
hasTrue
,
hasFalse
bool
cond
=
string
(
r
.
Condition
)
// check for list
if
len
(
cond
)
>
0
{
if
strings
.
Contains
(
cond
,
","
)
{
conds
=
strings
.
Split
(
strings
.
TrimSpace
(
cond
),
","
)
}
else
{
conds
=
[]
string
{
strings
.
TrimSpace
(
cond
)}
}
for
_
,
c
:=
range
conds
{
if
len
(
c
)
>
0
{
// retrieve value
vv
,
err
:=
cvals
.
PathValue
(
c
)
if
err
==
nil
{
// if not bool, warn
if
bv
,
ok
:=
vv
.
(
bool
);
ok
{
if
bv
{
hasTrue
=
true
}
if
!
vv
.
(
bool
)
{
}
else
{
hasFalse
=
true
}
}
else
{
if
_
,
ok
:=
err
.
(
ErrNoValue
);
!
ok
{
// this is a real error
log
.
Printf
(
"Warning: PathValue returned error %v"
,
err
)
}
}
if
vv
!=
nil
{
// got first value, break loop
break
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
)
}
}
if
!
hasTrue
&&
hasFalse
{
r
.
Enabled
=
false
}
else
{
if
hasTrue
{
r
.
Enabled
=
true
if
vv
!=
nil
{
// got first value, break loop
break
}
}
}
if
!
hasTrue
&&
hasFalse
{
r
.
Enabled
=
false
}
else
if
hasTrue
{
r
.
Enabled
=
true
}
}
}
}
// ProcessRequirementsTags disables charts based on tags in values
...
...
@@ -176,33 +179,38 @@ func ProcessRequirementsTags(reqs *Requirements, cvals Values) {
return
}
if
reqs
!=
nil
&&
len
(
reqs
.
Dependencies
)
>
0
{
for
_
,
r
:=
range
reqs
.
Dependencies
{
if
len
(
r
.
Tags
)
>
0
{
tags
:=
r
.
Tags
if
reqs
==
nil
||
len
(
reqs
.
Dependencies
)
==
0
{
return
}
for
_
,
r
:=
range
reqs
.
Dependencies
{
if
len
(
r
.
Tags
)
>
0
{
tags
:=
r
.
Tags
var
hasTrue
,
hasFalse
bool
for
_
,
k
:=
range
tags
{
if
b
,
ok
:=
vt
[
k
];
ok
{
if
b
.
(
bool
)
{
var
hasTrue
,
hasFalse
bool
for
_
,
k
:=
range
tags
{
if
b
,
ok
:=
vt
[
k
];
ok
{
// if not bool, warn
if
bv
,
ok
:=
b
.
(
bool
);
ok
{
if
bv
{
hasTrue
=
true
}
if
!
b
.
(
bool
)
{
}
else
{
hasFalse
=
true
}
}
else
{
log
.
Printf
(
"Warning: Tag '%s' for chart %s returned non-bool value"
,
k
,
r
.
Name
)
}
}
if
!
hasTrue
&&
hasFalse
{
r
.
Enabled
=
false
}
else
{
if
hasTrue
||
!
hasTrue
&&
!
hasFalse
{
r
.
Enabled
=
true
}
}
}
if
!
hasTrue
&&
hasFalse
{
r
.
Enabled
=
false
}
else
if
hasTrue
||
!
hasTrue
&&
!
hasFalse
{
r
.
Enabled
=
true
}
}
}
}
// ProcessRequirementsEnabled removes disabled charts from dependencies
...
...
@@ -212,10 +220,10 @@ func ProcessRequirementsEnabled(c *chart.Chart, v *chart.Config) error {
// if not just missing requirements file, return error
if
nerr
,
ok
:=
err
.
(
ErrNoRequirementsFile
);
!
ok
{
return
nerr
}
else
{
// no requirements to process
return
nil
}
// no requirements to process
return
nil
}
// set all to true
for
_
,
lr
:=
range
reqs
.
Dependencies
{
...
...
@@ -238,7 +246,8 @@ func ProcessRequirementsEnabled(c *chart.Chart, v *chart.Config) error {
}
}
// don't keep disabled charts in new slice
cd
:=
c
.
Dependencies
[
:
0
]
cd
:=
[]
*
chart
.
Chart
{}
copy
(
cd
,
c
.
Dependencies
[
:
0
])
for
_
,
n
:=
range
c
.
Dependencies
{
if
_
,
ok
:=
rm
[
n
.
Metadata
.
Name
];
!
ok
{
cd
=
append
(
cd
,
n
)
...
...
This diff is collapsed.
Click to expand it.
pkg/chartutil/requirements_test.go
+
11
-
11
View file @
58c8aca1
...
...
@@ -42,7 +42,7 @@ func TestRequirementsTagsNonValue(t *testing.T) {
t
.
Fatalf
(
"Failed to load testdata: %s"
,
err
)
}
// tags with no effect
v
:=
&
chart
.
Config
{
Raw
:
string
(
"tags:
\n
nothinguseful: false
\n\n
"
)
}
v
:=
&
chart
.
Config
{
Raw
:
"tags:
\n
nothinguseful: false
\n\n
"
}
// expected charts including duplicates in alphanumeric order
e
:=
[]
string
{
"parentchart"
,
"subchart1"
,
"subcharta"
,
"subchartb"
}
...
...
@@ -54,7 +54,7 @@ func TestRequirementsTagsDisabledL1(t *testing.T) {
t
.
Fatalf
(
"Failed to load testdata: %s"
,
err
)
}
// tags disabling a group
v
:=
&
chart
.
Config
{
Raw
:
string
(
"tags:
\n
front-end: false
\n\n
"
)
}
v
:=
&
chart
.
Config
{
Raw
:
"tags:
\n
front-end: false
\n\n
"
}
// expected charts including duplicates in alphanumeric order
e
:=
[]
string
{
"parentchart"
}
...
...
@@ -66,7 +66,7 @@ func TestRequirementsTagsEnabledL1(t *testing.T) {
t
.
Fatalf
(
"Failed to load testdata: %s"
,
err
)
}
// tags disabling a group and enabling a different group
v
:=
&
chart
.
Config
{
Raw
:
string
(
"tags:
\n
front-end: false
\n\n
back-end: true
\n
"
)
}
v
:=
&
chart
.
Config
{
Raw
:
"tags:
\n
front-end: false
\n\n
back-end: true
\n
"
}
// expected charts including duplicates in alphanumeric order
e
:=
[]
string
{
"parentchart"
,
"subchart2"
,
"subchartb"
,
"subchartc"
}
...
...
@@ -78,7 +78,7 @@ func TestRequirementsTagsDisabledL2(t *testing.T) {
t
.
Fatalf
(
"Failed to load testdata: %s"
,
err
)
}
// tags disabling only children
v
:=
&
chart
.
Config
{
Raw
:
string
(
"tags:
\n
subcharta: false
\n\n
subchartb: false
\n
"
)
}
v
:=
&
chart
.
Config
{
Raw
:
"tags:
\n
subcharta: false
\n\n
subchartb: false
\n
"
}
// expected charts including duplicates in alphanumeric order
e
:=
[]
string
{
"parentchart"
,
"subchart1"
}
...
...
@@ -90,7 +90,7 @@ func TestRequirementsTagsDisabledL1Mixed(t *testing.T) {
t
.
Fatalf
(
"Failed to load testdata: %s"
,
err
)
}
// tags disabling all parents/children with additional tag re-enabling a parent
v
:=
&
chart
.
Config
{
Raw
:
string
(
"tags:
\n
front-end: false
\n\n
subchart1: true
\n\n
back-end: false
\n
"
)
}
v
:=
&
chart
.
Config
{
Raw
:
"tags:
\n
front-end: false
\n\n
subchart1: true
\n\n
back-end: false
\n
"
}
// expected charts including duplicates in alphanumeric order
e
:=
[]
string
{
"parentchart"
,
"subchart1"
}
...
...
@@ -102,7 +102,7 @@ func TestRequirementsConditionsNonValue(t *testing.T) {
t
.
Fatalf
(
"Failed to load testdata: %s"
,
err
)
}
// tags with no effect
v
:=
&
chart
.
Config
{
Raw
:
string
(
"subchart1:
\n
nothinguseful: false
\n\n
"
)
}
v
:=
&
chart
.
Config
{
Raw
:
"subchart1:
\n
nothinguseful: false
\n\n
"
}
// expected charts including duplicates in alphanumeric order
e
:=
[]
string
{
"parentchart"
,
"subchart1"
,
"subcharta"
,
"subchartb"
}
...
...
@@ -114,7 +114,7 @@ func TestRequirementsConditionsEnabledL1Both(t *testing.T) {
t
.
Fatalf
(
"Failed to load testdata: %s"
,
err
)
}
// conditions enabling the parent charts, effectively enabling children
v
:=
&
chart
.
Config
{
Raw
:
string
(
"subchart1:
\n
enabled: true
\n
subchart2:
\n
enabled: true
\n
"
)
}
v
:=
&
chart
.
Config
{
Raw
:
"subchart1:
\n
enabled: true
\n
subchart2:
\n
enabled: true
\n
"
}
// expected charts including duplicates in alphanumeric order
e
:=
[]
string
{
"parentchart"
,
"subchart1"
,
"subchart2"
,
"subcharta"
,
"subchartb"
,
"subchartb"
,
"subchartc"
}
...
...
@@ -126,7 +126,7 @@ func TestRequirementsConditionsDisabledL1Both(t *testing.T) {
t
.
Fatalf
(
"Failed to load testdata: %s"
,
err
)
}
// conditions disabling the parent charts, effectively disabling children
v
:=
&
chart
.
Config
{
Raw
:
string
(
"subchart1:
\n
enabled: false
\n
subchart2:
\n
enabled: false
\n
"
)
}
v
:=
&
chart
.
Config
{
Raw
:
"subchart1:
\n
enabled: false
\n
subchart2:
\n
enabled: false
\n
"
}
// expected charts including duplicates in alphanumeric order
e
:=
[]
string
{
"parentchart"
}
...
...
@@ -139,7 +139,7 @@ func TestRequirementsConditionsSecond(t *testing.T) {
t
.
Fatalf
(
"Failed to load testdata: %s"
,
err
)
}
// conditions a child using the second condition path of child's condition
v
:=
&
chart
.
Config
{
Raw
:
string
(
"subchart1:
\n
subcharta:
\n
enabled: false
\n
"
)
}
v
:=
&
chart
.
Config
{
Raw
:
"subchart1:
\n
subcharta:
\n
enabled: false
\n
"
}
// expected charts including duplicates in alphanumeric order
e
:=
[]
string
{
"parentchart"
,
"subchart1"
,
"subchartb"
}
...
...
@@ -151,7 +151,7 @@ func TestRequirementsCombinedDisabledL2(t *testing.T) {
t
.
Fatalf
(
"Failed to load testdata: %s"
,
err
)
}
// tags enabling a parent/child group with condition disabling one child
v
:=
&
chart
.
Config
{
Raw
:
string
(
"subchartc:
\n
enabled: false
\n
tags:
\n
back-end: true
\n
"
)
}
v
:=
&
chart
.
Config
{
Raw
:
"subchartc:
\n
enabled: false
\n
tags:
\n
back-end: true
\n
"
}
// expected charts including duplicates in alphanumeric order
e
:=
[]
string
{
"parentchart"
,
"subchart1"
,
"subchart2"
,
"subcharta"
,
"subchartb"
,
"subchartb"
}
...
...
@@ -163,7 +163,7 @@ func TestRequirementsCombinedDisabledL1(t *testing.T) {
t
.
Fatalf
(
"Failed to load testdata: %s"
,
err
)
}
// tags will not enable a child if parent is explicitly disabled with condition
v
:=
&
chart
.
Config
{
Raw
:
string
(
"subchart1:
\n
enabled: false
\n
tags:
\n
front-end: true
\n
"
)
}
v
:=
&
chart
.
Config
{
Raw
:
"subchart1:
\n
enabled: false
\n
tags:
\n
front-end: true
\n
"
}
// expected charts including duplicates in alphanumeric order
e
:=
[]
string
{
"parentchart"
}
...
...
This diff is collapsed.
Click to expand it.
pkg/chartutil/testdata/subpop/Chart.yaml
+
1
-
1
View file @
58c8aca1
apiVersion
:
v1
description
:
A Helm chart for Kubernetes
name
:
parentchart
version
:
0.1.0
\ No newline at end of file
version
:
0.1.0
This diff is collapsed.
Click to expand it.
pkg/chartutil/testdata/subpop/charts/subchart1/requirements.yaml
+
1
-
1
View file @
58c8aca1
...
...
@@ -12,4 +12,4 @@ dependencies:
condition
:
subchartb.enabled
tags
:
-
front-end
-
subchartb
\ No newline at end of file
-
subchartb
This diff is collapsed.
Click to expand it.
pkg/chartutil/testdata/subpop/charts/subchart2/requirements.yaml
+
1
-
1
View file @
58c8aca1
...
...
@@ -12,4 +12,4 @@ dependencies:
condition
:
subchartc.enabled
tags
:
-
back-end
-
subchartc
\ No newline at end of file
-
subchartc
This diff is collapsed.
Click to expand it.
pkg/chartutil/testdata/subpop/noreqs/Chart.yaml
+
1
-
1
View file @
58c8aca1
apiVersion
:
v1
description
:
A Helm chart for Kubernetes
name
:
parentchart
version
:
0.1.0
\ No newline at end of file
version
:
0.1.0
This diff is collapsed.
Click to expand it.
pkg/chartutil/testdata/subpop/noreqs/values.yaml
+
0
-
1
View file @
58c8aca1
...
...
@@ -24,4 +24,3 @@ resources:
tags
:
front-end
:
true
back-end
:
false
This diff is collapsed.
Click to expand it.
pkg/chartutil/testdata/subpop/requirements.yaml
+
1
-
1
View file @
58c8aca1
...
...
@@ -12,4 +12,4 @@ dependencies:
condition
:
subchart2.enabled
tags
:
-
back-end
-
subchart2
\ No newline at end of file
-
subchart2
This diff is collapsed.
Click to expand it.
pkg/chartutil/values.go
+
8
-
4
View file @
58c8aca1
...
...
@@ -383,7 +383,7 @@ func istable(v interface{}) bool {
// PathValue takes a yaml path with . notation and returns the value if exists
func
(
v
Values
)
PathValue
(
ypath
string
)
(
interface
{},
error
)
{
if
len
(
ypath
)
==
0
{
return
nil
,
error
(
fmt
.
Errorf
(
"yaml path string cannot be zero length"
)
)
return
nil
,
fmt
.
Errorf
(
"yaml path string cannot be zero length"
)
}
yps
:=
strings
.
Split
(
ypath
,
"."
)
if
len
(
yps
)
==
1
{
...
...
@@ -397,16 +397,20 @@ func (v Values) PathValue(ypath string) (interface{}, error) {
// key not found
return
nil
,
ErrNoValue
(
fmt
.
Errorf
(
"%v is not a value"
,
k
))
}
table
:=
yps
[
:
len
(
yps
)
-
1
]
// join all elements of YAML path except last to get string table path
ypsLen
:=
len
(
yps
)
table
:=
yps
[
:
ypsLen
-
1
]
st
:=
strings
.
Join
(
table
,
"."
)
key
:=
yps
[
len
(
yps
)
-
1
:
]
// get the last element as a string key
key
:=
yps
[
ypsLen
-
1
:
]
sk
:=
string
(
key
[
0
])
// get our table for table path
t
,
err
:=
v
.
Table
(
st
)
if
err
!=
nil
{
//no table
return
nil
,
ErrNoValue
(
fmt
.
Errorf
(
"%v is not a value"
,
sk
))
}
// check table for key and ensure value is not a table
if
k
,
ok
:=
t
[
sk
];
ok
&&
!
istable
(
k
)
{
// key found
return
k
,
nil
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help