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
6f9afae6
Commit
6f9afae6
authored
7 years ago
by
Alex Clemmer
Browse files
Options
Downloads
Patches
Plain Diff
Add user-level ksonnet directory
parent
b7ddd956
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
metadata/manager.go
+48
-4
48 additions, 4 deletions
metadata/manager.go
metadata/manager_test.go
+23
-0
23 additions, 0 deletions
metadata/manager_test.go
with
71 additions
and
4 deletions
metadata/manager.go
+
48
−
4
View file @
6f9afae6
...
...
@@ -18,6 +18,7 @@ package metadata
import
(
"fmt"
"os"
"os/user"
"path"
"path/filepath"
"strings"
...
...
@@ -47,11 +48,16 @@ const (
ComponentsExtCodeKey
=
"__ksonnet/components"
// ParamsExtCodeKey is the ExtCode key for importing environment parameters
ParamsExtCodeKey
=
"__ksonnet/params"
// User-level ksonnet directories.
userKsonnetRootDir
=
".ksonnet"
pkgSrcCacheDir
=
"src"
)
type
manager
struct
{
appFS
afero
.
Fs
// Application paths.
rootPath
AbsPath
ksonnetPath
AbsPath
libPath
AbsPath
...
...
@@ -61,6 +67,10 @@ type manager struct {
componentParamsPath
AbsPath
baseLibsonnetPath
AbsPath
// User-level paths.
userKsonnetRootPath
AbsPath
pkgSrcCachePath
AbsPath
}
func
findManager
(
abs
AbsPath
,
appFS
afero
.
Fs
)
(
*
manager
,
error
)
{
...
...
@@ -74,7 +84,7 @@ func findManager(abs AbsPath, appFS afero.Fs) (*manager, error) {
return
nil
,
err
}
if
exists
{
return
newManager
(
AbsPath
(
currBase
),
appFS
)
,
nil
return
newManager
(
AbsPath
(
currBase
),
appFS
)
}
lastBase
=
currBase
...
...
@@ -86,7 +96,10 @@ func findManager(abs AbsPath, appFS afero.Fs) (*manager, error) {
}
func
initManager
(
rootPath
AbsPath
,
spec
ClusterSpec
,
serverURI
,
namespace
*
string
,
appFS
afero
.
Fs
)
(
*
manager
,
error
)
{
m
:=
newManager
(
rootPath
,
appFS
)
m
,
err
:=
newManager
(
rootPath
,
appFS
)
if
err
!=
nil
{
return
nil
,
err
}
// Generate the program text for ksonnet-lib.
//
...
...
@@ -105,6 +118,11 @@ func initManager(rootPath AbsPath, spec ClusterSpec, serverURI, namespace *strin
return
nil
,
err
}
// Initialize user dir structure.
if
err
:=
m
.
createUserDirTree
();
err
!=
nil
{
return
nil
,
err
}
// Initialize environment, and cache specification data.
if
serverURI
!=
nil
{
err
:=
m
.
createEnvironment
(
defaultEnvName
,
*
serverURI
,
*
namespace
,
extensionsLibData
,
k8sLibData
,
specData
)
...
...
@@ -116,10 +134,17 @@ func initManager(rootPath AbsPath, spec ClusterSpec, serverURI, namespace *strin
return
m
,
nil
}
func
newManager
(
rootPath
AbsPath
,
appFS
afero
.
Fs
)
*
manager
{
func
newManager
(
rootPath
AbsPath
,
appFS
afero
.
Fs
)
(
*
manager
,
error
)
{
usr
,
err
:=
user
.
Current
()
if
err
!=
nil
{
return
nil
,
err
}
userRootPath
:=
appendToAbsPath
(
AbsPath
(
usr
.
HomeDir
),
userKsonnetRootDir
)
return
&
manager
{
appFS
:
appFS
,
// Application paths.
rootPath
:
rootPath
,
ksonnetPath
:
appendToAbsPath
(
rootPath
,
ksonnetDir
),
libPath
:
appendToAbsPath
(
rootPath
,
libDir
),
...
...
@@ -129,7 +154,11 @@ func newManager(rootPath AbsPath, appFS afero.Fs) *manager {
componentParamsPath
:
appendToAbsPath
(
rootPath
,
componentsDir
,
componentParamsFile
),
baseLibsonnetPath
:
appendToAbsPath
(
rootPath
,
environmentsDir
,
baseLibsonnetFile
),
}
// User-level paths.
userKsonnetRootPath
:
userRootPath
,
pkgSrcCachePath
:
appendToAbsPath
(
userRootPath
,
pkgSrcCacheDir
),
},
nil
}
func
(
m
*
manager
)
Root
()
AbsPath
{
...
...
@@ -226,6 +255,21 @@ func (m *manager) SetComponentParams(component string, params param.Params) erro
return
afero
.
WriteFile
(
m
.
appFS
,
string
(
m
.
componentParamsPath
),
[]
byte
(
jsonnet
),
defaultFilePermissions
)
}
func
(
m
*
manager
)
createUserDirTree
()
error
{
dirPaths
:=
[]
AbsPath
{
m
.
userKsonnetRootPath
,
m
.
pkgSrcCachePath
,
}
for
_
,
p
:=
range
dirPaths
{
if
err
:=
m
.
appFS
.
MkdirAll
(
string
(
p
),
defaultFolderPermissions
);
err
!=
nil
{
return
err
}
}
return
nil
}
func
(
m
*
manager
)
createAppDirTree
()
error
{
exists
,
err
:=
afero
.
DirExists
(
m
.
appFS
,
string
(
m
.
rootPath
))
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
metadata/manager_test.go
+
23
−
0
View file @
6f9afae6
...
...
@@ -17,6 +17,7 @@ package metadata
import
(
"fmt"
"os"
"os/user"
"path"
"sort"
"testing"
...
...
@@ -65,6 +66,7 @@ func TestInitSuccess(t *testing.T) {
t
.
Fatalf
(
"Failed to init cluster spec: %v"
,
err
)
}
// Verify path locations.
defaultEnvDir
:=
appendToAbsPath
(
environmentsDir
,
defaultEnvName
)
paths
:=
[]
AbsPath
{
ksonnetDir
,
...
...
@@ -85,6 +87,27 @@ func TestInitSuccess(t *testing.T) {
}
}
paths
=
[]
AbsPath
{
pkgSrcCacheDir
,
}
usr
,
err
:=
user
.
Current
()
if
err
!=
nil
{
t
.
Fatalf
(
"Could not get user information:
\n
%v"
,
err
)
}
userRootPath
:=
appendToAbsPath
(
AbsPath
(
usr
.
HomeDir
),
userKsonnetRootDir
)
for
_
,
p
:=
range
paths
{
path
:=
appendToAbsPath
(
userRootPath
,
string
(
p
))
exists
,
err
:=
afero
.
DirExists
(
testFS
,
string
(
path
))
if
err
!=
nil
{
t
.
Fatalf
(
"Expected to create directory '%s', but failed:
\n
%v"
,
p
,
err
)
}
else
if
!
exists
{
t
.
Fatalf
(
"Expected to create directory '%s', but failed"
,
path
)
}
}
// Verify contents of metadata.
envPath
:=
appendToAbsPath
(
appPath
,
string
(
environmentsDir
))
metadataPath
:=
appendToAbsPath
(
appPath
,
string
(
defaultEnvDir
),
string
(
metadataDirName
))
...
...
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