-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update import-image cmd to use external versions #20333
update import-image cmd to use external versions #20333
Conversation
@@ -384,39 +413,55 @@ func (o *ImportImageOptions) importTag(stream *imageapi.ImageStream) (*imageapi. | |||
existing.Generation = &zero | |||
|
|||
} | |||
stream.Spec.Tags[tag] = *existing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deads2k imageapiv1 switches an imagestream's spec.tags
field from a map[string]TagReference
to a slice of TagReferences. Not sure how to handle tag lookups in the command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deads2k imageapiv1 switches an imagestream's spec.tags field from a map[string]TagReference to a slice of TagReferences. Not sure how to handle tag lookups in the command
You can't just iterate over the list? There shouldn't be any conflicting names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not want to assume that a ReferenceTag.Name
value was the same as the value used for a key in the map that was used in the internal api. Latest changes to this PR make use of the imageapi.SplitImageStreamTag helper:
origin/pkg/image/apis/image/helper.go
Lines 161 to 171 in 6f8c120
func SplitImageStreamTag(nameAndTag string) (name string, tag string, ok bool) { | |
parts := strings.SplitN(nameAndTag, ":", 2) | |
name = parts[0] | |
if len(parts) > 1 { | |
tag = parts[1] | |
} | |
if len(tag) == 0 { | |
tag = DefaultImageTag | |
} | |
return name, tag, len(parts) == 2 | |
} |
isi, streamInsecure := o.newImageStreamImport(stream) | ||
for tag, from := range tags { | ||
insecure := streamInsecure | ||
scheduled := o.Scheduled | ||
oldTag, ok := stream.Spec.Tags[tag] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @bparees
External image api does not allow maps, and instead stores tags as a slice. Is there any preference here as to how tag lookups should occur?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, iterating seems reasonable to me.
oldTagFound := false | ||
var oldTag imageapiv1.TagReference | ||
for _, t := range stream.Spec.Tags { | ||
if t.Name == tag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mfojtik is there a helper I can use here to match a TagReference? I'm pretty sure matching on t.Name
is not correct
f33b464
to
e17103b
Compare
e17103b
to
3771854
Compare
Switched from using @bparees @mfojtik would appreciate one last look at these changes. Particularly here, here, here, and here |
lgtm |
"k8s.io/kubernetes/pkg/api/legacyscheme" | ||
kapi "k8s.io/kubernetes/pkg/apis/core" | ||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates" | ||
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" | ||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions" | ||
|
||
imageapiv1 "github.com/openshift/api/image/v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imagev1
"k8s.io/kubernetes/pkg/kubectl/cmd/templates" | ||
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" | ||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions" | ||
|
||
imageapiv1 "github.com/openshift/api/image/v1" | ||
imageclientv1 "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imagev1client
"github.com/openshift/origin/pkg/oc/cli/tag" | ||
"github.com/openshift/origin/pkg/oc/lib/describe" | ||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up to k8s imports
// an import. | ||
func (o *ImportImageOptions) Validate(cmd *cobra.Command) error { | ||
if len(o.Target) == 0 { | ||
return kcmdutil.UsageErrorf(cmd, "you must specify the name of an image stream") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate
only works with *Options
and does not accept any input, return fmt.Errorf
here.
|
||
if result.Status.Import != nil { | ||
// TODO: remove once we have external describers | ||
var internalResult imageapi.ImageStreamImport | ||
if legacyscheme.Scheme.Convert(result, &internalResult, nil); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use legacyscheme
it's legacy for a reason. Invoke the actual conversion function from image package, like we're doing that already elsewhere (eg. #20343).
info, err := describe.DescribeImage(image.Image, imageapi.JoinImageStreamTag(stream.Name, image.Tag)) | ||
// TODO: remove once we have external describers | ||
var internalImage imageapi.Image | ||
if legacyscheme.Scheme.Convert(image.Image, &internalImage, nil); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
|
||
oldTagFound := false | ||
var oldTag imageapiv1.TagReference | ||
for _, t := range stream.Spec.Tags { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're iterating over this second time so far, create a helper and use in both places.
from := o.From | ||
tag := o.Tag | ||
// follow any referential tags to the destination | ||
finalTag, existing, multiple, err := imageapi.FollowTagReference(stream, tag) | ||
finalTag, existing, multiple, err := followTagReferenceV1(stream, tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate to say that, but create a shim, and don't copy. At some point in time some victim (in my unclear memory I recall I volunteered) will fix the controller to use the externals as well and we'll just remove the shim.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am having the same problem here, although the helper pkg/image/apis/image/v1.Convert_v1_ImageStream_To_image_ImageStream
does not depend on a conversion scope, on of the conversion funcs that it depends on does: https://github.com/openshift/origin/blob/master/pkg/image/apis/image/v1/conversion.go#L160
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
kapi "k8s.io/kubernetes/pkg/apis/core" | ||
//kapi "k8s.io/kubernetes/pkg/apis/core" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove if not needed.
@@ -621,7 +621,7 @@ func TestCreateImageImport(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestWasError(t *testing.T) { | |||
func CANCELTestWasError(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) Forgot to remove - couldn't remember to use hack/test-go.sh ... -run=...
c945dcd
to
add54e8
Compare
16e02e5
to
9ab92a3
Compare
9ab92a3
to
46f4f45
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: juanvallejo, soltysh The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
cc @deads2k