Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ijaz Ahmad
ksonnet
Commits
a019cf82
Commit
a019cf82
authored
Jun 19, 2018
by
Oren Shomron
Browse files
Rename EnvironmentSpec[s] -> EnvironmentConfig[s]
Signed-off-by:
Oren Shomron
<
shomron@gmail.com
>
parent
d44b841c
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
211 additions
and
161 deletions
+211
-161
pkg/actions/env_describe_test.go
pkg/actions/env_describe_test.go
+1
-1
pkg/actions/env_list_test.go
pkg/actions/env_list_test.go
+2
-2
pkg/actions/env_set.go
pkg/actions/env_set.go
+5
-5
pkg/actions/env_set_test.go
pkg/actions/env_set_test.go
+10
-10
pkg/actions/env_targets_test.go
pkg/actions/env_targets_test.go
+3
-3
pkg/actions/env_update_test.go
pkg/actions/env_update_test.go
+1
-1
pkg/actions/validate_test.go
pkg/actions/validate_test.go
+1
-1
pkg/app/app.go
pkg/app/app.go
+3
-3
pkg/app/app001.go
pkg/app/app001.go
+7
-7
pkg/app/app001_test.go
pkg/app/app001_test.go
+6
-6
pkg/app/app010.go
pkg/app/app010.go
+4
-4
pkg/app/app010_test.go
pkg/app/app010_test.go
+10
-6
pkg/app/base_app.go
pkg/app/base_app.go
+4
-4
pkg/app/mocks/App.go
pkg/app/mocks/App.go
+10
-10
pkg/app/override.go
pkg/app/override.go
+4
-4
pkg/app/schema.go
pkg/app/schema.go
+69
-51
pkg/app/schema_test.go
pkg/app/schema_test.go
+66
-38
pkg/appinit/init.go
pkg/appinit/init.go
+1
-1
pkg/component/delete.go
pkg/component/delete.go
+2
-2
pkg/component/delete_test.go
pkg/component/delete_test.go
+2
-2
No files found.
pkg/actions/env_describe_test.go
View file @
a019cf82
...
...
@@ -28,7 +28,7 @@ func TestEnvDescribe(t *testing.T) {
withApp
(
t
,
func
(
appMock
*
amocks
.
App
)
{
envName
:=
"default"
env
:=
&
app
.
Environment
Spec
{
env
:=
&
app
.
Environment
Config
{
KubernetesVersion
:
"v1.7.0"
,
}
...
...
pkg/actions/env_list_test.go
View file @
a019cf82
...
...
@@ -29,14 +29,14 @@ import (
func
TestEnvList
(
t
*
testing
.
T
)
{
withApp
(
t
,
func
(
appMock
*
amocks
.
App
)
{
env
:=
&
app
.
Environment
Spec
{
env
:=
&
app
.
Environment
Config
{
KubernetesVersion
:
"v1.7.0"
,
Destination
:
&
app
.
EnvironmentDestinationSpec
{
Namespace
:
"default"
,
Server
:
"http://example.com"
,
},
}
envs
:=
app
.
Environment
Spec
s
{
envs
:=
app
.
Environment
Config
s
{
"default"
:
env
,
}
...
...
pkg/actions/env_set.go
View file @
a019cf82
...
...
@@ -50,7 +50,7 @@ func RunEnvSet(m map[string]interface{}) error {
// func types for renaming and updating environments
type
envRenameFn
func
(
a
app
.
App
,
from
,
to
string
,
override
bool
)
error
type
updateEnvFn
func
(
a
app
.
App
,
envName
,
k8sAPISpec
string
,
spec
*
app
.
Environment
Spec
,
override
bool
)
error
type
updateEnvFn
func
(
a
app
.
App
,
envName
,
k8sAPISpec
string
,
spec
*
app
.
Environment
Config
,
override
bool
)
error
// EnvSet sets targets for an environment.
type
EnvSet
struct
{
...
...
@@ -99,7 +99,7 @@ func (es *EnvSet) Run() error {
return
err
}
if
err
:=
es
.
updateEnv
Spec
(
env
);
err
!=
nil
{
if
err
:=
es
.
updateEnv
Config
(
env
);
err
!=
nil
{
return
err
}
...
...
@@ -118,7 +118,7 @@ func (es *EnvSet) updateName(isOverride bool) error {
return
nil
}
func
(
es
*
EnvSet
)
updateEnv
Spec
(
env
*
app
.
Environment
Spec
)
error
{
func
(
es
*
EnvSet
)
updateEnv
Config
(
env
*
app
.
Environment
Config
)
error
{
if
es
.
newNsName
==
""
&&
es
.
newServer
==
""
&&
es
.
newAPISpec
==
""
{
return
nil
}
...
...
@@ -134,6 +134,6 @@ func (es *EnvSet) updateEnvSpec(env *app.EnvironmentSpec) error {
return
es
.
updateEnvFn
(
es
.
app
,
es
.
envName
,
es
.
newAPISpec
,
env
,
env
.
IsOverride
())
}
func
updateEnv
(
a
app
.
App
,
envName
,
k8sAPISpec
string
,
spec
*
app
.
Environment
Spec
,
override
bool
)
error
{
return
a
.
AddEnvironment
(
envName
,
k8sAPISpec
,
spec
,
override
)
func
updateEnv
(
a
app
.
App
,
envName
,
k8sAPISpec
string
,
env
*
app
.
Environment
Config
,
override
bool
)
error
{
return
a
.
AddEnvironment
(
envName
,
k8sAPISpec
,
env
,
override
)
}
pkg/actions/env_set_test.go
View file @
a019cf82
...
...
@@ -33,8 +33,8 @@ func TestEnvSet(t *testing.T) {
server
:=
"new_server"
newk8sAPISpec
:=
"version:new_api_spec"
environmentMockFn
:=
func
(
name
string
)
*
app
.
Environment
Spec
{
return
&
app
.
Environment
Spec
{
environmentMockFn
:=
func
(
name
string
)
*
app
.
Environment
Config
{
return
&
app
.
Environment
Config
{
Destination
:
&
app
.
EnvironmentDestinationSpec
{
Namespace
:
oldNamespace
,
Server
:
oldServer
,
...
...
@@ -46,7 +46,7 @@ func TestEnvSet(t *testing.T) {
cases
:=
[]
struct
{
name
string
in
map
[
string
]
interface
{}
spec
*
app
.
Environment
Spec
spec
*
app
.
Environment
Config
envRenameFn
func
(
t
*
testing
.
T
)
envRenameFn
updateEnvFn
func
(
t
*
testing
.
T
)
updateEnvFn
}{
...
...
@@ -75,8 +75,8 @@ func TestEnvSet(t *testing.T) {
OptionNamespace
:
namespace
,
},
updateEnvFn
:
func
(
t
*
testing
.
T
)
updateEnvFn
{
return
func
(
a
app
.
App
,
envName
,
k8sAPISpec
string
,
spec
*
app
.
Environment
Spec
,
override
bool
)
error
{
assert
.
Equal
(
t
,
spec
,
&
app
.
Environment
Spec
{
return
func
(
a
app
.
App
,
envName
,
k8sAPISpec
string
,
spec
*
app
.
Environment
Config
,
override
bool
)
error
{
assert
.
Equal
(
t
,
spec
,
&
app
.
Environment
Config
{
Destination
:
&
app
.
EnvironmentDestinationSpec
{
Namespace
:
namespace
,
Server
:
oldServer
,
...
...
@@ -94,8 +94,8 @@ func TestEnvSet(t *testing.T) {
OptionServer
:
server
,
},
updateEnvFn
:
func
(
t
*
testing
.
T
)
updateEnvFn
{
return
func
(
a
app
.
App
,
envName
,
k8sAPISpec
string
,
spec
*
app
.
Environment
Spec
,
override
bool
)
error
{
assert
.
Equal
(
t
,
spec
,
&
app
.
Environment
Spec
{
return
func
(
a
app
.
App
,
envName
,
k8sAPISpec
string
,
spec
*
app
.
Environment
Config
,
override
bool
)
error
{
assert
.
Equal
(
t
,
spec
,
&
app
.
Environment
Config
{
Destination
:
&
app
.
EnvironmentDestinationSpec
{
Namespace
:
oldNamespace
,
Server
:
server
,
...
...
@@ -113,7 +113,7 @@ func TestEnvSet(t *testing.T) {
OptionSpecFlag
:
newk8sAPISpec
,
},
updateEnvFn
:
func
(
t
*
testing
.
T
)
updateEnvFn
{
return
func
(
a
app
.
App
,
envName
,
k8sAPISpec
string
,
spec
*
app
.
Environment
Spec
,
override
bool
)
error
{
return
func
(
a
app
.
App
,
envName
,
k8sAPISpec
string
,
spec
*
app
.
Environment
Config
,
override
bool
)
error
{
assert
.
Equal
(
t
,
newk8sAPISpec
,
k8sAPISpec
)
return
nil
}
...
...
@@ -130,8 +130,8 @@ func TestEnvSet(t *testing.T) {
OptionSpecFlag
:
newk8sAPISpec
,
},
updateEnvFn
:
func
(
t
*
testing
.
T
)
updateEnvFn
{
return
func
(
a
app
.
App
,
newName
,
k8sAPISpec
string
,
spec
*
app
.
Environment
Spec
,
override
bool
)
error
{
assert
.
Equal
(
t
,
spec
,
&
app
.
Environment
Spec
{
return
func
(
a
app
.
App
,
newName
,
k8sAPISpec
string
,
spec
*
app
.
Environment
Config
,
override
bool
)
error
{
assert
.
Equal
(
t
,
spec
,
&
app
.
Environment
Config
{
Destination
:
&
app
.
EnvironmentDestinationSpec
{
Namespace
:
namespace
,
Server
:
server
,
...
...
pkg/actions/env_targets_test.go
View file @
a019cf82
...
...
@@ -32,7 +32,7 @@ func TestEnvTargets(t *testing.T) {
envName
:=
"default"
modules
:=
[]
string
{
"foo"
}
env
:=
&
app
.
Environment
Spec
{}
env
:=
&
app
.
Environment
Config
{}
appMock
.
On
(
"Environment"
,
"default"
)
.
Return
(
env
,
nil
)
appMock
.
On
(
"UpdateTargets"
,
envName
,
modules
)
.
Return
(
nil
)
...
...
@@ -62,7 +62,7 @@ func TestEnvTargets_invalid_module(t *testing.T) {
envName
:=
"default"
modules
:=
[]
string
{
"foo"
}
env
:=
&
app
.
Environment
Spec
{}
env
:=
&
app
.
Environment
Config
{}
appMock
.
On
(
"Environment"
,
"default"
)
.
Return
(
env
,
nil
)
appMock
.
On
(
"UpdateTargets"
,
envName
,
modules
)
.
Return
(
nil
)
...
...
@@ -92,7 +92,7 @@ func TestEnvTargets_invalid_environment(t *testing.T) {
envName
:=
"invalid"
modules
:=
[]
string
{
"foo"
}
env
:=
&
app
.
Environment
Spec
{}
env
:=
&
app
.
Environment
Config
{}
envErr
:=
errors
.
New
(
"environment invalid was not found"
)
appMock
.
On
(
"Environment"
,
"invalid"
)
.
Return
(
env
,
envErr
)
...
...
pkg/actions/env_update_test.go
View file @
a019cf82
...
...
@@ -27,7 +27,7 @@ import (
func
TestEnvUpdate
(
t
*
testing
.
T
)
{
withApp
(
t
,
func
(
appMock
*
amocks
.
App
)
{
envSpec
:=
&
app
.
Environment
Spec
{
envSpec
:=
&
app
.
Environment
Config
{
KubernetesVersion
:
"v1.8.9"
,
}
appMock
.
On
(
"Environment"
,
"envName"
)
.
Return
(
envSpec
,
nil
)
...
...
pkg/actions/validate_test.go
View file @
a019cf82
...
...
@@ -64,7 +64,7 @@ func TestValidate(t *testing.T) {
aModuleName
:=
"module"
aClientConfig
:=
&
client
.
Config
{}
env
:=
&
app
.
Environment
Spec
{}
env
:=
&
app
.
Environment
Config
{}
appMock
.
On
(
"Environment"
,
"default"
)
.
Return
(
env
,
nil
)
in
:=
map
[
string
]
interface
{}{
...
...
pkg/app/app.go
View file @
a019cf82
...
...
@@ -56,15 +56,15 @@ var (
// App is a ksonnet application.
type
App
interface
{
// AddEnvironment adds an environment.
AddEnvironment
(
name
,
k8sSpecFlag
string
,
spec
*
Environment
Spec
,
isOverride
bool
)
error
AddEnvironment
(
name
,
k8sSpecFlag
string
,
spec
*
Environment
Config
,
isOverride
bool
)
error
// AddRegistry adds a registry.
AddRegistry
(
spec
*
RegistryConfig
,
isOverride
bool
)
error
// CurrentEnvironment returns the current environment name or an empty string.
CurrentEnvironment
()
string
// Environment finds an environment by name.
Environment
(
name
string
)
(
*
Environment
Spec
,
error
)
Environment
(
name
string
)
(
*
Environment
Config
,
error
)
// Environments returns all environments.
Environments
()
(
Environment
Spec
s
,
error
)
Environments
()
(
Environment
Config
s
,
error
)
// EnvironmentParams returns params for an environment.
EnvironmentParams
(
name
string
)
(
string
,
error
)
// Fs is the app's afero Fs.
...
...
pkg/app/app001.go
View file @
a019cf82
...
...
@@ -54,7 +54,7 @@ func NewApp001(fs afero.Fs, root string) *App001 {
// AddEnvironment adds an environment spec to the app spec. If the spec already exists,
// it is overwritten.
func
(
a
*
App001
)
AddEnvironment
(
name
,
k8sSpecFlag
string
,
spec
*
Environment
Spec
,
isOverride
bool
)
error
{
func
(
a
*
App001
)
AddEnvironment
(
name
,
k8sSpecFlag
string
,
spec
*
Environment
Config
,
isOverride
bool
)
error
{
// if it is an override, write the destination to override file. If not, do the normal thing.
envPath
:=
filepath
.
Join
(
a
.
root
,
EnvironmentDirName
,
name
)
...
...
@@ -77,21 +77,21 @@ func (a *App001) AddEnvironment(name, k8sSpecFlag string, spec *EnvironmentSpec,
return
err
}
func
(
a
*
App001
)
overrideDestintation
(
name
string
,
envSpec
*
Environment
Spec
)
error
{
func
(
a
*
App001
)
overrideDestintation
(
name
string
,
envSpec
*
Environment
Config
)
error
{
return
nil
}
// Environment returns the spec for an environment. In 0.1.0, the file lives in
// /environments/name/spec.json.
func
(
a
*
App001
)
Environment
(
name
string
)
(
*
Environment
Spec
,
error
)
{
func
(
a
*
App001
)
Environment
(
name
string
)
(
*
Environment
Config
,
error
)
{
path
:=
filepath
.
Join
(
a
.
root
,
EnvironmentDirName
,
name
,
app001specJSON
)
return
read001EnvSpec
(
a
.
fs
,
name
,
path
)
}
// Environments returns specs for all environments. In 0.1.0, the environment spec
// lives in spec.json files.
func
(
a
*
App001
)
Environments
()
(
Environment
Spec
s
,
error
)
{
specs
:=
Environment
Spec
s
{}
func
(
a
*
App001
)
Environments
()
(
Environment
Config
s
,
error
)
{
specs
:=
Environment
Config
s
{}
root
:=
filepath
.
Join
(
a
.
root
,
EnvironmentDirName
)
...
...
@@ -222,7 +222,7 @@ type k8sSchema struct {
}
`json:"info,omitempty"`
}
func
read001EnvSpec
(
fs
afero
.
Fs
,
name
,
path
string
)
(
*
Environment
Spec
,
error
)
{
func
read001EnvSpec
(
fs
afero
.
Fs
,
name
,
path
string
)
(
*
Environment
Config
,
error
)
{
b
,
err
:=
afero
.
ReadFile
(
fs
,
path
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -254,7 +254,7 @@ func read001EnvSpec(fs afero.Fs, name, path string) (*EnvironmentSpec, error) {
return
nil
,
errors
.
New
(
"unable to determine environment Kubernetes version"
)
}
spec
:=
Environment
Spec
{
spec
:=
Environment
Config
{
Path
:
name
,
Destination
:
&
s
,
KubernetesVersion
:
ks
.
Info
.
Version
,
...
...
pkg/app/app001_test.go
View file @
a019cf82
...
...
@@ -89,8 +89,8 @@ func TestApp001_RenameEnvironment(t *testing.T) {
func
TestApp001_Environments
(
t
*
testing
.
T
)
{
withApp001Fs
(
t
,
"app001_app.yaml"
,
func
(
app
*
App001
)
{
expected
:=
Environment
Spec
s
{
"default"
:
&
Environment
Spec
{
expected
:=
Environment
Config
s
{
"default"
:
&
Environment
Config
{
Destination
:
&
EnvironmentDestinationSpec
{
Namespace
:
"some-namespace"
,
Server
:
"http://example.com"
,
...
...
@@ -98,7 +98,7 @@ func TestApp001_Environments(t *testing.T) {
KubernetesVersion
:
"v1.7.0"
,
Path
:
"default"
,
},
"us-east/test"
:
&
Environment
Spec
{
"us-east/test"
:
&
Environment
Config
{
Destination
:
&
EnvironmentDestinationSpec
{
Namespace
:
"some-namespace"
,
Server
:
"http://example.com"
,
...
...
@@ -106,7 +106,7 @@ func TestApp001_Environments(t *testing.T) {
KubernetesVersion
:
"v1.7.0"
,
Path
:
"us-east/test"
,
},
"us-west/test"
:
&
Environment
Spec
{
"us-west/test"
:
&
Environment
Config
{
Destination
:
&
EnvironmentDestinationSpec
{
Namespace
:
"some-namespace"
,
Server
:
"http://example.com"
,
...
...
@@ -114,7 +114,7 @@ func TestApp001_Environments(t *testing.T) {
KubernetesVersion
:
"v1.7.0"
,
Path
:
"us-west/test"
,
},
"us-west/prod"
:
&
Environment
Spec
{
"us-west/prod"
:
&
Environment
Config
{
Destination
:
&
EnvironmentDestinationSpec
{
Namespace
:
"some-namespace"
,
Server
:
"http://example.com"
,
...
...
@@ -164,7 +164,7 @@ func TestApp001_Environment(t *testing.T) {
func
TestApp001_AddEnvironment
(
t
*
testing
.
T
)
{
withApp001Fs
(
t
,
"app001_app.yaml"
,
func
(
app
*
App001
)
{
newEnv
:=
&
Environment
Spec
{
newEnv
:=
&
Environment
Config
{
Destination
:
&
EnvironmentDestinationSpec
{
Namespace
:
"some-namespace"
,
Server
:
"http://example.com"
,
...
...
pkg/app/app010.go
View file @
a019cf82
...
...
@@ -48,7 +48,7 @@ func NewApp010(fs afero.Fs, root string) *App010 {
// AddEnvironment adds an environment spec to the app spec. If the spec already exists,
// it is overwritten.
func
(
a
*
App010
)
AddEnvironment
(
name
,
k8sSpecFlag
string
,
newEnv
*
Environment
Spec
,
isOverride
bool
)
error
{
func
(
a
*
App010
)
AddEnvironment
(
name
,
k8sSpecFlag
string
,
newEnv
*
Environment
Config
,
isOverride
bool
)
error
{
logrus
.
WithFields
(
logrus
.
Fields
{
"k8s-spec-flag"
:
k8sSpecFlag
,
"name"
:
name
,
...
...
@@ -79,7 +79,7 @@ func (a *App010) AddEnvironment(name, k8sSpecFlag string, newEnv *EnvironmentSpe
}
// Environment returns the spec for an environment.
func
(
a
*
App010
)
Environment
(
name
string
)
(
*
Environment
Spec
,
error
)
{
func
(
a
*
App010
)
Environment
(
name
string
)
(
*
Environment
Config
,
error
)
{
if
err
:=
a
.
load
();
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"load configuration"
)
}
...
...
@@ -100,12 +100,12 @@ func (a *App010) Environment(name string) (*EnvironmentSpec, error) {
}
// Environments returns all environment specs.
func
(
a
*
App010
)
Environments
()
(
Environment
Spec
s
,
error
)
{
func
(
a
*
App010
)
Environments
()
(
Environment
Config
s
,
error
)
{
if
err
:=
a
.
load
();
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"load configuration"
)
}
environments
:=
Environment
Spec
s
{}
environments
:=
Environment
Config
s
{}
for
k
,
v
:=
range
a
.
config
.
Environments
{
environments
[
k
]
=
v
}
...
...
pkg/app/app010_test.go
View file @
a019cf82
...
...
@@ -33,7 +33,7 @@ func TestApp010_AddEnvironment(t *testing.T) {
envLen
:=
len
(
envs
)
newEnv
:=
&
Environment
Spec
{
newEnv
:=
&
Environment
Config
{
Destination
:
&
EnvironmentDestinationSpec
{
Namespace
:
"some-namespace"
,
Server
:
"http://example.com"
,
...
...
@@ -83,8 +83,9 @@ func TestApp010_AddEnvironment_empty_spec_flag(t *testing.T) {
func
TestApp0101_Environments
(
t
*
testing
.
T
)
{
withApp010Fs
(
t
,
"app010_app.yaml"
,
func
(
app
*
App010
)
{
expected
:=
EnvironmentSpecs
{
"default"
:
&
EnvironmentSpec
{
expected
:=
EnvironmentConfigs
{
"default"
:
&
EnvironmentConfig
{
Name
:
"default"
,
Destination
:
&
EnvironmentDestinationSpec
{
Namespace
:
"some-namespace"
,
Server
:
"http://example.com"
,
...
...
@@ -92,7 +93,8 @@ func TestApp0101_Environments(t *testing.T) {
KubernetesVersion
:
"v1.7.0"
,
Path
:
"default"
,
},
"us-east/test"
:
&
EnvironmentSpec
{
"us-east/test"
:
&
EnvironmentConfig
{
Name
:
"us-east/test"
,
Destination
:
&
EnvironmentDestinationSpec
{
Namespace
:
"some-namespace"
,
Server
:
"http://example.com"
,
...
...
@@ -100,7 +102,8 @@ func TestApp0101_Environments(t *testing.T) {
KubernetesVersion
:
"v1.7.0"
,
Path
:
"us-east/test"
,
},
"us-west/test"
:
&
EnvironmentSpec
{
"us-west/test"
:
&
EnvironmentConfig
{
Name
:
"us-west/test"
,
Destination
:
&
EnvironmentDestinationSpec
{
Namespace
:
"some-namespace"
,
Server
:
"http://example.com"
,
...
...
@@ -108,7 +111,8 @@ func TestApp0101_Environments(t *testing.T) {
KubernetesVersion
:
"v1.7.0"
,
Path
:
"us-west/test"
,
},
"us-west/prod"
:
&
EnvironmentSpec
{
"us-west/prod"
:
&
EnvironmentConfig
{
Name
:
"us-west/prod"
,
Destination
:
&
EnvironmentDestinationSpec
{
Namespace
:
"some-namespace"
,
Server
:
"http://example.com"
,
...
...
pkg/app/base_app.go
View file @
a019cf82
...
...
@@ -40,7 +40,7 @@ func newBaseApp(fs afero.Fs, root string) *baseApp {
root
:
root
,
config
:
&
Spec
{},
overrides
:
&
Override
{
Environments
:
Environment
Spec
s
{},
Environments
:
Environment
Config
s
{},
Registries
:
RegistryConfigs
{},
},
}
...
...
@@ -113,7 +113,7 @@ func (ba *baseApp) load() error {
}
if
len
(
config
.
Environments
)
==
0
{
config
.
Environments
=
Environment
Spec
s
{}
config
.
Environments
=
Environment
Config
s
{}
}
if
len
(
config
.
Registries
)
==
0
{
...
...
@@ -121,7 +121,7 @@ func (ba *baseApp) load() error {
}
override
:=
Override
{
Environments
:
Environment
Spec
s
{},
Environments
:
Environment
Config
s
{},
Registries
:
RegistryConfigs
{},
}
if
exists
{
...
...
@@ -138,7 +138,7 @@ func (ba *baseApp) load() error {
}
if
len
(
override
.
Environments
)
==
0
{
override
.
Environments
=
Environment
Spec
s
{}
override
.
Environments
=
Environment
Config
s
{}
}
if
len
(
override
.
Registries
)
==
0
{
...
...
pkg/app/mocks/App.go
View file @
a019cf82
...
...
@@ -26,11 +26,11 @@ type App struct {
}
// AddEnvironment provides a mock function with given fields: name, k8sSpecFlag, spec, isOverride
func
(
_m
*
App
)
AddEnvironment
(
name
string
,
k8sSpecFlag
string
,
spec
*
app
.
Environment
Spec
,
isOverride
bool
)
error
{
func
(
_m
*
App
)
AddEnvironment
(
name
string
,
k8sSpecFlag
string
,
spec
*
app
.
Environment
Config
,
isOverride
bool
)
error
{
ret
:=
_m
.
Called
(
name
,
k8sSpecFlag
,
spec
,
isOverride
)
var
r0
error
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
string
,
string
,
*
app
.
Environment
Spec
,
bool
)
error
);
ok
{
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
string
,
string
,
*
app
.
Environment
Config
,
bool
)
error
);
ok
{
r0
=
rf
(
name
,
k8sSpecFlag
,
spec
,
isOverride
)
}
else
{
r0
=
ret
.
Error
(
0
)
...
...
@@ -68,15 +68,15 @@ func (_m *App) CurrentEnvironment() string {
}
// Environment provides a mock function with given fields: name
func
(
_m
*
App
)
Environment
(
name
string
)
(
*
app
.
Environment
Spec
,
error
)
{
func
(
_m
*
App
)
Environment
(
name
string
)
(
*
app
.
Environment
Config
,
error
)
{
ret
:=
_m
.
Called
(
name
)
var
r0
*
app
.
Environment
Spec
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
string
)
*
app
.
Environment
Spec
);
ok
{
var
r0
*
app
.
Environment
Config
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
string
)
*
app
.
Environment
Config
);
ok
{
r0
=
rf
(
name
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
app
.
Environment
Spec
)
r0
=
ret
.
Get
(
0
)
.
(
*
app
.
Environment
Config
)
}
}
...
...
@@ -112,15 +112,15 @@ func (_m *App) EnvironmentParams(name string) (string, error) {
}
// Environments provides a mock function with given fields:
func
(
_m
*
App
)
Environments
()
(
app
.
Environment
Spec
s
,
error
)
{
func
(
_m
*
App
)
Environments
()
(
app
.
Environment
Config
s
,
error
)
{
ret
:=
_m
.
Called
()
var
r0
app
.
Environment
Spec
s
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
()
app
.
Environment
Spec
s
);
ok
{
var
r0
app
.
Environment
Config
s
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
()
app
.
Environment
Config
s
);
ok
{
r0
=
rf
()
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
app
.
Environment
Spec
s
)
r0
=
ret
.
Get
(
0
)
.
(
app
.
Environment
Config
s
)
}
}
...
...
pkg/app/override.go
View file @
a019cf82
...
...
@@ -31,10 +31,10 @@ const (
// Override defines overrides to ksonnet project configurations.
type
Override
struct
{
Kind
string
`json:"kind"`
APIVersion
string
`json:"apiVersion"`
Environments
Environment
Spec
s
`json:"environments,omitempty"`
Registries
RegistryConfigs
`json:"registries,omitempty"`
Kind
string
`json:"kind"`
APIVersion
string
`json:"apiVersion"`
Environments
Environment
Config
s
`json:"environments,omitempty"`
Registries
RegistryConfigs
`json:"registries,omitempty"`
}
// Validate validates an Override.
...
...
pkg/app/schema.go
View file @
a019cf82
...
...
@@ -52,20 +52,20 @@ var (
// Spec defines all the ksonnet project metadata. This includes details such as
// the project name, authors, environments, and registries.
type
Spec
struct
{
APIVersion
string
`json:"apiVersion,omitempty"`
Kind
string
`json:"kind,omitempty"`
Name
string
`json:"name,omitempty"`
Version
string
`json:"version,omitempty"`
Description
string
`json:"description,omitempty"`
Authors
[]
string
`json:"authors,omitempty"`
Contributors
ContributorSpecs
`json:"contributors,omitempty"`
Repository
*
RepositorySpec
`json:"repository,omitempty"`
Bugs
string
`json:"bugs,omitempty"`
Keywords
[]
string
`json:"keywords,omitempty"`
Registries
RegistryConfigs
`json:"registries,omitempty"`
Environments
Environment
Spec
s
`json:"environments,omitempty"`
Libraries
LibraryConfigs
`json:"libraries,omitempty"`
License
string
`json:"license,omitempty"`
APIVersion
string
`json:"apiVersion,omitempty"`
Kind
string
`json:"kind,omitempty"`
Name
string
`json:"name,omitempty"`
Version
string
`json:"version,omitempty"`
Description
string
`json:"description,omitempty"`
Authors
[]
string
`json:"authors,omitempty"`
Contributors
ContributorSpecs
`json:"contributors,omitempty"`
Repository
*
RepositorySpec
`json:"repository,omitempty"`
Bugs
string
`json:"bugs,omitempty"`
Keywords
[]
string
`json:"keywords,omitempty"`
Registries
RegistryConfigs
`json:"registries,omitempty"`
Environments
Environment
Config
s
`json:"environments,omitempty"`
Libraries
LibraryConfigs
`json:"libraries,omitempty"`
License
string
`json:"license,omitempty"`
}
// Read will return the specification for a ksonnet application. It will navigate up directories
...
...
@@ -130,7 +130,7 @@ func write(fs afero.Fs, appRoot string, spec *Spec) error {
o
:=
Override
{
Kind
:
overrideKind
,
APIVersion
:
overrideVersion
,
Environments
:
Environment
Spec
s
{},
Environments
:
Environment
Config
s
{},
Registries
:
RegistryConfigs
{},
}
...
...
@@ -248,11 +248,29 @@ func (r *RegistryConfigs) UnmarshalJSON(b []byte) error {
return
nil
}
// Environment
Spec
s contains one or more Environment
Spec
.
type
Environment
Spec
s
map
[
string
]
*
Environment
Spec
// Environment
Config
s contains one or more Environment
Config
.
type
Environment
Config
s
map
[
string
]
*
Environment
Config
// EnvironmentSpec contains the specification for ksonnet environments.
type
EnvironmentSpec
struct
{
// UnmarshalJSON implements the json.Unmarshaler interface.
// Our goal is to populate the Name field of EnvironmentConfig
// objects according to they key name in the environments map.
func
(
e
*
EnvironmentConfigs
)
UnmarshalJSON
(
b
[]
byte
)
error
{
envs
:=
make
(
map
[
string
]
*
EnvironmentConfig
)
if
err
:=
json
.
Unmarshal
(
b
,
&
envs
);
err
!=
nil
{
return
err
}
// Set Name fields according to map keys
for
k
,
v
:=
range
envs
{
v
.
Name
=
k
}
*
e
=
EnvironmentConfigs
(
envs
)
return
nil
}
// EnvironmentConfig contains the specification for ksonnet environments.
type
EnvironmentConfig
struct
{
// Name is the user defined name of an environment
Name
string
`json:"-"`
// KubernetesVersion is the kubernetes version the targeted cluster is
...
...
@@ -271,15 +289,15 @@ type EnvironmentSpec struct {
}
// MakePath return the absolute path to the environment directory.
func
(
e
*
Environment
Spec
)
MakePath
(
rootPath
string
)
string
{
func
(
e
*
Environment
Config
)
MakePath
(
rootPath
string
)
string
{
return
filepath
.
Join
(
rootPath
,
EnvironmentDirName
,
filepath
.
FromSlash
(
e
.
Path
))
}
// IsOverride is true if this Environment
Spec
is an override.
func
(
e
*
Environment
Spec
)
IsOverride
()
bool
{
// IsOverride is true if this Environment
Config
is an override.
func
(
e
*
Environment
Config
)
IsOverride
()
bool
{
return
e
.
isOverride
}
...
...
@@ -338,16 +356,16 @@ func (s *Spec) RegistryConfig(name string) (*RegistryConfig, bool) {
}
// AddRegistryConfig adds the RegistryConfig to the app spec.
func
(
s
*
Spec
)
AddRegistryConfig
(
RegistryConfi
g
*
RegistryConfig
)
error
{
if
RegistryConfi
g
.
Name
==
""
{
func
(
s
*
Spec
)
AddRegistryConfig
(
cf
g
*
RegistryConfig
)
error
{
if
cf
g
.
Name
==
""
{
return
ErrRegistryNameInvalid
}
if
_
,
exists
:=
s
.
Registries
[
RegistryConfi
g
.
Name
];
exists
{
if
_
,
exists
:=
s
.
Registries
[
cf
g
.
Name
];
exists
{
return
ErrRegistryExists
}
s
.
Registries
[
RegistryConfig
.
Name
]
=
RegistryConfi
g
s
.
Registries
[
cfg
.
Name
]
=
cf
g
return
nil
}
...
...
@@ -365,7 +383,7 @@ func (s *Spec) validate() error {
}
if
s
.
Environments
==
nil
{
s
.
Environments
=
Environment
Spec
s
{}
s
.
Environments
=
Environment
Config
s
{}
}
if
s
.
APIVersion
==
"0.0.0"
{
...
...
@@ -388,9 +406,9 @@ func (s *Spec) validate() error {
return
nil
}
// GetEnvironment
Spec
s returns all environment specifications.
//
We need to pre-populate th EnvironmentSpec name before returning.
func
(
s
*
Spec
)
GetEnvironment
Spec
s
()
Environment
Spec
s
{
// GetEnvironment
Config
s returns all environment specifications.