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

mount node product_uuid and product_name in pod containers #2321

Closed
wants to merge 1 commit into from

Conversation

qinqon
Copy link
Contributor

@qinqon qinqon commented Jun 22, 2021

When pods are running at kind cluster their product_uuid and product_name is the same since the share the kernel vfs, this PR add a new mount to OCI spec to bind mount node's product_uuid and product_name into pod's containers.
This is the result

$ kubectl exec nginx-kind-worker cat /sys/class/dmi/id/product_uuid
053ba73c-3a24-4cfe-b7ca-5a938a4600d7
$ kubectl exec nginx-kind-worker2 cat /sys/class/dmi/id/product_uuid
db9f435b-0316-4f66-92a0-8d3632d6f69c

Closes ##2318

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 22, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: qinqon
To complete the pull request process, please assign amwat after the PR has been reviewed.
You can assign the PR to them by writing /assign @amwat in a comment when ready.

The full list of commands accepted by this bot can be found 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

@k8s-ci-robot
Copy link
Contributor

Hi @qinqon. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 22, 2021
@qinqon qinqon marked this pull request as ready for review June 22, 2021 10:40
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 22, 2021
@qinqon
Copy link
Contributor Author

qinqon commented Jun 22, 2021

/hold
not ready

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 22, 2021
Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

TIL base_runtime_spec. Neat!

images/base/Dockerfile Show resolved Hide resolved
@@ -144,6 +145,7 @@ RUN echo "Installing containerd ..." \
&& chmod 755 /usr/local/sbin/runc \
&& containerd --version \
&& runc --version \
&& ctr oci spec |jq '.mounts[.mounts | length] |= . + {"destination": "/sys/class/dmi/id/product_uuid", "source": "/proc/sys/kernel/random/uuid", "options": ["bind"]}'> /etc/containerd/cri-base.json \
Copy link
Member

Choose a reason for hiding this comment

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

Mount should be read only?
Why wouldn't we mount the file from the kind node instead of a random file per container?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

# base_runtime_spec is a file path to a JSON file with the OCI spec that will be used as the base spec that all
# container's are created from.
# Use containerd's `ctr oci spec > /etc/containerd/cri-base.json` to output initial spec file.
# Spec files are loaded at launch, so containerd daemon must be restarted on any changes to refresh default specs.
Copy link
Member

Choose a reason for hiding this comment

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

We only need to justify why were are setting this, we can leave the rest to the upstream docs without repeating all of it here. We can also see what we're doing in the referenced file in the other sources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@qinqon
Copy link
Contributor Author

qinqon commented Jun 23, 2021

@BenTheElder I have move to the entrypoint the modification of OCI spec so we can do like other product_uuid https://github.com/kubernetes-sigs/kind/compare/b31b3842d57c6e712eb2332baafeb58e7e23ca3f..e196b8abd76be173bdb277665034edaccfb20ebc

But I was not able to do it for the virtual one, since /sys/device is mounted read only.

Jun 23 13:54:29 kind-control-plane containerd[238]: time="2021-06-23T13:54:29.230084841Z" level=error msg="StartContainer for \"262a111c5a5efe56fd2b57a1b07f737b646852ffa7074836021d94fc18612f8b\" failed" error="failed to create containerd task: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting \"/kind/product_uuid\" to rootfs at \"/sys/device/virtual/dmi/id/product_uuid\" caused: mkdir /run/containerd/io.containerd.runtime.v2.task/k8s.io/262a111c5a5efe56fd2b57a1b07f737b646852ffa7074836021d94fc18612f8b/rootfs/sys/device: read-only file system: unknown"

fi
if [[ -f /sys/devices/virtual/dmi/id/product_uuid ]]; then
echo 'INFO: faking /sys/devices/virtual/dmi/id/product_uuid as well' >&2
mount -o ro,bind /kind/product_uuid /sys/devices/virtual/dmi/id/product_uuid
#cat <<< "$(jq '.mounts[.mounts | length] |= . + {"destination": "/sys/device/virtual/dmi/id/product_uuid", "source": "/kind/product_uuid", "options": ["ro", "bind"]}' < /etc/containerd/cri-base.json)" > /etc/containerd/cri-base.json
Copy link
Member

Choose a reason for hiding this comment

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

remove commented code?
edit: or just fix the typo 😅 , see #2321 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ups.... fixed, thanks!

@BenTheElder
Copy link
Member

sorry, will get back to this tomorrow, I'm probably still the best person to review this but I've been a bit behind.

But I was not able to do it for the virtual one, since /sys/device is mounted read only.

I think the problem is actually just that it should be /sys/devices (plural) not /sys/device. Besides the existing reference in the entrypoint script, see the docs at https://man7.org/linux/man-pages/man5/sysfs.5.html 😅

@qinqon
Copy link
Contributor Author

qinqon commented Jun 25, 2021

The k8s conformance tests does not check product_uuid at pods right ?

@BenTheElder
Copy link
Member

The k8s conformance tests does not check product_uuid at pods right ?

not as far as I know, but some things try to read product_name as well (kubelet does, not the tests), we might also want to mount that while we're at it.

@qinqon
Copy link
Contributor Author

qinqon commented Jun 25, 2021

The k8s conformance tests does not check product_uuid at pods right ?

not as far as I know, but some things try to read product_name as well (kubelet does, not the tests), we might also want to mount that while we're at it.

I was thinking about adding some tests for this, but maybe it's not worth it, I can put in place an extra commit with product_name

I see product_name is "hacked" too

fix_product_name() {
# this is a small fix to hide the underlying hardware and fix issue #426
# https://github.com/kubernetes-sigs/kind/issues/426
if [[ -f /sys/class/dmi/id/product_name ]]; then
echo 'INFO: faking /sys/class/dmi/id/product_name to be "kind"' >&2
echo 'kind' > /kind/product_name
mount -o ro,bind /kind/product_name /sys/class/dmi/id/product_name
fi
}

UPDATE: Confirmed that product_name has the same issue

$ for pod in $(kubectl get pod -n kube-system -o wide  |grep kube-proxy |awk '{print $1}'); do kubectl exec -n kube-system $pod cat /sys/class/dmi/id/product_name /sys/devices/virtual/dmi/id/product_name ;done
20HGS22D0C
20HGS22D0C
20HGS22D0C
20HGS22D0C
20HGS22D0C
20HGS22D0C

20HGS22D0C is my laptop's product_name

UPDATE2:

The product_name at "nodes"

[ellorent@localhost images]$ docker exec kind-control-plane cat /sys/devices/virtual/dmi/id/product_name /sys/devices/virtual/dmi/id/product_name
kind
kind
[ellorent@localhost images]$ docker exec kind-worker  cat /sys/devices/virtual/dmi/id/product_name /sys/devices/virtual/dmi/id/product_name
kind
kind
[ellorent@localhost images]$ docker exec kind-worker2  cat /sys/devices/virtual/dmi/id/product_name /sys/devices/virtual/dmi/id/product_name
kind
kind

@qinqon
Copy link
Contributor Author

qinqon commented Jun 25, 2021

/hold cancel

working fine now:

$ for pod in $(kubectl get pod -n kube-system -o wide  |grep kube-proxy |awk '{print $1}'); do kubectl exec -n kube-system $pod cat /sys/class/dmi/id/product_uuid /sys/devices/virtual/dmi/id/product_uuid ;done
5fec4d4d-826c-4c5d-9ab4-eb7e811d2f47
5fec4d4d-826c-4c5d-9ab4-eb7e811d2f47
da43c828-f1e0-4ce4-a842-40b3d5a0d828
da43c828-f1e0-4ce4-a842-40b3d5a0d828
bddd0385-2f21-4335-9875-530e9a2deaae
bddd0385-2f21-4335-9875-530e9a2deaae

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 25, 2021
@BenTheElder BenTheElder changed the title Generate a random product_uuid at containerd mount node product_uuid in pod containers Jun 25, 2021
@BenTheElder
Copy link
Member

This should be better implemented in containerd rather than modifying OCI bundles

@AkihiroSuda what would you propose the abstraction be like?

OCI gets us close with "insert some additional standard mounts in the base config" but it seems we have contention?/performance issues if we don't do a file per container. I'm not sure what would be reasonable for suggesting containerd do this.

@AkihiroSuda
Copy link
Member

what would you propose the abstraction be like?

I was thinking that we could just have a new boolean like bind_mount_dmi_product in /etc/containerd/config.toml, but not a strong opinion.

But at least, let's avoid parsing JSON with sed.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 26, 2021
@qinqon
Copy link
Contributor Author

qinqon commented Sep 1, 2021

what would you propose the abstraction be like?

I was thinking that we could just have a new boolean like bind_mount_dmi_product in /etc/containerd/config.toml, but not a strong opinion.

But at least, let's avoid parsing JSON with sed.

Going back to installing jq at node containers and use it is ok ?

@AkihiroSuda
Copy link
Member

Going back to installing jq at node containers and use it is ok ?

Yes, SGTM (non-binding)

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 1, 2021
@qinqon
Copy link
Contributor Author

qinqon commented Sep 1, 2021

Going back to installing jq at node containers and use it is ok ?

Yes, SGTM (non-binding)

Added a commit with it, since jq is quite small It may be not an issue to keep it installed at the node container.

@qinqon
Copy link
Contributor Author

qinqon commented Sep 6, 2021

@AkihiroSuda, this is ready now with your suggestion.

@qinqon
Copy link
Contributor Author

qinqon commented Sep 10, 2021

@BenTheElder is this PR ok, or do it present any problem?

@aojea
Copy link
Contributor

aojea commented Sep 17, 2021

I'm fine with merging and iterating, the issue is legit #2318 and I think that we have explored all the possibles alternatives.
+1
Please squash and remove the commit for the custom images
Thanks

When pods are running at kind cluster their product_uuid and product_name
is the same since the share the kernel vfs,
this PR add a new mount to OCI spec to bind mount node's product_uuid
and product_name into pod's containers.

Signed-off-by: Quique Llorente <ellorent@redhat.com>
@qinqon
Copy link
Contributor Author

qinqon commented Sep 17, 2021

I'm fine with merging and iterating, the issue is legit #2318 and I think that we have explored all the possibles alternatives.
+1
Please squash and remove the commit for the custom images
Thanks

Done

@k8s-ci-robot
Copy link
Contributor

@qinqon: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Rerun command
pull-kind-e2e-kubernetes 9834db3 link /test pull-kind-e2e-kubernetes

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@aojea aojea mentioned this pull request Sep 18, 2021
@qinqon
Copy link
Contributor Author

qinqon commented Sep 22, 2021

Bum image blocked by docker/buildx#772

@aojea aojea added this to the v0.12.0 milestone Oct 8, 2021
@aojea
Copy link
Contributor

aojea commented Oct 8, 2021

This will go in this PR #2465 , with the base image bump
Thanks

@BenTheElder
Copy link
Member

rebased version merged in #2465, thank you!

ormergi added a commit to ormergi/kubevirtci that referenced this pull request Oct 20, 2021
The new KinD k8s-1.22 nodes includes a change [1] [2] that allows us
to stop using PodPresets and still support Kubevirt Live Migration.

[1] kubernetes-sigs/kind#2465
[2] kubernetes-sigs/kind#2321

Signed-off-by: Or Mergi <ormergi@redhat.com>
ormergi added a commit to ormergi/kubevirtci that referenced this pull request Oct 20, 2021
The new KinD k8s-1.22 nodes includes a change [1] [2] that allows us
to stop using PodPresets and still support Kubevirt Live Migration.

[1] kubernetes-sigs/kind#2465
[2] kubernetes-sigs/kind#2321

Signed-off-by: Or Mergi <ormergi@redhat.com>
kubevirt-bot pushed a commit to kubevirt/kubevirtci that referenced this pull request Oct 21, 2021
The new KinD k8s-1.22 nodes includes a change [1] [2] that allows us
to stop using PodPresets and still support Kubevirt Live Migration.

[1] kubernetes-sigs/kind#2465
[2] kubernetes-sigs/kind#2321

Signed-off-by: Or Mergi <ormergi@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants