Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
43a6876a
Commit
43a6876a
authored
Mar 23, 2016
by
jackgr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor manager/manager
parent
e1afffbc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
163 deletions
+116
-163
manager.go
cmd/manager/manager/manager.go
+69
-116
manager_test.go
cmd/manager/manager/manager_test.go
+45
-45
types.go
pkg/common/types.go
+2
-2
No files found.
cmd/manager/manager/manager.go
View file @
43a6876a
...
@@ -19,15 +19,13 @@ package manager
...
@@ -19,15 +19,13 @@ package manager
import
(
import
(
"fmt"
"fmt"
"log"
"log"
"net/url"
"regexp"
"regexp"
"strings"
"time"
"time"
"github.com/kubernetes/helm/cmd/manager/repository"
"github.com/kubernetes/helm/cmd/manager/repository"
"github.com/kubernetes/helm/pkg/chart"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/registry"
"github.com/kubernetes/helm/pkg/repo"
"github.com/kubernetes/helm/pkg/util"
)
)
// Manager manages a persistent set of Deployments.
// Manager manages a persistent set of Deployments.
...
@@ -44,26 +42,20 @@ type Manager interface {
...
@@ -44,26 +42,20 @@ type Manager interface {
GetManifest
(
deploymentName
string
,
manifest
string
)
(
*
common
.
Manifest
,
error
)
GetManifest
(
deploymentName
string
,
manifest
string
)
(
*
common
.
Manifest
,
error
)
Expand
(
t
*
common
.
Template
)
(
*
common
.
Manifest
,
error
)
Expand
(
t
*
common
.
Template
)
(
*
common
.
Manifest
,
error
)
// Types
// Charts
ListTypes
()
([]
string
,
error
)
ListCharts
()
([]
string
,
error
)
ListInstances
(
typeName
string
)
([]
*
common
.
TypeInstance
,
error
)
ListChartInstances
(
chartName
string
)
([]
*
common
.
ChartInstance
,
error
)
GetRegistryForType
(
typeName
string
)
(
string
,
error
)
GetRepoForChart
(
chartName
string
)
(
string
,
error
)
GetMetadataForType
(
typeName
string
)
(
string
,
error
)
GetMetadataForChart
(
chartName
string
)
(
*
chart
.
Chartfile
,
error
)
GetChart
(
chartName
string
)
(
*
chart
.
Chart
,
error
)
// Registries
// Repo Charts
ListRegistries
()
([]
*
common
.
Registry
,
error
)
ListRepoCharts
(
repoName
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
CreateRegistry
(
pr
*
common
.
Registry
)
error
GetChartForRepo
(
repoName
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
GetRegistry
(
name
string
)
(
*
common
.
Registry
,
error
)
DeleteRegistry
(
name
string
)
error
// Registry Types
ListRegistryTypes
(
registryName
string
,
regex
*
regexp
.
Regexp
)
([]
registry
.
Type
,
error
)
GetDownloadURLs
(
registryName
string
,
t
registry
.
Type
)
([]
*
url
.
URL
,
error
)
GetFile
(
registryName
string
,
url
string
)
(
string
,
error
)
// Credentials
// Credentials
CreateCredential
(
name
string
,
c
*
common
.
Registry
Credential
)
error
CreateCredential
(
name
string
,
c
*
repo
.
Credential
)
error
GetCredential
(
name
string
)
(
*
common
.
Registry
Credential
,
error
)
GetCredential
(
name
string
)
(
*
repo
.
Credential
,
error
)
// Chart Repositories
// Chart Repositories
ListChartRepos
()
([]
string
,
error
)
ListChartRepos
()
([]
string
,
error
)
...
@@ -72,24 +64,23 @@ type Manager interface {
...
@@ -72,24 +64,23 @@ type Manager interface {
}
}
type
manager
struct
{
type
manager
struct
{
expander
Expander
expander
Expander
deployer
Deployer
deployer
Deployer
repository
repository
.
Repository
repository
repository
.
Repository
re
gistryProvider
registry
.
Registry
Provider
re
poProvider
repo
.
IRepo
Provider
service
common
.
Registry
Service
service
repo
.
IRepo
Service
//TODO: add chart repo service
//TODO: add chart repo service
credentialProvider
common
.
CredentialProvider
credentialProvider
repo
.
I
CredentialProvider
}
}
// NewManager returns a new initialized Manager.
// NewManager returns a new initialized Manager.
func
NewManager
(
expander
Expander
,
func
NewManager
(
expander
Expander
,
deployer
Deployer
,
deployer
Deployer
,
repository
repository
.
Repository
,
repository
repository
.
Repository
,
registryProvider
registry
.
RegistryProvider
,
repoProvider
repo
.
IRepoProvider
,
service
common
.
RegistryService
,
service
repo
.
IRepoService
,
//TODO: add chart repo service
credentialProvider
repo
.
ICredentialProvider
)
Manager
{
credentialProvider
common
.
CredentialProvider
)
Manager
{
return
&
manager
{
expander
,
deployer
,
repository
,
repoProvider
,
service
,
credentialProvider
}
return
&
manager
{
expander
,
deployer
,
repository
,
registryProvider
,
service
,
credentialProvider
}
}
}
// ListDeployments returns the list of deployments
// ListDeployments returns the list of deployments
...
@@ -190,7 +181,7 @@ func (m *manager) CreateDeployment(t *common.Template) (*common.Deployment, erro
...
@@ -190,7 +181,7 @@ func (m *manager) CreateDeployment(t *common.Template) (*common.Deployment, erro
}
}
// Finally update the type instances for this deployment.
// Finally update the type instances for this deployment.
m
.
set
Type
Instances
(
t
.
Name
,
manifest
.
Name
,
manifest
.
Layout
)
m
.
set
Chart
Instances
(
t
.
Name
,
manifest
.
Name
,
manifest
.
Layout
)
return
m
.
repository
.
GetValidDeployment
(
t
.
Name
)
return
m
.
repository
.
GetValidDeployment
(
t
.
Name
)
}
}
...
@@ -210,20 +201,20 @@ func (m *manager) createManifest(t *common.Template) (*common.Manifest, error) {
...
@@ -210,20 +201,20 @@ func (m *manager) createManifest(t *common.Template) (*common.Manifest, error) {
},
nil
},
nil
}
}
func
(
m
*
manager
)
set
Type
Instances
(
deploymentName
string
,
manifestName
string
,
layout
*
common
.
Layout
)
{
func
(
m
*
manager
)
set
Chart
Instances
(
deploymentName
string
,
manifestName
string
,
layout
*
common
.
Layout
)
{
m
.
repository
.
Clear
Type
InstancesForDeployment
(
deploymentName
)
m
.
repository
.
Clear
Chart
InstancesForDeployment
(
deploymentName
)
instances
:=
make
(
map
[
string
][]
*
common
.
Type
Instance
)
instances
:=
make
(
map
[
string
][]
*
common
.
Chart
Instance
)
for
i
,
r
:=
range
layout
.
Resources
{
for
i
,
r
:=
range
layout
.
Resources
{
add
Type
Instances
(
&
instances
,
r
,
deploymentName
,
manifestName
,
fmt
.
Sprintf
(
"$.resources[%d]"
,
i
))
add
Chart
Instances
(
&
instances
,
r
,
deploymentName
,
manifestName
,
fmt
.
Sprintf
(
"$.resources[%d]"
,
i
))
}
}
m
.
repository
.
Add
Type
Instances
(
instances
)
m
.
repository
.
Add
Chart
Instances
(
instances
)
}
}
func
add
TypeInstances
(
instances
*
map
[
string
][]
*
common
.
Type
Instance
,
r
*
common
.
LayoutResource
,
deploymentName
string
,
manifestName
string
,
jsonPath
string
)
{
func
add
ChartInstances
(
instances
*
map
[
string
][]
*
common
.
Chart
Instance
,
r
*
common
.
LayoutResource
,
deploymentName
string
,
manifestName
string
,
jsonPath
string
)
{
// Add this resource.
// Add this resource.
inst
:=
&
common
.
Type
Instance
{
inst
:=
&
common
.
Chart
Instance
{
Name
:
r
.
Name
,
Name
:
r
.
Name
,
Type
:
r
.
Type
,
Type
:
r
.
Type
,
Deployment
:
deploymentName
,
Deployment
:
deploymentName
,
...
@@ -235,7 +226,7 @@ func addTypeInstances(instances *map[string][]*common.TypeInstance, r *common.La
...
@@ -235,7 +226,7 @@ func addTypeInstances(instances *map[string][]*common.TypeInstance, r *common.La
// Add all sub resources if they exist.
// Add all sub resources if they exist.
for
i
,
sr
:=
range
r
.
Resources
{
for
i
,
sr
:=
range
r
.
Resources
{
add
Type
Instances
(
instances
,
sr
,
deploymentName
,
manifestName
,
fmt
.
Sprintf
(
"%s.resources[%d]"
,
jsonPath
,
i
))
add
Chart
Instances
(
instances
,
sr
,
deploymentName
,
manifestName
,
fmt
.
Sprintf
(
"%s.resources[%d]"
,
jsonPath
,
i
))
}
}
}
}
...
@@ -286,7 +277,7 @@ func (m *manager) DeleteDeployment(name string, forget bool) (*common.Deployment
...
@@ -286,7 +277,7 @@ func (m *manager) DeleteDeployment(name string, forget bool) (*common.Deployment
}
}
// Finally remove the type instances for this deployment.
// Finally remove the type instances for this deployment.
m
.
repository
.
Clear
Type
InstancesForDeployment
(
name
)
m
.
repository
.
Clear
Chart
InstancesForDeployment
(
name
)
return
d
,
nil
return
d
,
nil
}
}
...
@@ -319,7 +310,7 @@ func (m *manager) PutDeployment(name string, t *common.Template) (*common.Deploy
...
@@ -319,7 +310,7 @@ func (m *manager) PutDeployment(name string, t *common.Template) (*common.Deploy
}
}
// Finally update the type instances for this deployment.
// Finally update the type instances for this deployment.
m
.
set
Type
Instances
(
t
.
Name
,
manifest
.
Name
,
manifest
.
Layout
)
m
.
set
Chart
Instances
(
t
.
Name
,
manifest
.
Name
,
manifest
.
Layout
)
return
m
.
repository
.
GetValidDeployment
(
t
.
Name
)
return
m
.
repository
.
GetValidDeployment
(
t
.
Name
)
}
}
...
@@ -336,59 +327,47 @@ func (m *manager) Expand(t *common.Template) (*common.Manifest, error) {
...
@@ -336,59 +327,47 @@ func (m *manager) Expand(t *common.Template) (*common.Manifest, error) {
},
nil
},
nil
}
}
func
(
m
*
manager
)
List
Type
s
()
([]
string
,
error
)
{
func
(
m
*
manager
)
List
Chart
s
()
([]
string
,
error
)
{
return
m
.
repository
.
List
Type
s
()
return
m
.
repository
.
List
Chart
s
()
}
}
func
(
m
*
manager
)
List
Instances
(
typeName
string
)
([]
*
common
.
Type
Instance
,
error
)
{
func
(
m
*
manager
)
List
ChartInstances
(
chartName
string
)
([]
*
common
.
Chart
Instance
,
error
)
{
return
m
.
repository
.
Get
TypeInstances
(
type
Name
)
return
m
.
repository
.
Get
ChartInstances
(
chart
Name
)
}
}
// GetRe
gistryForType returns the registry where a type
resides.
// GetRe
poForChart returns the repository where a chart
resides.
func
(
m
*
manager
)
GetRe
gistryForType
(
type
Name
string
)
(
string
,
error
)
{
func
(
m
*
manager
)
GetRe
poForChart
(
chart
Name
string
)
(
string
,
error
)
{
_
,
r
,
err
:=
registry
.
GetDownloadURLs
(
m
.
registryProvider
,
type
Name
)
_
,
r
,
err
:=
m
.
repoProvider
.
GetChartByReference
(
chart
Name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
return
r
.
Get
Registry
Name
(),
nil
return
r
.
GetName
(),
nil
}
}
// GetMetadataFor
Type returns the metadata for type
.
// GetMetadataFor
Chart returns the metadata for a chart
.
func
(
m
*
manager
)
GetMetadataFor
Type
(
typeName
string
)
(
string
,
error
)
{
func
(
m
*
manager
)
GetMetadataFor
Chart
(
chartName
string
)
(
*
chart
.
Chartfile
,
error
)
{
URLs
,
r
,
err
:=
registry
.
GetDownloadURLs
(
m
.
registryProvider
,
type
Name
)
c
,
_
,
err
:=
m
.
repoProvider
.
GetChartByReference
(
chart
Name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
nil
,
err
}
if
len
(
URLs
)
<
1
{
return
""
,
nil
}
}
// If it's a chart, we want the provenance file
return
c
.
Chartfile
(),
nil
fPath
:=
URLs
[
0
]
}
if
!
strings
.
Contains
(
fPath
,
".prov"
)
{
// It's not a chart, so we want the schema
fPath
+=
".schema"
}
metadata
,
err
:=
getFileFromRegistry
(
fPath
,
r
)
// GetChart returns a chart.
func
(
m
*
manager
)
GetChart
(
chartName
string
)
(
*
chart
.
Chart
,
error
)
{
c
,
_
,
err
:=
m
.
repoProvider
.
GetChartByReference
(
chartName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"cannot get metadata for type (%s): %s"
,
typeName
,
err
)
return
nil
,
err
}
}
return
metadata
,
nil
return
c
,
nil
}
// ListRegistries returns the list of registries
func
(
m
*
manager
)
ListRegistries
()
([]
*
common
.
Registry
,
error
)
{
return
m
.
service
.
List
()
}
}
// ListChartRepos returns the list of chart repositories
// ListChartRepos returns the list of chart repositories
func
(
m
*
manager
)
ListChartRepos
()
([]
string
,
error
)
{
func
(
m
*
manager
)
ListChartRepos
()
([]
string
,
error
)
{
//TODO: implement
return
m
.
service
.
List
()
return
nil
,
nil
}
}
// AddChartRepo adds a chart repository to list of available chart repositories
// AddChartRepo adds a chart repository to list of available chart repositories
...
@@ -399,22 +378,17 @@ func (m *manager) AddChartRepo(name string) error {
...
@@ -399,22 +378,17 @@ func (m *manager) AddChartRepo(name string) error {
// RemoveChartRepo removes a chart repository to list of available chart repositories
// RemoveChartRepo removes a chart repository to list of available chart repositories
func
(
m
*
manager
)
RemoveChartRepo
(
name
string
)
error
{
func
(
m
*
manager
)
RemoveChartRepo
(
name
string
)
error
{
//TODO: implement
return
m
.
service
.
Delete
(
name
)
return
nil
}
}
func
(
m
*
manager
)
CreateRe
gistry
(
pr
*
common
.
Registry
)
error
{
func
(
m
*
manager
)
CreateRe
po
(
pr
repo
.
IRepo
)
error
{
return
m
.
service
.
Create
(
pr
)
return
m
.
service
.
Create
(
pr
)
}
}
func
(
m
*
manager
)
GetRe
gistry
(
name
string
)
(
*
common
.
Registry
,
error
)
{
func
(
m
*
manager
)
GetRe
po
(
name
string
)
(
repo
.
IRepo
,
error
)
{
return
m
.
service
.
Get
(
name
)
return
m
.
service
.
Get
(
name
)
}
}
func
(
m
*
manager
)
DeleteRegistry
(
name
string
)
error
{
return
m
.
service
.
Delete
(
name
)
}
func
generateManifestName
()
string
{
func
generateManifestName
()
string
{
return
fmt
.
Sprintf
(
"manifest-%d"
,
time
.
Now
()
.
UTC
()
.
UnixNano
())
return
fmt
.
Sprintf
(
"manifest-%d"
,
time
.
Now
()
.
UTC
()
.
UnixNano
())
}
}
...
@@ -437,54 +411,33 @@ func getResourceErrors(c *common.Configuration) []string {
...
@@ -437,54 +411,33 @@ func getResourceErrors(c *common.Configuration) []string {
return
errs
return
errs
}
}
// ListRe
gistryTypes lists types in a given registry whose string valu
es
// ListRe
poCharts lists charts in a given repository whose nam
es
// conform to the supplied regular expression, or all
type
s, if the regular
// conform to the supplied regular expression, or all
chart
s, if the regular
// expression is nil.
// expression is nil.
func
(
m
*
manager
)
ListRe
gistryTypes
(
registryName
string
,
regex
*
regexp
.
Regexp
)
([]
registry
.
Type
,
error
)
{
func
(
m
*
manager
)
ListRe
poCharts
(
repoName
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
{
r
,
err
:=
m
.
re
gistryProvider
.
GetRegistryByName
(
registry
Name
)
r
,
err
:=
m
.
re
poProvider
.
GetRepoByName
(
repo
Name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
r
.
List
Type
s
(
regex
)
return
r
.
List
Chart
s
(
regex
)
}
}
// GetDownloadURLs returns the URLs required to download the contents
// GetChartForRepo returns a chart from a given repository.
// of a given type in a given registry.
func
(
m
*
manager
)
GetChartForRepo
(
repoName
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
{
func
(
m
*
manager
)
GetDownloadURLs
(
registryName
string
,
t
registry
.
Type
)
([]
*
url
.
URL
,
error
)
{
r
,
err
:=
m
.
repoProvider
.
GetRepoByName
(
repoName
)
r
,
err
:=
m
.
registryProvider
.
GetRegistryByName
(
registryName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
r
.
GetDownloadURLs
(
t
)
return
r
.
GetChart
(
chartName
)
}
// GetFile returns a file from the backing registry
func
(
m
*
manager
)
GetFile
(
registryName
string
,
url
string
)
(
string
,
error
)
{
r
,
err
:=
m
.
registryProvider
.
GetRegistryByName
(
registryName
)
if
err
!=
nil
{
return
""
,
err
}
return
getFileFromRegistry
(
url
,
r
)
}
func
getFileFromRegistry
(
url
string
,
r
registry
.
Registry
)
(
string
,
error
)
{
getter
:=
util
.
NewHTTPClient
(
3
,
r
,
util
.
NewSleeper
())
body
,
_
,
err
:=
getter
.
Get
(
url
)
if
err
!=
nil
{
return
""
,
err
}
return
body
,
nil
}
}
// CreateCredential creates a credential that can be used to authenticate to re
gist
ry
// CreateCredential creates a credential that can be used to authenticate to re
posito
ry
func
(
m
*
manager
)
CreateCredential
(
name
string
,
c
*
common
.
Registry
Credential
)
error
{
func
(
m
*
manager
)
CreateCredential
(
name
string
,
c
*
repo
.
Credential
)
error
{
return
m
.
credentialProvider
.
SetCredential
(
name
,
c
)
return
m
.
credentialProvider
.
SetCredential
(
name
,
c
)
}
}
func
(
m
*
manager
)
GetCredential
(
name
string
)
(
*
common
.
Registry
Credential
,
error
)
{
func
(
m
*
manager
)
GetCredential
(
name
string
)
(
*
repo
.
Credential
,
error
)
{
return
m
.
credentialProvider
.
GetCredential
(
name
)
return
m
.
credentialProvider
.
GetCredential
(
name
)
}
}
cmd/manager/manager/manager_test.go
View file @
43a6876a
...
@@ -17,13 +17,13 @@ limitations under the License.
...
@@ -17,13 +17,13 @@ limitations under the License.
package
manager
package
manager
import
(
import
(
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/repo"
"errors"
"errors"
"reflect"
"reflect"
"strings"
"strings"
"testing"
"testing"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/registry"
)
)
var
template
=
common
.
Template
{
Name
:
"test"
,
Content
:
"test"
}
var
template
=
common
.
Template
{
Name
:
"test"
,
Content
:
"test"
}
...
@@ -128,17 +128,17 @@ func (deployer *deployerStub) PutConfiguration(configuration *common.Configurati
...
@@ -128,17 +128,17 @@ func (deployer *deployerStub) PutConfiguration(configuration *common.Configurati
}
}
type
repositoryStub
struct
{
type
repositoryStub
struct
{
FailListDeployments
bool
FailListDeployments
bool
Created
[]
string
Created
[]
string
ManifestAdd
map
[
string
]
*
common
.
Manifest
ManifestAdd
map
[
string
]
*
common
.
Manifest
ManifestSet
map
[
string
]
*
common
.
Manifest
ManifestSet
map
[
string
]
*
common
.
Manifest
Deleted
[]
string
Deleted
[]
string
GetValid
[]
string
GetValid
[]
string
Type
Instances
map
[
string
][]
string
Chart
Instances
map
[
string
][]
string
Type
InstancesCleared
bool
Chart
InstancesCleared
bool
Get
Type
InstancesCalled
bool
Get
Chart
InstancesCalled
bool
ListTypesCalled
bool
ListTypesCalled
bool
DeploymentStates
[]
*
common
.
DeploymentState
DeploymentStates
[]
*
common
.
DeploymentState
}
}
func
(
repository
*
repositoryStub
)
reset
()
{
func
(
repository
*
repositoryStub
)
reset
()
{
...
@@ -148,9 +148,9 @@ func (repository *repositoryStub) reset() {
...
@@ -148,9 +148,9 @@ func (repository *repositoryStub) reset() {
repository
.
ManifestSet
=
make
(
map
[
string
]
*
common
.
Manifest
)
repository
.
ManifestSet
=
make
(
map
[
string
]
*
common
.
Manifest
)
repository
.
Deleted
=
make
([]
string
,
0
)
repository
.
Deleted
=
make
([]
string
,
0
)
repository
.
GetValid
=
make
([]
string
,
0
)
repository
.
GetValid
=
make
([]
string
,
0
)
repository
.
Type
Instances
=
make
(
map
[
string
][]
string
)
repository
.
Chart
Instances
=
make
(
map
[
string
][]
string
)
repository
.
Type
InstancesCleared
=
false
repository
.
Chart
InstancesCleared
=
false
repository
.
Get
Type
InstancesCalled
=
false
repository
.
Get
Chart
InstancesCalled
=
false
repository
.
ListTypesCalled
=
false
repository
.
ListTypesCalled
=
false
repository
.
DeploymentStates
=
[]
*
common
.
DeploymentState
{}
repository
.
DeploymentStates
=
[]
*
common
.
DeploymentState
{}
}
}
...
@@ -233,26 +233,26 @@ func (repository *repositoryStub) GetLatestManifest(d string) (*common.Manifest,
...
@@ -233,26 +233,26 @@ func (repository *repositoryStub) GetLatestManifest(d string) (*common.Manifest,
}
}
// Types.
// Types.
func
(
repository
*
repositoryStub
)
List
Type
s
()
([]
string
,
error
)
{
func
(
repository
*
repositoryStub
)
List
Chart
s
()
([]
string
,
error
)
{
repository
.
ListTypesCalled
=
true
repository
.
ListTypesCalled
=
true
return
[]
string
{},
nil
return
[]
string
{},
nil
}
}
func
(
repository
*
repositoryStub
)
Get
TypeInstances
(
t
string
)
([]
*
common
.
Type
Instance
,
error
)
{
func
(
repository
*
repositoryStub
)
Get
ChartInstances
(
t
string
)
([]
*
common
.
Chart
Instance
,
error
)
{
repository
.
Get
Type
InstancesCalled
=
true
repository
.
Get
Chart
InstancesCalled
=
true
return
[]
*
common
.
Type
Instance
{},
nil
return
[]
*
common
.
Chart
Instance
{},
nil
}
}
func
(
repository
*
repositoryStub
)
Clear
Type
InstancesForDeployment
(
d
string
)
error
{
func
(
repository
*
repositoryStub
)
Clear
Chart
InstancesForDeployment
(
d
string
)
error
{
repository
.
Type
InstancesCleared
=
true
repository
.
Chart
InstancesCleared
=
true
return
nil
return
nil
}
}
func
(
repository
*
repositoryStub
)
Add
TypeInstances
(
is
map
[
string
][]
*
common
.
Type
Instance
)
error
{
func
(
repository
*
repositoryStub
)
Add
ChartInstances
(
is
map
[
string
][]
*
common
.
Chart
Instance
)
error
{
for
t
,
instances
:=
range
is
{
for
t
,
instances
:=
range
is
{
for
_
,
instance
:=
range
instances
{
for
_
,
instance
:=
range
instances
{
d
:=
instance
.
Deployment
d
:=
instance
.
Deployment
repository
.
TypeInstances
[
d
]
=
append
(
repository
.
Type
Instances
[
d
],
t
)
repository
.
ChartInstances
[
d
]
=
append
(
repository
.
Chart
Instances
[
d
],
t
)
}
}
}
}
...
@@ -264,10 +264,10 @@ func (repository *repositoryStub) Close() {}
...
@@ -264,10 +264,10 @@ func (repository *repositoryStub) Close() {}
var
testExpander
=
&
expanderStub
{}
var
testExpander
=
&
expanderStub
{}
var
testRepository
=
newRepositoryStub
()
var
testRepository
=
newRepositoryStub
()
var
testDeployer
=
newDeployerStub
()
var
testDeployer
=
newDeployerStub
()
var
testRe
gistryService
=
registry
.
NewInmemRegistry
Service
()
var
testRe
poService
=
repo
.
NewInmemRepo
Service
()
var
testCredentialProvider
=
re
gistry
.
NewInmemCredentialProvider
()
var
testCredentialProvider
=
re
po
.
NewInmemCredentialProvider
()
var
testProvider
=
re
gistry
.
NewRegistryProvider
(
nil
,
registry
.
NewTestGithubRegistryProvider
(
""
,
nil
),
registry
.
NewTestGCSRegistryProvider
(
""
,
nil
),
testCredentialProvider
)
var
testProvider
=
re
po
.
NewRepoProvider
(
nil
,
repo
.
NewGCSRepoProvider
(
testCredentialProvider
),
testCredentialProvider
)
var
testManager
=
NewManager
(
testExpander
,
testDeployer
,
testRepository
,
testProvider
,
testRe
gistry
Service
,
testCredentialProvider
)
var
testManager
=
NewManager
(
testExpander
,
testDeployer
,
testRepository
,
testProvider
,
testRe
po
Service
,
testCredentialProvider
)
func
TestListDeployments
(
t
*
testing
.
T
)
{
func
TestListDeployments
(
t
*
testing
.
T
)
{
testRepository
.
reset
()
testRepository
.
reset
()
...
@@ -363,12 +363,12 @@ func TestCreateDeployment(t *testing.T) {
...
@@ -363,12 +363,12 @@ func TestCreateDeployment(t *testing.T) {
t
.
Fatal
(
"CreateDeployment success did not mark deployment as deployed"
)
t
.
Fatal
(
"CreateDeployment success did not mark deployment as deployed"
)
}
}
if
!
testRepository
.
Type
InstancesCleared
{
if
!
testRepository
.
Chart
InstancesCleared
{
t
.
Fatal
(
"Repository did not clear type instances during creation"
)
t
.
Fatal
(
"Repository did not clear type instances during creation"
)
}
}
if
!
reflect
.
DeepEqual
(
testRepository
.
Type
Instances
,
typeInstMap
)
{
if
!
reflect
.
DeepEqual
(
testRepository
.
Chart
Instances
,
typeInstMap
)
{
t
.
Fatalf
(
"Unexpected type instances after CreateDeployment: %s"
,
testRepository
.
Type
Instances
)
t
.
Fatalf
(
"Unexpected type instances after CreateDeployment: %s"
,
testRepository
.
Chart
Instances
)
}
}
}
}
...
@@ -397,7 +397,7 @@ func TestCreateDeploymentCreationFailure(t *testing.T) {
...
@@ -397,7 +397,7 @@ func TestCreateDeploymentCreationFailure(t *testing.T) {
"Received: %v, %s. Expected: %s, %s."
,
d
,
err
,
"nil"
,
errTest
)
"Received: %v, %s. Expected: %s, %s."
,
d
,
err
,
"nil"
,
errTest
)
}
}
if
testRepository
.
Type
InstancesCleared
{
if
testRepository
.
Chart
InstancesCleared
{
t
.
Fatal
(
"Unexpected change to type instances during CreateDeployment failure."
)
t
.
Fatal
(
"Unexpected change to type instances during CreateDeployment failure."
)
}
}
}
}
...
@@ -437,7 +437,7 @@ func TestCreateDeploymentCreationResourceFailure(t *testing.T) {
...
@@ -437,7 +437,7 @@ func TestCreateDeploymentCreationResourceFailure(t *testing.T) {
"Received: %v, %v. Expected: %v, %v."
,
d
,
err
,
&
deployment
,
"nil"
)
"Received: %v, %v. Expected: %v, %v."
,
d
,
err
,
&
deployment
,
"nil"
)
}
}
if
!
testRepository
.
Type
InstancesCleared
{
if
!
testRepository
.
Chart
InstancesCleared
{
t
.
Fatal
(
"Repository did not clear type instances during creation"
)
t
.
Fatal
(
"Repository did not clear type instances during creation"
)
}
}
}
}
...
@@ -486,7 +486,7 @@ func TestDeleteDeploymentForget(t *testing.T) {
...
@@ -486,7 +486,7 @@ func TestDeleteDeploymentForget(t *testing.T) {
}
}
}
}
if
!
testRepository
.
Type
InstancesCleared
{
if
!
testRepository
.
Chart
InstancesCleared
{
t
.
Fatal
(
"Expected type instances to be cleared during DeleteDeployment."
)
t
.
Fatal
(
"Expected type instances to be cleared during DeleteDeployment."
)
}
}
}
}
...
@@ -521,29 +521,29 @@ func TestExpand(t *testing.T) {
...
@@ -521,29 +521,29 @@ func TestExpand(t *testing.T) {
func
TestListTypes
(
t
*
testing
.
T
)
{
func
TestListTypes
(
t
*
testing
.
T
)
{
testRepository
.
reset
()
testRepository
.
reset
()
testManager
.
List
Type
s
()
testManager
.
List
Chart
s
()
if
!
testRepository
.
ListTypesCalled
{
if
!
testRepository
.
ListTypesCalled
{
t
.
Fatal
(
"expected repository List
Type
s() call."
)
t
.
Fatal
(
"expected repository List
Chart
s() call."
)
}
}
}
}
func
TestListInstances
(
t
*
testing
.
T
)
{
func
TestListInstances
(
t
*
testing
.
T
)
{
testRepository
.
reset
()
testRepository
.
reset
()
testManager
.
ListInstances
(
"all"
)
testManager
.
List
Chart
Instances
(
"all"
)
if
!
testRepository
.
Get
Type
InstancesCalled
{
if
!
testRepository
.
Get
Chart
InstancesCalled
{
t
.
Fatal
(
"expected repository Get
Type
Instances() call."
)
t
.
Fatal
(
"expected repository Get
Chart
Instances() call."
)
}
}
}
}
// TODO(jackgr): Implement TestListRe
gistryType
s
// TODO(jackgr): Implement TestListRe
poChart
s
func
TestListRe
gistryType
s
(
t
*
testing
.
T
)
{
func
TestListRe
poChart
s
(
t
*
testing
.
T
)
{
/*
/*
types, err := testManager.ListRe
gistryType
s("", nil)
types, err := testManager.ListRe
poChart
s("", nil)
if err != nil {
if err != nil {
t.Fatalf("cannot list re
gist
ry types: %s", err)
t.Fatalf("cannot list re
posito
ry types: %s", err)
}
}
*/
*/
}
}
...
@@ -551,7 +551,7 @@ func TestListRegistryTypes(t *testing.T) {
...
@@ -551,7 +551,7 @@ func TestListRegistryTypes(t *testing.T) {
// TODO(jackgr): Implement TestGetDownloadURLs
// TODO(jackgr): Implement TestGetDownloadURLs
func
TestGetDownloadURLs
(
t
*
testing
.
T
)
{
func
TestGetDownloadURLs
(
t
*
testing
.
T
)
{
/*
/*
urls, err := testManager.GetDownloadURLs("", re
gistry
.Type{})
urls, err := testManager.GetDownloadURLs("", re
po
.Type{})
if err != nil {
if err != nil {
t.Fatalf("cannot list get download urls: %s", err)
t.Fatalf("cannot list get download urls: %s", err)
}
}
...
...
pkg/common/types.go
View file @
43a6876a
...
@@ -170,9 +170,9 @@ type Resource struct {
...
@@ -170,9 +170,9 @@ type Resource struct {
State
*
ResourceState
`json:"state,omitempty"`
State
*
ResourceState
`json:"state,omitempty"`
}
}
//
Type
Instance defines the metadata for an instantiation of a template type
//
Chart
Instance defines the metadata for an instantiation of a template type
// in a deployment.
// in a deployment.
type
Type
Instance
struct
{
type
Chart
Instance
struct
{
Name
string
`json:"name"`
// instance name
Name
string
`json:"name"`
// instance name
Type
string
`json:"type"`
// instance type
Type
string
`json:"type"`
// instance type
Deployment
string
`json:"deployment"`
// deployment name
Deployment
string
`json:"deployment"`
// deployment name
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment