Remove the deprecated Deployment resource.
| ... | ... |
@@ -63,8 +63,6 @@ func ValidateObject(obj runtime.Object) (errors []error) {
|
| 63 | 63 |
errors = imagev.ValidateImageStreamMapping(t) |
| 64 | 64 |
case *deployapi.DeploymentConfig: |
| 65 | 65 |
errors = deployv.ValidateDeploymentConfig(t) |
| 66 |
- case *deployapi.Deployment: |
|
| 67 |
- errors = deployv.ValidateDeployment(t) |
|
| 68 | 66 |
case *projectapi.Project: |
| 69 | 67 |
// this is a global resource that should not have a namespace |
| 70 | 68 |
t.Namespace = "" |
| ... | ... |
@@ -78,8 +78,6 @@ func NewHumanReadablePrinter(noHeaders bool) *kctl.HumanReadablePrinter {
|
| 78 | 78 |
p.Handler(projectColumns, printProjectList) |
| 79 | 79 |
p.Handler(routeColumns, printRoute) |
| 80 | 80 |
p.Handler(routeColumns, printRouteList) |
| 81 |
- p.Handler(deploymentColumns, printDeployment) |
|
| 82 |
- p.Handler(deploymentColumns, printDeploymentList) |
|
| 83 | 81 |
p.Handler(deploymentConfigColumns, printDeploymentConfig) |
| 84 | 82 |
p.Handler(deploymentConfigColumns, printDeploymentConfigList) |
| 85 | 83 |
p.Handler(templateColumns, printTemplate) |
| ... | ... |
@@ -345,28 +343,6 @@ func printRouteList(routeList *routeapi.RouteList, w io.Writer) error {
|
| 345 | 345 |
return nil |
| 346 | 346 |
} |
| 347 | 347 |
|
| 348 |
-func printDeployment(d *deployapi.Deployment, w io.Writer) error {
|
|
| 349 |
- causes := util.StringSet{}
|
|
| 350 |
- if d.Details != nil {
|
|
| 351 |
- for _, cause := range d.Details.Causes {
|
|
| 352 |
- causes.Insert(string(cause.Type)) |
|
| 353 |
- } |
|
| 354 |
- } |
|
| 355 |
- cStr := strings.Join(causes.List(), ", ") |
|
| 356 |
- _, err := fmt.Fprintf(w, "%s\t%s\t%s\n", d.Name, d.Status, cStr) |
|
| 357 |
- return err |
|
| 358 |
-} |
|
| 359 |
- |
|
| 360 |
-func printDeploymentList(list *deployapi.DeploymentList, w io.Writer) error {
|
|
| 361 |
- for _, d := range list.Items {
|
|
| 362 |
- if err := printDeployment(&d, w); err != nil {
|
|
| 363 |
- return err |
|
| 364 |
- } |
|
| 365 |
- } |
|
| 366 |
- |
|
| 367 |
- return nil |
|
| 368 |
-} |
|
| 369 |
- |
|
| 370 | 348 |
func printDeploymentConfig(dc *deployapi.DeploymentConfig, w io.Writer) error {
|
| 371 | 349 |
triggers := util.StringSet{}
|
| 372 | 350 |
for _, trigger := range dc.Triggers {
|
| ... | ... |
@@ -56,10 +56,8 @@ import ( |
| 56 | 56 |
deployconfigcontroller "github.com/openshift/origin/pkg/deploy/controller/deploymentconfig" |
| 57 | 57 |
imagechangecontroller "github.com/openshift/origin/pkg/deploy/controller/imagechange" |
| 58 | 58 |
deployconfiggenerator "github.com/openshift/origin/pkg/deploy/generator" |
| 59 |
- deployregistry "github.com/openshift/origin/pkg/deploy/registry/deploy" |
|
| 60 | 59 |
deployconfigregistry "github.com/openshift/origin/pkg/deploy/registry/deployconfig" |
| 61 | 60 |
deployconfigetcd "github.com/openshift/origin/pkg/deploy/registry/deployconfig/etcd" |
| 62 |
- deployetcd "github.com/openshift/origin/pkg/deploy/registry/etcd" |
|
| 63 | 61 |
deployrollback "github.com/openshift/origin/pkg/deploy/rollback" |
| 64 | 62 |
"github.com/openshift/origin/pkg/dns" |
| 65 | 63 |
imagecontroller "github.com/openshift/origin/pkg/image/controller" |
| ... | ... |
@@ -174,7 +172,6 @@ func (c *MasterConfig) InstallProtectedAPI(container *restful.Container) []strin |
| 174 | 174 |
deployConfigStorage := deployconfigetcd.NewStorage(c.EtcdHelper) |
| 175 | 175 |
deployConfigRegistry := deployconfigregistry.NewRegistry(deployConfigStorage) |
| 176 | 176 |
|
| 177 |
- deployEtcd := deployetcd.New(c.EtcdHelper) |
|
| 178 | 177 |
routeEtcd := routeetcd.New(c.EtcdHelper) |
| 179 | 178 |
hostSubnetStorage := hostsubnetetcd.NewREST(c.EtcdHelper) |
| 180 | 179 |
clusterNetworkStorage := clusternetworketcd.NewREST(c.EtcdHelper) |
| ... | ... |
@@ -289,7 +286,6 @@ func (c *MasterConfig) InstallProtectedAPI(container *restful.Container) []strin |
| 289 | 289 |
"imageRepositoryMappings": imageRepositoryMappingStorage, |
| 290 | 290 |
"imageRepositoryTags": imageRepositoryTagStorage, |
| 291 | 291 |
|
| 292 |
- "deployments": deployregistry.NewREST(deployEtcd), |
|
| 293 | 292 |
"deploymentConfigs": deployConfigStorage, |
| 294 | 293 |
"generateDeploymentConfigs": deployconfiggenerator.NewREST(deployConfigGenerator, latest.Codec), |
| 295 | 294 |
"deploymentConfigRollbacks": deployrollback.NewREST(deployRollbackClient, latest.Codec), |
| ... | ... |
@@ -6,16 +6,12 @@ import ( |
| 6 | 6 |
|
| 7 | 7 |
func init() {
|
| 8 | 8 |
api.Scheme.AddKnownTypes("",
|
| 9 |
- &Deployment{},
|
|
| 10 |
- &DeploymentList{},
|
|
| 11 | 9 |
&DeploymentConfig{},
|
| 12 | 10 |
&DeploymentConfigList{},
|
| 13 | 11 |
&DeploymentConfigRollback{},
|
| 14 | 12 |
) |
| 15 | 13 |
} |
| 16 | 14 |
|
| 17 |
-func (*Deployment) IsAnAPIObject() {}
|
|
| 18 |
-func (*DeploymentList) IsAnAPIObject() {}
|
|
| 19 | 15 |
func (*DeploymentConfig) IsAnAPIObject() {}
|
| 20 | 16 |
func (*DeploymentConfigList) IsAnAPIObject() {}
|
| 21 | 17 |
func (*DeploymentConfigRollback) IsAnAPIObject() {}
|
| ... | ... |
@@ -4,30 +4,6 @@ import ( |
| 4 | 4 |
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
| 5 | 5 |
) |
| 6 | 6 |
|
| 7 |
-// Deployment represents a single configuration of a pod deployed into the cluster, and may |
|
| 8 |
-// represent both a current deployment or a historical deployment. |
|
| 9 |
-// |
|
| 10 |
-// DEPRECATED: This type longer drives any system behavior. Deployments are now represented directly |
|
| 11 |
-// by ReplicationControllers. Use DeploymentConfig to drive deployments. |
|
| 12 |
-type Deployment struct {
|
|
| 13 |
- kapi.TypeMeta `json:",inline"` |
|
| 14 |
- kapi.ObjectMeta `json:"metadata,omitempty"` |
|
| 15 |
- |
|
| 16 |
- // Strategy describes how a deployment is executed. |
|
| 17 |
- Strategy DeploymentStrategy `json:"strategy,omitempty"` |
|
| 18 |
- // ControllerTemplate is the desired replication state the deployment works to materialize. |
|
| 19 |
- ControllerTemplate kapi.ReplicationControllerSpec `json:"controllerTemplate,omitempty"` |
|
| 20 |
- // Status is the execution status of the deployment. |
|
| 21 |
- Status DeploymentStatus `json:"status,omitempty"` |
|
| 22 |
- // Details captures the causes for the creation of this deployment resource. |
|
| 23 |
- // This could be based on a change made by the user to the deployment config |
|
| 24 |
- // or caused by an automatic trigger that was specified in the deployment config. |
|
| 25 |
- // Multiple triggers could have caused this deployment. |
|
| 26 |
- // If no trigger is specified here, then the deployment was likely created as a result of an |
|
| 27 |
- // explicit client request to create a new deployment resource. |
|
| 28 |
- Details *DeploymentDetails `json:"details,omitempty"` |
|
| 29 |
-} |
|
| 30 |
- |
|
| 31 | 7 |
// DeploymentStatus describes the possible states a deployment can be in. |
| 32 | 8 |
type DeploymentStatus string |
| 33 | 9 |
|
| ... | ... |
@@ -141,14 +117,6 @@ type RollingDeploymentStrategyParams struct {
|
| 141 | 141 |
TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty" description:"the time to wait for updates before giving up"` |
| 142 | 142 |
} |
| 143 | 143 |
|
| 144 |
-// DeploymentList is a collection of deployments. |
|
| 145 |
-// DEPRECATED: Like Deployment, this is no longer used. |
|
| 146 |
-type DeploymentList struct {
|
|
| 147 |
- kapi.TypeMeta `json:",inline"` |
|
| 148 |
- kapi.ListMeta `json:"metadata,omitempty"` |
|
| 149 |
- Items []Deployment `json:"items"` |
|
| 150 |
-} |
|
| 151 |
- |
|
| 152 | 144 |
// These constants represent keys used for correlating objects related to deployments. |
| 153 | 145 |
const ( |
| 154 | 146 |
// DeploymentConfigAnnotation is an annotation name used to correlate a deployment with the |
| ... | ... |
@@ -6,16 +6,12 @@ import ( |
| 6 | 6 |
|
| 7 | 7 |
func init() {
|
| 8 | 8 |
api.Scheme.AddKnownTypes("v1beta1",
|
| 9 |
- &Deployment{},
|
|
| 10 |
- &DeploymentList{},
|
|
| 11 | 9 |
&DeploymentConfig{},
|
| 12 | 10 |
&DeploymentConfigList{},
|
| 13 | 11 |
&DeploymentConfigRollback{},
|
| 14 | 12 |
) |
| 15 | 13 |
} |
| 16 | 14 |
|
| 17 |
-func (*Deployment) IsAnAPIObject() {}
|
|
| 18 |
-func (*DeploymentList) IsAnAPIObject() {}
|
|
| 19 | 15 |
func (*DeploymentConfig) IsAnAPIObject() {}
|
| 20 | 16 |
func (*DeploymentConfigList) IsAnAPIObject() {}
|
| 21 | 17 |
func (*DeploymentConfigRollback) IsAnAPIObject() {}
|
| ... | ... |
@@ -5,30 +5,6 @@ import ( |
| 5 | 5 |
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3" |
| 6 | 6 |
) |
| 7 | 7 |
|
| 8 |
-// A deployment represents a single configuration of a pod deployed into the cluster, and may |
|
| 9 |
-// represent both a current deployment or a historical deployment. |
|
| 10 |
-// |
|
| 11 |
-// DEPRECATED: This type longer drives any system behavior. Deployments are now represented directly |
|
| 12 |
-// by ReplicationControllers. Use DeploymentConfig to drive deployments. |
|
| 13 |
-type Deployment struct {
|
|
| 14 |
- kapi.TypeMeta `json:",inline"` |
|
| 15 |
- kapi.ObjectMeta `json:"metadata,omitempty"` |
|
| 16 |
- |
|
| 17 |
- // Strategy describes how a deployment is executed. |
|
| 18 |
- Strategy DeploymentStrategy `json:"strategy,omitempty"` |
|
| 19 |
- // ControllerTemplate is the desired replication state the deployment works to materialize. |
|
| 20 |
- ControllerTemplate v1beta1.ReplicationControllerState `json:"controllerTemplate,omitempty"` |
|
| 21 |
- // Status is the execution status of the deployment. |
|
| 22 |
- Status DeploymentStatus `json:"status,omitempty"` |
|
| 23 |
- // Details captures the causes for the creation of this deployment resource. |
|
| 24 |
- // This could be based on a change made by the user to the deployment config |
|
| 25 |
- // or caused by an automatic trigger that was specified in the deployment config. |
|
| 26 |
- // Multiple triggers could have caused this deployment. |
|
| 27 |
- // If no trigger is specified here, then the deployment was likely created as a result of an |
|
| 28 |
- // explicit client request to create a new deployment resource. |
|
| 29 |
- Details *DeploymentDetails `json:"details,omitempty"` |
|
| 30 |
-} |
|
| 31 |
- |
|
| 32 | 8 |
// DeploymentStatus describes the possible states a deployment can be in. |
| 33 | 9 |
type DeploymentStatus string |
| 34 | 10 |
|
| ... | ... |
@@ -142,14 +118,6 @@ type RollingDeploymentStrategyParams struct {
|
| 142 | 142 |
TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty" description:"the time to wait for updates before giving up"` |
| 143 | 143 |
} |
| 144 | 144 |
|
| 145 |
-// A DeploymentList is a collection of deployments. |
|
| 146 |
-// DEPRECATED: Like Deployment, this is no longer used. |
|
| 147 |
-type DeploymentList struct {
|
|
| 148 |
- kapi.TypeMeta `json:",inline"` |
|
| 149 |
- kapi.ListMeta `json:"metadata,omitempty"` |
|
| 150 |
- Items []Deployment `json:"items"` |
|
| 151 |
-} |
|
| 152 |
- |
|
| 153 | 145 |
// These constants represent keys used for correlating objects related to deployments. |
| 154 | 146 |
const ( |
| 155 | 147 |
// DeploymentConfigAnnotation is an annotation name used to correlate a deployment with the |
| ... | ... |
@@ -16,23 +16,6 @@ import ( |
| 16 | 16 |
// The upstream validation API isn't factored currently to allow this; we'll make a PR to |
| 17 | 17 |
// upstream and fix when it goes in. |
| 18 | 18 |
|
| 19 |
-func ValidateDeployment(deployment *deployapi.Deployment) fielderrors.ValidationErrorList {
|
|
| 20 |
- errs := validateDeploymentStrategy(&deployment.Strategy).Prefix("strategy")
|
|
| 21 |
- if len(deployment.Name) == 0 {
|
|
| 22 |
- errs = append(errs, fielderrors.NewFieldRequired("name"))
|
|
| 23 |
- } else if !util.IsDNS1123Subdomain(deployment.Name) {
|
|
| 24 |
- errs = append(errs, fielderrors.NewFieldInvalid("name", deployment.Name, "name must be a valid subdomain"))
|
|
| 25 |
- } |
|
| 26 |
- if len(deployment.Namespace) == 0 {
|
|
| 27 |
- errs = append(errs, fielderrors.NewFieldRequired("namespace"))
|
|
| 28 |
- } else if !util.IsDNS1123Subdomain(deployment.Namespace) {
|
|
| 29 |
- errs = append(errs, fielderrors.NewFieldInvalid("namespace", deployment.Namespace, "namespace must be a valid subdomain"))
|
|
| 30 |
- } |
|
| 31 |
- errs = append(errs, validation.ValidateLabels(deployment.Labels, "labels")...) |
|
| 32 |
- errs = append(errs, validation.ValidateReplicationControllerSpec(&deployment.ControllerTemplate).Prefix("controllerTemplate")...)
|
|
| 33 |
- return errs |
|
| 34 |
-} |
|
| 35 |
- |
|
| 36 | 19 |
func ValidateDeploymentConfig(config *deployapi.DeploymentConfig) fielderrors.ValidationErrorList {
|
| 37 | 20 |
errs := fielderrors.ValidationErrorList{}
|
| 38 | 21 |
if len(config.Name) == 0 {
|
| ... | ... |
@@ -22,50 +22,6 @@ func manualTrigger() []api.DeploymentTriggerPolicy {
|
| 22 | 22 |
|
| 23 | 23 |
// TODO: test validation errors for ReplicationControllerTemplates |
| 24 | 24 |
|
| 25 |
-func TestValidateDeploymentOK(t *testing.T) {
|
|
| 26 |
- errs := ValidateDeployment(&api.Deployment{
|
|
| 27 |
- ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
|
|
| 28 |
- Strategy: test.OkStrategy(), |
|
| 29 |
- ControllerTemplate: test.OkControllerTemplate(), |
|
| 30 |
- }) |
|
| 31 |
- if len(errs) > 0 {
|
|
| 32 |
- t.Errorf("Unxpected non-empty error list: %#v", errs)
|
|
| 33 |
- } |
|
| 34 |
-} |
|
| 35 |
- |
|
| 36 |
-func TestValidateDeploymentMissingFields(t *testing.T) {
|
|
| 37 |
- errorCases := map[string]struct {
|
|
| 38 |
- D api.Deployment |
|
| 39 |
- T fielderrors.ValidationErrorType |
|
| 40 |
- F string |
|
| 41 |
- }{
|
|
| 42 |
- "missing strategy.type": {
|
|
| 43 |
- api.Deployment{
|
|
| 44 |
- ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
|
|
| 45 |
- Strategy: api.DeploymentStrategy{},
|
|
| 46 |
- ControllerTemplate: test.OkControllerTemplate(), |
|
| 47 |
- }, |
|
| 48 |
- fielderrors.ValidationErrorTypeRequired, |
|
| 49 |
- "strategy.type", |
|
| 50 |
- }, |
|
| 51 |
- } |
|
| 52 |
- |
|
| 53 |
- for k, v := range errorCases {
|
|
| 54 |
- errs := ValidateDeployment(&v.D) |
|
| 55 |
- if len(errs) == 0 {
|
|
| 56 |
- t.Errorf("Expected failure for scenario %s", k)
|
|
| 57 |
- } |
|
| 58 |
- for i := range errs {
|
|
| 59 |
- if errs[i].(*fielderrors.ValidationError).Type != v.T {
|
|
| 60 |
- t.Errorf("%s: expected errors to have type %s: %v", k, v.T, errs[i])
|
|
| 61 |
- } |
|
| 62 |
- if errs[i].(*fielderrors.ValidationError).Field != v.F {
|
|
| 63 |
- t.Errorf("%s: expected errors to have field %s: %v", k, v.F, errs[i])
|
|
| 64 |
- } |
|
| 65 |
- } |
|
| 66 |
- } |
|
| 67 |
-} |
|
| 68 |
- |
|
| 69 | 25 |
func TestValidateDeploymentConfigOK(t *testing.T) {
|
| 70 | 26 |
errs := ValidateDeploymentConfig(&api.DeploymentConfig{
|
| 71 | 27 |
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
|
| 4 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,20 +0,0 @@ |
| 1 |
-package deploy |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 5 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
|
| 6 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
|
| 7 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" |
|
| 8 |
- |
|
| 9 |
- deployapi "github.com/openshift/origin/pkg/deploy/api" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-// Registry is an interface for things that know how to store Deployments. |
|
| 13 |
-type Registry interface {
|
|
| 14 |
- ListDeployments(ctx kapi.Context, label labels.Selector, field fields.Selector) (*deployapi.DeploymentList, error) |
|
| 15 |
- GetDeployment(ctx kapi.Context, id string) (*deployapi.Deployment, error) |
|
| 16 |
- CreateDeployment(ctx kapi.Context, deployment *deployapi.Deployment) error |
|
| 17 |
- UpdateDeployment(ctx kapi.Context, deployment *deployapi.Deployment) error |
|
| 18 |
- DeleteDeployment(ctx kapi.Context, id string) error |
|
| 19 |
- WatchDeployments(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) |
|
| 20 |
-} |
| 21 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,116 +0,0 @@ |
| 1 |
-package deploy |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "fmt" |
|
| 5 |
- |
|
| 6 |
- "code.google.com/p/go-uuid/uuid" |
|
| 7 |
- kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 8 |
- kerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" |
|
| 9 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
|
| 10 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
|
| 11 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" |
|
| 12 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" |
|
| 13 |
- "github.com/golang/glog" |
|
| 14 |
- |
|
| 15 |
- deployapi "github.com/openshift/origin/pkg/deploy/api" |
|
| 16 |
- "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 Deployment for use with Create and Update. |
|
| 32 |
-func (s *REST) New() runtime.Object {
|
|
| 33 |
- return &deployapi.Deployment{}
|
|
| 34 |
-} |
|
| 35 |
- |
|
| 36 |
-func (*REST) NewList() runtime.Object {
|
|
| 37 |
- return &deployapi.Deployment{}
|
|
| 38 |
-} |
|
| 39 |
- |
|
| 40 |
-// List obtains a list of Deployments that match selector. |
|
| 41 |
-func (s *REST) List(ctx kapi.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) {
|
|
| 42 |
- deployments, err := s.registry.ListDeployments(ctx, label, field) |
|
| 43 |
- if err != nil {
|
|
| 44 |
- return nil, err |
|
| 45 |
- } |
|
| 46 |
- |
|
| 47 |
- return deployments, nil |
|
| 48 |
-} |
|
| 49 |
- |
|
| 50 |
-// Get obtains the Deployment specified by its id. |
|
| 51 |
-func (s *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) {
|
|
| 52 |
- deployment, err := s.registry.GetDeployment(ctx, id) |
|
| 53 |
- if err != nil {
|
|
| 54 |
- return nil, err |
|
| 55 |
- } |
|
| 56 |
- return deployment, err |
|
| 57 |
-} |
|
| 58 |
- |
|
| 59 |
-// Delete asynchronously deletes the Deployment specified by its id. |
|
| 60 |
-func (s *REST) Delete(ctx kapi.Context, id string) (runtime.Object, error) {
|
|
| 61 |
- return &kapi.Status{Status: kapi.StatusSuccess}, s.registry.DeleteDeployment(ctx, id)
|
|
| 62 |
-} |
|
| 63 |
- |
|
| 64 |
-// Create registers a given new Deployment instance to s.registry. |
|
| 65 |
-func (s *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
|
|
| 66 |
- deployment, ok := obj.(*deployapi.Deployment) |
|
| 67 |
- if !ok {
|
|
| 68 |
- return nil, fmt.Errorf("not a deployment: %#v", obj)
|
|
| 69 |
- } |
|
| 70 |
- if !kapi.ValidNamespace(ctx, &deployment.ObjectMeta) {
|
|
| 71 |
- return nil, kerrors.NewConflict("deployment", deployment.Namespace, fmt.Errorf("Deployment.Namespace does not match the provided context"))
|
|
| 72 |
- } |
|
| 73 |
- |
|
| 74 |
- kapi.FillObjectMetaSystemFields(ctx, &deployment.ObjectMeta) |
|
| 75 |
- |
|
| 76 |
- if len(deployment.Name) == 0 {
|
|
| 77 |
- deployment.Name = uuid.NewUUID().String() |
|
| 78 |
- } |
|
| 79 |
- deployment.Status = deployapi.DeploymentStatusNew |
|
| 80 |
- |
|
| 81 |
- glog.Infof("Creating deployment with namespace::Name: %v::%v", deployment.Namespace, deployment.Name)
|
|
| 82 |
- |
|
| 83 |
- if errs := validation.ValidateDeployment(deployment); len(errs) > 0 {
|
|
| 84 |
- return nil, kerrors.NewInvalid("deployment", deployment.Name, errs)
|
|
| 85 |
- } |
|
| 86 |
- |
|
| 87 |
- err := s.registry.CreateDeployment(ctx, deployment) |
|
| 88 |
- if err != nil {
|
|
| 89 |
- return nil, err |
|
| 90 |
- } |
|
| 91 |
- return deployment, nil |
|
| 92 |
-} |
|
| 93 |
- |
|
| 94 |
-// Update replaces a given Deployment instance with an existing instance in s.registry. |
|
| 95 |
-func (s *REST) Update(ctx kapi.Context, obj runtime.Object) (runtime.Object, bool, error) {
|
|
| 96 |
- deployment, ok := obj.(*deployapi.Deployment) |
|
| 97 |
- if !ok {
|
|
| 98 |
- return nil, false, fmt.Errorf("not a deployment: %#v", obj)
|
|
| 99 |
- } |
|
| 100 |
- if len(deployment.Name) == 0 {
|
|
| 101 |
- return nil, false, fmt.Errorf("name is unspecified: %#v", deployment)
|
|
| 102 |
- } |
|
| 103 |
- if !kapi.ValidNamespace(ctx, &deployment.ObjectMeta) {
|
|
| 104 |
- return nil, false, kerrors.NewConflict("deployment", deployment.Namespace, fmt.Errorf("Deployment.Namespace does not match the provided context"))
|
|
| 105 |
- } |
|
| 106 |
- |
|
| 107 |
- err := s.registry.UpdateDeployment(ctx, deployment) |
|
| 108 |
- if err != nil {
|
|
| 109 |
- return nil, false, err |
|
| 110 |
- } |
|
| 111 |
- return deployment, false, nil |
|
| 112 |
-} |
|
| 113 |
- |
|
| 114 |
-func (s *REST) Watch(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
|
|
| 115 |
- return s.registry.WatchDeployments(ctx, label, field, resourceVersion) |
|
| 116 |
-} |
| 117 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,298 +0,0 @@ |
| 1 |
-package deploy |
|
| 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 TestListDeploymentsError(t *testing.T) {
|
|
| 19 |
- mockRegistry := test.NewDeploymentRegistry() |
|
| 20 |
- mockRegistry.Err = fmt.Errorf("test error")
|
|
| 21 |
- |
|
| 22 |
- storage := REST{
|
|
| 23 |
- registry: mockRegistry, |
|
| 24 |
- } |
|
| 25 |
- |
|
| 26 |
- deployments, 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 deployments != nil {
|
|
| 32 |
- t.Errorf("Unexpected non-nil deployments list: %#v", deployments)
|
|
| 33 |
- } |
|
| 34 |
-} |
|
| 35 |
- |
|
| 36 |
-func TestListDeploymentsEmptyList(t *testing.T) {
|
|
| 37 |
- mockRegistry := test.NewDeploymentRegistry() |
|
| 38 |
- mockRegistry.Deployments = &api.DeploymentList{
|
|
| 39 |
- Items: []api.Deployment{},
|
|
| 40 |
- } |
|
| 41 |
- |
|
| 42 |
- storage := REST{
|
|
| 43 |
- registry: mockRegistry, |
|
| 44 |
- } |
|
| 45 |
- |
|
| 46 |
- deployments, 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(deployments.(*api.DeploymentList).Items) != 0 {
|
|
| 52 |
- t.Errorf("Unexpected non-zero deployments list: %#v", deployments)
|
|
| 53 |
- } |
|
| 54 |
-} |
|
| 55 |
- |
|
| 56 |
-func TestListDeploymentsPopulatedList(t *testing.T) {
|
|
| 57 |
- mockRegistry := test.NewDeploymentRegistry() |
|
| 58 |
- mockRegistry.Deployments = &api.DeploymentList{
|
|
| 59 |
- Items: []api.Deployment{
|
|
| 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 |
- deployments := list.(*api.DeploymentList) |
|
| 83 |
- |
|
| 84 |
- if e, a := 2, len(deployments.Items); e != a {
|
|
| 85 |
- t.Errorf("Expected %v, got %v", e, a)
|
|
| 86 |
- } |
|
| 87 |
-} |
|
| 88 |
- |
|
| 89 |
-func TestCreateDeploymentBadObject(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 deployment") == -1 {
|
|
| 97 |
- t.Errorf("Expected 'not a deployment' error, got '%v'", err.Error())
|
|
| 98 |
- } |
|
| 99 |
-} |
|
| 100 |
- |
|
| 101 |
-func TestCreateRegistrySaveError(t *testing.T) {
|
|
| 102 |
- mockRegistry := test.NewDeploymentRegistry() |
|
| 103 |
- mockRegistry.Err = fmt.Errorf("test error")
|
|
| 104 |
- storage := REST{registry: mockRegistry}
|
|
| 105 |
- |
|
| 106 |
- _, err := storage.Create(kapi.NewDefaultContext(), &api.Deployment{
|
|
| 107 |
- ObjectMeta: kapi.ObjectMeta{Name: "foo"},
|
|
| 108 |
- Strategy: deploytest.OkStrategy(), |
|
| 109 |
- ControllerTemplate: deploytest.OkControllerTemplate(), |
|
| 110 |
- }) |
|
| 111 |
- if err != mockRegistry.Err {
|
|
| 112 |
- t.Errorf("Unexpected non-nil error: %#v", err)
|
|
| 113 |
- } |
|
| 114 |
-} |
|
| 115 |
- |
|
| 116 |
-func TestCreateDeploymentOk(t *testing.T) {
|
|
| 117 |
- mockRegistry := test.NewDeploymentRegistry() |
|
| 118 |
- storage := REST{registry: mockRegistry}
|
|
| 119 |
- |
|
| 120 |
- obj, err := storage.Create(kapi.NewDefaultContext(), &api.Deployment{
|
|
| 121 |
- ObjectMeta: kapi.ObjectMeta{Name: "foo"},
|
|
| 122 |
- Strategy: deploytest.OkStrategy(), |
|
| 123 |
- ControllerTemplate: deploytest.OkControllerTemplate(), |
|
| 124 |
- }) |
|
| 125 |
- if obj == nil {
|
|
| 126 |
- t.Errorf("Expected nil obj, got %v", obj)
|
|
| 127 |
- } |
|
| 128 |
- if err != nil {
|
|
| 129 |
- t.Errorf("Unexpected non-nil error: %#v", err)
|
|
| 130 |
- } |
|
| 131 |
- |
|
| 132 |
- deployment, ok := obj.(*api.Deployment) |
|
| 133 |
- if !ok {
|
|
| 134 |
- t.Errorf("Expected deployment type, got: %#v", obj)
|
|
| 135 |
- } |
|
| 136 |
- if deployment.Name != "foo" {
|
|
| 137 |
- t.Errorf("Unexpected deployment: %#v", deployment)
|
|
| 138 |
- } |
|
| 139 |
-} |
|
| 140 |
- |
|
| 141 |
-func TestGetDeploymentError(t *testing.T) {
|
|
| 142 |
- mockRegistry := test.NewDeploymentRegistry() |
|
| 143 |
- mockRegistry.Err = fmt.Errorf("bad")
|
|
| 144 |
- storage := REST{registry: mockRegistry}
|
|
| 145 |
- |
|
| 146 |
- deployment, err := storage.Get(kapi.NewDefaultContext(), "foo") |
|
| 147 |
- if deployment != nil {
|
|
| 148 |
- t.Errorf("Unexpected non-nil deployment: %#v", deployment)
|
|
| 149 |
- } |
|
| 150 |
- if err != mockRegistry.Err {
|
|
| 151 |
- t.Errorf("Expected %#v, got %#v", mockRegistry.Err, err)
|
|
| 152 |
- } |
|
| 153 |
-} |
|
| 154 |
- |
|
| 155 |
-func TestGetDeploymentOk(t *testing.T) {
|
|
| 156 |
- mockRegistry := test.NewDeploymentRegistry() |
|
| 157 |
- mockRegistry.Deployment = &api.Deployment{
|
|
| 158 |
- ObjectMeta: kapi.ObjectMeta{Name: "foo"},
|
|
| 159 |
- } |
|
| 160 |
- storage := REST{registry: mockRegistry}
|
|
| 161 |
- |
|
| 162 |
- deployment, err := storage.Get(kapi.NewDefaultContext(), "foo") |
|
| 163 |
- if deployment == nil {
|
|
| 164 |
- t.Error("Unexpected nil deployment")
|
|
| 165 |
- } |
|
| 166 |
- if err != nil {
|
|
| 167 |
- t.Errorf("Unexpected non-nil error: %v", err)
|
|
| 168 |
- } |
|
| 169 |
- if deployment.(*api.Deployment).Name != "foo" {
|
|
| 170 |
- t.Errorf("Unexpected deployment: %#v", deployment)
|
|
| 171 |
- } |
|
| 172 |
-} |
|
| 173 |
- |
|
| 174 |
-func TestUpdateDeploymentBadObject(t *testing.T) {
|
|
| 175 |
- storage := REST{}
|
|
| 176 |
- |
|
| 177 |
- obj, created, err := storage.Update(kapi.NewDefaultContext(), &api.DeploymentConfig{})
|
|
| 178 |
- if obj != nil || created {
|
|
| 179 |
- t.Errorf("Expected nil, got %v", obj)
|
|
| 180 |
- } |
|
| 181 |
- if strings.Index(err.Error(), "not a deployment:") == -1 {
|
|
| 182 |
- t.Errorf("Expected 'not a deployment' error, got %v", err)
|
|
| 183 |
- } |
|
| 184 |
-} |
|
| 185 |
- |
|
| 186 |
-func TestUpdateDeploymentMissingID(t *testing.T) {
|
|
| 187 |
- storage := REST{}
|
|
| 188 |
- |
|
| 189 |
- obj, created, err := storage.Update(kapi.NewDefaultContext(), &api.Deployment{})
|
|
| 190 |
- if obj != nil || created {
|
|
| 191 |
- t.Errorf("Expected nil, got %v", obj)
|
|
| 192 |
- } |
|
| 193 |
- if strings.Index(err.Error(), "name is unspecified:") == -1 {
|
|
| 194 |
- t.Errorf("Expected 'name is unspecified' error, got %v", err)
|
|
| 195 |
- } |
|
| 196 |
-} |
|
| 197 |
- |
|
| 198 |
-func TestUpdateRegistryErrorSaving(t *testing.T) {
|
|
| 199 |
- mockRepositoryRegistry := test.NewDeploymentRegistry() |
|
| 200 |
- mockRepositoryRegistry.Err = fmt.Errorf("foo")
|
|
| 201 |
- storage := REST{registry: mockRepositoryRegistry}
|
|
| 202 |
- |
|
| 203 |
- _, created, err := storage.Update(kapi.NewDefaultContext(), &api.Deployment{
|
|
| 204 |
- ObjectMeta: kapi.ObjectMeta{Name: "bar"},
|
|
| 205 |
- }) |
|
| 206 |
- if err != mockRepositoryRegistry.Err || created {
|
|
| 207 |
- t.Errorf("Unexpected non-nil error: %#v", err)
|
|
| 208 |
- } |
|
| 209 |
-} |
|
| 210 |
- |
|
| 211 |
-func TestUpdateDeploymentOk(t *testing.T) {
|
|
| 212 |
- mockRepositoryRegistry := test.NewDeploymentRegistry() |
|
| 213 |
- storage := REST{registry: mockRepositoryRegistry}
|
|
| 214 |
- |
|
| 215 |
- obj, created, err := storage.Update(kapi.NewDefaultContext(), &api.Deployment{
|
|
| 216 |
- ObjectMeta: kapi.ObjectMeta{Name: "bar"},
|
|
| 217 |
- }) |
|
| 218 |
- if err != nil || created {
|
|
| 219 |
- t.Errorf("Unexpected non-nil error: %#v", err)
|
|
| 220 |
- } |
|
| 221 |
- repo, ok := obj.(*api.Deployment) |
|
| 222 |
- if !ok {
|
|
| 223 |
- t.Errorf("Expected Deployment, got %#v", obj)
|
|
| 224 |
- } |
|
| 225 |
- if repo.Name != "bar" {
|
|
| 226 |
- t.Errorf("Unexpected repo returned: %#v", repo)
|
|
| 227 |
- } |
|
| 228 |
-} |
|
| 229 |
- |
|
| 230 |
-func TestDeleteDeployment(t *testing.T) {
|
|
| 231 |
- mockRegistry := test.NewDeploymentRegistry() |
|
| 232 |
- storage := REST{registry: mockRegistry}
|
|
| 233 |
- obj, err := storage.Delete(kapi.NewDefaultContext(), "foo") |
|
| 234 |
- if obj == nil {
|
|
| 235 |
- t.Error("Unexpected nil obj")
|
|
| 236 |
- } |
|
| 237 |
- if err != nil {
|
|
| 238 |
- t.Errorf("Unexpected non-nil error: %#v", err)
|
|
| 239 |
- } |
|
| 240 |
- |
|
| 241 |
- status, ok := obj.(*kapi.Status) |
|
| 242 |
- if !ok {
|
|
| 243 |
- t.Errorf("Expected status type, got: %#v", obj)
|
|
| 244 |
- } |
|
| 245 |
- if status.Status != kapi.StatusSuccess {
|
|
| 246 |
- t.Errorf("Expected status=success, got: %#v", status)
|
|
| 247 |
- } |
|
| 248 |
-} |
|
| 249 |
- |
|
| 250 |
-func TestCreateDeploymentConflictingNamespace(t *testing.T) {
|
|
| 251 |
- storage := REST{}
|
|
| 252 |
- |
|
| 253 |
- obj, err := storage.Create(kapi.WithNamespace(kapi.NewContext(), "legal-name"), &api.Deployment{
|
|
| 254 |
- ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "some-value"},
|
|
| 255 |
- Strategy: deploytest.OkStrategy(), |
|
| 256 |
- }) |
|
| 257 |
- |
|
| 258 |
- if obj != nil {
|
|
| 259 |
- t.Error("Expected a nil obj, but we got a value")
|
|
| 260 |
- } |
|
| 261 |
- |
|
| 262 |
- checkExpectedNamespaceError(t, err) |
|
| 263 |
-} |
|
| 264 |
- |
|
| 265 |
-func TestUpdateDeploymentConflictingNamespace(t *testing.T) {
|
|
| 266 |
- mockRepositoryRegistry := test.NewDeploymentRegistry() |
|
| 267 |
- storage := REST{registry: mockRepositoryRegistry}
|
|
| 268 |
- |
|
| 269 |
- obj, created, err := storage.Update(kapi.WithNamespace(kapi.NewContext(), "legal-name"), &api.Deployment{
|
|
| 270 |
- ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "some-value"},
|
|
| 271 |
- Strategy: deploytest.OkStrategy(), |
|
| 272 |
- }) |
|
| 273 |
- |
|
| 274 |
- if obj != nil || created {
|
|
| 275 |
- t.Error("Expected a nil obj, but we got a value")
|
|
| 276 |
- } |
|
| 277 |
- |
|
| 278 |
- checkExpectedNamespaceError(t, err) |
|
| 279 |
-} |
|
| 280 |
- |
|
| 281 |
-func checkExpectedNamespaceError(t *testing.T, err error) {
|
|
| 282 |
- expectedError := "Deployment.Namespace does not match the provided context" |
|
| 283 |
- if err == nil {
|
|
| 284 |
- t.Errorf("Expected '" + expectedError + "', but we didn't get one")
|
|
| 285 |
- } else {
|
|
| 286 |
- e, ok := err.(kclient.APIStatus) |
|
| 287 |
- if !ok {
|
|
| 288 |
- t.Errorf("error was not a statusError: %v", err)
|
|
| 289 |
- } |
|
| 290 |
- if e.Status().Code != http.StatusConflict {
|
|
| 291 |
- t.Errorf("Unexpected failure status: %v", e.Status())
|
|
| 292 |
- } |
|
| 293 |
- if strings.Index(err.Error(), expectedError) == -1 {
|
|
| 294 |
- t.Errorf("Expected '"+expectedError+"' error, got '%v'", err.Error())
|
|
| 295 |
- } |
|
| 296 |
- } |
|
| 297 |
- |
|
| 298 |
-} |
| 4 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,130 +0,0 @@ |
| 1 |
-package etcd |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "github.com/golang/glog" |
|
| 5 |
- |
|
| 6 |
- etcderr "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd" |
|
| 7 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
|
| 8 |
- |
|
| 9 |
- kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 10 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
|
| 11 |
- kubeetcd "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/etcd" |
|
| 12 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" |
|
| 13 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" |
|
| 14 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" |
|
| 15 |
- |
|
| 16 |
- "github.com/openshift/origin/pkg/deploy/api" |
|
| 17 |
-) |
|
| 18 |
- |
|
| 19 |
-const ( |
|
| 20 |
- // DeploymentPath is the path to deployment resources in etcd |
|
| 21 |
- DeploymentPath string = "/deployments" |
|
| 22 |
-) |
|
| 23 |
- |
|
| 24 |
-// Etcd implements deployment.Registry and deploymentconfig.Registry interfaces. |
|
| 25 |
-type Etcd struct {
|
|
| 26 |
- tools.EtcdHelper |
|
| 27 |
-} |
|
| 28 |
- |
|
| 29 |
-// New creates an etcd registry. |
|
| 30 |
-func New(helper tools.EtcdHelper) *Etcd {
|
|
| 31 |
- return &Etcd{
|
|
| 32 |
- EtcdHelper: helper, |
|
| 33 |
- } |
|
| 34 |
-} |
|
| 35 |
- |
|
| 36 |
-// ListDeployments obtains a list of Deployments. |
|
| 37 |
-func (r *Etcd) ListDeployments(ctx kapi.Context, label labels.Selector, field fields.Selector) (*api.DeploymentList, error) {
|
|
| 38 |
- deployments := api.DeploymentList{}
|
|
| 39 |
- err := r.ExtractToList(makeDeploymentListKey(ctx), &deployments) |
|
| 40 |
- if err != nil {
|
|
| 41 |
- return nil, err |
|
| 42 |
- } |
|
| 43 |
- |
|
| 44 |
- filtered := []api.Deployment{}
|
|
| 45 |
- for _, item := range deployments.Items {
|
|
| 46 |
- fields := labels.Set{
|
|
| 47 |
- "name": item.Name, |
|
| 48 |
- "status": string(item.Status), |
|
| 49 |
- } |
|
| 50 |
- if label.Matches(labels.Set(item.Labels)) && field.Matches(fields) {
|
|
| 51 |
- filtered = append(filtered, item) |
|
| 52 |
- } |
|
| 53 |
- } |
|
| 54 |
- |
|
| 55 |
- deployments.Items = filtered |
|
| 56 |
- return &deployments, err |
|
| 57 |
-} |
|
| 58 |
- |
|
| 59 |
-func makeDeploymentListKey(ctx kapi.Context) string {
|
|
| 60 |
- return kubeetcd.MakeEtcdListKey(ctx, DeploymentPath) |
|
| 61 |
-} |
|
| 62 |
- |
|
| 63 |
-func makeDeploymentKey(ctx kapi.Context, id string) (string, error) {
|
|
| 64 |
- return kubeetcd.MakeEtcdItemKey(ctx, DeploymentPath, id) |
|
| 65 |
-} |
|
| 66 |
- |
|
| 67 |
-// GetDeployment gets a specific Deployment specified by its ID. |
|
| 68 |
-func (r *Etcd) GetDeployment(ctx kapi.Context, id string) (*api.Deployment, error) {
|
|
| 69 |
- var deployment api.Deployment |
|
| 70 |
- key, err := makeDeploymentKey(ctx, id) |
|
| 71 |
- if err != nil {
|
|
| 72 |
- return nil, err |
|
| 73 |
- } |
|
| 74 |
- err = r.ExtractObj(key, &deployment, false) |
|
| 75 |
- if err != nil {
|
|
| 76 |
- return nil, etcderr.InterpretGetError(err, "deployment", id) |
|
| 77 |
- } |
|
| 78 |
- return &deployment, nil |
|
| 79 |
-} |
|
| 80 |
- |
|
| 81 |
-// CreateDeployment creates a new Deployment. |
|
| 82 |
-func (r *Etcd) CreateDeployment(ctx kapi.Context, deployment *api.Deployment) error {
|
|
| 83 |
- key, err := makeDeploymentKey(ctx, deployment.Name) |
|
| 84 |
- if err != nil {
|
|
| 85 |
- return err |
|
| 86 |
- } |
|
| 87 |
- err = r.CreateObj(key, deployment, nil, 0) |
|
| 88 |
- return etcderr.InterpretCreateError(err, "deployment", deployment.Name) |
|
| 89 |
-} |
|
| 90 |
- |
|
| 91 |
-// UpdateDeployment replaces an existing Deployment. |
|
| 92 |
-func (r *Etcd) UpdateDeployment(ctx kapi.Context, deployment *api.Deployment) error {
|
|
| 93 |
- key, err := makeDeploymentKey(ctx, deployment.Name) |
|
| 94 |
- if err != nil {
|
|
| 95 |
- return err |
|
| 96 |
- } |
|
| 97 |
- err = r.SetObj(key, deployment, nil, 0) |
|
| 98 |
- return etcderr.InterpretUpdateError(err, "deployment", deployment.Name) |
|
| 99 |
-} |
|
| 100 |
- |
|
| 101 |
-// DeleteDeployment deletes a Deployment specified by its ID. |
|
| 102 |
-func (r *Etcd) DeleteDeployment(ctx kapi.Context, id string) error {
|
|
| 103 |
- key, err := makeDeploymentKey(ctx, id) |
|
| 104 |
- if err != nil {
|
|
| 105 |
- return err |
|
| 106 |
- } |
|
| 107 |
- err = r.Delete(key, false) |
|
| 108 |
- return etcderr.InterpretDeleteError(err, "deployment", id) |
|
| 109 |
-} |
|
| 110 |
- |
|
| 111 |
-// WatchDeployments begins watching for new, changed, or deleted Deployments. |
|
| 112 |
-func (r *Etcd) WatchDeployments(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
|
|
| 113 |
- version, err := tools.ParseWatchResourceVersion(resourceVersion, "deployment") |
|
| 114 |
- if err != nil {
|
|
| 115 |
- return nil, err |
|
| 116 |
- } |
|
| 117 |
- |
|
| 118 |
- return r.WatchList(makeDeploymentListKey(ctx), version, func(obj runtime.Object) bool {
|
|
| 119 |
- deployment, ok := obj.(*api.Deployment) |
|
| 120 |
- if !ok {
|
|
| 121 |
- glog.Errorf("Unexpected object during deployment watch: %#v", obj)
|
|
| 122 |
- return false |
|
| 123 |
- } |
|
| 124 |
- fields := labels.Set{
|
|
| 125 |
- "name": deployment.Name, |
|
| 126 |
- "status": string(deployment.Status), |
|
| 127 |
- } |
|
| 128 |
- return label.Matches(labels.Set(deployment.Labels)) && field.Matches(fields) |
|
| 129 |
- }) |
|
| 130 |
-} |
| 131 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,454 +0,0 @@ |
| 1 |
-package etcd |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "fmt" |
|
| 5 |
- "testing" |
|
| 6 |
- |
|
| 7 |
- "github.com/coreos/go-etcd/etcd" |
|
| 8 |
- |
|
| 9 |
- kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 10 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" |
|
| 11 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta" |
|
| 12 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
|
| 13 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
|
| 14 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" |
|
| 15 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" |
|
| 16 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest" |
|
| 17 |
- |
|
| 18 |
- "github.com/openshift/origin/pkg/api/v1beta1" |
|
| 19 |
- "github.com/openshift/origin/pkg/deploy/api" |
|
| 20 |
-) |
|
| 21 |
- |
|
| 22 |
-// This copy and paste is not pure ignorance. This is that we can be sure that the key is getting made as we |
|
| 23 |
-// expect it to. If someone changes the location of these resources by say moving all the resources to |
|
| 24 |
-// "/origin/resources" (which is a really good idea), then they've made a breaking change and something should |
|
| 25 |
-// fail to let them know they've change some significant change and that other dependent pieces may break. |
|
| 26 |
-func makeTestDeploymentListKey(namespace string) string {
|
|
| 27 |
- if len(namespace) != 0 {
|
|
| 28 |
- return "/deployments/" + namespace |
|
| 29 |
- } |
|
| 30 |
- return "/deployments" |
|
| 31 |
-} |
|
| 32 |
-func makeTestDeploymentKey(namespace, id string) string {
|
|
| 33 |
- return "/deployments/" + namespace + "/" + id |
|
| 34 |
-} |
|
| 35 |
-func makeTestDefaultDeploymentKey(id string) string {
|
|
| 36 |
- return makeTestDeploymentKey(kapi.NamespaceDefault, id) |
|
| 37 |
-} |
|
| 38 |
-func makeTestDefaultDeploymentListKey() string {
|
|
| 39 |
- return makeTestDeploymentListKey(kapi.NamespaceDefault) |
|
| 40 |
-} |
|
| 41 |
- |
|
| 42 |
-func NewTestEtcd(client tools.EtcdClient) *Etcd {
|
|
| 43 |
- return New(tools.NewEtcdHelper(client, v1beta1.Codec, etcdtest.PathPrefix())) |
|
| 44 |
-} |
|
| 45 |
- |
|
| 46 |
-func TestEtcdListEmptyDeployments(t *testing.T) {
|
|
| 47 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 48 |
- key := makeTestDefaultDeploymentListKey() |
|
| 49 |
- fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
| 50 |
- R: &etcd.Response{
|
|
| 51 |
- Node: &etcd.Node{
|
|
| 52 |
- Nodes: []*etcd.Node{},
|
|
| 53 |
- }, |
|
| 54 |
- }, |
|
| 55 |
- E: nil, |
|
| 56 |
- } |
|
| 57 |
- registry := NewTestEtcd(fakeClient) |
|
| 58 |
- deployments, err := registry.ListDeployments(kapi.NewDefaultContext(), labels.Everything(), fields.Everything()) |
|
| 59 |
- if err != nil {
|
|
| 60 |
- t.Errorf("unexpected error: %v", err)
|
|
| 61 |
- } |
|
| 62 |
- |
|
| 63 |
- if len(deployments.Items) != 0 {
|
|
| 64 |
- t.Errorf("Unexpected deployments list: %#v", deployments)
|
|
| 65 |
- } |
|
| 66 |
-} |
|
| 67 |
- |
|
| 68 |
-func TestEtcdListErrorDeployments(t *testing.T) {
|
|
| 69 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 70 |
- key := makeTestDefaultDeploymentListKey() |
|
| 71 |
- fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
| 72 |
- R: &etcd.Response{
|
|
| 73 |
- Node: nil, |
|
| 74 |
- }, |
|
| 75 |
- E: fmt.Errorf("some error"),
|
|
| 76 |
- } |
|
| 77 |
- registry := NewTestEtcd(fakeClient) |
|
| 78 |
- deployments, err := registry.ListDeployments(kapi.NewDefaultContext(), labels.Everything(), fields.Everything()) |
|
| 79 |
- if err == nil {
|
|
| 80 |
- t.Error("unexpected nil error")
|
|
| 81 |
- } |
|
| 82 |
- |
|
| 83 |
- if deployments != nil {
|
|
| 84 |
- t.Errorf("Unexpected non-nil deployments: %#v", deployments)
|
|
| 85 |
- } |
|
| 86 |
-} |
|
| 87 |
- |
|
| 88 |
-func TestEtcdListEverythingDeployments(t *testing.T) {
|
|
| 89 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 90 |
- key := makeTestDefaultDeploymentListKey() |
|
| 91 |
- fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
| 92 |
- R: &etcd.Response{
|
|
| 93 |
- Node: &etcd.Node{
|
|
| 94 |
- Nodes: []*etcd.Node{
|
|
| 95 |
- {
|
|
| 96 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}),
|
|
| 97 |
- }, |
|
| 98 |
- {
|
|
| 99 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{ObjectMeta: kapi.ObjectMeta{Name: "bar"}}),
|
|
| 100 |
- }, |
|
| 101 |
- }, |
|
| 102 |
- }, |
|
| 103 |
- }, |
|
| 104 |
- E: nil, |
|
| 105 |
- } |
|
| 106 |
- registry := NewTestEtcd(fakeClient) |
|
| 107 |
- deployments, err := registry.ListDeployments(kapi.NewDefaultContext(), labels.Everything(), fields.Everything()) |
|
| 108 |
- if err != nil {
|
|
| 109 |
- t.Errorf("unexpected error: %v", err)
|
|
| 110 |
- } |
|
| 111 |
- |
|
| 112 |
- if len(deployments.Items) != 2 || deployments.Items[0].Name != "foo" || deployments.Items[1].Name != "bar" {
|
|
| 113 |
- t.Errorf("Unexpected deployments list: %#v", deployments)
|
|
| 114 |
- } |
|
| 115 |
-} |
|
| 116 |
- |
|
| 117 |
-func TestEtcdListFilteredDeployments(t *testing.T) {
|
|
| 118 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 119 |
- key := makeTestDefaultDeploymentListKey() |
|
| 120 |
- fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
| 121 |
- R: &etcd.Response{
|
|
| 122 |
- Node: &etcd.Node{
|
|
| 123 |
- Nodes: []*etcd.Node{
|
|
| 124 |
- {
|
|
| 125 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{
|
|
| 126 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 127 |
- Name: "foo", |
|
| 128 |
- Labels: map[string]string{"env": "prod"},
|
|
| 129 |
- }, |
|
| 130 |
- }), |
|
| 131 |
- }, |
|
| 132 |
- {
|
|
| 133 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{
|
|
| 134 |
- ObjectMeta: kapi.ObjectMeta{Name: "bar",
|
|
| 135 |
- Labels: map[string]string{"env": "dev"},
|
|
| 136 |
- }, |
|
| 137 |
- Status: api.DeploymentStatusRunning, |
|
| 138 |
- }), |
|
| 139 |
- }, |
|
| 140 |
- {
|
|
| 141 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{
|
|
| 142 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 143 |
- Name: "baz", |
|
| 144 |
- Labels: map[string]string{"env": "stg"},
|
|
| 145 |
- }, |
|
| 146 |
- Status: api.DeploymentStatusRunning, |
|
| 147 |
- }), |
|
| 148 |
- }, |
|
| 149 |
- }, |
|
| 150 |
- }, |
|
| 151 |
- }, |
|
| 152 |
- E: nil, |
|
| 153 |
- } |
|
| 154 |
- |
|
| 155 |
- registry := NewTestEtcd(fakeClient) |
|
| 156 |
- |
|
| 157 |
- testCase := selectorTest{
|
|
| 158 |
- {labels.SelectorFromSet(labels.Set{"env": "dev"}), fields.Everything(), []string{"bar"}},
|
|
| 159 |
- {labels.SelectorFromSet(labels.Set{"env": "stg"}), fields.Everything(), []string{"baz"}},
|
|
| 160 |
- {labels.Everything(), fields.Everything(), []string{"foo", "bar", "baz"}},
|
|
| 161 |
- {labels.Everything(), fields.SelectorFromSet(fields.Set{"name": "baz"}), []string{"baz"}},
|
|
| 162 |
- {labels.Everything(), fields.SelectorFromSet(fields.Set{"status": string(api.DeploymentStatusRunning)}), []string{"bar", "baz"}},
|
|
| 163 |
- } |
|
| 164 |
- |
|
| 165 |
- testCase.validate(t, func(scenario selectorScenario) (runtime.Object, error) {
|
|
| 166 |
- return registry.ListDeployments(kapi.NewDefaultContext(), scenario.label, scenario.field) |
|
| 167 |
- }) |
|
| 168 |
-} |
|
| 169 |
- |
|
| 170 |
-func TestEtcdGetDeployments(t *testing.T) {
|
|
| 171 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 172 |
- fakeClient.Set(makeTestDefaultDeploymentKey("foo"), runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}), 0)
|
|
| 173 |
- registry := NewTestEtcd(fakeClient) |
|
| 174 |
- deployment, err := registry.GetDeployment(kapi.NewDefaultContext(), "foo") |
|
| 175 |
- if err != nil {
|
|
| 176 |
- t.Errorf("unexpected error: %v", err)
|
|
| 177 |
- } |
|
| 178 |
- |
|
| 179 |
- if deployment.Name != "foo" {
|
|
| 180 |
- t.Errorf("Unexpected deployment: %#v", deployment)
|
|
| 181 |
- } |
|
| 182 |
-} |
|
| 183 |
- |
|
| 184 |
-func TestEtcdGetNotFoundDeployments(t *testing.T) {
|
|
| 185 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 186 |
- fakeClient.Data[makeTestDefaultDeploymentKey("foo")] = tools.EtcdResponseWithError{
|
|
| 187 |
- R: &etcd.Response{
|
|
| 188 |
- Node: nil, |
|
| 189 |
- }, |
|
| 190 |
- E: tools.EtcdErrorNotFound, |
|
| 191 |
- } |
|
| 192 |
- registry := NewTestEtcd(fakeClient) |
|
| 193 |
- deployment, err := registry.GetDeployment(kapi.NewDefaultContext(), "foo") |
|
| 194 |
- if err == nil {
|
|
| 195 |
- t.Errorf("Unexpected non-error.")
|
|
| 196 |
- } |
|
| 197 |
- if deployment != nil {
|
|
| 198 |
- t.Errorf("Unexpected deployment: %#v", deployment)
|
|
| 199 |
- } |
|
| 200 |
-} |
|
| 201 |
- |
|
| 202 |
-func TestEtcdCreateDeployments(t *testing.T) {
|
|
| 203 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 204 |
- fakeClient.TestIndex = true |
|
| 205 |
- fakeClient.Data[makeTestDefaultDeploymentKey("foo")] = tools.EtcdResponseWithError{
|
|
| 206 |
- R: &etcd.Response{
|
|
| 207 |
- Node: nil, |
|
| 208 |
- }, |
|
| 209 |
- E: tools.EtcdErrorNotFound, |
|
| 210 |
- } |
|
| 211 |
- registry := NewTestEtcd(fakeClient) |
|
| 212 |
- err := registry.CreateDeployment(kapi.NewDefaultContext(), &api.Deployment{
|
|
| 213 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 214 |
- Name: "foo", |
|
| 215 |
- }, |
|
| 216 |
- }) |
|
| 217 |
- if err != nil {
|
|
| 218 |
- t.Fatalf("unexpected error: %v", err)
|
|
| 219 |
- } |
|
| 220 |
- |
|
| 221 |
- resp, err := fakeClient.Get(makeTestDefaultDeploymentKey("foo"), false, false)
|
|
| 222 |
- if err != nil {
|
|
| 223 |
- t.Fatalf("Unexpected error %v", err)
|
|
| 224 |
- } |
|
| 225 |
- var deployment api.Deployment |
|
| 226 |
- err = v1beta1.Codec.DecodeInto([]byte(resp.Node.Value), &deployment) |
|
| 227 |
- if err != nil {
|
|
| 228 |
- t.Errorf("unexpected error: %v", err)
|
|
| 229 |
- } |
|
| 230 |
- |
|
| 231 |
- if deployment.Name != "foo" {
|
|
| 232 |
- t.Errorf("Unexpected deployment: %#v %s", deployment, resp.Node.Value)
|
|
| 233 |
- } |
|
| 234 |
-} |
|
| 235 |
- |
|
| 236 |
-func TestEtcdCreateAlreadyExistsDeployments(t *testing.T) {
|
|
| 237 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 238 |
- fakeClient.Data[makeTestDefaultDeploymentKey("foo")] = tools.EtcdResponseWithError{
|
|
| 239 |
- R: &etcd.Response{
|
|
| 240 |
- Node: &etcd.Node{
|
|
| 241 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}),
|
|
| 242 |
- }, |
|
| 243 |
- }, |
|
| 244 |
- E: nil, |
|
| 245 |
- } |
|
| 246 |
- registry := NewTestEtcd(fakeClient) |
|
| 247 |
- err := registry.CreateDeployment(kapi.NewDefaultContext(), &api.Deployment{
|
|
| 248 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 249 |
- Name: "foo", |
|
| 250 |
- }, |
|
| 251 |
- }) |
|
| 252 |
- if err == nil {
|
|
| 253 |
- t.Error("Unexpected non-error")
|
|
| 254 |
- } |
|
| 255 |
- if !errors.IsAlreadyExists(err) {
|
|
| 256 |
- t.Errorf("Expected 'already exists' error, got %#v", err)
|
|
| 257 |
- } |
|
| 258 |
-} |
|
| 259 |
- |
|
| 260 |
-func TestEtcdUpdateOkDeployments(t *testing.T) {
|
|
| 261 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 262 |
- registry := NewTestEtcd(fakeClient) |
|
| 263 |
- err := registry.UpdateDeployment(kapi.NewDefaultContext(), &api.Deployment{ObjectMeta: kapi.ObjectMeta{Name: "foo"}})
|
|
| 264 |
- if err != nil {
|
|
| 265 |
- t.Errorf("Unexpected error: %#v", err)
|
|
| 266 |
- } |
|
| 267 |
-} |
|
| 268 |
- |
|
| 269 |
-func TestEtcdDeleteNotFoundDeployments(t *testing.T) {
|
|
| 270 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 271 |
- fakeClient.Err = tools.EtcdErrorNotFound |
|
| 272 |
- registry := NewTestEtcd(fakeClient) |
|
| 273 |
- err := registry.DeleteDeployment(kapi.NewDefaultContext(), "foo") |
|
| 274 |
- if err == nil {
|
|
| 275 |
- t.Error("Unexpected non-error")
|
|
| 276 |
- } |
|
| 277 |
- if !errors.IsNotFound(err) {
|
|
| 278 |
- t.Errorf("Expected 'not found' error, got %#v", err)
|
|
| 279 |
- } |
|
| 280 |
-} |
|
| 281 |
- |
|
| 282 |
-func TestEtcdDeleteErrorDeployments(t *testing.T) {
|
|
| 283 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 284 |
- fakeClient.Err = fmt.Errorf("Some error")
|
|
| 285 |
- registry := NewTestEtcd(fakeClient) |
|
| 286 |
- err := registry.DeleteDeployment(kapi.NewDefaultContext(), "foo") |
|
| 287 |
- if err == nil {
|
|
| 288 |
- t.Error("Unexpected non-error")
|
|
| 289 |
- } |
|
| 290 |
-} |
|
| 291 |
- |
|
| 292 |
-func TestEtcdDeleteOkDeployments(t *testing.T) {
|
|
| 293 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 294 |
- registry := NewTestEtcd(fakeClient) |
|
| 295 |
- key := makeTestDefaultDeploymentListKey() + "/foo" |
|
| 296 |
- fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
| 297 |
- R: &etcd.Response{
|
|
| 298 |
- Node: &etcd.Node{
|
|
| 299 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}),
|
|
| 300 |
- }, |
|
| 301 |
- }, |
|
| 302 |
- E: nil, |
|
| 303 |
- } |
|
| 304 |
- err := registry.DeleteDeployment(kapi.NewDefaultContext(), "foo") |
|
| 305 |
- if err != nil {
|
|
| 306 |
- t.Errorf("Unexpected error: %#v", err)
|
|
| 307 |
- } |
|
| 308 |
- if len(fakeClient.DeletedKeys) != 1 {
|
|
| 309 |
- t.Errorf("Expected 1 delete, found %#v", fakeClient.DeletedKeys)
|
|
| 310 |
- } else if fakeClient.DeletedKeys[0] != key {
|
|
| 311 |
- t.Errorf("Unexpected key: %s, expected %s", fakeClient.DeletedKeys[0], key)
|
|
| 312 |
- } |
|
| 313 |
-} |
|
| 314 |
- |
|
| 315 |
-func TestEtcdCreateDeploymentFailsWithoutNamespace(t *testing.T) {
|
|
| 316 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 317 |
- fakeClient.TestIndex = true |
|
| 318 |
- registry := NewTestEtcd(fakeClient) |
|
| 319 |
- err := registry.CreateDeployment(kapi.NewContext(), &api.Deployment{
|
|
| 320 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 321 |
- Name: "foo", |
|
| 322 |
- }, |
|
| 323 |
- }) |
|
| 324 |
- |
|
| 325 |
- if err == nil {
|
|
| 326 |
- t.Errorf("expected error that namespace was missing from context")
|
|
| 327 |
- } |
|
| 328 |
-} |
|
| 329 |
- |
|
| 330 |
-func TestEtcdListDeploymentsInDifferentNamespaces(t *testing.T) {
|
|
| 331 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 332 |
- namespaceAlfa := kapi.WithNamespace(kapi.NewContext(), "alfa") |
|
| 333 |
- namespaceBravo := kapi.WithNamespace(kapi.NewContext(), "bravo") |
|
| 334 |
- fakeClient.Data["/deployments/alfa"] = tools.EtcdResponseWithError{
|
|
| 335 |
- R: &etcd.Response{
|
|
| 336 |
- Node: &etcd.Node{
|
|
| 337 |
- Nodes: []*etcd.Node{
|
|
| 338 |
- {
|
|
| 339 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{ObjectMeta: kapi.ObjectMeta{Name: "foo1"}}),
|
|
| 340 |
- }, |
|
| 341 |
- }, |
|
| 342 |
- }, |
|
| 343 |
- }, |
|
| 344 |
- E: nil, |
|
| 345 |
- } |
|
| 346 |
- fakeClient.Data["/deployments/bravo"] = tools.EtcdResponseWithError{
|
|
| 347 |
- R: &etcd.Response{
|
|
| 348 |
- Node: &etcd.Node{
|
|
| 349 |
- Nodes: []*etcd.Node{
|
|
| 350 |
- {
|
|
| 351 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{ObjectMeta: kapi.ObjectMeta{Name: "foo2"}}),
|
|
| 352 |
- }, |
|
| 353 |
- {
|
|
| 354 |
- Value: runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{ObjectMeta: kapi.ObjectMeta{Name: "bar2"}}),
|
|
| 355 |
- }, |
|
| 356 |
- }, |
|
| 357 |
- }, |
|
| 358 |
- }, |
|
| 359 |
- E: nil, |
|
| 360 |
- } |
|
| 361 |
- registry := NewTestEtcd(fakeClient) |
|
| 362 |
- |
|
| 363 |
- deploymentsAlfa, err := registry.ListDeployments(namespaceAlfa, labels.Everything(), fields.Everything()) |
|
| 364 |
- if err != nil {
|
|
| 365 |
- t.Errorf("unexpected error: %v", err)
|
|
| 366 |
- } |
|
| 367 |
- if len(deploymentsAlfa.Items) != 1 || deploymentsAlfa.Items[0].Name != "foo1" {
|
|
| 368 |
- t.Errorf("Unexpected deployments list: %#v", deploymentsAlfa)
|
|
| 369 |
- } |
|
| 370 |
- |
|
| 371 |
- deploymentsBravo, err := registry.ListDeployments(namespaceBravo, labels.Everything(), fields.Everything()) |
|
| 372 |
- if err != nil {
|
|
| 373 |
- t.Errorf("unexpected error: %v", err)
|
|
| 374 |
- } |
|
| 375 |
- if len(deploymentsBravo.Items) != 2 || deploymentsBravo.Items[0].Name != "foo2" || deploymentsBravo.Items[1].Name != "bar2" {
|
|
| 376 |
- t.Errorf("Unexpected deployments list: %#v", deploymentsBravo)
|
|
| 377 |
- } |
|
| 378 |
-} |
|
| 379 |
- |
|
| 380 |
-func TestEtcdGetDeploymentInDifferentNamespaces(t *testing.T) {
|
|
| 381 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 382 |
- namespaceAlfa := kapi.WithNamespace(kapi.NewContext(), "alfa") |
|
| 383 |
- namespaceBravo := kapi.WithNamespace(kapi.NewContext(), "bravo") |
|
| 384 |
- fakeClient.Set("/deployments/alfa/foo", runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}), 0)
|
|
| 385 |
- fakeClient.Set("/deployments/bravo/foo", runtime.EncodeOrDie(v1beta1.Codec, &api.Deployment{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}), 0)
|
|
| 386 |
- registry := NewTestEtcd(fakeClient) |
|
| 387 |
- |
|
| 388 |
- alfaFoo, err := registry.GetDeployment(namespaceAlfa, "foo") |
|
| 389 |
- if err != nil {
|
|
| 390 |
- t.Errorf("unexpected error: %v", err)
|
|
| 391 |
- } |
|
| 392 |
- if alfaFoo == nil || alfaFoo.Name != "foo" {
|
|
| 393 |
- t.Errorf("Unexpected deployment: %#v", alfaFoo)
|
|
| 394 |
- } |
|
| 395 |
- |
|
| 396 |
- bravoFoo, err := registry.GetDeployment(namespaceBravo, "foo") |
|
| 397 |
- if err != nil {
|
|
| 398 |
- t.Errorf("unexpected error: %v", err)
|
|
| 399 |
- } |
|
| 400 |
- if bravoFoo == nil || bravoFoo.Name != "foo" {
|
|
| 401 |
- t.Errorf("Unexpected deployment: %#v", bravoFoo)
|
|
| 402 |
- } |
|
| 403 |
-} |
|
| 404 |
- |
|
| 405 |
-type selectorScenario struct {
|
|
| 406 |
- label labels.Selector |
|
| 407 |
- field fields.Selector |
|
| 408 |
- expectedIDs []string |
|
| 409 |
-} |
|
| 410 |
- |
|
| 411 |
-type scenarioObjectLister func(selectorScenario) (runtime.Object, error) |
|
| 412 |
- |
|
| 413 |
-type selectorTest []selectorScenario |
|
| 414 |
- |
|
| 415 |
-func (s selectorTest) validate(t *testing.T, lister scenarioObjectLister) {
|
|
| 416 |
- for _, scenario := range s {
|
|
| 417 |
- list, err := lister(scenario) |
|
| 418 |
- if err != nil {
|
|
| 419 |
- t.Fatalf("Error listing objects for scenario %+v: %#v", scenario, err)
|
|
| 420 |
- } |
|
| 421 |
- |
|
| 422 |
- objects, err := runtime.ExtractList(list) |
|
| 423 |
- if err != nil {
|
|
| 424 |
- t.Fatalf("Error extracting objects from list for scenario %+v: %#v", scenario, err)
|
|
| 425 |
- } |
|
| 426 |
- |
|
| 427 |
- for _, id := range scenario.expectedIDs {
|
|
| 428 |
- found := false |
|
| 429 |
- for _, object := range objects {
|
|
| 430 |
- apiObject, _ := meta.Accessor(object) |
|
| 431 |
- if apiObject.Name() == id {
|
|
| 432 |
- found = true |
|
| 433 |
- break |
|
| 434 |
- } |
|
| 435 |
- } |
|
| 436 |
- if !found {
|
|
| 437 |
- t.Errorf("Expected but didn't find object %s for scenario: %+v", id, scenario)
|
|
| 438 |
- } |
|
| 439 |
- } |
|
| 440 |
- |
|
| 441 |
- for _, object := range objects {
|
|
| 442 |
- apiObject, _ := meta.Accessor(object) |
|
| 443 |
- found := false |
|
| 444 |
- for _, id := range scenario.expectedIDs {
|
|
| 445 |
- if apiObject.Name() == id {
|
|
| 446 |
- found = true |
|
| 447 |
- } |
|
| 448 |
- } |
|
| 449 |
- if !found {
|
|
| 450 |
- t.Errorf("Unexpected object %s for scenario: %+v", apiObject.Name(), scenario)
|
|
| 451 |
- } |
|
| 452 |
- } |
|
| 453 |
- } |
|
| 454 |
-} |
| 455 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,63 +0,0 @@ |
| 1 |
-package test |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "sync" |
|
| 5 |
- |
|
| 6 |
- kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 7 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" |
|
| 8 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
|
| 9 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" |
|
| 10 |
- "github.com/openshift/origin/pkg/deploy/api" |
|
| 11 |
-) |
|
| 12 |
- |
|
| 13 |
-type DeploymentRegistry struct {
|
|
| 14 |
- Err error |
|
| 15 |
- Deployment *api.Deployment |
|
| 16 |
- Deployments *api.DeploymentList |
|
| 17 |
- sync.Mutex |
|
| 18 |
-} |
|
| 19 |
- |
|
| 20 |
-func NewDeploymentRegistry() *DeploymentRegistry {
|
|
| 21 |
- return &DeploymentRegistry{}
|
|
| 22 |
-} |
|
| 23 |
- |
|
| 24 |
-func (r *DeploymentRegistry) ListDeployments(ctx kapi.Context, label labels.Selector, field fields.Selector) (*api.DeploymentList, error) {
|
|
| 25 |
- r.Lock() |
|
| 26 |
- defer r.Unlock() |
|
| 27 |
- |
|
| 28 |
- return r.Deployments, r.Err |
|
| 29 |
-} |
|
| 30 |
- |
|
| 31 |
-func (r *DeploymentRegistry) GetDeployment(ctx kapi.Context, id string) (*api.Deployment, error) {
|
|
| 32 |
- r.Lock() |
|
| 33 |
- defer r.Unlock() |
|
| 34 |
- |
|
| 35 |
- return r.Deployment, r.Err |
|
| 36 |
-} |
|
| 37 |
- |
|
| 38 |
-func (r *DeploymentRegistry) CreateDeployment(ctx kapi.Context, deployment *api.Deployment) error {
|
|
| 39 |
- r.Lock() |
|
| 40 |
- defer r.Unlock() |
|
| 41 |
- |
|
| 42 |
- r.Deployment = deployment |
|
| 43 |
- return r.Err |
|
| 44 |
-} |
|
| 45 |
- |
|
| 46 |
-func (r *DeploymentRegistry) UpdateDeployment(ctx kapi.Context, deployment *api.Deployment) error {
|
|
| 47 |
- r.Lock() |
|
| 48 |
- defer r.Unlock() |
|
| 49 |
- |
|
| 50 |
- r.Deployment = deployment |
|
| 51 |
- return r.Err |
|
| 52 |
-} |
|
| 53 |
- |
|
| 54 |
-func (r *DeploymentRegistry) DeleteDeployment(ctx kapi.Context, id string) error {
|
|
| 55 |
- r.Lock() |
|
| 56 |
- defer r.Unlock() |
|
| 57 |
- |
|
| 58 |
- return r.Err |
|
| 59 |
-} |
|
| 60 |
- |
|
| 61 |
-func (r *DeploymentRegistry) WatchDeployments(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
|
|
| 62 |
- return nil, r.Err |
|
| 63 |
-} |
| ... | ... |
@@ -49,17 +49,6 @@ func addReplicationControllerNestedLabels(obj *kapi.ReplicationController, label |
| 49 | 49 |
return nil |
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 |
-// addDeploymentNestedLabels adds new label(s) to a nested labels of a single Deployment object |
|
| 53 |
-func addDeploymentNestedLabels(obj *deployapi.Deployment, labels labels.Set) error {
|
|
| 54 |
- if obj.ControllerTemplate.Template.Labels == nil {
|
|
| 55 |
- obj.ControllerTemplate.Template.Labels = make(map[string]string) |
|
| 56 |
- } |
|
| 57 |
- if err := MergeInto(obj.ControllerTemplate.Template.Labels, labels, ErrorOnDifferentDstKeyValue); err != nil {
|
|
| 58 |
- return fmt.Errorf("unable to add labels to Template.Deployment.ControllerTemplate.Template: %v", err)
|
|
| 59 |
- } |
|
| 60 |
- return nil |
|
| 61 |
-} |
|
| 62 |
- |
|
| 63 | 52 |
// addDeploymentConfigNestedLabels adds new label(s) to a nested labels of a single DeploymentConfig object |
| 64 | 53 |
func addDeploymentConfigNestedLabels(obj *deployapi.DeploymentConfig, labels labels.Set) error {
|
| 65 | 54 |
if obj.Template.ControllerTemplate.Template.Labels == nil {
|
| ... | ... |
@@ -97,8 +86,6 @@ func AddObjectLabels(obj runtime.Object, labels labels.Set) error {
|
| 97 | 97 |
switch objType := obj.(type) {
|
| 98 | 98 |
case *kapi.ReplicationController: |
| 99 | 99 |
return addReplicationControllerNestedLabels(objType, labels) |
| 100 |
- case *deployapi.Deployment: |
|
| 101 |
- return addDeploymentNestedLabels(objType, labels) |
|
| 102 | 100 |
case *deployapi.DeploymentConfig: |
| 103 | 101 |
return addDeploymentConfigNestedLabels(objType, labels) |
| 104 | 102 |
} |
| ... | ... |
@@ -138,23 +138,6 @@ func TestAddConfigLabels(t *testing.T) {
|
| 138 | 138 |
err: true, |
| 139 | 139 |
expectedLabels: map[string]string{"foo": "first value"},
|
| 140 | 140 |
}, |
| 141 |
- { // [11] Test adding labels to a Deployment object
|
|
| 142 |
- obj: &deployapi.Deployment{
|
|
| 143 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 144 |
- Labels: map[string]string{"foo": "first value"},
|
|
| 145 |
- }, |
|
| 146 |
- ControllerTemplate: kapi.ReplicationControllerSpec{
|
|
| 147 |
- Template: &kapi.PodTemplateSpec{
|
|
| 148 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 149 |
- Labels: map[string]string{"foo": "first value"},
|
|
| 150 |
- }, |
|
| 151 |
- }, |
|
| 152 |
- }, |
|
| 153 |
- }, |
|
| 154 |
- addLabels: map[string]string{"bar": "second value"},
|
|
| 155 |
- err: false, |
|
| 156 |
- expectedLabels: map[string]string{"foo": "first value", "bar": "second value"},
|
|
| 157 |
- }, |
|
| 158 | 141 |
{ // [12] Test adding labels to a DeploymentConfig object
|
| 159 | 142 |
obj: &deployapi.DeploymentConfig{
|
| 160 | 143 |
ObjectMeta: kapi.ObjectMeta{
|
| ... | ... |
@@ -210,10 +193,6 @@ func TestAddConfigLabels(t *testing.T) {
|
| 210 | 210 |
if e, a := test.expectedLabels, objType.Spec.Selector; !reflect.DeepEqual(e, a) {
|
| 211 | 211 |
t.Errorf("Unexpected labels on testCase[%v]. Expected: %#v, got: %#v.", i, e, a)
|
| 212 | 212 |
} |
| 213 |
- case *deployapi.Deployment: |
|
| 214 |
- if e, a := test.expectedLabels, objType.ControllerTemplate.Template.Labels; !reflect.DeepEqual(e, a) {
|
|
| 215 |
- t.Errorf("Unexpected labels on testCase[%v]. Expected: %#v, got: %#v.", i, e, a)
|
|
| 216 |
- } |
|
| 217 | 213 |
case *deployapi.DeploymentConfig: |
| 218 | 214 |
if e, a := test.expectedLabels, objType.Template.ControllerTemplate.Template.Labels; !reflect.DeepEqual(e, a) {
|
| 219 | 215 |
t.Errorf("Unexpected labels on testCase[%v]. Expected: %#v, got: %#v.", i, e, a)
|