From 1b8086c01387895c8c06a72b3022e8dacb7415cc Mon Sep 17 00:00:00 2001 From: Ben Parees Date: Fri, 27 Oct 2017 22:48:24 +0200 Subject: [PATCH] merge imagestreamtag list on patch --- ...shift_origin_pkg_image_apis_image_v1.proto | 4 ++ api/swagger-spec/openshift-openapi-spec.json | 8 +++- pkg/image/apis/image/v1/generated.proto | 4 ++ pkg/image/apis/image/v1/types.go | 8 +++- pkg/openapi/zz_generated.openapi.go | 12 ++++++ test/cmd/images.sh | 13 ++++++- .../images/modified-ruby-imagestream.json | 38 +++++++++++++++++++ 7 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 test/testdata/images/modified-ruby-imagestream.json diff --git a/api/protobuf-spec/github_com_openshift_origin_pkg_image_apis_image_v1.proto b/api/protobuf-spec/github_com_openshift_origin_pkg_image_apis_image_v1.proto index 34c91b297553..cf76973f8711 100644 --- a/api/protobuf-spec/github_com_openshift_origin_pkg_image_apis_image_v1.proto +++ b/api/protobuf-spec/github_com_openshift_origin_pkg_image_apis_image_v1.proto @@ -270,6 +270,8 @@ message ImageStreamSpec { optional string dockerImageRepository = 1; // tags map arbitrary string values to specific image locators + // +patchMergeKey=name + // +patchStrategy=merge repeated TagReference tags = 2; } @@ -286,6 +288,8 @@ message ImageStreamStatus { // Tags are a historical record of images associated with each tag. The first entry in the // TagEvent array is the currently tagged image. + // +patchMergeKey=tag + // +patchStrategy=merge repeated NamedTagEventList tags = 2; } diff --git a/api/swagger-spec/openshift-openapi-spec.json b/api/swagger-spec/openshift-openapi-spec.json index 65d9b1b61f0e..a2b3bdb122dd 100644 --- a/api/swagger-spec/openshift-openapi-spec.json +++ b/api/swagger-spec/openshift-openapi-spec.json @@ -90333,7 +90333,9 @@ "type": "array", "items": { "$ref": "#/definitions/com.github.openshift.origin.pkg.image.apis.image.v1.TagReference" - } + }, + "x-kubernetes-patch-merge-key": "name", + "x-kubernetes-patch-strategy": "merge" } } }, @@ -90356,7 +90358,9 @@ "type": "array", "items": { "$ref": "#/definitions/com.github.openshift.origin.pkg.image.apis.image.v1.NamedTagEventList" - } + }, + "x-kubernetes-patch-merge-key": "tag", + "x-kubernetes-patch-strategy": "merge" } } }, diff --git a/pkg/image/apis/image/v1/generated.proto b/pkg/image/apis/image/v1/generated.proto index 34c91b297553..cf76973f8711 100644 --- a/pkg/image/apis/image/v1/generated.proto +++ b/pkg/image/apis/image/v1/generated.proto @@ -270,6 +270,8 @@ message ImageStreamSpec { optional string dockerImageRepository = 1; // tags map arbitrary string values to specific image locators + // +patchMergeKey=name + // +patchStrategy=merge repeated TagReference tags = 2; } @@ -286,6 +288,8 @@ message ImageStreamStatus { // Tags are a historical record of images associated with each tag. The first entry in the // TagEvent array is the currently tagged image. + // +patchMergeKey=tag + // +patchStrategy=merge repeated NamedTagEventList tags = 2; } diff --git a/pkg/image/apis/image/v1/types.go b/pkg/image/apis/image/v1/types.go index 556875b81811..c38dc582fc29 100644 --- a/pkg/image/apis/image/v1/types.go +++ b/pkg/image/apis/image/v1/types.go @@ -184,7 +184,9 @@ type ImageStreamSpec struct { // Specify the source for the tags to be imported in each tag via the spec.tags.from reference instead. DockerImageRepository string `json:"dockerImageRepository,omitempty" protobuf:"bytes,1,opt,name=dockerImageRepository"` // tags map arbitrary string values to specific image locators - Tags []TagReference `json:"tags,omitempty" protobuf:"bytes,2,rep,name=tags"` + // +patchMergeKey=name + // +patchStrategy=merge + Tags []TagReference `json:"tags,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,2,rep,name=tags"` } // ImageLookupPolicy describes how an image stream can be used to override the image references @@ -272,7 +274,9 @@ type ImageStreamStatus struct { PublicDockerImageRepository string `json:"publicDockerImageRepository,omitempty" protobuf:"bytes,3,opt,name=publicDockerImageRepository"` // Tags are a historical record of images associated with each tag. The first entry in the // TagEvent array is the currently tagged image. - Tags []NamedTagEventList `json:"tags,omitempty" protobuf:"bytes,2,rep,name=tags"` + // +patchMergeKey=tag + // +patchStrategy=merge + Tags []NamedTagEventList `json:"tags,omitempty" patchStrategy:"merge" patchMergeKey:"tag" protobuf:"bytes,2,rep,name=tags"` } // NamedTagEventList relates a tag to its image history. diff --git a/pkg/openapi/zz_generated.openapi.go b/pkg/openapi/zz_generated.openapi.go index b474ca9081ff..c0af996eee43 100644 --- a/pkg/openapi/zz_generated.openapi.go +++ b/pkg/openapi/zz_generated.openapi.go @@ -6136,6 +6136,12 @@ func GetOpenAPIDefinitions(ref openapi.ReferenceCallback) map[string]openapi.Ope }, }, "tags": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-patch-merge-key": "name", + "x-kubernetes-patch-strategy": "merge", + }, + }, SchemaProps: spec.SchemaProps{ Description: "tags map arbitrary string values to specific image locators", Type: []string{"array"}, @@ -6174,6 +6180,12 @@ func GetOpenAPIDefinitions(ref openapi.ReferenceCallback) map[string]openapi.Ope }, }, "tags": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-patch-merge-key": "tag", + "x-kubernetes-patch-strategy": "merge", + }, + }, SchemaProps: spec.SchemaProps{ Description: "Tags are a historical record of images associated with each tag. The first entry in the TagEvent array is the currently tagged image.", Type: []string{"array"}, diff --git a/test/cmd/images.sh b/test/cmd/images.sh index f7e4bfc170ca..bd15283a9984 100755 --- a/test/cmd/images.sh +++ b/test/cmd/images.sh @@ -9,7 +9,7 @@ trap os::test::junit::reconcile_output EXIT os::cmd::expect_success 'oc login -u system:admin' cluster_admin_context="$( oc config current-context )" os::cmd::expect_success "oc config use-context '${original_context}'" - oc delete project test-cmd-images-2 --context=${cluster_admin_context} + oc delete project test-cmd-images-2 merge-tags --context=${cluster_admin_context} oc delete all,templates --all --context=${cluster_admin_context} exit 0 @@ -292,4 +292,15 @@ os::cmd::expect_success 'oc delete all --all' echo "delete istag: ok" os::test::junit::declare_suite_end +os::test::junit::declare_suite_start "cmd/images${IMAGES_TESTS_POSTFIX:-}/merge-tags-on-apply" +os::cmd::expect_success 'oc new-project merge-tags' +os::cmd::expect_success 'oc create -f examples/image-streams/image-streams-centos7.json' +os::cmd::expect_success_and_text 'oc get is ruby -o jsonpath={.spec.tags[*].name}' '2.0 2.2 2.3 2.4 latest' +os::cmd::expect_success 'oc apply -f test/testdata/images/modified-ruby-imagestream.json' +os::cmd::expect_success_and_text 'oc get is ruby -o jsonpath={.spec.tags[*].name}' '2.0 2.2 2.3 2.4 latest newtag' +os::cmd::expect_success_and_text 'oc get is ruby -o jsonpath={.spec.tags[3].annotations.version}' '2.4 patched' +os::cmd::expect_success 'oc delete project merge-tags' +echo "apply new imagestream tags: ok" +os::test::junit::declare_suite_end + os::test::junit::declare_suite_end diff --git a/test/testdata/images/modified-ruby-imagestream.json b/test/testdata/images/modified-ruby-imagestream.json new file mode 100644 index 000000000000..f23051c9b543 --- /dev/null +++ b/test/testdata/images/modified-ruby-imagestream.json @@ -0,0 +1,38 @@ +{ + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "ruby", + "annotations": { + "openshift.io/display-name": "Ruby" + } + }, + "spec": { + "tags": [ + { + "name": "2.4", + "annotations": { + "openshift.io/display-name": "Ruby Patched", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Build and run Ruby 2.4 applications on CentOS 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-ruby-container/blob/master/2.4/README.md.", + "iconClass": "icon-ruby", + "tags": "builder,ruby", + "supports": "ruby:2.4,ruby", + "version": "2.4 patched", + "sampleRepo": "https://github.com/openshift/ruby-ex.git" + }, + "from": { + "kind": "DockerImage", + "name": "centos/ruby-24-centos7:latest" + } + }, + { + "name": "newtag", + "from": { + "kind": "DockerImage", + "name": "centos/ruby-24-centos7:latest" + } + } + ] + } +}