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

Convert spec command for virtctl #189

Merged
merged 3 commits into from Apr 21, 2017
Merged

Convert spec command for virtctl #189

merged 3 commits into from Apr 21, 2017

Conversation

rmohr
Copy link
Member

@rmohr rmohr commented Apr 7, 2017

Three things missing:

  • The libvirt struct still depends on libvirt-go stuff
  • Tests
  • Documentation

Example usage:

Convert between Kubevirt and Libvirt VM representations:

Examples:
# Convert Domain xml to yaml via stdin
virsh dumpxml testvm | virtctl convert-spec -f - -o yaml

# Convert yaml into json from a http resource
virtctl convert-spec -f http://127.0.0.1:4012/vm.yaml -o json

# Convert VM specification from a yaml file into a Libvirt Domain XML
virtctl convert-spec -f vm.yaml -o xml > dom.xml

Options:
  -f, --filename string         Filename, directory, or URL to files identifying the resource to get from a server.
  -o, --output string           Output format. One of: json|yaml|xml. (default "json")
      --output-version string   Output the formatted object with the given group version (default "kubevirt.io/v1alpha1")

The input format is automatically detected.

@rmohr
Copy link
Member Author

rmohr commented Apr 7, 2017

/cc @fabiand @stu-gott @admiyo See above that it is not yet completely done, but the functionality is there and works.

Could you provide some feedback if the commandline arguments and the examples make sense in you eyes?

return buffer, b, hasXMLPrefix(b)
}

var xmlPrefix = []byte("<")
Copy link
Member

Choose a reason for hiding this comment

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

Is this truly sufficient?

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 it is good enough. Everything more than that would involve parsing the whole xml (basically a validation then, which will be done by the decoder later on)

} else if r, _, isJSON := yaml.GuessJSONStream(r, size); isJSON {
return r, JSON
} else {
return r, YAML
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to explicitly test for yaml rather than assuming at this point?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really. For JSON, YAML and XML, we can just guess in every case. For JSON "{" (definitely not xml or yaml", for XML "<" (definitely not yaml or json).

If both don't match, I take the only possible left solution which will then later on fail when it is parsed.

"unicode"
)

func GuessStreamType(source io.Reader, size int) (io.Reader, Type) {
Copy link
Member

Choose a reason for hiding this comment

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

This function signature should probably also include an error code. For example there might be parse errors, or the stream doesn't match anything we know.

Copy link
Member Author

@rmohr rmohr Apr 7, 2017

Choose a reason for hiding this comment

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

My assumption is, that the conversion later on will fail, if we have an unsupported format. I will think about it a little bit more.

return resp.Body, nil

} else {
return os.Open(sourceName)
Copy link
Member

Choose a reason for hiding this comment

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

Open returns (*File, error), is *File also a io.ReadCloser?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

@fabiand
Copy link
Member

fabiand commented Apr 7, 2017

/cc @michalskrivanek @mpolednik

@rmohr rmohr mentioned this pull request Apr 10, 2017
6 tasks
To make sure, we don't depend on anything from libvirt-go we have to
move the xml struct into a separate package. If we depend  on
libvirt-go, virtctl would required libvirt-client to be installed.
@michalskrivanek
Copy link

@rmohr why don't you want to depend on libvirt-go?

@rmohr
Copy link
Member Author

rmohr commented Apr 10, 2017

@rmohr why don't you want to depend on libvirt-go?

@michalskrivanek In the backend we do. virtctl is just a frontend commandline tool. If we would depend anywhere there directly on libvirt-go code, golang would link against the libvirt C library. We don't need anything from libvirt-go in this frontend.

@michalskrivanek
Copy link

ah, sure, thanks for clarification

@rmohr rmohr changed the title [WIP] Converter [skip ci] Convert spec command for virtctl Apr 10, 2017
@rmohr
Copy link
Member Author

rmohr commented Apr 10, 2017

Ready for review

Copy link
Member

@stu-gott stu-gott left a comment

Choose a reason for hiding this comment

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

Minor nits only. Looks good!

.travis.yml Outdated
- 1.6.3
- 1.7.x
- 1.7.5
- 1.8.x
Copy link
Member

Choose a reason for hiding this comment

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

Trailing whitespace


Basic Commands:
console Connect to a serial console on a VM
convert-spec Convert between Libvirt and Kubevirt specifications
Copy link
Member

Choose a reason for hiding this comment

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

KubeVirt, right?

}

func (c *Convert) Usage() string {
usage := "Convert between Kubevirt and Libvirt VM representations:\n\n"
Copy link
Member

Choose a reason for hiding this comment

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

KubeVirt


if sourceName == "" {
log.Println("No source specified")
return 1
Copy link
Member

Choose a reason for hiding this comment

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

It might be more clear if we create enums at the top of the module along the lines of "RuntimeSuccess" and "RuntimeError"

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's return an error or nil instead, how about that?

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 would do that in a separate PR, since it is an interface change for all virtcl commands ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Anyway, your suggestion is good. Done.

)

var _ = Describe("Guess", func() {
table.DescribeTable("Should detect stram type", func(data string, detected Type) {
Copy link
Member

Choose a reason for hiding this comment

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

"stream type"

@stu-gott
Copy link
Member

retest this please

@rmohr rmohr merged commit 13a495b into kubevirt:master Apr 21, 2017
kubevirt-bot pushed a commit to kubevirt-bot/kubevirt that referenced this pull request Nov 6, 2020
mzzgaopeng pushed a commit to mzzgaopeng/kubevirt that referenced this pull request Mar 8, 2021
Remove reference to policy on accepting PRs
kubevirt-bot pushed a commit to kubevirt-bot/kubevirt that referenced this pull request Dec 7, 2021
We need special treatment to make OKD clusters working with
the `pack8s` helper.
Differently from docker, we can't just call podman, because
we can be running with an user != root. In that case, the
copy step will fail. Hence, we use a special new command
in pack8s to do the copy on our behalf.

Signed-off-by: Karel Šimon <ksimon@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants