Skip to content

fix newapp resource convert for extensions and apps groups #15787

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

Conversation

juanvallejo
Copy link
Contributor

@juanvallejo juanvallejo commented Aug 15, 2017

Fixes #15783

Before

$ oc new-app -f examples/prometheus/prometheus.yaml -o yaml
error: extensions.Deployment is not suitable for converting to ""

After

$ oc new-app -f examples/prometheus/prometheus.yaml -o yaml | head
apiVersion: v1
items:
- apiVersion: v1
  kind: ServiceAccount
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftNewApp
      serviceaccounts.openshift.io/oauth-redirectreference.primary: '{"kind":"OAuthRedirectReference","apiVersion":"v1","reference":{"kind":"Route","name":"prometheus"}}'
    creationTimestamp: null
    name: prometheus

cc @fabianofranz @smarterclayton

@openshift-merge-robot openshift-merge-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 15, 2017
// if no preferred version found in the list of given GroupVersions,
// attempt to convert to first GroupVersion that satisfies a preferred version
if len(actualOutputVersion.Version) == 0 {
for _, version := range preferredVersions {
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't even need to do this loop - you should be passing preferredVersions in to ConvertToVersion as a Versioner.

// the given object is guaranteed to be at least part of one group by this point.
if len(preferredVersions) == 0 {
defaultGroupVersion := groups[0].GroupVersion
convertedObject, err := kapi.Scheme.ConvertToVersion(obj, defaultGroupVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

You should just be passing in groupVersions to ConvertToVersion (you'll need to cast to the runtime schema type which handles Versioner).

@smarterclayton
Copy link
Contributor

Tests.

@openshift-merge-robot openshift-merge-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 16, 2017
@juanvallejo
Copy link
Contributor Author

/test extended_templates
/test extended_conformance_gce

@juanvallejo
Copy link
Contributor Author

/test extended_conformance_gce

@juanvallejo
Copy link
Contributor Author

@smarterclayton thanks for the feedback, review comments addressed

os::cmd::expect_success_and_text 'oc new-app -f examples/prometheus/prometheus.yaml -o yaml' 'apiVersion: apps/v1beta1'
# check that if an --output-version is requested on a list of varying resource kinds, an error is returned if
# at least one of the resource groups does not support the given version
os::cmd::expect_failure_and_text 'oc new-app -f examples/prometheus/prometheus.yaml -o yaml --output-version=v1' 'extensions.Deployment is not suitable for converting'
Copy link
Member

Choose a reason for hiding this comment

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

Minor comment, make it more defensive against future changes by just checking "not suitable for converting".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@juanvallejo juanvallejo force-pushed the jvallejo/update-cmdutil-resource-convert branch from 338aad1 to b9be10f Compare August 18, 2017 19:08
@fabianofranz
Copy link
Member

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 18, 2017
@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 18, 2017
@juanvallejo juanvallejo force-pushed the jvallejo/update-cmdutil-resource-convert branch from b9be10f to 385da29 Compare August 18, 2017 20:29
@openshift-merge-robot openshift-merge-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 18, 2017
@juanvallejo juanvallejo force-pushed the jvallejo/update-cmdutil-resource-convert branch from 385da29 to 2f39e7f Compare August 18, 2017 20:29
@juanvallejo juanvallejo force-pushed the jvallejo/update-cmdutil-resource-convert branch from 2f39e7f to d065082 Compare August 18, 2017 20:31
@juanvallejo
Copy link
Contributor Author

@fabianofranz

Minor comment, make it more defensive against future changes by just checking "not suitable for converting".

Since examples/prometheus/prometheus.yaml contains multiple resources of different group versions, any time I test the --output-version flag I will get at least one resource that is incompatible with the user-supplied version (e.g. --output-version=extensions/v1beta1 would not be compatible with api.Secret). I have gone ahead and created a new test file that only deals with two specific resources (api.Secret, and extensions.Deployment) in order to check for the specific resource in the tests.

@juanvallejo
Copy link
Contributor Author

/test unit

@fabianofranz
Copy link
Member

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 21, 2017
@smarterclayton
Copy link
Contributor

smarterclayton commented Aug 23, 2017 via email

@openshift-merge-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabianofranz, juanvallejo, smarterclayton

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 23, 2017
@openshift-merge-robot
Copy link
Contributor

/test all [submit-queue is verifying that this PR is safe to merge]

@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue

@openshift-merge-robot openshift-merge-robot merged commit c1e9505 into openshift:master Aug 23, 2017
@juanvallejo juanvallejo deleted the jvallejo/update-cmdutil-resource-convert branch August 23, 2017 13:50
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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants