-
Notifications
You must be signed in to change notification settings - Fork 373
annotations: Improve asset annotation handling #3031
Conversation
/test |
Minimal manual test (based on https://github.com/kata-containers/documentation/blob/master/Developer-Guide.md#running-standalone): $ bundle="/tmp/bundle"
$ rootfs="$bundle/rootfs"
$ mkdir -p "$rootfs" && (cd "$bundle" && kata-runtime spec)
$ sudo docker export $(sudo docker create busybox) | tar -C "$rootfs" -xvf -
$ (cd $bundle && jq '. |= . + {"annotations": {"io.katacontainers.config.hypervisor.path": "/does/not/exist"}}' < config.json > tmp && mv tmp config.json)
$ sudo kata-runtime --log=/dev/stdout run --bundle "$bundle" foo The above will work (incorrectly) with current releases, but will fail with this PR (assuming /cc @gkunz |
@jodh-intel thanks for the quick fix! I'll test this PR as well in my lab. |
Codecov Report
@@ Coverage Diff @@
## master #3031 +/- ##
==========================================
+ Coverage 50.25% 50.30% +0.05%
==========================================
Files 120 120
Lines 15844 15840 -4
==========================================
+ Hits 7963 7969 +6
+ Misses 6799 6786 -13
- Partials 1082 1085 +3 |
@GabyCT -
|
virtcontainers/pkg/oci/utils.go
Outdated
vcAnnotations.KernelPath, | ||
vcAnnotations.ImagePath, | ||
vcAnnotations.InitrdPath, | ||
vcAnnotations.AssetHashType, |
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.
are you not missing vcAnnotations.HypervisorPath
here? In my local test of this PR, the hypervisor annotations still gets ignored. Upon including vcAnnotations.HypervisorPath
here, it works.
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.
@gkunz - apologies - git stash
fail :) I've actually found a way to make the code more robust, so marking as do-not-merge for now. I'll push an update tomorrow...
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.
@jodh-intel no problem. Thanks again for addressing the issue so quickly!
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.
thanks @jodh-intel
Improve formatting, grammar and whitespace. Signed-off-by: James O. D. Hunt <[email protected]>
Add missing annotation definitions for a hypervisor control binary: - `io.katacontainers.config.hypervisor.ctlpath` - `io.katacontainers.config.hypervisor.hypervisorctl_hash` Signed-off-by: James O. D. Hunt <[email protected]>
a8df626
to
935e607
Compare
/test |
935e607
to
d1db6aa
Compare
/test |
virtcontainers/hypervisor.go
Outdated
// We could not find a custom asset for the given type, let's | ||
// fall back to the configured ones. | ||
switch t { | ||
case types.KernelAsset: | ||
return conf.KernelPath, nil | ||
case types.ImageAsset: | ||
return conf.ImagePath, nil | ||
case types.InitrdAsset: | ||
return conf.InitrdPath, nil | ||
case types.HypervisorAsset: | ||
return conf.HypervisorPath, nil | ||
case types.HypervisorCtlAsset: | ||
return conf.HypervisorCtlPath, nil | ||
case types.JailerAsset: | ||
return conf.JailerPath, nil | ||
case types.FirmwareAsset: | ||
return conf.FirmwarePath, nil | ||
default: | ||
return "", fmt.Errorf("Unknown asset type %v", t) | ||
assetPath, _, err := t.Annotations() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return assetPath, 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.
This is incorrect as it changes the function to return the asset annotation name, not the config value. I'm about to push a fix and a new TestAssetPath()
test to assert the expected behaviour. However, I'm going to have to revert this change meaning we will still have a "list of asset annotations" outside of asset.go
. This is annoying as I'd like to totally encapsulate that list in asset.go
.
One possible improvement would be to annotate HypervisorConfig
with custom struct tags like this:
type HypervisorConfig struct {
FirmwarePath string `annotation:"io.katacontainers.config.hypervisor.firmware"`
HypervisorCtlPath string `annotation:"io.katacontainers.config.hypervisor.ctlpath"`
HypervisorPath string `annotation:"io.katacontainers.config.hypervisor.path"`
ImagePath string `annotation:"io.katacontainers.config.hypervisor.image"`
InitrdPath string `annotation:"io.katacontainers.config.hypervisor.initrd"`
JailerPath string `annotation:"io.katacontainers.config.hypervisor.jailer_path"`
KernelPath string `annotation:"io.katacontainers.config.hypervisor.kernel"`
}
That may make the code clearer and less error prone. However, there would be a runtime impact as we'd need to use reflect
to map the struct tag (annotation) back to the config value.
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.
@jodh-intel I like the idea of encapsulating all the assets constants and logic in assets.go, feel that it is all over the place right now. Maybe using reflection is not such a bad idea if we can cleanup the code and make sure that we do this once in the CreateSandbox code path.
We can address that in a separate PR.
What I did see is that the hypervisor.go has a lot of functions CustomFirmwareAsset
, CustomJailerAsset
etc which are not being called at all.
We need to assess if these functions should be called from getHypervisorDetails
or we can just get rid of them.
d1db6aa
to
6a31139
Compare
/test |
HI @gkunz - I've updated the branch now if you'd like to give the latest a try? |
@jodh-intel works nicely for me! |
Thanks for confirming @gkunz ! |
Added dnm label to allow for a few more eyes to review before this lands. |
@amshinde - any further thoughts on this? I've updated since you approved I think. |
virtcontainers/types/asset.go
Outdated
} | ||
|
||
// Add the odd one out; it isn't part of a (path+hash) pair. | ||
result = append(result, annotations.AssetHashType) |
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 dont need to address this in this PR.
But raising my concern about value of supporting this. Maybe we should just support sha512 hash and document it so, rather than providing 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.
Fixed.
// AssetTypes returns a list of all known asset types. | ||
// | ||
// XXX: New asset types *MUST* be added here. | ||
func AssetTypes() []AssetType { |
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: Suggestion to move all the consts for FirmwareAsset, HypervisorAsset etc to the top of the file for better readability.
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.
Fixed.
JailerAsset, | ||
KernelAsset, | ||
} | ||
} |
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.
In terms of cleanup, there is another function called Valid()
which could make use of this list instead of comparing against individual values.
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.
Fixed.
virtcontainers/hypervisor.go
Outdated
// We could not find a custom asset for the given type, let's | ||
// fall back to the configured ones. | ||
switch t { | ||
case types.KernelAsset: | ||
return conf.KernelPath, nil | ||
case types.ImageAsset: | ||
return conf.ImagePath, nil | ||
case types.InitrdAsset: | ||
return conf.InitrdPath, nil | ||
case types.HypervisorAsset: | ||
return conf.HypervisorPath, nil | ||
case types.HypervisorCtlAsset: | ||
return conf.HypervisorCtlPath, nil | ||
case types.JailerAsset: | ||
return conf.JailerPath, nil | ||
case types.FirmwareAsset: | ||
return conf.FirmwarePath, nil | ||
default: | ||
return "", fmt.Errorf("Unknown asset type %v", t) | ||
assetPath, _, err := t.Annotations() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return assetPath, 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.
@jodh-intel I like the idea of encapsulating all the assets constants and logic in assets.go, feel that it is all over the place right now. Maybe using reflection is not such a bad idea if we can cleanup the code and make sure that we do this once in the CreateSandbox code path.
We can address that in a separate PR.
What I did see is that the hypervisor.go has a lot of functions CustomFirmwareAsset
, CustomJailerAsset
etc which are not being called at all.
We need to assess if these functions should be called from getHypervisorDetails
or we can just get rid of them.
9f1c7e9
to
0f8b94b
Compare
@amshinde - I've removed the unused functions. On reflection (:smile:), I'm not totally convinced about my reflection idea: there Let's ponder this some more and make further improvements if possible on a follow-up PR. For now, I'd like to get this landed so it can be ported to 2.x. |
/test |
Agree. SGTM. |
Make `asset.go` the arbiter of asset annotations by removing all asset annotations lists from other parts of the codebase. This makes the code simpler, easier to maintain, and more robust. Specifically, the previous behaviour was inconsistent as the following ways: - `createAssets()` in `sandbox.go` was not handling the following asset annotations: - firmware: - `io.katacontainers.config.hypervisor.firmware` - `io.katacontainers.config.hypervisor.firmware_hash` - hypervisor: - `io.katacontainers.config.hypervisor.path` - `io.katacontainers.config.hypervisor.hypervisor_hash` - hypervisor control binary: - `io.katacontainers.config.hypervisor.ctlpath` - `io.katacontainers.config.hypervisor.hypervisorctl_hash` - jailer: - `io.katacontainers.config.hypervisor.jailer_path` - `io.katacontainers.config.hypervisor.jailer_hash` - `addAssetAnnotations()` in the `oci` package was not handling the following asset annotations: - hypervisor: - `io.katacontainers.config.hypervisor.path` - `io.katacontainers.config.hypervisor.hypervisor_hash` - hypervisor control binary: - `io.katacontainers.config.hypervisor.ctlpath` - `io.katacontainers.config.hypervisor.hypervisorctl_hash` - jailer: - `io.katacontainers.config.hypervisor.jailer_path` - `io.katacontainers.config.hypervisor.jailer_hash` This change fixes the bug where specifying a custom hypervisor path via an asset annotation was having no effect. Fixes: kata-containers#3030. Signed-off-by: James O. D. Hunt <[email protected]>
Deleted `HypervisorConfig`'s unused `CustomFirmwareAsset()` and `JailerAssetPath()` methods. Signed-off-by: James O. D. Hunt <[email protected]>
0f8b94b
to
4ce09fb
Compare
/test |
forward port PR: kata-containers/kata-containers#1086 |
The changes introduced in PR kata-containers#3031 require additional changes. Code lifted from kata-containers/kata-containers#1086. Fixes: kata-containers#3005 Suggested-by: James O.D. Hunt <[email protected]> Signed-off-by: Christophe de Dinechin <[email protected]>
The changes introduced in PR kata-containers#3031 require additional changes. Code lifted from kata-containers/kata-containers#1086. Fixes: kata-containers#3005 Suggested-by: James O.D. Hunt <[email protected]> Signed-off-by: Christophe de Dinechin <[email protected]>
The changes introduced in PR kata-containers#3031 require additional changes. Code lifted from kata-containers/kata-containers#1086. Fixes: kata-containers#3005 Suggested-by: James O.D. Hunt <[email protected]> Signed-off-by: Christophe de Dinechin <[email protected]>
The changes introduced in PR kata-containers#3031 require additional changes. Code lifted from kata-containers/kata-containers#1086. Fixes: kata-containers#3005 Suggested-by: James O.D. Hunt <[email protected]> Signed-off-by: Christophe de Dinechin <[email protected]>
The changes introduced in PR kata-containers#3031 require additional changes. Code lifted from kata-containers/kata-containers#1086. Fixes: kata-containers#3005 Suggested-by: James O.D. Hunt <[email protected]> Signed-off-by: Christophe de Dinechin <[email protected]>
Make
asset.go
the arbiter of asset annotations by removing all assetannotations lists from other parts of the codebase.
This makes the code simpler, easier to maintain, and more robust.
Specifically, the previous behaviour was inconsistent as the following
ways:
createAssets()
insandbox.go
was not handling the following assetannotations:
firmware:
io.katacontainers.config.hypervisor.firmware
io.katacontainers.config.hypervisor.firmware_hash
hypervisor:
io.katacontainers.config.hypervisor.path
io.katacontainers.config.hypervisor.hypervisor_hash
hypervisor control binary:
io.katacontainers.config.hypervisor.ctlpath
io.katacontainers.config.hypervisor.hypervisorctl_hash
jailer:
io.katacontainers.config.hypervisor.jailer_path
io.katacontainers.config.hypervisor.jailer_hash
addAssetAnnotations()
in theoci
package was not handling thefollowing asset annotations:
hypervisor:
io.katacontainers.config.hypervisor.path
io.katacontainers.config.hypervisor.hypervisor_hash
hypervisor control binary:
io.katacontainers.config.hypervisor.ctlpath
io.katacontainers.config.hypervisor.hypervisorctl_hash
jailer:
io.katacontainers.config.hypervisor.jailer_path
io.katacontainers.config.hypervisor.jailer_hash
This change fixes the bug where specifying a custom hypervisor path via an
asset annotation was having no effect.
Fixes: #3030.
Signed-off-by: James O. D. Hunt [email protected]