Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beaver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orus-io
beaver
Commits
a367b04352c7
Commit
a367b04352c7
authored
2 years ago
by
Florent Aide
Browse files
Options
Downloads
Patches
Plain Diff
reorge to allow easier chart segregation
parent
00dd885393fa
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
runner/config.go
+34
-20
34 additions, 20 deletions
runner/config.go
runner/config_test.go
+11
-2
11 additions, 2 deletions
runner/config_test.go
runner/fixtures/beaver.yml
+19
-20
19 additions, 20 deletions
runner/fixtures/beaver.yml
with
64 additions
and
42 deletions
runner/config.go
+
34
−
20
View file @
a367b043
...
...
@@ -22,9 +22,9 @@
Value
string
`mapstructure:"value"`
}
type
Chart
struct
{
type
Helm
Chart
struct
{
Type
string
`mapstructure:"type"`
Name
string
`mapstructure:"name"`
Values
interface
{}
`mapstructure:"values"`
}
...
...
@@ -26,7 +26,18 @@
Type
string
`mapstructure:"type"`
Name
string
`mapstructure:"name"`
Values
interface
{}
`mapstructure:"values"`
}
type
YttChart
struct
{
Type
string
`mapstructure:"type"`
Name
string
`mapstructure:"name"`
Values
[]
Value
`mapstructure:"values"`
}
type
Charts
struct
{
Helm
map
[
string
]
HelmChart
`mapstructure:"helm"`
Ytt
map
[
string
]
YttChart
`mapstructure:"ytt"`
}
// Spec ...
type
Spec
struct
{
...
...
@@ -31,7 +42,7 @@
// Spec ...
type
Spec
struct
{
Variables
[]
Variable
`mapstructure:"variables"`
Charts
map
[
string
]
Chart
`mapstructure:"charts"`
Variables
[]
Variable
`mapstructure:"variables"`
Charts
Chart
s
`mapstructure:"charts"`
}
// Config is the configuration we get after parsing our beaver.yml file
...
...
@@ -67,7 +78,10 @@
// hydrate expands templated variables in our config with concrete values
func
(
c
*
Config
)
hydrate
()
error
{
if
err
:=
c
.
hydrateCharts
();
err
!=
nil
{
if
err
:=
c
.
hydrateHelmCharts
();
err
!=
nil
{
return
err
}
if
err
:=
c
.
hydrateYttCharts
();
err
!=
nil
{
return
err
}
return
nil
...
...
@@ -82,10 +96,17 @@
return
variables
}
/*
func (c *Config) hydrateYtt() error {
for index, entry := range c.Spec.Ytt {
valueTmpl, err := template.New("entry").Parse(entry.Value)
if err != nil {
return fmt.Errorf("failed to parse ytt entry value as template: %q, %w", entry.Value, err)
func
(
c
*
Config
)
hydrateYttCharts
()
error
{
for
entryFileName
,
entry
:=
range
c
.
Spec
.
Charts
.
Ytt
{
for
valIndex
,
val
:=
range
entry
.
Values
{
valueTmpl
,
err
:=
template
.
New
(
"ytt entry value"
)
.
Parse
(
val
.
Value
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to parse ytt entry value as template: %q, %w"
,
val
.
Value
,
err
)
}
buf
:=
new
(
bytes
.
Buffer
)
if
err
:=
valueTmpl
.
Execute
(
buf
,
c
.
prepareVariables
(
c
.
Spec
.
Variables
));
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to hydrate ytt entry: %q, %w"
,
val
.
Value
,
err
)
}
// replace original content with hydrated version
c
.
Spec
.
Charts
.
Ytt
[
entryFileName
]
.
Values
[
valIndex
]
.
Value
=
buf
.
String
()
}
...
...
@@ -91,10 +112,4 @@
}
buf := new(bytes.Buffer)
if err := valueTmpl.Execute(buf, c.prepareVariables(c.Spec.Variables)); err != nil {
return fmt.Errorf("failed to hydrate ytt entry: %q, %w", entry.Value, err)
}
// replace original content with hydrated version
c.Spec.Ytt[index].Value = buf.String()
}
return
nil
}
...
...
@@ -98,5 +113,4 @@
}
return
nil
}
*/
...
...
@@ -102,6 +116,6 @@
func
(
c
*
Config
)
hydrateCharts
()
error
{
for
name
,
chart
:=
range
c
.
Spec
.
Charts
{
func
(
c
*
Config
)
hydrate
Helm
Charts
()
error
{
for
name
,
chart
:=
range
c
.
Spec
.
Charts
.
Helm
{
rawChartValues
,
err
:=
yaml
.
Marshal
(
chart
.
Values
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get chart values as string: %w"
,
err
)
...
...
@@ -117,7 +131,7 @@
// replace original content with hydrated version
hydratedChart
:=
chart
hydratedChart
.
Values
=
buf
.
String
()
c
.
Spec
.
Charts
[
name
]
=
hydratedChart
c
.
Spec
.
Charts
.
Helm
[
name
]
=
hydratedChart
}
return
nil
}
This diff is collapsed.
Click to expand it.
runner/config_test.go
+
11
−
2
View file @
a367b043
...
...
@@ -11,7 +11,8 @@
func
TestConfig
(
t
*
testing
.
T
)
{
logger
:=
testutils
.
GetLogger
(
t
)
configDir
:=
"fixtures/"
config
,
err
:=
NewConfig
(
logger
,
configDir
,
"ns1"
)
testNS
:=
"ns1"
config
,
err
:=
NewConfig
(
logger
,
configDir
,
testNS
)
require
.
NoError
(
t
,
err
)
// first config.spec.variables entry name should be VAULT_KV in our test file
assert
.
Equal
(
t
,
"VAULT_KV"
,
config
.
Spec
.
Variables
[
0
]
.
Name
)
...
...
@@ -23,5 +24,5 @@
password: <path:cnpp.k8s.cloudcrane.io/data/ns1/postgres#password>
fullnameoverride: pg-exporter-ns1
`
,
config
.
Spec
.
Charts
[
"postgres"
]
.
Values
,
config
.
Spec
.
Charts
.
Helm
[
"postgres"
]
.
Values
,
)
...
...
@@ -27,2 +28,10 @@
)
// verify ytt entries
assert
.
Equal
(
t
,
"cnpp.k8s.cloudcrane.io"
,
config
.
Spec
.
Charts
.
Ytt
[
"odoo"
]
.
Values
[
0
]
.
Value
)
assert
.
Equal
(
t
,
testNS
,
config
.
Spec
.
Charts
.
Ytt
[
"odoo"
]
.
Values
[
1
]
.
Value
)
// yaml support should let toto entry use DEFAULT_VALUES defined in odoo
assert
.
Equal
(
t
,
"cnpp.k8s.cloudcrane.io"
,
config
.
Spec
.
Charts
.
Ytt
[
"toto"
]
.
Values
[
0
]
.
Value
)
assert
.
Equal
(
t
,
testNS
,
config
.
Spec
.
Charts
.
Ytt
[
"toto"
]
.
Values
[
1
]
.
Value
)
}
This diff is collapsed.
Click to expand it.
runner/fixtures/beaver.yml
+
19
−
20
View file @
a367b043
...
...
@@ -5,23 +5,22 @@
-
name
:
VAULT_KV
value
:
cnpp.k8s.cloudcrane.io
charts
:
postgres
:
type
:
helm
name
:
postgresql
values
:
config
:
datasource
:
password
:
"
<path:{{.VAULT_KV}}/data/{{.namespace}}/postgres#password>"
fullnameOverride
:
"
pg-exporter-{{.namespace}}"
odoo
:
type
:
ytt
name
:
odoo
values
:
&DEFAULT_VALUES
-
key
:
vault.kv
value
:
"
{{.VAULT_KV}}"
-
key
:
namespace
value
:
"
{{.namespace}}"
toto
:
type
:
ytt
name
:
odoo
values
:
*DEFAULT_VALUES
helm
:
postgres
:
name
:
postgresql
values
:
config
:
datasource
:
password
:
"
<path:{{.VAULT_KV}}/data/{{.namespace}}/postgres#password>"
fullnameOverride
:
"
pg-exporter-{{.namespace}}"
ytt
:
odoo
:
name
:
odoo
values
:
&DEFAULT_VALUES
-
key
:
vault.kv
value
:
"
{{.VAULT_KV}}"
-
key
:
namespace
value
:
"
{{.namespace}}"
toto
:
name
:
toto
values
:
*DEFAULT_VALUES
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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