Skip to content

Commit

Permalink
merge imagestreamtag list on patch
Browse files Browse the repository at this point in the history
  • Loading branch information
bparees committed Oct 30, 2017
1 parent ce78d7a commit 3a5a100
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 5 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions api/swagger-spec/openshift-openapi-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand All @@ -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"
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/image/apis/image/v1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions pkg/image/apis/image/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions pkg/openapi/zz_generated.openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down
12 changes: 11 additions & 1 deletion test/cmd/images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -292,4 +292,14 @@ 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'

This comment has been minimized.

Copy link
@smarterclayton

smarterclayton Oct 31, 2017

Contributor

This is a nit but why create a new project?

This comment has been minimized.

Copy link
@bparees

bparees Nov 1, 2017

Author Contributor

easier than worrying about mucking up an existing project or dealing w/ other mucking that may have been done in it w/ respect to expected tags.

os::cmd::expect_success 'oc create -f examples/image-streams/image-streams-centos7.json'
os::cmd::expect_success_and_test '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_test 'oc get is ruby -o jsonpath={.spec.tags[*].name}' '2.0 2.2 2.3 2.4 latest newtag'

This comment has been minimized.

Copy link
@smarterclayton

smarterclayton Oct 31, 2017

Contributor

Test the merged tag value/values

This comment has been minimized.

Copy link
@bparees

bparees Nov 1, 2017

Author Contributor

why? either the merge strategy works or it doesn't. the presence of the entries shows it merged the keys. Do we not have sufficient testing elsewhere for the general concept of merging arrays?

This comment has been minimized.

Copy link
@smarterclayton

smarterclayton via email Nov 1, 2017

Contributor
os::cmd::expect_success 'oc delete project mergetags'
echo "apply new imagestream tags: ok"
os::test::junit::declare_suite_end

os::test::junit::declare_suite_end
38 changes: 38 additions & 0 deletions test/testdata/images/modified-ruby-imagestream.json
Original file line number Diff line number Diff line change
@@ -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": "Apache HTTP Server 2.4",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"description": "Build and serve static content via Apache HTTP Server (httpd) 2.4 on CentOS 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/httpd-container/blob/master/2.4/README.md.",
"iconClass": "icon-apache",
"tags": "builder,httpd",
"supports":"httpd",
"version": "2.4",
"sampleRepo": "https://github.com/openshift/httpd-ex.git"
},
"from": {
"kind": "DockerImage",
"name": "centos/httpd-24-centos7:latest"
}
},
{
"name": "newtag",
"from": {
"kind": "DockerImage",
"name": "centos/ruby-24-centos7:latest"
}
}
]
}
}

0 comments on commit 3a5a100

Please sign in to comment.