@@ -9,9 +9,9 @@ package daemonconfig
99
1010import (
1111 "encoding/json"
12+ "os"
1213 "reflect"
1314 "strings"
14- "sync"
1515
1616 "github.com/pkg/errors"
1717
@@ -36,6 +36,7 @@ type DaemonConfig interface {
3636 StorageBackend () (StorageBackendType , * BackendConfig )
3737 UpdateMirrors (mirrorsConfigDir , registryHost string ) error
3838 DumpString () (string , error )
39+ DumpFile (path string ) error
3940}
4041
4142// Daemon configurations factory
@@ -121,14 +122,19 @@ type DeviceConfig struct {
121122 } `json:"cache"`
122123}
123124
124- var configRWMutex sync.RWMutex
125+ // For nydusd as FUSE daemon. Serialize Daemon info and persist to a json file
126+ // We don't have to persist configuration file for fscache since its configuration
127+ // is passed through HTTP API.
128+ func DumpConfigFile (c interface {}, path string ) error {
129+ if config .IsBackendSourceEnabled () {
130+ c = serializeWithSecretFilter (c )
131+ }
132+ b , err := json .Marshal (c )
133+ if err != nil {
134+ return errors .Wrapf (err , "marshal config" )
135+ }
125136
126- type SupplementInfoInterface interface {
127- GetImageID () string
128- GetSnapshotID () string
129- IsVPCRegistry () bool
130- GetLabels () map [string ]string
131- GetParams () map [string ]string
137+ return os .WriteFile (path , b , 0600 )
132138}
133139
134140func DumpConfigString (c interface {}) (string , error ) {
@@ -137,22 +143,20 @@ func DumpConfigString(c interface{}) (string, error) {
137143}
138144
139145// Achieve a daemon configuration from template or snapshotter's configuration
140- func SupplementDaemonConfig (c DaemonConfig , info SupplementInfoInterface ) error {
141-
142- configRWMutex .Lock ()
143- defer configRWMutex .Unlock ()
146+ func SupplementDaemonConfig (c DaemonConfig , imageID , snapshotID string ,
147+ vpcRegistry bool , labels map [string ]string , params map [string ]string ) error {
144148
145- image , err := registry .ParseImage (info . GetImageID () )
149+ image , err := registry .ParseImage (imageID )
146150 if err != nil {
147- return errors .Wrapf (err , "parse image %s" , info . GetImageID () )
151+ return errors .Wrapf (err , "parse image %s" , imageID )
148152 }
149153
150154 backendType , _ := c .StorageBackend ()
151155
152156 switch backendType {
153157 case backendTypeRegistry :
154158 registryHost := image .Host
155- if info . IsVPCRegistry () {
159+ if vpcRegistry {
156160 registryHost = registry .ConvertToVPCHost (registryHost )
157161 } else if registryHost == "docker.io" {
158162 // For docker.io images, we should use index.docker.io
@@ -166,8 +170,8 @@ func SupplementDaemonConfig(c DaemonConfig, info SupplementInfoInterface) error
166170 // If no auth is provided, don't touch auth from provided nydusd configuration file.
167171 // We don't validate the original nydusd auth from configuration file since it can be empty
168172 // when repository is public.
169- keyChain := auth .GetRegistryKeyChain (registryHost , info . GetImageID (), info . GetLabels () )
170- c .Supplement (registryHost , image .Repo , info . GetSnapshotID (), info . GetParams () )
173+ keyChain := auth .GetRegistryKeyChain (registryHost , imageID , labels )
174+ c .Supplement (registryHost , image .Repo , snapshotID , params )
171175 c .FillAuth (keyChain )
172176
173177 // Localfs and OSS backends don't need any update,
0 commit comments