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

externalize migration commands #20927

Conversation

juanvallejo
Copy link
Contributor

Updates migration commands to use external clients and object versions.

cc @soltysh @deads2k @enj

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 10, 2018
@juanvallejo
Copy link
Contributor Author

/assign soltysh enj

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

A few nits when you'll be fixing the tests.

@@ -75,17 +73,14 @@ var (
type MigrateImageReferenceOptions struct {
migrate.ResourceOptions

Client imagetypedclient.ImageStreamsGetter
Client imagev1typedclient.ImageStreamsGetter
Mappings ImageReferenceMappings
UpdatePodSpecFn func(obj runtime.Object, fn func(*corev1.PodSpec) error) (bool, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

polymorphichelpers.UpdatePodSpecForObjectFunc

obj, err := legacyscheme.Scheme.ConvertToVersion(info.Object, info.Mapping.GroupVersionKind.GroupVersion())
if err != nil {
return err
}
// TODO: PrintObj is not correct for YAML - it should inject document separators itself
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it all still needed, isn't our new printing stack capable of handling these?

Copy link
Contributor Author

@juanvallejo juanvallejo Sep 11, 2018

Choose a reason for hiding this comment

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

The new printing stack only handles api lists correctly when printing yaml or json. The yaml printer cannot know to print --- after every yaml object that it prints without keeping state or just printing --- every time its PrintObj method is called.

I am not a fan of having a yaml printer that knows about the last object that was printed, and I think expecting consumers of the printer to pass an api list is reasonable.

@soltysh
Copy link
Contributor

soltysh commented Sep 11, 2018

/approve

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 11, 2018
@juanvallejo juanvallejo force-pushed the jvallejo/externalize-migrate-cmds branch from 42c1d5c to 684272e Compare September 11, 2018 21:51
@juanvallejo
Copy link
Contributor Author

@soltysh thanks for the review, comments addressed

Copy link
Contributor

@enj enj left a comment

Choose a reason for hiding this comment

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

Some questions.

@@ -135,6 +138,38 @@ type ResourceOptions struct {
genericclioptions.IOStreams
}

func NewResourceOptions(streams genericclioptions.IOStreams) *ResourceOptions {
return &ResourceOptions{
PrintFlags: genericclioptions.NewPrintFlags("migrated").WithTypeSetter(scheme.Scheme),
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

New printing stack. We have been pushing the use of a single code-path (this one) to print anything in the cli. The genericclioptions package was recently moved to its own repo upstream (k8s.io/cli-runtime) which means that oc will become a primary consumer of that package.

The main gist behind the new printing stack is that it requires all consumers to pass it external objects only. It also enforces additional metadata for each object that it receives, so that anything that is printed to the user is displayed accurately, and in a format consumable by other oc commands. We start out with a struct that the command can use to bind all printing-related flags at once. Then from that struct, use flag values provided by the user to generate the appropriate printer.

The type-setter is temporary, but for now it allows us to attempt to retrieve the gvk for runtime.Objects that may not have it set.


usage := "Filename, directory, or URL to docker-compose.yml file to use"
kcmdutil.AddJsonFilenameFlag(c.Flags(), &o.Filenames, usage)
}

func (o *ResourceOptions) Complete(f kcmdutil.Factory, c *cobra.Command) error {
o.Output = kcmdutil.GetFlagString(c, "output")

if o.DryRun {
o.PrintFlags.Complete("%s (dry run)")
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This looks weird to me as well, but it is the current solution that we have in place for generating dry-run messages.

By default, if no --output argument is supplied by a user, the printing stack's ToPrinter() method returns a success-message printer, which as the name implies, prints a successful message (such as pod/foo-bar successfully deleted or something similar). In the case of a dry-run for the command, the only way to currently note that in a successful output (using the printing stack) is to go through the flags' Complete method.

@@ -310,7 +345,7 @@ func (o *ResourceOptions) Complete(f kcmdutil.Factory, c *cobra.Command) error {
if o.Unstructured {
o.Builder.Unstructured()
} else {
o.Builder.WithScheme(ocscheme.ReadingInternalScheme)
o.Builder.WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...)
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope this is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this scheme contains our resources + kubectl resources. We have been using it to prioritize getting external, grouped resources across commands here and upstream

@@ -267,13 +263,11 @@ func (o *MigrateAPIStorageOptions) Complete(f kcmdutil.Factory, c *cobra.Command
clientConfigCopy.Burst = 99999
clientConfigCopy.QPS = 99999

client, err := dynamic.NewForConfig(clientConfigCopy)
o.client, err = dynamic.NewForConfig(clientConfigCopy)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ew.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

?
We were setting the client a few lines below. Figured it was cleaner to assign it directly

Copy link
Contributor

Choose a reason for hiding this comment

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

I am just not a fan of that pattern.

Copy link
Contributor

Choose a reason for hiding this comment

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

@enj what's wrong with it? Why would you prefer setting a temporary variable and then assign it to a struct member instead of direct assignment? I'm curious.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feels weird to me to set a struct member before first checking the error. But it is really just a preference.

@juanvallejo juanvallejo force-pushed the jvallejo/externalize-migrate-cmds branch from 684272e to 21bf987 Compare September 12, 2018 22:48
@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 12, 2018
@juanvallejo
Copy link
Contributor Author

/test gcp

@enj
Copy link
Contributor

enj commented Sep 13, 2018

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 13, 2018
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: enj, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit bbc3ca5 into openshift:master Sep 13, 2018
@juanvallejo juanvallejo deleted the jvallejo/externalize-migrate-cmds branch September 13, 2018 17:24
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants