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
Conversation
return buffer, b, hasXMLPrefix(b) | ||
} | ||
|
||
var xmlPrefix = []byte("<") |
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.
Is this truly sufficient?
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 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 |
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.
Is it possible to explicitly test for yaml rather than assuming at this point?
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.
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.
pkg/virtctl/convert/guess.go
Outdated
"unicode" | ||
) | ||
|
||
func GuessStreamType(source io.Reader, size int) (io.Reader, Type) { |
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.
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.
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.
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) |
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.
Open returns (*File, error), is *File also a io.ReadCloser?
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.
Yes.
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.
@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. |
ah, sure, thanks for clarification |
Ready for review |
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.
Minor nits only. Looks good!
.travis.yml
Outdated
- 1.6.3 | ||
- 1.7.x | ||
- 1.7.5 | ||
- 1.8.x |
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.
Trailing whitespace
cmd/virtctl/virtctl.go
Outdated
|
||
Basic Commands: | ||
console Connect to a serial console on a VM | ||
convert-spec Convert between Libvirt and Kubevirt specifications |
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.
KubeVirt, right?
pkg/virtctl/convert/convert.go
Outdated
} | ||
|
||
func (c *Convert) Usage() string { | ||
usage := "Convert between Kubevirt and Libvirt VM representations:\n\n" |
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.
KubeVirt
pkg/virtctl/convert/convert.go
Outdated
|
||
if sourceName == "" { | ||
log.Println("No source specified") | ||
return 1 |
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.
It might be more clear if we create enums at the top of the module along the lines of "RuntimeSuccess" and "RuntimeError"
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.
Let's return an error or nil instead, how about that?
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 would do that in a separate PR, since it is an interface change for all virtcl commands ...
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.
Anyway, your suggestion is good. Done.
pkg/virtctl/convert/guess_test.go
Outdated
) | ||
|
||
var _ = Describe("Guess", func() { | ||
table.DescribeTable("Should detect stram type", func(data string, detected Type) { |
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.
"stream type"
retest this please |
DataVolume CRD
Remove reference to policy on accepting PRs
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>
Three things missing:The libvirt struct still depends on libvirt-go stuffTestsDocumentationExample usage:
The input format is automatically detected.