Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
ksonnet
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ijaz Ahmad
ksonnet
Commits
eaec9fba
Commit
eaec9fba
authored
7 years ago
by
Jessica Yuen
Browse files
Options
Downloads
Patches
Plain Diff
Move component param logic out of manager.go
Signed-off-by:
Jessica Yuen
<
im.jessicayuen@gmail.com
>
parent
2dbd7ecc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
metadata/component.go
+60
-0
60 additions, 0 deletions
metadata/component.go
metadata/component_test.go
+18
-0
18 additions, 0 deletions
metadata/component_test.go
metadata/manager.go
+0
-61
0 additions, 61 deletions
metadata/manager.go
metadata/manager_test.go
+0
-18
0 additions, 18 deletions
metadata/manager_test.go
with
78 additions
and
79 deletions
metadata/component.go
+
60
−
0
View file @
eaec9fba
...
...
@@ -171,6 +171,38 @@ func (m *manager) DeleteComponent(name string) error {
return
nil
}
func
(
m
*
manager
)
GetComponentParams
(
component
string
)
(
param
.
Params
,
error
)
{
text
,
err
:=
afero
.
ReadFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
))
if
err
!=
nil
{
return
nil
,
err
}
return
param
.
GetComponentParams
(
component
,
string
(
text
))
}
func
(
m
*
manager
)
GetAllComponentParams
()
(
map
[
string
]
param
.
Params
,
error
)
{
text
,
err
:=
afero
.
ReadFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
))
if
err
!=
nil
{
return
nil
,
err
}
return
param
.
GetAllComponentParams
(
string
(
text
))
}
func
(
m
*
manager
)
SetComponentParams
(
component
string
,
params
param
.
Params
)
error
{
text
,
err
:=
afero
.
ReadFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
))
if
err
!=
nil
{
return
err
}
jsonnet
,
err
:=
param
.
SetComponentParams
(
component
,
string
(
text
),
params
)
if
err
!=
nil
{
return
err
}
return
afero
.
WriteFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
),
[]
byte
(
jsonnet
),
defaultFilePermissions
)
}
func
(
m
*
manager
)
findComponentPath
(
name
string
)
(
string
,
error
)
{
componentPaths
,
err
:=
m
.
ComponentPaths
()
if
err
!=
nil
{
...
...
@@ -198,3 +230,31 @@ func (m *manager) findComponentPath(name string) (string, error) {
return
componentPath
,
nil
}
func
(
m
*
manager
)
writeComponentParams
(
componentName
string
,
params
param
.
Params
)
error
{
text
,
err
:=
afero
.
ReadFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
))
if
err
!=
nil
{
return
err
}
appended
,
err
:=
param
.
AppendComponent
(
componentName
,
string
(
text
),
params
)
if
err
!=
nil
{
return
err
}
return
afero
.
WriteFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
),
[]
byte
(
appended
),
defaultFilePermissions
)
}
func
genComponentParamsContent
()
[]
byte
{
return
[]
byte
(
`{
global: {
// User-defined global parameters; accessible to all component and environments, Ex:
// replicas: 4,
},
components: {
// Component-level parameters, defined initially from 'ks prototype use ...'
// Each object below should correspond to a component in the components/ directory
},
}
`
)
}
This diff is collapsed.
Click to expand it.
metadata/component_test.go
+
18
−
0
View file @
eaec9fba
...
...
@@ -138,3 +138,21 @@ func TestFindComponentPath(t *testing.T) {
t
.
Fatalf
(
"m.findComponentPath failed; expected '%s', got '%s'"
,
expected
,
path
)
}
}
func
TestGenComponentParamsContent
(
t
*
testing
.
T
)
{
expected
:=
`{
global: {
// User-defined global parameters; accessible to all component and environments, Ex:
// replicas: 4,
},
components: {
// Component-level parameters, defined initially from 'ks prototype use ...'
// Each object below should correspond to a component in the components/ directory
},
}
`
content
:=
string
(
genComponentParamsContent
())
if
content
!=
expected
{
t
.
Fatalf
(
"Expected to generate:
\n
%s
\n
, got:
\n
%s"
,
expected
,
content
)
}
}
This diff is collapsed.
Click to expand it.
metadata/manager.go
+
0
−
61
View file @
eaec9fba
...
...
@@ -23,7 +23,6 @@ import (
"github.com/ksonnet/ksonnet/generator"
"github.com/ksonnet/ksonnet/metadata/app"
param
"github.com/ksonnet/ksonnet/metadata/params"
"github.com/ksonnet/ksonnet/metadata/registry"
log
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
...
...
@@ -223,38 +222,6 @@ func (m *manager) EnvPaths(env string) (metadataPath, mainPath, paramsPath, spec
return
}
func
(
m
*
manager
)
GetComponentParams
(
component
string
)
(
param
.
Params
,
error
)
{
text
,
err
:=
afero
.
ReadFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
))
if
err
!=
nil
{
return
nil
,
err
}
return
param
.
GetComponentParams
(
component
,
string
(
text
))
}
func
(
m
*
manager
)
GetAllComponentParams
()
(
map
[
string
]
param
.
Params
,
error
)
{
text
,
err
:=
afero
.
ReadFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
))
if
err
!=
nil
{
return
nil
,
err
}
return
param
.
GetAllComponentParams
(
string
(
text
))
}
func
(
m
*
manager
)
SetComponentParams
(
component
string
,
params
param
.
Params
)
error
{
text
,
err
:=
afero
.
ReadFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
))
if
err
!=
nil
{
return
err
}
jsonnet
,
err
:=
param
.
SetComponentParams
(
component
,
string
(
text
),
params
)
if
err
!=
nil
{
return
err
}
return
afero
.
WriteFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
),
[]
byte
(
jsonnet
),
defaultFilePermissions
)
}
// AppSpec will return the specification for a ksonnet application
// (typically stored in `app.yaml`)
func
(
m
*
manager
)
AppSpec
()
(
*
app
.
Spec
,
error
)
{
...
...
@@ -356,34 +323,6 @@ func (m *manager) createAppDirTree(name string, appYAMLData, baseLibData []byte,
return
nil
}
func
(
m
*
manager
)
writeComponentParams
(
componentName
string
,
params
param
.
Params
)
error
{
text
,
err
:=
afero
.
ReadFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
))
if
err
!=
nil
{
return
err
}
appended
,
err
:=
param
.
AppendComponent
(
componentName
,
string
(
text
),
params
)
if
err
!=
nil
{
return
err
}
return
afero
.
WriteFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
),
[]
byte
(
appended
),
defaultFilePermissions
)
}
func
genComponentParamsContent
()
[]
byte
{
return
[]
byte
(
`{
global: {
// User-defined global parameters; accessible to all component and environments, Ex:
// replicas: 4,
},
components: {
// Component-level parameters, defined initially from 'ks prototype use ...'
// Each object below should correspond to a component in the components/ directory
},
}
`
)
}
func
generateRegistryYAMLData
(
incubatorReg
registry
.
Manager
)
([]
byte
,
error
)
{
regSpec
,
err
:=
incubatorReg
.
FetchRegistrySpec
()
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
metadata/manager_test.go
+
0
−
18
View file @
eaec9fba
...
...
@@ -277,21 +277,3 @@ func TestDoubleNewFailure(t *testing.T) {
t
.
Fatalf
(
"Expected to fail to create app with message '%s', got '%s'"
,
targetErr
,
err
.
Error
())
}
}
func
TestGenComponentParamsContent
(
t
*
testing
.
T
)
{
expected
:=
`{
global: {
// User-defined global parameters; accessible to all component and environments, Ex:
// replicas: 4,
},
components: {
// Component-level parameters, defined initially from 'ks prototype use ...'
// Each object below should correspond to a component in the components/ directory
},
}
`
content
:=
string
(
genComponentParamsContent
())
if
content
!=
expected
{
t
.
Fatalf
(
"Expected to generate:
\n
%s
\n
, got:
\n
%s"
,
expected
,
content
)
}
}
This diff is collapsed.
Click to expand it.
Preview
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