Skip to content
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

IR-260: Add CLI flag to set ImportMode when importing a tag #1289

Merged
merged 5 commits into from
Jan 13, 2023
Merged

Conversation

dorzel
Copy link
Member

@dorzel dorzel commented Nov 14, 2022

issues.redhat.com/browse/IR-260

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 14, 2022
@dorzel dorzel marked this pull request as draft November 14, 2022 22:42
@dorzel dorzel changed the title WIP IR-260: Add CLI flag to set ImportMode when importing a tag IR-260: Add CLI flag to set ImportMode when importing a tag Jan 3, 2023
@dorzel dorzel marked this pull request as ready for review January 3, 2023 19:29
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 3, 2023
Copy link
Member

@flavianmissi flavianmissi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to validate the user input against the known values for the import mode (before we hit the server). Something like what we do here for the ReferencePolicy.
WDYT?

@dorzel
Copy link
Member Author

dorzel commented Jan 5, 2023

It would be nice to validate the user input against the known values for the import mode (before we hit the server). Something like what we do here for the ReferencePolicy. WDYT?

I think that makes sense to do, added a commit

@flavianmissi
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 9, 2023
ImportMode: imagev1.ImportModeLegacy,
},
}},
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a test case also for valid ImportMode values are %s or %s error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the test case in a new commit. I realized the test cases weren't running the validation step, so I've also added that step along with related error checking.

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2023
Copy link
Member

@ardaguclu ardaguclu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few non-blocker comments. After that I'll tag the PR. Thanks.

switch o.ImportMode {
case string(imagev1.ImportModeLegacy):
case string(imagev1.ImportModePreserveOriginal):
case "":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to this assignment, there is no problem. But would it be better to set ImportMode to Legacy in this initialization

ReferencePolicy: tag.SourceReferencePolicy,
like we do for ReferencePolicy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would seem to be the better place, but this is also done for ReferencePolicy just above. I'm wondering if this is needed for either of these.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it seems this assignment is needed here regardless in the specific case that the user specifies --reference-policy="" or --import-mode="".

if err := o.parseImageReference(); err != nil {
t.Errorf("unexpected error: %v", err)
continue
}

if err := o.Validate(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for handling this missing bit. Would it be better to handle the case where validate returns no error but test expects(also a trivial modification by discarding continue statements).
I mean something like this;

if err := o.Validate(); err != nil {
    if len(test.err) == 0 || !strings.Contains(err.Error(), test.err) { 
         t.Errorf("unexpected error %v", err)
    }
} else {
    if len(test.error) > 0 {
         t.Errorf("error expected but not get")
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense. I've tweaked it a bit as retaining the behavior of continue is needed if there is a validation error so that the import object doesn't actually get created in the test. This makes it clearer what actually failed and emulates the actual behavior better. The general "unexpected error" case is already handled below.

// set default for referencePolicy
if len(test.referencePolicy) == 0 {
for i := range test.expectedImages {
test.expectedImages[i].ReferencePolicy.Type = imagev1.SourceTagReferencePolicy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, these expected fields should be immutable. Wouldn't it be better to set them in their initializations instead in here?. Is there any reason for doing these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main reason for doing this here was to emulate the behavior of the user not needing to specify the default for it to be set, as it does when working with oc. These needed to be set because the Validate() step ends up mutating the ImportOptions object. But it would be nicer to not have to change the expected fields ever.

@dorzel
Copy link
Member Author

dorzel commented Jan 12, 2023

/retest

1 similar comment
@flavianmissi
Copy link
Member

/retest

@ardaguclu
Copy link
Member

/approve

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 13, 2023
@flavianmissi
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 13, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ardaguclu, dorzel, flavianmissi

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit b9830af into openshift:master Jan 13, 2023
@dorzel dorzel deleted the IR-260 branch January 13, 2023 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants