-
Notifications
You must be signed in to change notification settings - Fork 290
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
Add calicoctl convert command for manifest offline conversions #1782
Conversation
a41c635
to
9043fa8
Compare
calicoctl/commands/convert.go
Outdated
|
||
|
||
Description: | ||
Convert config files between different API versions. Both YAML and JSON formats are accepted. |
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.
between different implies this is more flexible than it is. I think it's just that it converts v1 manifests to v3.
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.
👍
calicoctl/commands/convert.go
Outdated
} | ||
} | ||
|
||
func convertResource(v1resource unversioned.Resource) (runtime.Object, error) { |
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.
missing a fn description. Perhaps should make clear it's converting v1 to v3.
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.
:
calicoctl/commands/convert.go
Outdated
} | ||
} | ||
|
||
func convert(convRes conversion.Converter, v1resource unversioned.Resource) (conversion.Resource, error) { |
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.
missing a fn description.
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 sure you gain much from this extra method, other than making it difficult to explain the difference between convertResource() and convert().
I'm not too fussed if this stays as it is, but another way to structure this would be to have the resource-specific switch statement select a converter to use and then just join two methods together, or have a method that returns the converter for a specific resource type (which is easier to explain than the subtle different between convertResource and convert).
Anyways, it's a nit and I'm talking more than I should.
if err != nil { | ||
return nil, err | ||
} | ||
|
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.
We should probably validate the final result resource too. WDYT?
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 would be a good idea, that would catch some of the problems I've seen in testing when taking converted data and applying it.
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.
hmmm, not sure if it makes sense to fail validation on something that user can't control, I'd say it's better to fail when a user tries to apply the config. Failing validation on the config we generated seems a bit weird (from the UX PoV)
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.
Agree with @gunjan5 on this - our bad v3 manifest will be caught when the user applies it. As G5 mentions, there's nothing the user can do about our botched conversion (other than edit and try to apply again).
calicoctl/commands/convert.go
Outdated
rp = nil | ||
} | ||
|
||
if rp == nil { |
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.
nit: can the following two lines just be put in the default: branch above and then we can do away with this if statement.
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.
👍
calicoctl/commands/convert.go
Outdated
|
||
err = rp.print(nil, results) | ||
if err != nil { | ||
fmt.Println(err) |
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.
should exit with non-zero RC here.
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.
Some really minor feedback - but otherwise this looks good.
Please add STs :) |
I've got a PR against gunjan's branch gunjan5#2 to add some STs for this. |
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.
a few nits, overall looks quite good.
calicoctl/commands/convert.go
Outdated
[--output=<OUTPUT>] | ||
|
||
Examples: | ||
# Create a policy using the data in policy.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.
Prefer "convert" to "create" here. Something like: "Convert the contents of policy.yaml to v3 policy."
calicoctl/commands/convert.go
Outdated
# Create a policy using the data in policy.yaml. | ||
calicoctl convert -f ./policy.yaml -o yaml | ||
|
||
# Create a policy based on the JSON passed into stdin. |
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.
Probably "Create" -> "Convert"
calicoctl/commands/convert.go
Outdated
|
||
Options: | ||
-h --help Show this screen. | ||
-f --filename=<FILENAME> Filename to use to create the resource. If set to |
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.
nit, single space after period.
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.
hehe, i know i know i complain about this and now i have this in my code too. I guess blind copy paste :em
calicoctl/commands/convert.go
Outdated
|
||
|
||
Description: | ||
Convert config files between different API versions. Both YAML and JSON formats are accepted. |
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.
👍
calicoctl/commands/convert.go
Outdated
rp = nil | ||
} | ||
|
||
if rp == nil { |
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.
👍
calicoctl/commands/convert.go
Outdated
} | ||
} | ||
|
||
func convertResource(v1resource unversioned.Resource) (runtime.Object, error) { |
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.
:
if !ok { | ||
return nil, errors.New(fmt.Sprintf("Unknown resource type (%s) and/or version (%s)", tm.Kind, tm.APIVersion)) | ||
} | ||
log.Infof("Found resource helper: %s", rh) |
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.
debug level log?
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.
hmm I've used Info
to be consistent with the other calicoctl commands, but I think you're right, it/they should be debug
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.
o nvm i thought you were talking about the log.Infof("results: %+v", results)
line in convert.go
, but this makes more sense, I'll change it to debug
calicoctl/commands/convert.go
Outdated
Description: | ||
Convert config files between different API versions. Both YAML and JSON formats are accepted. | ||
|
||
The default output will be printed to stdout in YAML format. |
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.
suggest: "calicoctl sends YAML to standard output (stdout) by default."
"will be printed" is future tense/passive voice.
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 mostly copied the description from kubectl convert
command help to be consistent, I can change it if you like.
@robbrockbank @bcreane @tmjd @lwr20 I've added validation for the converted resources as well as a new |
050bd8d
to
e08dd2d
Compare
I assume we'll look into fixing the |
yeah it's hard to get rid of, we also print that with |
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.
lgtm, just one potential nit.
calicoctl/commands/convert.go
Outdated
|
||
|
||
Description: | ||
Convert config files from Calico V1 to V3 API versions. Both YAML and JSON formats are accepted. |
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.
nit: is it v[13] or V[13]? Thought the former ...
if err != nil { | ||
return nil, err | ||
} | ||
|
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.
Agree with @gunjan5 on this - our bad v3 manifest will be caught when the user applies it. As G5 mentions, there's nothing the user can do about our botched conversion (other than edit and try to apply again).
85a37e3
to
8c31bfb
Compare
Description
example multi-resource manifest conversion:
Original:
Conversion command:
Another example:
original yaml file:
conversion:
Todos
Release Note