Validate both ImageRepository and ImageStream kinds in deployment
trigger parameters.
| ... | ... |
@@ -189,10 +189,10 @@ func validateImageChangeParams(params *deployapi.DeploymentTriggerImageChangePar |
| 189 | 189 |
|
| 190 | 190 |
if len(params.From.Name) != 0 {
|
| 191 | 191 |
if len(params.From.Kind) == 0 {
|
| 192 |
- params.From.Kind = "ImageRepository" |
|
| 192 |
+ params.From.Kind = "ImageStream" |
|
| 193 | 193 |
} |
| 194 |
- if params.From.Kind != "ImageRepository" {
|
|
| 195 |
- errs = append(errs, fielderrors.NewFieldInvalid("from.kind", params.From.Kind, "only 'ImageRepository' is allowed"))
|
|
| 194 |
+ if params.From.Kind != "ImageRepository" && params.From.Kind != "ImageStream" {
|
|
| 195 |
+ errs = append(errs, fielderrors.NewFieldInvalid("from.kind", params.From.Kind, "kind must be 'ImageStream' or 'ImageRepository'"))
|
|
| 196 | 196 |
} |
| 197 | 197 |
|
| 198 | 198 |
if !util.IsDNS1123Subdomain(params.From.Name) {
|
| ... | ... |
@@ -148,6 +148,26 @@ func TestValidateDeploymentConfigMissingFields(t *testing.T) {
|
| 148 | 148 |
fielderrors.ValidationErrorTypeRequired, |
| 149 | 149 |
"triggers[0].imageChangeParams.from", |
| 150 | 150 |
}, |
| 151 |
+ "invalid Trigger imageChangeParams.from.kind": {
|
|
| 152 |
+ api.DeploymentConfig{
|
|
| 153 |
+ ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
|
|
| 154 |
+ Triggers: []api.DeploymentTriggerPolicy{
|
|
| 155 |
+ {
|
|
| 156 |
+ Type: api.DeploymentTriggerOnImageChange, |
|
| 157 |
+ ImageChangeParams: &api.DeploymentTriggerImageChangeParams{
|
|
| 158 |
+ From: kapi.ObjectReference{
|
|
| 159 |
+ Kind: "Invalid", |
|
| 160 |
+ Name: "name", |
|
| 161 |
+ }, |
|
| 162 |
+ ContainerNames: []string{"foo"},
|
|
| 163 |
+ }, |
|
| 164 |
+ }, |
|
| 165 |
+ }, |
|
| 166 |
+ Template: test.OkDeploymentTemplate(), |
|
| 167 |
+ }, |
|
| 168 |
+ fielderrors.ValidationErrorTypeInvalid, |
|
| 169 |
+ "triggers[0].imageChangeParams.from.kind", |
|
| 170 |
+ }, |
|
| 151 | 171 |
"both fields illegal Trigger imageChangeParams.repositoryName": {
|
| 152 | 172 |
api.DeploymentConfig{
|
| 153 | 173 |
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
|
| ... | ... |
@@ -389,3 +409,58 @@ func TestValidateDeploymentConfigRollbackInvalidFields(t *testing.T) {
|
| 389 | 389 |
} |
| 390 | 390 |
} |
| 391 | 391 |
} |
| 392 |
+ |
|
| 393 |
+func TestValidateDeploymentConfigDefaultImageStreamKind(t *testing.T) {
|
|
| 394 |
+ config := &api.DeploymentConfig{
|
|
| 395 |
+ ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
|
|
| 396 |
+ Triggers: []api.DeploymentTriggerPolicy{
|
|
| 397 |
+ {
|
|
| 398 |
+ Type: api.DeploymentTriggerOnImageChange, |
|
| 399 |
+ ImageChangeParams: &api.DeploymentTriggerImageChangeParams{
|
|
| 400 |
+ From: kapi.ObjectReference{
|
|
| 401 |
+ Name: "name", |
|
| 402 |
+ }, |
|
| 403 |
+ ContainerNames: []string{"foo"},
|
|
| 404 |
+ }, |
|
| 405 |
+ }, |
|
| 406 |
+ }, |
|
| 407 |
+ Template: test.OkDeploymentTemplate(), |
|
| 408 |
+ } |
|
| 409 |
+ |
|
| 410 |
+ errs := ValidateDeploymentConfig(config) |
|
| 411 |
+ if len(errs) > 0 {
|
|
| 412 |
+ t.Errorf("Unxpected non-empty error list: %v", errs)
|
|
| 413 |
+ } |
|
| 414 |
+ |
|
| 415 |
+ if e, a := "ImageStream", config.Triggers[0].ImageChangeParams.From.Kind; e != a {
|
|
| 416 |
+ t.Errorf("expected imageChangeParams.from.kind %s, got %s", e, a)
|
|
| 417 |
+ } |
|
| 418 |
+} |
|
| 419 |
+ |
|
| 420 |
+func TestValidateDeploymentConfigImageRepositorySupported(t *testing.T) {
|
|
| 421 |
+ config := &api.DeploymentConfig{
|
|
| 422 |
+ ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
|
|
| 423 |
+ Triggers: []api.DeploymentTriggerPolicy{
|
|
| 424 |
+ {
|
|
| 425 |
+ Type: api.DeploymentTriggerOnImageChange, |
|
| 426 |
+ ImageChangeParams: &api.DeploymentTriggerImageChangeParams{
|
|
| 427 |
+ From: kapi.ObjectReference{
|
|
| 428 |
+ Kind: "ImageRepository", |
|
| 429 |
+ Name: "name", |
|
| 430 |
+ }, |
|
| 431 |
+ ContainerNames: []string{"foo"},
|
|
| 432 |
+ }, |
|
| 433 |
+ }, |
|
| 434 |
+ }, |
|
| 435 |
+ Template: test.OkDeploymentTemplate(), |
|
| 436 |
+ } |
|
| 437 |
+ |
|
| 438 |
+ errs := ValidateDeploymentConfig(config) |
|
| 439 |
+ if len(errs) > 0 {
|
|
| 440 |
+ t.Errorf("Unxpected non-empty error list: %v", errs)
|
|
| 441 |
+ } |
|
| 442 |
+ |
|
| 443 |
+ if e, a := "ImageRepository", config.Triggers[0].ImageChangeParams.From.Kind; e != a {
|
|
| 444 |
+ t.Errorf("expected imageChangeParams.from.kind %s, got %s", e, a)
|
|
| 445 |
+ } |
|
| 446 |
+} |