-
Notifications
You must be signed in to change notification settings - Fork 97
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 a doc for prefetchfiles-nri-plugin #524
Conversation
docs/prefetchfiles-nri-plugin.md
Outdated
@@ -0,0 +1,156 @@ | |||
# User self-defined nydus image files prefetch | |||
To improve the flexibility of nydus image files prefetch, for the k8s scenario, we can specify a prefetch files list when create a nydus daemon. The prefetch files list is user self-defined. Nydus-snapshotter has implemented a containerd NRI plugin to transmit the path of prefetch files list to nydus-snapshotter. The prefetch plugin requires NRI 2.0, which is available in containerd (>=v1.7.0). The prefetch plugin subscribes pod creation event, fetches the path of prefetch files list and forwards it to nydus-snapshotter. Then when `nydusd` starts, it will pull the files defined in the prefetch files list through lazy loading. This allows the pull of the prefetch files to be done during container creation rather than image convert, improving the flexibility of file prefetching. |
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.
Do you mean "the list of prefetch file paths"?
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 for your comment. What is saved in the prefetch file is indeed the list of prefetch file paths. But the --prefetch-files parameter of nydusd needs to specify a path that points to the file containing the prefetch files (maybe a txt file). So I mean the path of prefetch files list, which is the actual parameter of --prefetch-files
docs/prefetchfiles-nri-plugin.md
Outdated
## Workflow | ||
|
||
1. Add information such as image reference and prefetch list path to annotations in pod configuration file. | ||
2. Run the prefetch plugin to monitoring RunPodSandbox events. |
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.
Bad syntax, should be "to monitor"
docs/prefetchfiles-nri-plugin.md
Outdated
|
||
1. Add information such as image reference and prefetch list path to annotations in pod configuration file. | ||
2. Run the prefetch plugin to monitoring RunPodSandbox events. | ||
3. The prefetch plugin fetches image reference and prefetch files path and forwards them to nydus-snapshotter. |
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.
file paths
docs/prefetchfiles-nri-plugin.md
Outdated
3. The prefetch plugin fetches image reference and prefetch files path and forwards them to nydus-snapshotter. | ||
4. Nydus-snapshotter specifies the prefetch list when starting nydus daemon. | ||
5. Nydusd completes the mounting of the nydus image. | ||
<!-- 4. Run the prefetch plugin to fetch those information and forward them to nydus-snapshotter when the RunPodSandbox event occurs. --> |
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.
What is this line for?
docs/prefetchfiles-nri-plugin.md
Outdated
|
||
|
||
|
||
Note that the naming of keys in annotations is fixed, and the values in annotations is user self-defined. |
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 user self-defined.
docs/prefetchfiles-nri-plugin.md
Outdated
|
||
|
||
Note that the naming of keys in annotations is fixed, and the values in annotations is user self-defined. | ||
After create a pod, image reference and path of prefetch list will received by nydus-snapshotter. |
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.
After creating a pod
docs/prefetchfiles-nri-plugin.md
Outdated
annotations: | ||
containerd.io/nydus-prefetch: | | ||
[ | ||
{"image": "dockerhub.kubekey.local/dfns/wordpress:nydus_latest", "prefetch": "/path/to/wordpress_prefetch.txt"} |
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.
Um. If the value is a file path, I am concerning how can we distribute the file to each K8s node?
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.
Maybe add an comment: specify the prefetch
value with an URL is coming. 😉
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 very much! Other comments have been modified, and I will also correct this comment in the next version commit
docs/prefetchfiles-nri-plugin.md
Outdated
socket_address = "/run/containerd-nydus/system.sock" | ||
EOF | ||
``` | ||
Also, when manually starting the prefetch NRI plugin, the socket address can also be modified through the command line parameter `socket-addr`. Note that the priority of configuration file parameter passing is higher than that of command line parameter passing. |
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.
Perhaps command line parameters have higher priority would make more sense.
docs/prefetchfiles-nri-plugin.md
Outdated
``` | ||
Add a prefetch configuration file to specify the correct socket address. Note that this configuration file is designed for starting the NRI plugin in `pre-connection` mode. In this mode, the NRI plugin and containerd will start simultaneously. | ||
```console | ||
sudo tee /etc/nydus/prefetchConfig.toml <<- EOF |
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 /etc/nydus/prefetchConfig.toml
the right path? In default, containerd read NRI's configuration file from /etc/nri/conf.d
.
docs/prefetchfiles-nri-plugin.md
Outdated
annotations: | ||
containerd.io/nydus-prefetch: | | ||
[ | ||
{"image": "dockerhub.kubekey.local/dfns/wordpress:nydus_latest", "prefetch": "/path/to/wordpress_prefetch.txt"} |
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.
Maybe add an comment: specify the prefetch
value with an URL is coming. 😉
e2f26c6
to
87b8fa0
Compare
The |
socket_address = "/run/containerd-nydus/system.sock" | ||
# The events that containerd subscribes to. | ||
# Do not change this element. | ||
events = ["RunPodSandbox"] |
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.
There is no need to export this entry.
cmd/prefetchfiles-nri-plugin/main.go
Outdated
} | ||
} else { | ||
globalSocket = flags.Args.SocketAddress | ||
if globalSocket == "" { |
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 we should verify if the flags.Args.Config.SocketAddr
is nil.
if flags.Args.Config.SocketAddr != nil {
globalSocket = flags.Args.Config.SocketAddr
} else {
globalSocket = defaultSystemControllerAddress
}
cmd/prefetchfiles-nri-plugin/main.go
Outdated
nydusPrefetchAnnotation = "containerd.io/nydus-prefetch" | ||
) | ||
|
||
type PluginConfig struct { | ||
SocketAddr string `toml:"socket_address"` | ||
Events []string `toml:"events"` |
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 can remove it because it is unused. The defaultEvents
is enough.
5ac4580
to
0bae30a
Compare
21cb39c
to
d585766
Compare
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.
Others, LGTM
.github/workflows/ci.yml
Outdated
@@ -82,7 +82,8 @@ jobs: | |||
- name: Build | |||
run: | | |||
# Download nydus components | |||
NYDUS_VER=v$(curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -s "https://api.github.com/repos/dragonflyoss/image-service/releases/latest" | jq -r .tag_name | sed 's/^v//') | |||
# NYDUS_VER=v$(curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -s "https://api.github.com/repos/dragonflyoss/image-service/releases/latest" | jq -r .tag_name | sed 's/^v//') |
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.
Please remove the dead code.
cmd/prefetchfiles-nri-plugin/main.go
Outdated
@@ -62,8 +64,8 @@ func buildFlags(args *PluginArgs) []cli.Flag { | |||
&cli.StringFlag{ | |||
Name: "socket-addr", | |||
Value: defaultSystemControllerAddress, | |||
Usage: "unix domain socket address. If defined in the configuration file, there is no need to add ", | |||
Destination: &args.SocketAddress, | |||
Usage: "unix domain socket address.", |
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.
Maybe we need more information. UNIX domain socket address for connection to the nydus-snapshotter API.
?
cmd/prefetchfiles-nri-plugin/main.go
Outdated
} else { | ||
globalSocket = flags.Args.SocketAddress | ||
globalSocket = defaultSystemControllerAddress |
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.
No need to set defaultSystemControllerAddress
for globalSocket because we have specify defaultSystemControllerAddress
as the default value for SocketAddr
flag. IOW, the flags.Args.Config.SocketAddr
must not be nil.
docs/prefetchfiles-nri-plugin.md
Outdated
```console | ||
sudo systemctl restart containerd | ||
``` | ||
If you want to start the plugin using `pre-connection` mode, that is, `disableConnections: true`. You need to write a configuration file and place the plugin's binary file and configuration file in the correct directories. Here is an example of configuration file: |
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.
The pre-connection
mode is not related to disableConnections
, they can work at the same time.
docs/prefetchfiles-nri-plugin.md
Outdated
|
||
crictl runp pod.yaml | ||
``` | ||
The files that require prefetching are written in a URL, and `nydus-snapshoter` will read the prefetch list based on the URL address and transfer it to a local text file. The specific content of the prefetch files can be customized by the user. |
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.
The list of files to be prefetched is written in a URL, and `nydus-snapshoter` will read the prefetch list based on the URL address and transfer it to a local file.
@@ -0,0 +1,3 @@ | |||
# unix domain socket address |
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.
ditto.
integration/prefetch.sh
Outdated
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 necessary to create a new script for integration?
Morever, entrypoint.sh
is used as the ENTRYPOINT
of image, but this script integration/prefetch.sh
is not used by make integrate
command.
pkg/prefetch/prefetch.go
Outdated
) | ||
|
||
const prefetchlistPath string = "/opt/PrefetchFiles" |
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 configurable?
pkg/prefetch/prefetch.go
Outdated
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
errMsg := fmt.Sprintf("HTTP response status code is not 200 OK: %s", resp.Status) |
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.
"failed to GET %s, response status $v", url, resp.Status
pkg/prefetch/prefetch.go
Outdated
tokenizer := html.NewTokenizer(resp.Body) | ||
inBody := false | ||
|
||
for { |
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 don't understand why we need this loop. May have a more concise implementation?
Could you take a look at this? cc @imeoer
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, we can't assume the server side returns such html format.
03a0a2e
to
1589530
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #524 +/- ##
==========================================
- Coverage 33.52% 33.49% -0.04%
==========================================
Files 65 65
Lines 8287 8298 +11
==========================================
+ Hits 2778 2779 +1
- Misses 5194 5204 +10
Partials 315 315
|
1589530
to
f585f28
Compare
@@ -0,0 +1,127 @@ | |||
# User self-defined nydus image files prefetch | |||
To improve the flexibility of nydus image files prefetch, for the k8s scenario, we can specify a prefetch files list when create a nydus daemon. The prefetch files list is user self-defined. Nydus-snapshotter has implemented a containerd NRI plugin to transmit the path of prefetch files list to nydus-snapshotter. The prefetch plugin requires NRI 2.0, which is available in containerd (>=v1.7.0). The prefetch plugin subscribes pod creation event, obtains the URL address containing the content of the files need to be prefetched, and forwards it to `nydus-snapshotter`. The `nydus-snapshotter` reads the data through the URL and stores it locally. Then when `nydusd` starts, it will pull the files defined in the prefetch files list through lazy loading. This allows the pull of the prefetch files to be done during container creation rather than image convert, improving the flexibility of file prefetching. |
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.
First should explain why we need the prefetch, then say the flexibility of prefetch on runtime.
docs/prefetchfiles-nri-plugin.md
Outdated
|
||
## Requirements | ||
|
||
- [NRI 2.0](https://github.com/containerd/nri): Which has been integrated into containerd since [v1.7.0](https://github.com/containerd/containerd/tree/v1.7.0-beta.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.
Should be https://github.com/containerd/containerd/tree/v1.7.0
?
docs/prefetchfiles-nri-plugin.md
Outdated
|
||
|
||
|
||
|
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.
Remove multiple spaces before this.
log_directory: /tmp | ||
annotations: | ||
containerd.io/nydus-prefetch: | | ||
[ |
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.
Format it:
[
{
"image": "ghcr.io/dragonflyoss/image-service/wordpress:nydus-nightly-v6",
"prefetch": "http://example.com/api/v1/resource/wordpress",
}
]
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.
Does the annotation work with multiple line 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.
yes, if there are multiple images and prefetchlists in annotations, the code works correctly.
go.mod
Outdated
github.com/godbus/dbus/v5 v5.1.0 // indirect | ||
) | ||
|
||
require github.com/freddierice/go-losetup v0.0.0-20220711213114-2a14873012db |
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.
Please merge require
section.
misc/prefetch/crictl.yaml
Outdated
runtime-endpoint: unix:///run/containerd/containerd.sock | ||
image-endpoint: unix:///run/containerd/containerd.sock | ||
timeout: 10 | ||
debug: true |
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.
Add blank line here.
misc/prefetch/prefetch_server.go
Outdated
"net/http" | ||
) | ||
|
||
func wordpress_prefetchlist(w http.ResponseWriter, req *http.Request) { |
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.
getWordpressPrefetchList
misc/prefetch/prefetch_server.go
Outdated
fmt.Fprintf(w, responseText) | ||
} | ||
|
||
func tomcat_prefetchlist(w http.ResponseWriter, req *http.Request) { |
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.
getTomcatPrefetchList
misc/snapshotter/config.toml
Outdated
@@ -63,6 +63,9 @@ address = ":9110" | |||
[remote] | |||
convert_vpc_registry = false | |||
|
|||
[prefetch] | |||
dir = "/opt/prefetch" |
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.
How do we remove the useless prefetch list file in this dir?
type prefetchlist struct { | ||
PrefetchFiles []string `json:"prefetchFiles"` | ||
} | ||
|
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.
type prefetchList struct {
Files []string `json:"files"`
}
pkg/prefetch/prefetch.go
Outdated
p.prefetchMap[image] = prefetchfiles | ||
} | ||
|
||
log.L.Infof("received prefetch list from nri plugin: %v ", p.prefetchMap) | ||
return nil | ||
} | ||
|
||
// Obtain the prefetch files through the URL and transfer them to local files(). | ||
func (p *prefetchInfo) getprefetchConfigFile(url, image string) (string, 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.
getPrefetchListPath
392de38
to
eb73d5d
Compare
eb73d5d
to
8f21a90
Compare
34808aa
to
9d3ff61
Compare
Signed-off-by: billie60 <[email protected]>
1. specify the prefetch value with an URL 2. Modify the reading mode of configuration file 3. add prefetchlist path in config.toml and so on Signed-off-by: billie60 <[email protected]>
Signed-off-by: billie60 <[email protected]> crictl 1.29.0 cni v1.4.0 dockerfile all newest version
a418ce6
to
c822caa
Compare
This document mainly introduces the early configuration and usage of prefetch-nri-plugin.