@@ -18,7 +18,7 @@ import (
18
18
19
19
// BuildImage will build image
20
20
func (c * Calcium ) BuildImage (ctx context.Context , opts * types.BuildOptions ) (ch chan * types.BuildImageMessage , err error ) {
21
- logger := log .WithField ( "Calcium" , " BuildImage" ).WithField ("opts" , opts )
21
+ logger := log .WithFunc ( "calcium. BuildImage" ).WithField ("opts" , opts )
22
22
// Disable build API if scm not set
23
23
if c .source == nil {
24
24
return nil , types .ErrNoSCMSetting
@@ -30,7 +30,7 @@ func (c *Calcium) BuildImage(ctx context.Context, opts *types.BuildOptions) (ch
30
30
return nil , err
31
31
}
32
32
33
- log .Infof (ctx , "[BuildImage] Building image at pod %s node %s" , node .Podname , node .Name )
33
+ logger .Infof (ctx , "Building image at pod %s node %s" , node .Podname , node .Name )
34
34
35
35
var (
36
36
refs []string
@@ -131,8 +131,8 @@ func (c *Calcium) buildFromExist(ctx context.Context, opts *types.BuildOptions)
131
131
}
132
132
133
133
func (c * Calcium ) pushImageAndClean (ctx context.Context , resp io.ReadCloser , node * types.Node , tags []string ) (chan * types.BuildImageMessage , error ) { //nolint:unparam
134
- logger := log .WithField ( "Calcium" , "pushImage " ).WithField ("node" , node ).WithField ("tags" , tags )
135
- log .Infof (ctx , "[BuildImage] Pushing image at pod %s node %s" , node .Podname , node .Name )
134
+ logger := log .WithFunc ( "calcium.pushImageAndClean " ).WithField ("node" , node ).WithField ("tags" , tags )
135
+ logger .Infof (ctx , "Pushing image at pod %s node %s" , node .Podname , node .Name )
136
136
return c .withImageBuiltChannel (func (ch chan * types.BuildImageMessage ) {
137
137
defer resp .Close ()
138
138
decoder := json .NewDecoder (resp )
@@ -144,29 +144,29 @@ func (c *Calcium) pushImageAndClean(ctx context.Context, resp io.ReadCloser, nod
144
144
break
145
145
}
146
146
if err == context .Canceled || err == context .DeadlineExceeded {
147
- log .Error (ctx , err , "[BuildImage] context timeout" )
147
+ logger .Error (ctx , err , "context timeout" )
148
148
lastMessage .ErrorDetail .Code = - 1
149
149
lastMessage .ErrorDetail .Message = err .Error ()
150
150
lastMessage .Error = err .Error ()
151
151
break
152
152
}
153
153
malformed , _ := io .ReadAll (decoder .Buffered ()) // TODO err check
154
- logger .Errorf (ctx , err , "[BuildImage] Decode build image message failed, buffered: %+v" , malformed )
154
+ logger .Errorf (ctx , err , "Decode build image message failed, buffered: %+v" , malformed )
155
155
return
156
156
}
157
157
ch <- message
158
158
lastMessage = message
159
159
}
160
160
161
161
if lastMessage .Error != "" {
162
- logger .Errorf (ctx , errors .New (lastMessage .Error ), "[BuildImage] Build image failed %+v" , lastMessage .ErrorDetail .Message )
162
+ logger .Errorf (ctx , errors .New (lastMessage .Error ), "Build image failed %+v" , lastMessage .ErrorDetail .Message )
163
163
return
164
164
}
165
165
166
166
// push and clean
167
167
for i := range tags {
168
168
tag := tags [i ]
169
- log .Infof (ctx , "[BuildImage] Push image %s" , tag )
169
+ logger .Infof (ctx , "Push image %s" , tag )
170
170
rc , err := node .Engine .ImagePush (ctx , tag )
171
171
if err != nil {
172
172
logger .Error (ctx , err )
@@ -190,8 +190,8 @@ func (c *Calcium) pushImageAndClean(ctx context.Context, resp io.ReadCloser, nod
190
190
191
191
}
192
192
193
- func (c * Calcium ) getWorkloadNode (ctx context.Context , id string ) (* types.Node , error ) {
194
- w , err := c .store .GetWorkload (ctx , id )
193
+ func (c * Calcium ) getWorkloadNode (ctx context.Context , ID string ) (* types.Node , error ) {
194
+ w , err := c .store .GetWorkload (ctx , ID )
195
195
if err != nil {
196
196
return nil , err
197
197
}
@@ -208,19 +208,19 @@ func (c *Calcium) withImageBuiltChannel(f func(chan *types.BuildImageMessage)) c
208
208
return ch
209
209
}
210
210
211
- func cleanupNodeImages (ctx context.Context , node * types.Node , ids []string , ttl time.Duration ) {
212
- logger := log .WithField ( "Calcium" , " cleanupNodeImages" ).WithField ("node" , node ).WithField ("ids " , ids ).WithField ("ttl" , ttl )
213
- ctx , cancel := context .WithTimeout (utils .InheritTracingInfo (ctx , context . TODO () ), ttl )
211
+ func cleanupNodeImages (ctx context.Context , node * types.Node , IDs []string , ttl time.Duration ) {
212
+ logger := log .WithFunc ( "calcium. cleanupNodeImages" ).WithField ("node" , node ).WithField ("IDs " , IDs ).WithField ("ttl" , ttl )
213
+ ctx , cancel := context .WithTimeout (utils .NewInheritCtx (ctx ), ttl )
214
214
defer cancel ()
215
- for _ , id := range ids {
216
- if _ , err := node .Engine .ImageRemove (ctx , id , false , true ); err != nil {
217
- logger .Error (ctx , err , "[BuildImage] Remove image error" )
215
+ for _ , ID := range IDs {
216
+ if _ , err := node .Engine .ImageRemove (ctx , ID , false , true ); err != nil {
217
+ logger .Error (ctx , err , "Remove image error" )
218
218
}
219
219
}
220
220
if spaceReclaimed , err := node .Engine .ImageBuildCachePrune (ctx , true ); err != nil {
221
- logger .Error (ctx , err , "[BuildImage] Remove build image cache error" )
221
+ logger .Error (ctx , err , "Remove build image cache error" )
222
222
} else {
223
- logger .Infof (ctx , "[BuildImage] Clean cached image and release space %d" , spaceReclaimed )
223
+ logger .Infof (ctx , "Clean cached image and release space %d" , spaceReclaimed )
224
224
}
225
225
}
226
226
0 commit comments