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
90fe67de
Commit
90fe67de
authored
7 years ago
by
Jessica Yuen
Committed by
bryanl
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Attempt to generate lib directory when not found
Signed-off-by:
Jessica Yuen
<
im.jessicayuen@gmail.com
>
parent
44700711
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/environment.go
+21
-11
21 additions, 11 deletions
metadata/environment.go
metadata/lib/lib.go
+10
-8
10 additions, 8 deletions
metadata/lib/lib.go
metadata/lib/lib_test.go
+1
-1
1 addition, 1 deletion
metadata/lib/lib_test.go
metadata/manager_test.go
+2
-5
2 additions, 5 deletions
metadata/manager_test.go
with
34 additions
and
25 deletions
metadata/environment.go
+
21
−
11
View file @
90fe67de
...
@@ -50,7 +50,7 @@ var envPaths = []string{
...
@@ -50,7 +50,7 @@ var envPaths = []string{
func
(
m
*
manager
)
CreateEnvironment
(
name
,
server
,
namespace
,
k8sSpecFlag
string
)
error
{
func
(
m
*
manager
)
CreateEnvironment
(
name
,
server
,
namespace
,
k8sSpecFlag
string
)
error
{
// generate the lib data for this kubernetes version
// generate the lib data for this kubernetes version
libManager
,
err
:=
lib
.
NewManager
WithSpec
(
k8sSpecFlag
,
m
.
appFS
,
m
.
libPath
)
libManager
,
err
:=
lib
.
NewManager
(
k8sSpecFlag
,
m
.
appFS
,
m
.
libPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -371,26 +371,36 @@ func (m *manager) SetEnvironmentParams(env, component string, params param.Param
...
@@ -371,26 +371,36 @@ func (m *manager) SetEnvironmentParams(env, component string, params param.Param
}
}
func
(
m
*
manager
)
EnvPaths
(
env
string
)
(
libPath
,
mainPath
,
paramsPath
string
,
err
error
)
{
func
(
m
*
manager
)
EnvPaths
(
env
string
)
(
libPath
,
mainPath
,
paramsPath
string
,
err
error
)
{
envSpec
,
err
:=
m
.
GetEnvironment
(
env
)
mainPath
,
paramsPath
=
m
.
makeEnvPaths
(
env
)
if
err
!=
nil
{
libPath
,
err
=
m
.
getLibPath
(
env
)
return
return
}
}
libManager
:=
lib
.
NewManager
(
envSpec
.
KubernetesVersion
,
m
.
appFS
,
m
.
libPath
)
func
(
m
*
manager
)
makeEnvPaths
(
env
string
)
(
mainPath
,
paramsPath
string
)
{
envPath
:=
str
.
AppendToPath
(
m
.
environmentsPath
,
env
)
envPath
:=
str
.
AppendToPath
(
m
.
environmentsPath
,
env
)
// main.jsonnet file
// main.jsonnet file
mainPath
=
str
.
AppendToPath
(
envPath
,
envFileName
)
mainPath
=
str
.
AppendToPath
(
envPath
,
envFileName
)
// params.libsonnet file
// params.libsonnet file
paramsPath
=
str
.
AppendToPath
(
envPath
,
componentParamsFile
)
paramsPath
=
str
.
AppendToPath
(
envPath
,
componentParamsFile
)
// ksonnet-lib file directory
libPath
,
err
=
libManager
.
GetLibPath
()
return
return
}
}
// errorOnSpec file is a temporary function to help migration from ks 0.8 to 0.9.
func
(
m
*
manager
)
getLibPath
(
env
string
)
(
string
,
error
)
{
// It will return an error if a spec.json file is found in an environment directory.
envSpec
,
err
:=
m
.
GetEnvironment
(
env
)
if
err
!=
nil
{
return
""
,
err
}
libManager
,
err
:=
lib
.
NewManager
(
fmt
.
Sprintf
(
"version:%s"
,
envSpec
.
KubernetesVersion
),
m
.
appFS
,
m
.
libPath
)
if
err
!=
nil
{
return
""
,
err
}
return
libManager
.
GetLibPath
()
}
func
(
m
*
manager
)
errorOnSpecFile
()
error
{
func
(
m
*
manager
)
errorOnSpecFile
()
error
{
return
afero
.
Walk
(
m
.
appFS
,
m
.
environmentsPath
,
func
(
p
string
,
f
os
.
FileInfo
,
err
error
)
error
{
return
afero
.
Walk
(
m
.
appFS
,
m
.
environmentsPath
,
func
(
p
string
,
f
os
.
FileInfo
,
err
error
)
error
{
if
err
!=
nil
{
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
metadata/lib/lib.go
+
10
−
8
View file @
90fe67de
...
@@ -48,13 +48,8 @@ type Manager struct {
...
@@ -48,13 +48,8 @@ type Manager struct {
fs
afero
.
Fs
fs
afero
.
Fs
}
}
// NewManager creates a crew instance of lib.Manager
// NewManager creates a new instance of lib.Manager
func
NewManager
(
k8sVersion
string
,
fs
afero
.
Fs
,
libPath
string
)
*
Manager
{
func
NewManager
(
k8sSpecFlag
string
,
fs
afero
.
Fs
,
libPath
string
)
(
*
Manager
,
error
)
{
return
&
Manager
{
K8sVersion
:
k8sVersion
,
fs
:
fs
,
libPath
:
libPath
}
}
// NewManagerWithSpec creates a new instance of lib.Manager with the cluster spec initialized.
func
NewManagerWithSpec
(
k8sSpecFlag
string
,
fs
afero
.
Fs
,
libPath
string
)
(
*
Manager
,
error
)
{
//
//
// Generate the program text for ksonnet-lib.
// Generate the program text for ksonnet-lib.
//
//
...
@@ -148,7 +143,14 @@ func (m *Manager) GetLibPath() (string, error) {
...
@@ -148,7 +143,14 @@ func (m *Manager) GetLibPath() (string, error) {
return
""
,
err
return
""
,
err
}
}
if
!
ok
{
if
!
ok
{
return
""
,
fmt
.
Errorf
(
"Expected lib directory '%s' but was not found"
,
m
.
K8sVersion
)
log
.
Debugf
(
"Expected lib directory '%s' but was not found"
,
m
.
K8sVersion
)
// create the directory
if
err
:=
m
.
GenerateLibData
();
err
!=
nil
{
return
""
,
err
}
return
path
,
nil
}
}
return
path
,
err
return
path
,
err
}
}
This diff is collapsed.
Click to expand it.
metadata/lib/lib_test.go
+
1
−
1
View file @
90fe67de
...
@@ -50,7 +50,7 @@ func TestGenerateLibData(t *testing.T) {
...
@@ -50,7 +50,7 @@ func TestGenerateLibData(t *testing.T) {
specFlag
:=
fmt
.
Sprintf
(
"file:%s"
,
blankSwagger
)
specFlag
:=
fmt
.
Sprintf
(
"file:%s"
,
blankSwagger
)
libPath
:=
"lib"
libPath
:=
"lib"
libManager
,
err
:=
NewManager
WithSpec
(
specFlag
,
testFS
,
libPath
)
libManager
,
err
:=
NewManager
(
specFlag
,
testFS
,
libPath
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
"Failed to initialize lib.Manager"
)
t
.
Fatal
(
"Failed to initialize lib.Manager"
)
}
}
...
...
This diff is collapsed.
Click to expand it.
metadata/manager_test.go
+
2
−
5
View file @
90fe67de
...
@@ -191,16 +191,13 @@ func TestLibPaths(t *testing.T) {
...
@@ -191,16 +191,13 @@ func TestLibPaths(t *testing.T) {
}
}
}
}
func
TestEnvPaths
(
t
*
testing
.
T
)
{
func
Test
Make
EnvPaths
(
t
*
testing
.
T
)
{
appName
:=
"test-env-paths"
appName
:=
"test-env-paths"
expectedMainPath
:=
path
.
Join
(
appName
,
environmentsDir
,
mockEnvName
,
envFileName
)
expectedMainPath
:=
path
.
Join
(
appName
,
environmentsDir
,
mockEnvName
,
envFileName
)
expectedParamsPath
:=
path
.
Join
(
appName
,
environmentsDir
,
mockEnvName
,
paramsFileName
)
expectedParamsPath
:=
path
.
Join
(
appName
,
environmentsDir
,
mockEnvName
,
paramsFileName
)
m
:=
mockEnvironments
(
t
,
appName
)
m
:=
mockEnvironments
(
t
,
appName
)
_
,
mainPath
,
paramsPath
,
err
:=
m
.
EnvPaths
(
mockEnvName
)
mainPath
,
paramsPath
:=
m
.
makeEnvPaths
(
mockEnvName
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failure retrieving EnvPaths"
)
}
if
mainPath
!=
expectedMainPath
{
if
mainPath
!=
expectedMainPath
{
t
.
Fatalf
(
"Expected environment main path to be:
\n
'%s'
\n
, got:
\n
'%s'"
,
expectedMainPath
,
mainPath
)
t
.
Fatalf
(
"Expected environment main path to be:
\n
'%s'
\n
, got:
\n
'%s'"
,
expectedMainPath
,
mainPath
)
...
...
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