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

Transmit the prefetch list to snapshotter during runp pod.yaml #493

Merged
merged 1 commit into from
Aug 28, 2023

Conversation

billie60
Copy link
Contributor

Hello, in this PR, I start an NRI plugin and subscribe to pod creation event. The plugin invokes the RunPodSandbox method to obtain prefetch list file path recorded in pod.yaml when monitoring the pod creation command. Then send the prefetch list file path to snapshotter through the specified socket API. After receiving prefetch list file path, snapshotter will save the content and add --prefetch-files parameter when building nydusd command to customize prefetch files content. I will submit the modifications to snapshotter in the next PR.

@imeoer
Copy link
Collaborator

imeoer commented Jun 16, 2023

cc @sctb512 @changweige

@imeoer
Copy link
Collaborator

imeoer commented Jun 16, 2023

}

func sendDataOverHTTP(data string, endpoint string) error {
url := "http://172.0.0.1:9110" + endpoint
Copy link
Member

Choose a reason for hiding this comment

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

Should we POST a request to "http://172.0.0.1:9110"? This HTTP URL is used to export metrics and may not always be enabled, so we can not be fully dependent on it. I think the unix domain socket for the system controller is more reasonable.

type PluginConfig struct {
Events []string `toml:"events"`
ServerPath string `toml:"server_path"`
PersistDir string `toml:"persist_dir"`
Copy link
Member

Choose a reason for hiding this comment

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

It appears that this entry is not used in your nri plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it in commits fd34

return err
}

conn, err := net.Dial("unix", "/run/containerd-nydus/system.sock")
Copy link
Member

Choose a reason for hiding this comment

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

It is better to set the unix domain socket path from a configuration entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set sockaddr as a command parameter in fd34

cmd/prefetchfiles-nri-plugin/main.go Outdated Show resolved Hide resolved
cmd/prefetchfiles-nri-plugin/main.go Outdated Show resolved Hide resolved
}

func (p *plugin) onClose() {
for _, fanotifyServer := range globalFanotifyServer {
Copy link
Member

Choose a reason for hiding this comment

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

The fanotifyServer is not used by this NRI plugin, please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed fanotifyServer

cmd/prefetchfiles-nri-plugin/main.go Outdated Show resolved Hide resolved
type PluginArgs struct {
PluginName string
PluginIdx string
PluginEvents string
Copy link
Member

Choose a reason for hiding this comment

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

If you only need to use RunPodSandbox interface, you can remove this configuration entry and define it as a constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to improve the flexibility of prefetch files transmit, it may be necessary to increase the monitoring of the Create Container event, so I have temporarily kept this part. If any modifications are needed, I will make them the next time I update the PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Only some specific events can catch the container image name & prefetch list, why do we still need to export the arg?

"bytes"
"context"
"fmt"
"github.com/containerd/nydus-snapshotter/pkg/errdefs"
Copy link
Collaborator

Choose a reason for hiding this comment

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

The external package should be moved to the bottom.

const (
defaultEvents = "RunPodSandbox"
defaultServerPath = "/usr/local/bin/optimizer-server"
defaultPersistDir = "/opt/nri/optimizer/results"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove some irrelevant codes.

)

const (
endpointPL = "/api/v1/daemons/prefetch" //////////todo
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO: what's todo.

Copy link
Collaborator

Choose a reason for hiding this comment

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

endpointPrefetch

endpointPL = "/api/v1/daemons/prefetch" //////////todo
defaultEvents = "RunPodSandbox"
defaulthttp = "http://system.sock"
defaultsockaddr = "/run/containerd-nydus/system.sock"
Copy link
Collaborator

Choose a reason for hiding this comment

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

defaultSockAddr

type PluginArgs struct {
PluginName string
PluginIdx string
PluginEvents string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Only some specific events can catch the container image name & prefetch list, why do we still need to export the arg?

logWriter *syslog.Writer
)

func sendDataOverHTTP(data string, endpoint string, sock string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

data, endpoint, sock string

client := &http.Client{
Transport: &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return conn, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should put return net.Dial("unix", sock) in here?


func (p *plugin) RunPodSandbox(pod *api.PodSandbox) error {
name := pod.Name
parts := strings.Split(name, "-")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why split the name here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In pod.yaml, the name is defined as image_name-sandbox, splitting the name is to obtain the image_ name. And if the PrefetchList in the States structure needs to be defined as a dictionary in subsequent modifications, image_ name can be used as a key in the dictionary.

name = parts[0]
if pod.Annotations == nil {
log.Printf("error: Pod annotations is nil")
return errors.New("Pod annotations is nil")
Copy link
Collaborator

Choose a reason for hiding this comment

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

The error message should start with a lowercase letter.


err = p.stub.Run(context.Background())
if err != nil {
log.Errorf("plugin exited with error %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

return errors.Wrap(err, "plugin exited")

@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Merging #493 (a33ce0b) into main (a6f4457) will decrease coverage by 0.12%.
The diff coverage is 0.00%.

❗ Current head a33ce0b differs from pull request most recent head eebcc0f. Consider uploading reports for the commit eebcc0f to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #493      +/-   ##
==========================================
- Coverage   37.81%   37.70%   -0.12%     
==========================================
  Files          60       60              
  Lines        7090     7116      +26     
==========================================
+ Hits         2681     2683       +2     
- Misses       4097     4121      +24     
  Partials      312      312              
Files Changed Coverage Δ
config/global.go 31.64% <ø> (ø)
pkg/daemon/command/command.go 56.88% <0.00%> (-2.17%) ⬇️
pkg/daemon/config.go 0.00% <0.00%> (ø)
pkg/daemon/daemon.go 0.00% <ø> (ø)
pkg/manager/daemon_adaptor.go 0.00% <0.00%> (ø)
pkg/system/system.go 5.48% <0.00%> (-0.30%) ⬇️

... and 2 files with indirect coverage changes

@billie60 billie60 force-pushed the prefetchfiles-nri branch 4 times, most recently from 9168fc0 to 03307c5 Compare June 20, 2023 11:13
}

var (
globalsock string
Copy link
Member

Choose a reason for hiding this comment

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

globalsock -> globalSocket

endpointPrefetch = "/api/v1/daemons/prefetch"
defaultEvents = "RunPodSandbox"
defaultHTTPURL = "http://system.sock"
defaultSockaddr = "/run/containerd-nydus/system.sock"
Copy link
Member

Choose a reason for hiding this comment

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

const (
endpointPrefetch = "/api/v1/daemons/prefetch"
defaultEvents = "RunPodSandbox"
defaultHTTPURL = "http://system.sock"
Copy link
Member

Choose a reason for hiding this comment

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

Please refer to the implementation that nydus-snapshotter dials nydusd through an unix domain socket. https://github.com/containerd/nydus-snapshotter/blob/v0.9.0/pkg/daemon/client.go#L90


func sendDataOverHTTP(data, endpoint, sock string) error {
url := defaultHTTPURL + endpoint
req, err := http.NewRequest("POST", url, bytes.NewBufferString(data))
Copy link
Member

@sctb512 sctb512 Jun 20, 2023

Choose a reason for hiding this comment

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

Why use POST method. Morever we can use a constant http.MethodGet instead of "GET".
Please refer to https://github.com/containerd/nydus-snapshotter/blob/v0.9.0/pkg/daemon/client.go#L284

cmd/prefetchfiles-nri-plugin/main.go Show resolved Hide resolved
err error
)

flags.Args.Sockaddr = c.String("sockaddr")
Copy link
Member

Choose a reason for hiding this comment

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

This line is redundant.

log.SetFormatter(&logrus.TextFormatter{
PadLevelText: true,
})
logWriter, err = syslog.New(syslog.LOG_INFO, "prefetchfiles-nri-plugin")
Copy link
Member

Choose a reason for hiding this comment

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

ditto

type PluginArgs struct {
PluginName string
PluginIdx string
Sockaddr string
Copy link
Member

Choose a reason for hiding this comment

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

SocketAddress or Address?

Destination: &args.PluginIdx,
},
&cli.StringFlag{
Name: "sockaddr",
Copy link
Member

@sctb512 sctb512 Jun 20, 2023

Choose a reason for hiding this comment

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

Please use - to split two words for command arguments. Just like socket-addr.


p := &plugin{}

Events := defaultEvents
Copy link
Member

Choose a reason for hiding this comment

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

This line is redundant.

@billie60 billie60 force-pushed the prefetchfiles-nri branch 4 times, most recently from aae793e to c146069 Compare June 28, 2023 16:22
Copy link
Member

@changweige changweige left a comment

Choose a reason for hiding this comment

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

Thanks but we still need more work

)

const (
endpointPrefetch = "/api/v1/daemons/prefetch"
Copy link
Member

Choose a reason for hiding this comment

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

How about replacing the service endpoint with /api/v1/prefetch since it's possible no nydusd daemon is running while nydus-snapshotter is preparing snapshots

@@ -0,0 +1,10 @@
package globalvar

// var PldataDict = make(map[string]string)
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid dead code

@@ -53,6 +53,7 @@ type States struct {
// Where the configuration file resides, all rafs instances share the same configuration template
ConfigDir string
SupervisorPath string
PrefetchFiles string
Copy link
Member

Choose a reason for hiding this comment

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

Data in States field will all be persisted in the DB, is it necessary to store the PrefetchFiles into DB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello, thanks for your review. According to my understanding, adding PrefetchFiles to States is to persist this parameter. If PrefetchFiles is not added to States, when snapshotter unexpectedly restarts and triggers the recovery process after running the nydusd command, the BuildDaemonCommand method will discard the --prefetch-files parameter when rebuilding the nydusd command.

Copy link
Member

@changweige changweige Jul 13, 2023

Choose a reason for hiding this comment

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

Is this resolved? I suppose it's not. You CAN'T put the prefetch info into DB definitely. I am a little tired of such things

Copy link
Member

@sctb512 sctb512 Aug 13, 2023

Choose a reason for hiding this comment

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

I also think that saving the PrefetchFiles to DB is not a good choice. You can move it to Rafs struct if this value is different to each instance. If we need to store it in the DB, please provide more details. TKS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am sooo sorry that many of my previous replies to comments were in a pending state, so that you cannot see them. I will reply again, I'm really really sorry.

if !ok {
errMsg := "pod.yaml annotations don't have prefetch list."
log.Printf("error: %s", errMsg)
return errors.New(errMsg)
Copy link
Member

@changweige changweige Jun 29, 2023

Choose a reason for hiding this comment

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

We should not return error as it's possible that no prefetch list is ever specified the user

return errors.New("pod annotations is nil")
}

prefetchList, ok := pod.Annotations["prefetch_list"]
Copy link
Member

@changweige changweige Jun 29, 2023

Choose a reason for hiding this comment

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

I am worrying if the prefetch_list matches K8s annotation nameing requirement. It should have a name space. Or is it possible to configure the annotation name since different cloud vendors may have different namespaces

log.Printf("failed to send data: %v\n", err)
return err
}
log.Println("Data sent successfully")
Copy link
Member

Choose a reason for hiding this comment

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

Please don't print tons of normal message to system log

Copy link
Member

Choose a reason for hiding this comment

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

Please remove this message.

@@ -167,8 +170,19 @@ func (sc *Controller) registerRouter() {
sc.router.HandleFunc(endpointDaemons, sc.describeDaemons()).Methods(http.MethodGet)
sc.router.HandleFunc(endpointDaemonsUpgrade, sc.upgradeDaemons()).Methods(http.MethodPut)
sc.router.HandleFunc(endpointDaemonRecords, sc.getDaemonRecords()).Methods(http.MethodGet)
sc.router.HandleFunc(endpointPrefetch, sc.getPrefetchFiles()).Methods(http.MethodGet)
Copy link
Member

Choose a reason for hiding this comment

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

Http Get method should be used when client wants to query nydus-snapshotter's states. I am suggesting using Put method here

@@ -167,8 +170,19 @@ func (sc *Controller) registerRouter() {
sc.router.HandleFunc(endpointDaemons, sc.describeDaemons()).Methods(http.MethodGet)
sc.router.HandleFunc(endpointDaemonsUpgrade, sc.upgradeDaemons()).Methods(http.MethodPut)
sc.router.HandleFunc(endpointDaemonRecords, sc.getDaemonRecords()).Methods(http.MethodGet)
sc.router.HandleFunc(endpointPrefetch, sc.getPrefetchFiles()).Methods(http.MethodGet)
}
func (sc *Controller) getPrefetchFiles() func(w http.ResponseWriter, r *http.Request) {
Copy link
Member

Choose a reason for hiding this comment

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

rename it setPrefetchFiles ?

func (sc *Controller) getPrefetchFiles() func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
err := json.Unmarshal(body, &globalvar.Msg)
Copy link
Member

Choose a reason for hiding this comment

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

Deserializing the body to a global variable is not safe. We need to reconsider how to manage the prefetch files list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello, other comments have been modified. However, this comment has been tried many ways but no better solution has been found. May I ask if you have any specific suggestions so that I can improve this part of the code again? Thank you very much.

}
func (sc *Controller) getPrefetchFiles() func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
Copy link
Member

Choose a reason for hiding this comment

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

Please don't ignore any retured error

@billie60 billie60 force-pushed the prefetchfiles-nri branch 2 times, most recently from 758ab42 to 6dac99b Compare July 6, 2023 12:03
return err
}

req, err := http.NewRequest(http.MethodPut, url, bytes.NewBuffer(body)) // todo 改为put
Copy link
Member

Choose a reason for hiding this comment

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

Please remove unnecessary comments.

return err
}
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to GET request with code %d", resp.StatusCode)
Copy link
Member

Choose a reason for hiding this comment

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

"failed to send data, status code: %d"

return nil
}

prefetchList, ok := pod.Annotations["containerd.io/snapshotter/nydus-prefetch-list"]
Copy link
Member

Choose a reason for hiding this comment

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

How about "containerd.io/snapshot/nydus-prefetch"? In addition, this value should be assigned to a constant.

prefetchList, ok := pod.Annotations["containerd.io/snapshotter/nydus-prefetch-list"]
if !ok {
errMsg := "pod.yaml annotations don't have prefetch list."
log.Warnf("error: %s", errMsg)
Copy link
Member

@sctb512 sctb512 Jul 7, 2023

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 use a variable to hold errMsg. Moreover, error: is confused.

I think this message is surplus.

log.Printf("failed to send data: %v\n", err)
return err
}
log.Println("Data sent successfully")
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this message.

package globalvar

type Message struct {
Name string `json:"name"`
Copy link
Member

Choose a reason for hiding this comment

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

Is this the image name? I think it is not enough to identify a unique image.


type Message struct {
Name string `json:"name"`
PrefetchFiles string `json:"prefetchList"`
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure the variables express the same meaning. In addition, we often use underscore naming convention for json data.

return
}

log.L.Infof("received msg from RunPodSandbox event: %v ", filesystem.PrefetchMsg)
Copy link
Member

Choose a reason for hiding this comment

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

received prefetch list from nri plugin: %v

body, err := io.ReadAll(r.Body)
if err != nil {
log.L.Errorf("Failed to read prefetch list: %v", err)
http.Error(w, "Failed to read prefetch list", http.StatusInternalServerError)
Copy link
Member

Choose a reason for hiding this comment

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

Should we return this error to client?

@@ -45,6 +46,8 @@ const (
DummyMountpoint string = "/dummy"
)

var PrefetchMsg globalvar.Message
Copy link
Member

Choose a reason for hiding this comment

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

This can be replaced by lru.Cache. Moreover, we should consider whether global variables should be used.

@billie60 billie60 force-pushed the prefetchfiles-nri branch 4 times, most recently from c22f52c to 2b1e837 Compare July 11, 2023 01:21
cmd/prefetchfiles-nri-plugin/main.go Show resolved Hide resolved
config/global.go Outdated
if err := json.Unmarshal(body, &prefetchMsg); err != nil {
return err
}
globalConfig.PrefetchFiles = prefetchMsg
Copy link
Member

Choose a reason for hiding this comment

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

This is not safe, I suggest to use a map to store this message and use a lock before modifying it.

Copy link
Member

Choose a reason for hiding this comment

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

And delete it by key registry/repo/name:tag when starting nydusd successfully.

log.L.Errorf("Failed to read prefetch list: %v", err)
return
}
if err = config.SetPrefetchFiles(Msg, body); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

It seems the Msg transmitted to SetPrefetchFiles is redundant.

@sctb512
Copy link
Member

sctb512 commented Jul 11, 2023

Also, please make sure that this plugin doesn't hang for too long if sending data fails, which will result in a context deadline exceeded error for containerd.

Others, LGTM. cc @changweige @imeoer

Thanks for @billie60's great work making nydus snapshotter more flexible to use prefetch list in k8s scenario. I'd like to move this forward.

Copy link
Member

@changweige changweige left a comment

Choose a reason for hiding this comment

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

Could you help add an e2e test for the plugin?

config/global.go Outdated
PrefetchFiles PrefetchMessage
}
type PrefetchMessage struct {
ImageAddress string `json:"image_address"`
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename image_address to image_reference which means it format of REPOSITORY:TAG

defaultEvents = "RunPodSandbox"
defaultSystemControllerAddress = "/run/containerd-nydus/system.sock"
nydusPrefetchAnnotation = "containerd.io/snapshot/nydus-prefetch"
imageAddressAnnotation = "containerd.io/snapshot/nydus-image-address"
Copy link
Member

Choose a reason for hiding this comment

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

Can this annotation be passed by k8s ? https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
There are too many slashes?

Copy link
Member

Choose a reason for hiding this comment

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

Also please rename it to nydus-image or nydus-image-reference

config/global.go Outdated
@@ -37,6 +39,15 @@ type GlobalConfig struct {
DaemonThreadsNum int
CacheGCPeriod time.Duration
MirrorsConfig MirrorsConfig
PrefetchFiles PrefetchMessage
Copy link
Member

Choose a reason for hiding this comment

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

This is not the right place for storing prefetch information. The struct GlobalConfig is only for storing configuration items from CLI and toml configuration file

config/global.go Outdated
if err := json.Unmarshal(body, &prefetchMsg); err != nil {
return err
}
globalConfig.PrefetchFiles = prefetchMsg
Copy link
Member

Choose a reason for hiding this comment

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

Moreover, it's not concurrency-safe.

@changweige
Copy link
Member

Please refine the commit name. At least, remove the WIP prefix

@billie60 billie60 force-pushed the prefetchfiles-nri branch 5 times, most recently from 38f109b to 27aee64 Compare July 27, 2023 06:11
@imeoer
Copy link
Collaborator

imeoer commented Jul 31, 2023

cc @changweige PATL again, thanks!

@changweige
Copy link
Member

Is the commit Merge branch 'main' into prefetchfiles-nri purposed carried on this PR ? Could you squash or fix it?

@billie60 billie60 force-pushed the prefetchfiles-nri branch 2 times, most recently from 038fb4b to eebcc0f Compare August 7, 2023 16:09

log = logrus.StandardLogger()

viper.SetConfigName("prefetchConfig")
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to import the viper package?

)

var (
prefetchMsg MessagePrefetch
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure, but I think this global variable may cause some inconsistencies. For instance, if two pods are started, the first one needs to pull a larger image than the second one. Can they get the correct prefetch files? Do you have a test for this case?

@@ -53,6 +53,7 @@ type States struct {
// Where the configuration file resides, all rafs instances share the same configuration template
ConfigDir string
SupervisorPath string
PrefetchFiles string
Copy link
Member

@sctb512 sctb512 Aug 13, 2023

Choose a reason for hiding this comment

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

I also think that saving the PrefetchFiles to DB is not a good choice. You can move it to Rafs struct if this value is different to each instance. If we need to store it in the DB, please provide more details. TKS.

@billie60 billie60 force-pushed the prefetchfiles-nri branch 3 times, most recently from 06c3bcd to e8ad73c Compare August 21, 2023 05:25
Copy link
Member

@changweige changweige left a comment

Choose a reason for hiding this comment

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

Otherwise, looks good

pkg/prefetch/prefetch.go Show resolved Hide resolved
pkg/prefetch/prefetch.go Show resolved Hide resolved
@@ -160,6 +165,17 @@ func (m *Manager) BuildDaemonCommand(d *daemon.Daemon, bin string, upgrade bool)
command.WithID(d.ID()))
}

prefetchMap := prefetch.GetPrefetchMap()
if imageReference != "" {
prefetchfiles, ok := prefetchMap[imageReference]
Copy link
Member

Choose a reason for hiding this comment

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

Accessing prefetchMap should be locked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, I have add a lock in GetPrefetchMap and copy value in it.


err := sendDataOverHTTP(prefetchList, endpointPrefetch, globalSocket)
if err != nil {
log.Errorf("failed to send data: %v\n", err)
Copy link
Member

Choose a reason for hiding this comment

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

No need to append \n

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

log = logrus.StandardLogger()

configFileName := "prefetchConfig.toml"
configPath := "."
Copy link
Member

Choose a reason for hiding this comment

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

Do you man configDir? configPath looks like a path to the config file

Copy link
Member

Choose a reason for hiding this comment

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

Though current dir . looks strange. If NRI plugin process' current dir has the config file, it is not necessary to have it prefix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

if err != nil {
log.Warnf("failed to read config file: %v", err)
}
if configSocketAddr := config.Get("file_prefetch.socket_address").(string); configSocketAddr != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Type assertion may fail, please handl it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes! fixed

cmd/prefetchfiles-nri-plugin/prefetchConfig.toml Outdated Show resolved Hide resolved
pkg/manager/daemon_adaptor.go Outdated Show resolved Hide resolved
@changweige
Copy link
Member

Can we have a doc to describe how to deploy the NRI plugin and an associated e2e test would be greater

@billie60 billie60 force-pushed the prefetchfiles-nri branch 2 times, most recently from a4792cf to 7584fee Compare August 25, 2023 04:15
cmd/prefetchfiles-nri-plugin/main.go Outdated Show resolved Hide resolved
pkg/prefetch/prefetch.go Outdated Show resolved Hide resolved
1. modify config file's default dir in /etc/nydus/
2. modify GetPrefetchMap in prefetch package to GetPrefetchInfo
Copy link
Member

@changweige changweige left a comment

Choose a reason for hiding this comment

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

LGTM~ Thanks for your contribution! 👍

@changweige
Copy link
Member

Hopefully, we can have following PRs:

  1. Add related documents
  2. Define a Makefile target to build the plugin in the CI job
  3. Add e2e test

@changweige changweige merged commit 490cc94 into containerd:main Aug 28, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants