| ... | ... |
@@ -57,6 +57,7 @@ import ( |
| 57 | 57 |
deployconfiggenerator "github.com/openshift/origin/pkg/deploy/generator" |
| 58 | 58 |
deployregistry "github.com/openshift/origin/pkg/deploy/registry/deploy" |
| 59 | 59 |
deployconfigregistry "github.com/openshift/origin/pkg/deploy/registry/deployconfig" |
| 60 |
+ deployconfigetcd "github.com/openshift/origin/pkg/deploy/registry/deployconfig/etcd" |
|
| 60 | 61 |
deployetcd "github.com/openshift/origin/pkg/deploy/registry/etcd" |
| 61 | 62 |
deployrollback "github.com/openshift/origin/pkg/deploy/rollback" |
| 62 | 63 |
"github.com/openshift/origin/pkg/dns" |
| ... | ... |
@@ -169,6 +170,9 @@ func (c *MasterConfig) InstallProtectedAPI(container *restful.Container) []strin |
| 169 | 169 |
buildConfigStorage := buildconfigetcd.NewStorage(c.EtcdHelper) |
| 170 | 170 |
buildConfigRegistry := buildconfigregistry.NewRegistry(buildConfigStorage) |
| 171 | 171 |
|
| 172 |
+ deployConfigStorage := deployconfigetcd.NewStorage(c.EtcdHelper) |
|
| 173 |
+ deployConfigRegistry := deployconfigregistry.NewRegistry(deployConfigStorage) |
|
| 174 |
+ |
|
| 172 | 175 |
deployEtcd := deployetcd.New(c.EtcdHelper) |
| 173 | 176 |
routeEtcd := routeetcd.New(c.EtcdHelper) |
| 174 | 177 |
hostSubnetStorage := hostsubnetetcd.NewREST(c.EtcdHelper) |
| ... | ... |
@@ -231,7 +235,7 @@ func (c *MasterConfig) InstallProtectedAPI(container *restful.Container) []strin |
| 231 | 231 |
// TODO: with sharding, this needs to be changed |
| 232 | 232 |
deployConfigGenerator := &deployconfiggenerator.DeploymentConfigGenerator{
|
| 233 | 233 |
Client: deployconfiggenerator.Client{
|
| 234 |
- DCFn: deployEtcd.GetDeploymentConfig, |
|
| 234 |
+ DCFn: deployConfigRegistry.GetDeploymentConfig, |
|
| 235 | 235 |
ISFn: imageStreamRegistry.GetImageStream, |
| 236 | 236 |
LISFn2: imageStreamRegistry.ListImageStreams, |
| 237 | 237 |
}, |
| ... | ... |
@@ -239,7 +243,7 @@ func (c *MasterConfig) InstallProtectedAPI(container *restful.Container) []strin |
| 239 | 239 |
_, kclient := c.DeploymentConfigControllerClients() |
| 240 | 240 |
deployRollback := &deployrollback.RollbackGenerator{}
|
| 241 | 241 |
deployRollbackClient := deployrollback.Client{
|
| 242 |
- DCFn: deployEtcd.GetDeploymentConfig, |
|
| 242 |
+ DCFn: deployConfigRegistry.GetDeploymentConfig, |
|
| 243 | 243 |
RCFn: clientDeploymentInterface{kclient}.GetDeployment,
|
| 244 | 244 |
GRFn: deployRollback.GenerateRollback, |
| 245 | 245 |
} |
| ... | ... |
@@ -285,7 +289,7 @@ func (c *MasterConfig) InstallProtectedAPI(container *restful.Container) []strin |
| 285 | 285 |
"imageRepositoryTags": imageRepositoryTagStorage, |
| 286 | 286 |
|
| 287 | 287 |
"deployments": deployregistry.NewREST(deployEtcd), |
| 288 |
- "deploymentConfigs": deployconfigregistry.NewREST(deployEtcd), |
|
| 288 |
+ "deploymentConfigs": deployConfigStorage, |
|
| 289 | 289 |
"generateDeploymentConfigs": deployconfiggenerator.NewREST(deployConfigGenerator, latest.Codec), |
| 290 | 290 |
"deploymentConfigRollbacks": deployrollback.NewREST(deployRollbackClient, latest.Codec), |
| 291 | 291 |
|
| ... | ... |
@@ -55,6 +55,13 @@ func ValidateDeploymentConfig(config *deployapi.DeploymentConfig) fielderrors.Va |
| 55 | 55 |
return errs |
| 56 | 56 |
} |
| 57 | 57 |
|
| 58 |
+func ValidateDeploymentConfigUpdate(newConfig *deployapi.DeploymentConfig, oldConfig *deployapi.DeploymentConfig) fielderrors.ValidationErrorList {
|
|
| 59 |
+ allErrs := fielderrors.ValidationErrorList{}
|
|
| 60 |
+ allErrs = append(allErrs, validation.ValidateObjectMetaUpdate(&oldConfig.ObjectMeta, &newConfig.ObjectMeta).Prefix("metadata")...)
|
|
| 61 |
+ allErrs = append(allErrs, ValidateDeploymentConfig(newConfig)...) |
|
| 62 |
+ return allErrs |
|
| 63 |
+} |
|
| 64 |
+ |
|
| 58 | 65 |
func ValidateDeploymentConfigRollback(rollback *deployapi.DeploymentConfigRollback) fielderrors.ValidationErrorList {
|
| 59 | 66 |
result := fielderrors.ValidationErrorList{}
|
| 60 | 67 |
|
| 61 | 68 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,48 @@ |
| 0 |
+package etcd |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 4 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
|
| 5 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
|
| 6 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic" |
|
| 7 |
+ etcdgeneric "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd" |
|
| 8 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" |
|
| 9 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" |
|
| 10 |
+ |
|
| 11 |
+ "github.com/openshift/origin/pkg/deploy/api" |
|
| 12 |
+ "github.com/openshift/origin/pkg/deploy/registry/deployconfig" |
|
| 13 |
+) |
|
| 14 |
+ |
|
| 15 |
+const DeploymentConfigPath string = "/deploymentconfigs" |
|
| 16 |
+ |
|
| 17 |
+type REST struct {
|
|
| 18 |
+ *etcdgeneric.Etcd |
|
| 19 |
+} |
|
| 20 |
+ |
|
| 21 |
+// NewStorage returns a RESTStorage object that will work against DeploymentConfig objects. |
|
| 22 |
+func NewStorage(h tools.EtcdHelper) *REST {
|
|
| 23 |
+ store := &etcdgeneric.Etcd{
|
|
| 24 |
+ NewFunc: func() runtime.Object { return &api.DeploymentConfig{} },
|
|
| 25 |
+ NewListFunc: func() runtime.Object { return &api.DeploymentConfigList{} },
|
|
| 26 |
+ EndpointName: "deploymentConfig", |
|
| 27 |
+ KeyRootFunc: func(ctx kapi.Context) string {
|
|
| 28 |
+ return etcdgeneric.NamespaceKeyRootFunc(ctx, DeploymentConfigPath) |
|
| 29 |
+ }, |
|
| 30 |
+ KeyFunc: func(ctx kapi.Context, id string) (string, error) {
|
|
| 31 |
+ return etcdgeneric.NamespaceKeyFunc(ctx, DeploymentConfigPath, id) |
|
| 32 |
+ }, |
|
| 33 |
+ ObjectNameFunc: func(obj runtime.Object) (string, error) {
|
|
| 34 |
+ return obj.(*api.DeploymentConfig).Name, nil |
|
| 35 |
+ }, |
|
| 36 |
+ PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
|
|
| 37 |
+ return deployconfig.Matcher(label, field) |
|
| 38 |
+ }, |
|
| 39 |
+ CreateStrategy: deployconfig.Strategy, |
|
| 40 |
+ UpdateStrategy: deployconfig.Strategy, |
|
| 41 |
+ DeleteStrategy: deployconfig.Strategy, |
|
| 42 |
+ ReturnDeletedObject: false, |
|
| 43 |
+ Helper: h, |
|
| 44 |
+ } |
|
| 45 |
+ |
|
| 46 |
+ return &REST{store}
|
|
| 47 |
+} |
| ... | ... |
@@ -2,6 +2,7 @@ package deployconfig |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
| 5 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest" |
|
| 5 | 6 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
| 6 | 7 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
| 7 | 8 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" |
| ... | ... |
@@ -13,8 +14,54 @@ import ( |
| 13 | 13 |
type Registry interface {
|
| 14 | 14 |
ListDeploymentConfigs(ctx kapi.Context, label labels.Selector, field fields.Selector) (*deployapi.DeploymentConfigList, error) |
| 15 | 15 |
WatchDeploymentConfigs(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) |
| 16 |
- GetDeploymentConfig(ctx kapi.Context, id string) (*deployapi.DeploymentConfig, error) |
|
| 16 |
+ GetDeploymentConfig(ctx kapi.Context, name string) (*deployapi.DeploymentConfig, error) |
|
| 17 | 17 |
CreateDeploymentConfig(ctx kapi.Context, deploymentConfig *deployapi.DeploymentConfig) error |
| 18 | 18 |
UpdateDeploymentConfig(ctx kapi.Context, deploymentConfig *deployapi.DeploymentConfig) error |
| 19 |
- DeleteDeploymentConfig(ctx kapi.Context, id string) error |
|
| 19 |
+ DeleteDeploymentConfig(ctx kapi.Context, name string) error |
|
| 20 |
+} |
|
| 21 |
+ |
|
| 22 |
+// storage puts strong typing around storage calls |
|
| 23 |
+type storage struct {
|
|
| 24 |
+ rest.StandardStorage |
|
| 25 |
+} |
|
| 26 |
+ |
|
| 27 |
+// NewRegistry returns a new Registry interface for the given Storage. Any mismatched |
|
| 28 |
+// types will panic. |
|
| 29 |
+func NewRegistry(s rest.StandardStorage) Registry {
|
|
| 30 |
+ return &storage{s}
|
|
| 31 |
+} |
|
| 32 |
+ |
|
| 33 |
+func (s *storage) ListDeploymentConfigs(ctx kapi.Context, label labels.Selector, field fields.Selector) (*deployapi.DeploymentConfigList, error) {
|
|
| 34 |
+ obj, err := s.List(ctx, label, field) |
|
| 35 |
+ if err != nil {
|
|
| 36 |
+ return nil, err |
|
| 37 |
+ } |
|
| 38 |
+ return obj.(*deployapi.DeploymentConfigList), nil |
|
| 39 |
+} |
|
| 40 |
+ |
|
| 41 |
+func (s *storage) WatchDeploymentConfigs(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
|
|
| 42 |
+ return s.Watch(ctx, label, field, resourceVersion) |
|
| 43 |
+} |
|
| 44 |
+ |
|
| 45 |
+func (s *storage) GetDeploymentConfig(ctx kapi.Context, name string) (*deployapi.DeploymentConfig, error) {
|
|
| 46 |
+ obj, err := s.Get(ctx, name) |
|
| 47 |
+ if err != nil {
|
|
| 48 |
+ return nil, err |
|
| 49 |
+ } |
|
| 50 |
+ return obj.(*deployapi.DeploymentConfig), nil |
|
| 51 |
+} |
|
| 52 |
+ |
|
| 53 |
+func (s *storage) CreateDeploymentConfig(ctx kapi.Context, deploymentConfig *deployapi.DeploymentConfig) error {
|
|
| 54 |
+ _, err := s.Create(ctx, deploymentConfig) |
|
| 55 |
+ return err |
|
| 56 |
+} |
|
| 57 |
+ |
|
| 58 |
+func (s *storage) UpdateDeploymentConfig(ctx kapi.Context, deploymentConfig *deployapi.DeploymentConfig) error {
|
|
| 59 |
+ _, _, err := s.Update(ctx, deploymentConfig) |
|
| 60 |
+ return err |
|
| 61 |
+} |
|
| 62 |
+ |
|
| 63 |
+func (s *storage) DeleteDeploymentConfig(ctx kapi.Context, name string) error {
|
|
| 64 |
+ _, err := s.Delete(ctx, name, nil) |
|
| 65 |
+ return err |
|
| 20 | 66 |
} |
| 21 | 67 |
deleted file mode 100644 |
| ... | ... |
@@ -1,115 +0,0 @@ |
| 1 |
-package deployconfig |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "fmt" |
|
| 5 |
- |
|
| 6 |
- "code.google.com/p/go-uuid/uuid" |
|
| 7 |
- |
|
| 8 |
- kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 9 |
- kerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" |
|
| 10 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
|
| 11 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
|
| 12 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" |
|
| 13 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" |
|
| 14 |
- |
|
| 15 |
- deployapi "github.com/openshift/origin/pkg/deploy/api" |
|
| 16 |
- validation "github.com/openshift/origin/pkg/deploy/api/validation" |
|
| 17 |
-) |
|
| 18 |
- |
|
| 19 |
-// REST is an implementation of RESTStorage for the api server. |
|
| 20 |
-type REST struct {
|
|
| 21 |
- registry Registry |
|
| 22 |
-} |
|
| 23 |
- |
|
| 24 |
-// NewREST creates a new REST backed by the given registry. |
|
| 25 |
-func NewREST(registry Registry) *REST {
|
|
| 26 |
- return &REST{
|
|
| 27 |
- registry: registry, |
|
| 28 |
- } |
|
| 29 |
-} |
|
| 30 |
- |
|
| 31 |
-// New creates a new DeploymentConfig for use with Create and Update. |
|
| 32 |
-func (s *REST) New() runtime.Object {
|
|
| 33 |
- return &deployapi.DeploymentConfig{}
|
|
| 34 |
-} |
|
| 35 |
- |
|
| 36 |
-func (*REST) NewList() runtime.Object {
|
|
| 37 |
- return &deployapi.DeploymentConfig{}
|
|
| 38 |
-} |
|
| 39 |
- |
|
| 40 |
-// List obtains a list of DeploymentConfigs that match selector. |
|
| 41 |
-func (s *REST) List(ctx kapi.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) {
|
|
| 42 |
- deploymentConfigs, err := s.registry.ListDeploymentConfigs(ctx, label, field) |
|
| 43 |
- if err != nil {
|
|
| 44 |
- return nil, err |
|
| 45 |
- } |
|
| 46 |
- |
|
| 47 |
- return deploymentConfigs, nil |
|
| 48 |
-} |
|
| 49 |
- |
|
| 50 |
-// Watch begins watching for new, changed, or deleted ImageRepositories. |
|
| 51 |
-func (s *REST) Watch(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
|
|
| 52 |
- return s.registry.WatchDeploymentConfigs(ctx, label, field, resourceVersion) |
|
| 53 |
-} |
|
| 54 |
- |
|
| 55 |
-// Get obtains the DeploymentConfig specified by its id. |
|
| 56 |
-func (s *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) {
|
|
| 57 |
- deploymentConfig, err := s.registry.GetDeploymentConfig(ctx, id) |
|
| 58 |
- if err != nil {
|
|
| 59 |
- return nil, err |
|
| 60 |
- } |
|
| 61 |
- return deploymentConfig, err |
|
| 62 |
-} |
|
| 63 |
- |
|
| 64 |
-// Delete asynchronously deletes the DeploymentConfig specified by its id. |
|
| 65 |
-func (s *REST) Delete(ctx kapi.Context, id string) (runtime.Object, error) {
|
|
| 66 |
- return &kapi.Status{Status: kapi.StatusSuccess}, s.registry.DeleteDeploymentConfig(ctx, id)
|
|
| 67 |
-} |
|
| 68 |
- |
|
| 69 |
-// Create registers a given new DeploymentConfig instance to s.registry. |
|
| 70 |
-func (s *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
|
|
| 71 |
- deploymentConfig, ok := obj.(*deployapi.DeploymentConfig) |
|
| 72 |
- if !ok {
|
|
| 73 |
- return nil, fmt.Errorf("not a deploymentConfig: %#v", obj)
|
|
| 74 |
- } |
|
| 75 |
- |
|
| 76 |
- kapi.FillObjectMetaSystemFields(ctx, &deploymentConfig.ObjectMeta) |
|
| 77 |
- |
|
| 78 |
- if len(deploymentConfig.Name) == 0 {
|
|
| 79 |
- deploymentConfig.Name = uuid.NewUUID().String() |
|
| 80 |
- } |
|
| 81 |
- if !kapi.ValidNamespace(ctx, &deploymentConfig.ObjectMeta) {
|
|
| 82 |
- return nil, kerrors.NewConflict("deploymentConfig", deploymentConfig.Namespace, fmt.Errorf("DeploymentConfig.Namespace does not match the provided context"))
|
|
| 83 |
- } |
|
| 84 |
- |
|
| 85 |
- if errs := validation.ValidateDeploymentConfig(deploymentConfig); len(errs) > 0 {
|
|
| 86 |
- return nil, kerrors.NewInvalid("deploymentConfig", deploymentConfig.Name, errs)
|
|
| 87 |
- } |
|
| 88 |
- |
|
| 89 |
- err := s.registry.CreateDeploymentConfig(ctx, deploymentConfig) |
|
| 90 |
- if err != nil {
|
|
| 91 |
- return nil, err |
|
| 92 |
- } |
|
| 93 |
- return deploymentConfig, nil |
|
| 94 |
-} |
|
| 95 |
- |
|
| 96 |
-// Update replaces a given DeploymentConfig instance with an existing instance in s.registry. |
|
| 97 |
-func (s *REST) Update(ctx kapi.Context, obj runtime.Object) (runtime.Object, bool, error) {
|
|
| 98 |
- deploymentConfig, ok := obj.(*deployapi.DeploymentConfig) |
|
| 99 |
- if !ok {
|
|
| 100 |
- return nil, false, fmt.Errorf("not a deploymentConfig: %#v", obj)
|
|
| 101 |
- } |
|
| 102 |
- if len(deploymentConfig.Name) == 0 {
|
|
| 103 |
- return nil, false, fmt.Errorf("id is unspecified: %#v", deploymentConfig)
|
|
| 104 |
- } |
|
| 105 |
- if !kapi.ValidNamespace(ctx, &deploymentConfig.ObjectMeta) {
|
|
| 106 |
- return nil, false, kerrors.NewConflict("deploymentConfig", deploymentConfig.Namespace, fmt.Errorf("DeploymentConfig.Namespace does not match the provided context"))
|
|
| 107 |
- } |
|
| 108 |
- |
|
| 109 |
- err := s.registry.UpdateDeploymentConfig(ctx, deploymentConfig) |
|
| 110 |
- if err != nil {
|
|
| 111 |
- return nil, false, err |
|
| 112 |
- } |
|
| 113 |
- out, err := s.Get(ctx, deploymentConfig.Name) |
|
| 114 |
- return out, false, err |
|
| 115 |
-} |
| 116 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,300 +0,0 @@ |
| 1 |
-package deployconfig |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "fmt" |
|
| 5 |
- "net/http" |
|
| 6 |
- "strings" |
|
| 7 |
- "testing" |
|
| 8 |
- |
|
| 9 |
- kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 10 |
- kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client" |
|
| 11 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
|
| 12 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
|
| 13 |
- "github.com/openshift/origin/pkg/deploy/api" |
|
| 14 |
- deploytest "github.com/openshift/origin/pkg/deploy/api/test" |
|
| 15 |
- "github.com/openshift/origin/pkg/deploy/registry/test" |
|
| 16 |
-) |
|
| 17 |
- |
|
| 18 |
-func TestListDeploymentConfigsError(t *testing.T) {
|
|
| 19 |
- mockRegistry := test.NewDeploymentConfigRegistry() |
|
| 20 |
- mockRegistry.Err = fmt.Errorf("test error")
|
|
| 21 |
- |
|
| 22 |
- storage := REST{
|
|
| 23 |
- registry: mockRegistry, |
|
| 24 |
- } |
|
| 25 |
- |
|
| 26 |
- deploymentConfigs, err := storage.List(kapi.NewDefaultContext(), nil, nil) |
|
| 27 |
- if err != mockRegistry.Err {
|
|
| 28 |
- t.Errorf("Expected %#v, Got %#v", mockRegistry.Err, err)
|
|
| 29 |
- } |
|
| 30 |
- |
|
| 31 |
- if deploymentConfigs != nil {
|
|
| 32 |
- t.Errorf("Unexpected non-nil deploymentConfigs list: %#v", deploymentConfigs)
|
|
| 33 |
- } |
|
| 34 |
-} |
|
| 35 |
- |
|
| 36 |
-func TestListDeploymentConfigsEmptyList(t *testing.T) {
|
|
| 37 |
- mockRegistry := test.NewDeploymentConfigRegistry() |
|
| 38 |
- mockRegistry.DeploymentConfigs = &api.DeploymentConfigList{
|
|
| 39 |
- Items: []api.DeploymentConfig{},
|
|
| 40 |
- } |
|
| 41 |
- |
|
| 42 |
- storage := REST{
|
|
| 43 |
- registry: mockRegistry, |
|
| 44 |
- } |
|
| 45 |
- |
|
| 46 |
- deploymentConfigs, err := storage.List(kapi.NewDefaultContext(), labels.Everything(), fields.Everything()) |
|
| 47 |
- if err != nil {
|
|
| 48 |
- t.Errorf("Unexpected non-nil error: %#v", err)
|
|
| 49 |
- } |
|
| 50 |
- |
|
| 51 |
- if len(deploymentConfigs.(*api.DeploymentConfigList).Items) != 0 {
|
|
| 52 |
- t.Errorf("Unexpected non-zero deploymentConfigs list: %#v", deploymentConfigs)
|
|
| 53 |
- } |
|
| 54 |
-} |
|
| 55 |
- |
|
| 56 |
-func TestListDeploymentConfigsPopulatedList(t *testing.T) {
|
|
| 57 |
- mockRegistry := test.NewDeploymentConfigRegistry() |
|
| 58 |
- mockRegistry.DeploymentConfigs = &api.DeploymentConfigList{
|
|
| 59 |
- Items: []api.DeploymentConfig{
|
|
| 60 |
- {
|
|
| 61 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 62 |
- Name: "foo", |
|
| 63 |
- }, |
|
| 64 |
- }, |
|
| 65 |
- {
|
|
| 66 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 67 |
- Name: "bar", |
|
| 68 |
- }, |
|
| 69 |
- }, |
|
| 70 |
- }, |
|
| 71 |
- } |
|
| 72 |
- |
|
| 73 |
- storage := REST{
|
|
| 74 |
- registry: mockRegistry, |
|
| 75 |
- } |
|
| 76 |
- |
|
| 77 |
- list, err := storage.List(kapi.NewDefaultContext(), labels.Everything(), fields.Everything()) |
|
| 78 |
- if err != nil {
|
|
| 79 |
- t.Errorf("Unexpected non-nil error: %#v", err)
|
|
| 80 |
- } |
|
| 81 |
- |
|
| 82 |
- deploymentConfigs := list.(*api.DeploymentConfigList) |
|
| 83 |
- |
|
| 84 |
- if e, a := 2, len(deploymentConfigs.Items); e != a {
|
|
| 85 |
- t.Errorf("Expected %v, got %v", e, a)
|
|
| 86 |
- } |
|
| 87 |
-} |
|
| 88 |
- |
|
| 89 |
-func TestCreateDeploymentConfigBadObject(t *testing.T) {
|
|
| 90 |
- storage := REST{}
|
|
| 91 |
- |
|
| 92 |
- obj, err := storage.Create(kapi.NewDefaultContext(), &api.DeploymentList{})
|
|
| 93 |
- if obj != nil {
|
|
| 94 |
- t.Errorf("Expected nil, got %v", obj)
|
|
| 95 |
- } |
|
| 96 |
- if strings.Index(err.Error(), "not a deploymentConfig") == -1 {
|
|
| 97 |
- t.Errorf("Expected 'not a deploymentConfig' error, got '%v'", err.Error())
|
|
| 98 |
- } |
|
| 99 |
-} |
|
| 100 |
- |
|
| 101 |
-func TestCreateRegistrySaveError(t *testing.T) {
|
|
| 102 |
- mockRegistry := test.NewDeploymentConfigRegistry() |
|
| 103 |
- mockRegistry.Err = fmt.Errorf("test error")
|
|
| 104 |
- storage := REST{registry: mockRegistry}
|
|
| 105 |
- |
|
| 106 |
- _, err := storage.Create(kapi.NewDefaultContext(), &api.DeploymentConfig{
|
|
| 107 |
- ObjectMeta: kapi.ObjectMeta{Name: "foo"},
|
|
| 108 |
- Template: api.DeploymentTemplate{
|
|
| 109 |
- Strategy: deploytest.OkStrategy(), |
|
| 110 |
- ControllerTemplate: deploytest.OkControllerTemplate(), |
|
| 111 |
- }, |
|
| 112 |
- }) |
|
| 113 |
- if err != mockRegistry.Err {
|
|
| 114 |
- t.Errorf("unexpected error: %v", err)
|
|
| 115 |
- } |
|
| 116 |
-} |
|
| 117 |
- |
|
| 118 |
-func TestCreateDeploymentConfigOK(t *testing.T) {
|
|
| 119 |
- mockRegistry := test.NewDeploymentConfigRegistry() |
|
| 120 |
- storage := REST{registry: mockRegistry}
|
|
| 121 |
- |
|
| 122 |
- obj, err := storage.Create(kapi.NewDefaultContext(), &api.DeploymentConfig{
|
|
| 123 |
- ObjectMeta: kapi.ObjectMeta{Name: "foo"},
|
|
| 124 |
- Template: api.DeploymentTemplate{
|
|
| 125 |
- Strategy: deploytest.OkStrategy(), |
|
| 126 |
- ControllerTemplate: deploytest.OkControllerTemplate(), |
|
| 127 |
- }, |
|
| 128 |
- }) |
|
| 129 |
- if obj == nil {
|
|
| 130 |
- t.Errorf("Expected nil obj, got %v", obj)
|
|
| 131 |
- } |
|
| 132 |
- if err != nil {
|
|
| 133 |
- t.Errorf("Unexpected non-nil error: %#v", err)
|
|
| 134 |
- } |
|
| 135 |
- |
|
| 136 |
- deploymentConfig, ok := obj.(*api.DeploymentConfig) |
|
| 137 |
- if !ok {
|
|
| 138 |
- t.Errorf("Expected deploymentConfig type, got: %#v", obj)
|
|
| 139 |
- } |
|
| 140 |
- if deploymentConfig.Name != "foo" {
|
|
| 141 |
- t.Errorf("Unexpected deploymentConfig: %#v", deploymentConfig)
|
|
| 142 |
- } |
|
| 143 |
-} |
|
| 144 |
- |
|
| 145 |
-func TestGetDeploymentConfigError(t *testing.T) {
|
|
| 146 |
- mockRegistry := test.NewDeploymentConfigRegistry() |
|
| 147 |
- mockRegistry.Err = fmt.Errorf("bad")
|
|
| 148 |
- storage := REST{registry: mockRegistry}
|
|
| 149 |
- |
|
| 150 |
- deploymentConfig, err := storage.Get(kapi.NewDefaultContext(), "foo") |
|
| 151 |
- if deploymentConfig != nil {
|
|
| 152 |
- t.Errorf("Unexpected non-nil deploymentConfig: %#v", deploymentConfig)
|
|
| 153 |
- } |
|
| 154 |
- if err != mockRegistry.Err {
|
|
| 155 |
- t.Errorf("Expected %#v, got %#v", mockRegistry.Err, err)
|
|
| 156 |
- } |
|
| 157 |
-} |
|
| 158 |
- |
|
| 159 |
-func TestGetDeploymentConfigOK(t *testing.T) {
|
|
| 160 |
- mockRegistry := test.NewDeploymentConfigRegistry() |
|
| 161 |
- mockRegistry.DeploymentConfig = &api.DeploymentConfig{
|
|
| 162 |
- ObjectMeta: kapi.ObjectMeta{Name: "foo"},
|
|
| 163 |
- } |
|
| 164 |
- storage := REST{registry: mockRegistry}
|
|
| 165 |
- |
|
| 166 |
- deploymentConfig, err := storage.Get(kapi.NewDefaultContext(), "foo") |
|
| 167 |
- if deploymentConfig == nil {
|
|
| 168 |
- t.Error("Unexpected nil deploymentConfig")
|
|
| 169 |
- } |
|
| 170 |
- if err != nil {
|
|
| 171 |
- t.Errorf("Unexpected non-nil error: %v", err)
|
|
| 172 |
- } |
|
| 173 |
- if deploymentConfig.(*api.DeploymentConfig).Name != "foo" {
|
|
| 174 |
- t.Errorf("Unexpected deploymentConfig: %#v", deploymentConfig)
|
|
| 175 |
- } |
|
| 176 |
-} |
|
| 177 |
- |
|
| 178 |
-func TestUpdateDeploymentConfigBadObject(t *testing.T) {
|
|
| 179 |
- storage := REST{}
|
|
| 180 |
- |
|
| 181 |
- obj, created, err := storage.Update(kapi.NewDefaultContext(), &api.DeploymentList{})
|
|
| 182 |
- if obj != nil || created {
|
|
| 183 |
- t.Errorf("Expected nil, got %v", obj)
|
|
| 184 |
- } |
|
| 185 |
- if strings.Index(err.Error(), "not a deploymentConfig:") == -1 {
|
|
| 186 |
- t.Errorf("Expected 'not a deploymentConfig' error, got %v", err)
|
|
| 187 |
- } |
|
| 188 |
-} |
|
| 189 |
- |
|
| 190 |
-func TestUpdateDeploymentConfigMissingID(t *testing.T) {
|
|
| 191 |
- storage := REST{}
|
|
| 192 |
- |
|
| 193 |
- obj, created, err := storage.Update(kapi.NewDefaultContext(), &api.DeploymentConfig{})
|
|
| 194 |
- if obj != nil || created {
|
|
| 195 |
- t.Errorf("Expected nil, got %v", obj)
|
|
| 196 |
- } |
|
| 197 |
- if strings.Index(err.Error(), "id is unspecified:") == -1 {
|
|
| 198 |
- t.Errorf("Expected 'id is unspecified' error, got %v", err)
|
|
| 199 |
- } |
|
| 200 |
-} |
|
| 201 |
- |
|
| 202 |
-func TestUpdateRegistryErrorSaving(t *testing.T) {
|
|
| 203 |
- mockRepositoryRegistry := test.NewDeploymentConfigRegistry() |
|
| 204 |
- mockRepositoryRegistry.Err = fmt.Errorf("foo")
|
|
| 205 |
- storage := REST{registry: mockRepositoryRegistry}
|
|
| 206 |
- |
|
| 207 |
- _, _, err := storage.Update(kapi.NewDefaultContext(), &api.DeploymentConfig{
|
|
| 208 |
- ObjectMeta: kapi.ObjectMeta{Name: "bar"},
|
|
| 209 |
- }) |
|
| 210 |
- if err != mockRepositoryRegistry.Err {
|
|
| 211 |
- t.Errorf("Unexpected error: %#v", err)
|
|
| 212 |
- } |
|
| 213 |
-} |
|
| 214 |
- |
|
| 215 |
-func TestUpdateDeploymentConfigOK(t *testing.T) {
|
|
| 216 |
- mockRepositoryRegistry := test.NewDeploymentConfigRegistry() |
|
| 217 |
- storage := REST{registry: mockRepositoryRegistry}
|
|
| 218 |
- |
|
| 219 |
- obj, created, err := storage.Update(kapi.NewDefaultContext(), &api.DeploymentConfig{
|
|
| 220 |
- ObjectMeta: kapi.ObjectMeta{Name: "bar"},
|
|
| 221 |
- }) |
|
| 222 |
- if err != nil || created {
|
|
| 223 |
- t.Errorf("Unexpected non-nil error: %#v", err)
|
|
| 224 |
- } |
|
| 225 |
- repo, ok := obj.(*api.DeploymentConfig) |
|
| 226 |
- if !ok {
|
|
| 227 |
- t.Errorf("Expected DeploymentConfig, got %#v", obj)
|
|
| 228 |
- } |
|
| 229 |
- if repo.Name != "bar" {
|
|
| 230 |
- t.Errorf("Unexpected repo returned: %#v", repo)
|
|
| 231 |
- } |
|
| 232 |
-} |
|
| 233 |
- |
|
| 234 |
-func TestDeleteDeploymentConfig(t *testing.T) {
|
|
| 235 |
- mockRegistry := test.NewDeploymentConfigRegistry() |
|
| 236 |
- storage := REST{registry: mockRegistry}
|
|
| 237 |
- obj, err := storage.Delete(kapi.NewDefaultContext(), "foo") |
|
| 238 |
- if obj == nil {
|
|
| 239 |
- t.Error("Unexpected nil obj")
|
|
| 240 |
- } |
|
| 241 |
- if err != nil {
|
|
| 242 |
- t.Errorf("Unexpected non-nil error: %#v", err)
|
|
| 243 |
- } |
|
| 244 |
- |
|
| 245 |
- status, ok := obj.(*kapi.Status) |
|
| 246 |
- if !ok {
|
|
| 247 |
- t.Errorf("Expected status type, got: %#v", obj)
|
|
| 248 |
- } |
|
| 249 |
- if status.Status != kapi.StatusSuccess {
|
|
| 250 |
- t.Errorf("Expected status=success, got: %#v", status)
|
|
| 251 |
- } |
|
| 252 |
-} |
|
| 253 |
- |
|
| 254 |
-func TestCreateDeploymentConfigConflictingNamespace(t *testing.T) {
|
|
| 255 |
- storage := REST{}
|
|
| 256 |
- |
|
| 257 |
- obj, err := storage.Create(kapi.WithNamespace(kapi.NewContext(), "legal-name"), &api.DeploymentConfig{
|
|
| 258 |
- ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "some-value"},
|
|
| 259 |
- }) |
|
| 260 |
- |
|
| 261 |
- if obj != nil {
|
|
| 262 |
- t.Error("Expected a nil obj, but we got a value")
|
|
| 263 |
- } |
|
| 264 |
- |
|
| 265 |
- checkExpectedNamespaceError(t, err) |
|
| 266 |
-} |
|
| 267 |
- |
|
| 268 |
-func TestUpdateDeploymentConfigConflictingNamespace(t *testing.T) {
|
|
| 269 |
- mockRepositoryRegistry := test.NewDeploymentConfigRegistry() |
|
| 270 |
- storage := REST{registry: mockRepositoryRegistry}
|
|
| 271 |
- |
|
| 272 |
- obj, created, err := storage.Update(kapi.WithNamespace(kapi.NewContext(), "legal-name"), &api.DeploymentConfig{
|
|
| 273 |
- ObjectMeta: kapi.ObjectMeta{Name: "bar", Namespace: "some-value"},
|
|
| 274 |
- }) |
|
| 275 |
- |
|
| 276 |
- if obj != nil || created {
|
|
| 277 |
- t.Error("Expected a nil obj, but we got a value")
|
|
| 278 |
- } |
|
| 279 |
- |
|
| 280 |
- checkExpectedNamespaceError(t, err) |
|
| 281 |
-} |
|
| 282 |
- |
|
| 283 |
-func checkExpectedNamespaceError(t *testing.T, err error) {
|
|
| 284 |
- expectedError := "DeploymentConfig.Namespace does not match the provided context" |
|
| 285 |
- if err == nil {
|
|
| 286 |
- t.Errorf("Expected '" + expectedError + "', but we didn't get one")
|
|
| 287 |
- } else {
|
|
| 288 |
- e, ok := err.(kclient.APIStatus) |
|
| 289 |
- if !ok {
|
|
| 290 |
- t.Errorf("error was not a statusError: %v", err)
|
|
| 291 |
- } |
|
| 292 |
- if e.Status().Code != http.StatusConflict {
|
|
| 293 |
- t.Errorf("Unexpected failure status: %v", e.Status())
|
|
| 294 |
- } |
|
| 295 |
- if strings.Index(err.Error(), expectedError) == -1 {
|
|
| 296 |
- t.Errorf("Expected '"+expectedError+"' error, got '%v'", err.Error())
|
|
| 297 |
- } |
|
| 298 |
- } |
|
| 299 |
- |
|
| 300 |
-} |
| 301 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,82 @@ |
| 0 |
+package deployconfig |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ |
|
| 5 |
+ kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 6 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
|
| 7 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
|
| 8 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic" |
|
| 9 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" |
|
| 10 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors" |
|
| 11 |
+ |
|
| 12 |
+ "github.com/openshift/origin/pkg/deploy/api" |
|
| 13 |
+ "github.com/openshift/origin/pkg/deploy/api/validation" |
|
| 14 |
+) |
|
| 15 |
+ |
|
| 16 |
+// strategy implements behavior for DeploymentConfig objects |
|
| 17 |
+type strategy struct {
|
|
| 18 |
+ runtime.ObjectTyper |
|
| 19 |
+ kapi.NameGenerator |
|
| 20 |
+} |
|
| 21 |
+ |
|
| 22 |
+// Strategy is the default logic that applies when creating and updating DeploymentConfig objects. |
|
| 23 |
+var Strategy = strategy{kapi.Scheme, kapi.SimpleNameGenerator}
|
|
| 24 |
+ |
|
| 25 |
+func (strategy) NamespaceScoped() bool {
|
|
| 26 |
+ return true |
|
| 27 |
+} |
|
| 28 |
+ |
|
| 29 |
+// AllowCreateOnUpdate is false for DeploymentConfig objects. |
|
| 30 |
+func (strategy) AllowCreateOnUpdate() bool {
|
|
| 31 |
+ return false |
|
| 32 |
+} |
|
| 33 |
+ |
|
| 34 |
+// PrepareForCreate clears fields that are not allowed to be set by end users on creation. |
|
| 35 |
+func (strategy) PrepareForCreate(obj runtime.Object) {
|
|
| 36 |
+ _ = obj.(*api.DeploymentConfig) |
|
| 37 |
+ // TODO: need to ensure status.latestVersion is not set out of order |
|
| 38 |
+} |
|
| 39 |
+ |
|
| 40 |
+// PrepareForUpdate clears fields that are not allowed to be set by end users on update. |
|
| 41 |
+func (strategy) PrepareForUpdate(obj, old runtime.Object) {
|
|
| 42 |
+ _ = obj.(*api.DeploymentConfig) |
|
| 43 |
+ // TODO: need to ensure status.latestVersion is not set out of order |
|
| 44 |
+} |
|
| 45 |
+ |
|
| 46 |
+// Validate validates a new policy. |
|
| 47 |
+func (strategy) Validate(ctx kapi.Context, obj runtime.Object) fielderrors.ValidationErrorList {
|
|
| 48 |
+ return validation.ValidateDeploymentConfig(obj.(*api.DeploymentConfig)) |
|
| 49 |
+} |
|
| 50 |
+ |
|
| 51 |
+// ValidateUpdate is the default update validation for an end user. |
|
| 52 |
+func (strategy) ValidateUpdate(ctx kapi.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
|
| 53 |
+ return validation.ValidateDeploymentConfigUpdate(obj.(*api.DeploymentConfig), old.(*api.DeploymentConfig)) |
|
| 54 |
+} |
|
| 55 |
+ |
|
| 56 |
+// CheckGracefulDelete allows a build to be gracefully deleted. |
|
| 57 |
+func (strategy) CheckGracefulDelete(obj runtime.Object, options *kapi.DeleteOptions) bool {
|
|
| 58 |
+ return false |
|
| 59 |
+} |
|
| 60 |
+ |
|
| 61 |
+// Matcher returns a generic matcher for a given label and field selector. |
|
| 62 |
+func Matcher(label labels.Selector, field fields.Selector) generic.Matcher {
|
|
| 63 |
+ return &generic.SelectionPredicate{
|
|
| 64 |
+ Label: label, |
|
| 65 |
+ Field: field, |
|
| 66 |
+ GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
|
|
| 67 |
+ deploymentConfig, ok := obj.(*api.DeploymentConfig) |
|
| 68 |
+ if !ok {
|
|
| 69 |
+ return nil, nil, fmt.Errorf("not a deployment config")
|
|
| 70 |
+ } |
|
| 71 |
+ return labels.Set(deploymentConfig.ObjectMeta.Labels), SelectableFields(deploymentConfig), nil |
|
| 72 |
+ }, |
|
| 73 |
+ } |
|
| 74 |
+} |
|
| 75 |
+ |
|
| 76 |
+// SelectableFields returns a label set that represents the object |
|
| 77 |
+func SelectableFields(deploymentConfig *api.DeploymentConfig) fields.Set {
|
|
| 78 |
+ return fields.Set{
|
|
| 79 |
+ "metadata.name": deploymentConfig.Name, |
|
| 80 |
+ } |
|
| 81 |
+} |
| 0 | 82 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,55 @@ |
| 0 |
+package deployconfig |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "testing" |
|
| 4 |
+ |
|
| 5 |
+ kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 6 |
+ |
|
| 7 |
+ deployapi "github.com/openshift/origin/pkg/deploy/api" |
|
| 8 |
+ deploytest "github.com/openshift/origin/pkg/deploy/api/test" |
|
| 9 |
+) |
|
| 10 |
+ |
|
| 11 |
+func TestDeploymentConfigStrategy(t *testing.T) {
|
|
| 12 |
+ ctx := kapi.NewDefaultContext() |
|
| 13 |
+ if !Strategy.NamespaceScoped() {
|
|
| 14 |
+ t.Errorf("DeploymentConfig is namespace scoped")
|
|
| 15 |
+ } |
|
| 16 |
+ if Strategy.AllowCreateOnUpdate() {
|
|
| 17 |
+ t.Errorf("DeploymentConfig should not allow create on update")
|
|
| 18 |
+ } |
|
| 19 |
+ deploymentConfig := &deployapi.DeploymentConfig{
|
|
| 20 |
+ ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "default"},
|
|
| 21 |
+ Template: deployapi.DeploymentTemplate{
|
|
| 22 |
+ Strategy: deploytest.OkStrategy(), |
|
| 23 |
+ ControllerTemplate: deploytest.OkControllerTemplate(), |
|
| 24 |
+ }, |
|
| 25 |
+ } |
|
| 26 |
+ Strategy.PrepareForCreate(deploymentConfig) |
|
| 27 |
+ errs := Strategy.Validate(ctx, deploymentConfig) |
|
| 28 |
+ if len(errs) != 0 {
|
|
| 29 |
+ t.Errorf("Unexpected error validating %v", errs)
|
|
| 30 |
+ } |
|
| 31 |
+ updatedDeploymentConfig := &deployapi.DeploymentConfig{
|
|
| 32 |
+ ObjectMeta: kapi.ObjectMeta{Name: "bar", Namespace: "default"},
|
|
| 33 |
+ Template: deployapi.DeploymentTemplate{
|
|
| 34 |
+ Strategy: deploytest.OkStrategy(), |
|
| 35 |
+ ControllerTemplate: deploytest.OkControllerTemplate(), |
|
| 36 |
+ }, |
|
| 37 |
+ } |
|
| 38 |
+ errs = Strategy.ValidateUpdate(ctx, updatedDeploymentConfig, deploymentConfig) |
|
| 39 |
+ if len(errs) == 0 {
|
|
| 40 |
+ t.Errorf("Expected error validating")
|
|
| 41 |
+ } |
|
| 42 |
+ // name must match, and resource version must be provided |
|
| 43 |
+ updatedDeploymentConfig.Name = "foo" |
|
| 44 |
+ updatedDeploymentConfig.ResourceVersion = "1" |
|
| 45 |
+ errs = Strategy.ValidateUpdate(ctx, updatedDeploymentConfig, deploymentConfig) |
|
| 46 |
+ if len(errs) != 0 {
|
|
| 47 |
+ t.Errorf("Unexpected error validating %v", errs)
|
|
| 48 |
+ } |
|
| 49 |
+ invalidDeploymentConfig := &deployapi.DeploymentConfig{}
|
|
| 50 |
+ errs = Strategy.Validate(ctx, invalidDeploymentConfig) |
|
| 51 |
+ if len(errs) == 0 {
|
|
| 52 |
+ t.Errorf("Expected error validating")
|
|
| 53 |
+ } |
|
| 54 |
+} |
| ... | ... |
@@ -19,8 +19,6 @@ import ( |
| 19 | 19 |
const ( |
| 20 | 20 |
// DeploymentPath is the path to deployment resources in etcd |
| 21 | 21 |
DeploymentPath string = "/deployments" |
| 22 |
- // DeploymentConfigPath is the path to deploymentConfig resources in etcd |
|
| 23 |
- DeploymentConfigPath string = "/deploymentconfigs" |
|
| 24 | 22 |
) |
| 25 | 23 |
|
| 26 | 24 |
// Etcd implements deployment.Registry and deploymentconfig.Registry interfaces. |
| ... | ... |
@@ -130,100 +128,3 @@ func (r *Etcd) WatchDeployments(ctx kapi.Context, label labels.Selector, field f |
| 130 | 130 |
return label.Matches(labels.Set(deployment.Labels)) && field.Matches(fields) |
| 131 | 131 |
}) |
| 132 | 132 |
} |
| 133 |
- |
|
| 134 |
-// ListDeploymentConfigs obtains a list of DeploymentConfigs. |
|
| 135 |
-func (r *Etcd) ListDeploymentConfigs(ctx kapi.Context, label labels.Selector, field fields.Selector) (*api.DeploymentConfigList, error) {
|
|
| 136 |
- deploymentConfigs := api.DeploymentConfigList{}
|
|
| 137 |
- err := r.ExtractToList(makeDeploymentConfigListKey(ctx), &deploymentConfigs) |
|
| 138 |
- if err != nil {
|
|
| 139 |
- return nil, err |
|
| 140 |
- } |
|
| 141 |
- filtered := []api.DeploymentConfig{}
|
|
| 142 |
- for _, item := range deploymentConfigs.Items {
|
|
| 143 |
- fields := labels.Set{
|
|
| 144 |
- "name": item.Name, |
|
| 145 |
- } |
|
| 146 |
- if label.Matches(labels.Set(item.Labels)) && field.Matches(fields) {
|
|
| 147 |
- filtered = append(filtered, item) |
|
| 148 |
- } |
|
| 149 |
- } |
|
| 150 |
- |
|
| 151 |
- deploymentConfigs.Items = filtered |
|
| 152 |
- return &deploymentConfigs, err |
|
| 153 |
-} |
|
| 154 |
- |
|
| 155 |
-// WatchDeploymentConfigs begins watching for new, changed, or deleted DeploymentConfigs. |
|
| 156 |
-func (r *Etcd) WatchDeploymentConfigs(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
|
|
| 157 |
- version, err := tools.ParseWatchResourceVersion(resourceVersion, "deploymentConfig") |
|
| 158 |
- if err != nil {
|
|
| 159 |
- return nil, err |
|
| 160 |
- } |
|
| 161 |
- |
|
| 162 |
- return r.WatchList(makeDeploymentConfigListKey(ctx), version, func(obj runtime.Object) bool {
|
|
| 163 |
- config, ok := obj.(*api.DeploymentConfig) |
|
| 164 |
- if !ok {
|
|
| 165 |
- glog.Errorf("Unexpected object during deploymentConfig watch: %#v", obj)
|
|
| 166 |
- return false |
|
| 167 |
- } |
|
| 168 |
- fields := labels.Set{
|
|
| 169 |
- "name": config.Name, |
|
| 170 |
- } |
|
| 171 |
- return label.Matches(labels.Set(config.Labels)) && field.Matches(fields) |
|
| 172 |
- }) |
|
| 173 |
-} |
|
| 174 |
- |
|
| 175 |
-func makeDeploymentConfigListKey(ctx kapi.Context) string {
|
|
| 176 |
- return kubeetcd.MakeEtcdListKey(ctx, DeploymentConfigPath) |
|
| 177 |
-} |
|
| 178 |
- |
|
| 179 |
-func makeDeploymentConfigKey(ctx kapi.Context, id string) (string, error) {
|
|
| 180 |
- return kubeetcd.MakeEtcdItemKey(ctx, DeploymentConfigPath, id) |
|
| 181 |
-} |
|
| 182 |
- |
|
| 183 |
-// GetDeploymentConfig gets a specific DeploymentConfig specified by its ID. |
|
| 184 |
-func (r *Etcd) GetDeploymentConfig(ctx kapi.Context, id string) (*api.DeploymentConfig, error) {
|
|
| 185 |
- var deploymentConfig api.DeploymentConfig |
|
| 186 |
- key, err := makeDeploymentConfigKey(ctx, id) |
|
| 187 |
- if err != nil {
|
|
| 188 |
- return nil, err |
|
| 189 |
- } |
|
| 190 |
- |
|
| 191 |
- err = r.ExtractObj(key, &deploymentConfig, false) |
|
| 192 |
- if err != nil {
|
|
| 193 |
- return nil, etcderr.InterpretGetError(err, "deploymentConfig", id) |
|
| 194 |
- } |
|
| 195 |
- return &deploymentConfig, nil |
|
| 196 |
-} |
|
| 197 |
- |
|
| 198 |
-// CreateDeploymentConfig creates a new DeploymentConfig. |
|
| 199 |
-func (r *Etcd) CreateDeploymentConfig(ctx kapi.Context, deploymentConfig *api.DeploymentConfig) error {
|
|
| 200 |
- key, err := makeDeploymentConfigKey(ctx, deploymentConfig.Name) |
|
| 201 |
- if err != nil {
|
|
| 202 |
- return err |
|
| 203 |
- } |
|
| 204 |
- |
|
| 205 |
- err = r.CreateObj(key, deploymentConfig, nil, 0) |
|
| 206 |
- return etcderr.InterpretCreateError(err, "deploymentConfig", deploymentConfig.Name) |
|
| 207 |
-} |
|
| 208 |
- |
|
| 209 |
-// UpdateDeploymentConfig replaces an existing DeploymentConfig. |
|
| 210 |
-func (r *Etcd) UpdateDeploymentConfig(ctx kapi.Context, deploymentConfig *api.DeploymentConfig) error {
|
|
| 211 |
- key, err := makeDeploymentConfigKey(ctx, deploymentConfig.Name) |
|
| 212 |
- if err != nil {
|
|
| 213 |
- return err |
|
| 214 |
- } |
|
| 215 |
- |
|
| 216 |
- err = r.SetObj(key, deploymentConfig, nil, 0) |
|
| 217 |
- return etcderr.InterpretUpdateError(err, "deploymentConfig", deploymentConfig.Name) |
|
| 218 |
-} |
|
| 219 |
- |
|
| 220 |
-// DeleteDeploymentConfig deletes a DeploymentConfig specified by its ID. |
|
| 221 |
-func (r *Etcd) DeleteDeploymentConfig(ctx kapi.Context, id string) error {
|
|
| 222 |
- key, err := makeDeploymentConfigKey(ctx, id) |
|
| 223 |
- if err != nil {
|
|
| 224 |
- return err |
|
| 225 |
- } |
|
| 226 |
- |
|
| 227 |
- err = r.Delete(key, false) |
|
| 228 |
- return etcderr.InterpretDeleteError(err, "deploymentConfig", id) |
|
| 229 |
-} |
| ... | ... |
@@ -15,7 +15,6 @@ import ( |
| 15 | 15 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools" |
| 16 | 16 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest" |
| 17 | 17 |
|
| 18 |
- "github.com/openshift/origin/pkg/api/latest" |
|
| 19 | 18 |
"github.com/openshift/origin/pkg/api/v1beta1" |
| 20 | 19 |
"github.com/openshift/origin/pkg/deploy/api" |
| 21 | 20 |
) |
| ... | ... |
@@ -39,21 +38,6 @@ func makeTestDefaultDeploymentKey(id string) string {
|
| 39 | 39 |
func makeTestDefaultDeploymentListKey() string {
|
| 40 | 40 |
return makeTestDeploymentListKey(kapi.NamespaceDefault) |
| 41 | 41 |
} |
| 42 |
-func makeTestDeploymentConfigListKey(namespace string) string {
|
|
| 43 |
- if len(namespace) != 0 {
|
|
| 44 |
- return "/deploymentconfigs/" + namespace |
|
| 45 |
- } |
|
| 46 |
- return "/deploymentconfigs" |
|
| 47 |
-} |
|
| 48 |
-func makeTestDeploymentConfigKey(namespace, id string) string {
|
|
| 49 |
- return "/deploymentconfigs/" + namespace + "/" + id |
|
| 50 |
-} |
|
| 51 |
-func makeTestDefaultDeploymentConfigKey(id string) string {
|
|
| 52 |
- return makeTestDeploymentConfigKey(kapi.NamespaceDefault, id) |
|
| 53 |
-} |
|
| 54 |
-func makeTestDefaultDeploymentConfigListKey() string {
|
|
| 55 |
- return makeTestDeploymentConfigListKey(kapi.NamespaceDefault) |
|
| 56 |
-} |
|
| 57 | 42 |
|
| 58 | 43 |
func NewTestEtcd(client tools.EtcdClient) *Etcd {
|
| 59 | 44 |
return New(tools.NewEtcdHelper(client, v1beta1.Codec, etcdtest.PathPrefix())) |
| ... | ... |
@@ -328,252 +312,6 @@ func TestEtcdDeleteOkDeployments(t *testing.T) {
|
| 328 | 328 |
} |
| 329 | 329 |
} |
| 330 | 330 |
|
| 331 |
-func TestEtcdListEmptyDeploymentConfig(t *testing.T) {
|
|
| 332 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 333 |
- key := makeTestDefaultDeploymentConfigListKey() |
|
| 334 |
- fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
| 335 |
- R: &etcd.Response{
|
|
| 336 |
- Node: &etcd.Node{
|
|
| 337 |
- Nodes: []*etcd.Node{},
|
|
| 338 |
- }, |
|
| 339 |
- }, |
|
| 340 |
- E: nil, |
|
| 341 |
- } |
|
| 342 |
- registry := NewTestEtcd(fakeClient) |
|
| 343 |
- deploymentConfigs, err := registry.ListDeploymentConfigs(kapi.NewDefaultContext(), labels.Everything(), fields.Everything()) |
|
| 344 |
- if err != nil {
|
|
| 345 |
- t.Errorf("unexpected error: %v", err)
|
|
| 346 |
- } |
|
| 347 |
- |
|
| 348 |
- if len(deploymentConfigs.Items) != 0 {
|
|
| 349 |
- t.Errorf("Unexpected deploymentConfigs list: %#v", deploymentConfigs)
|
|
| 350 |
- } |
|
| 351 |
-} |
|
| 352 |
- |
|
| 353 |
-func TestEtcdListErrorDeploymentConfig(t *testing.T) {
|
|
| 354 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 355 |
- key := makeTestDefaultDeploymentConfigListKey() |
|
| 356 |
- fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
| 357 |
- R: &etcd.Response{
|
|
| 358 |
- Node: nil, |
|
| 359 |
- }, |
|
| 360 |
- E: fmt.Errorf("some error"),
|
|
| 361 |
- } |
|
| 362 |
- registry := NewTestEtcd(fakeClient) |
|
| 363 |
- deploymentConfigs, err := registry.ListDeploymentConfigs(kapi.NewDefaultContext(), labels.Everything(), fields.Everything()) |
|
| 364 |
- if err == nil {
|
|
| 365 |
- t.Error("unexpected nil error")
|
|
| 366 |
- } |
|
| 367 |
- |
|
| 368 |
- if deploymentConfigs != nil {
|
|
| 369 |
- t.Errorf("Unexpected non-nil deploymentConfigs: %#v", deploymentConfigs)
|
|
| 370 |
- } |
|
| 371 |
-} |
|
| 372 |
- |
|
| 373 |
-func TestEtcdListFilteredDeploymentConfigs(t *testing.T) {
|
|
| 374 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 375 |
- key := makeTestDefaultDeploymentConfigListKey() |
|
| 376 |
- fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
| 377 |
- R: &etcd.Response{
|
|
| 378 |
- Node: &etcd.Node{
|
|
| 379 |
- Nodes: []*etcd.Node{
|
|
| 380 |
- {
|
|
| 381 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.DeploymentConfig{
|
|
| 382 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 383 |
- Name: "foo", |
|
| 384 |
- Labels: map[string]string{"env": "prod"},
|
|
| 385 |
- }, |
|
| 386 |
- }), |
|
| 387 |
- }, |
|
| 388 |
- {
|
|
| 389 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.DeploymentConfig{
|
|
| 390 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 391 |
- Name: "bar", |
|
| 392 |
- Labels: map[string]string{"env": "dev"},
|
|
| 393 |
- }, |
|
| 394 |
- }), |
|
| 395 |
- }, |
|
| 396 |
- }, |
|
| 397 |
- }, |
|
| 398 |
- }, |
|
| 399 |
- E: nil, |
|
| 400 |
- } |
|
| 401 |
- |
|
| 402 |
- registry := NewTestEtcd(fakeClient) |
|
| 403 |
- |
|
| 404 |
- testCase := selectorTest{
|
|
| 405 |
- {labels.SelectorFromSet(labels.Set{"env": "dev"}), fields.Everything(), []string{"bar"}},
|
|
| 406 |
- {labels.SelectorFromSet(labels.Set{"env": "prod"}), fields.Everything(), []string{"foo"}},
|
|
| 407 |
- {labels.Everything(), fields.Everything(), []string{"foo", "bar"}},
|
|
| 408 |
- {labels.Everything(), fields.SelectorFromSet(fields.Set{"name": "bar"}), []string{"bar"}},
|
|
| 409 |
- } |
|
| 410 |
- |
|
| 411 |
- testCase.validate(t, func(scenario selectorScenario) (runtime.Object, error) {
|
|
| 412 |
- return registry.ListDeploymentConfigs(kapi.NewDefaultContext(), scenario.label, scenario.field) |
|
| 413 |
- }) |
|
| 414 |
-} |
|
| 415 |
- |
|
| 416 |
-func TestEtcdGetDeploymentConfig(t *testing.T) {
|
|
| 417 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 418 |
- fakeClient.Set(makeTestDefaultDeploymentConfigKey("foo"), runtime.EncodeOrDie(v1beta1.Codec, &api.DeploymentConfig{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}), 0)
|
|
| 419 |
- registry := NewTestEtcd(fakeClient) |
|
| 420 |
- deployment, err := registry.GetDeploymentConfig(kapi.NewDefaultContext(), "foo") |
|
| 421 |
- if err != nil {
|
|
| 422 |
- t.Errorf("unexpected error: %v", err)
|
|
| 423 |
- } |
|
| 424 |
- |
|
| 425 |
- if deployment.Name != "foo" {
|
|
| 426 |
- t.Errorf("Unexpected deployment: %#v", deployment)
|
|
| 427 |
- } |
|
| 428 |
-} |
|
| 429 |
- |
|
| 430 |
-func TestEtcdGetNotFoundDeploymentConfig(t *testing.T) {
|
|
| 431 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 432 |
- fakeClient.Data[makeTestDefaultDeploymentConfigKey("foo")] = tools.EtcdResponseWithError{
|
|
| 433 |
- R: &etcd.Response{
|
|
| 434 |
- Node: nil, |
|
| 435 |
- }, |
|
| 436 |
- E: tools.EtcdErrorNotFound, |
|
| 437 |
- } |
|
| 438 |
- registry := NewTestEtcd(fakeClient) |
|
| 439 |
- deployment, err := registry.GetDeploymentConfig(kapi.NewDefaultContext(), "foo") |
|
| 440 |
- if err == nil {
|
|
| 441 |
- t.Errorf("Unexpected non-error.")
|
|
| 442 |
- } |
|
| 443 |
- if deployment != nil {
|
|
| 444 |
- t.Errorf("Unexpected deployment: %#v", deployment)
|
|
| 445 |
- } |
|
| 446 |
-} |
|
| 447 |
- |
|
| 448 |
-func TestEtcdCreateDeploymentConfig(t *testing.T) {
|
|
| 449 |
- key := makeTestDefaultDeploymentConfigKey("foo")
|
|
| 450 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 451 |
- fakeClient.TestIndex = true |
|
| 452 |
- fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
| 453 |
- R: &etcd.Response{
|
|
| 454 |
- Node: nil, |
|
| 455 |
- }, |
|
| 456 |
- E: tools.EtcdErrorNotFound, |
|
| 457 |
- } |
|
| 458 |
- registry := NewTestEtcd(fakeClient) |
|
| 459 |
- err := registry.CreateDeploymentConfig(kapi.NewDefaultContext(), &api.DeploymentConfig{
|
|
| 460 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 461 |
- Name: "foo", |
|
| 462 |
- }, |
|
| 463 |
- }) |
|
| 464 |
- if err != nil {
|
|
| 465 |
- t.Fatalf("unexpected error: %v", err)
|
|
| 466 |
- } |
|
| 467 |
- |
|
| 468 |
- resp, err := fakeClient.Get(key, false, false) |
|
| 469 |
- if err != nil {
|
|
| 470 |
- t.Fatalf("Unexpected error %v", err)
|
|
| 471 |
- } |
|
| 472 |
- var d api.DeploymentConfig |
|
| 473 |
- err = v1beta1.Codec.DecodeInto([]byte(resp.Node.Value), &d) |
|
| 474 |
- if err != nil {
|
|
| 475 |
- t.Errorf("unexpected error: %v", err)
|
|
| 476 |
- } |
|
| 477 |
- |
|
| 478 |
- if d.Name != "foo" {
|
|
| 479 |
- t.Errorf("Unexpected deploymentConfig: %#v %s", d, resp.Node.Value)
|
|
| 480 |
- } |
|
| 481 |
-} |
|
| 482 |
- |
|
| 483 |
-func TestEtcdCreateAlreadyExistsDeploymentConfig(t *testing.T) {
|
|
| 484 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 485 |
- fakeClient.Data[makeTestDefaultDeploymentConfigKey("foo")] = tools.EtcdResponseWithError{
|
|
| 486 |
- R: &etcd.Response{
|
|
| 487 |
- Node: &etcd.Node{
|
|
| 488 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.DeploymentConfig{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}),
|
|
| 489 |
- }, |
|
| 490 |
- }, |
|
| 491 |
- E: nil, |
|
| 492 |
- } |
|
| 493 |
- registry := NewTestEtcd(fakeClient) |
|
| 494 |
- err := registry.CreateDeploymentConfig(kapi.NewDefaultContext(), &api.DeploymentConfig{
|
|
| 495 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 496 |
- Name: "foo", |
|
| 497 |
- }, |
|
| 498 |
- }) |
|
| 499 |
- if err == nil {
|
|
| 500 |
- t.Error("Unexpected non-error")
|
|
| 501 |
- } |
|
| 502 |
- if !errors.IsAlreadyExists(err) {
|
|
| 503 |
- t.Errorf("Expected 'already exists' error, got %#v", err)
|
|
| 504 |
- } |
|
| 505 |
-} |
|
| 506 |
- |
|
| 507 |
-func TestEtcdUpdateOkDeploymentConfig(t *testing.T) {
|
|
| 508 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 509 |
- registry := NewTestEtcd(fakeClient) |
|
| 510 |
- err := registry.UpdateDeploymentConfig(kapi.NewDefaultContext(), &api.DeploymentConfig{ObjectMeta: kapi.ObjectMeta{Name: "foo"}})
|
|
| 511 |
- if err != nil {
|
|
| 512 |
- t.Errorf("Unexpected error %#v", err)
|
|
| 513 |
- } |
|
| 514 |
-} |
|
| 515 |
- |
|
| 516 |
-func TestEtcdDeleteNotFoundDeploymentConfig(t *testing.T) {
|
|
| 517 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 518 |
- fakeClient.Err = tools.EtcdErrorNotFound |
|
| 519 |
- registry := NewTestEtcd(fakeClient) |
|
| 520 |
- err := registry.DeleteDeploymentConfig(kapi.NewDefaultContext(), "foo") |
|
| 521 |
- if err == nil {
|
|
| 522 |
- t.Error("Unexpected non-error")
|
|
| 523 |
- } |
|
| 524 |
- if !errors.IsNotFound(err) {
|
|
| 525 |
- t.Errorf("Expected 'not found' error, got %#v", err)
|
|
| 526 |
- } |
|
| 527 |
-} |
|
| 528 |
- |
|
| 529 |
-func TestEtcdDeleteErrorDeploymentConfig(t *testing.T) {
|
|
| 530 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 531 |
- fakeClient.Err = fmt.Errorf("Some error")
|
|
| 532 |
- registry := NewTestEtcd(fakeClient) |
|
| 533 |
- err := registry.DeleteDeploymentConfig(kapi.NewDefaultContext(), "foo") |
|
| 534 |
- if err == nil {
|
|
| 535 |
- t.Error("Unexpected non-error")
|
|
| 536 |
- } |
|
| 537 |
-} |
|
| 538 |
- |
|
| 539 |
-func TestEtcdDeleteOkDeploymentConfig(t *testing.T) {
|
|
| 540 |
- key := makeTestDefaultDeploymentConfigKey("foo")
|
|
| 541 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 542 |
- fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
| 543 |
- R: &etcd.Response{
|
|
| 544 |
- Node: &etcd.Node{
|
|
| 545 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.DeploymentConfig{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}),
|
|
| 546 |
- }, |
|
| 547 |
- }, |
|
| 548 |
- E: nil, |
|
| 549 |
- } |
|
| 550 |
- registry := NewTestEtcd(fakeClient) |
|
| 551 |
- err := registry.DeleteDeploymentConfig(kapi.NewDefaultContext(), "foo") |
|
| 552 |
- if err != nil {
|
|
| 553 |
- t.Errorf("Unexpected error: %#v", err)
|
|
| 554 |
- } |
|
| 555 |
- if len(fakeClient.DeletedKeys) != 1 {
|
|
| 556 |
- t.Errorf("Expected 1 delete, found %#v", fakeClient.DeletedKeys)
|
|
| 557 |
- } else if fakeClient.DeletedKeys[0] != key {
|
|
| 558 |
- t.Errorf("Unexpected key: %s, expected %s", fakeClient.DeletedKeys[0], key)
|
|
| 559 |
- } |
|
| 560 |
-} |
|
| 561 |
- |
|
| 562 |
-func TestEtcdCreateDeploymentConfigFailsWithoutNamespace(t *testing.T) {
|
|
| 563 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 564 |
- fakeClient.TestIndex = true |
|
| 565 |
- registry := NewTestEtcd(fakeClient) |
|
| 566 |
- err := registry.CreateDeploymentConfig(kapi.NewContext(), &api.DeploymentConfig{
|
|
| 567 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 568 |
- Name: "foo", |
|
| 569 |
- }, |
|
| 570 |
- }) |
|
| 571 |
- |
|
| 572 |
- if err == nil {
|
|
| 573 |
- t.Errorf("expected error that namespace was missing from context")
|
|
| 574 |
- } |
|
| 575 |
-} |
|
| 576 |
- |
|
| 577 | 331 |
func TestEtcdCreateDeploymentFailsWithoutNamespace(t *testing.T) {
|
| 578 | 332 |
fakeClient := tools.NewFakeEtcdClient(t) |
| 579 | 333 |
fakeClient.TestIndex = true |
| ... | ... |
@@ -639,81 +377,6 @@ func TestEtcdListDeploymentsInDifferentNamespaces(t *testing.T) {
|
| 639 | 639 |
} |
| 640 | 640 |
} |
| 641 | 641 |
|
| 642 |
-func TestEtcdListDeploymentConfigsInDifferentNamespaces(t *testing.T) {
|
|
| 643 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 644 |
- namespaceAlfa := kapi.WithNamespace(kapi.NewContext(), "alfa") |
|
| 645 |
- namespaceBravo := kapi.WithNamespace(kapi.NewContext(), "bravo") |
|
| 646 |
- fakeClient.Data["/deploymentconfigs/alfa"] = tools.EtcdResponseWithError{
|
|
| 647 |
- R: &etcd.Response{
|
|
| 648 |
- Node: &etcd.Node{
|
|
| 649 |
- Nodes: []*etcd.Node{
|
|
| 650 |
- {
|
|
| 651 |
- Value: runtime.EncodeOrDie(latest.Codec, &api.DeploymentConfig{ObjectMeta: kapi.ObjectMeta{Name: "foo1"}}),
|
|
| 652 |
- }, |
|
| 653 |
- }, |
|
| 654 |
- }, |
|
| 655 |
- }, |
|
| 656 |
- E: nil, |
|
| 657 |
- } |
|
| 658 |
- fakeClient.Data["/deploymentconfigs/bravo"] = tools.EtcdResponseWithError{
|
|
| 659 |
- R: &etcd.Response{
|
|
| 660 |
- Node: &etcd.Node{
|
|
| 661 |
- Nodes: []*etcd.Node{
|
|
| 662 |
- {
|
|
| 663 |
- Value: runtime.EncodeOrDie(latest.Codec, &api.DeploymentConfig{ObjectMeta: kapi.ObjectMeta{Name: "foo2"}}),
|
|
| 664 |
- }, |
|
| 665 |
- {
|
|
| 666 |
- Value: runtime.EncodeOrDie(latest.Codec, &api.DeploymentConfig{ObjectMeta: kapi.ObjectMeta{Name: "bar2"}}),
|
|
| 667 |
- }, |
|
| 668 |
- }, |
|
| 669 |
- }, |
|
| 670 |
- }, |
|
| 671 |
- E: nil, |
|
| 672 |
- } |
|
| 673 |
- registry := NewTestEtcd(fakeClient) |
|
| 674 |
- |
|
| 675 |
- deploymentConfigsAlfa, err := registry.ListDeploymentConfigs(namespaceAlfa, labels.Everything(), fields.Everything()) |
|
| 676 |
- if err != nil {
|
|
| 677 |
- t.Errorf("unexpected error: %v", err)
|
|
| 678 |
- } |
|
| 679 |
- if len(deploymentConfigsAlfa.Items) != 1 || deploymentConfigsAlfa.Items[0].Name != "foo1" {
|
|
| 680 |
- t.Errorf("Unexpected deployments list: %#v", deploymentConfigsAlfa)
|
|
| 681 |
- } |
|
| 682 |
- |
|
| 683 |
- deploymentConfigsBravo, err := registry.ListDeploymentConfigs(namespaceBravo, labels.Everything(), fields.Everything()) |
|
| 684 |
- if err != nil {
|
|
| 685 |
- t.Errorf("unexpected error: %v", err)
|
|
| 686 |
- } |
|
| 687 |
- if len(deploymentConfigsBravo.Items) != 2 || deploymentConfigsBravo.Items[0].Name != "foo2" || deploymentConfigsBravo.Items[1].Name != "bar2" {
|
|
| 688 |
- t.Errorf("Unexpected deployments list: %#v", deploymentConfigsBravo)
|
|
| 689 |
- } |
|
| 690 |
-} |
|
| 691 |
- |
|
| 692 |
-func TestEtcdGetDeploymentConfigInDifferentNamespaces(t *testing.T) {
|
|
| 693 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 694 |
- namespaceAlfa := kapi.WithNamespace(kapi.NewContext(), "alfa") |
|
| 695 |
- namespaceBravo := kapi.WithNamespace(kapi.NewContext(), "bravo") |
|
| 696 |
- fakeClient.Set("/deploymentconfigs/alfa/foo", runtime.EncodeOrDie(latest.Codec, &api.DeploymentConfig{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}), 0)
|
|
| 697 |
- fakeClient.Set("/deploymentconfigs/bravo/foo", runtime.EncodeOrDie(latest.Codec, &api.DeploymentConfig{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}), 0)
|
|
| 698 |
- registry := NewTestEtcd(fakeClient) |
|
| 699 |
- |
|
| 700 |
- alfaFoo, err := registry.GetDeploymentConfig(namespaceAlfa, "foo") |
|
| 701 |
- if err != nil {
|
|
| 702 |
- t.Errorf("unexpected error: %v", err)
|
|
| 703 |
- } |
|
| 704 |
- if alfaFoo == nil || alfaFoo.Name != "foo" {
|
|
| 705 |
- t.Errorf("Unexpected deployment: %#v", alfaFoo)
|
|
| 706 |
- } |
|
| 707 |
- |
|
| 708 |
- bravoFoo, err := registry.GetDeploymentConfig(namespaceBravo, "foo") |
|
| 709 |
- if err != nil {
|
|
| 710 |
- t.Errorf("unexpected error: %v", err)
|
|
| 711 |
- } |
|
| 712 |
- if bravoFoo == nil || bravoFoo.Name != "foo" {
|
|
| 713 |
- t.Errorf("Unexpected deployment: %#v", bravoFoo)
|
|
| 714 |
- } |
|
| 715 |
-} |
|
| 716 |
- |
|
| 717 | 642 |
func TestEtcdGetDeploymentInDifferentNamespaces(t *testing.T) {
|
| 718 | 643 |
fakeClient := tools.NewFakeEtcdClient(t) |
| 719 | 644 |
namespaceAlfa := kapi.WithNamespace(kapi.NewContext(), "alfa") |
| ... | ... |
@@ -34,7 +34,7 @@ import ( |
| 34 | 34 |
imagechangecontroller "github.com/openshift/origin/pkg/deploy/controller/imagechange" |
| 35 | 35 |
deployconfiggenerator "github.com/openshift/origin/pkg/deploy/generator" |
| 36 | 36 |
deployconfigregistry "github.com/openshift/origin/pkg/deploy/registry/deployconfig" |
| 37 |
- deployetcd "github.com/openshift/origin/pkg/deploy/registry/etcd" |
|
| 37 |
+ deployconfigetcd "github.com/openshift/origin/pkg/deploy/registry/deployconfig/etcd" |
|
| 38 | 38 |
deployutil "github.com/openshift/origin/pkg/deploy/util" |
| 39 | 39 |
imageapi "github.com/openshift/origin/pkg/image/api" |
| 40 | 40 |
"github.com/openshift/origin/pkg/image/registry/image" |
| ... | ... |
@@ -410,10 +410,12 @@ func NewTestDeployOpenshift(t *testing.T) *testDeployOpenshift {
|
| 410 | 410 |
imageStreamTagStorage := imagestreamtag.NewREST(imageRegistry, imageStreamRegistry) |
| 411 | 411 |
//imageStreamTagRegistry := imagestreamtag.NewRegistry(imageStreamTagStorage) |
| 412 | 412 |
|
| 413 |
- deployEtcd := deployetcd.New(etcdHelper) |
|
| 413 |
+ deployConfigStorage := deployconfigetcd.NewStorage(etcdHelper) |
|
| 414 |
+ deployConfigRegistry := deployconfigregistry.NewRegistry(deployConfigStorage) |
|
| 415 |
+ |
|
| 414 | 416 |
deployConfigGenerator := &deployconfiggenerator.DeploymentConfigGenerator{
|
| 415 | 417 |
Client: deployconfiggenerator.Client{
|
| 416 |
- DCFn: deployEtcd.GetDeploymentConfig, |
|
| 418 |
+ DCFn: deployConfigRegistry.GetDeploymentConfig, |
|
| 417 | 419 |
ISFn: imageStreamRegistry.GetImageStream, |
| 418 | 420 |
LISFn2: imageStreamRegistry.ListImageStreams, |
| 419 | 421 |
}, |
| ... | ... |
@@ -425,7 +427,7 @@ func NewTestDeployOpenshift(t *testing.T) *testDeployOpenshift {
|
| 425 | 425 |
"imageStreamImages": imageStreamImageStorage, |
| 426 | 426 |
"imageStreamMappings": imageStreamMappingStorage, |
| 427 | 427 |
"imageStreamTags": imageStreamTagStorage, |
| 428 |
- "deploymentConfigs": deployconfigregistry.NewREST(deployEtcd), |
|
| 428 |
+ "deploymentConfigs": deployConfigStorage, |
|
| 429 | 429 |
"generateDeploymentConfigs": deployconfiggenerator.NewREST(deployConfigGenerator, latest.Codec), |
| 430 | 430 |
} |
| 431 | 431 |
for k, v := range storage {
|