Skip to content

Commit 29d2c5d

Browse files
authored
fix refs used by buildFromExist (#511)
1 parent dae0e91 commit 29d2c5d

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

cluster/calcium/build.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,20 @@ func (c *Calcium) BuildImage(ctx context.Context, opts *types.BuildOptions) (ch
3131
return nil, logger.Err(ctx, err)
3232
}
3333
log.Infof(ctx, "[BuildImage] Building image at pod %s node %s", node.Podname, node.Name)
34-
// get refs
35-
refs := node.Engine.BuildRefs(ctx, toBuildRefOptions(opts))
3634

37-
var resp io.ReadCloser
35+
var (
36+
refs []string
37+
resp io.ReadCloser
38+
)
3839
switch opts.BuildMethod {
3940
case types.BuildFromSCM:
41+
refs = node.Engine.BuildRefs(ctx, toBuildRefOptions(opts))
4042
resp, err = c.buildFromSCM(ctx, node, refs, opts)
4143
case types.BuildFromRaw:
44+
refs = node.Engine.BuildRefs(ctx, toBuildRefOptions(opts))
4245
resp, err = c.buildFromContent(ctx, node, refs, opts.Tar)
4346
case types.BuildFromExist:
44-
node, resp, err = c.buildFromExist(ctx, refs, opts.ExistID, opts.User)
47+
refs, node, resp, err = c.buildFromExist(ctx, opts)
4548
default:
4649
return nil, logger.Err(ctx, errors.WithStack(errors.New("unknown build type")))
4750
}
@@ -91,22 +94,24 @@ func (c *Calcium) buildFromContent(ctx context.Context, node *types.Node, refs [
9194
return resp, errors.WithStack(err)
9295
}
9396

94-
func (c *Calcium) buildFromExist(ctx context.Context, refs []string, existID, user string) (node *types.Node, resp io.ReadCloser, err error) {
95-
if node, err = c.getWorkloadNode(ctx, existID); err != nil {
96-
return nil, nil, err
97+
func (c *Calcium) buildFromExist(ctx context.Context, opts *types.BuildOptions) (refs []string, node *types.Node, resp io.ReadCloser, err error) {
98+
if node, err = c.getWorkloadNode(ctx, opts.ExistID); err != nil {
99+
return nil, nil, nil, err
97100
}
98101

99-
imgID, err := node.Engine.ImageBuildFromExist(ctx, existID, refs, user)
102+
refs = node.Engine.BuildRefs(ctx, toBuildRefOptions(opts))
103+
104+
imgID, err := node.Engine.ImageBuildFromExist(ctx, opts.ExistID, refs, opts.User)
100105
if err != nil {
101-
return nil, nil, errors.WithStack(err)
106+
return nil, nil, nil, errors.WithStack(err)
102107
}
103108

104109
buildMsg, err := json.Marshal(types.BuildImageMessage{ID: imgID})
105110
if err != nil {
106-
return nil, nil, errors.WithStack(err)
111+
return nil, nil, nil, errors.WithStack(err)
107112
}
108113

109-
return node, io.NopCloser(bytes.NewReader(buildMsg)), nil
114+
return refs, node, io.NopCloser(bytes.NewReader(buildMsg)), nil
110115
}
111116

112117
func (c *Calcium) pushImageAndClean(ctx context.Context, resp io.ReadCloser, node *types.Node, tags []string) (chan *types.BuildImageMessage, error) { // nolint:unparam

0 commit comments

Comments
 (0)