Skip to content

Commit 653e64d

Browse files
committed
support build with platform
1 parent 399905a commit 653e64d

File tree

15 files changed

+613
-606
lines changed

15 files changed

+613
-606
lines changed

cluster/calcium/build.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (c *Calcium) buildFromSCM(ctx context.Context, node *types.Node, opts *type
105105

106106
func (c *Calcium) buildFromContent(ctx context.Context, node *types.Node, opts *types.BuildOptions) ([]string, io.ReadCloser, error) {
107107
refs := node.Engine.BuildRefs(ctx, toBuildRefOptions(opts))
108-
resp, err := node.Engine.ImageBuild(ctx, opts.Tar, refs)
108+
resp, err := node.Engine.ImageBuild(ctx, opts.Tar, refs, opts.Platform)
109109
return refs, resp, errors.WithStack(err)
110110
}
111111

@@ -115,7 +115,6 @@ func (c *Calcium) buildFromExist(ctx context.Context, opts *types.BuildOptions)
115115
}
116116

117117
refs = node.Engine.BuildRefs(ctx, toBuildRefOptions(opts))
118-
119118
imgID, err := node.Engine.ImageBuildFromExist(ctx, opts.ExistID, refs, opts.User)
120119
if err != nil {
121120
return nil, nil, nil, errors.WithStack(err)
@@ -182,7 +181,6 @@ func (c *Calcium) pushImageAndClean(ctx context.Context, resp io.ReadCloser, nod
182181
// 无论如何都删掉build机器的
183182
// 事实上他不会跟cached pod一样
184183
// 一样就砍死
185-
// TODO Maybe blocked !!!
186184
_ = c.pool.Invoke(func() {
187185
cleanupNodeImages(ctx, node, tags, c.config.GlobalTimeout)
188186
})

cluster/calcium/build_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestBuild(t *testing.T) {
114114
engine.On("BuildContent", mock.Anything, mock.Anything, mock.Anything).Return("", b, nil)
115115
// failed by ImageBuild
116116
opts.BuildMethod = types.BuildFromRaw
117-
engine.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrNilEngine).Once()
117+
engine.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrNilEngine).Once()
118118
ch, err = c.BuildImage(ctx, opts)
119119
assert.Error(t, err)
120120
// build from exist not implemented
@@ -130,7 +130,7 @@ func TestBuild(t *testing.T) {
130130
ch, err = c.BuildImage(ctx, opts)
131131
assert.Error(t, err)
132132
// correct
133-
engine.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything).Return(buildImageRespReader, nil)
133+
engine.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(buildImageRespReader, nil)
134134
engine.On("ImagePush", mock.Anything, mock.Anything).Return(buildImageRespReader2, nil)
135135
engine.On("ImageRemove", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]string{}, nil)
136136
engine.On("ImageBuildCachePrune", mock.Anything, mock.Anything).Return(uint64(1024), nil)

core.yaml.sample

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,5 @@ scheduler:
7676

7777
resource_plugin:
7878
dir: /etc/eru/plugins # optional, default /etc/eru/plugins
79-
call_timeout: 30s # optional, if need to use plugin, set it
80-
whitelist: # optional, if need plugins whitelist
79+
call_timeout: 30s # optional, if need to use plugin, set it
80+
whitelist: # optional, if need plugins whitelist

engine/docker/image.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (e *Engine) ImagePush(ctx context.Context, ref string) (io.ReadCloser, erro
8585
}
8686

8787
// ImageBuild build image
88-
func (e *Engine) ImageBuild(ctx context.Context, input io.Reader, refs []string) (io.ReadCloser, error) {
88+
func (e *Engine) ImageBuild(ctx context.Context, input io.Reader, refs []string, platform string) (io.ReadCloser, error) {
8989
authConfigs := map[string]dockertypes.AuthConfig{}
9090
for domain, conf := range e.config.Docker.AuthConfigs {
9191
b64auth, err := encodeAuthToBase64(conf)
@@ -107,6 +107,7 @@ func (e *Engine) ImageBuild(ctx context.Context, input io.Reader, refs []string)
107107
Remove: true,
108108
ForceRemove: true,
109109
PullParent: true,
110+
Platform: platform,
110111
AuthConfigs: authConfigs,
111112
}
112113
resp, err := e.client.ImageBuild(ctx, input, buildOptions)

engine/engine.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type API interface {
2828
ImagesPrune(ctx context.Context) error
2929
ImagePull(ctx context.Context, ref string, all bool) (io.ReadCloser, error)
3030
ImagePush(ctx context.Context, ref string) (io.ReadCloser, error)
31-
ImageBuild(ctx context.Context, input io.Reader, refs []string) (io.ReadCloser, error)
31+
ImageBuild(ctx context.Context, input io.Reader, refs []string, platform string) (io.ReadCloser, error)
3232
ImageBuildCachePrune(ctx context.Context, all bool) (uint64, error)
3333
ImageLocalDigests(ctx context.Context, image string) ([]string, error)
3434
ImageRemoteDigest(ctx context.Context, image string) (string, error)

engine/fake/fake.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (f *Engine) ImagePush(ctx context.Context, ref string) (io.ReadCloser, erro
8585
}
8686

8787
// ImageBuild .
88-
func (f *Engine) ImageBuild(ctx context.Context, input io.Reader, refs []string) (io.ReadCloser, error) {
88+
func (f *Engine) ImageBuild(ctx context.Context, input io.Reader, refs []string, _ string) (io.ReadCloser, error) {
8989
return nil, f.DefaultErr
9090
}
9191

engine/mocks/API.go

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/mocks/fakeengine/mock.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func MakeClient(ctx context.Context, config coretypes.Config, nodename, endpoint
7373
pushImageData := io.NopCloser(bytes.NewBufferString("{\"stream\":\"push something...\"}\n"))
7474
e.On("ImagePush", mock.Anything, mock.Anything).Return(pushImageData, nil)
7575
buildImageData := io.NopCloser(bytes.NewBufferString("{\"stream\":\"build something...\"}\n"))
76-
e.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything).Return(buildImageData, nil)
76+
e.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(buildImageData, nil)
7777
e.On("ImageBuildCachePrune", mock.Anything, mock.Anything).Return(uint64(0), nil)
7878
imageDigest := utils.RandomString(64)
7979
e.On("ImageLocalDigests", mock.Anything, mock.Anything).Return([]string{imageDigest}, nil)

engine/virt/image.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (v *Virt) ImagePush(ctx context.Context, ref string) (rc io.ReadCloser, err
9191
}
9292

9393
// ImageBuild captures from a guest.
94-
func (v *Virt) ImageBuild(ctx context.Context, input io.Reader, refs []string) (rc io.ReadCloser, err error) {
94+
func (v *Virt) ImageBuild(ctx context.Context, input io.Reader, refs []string, _ string) (rc io.ReadCloser, err error) {
9595
log.Warnf(ctx, "imageBuild does not implement")
9696
return
9797
}

resources/cpumem/schedule/schedule.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strconv"
77

88
"github.com/projecteru2/core/resources/cpumem/types"
9+
"github.com/projecteru2/core/utils"
910
)
1011

1112
type cpuCore struct {
@@ -67,13 +68,6 @@ type CPUPlan struct {
6768
CPUMap types.CPUMap
6869
}
6970

70-
func min(a, b int) int {
71-
if a < b {
72-
return a
73-
}
74-
return b
75-
}
76-
7771
// GetCPUPlans .
7872
func GetCPUPlans(resourceInfo *types.NodeResourceInfo, originCPUMap types.CPUMap, shareBase int, maxFragmentCores int, resourceOpts *types.WorkloadResourceOpts) []*CPUPlan {
7973
cpuPlans := []*CPUPlan{}
@@ -220,7 +214,7 @@ func (h *host) getCPUPlans(cpuRequest float64) []types.CPUMap {
220214
fragmentCapacityMap := map[string]int{}
221215
totalFragmentCapacity := 0 // for lazy loading
222216
bestCPUPlans := [2][]types.CPUMap{h.getFullCPUPlans(h.fullCores, full), h.getFragmentCPUPlans(h.fragmentCores, fragment)}
223-
bestCapacity := min(len(bestCPUPlans[0]), len(bestCPUPlans[1]))
217+
bestCapacity := utils.Min(len(bestCPUPlans[0]), len(bestCPUPlans[1]))
224218

225219
for _, core := range h.fullCores {
226220
fragmentCapacityMap[core.id] = core.pieces / fragment
@@ -239,7 +233,7 @@ func (h *host) getCPUPlans(cpuRequest float64) []types.CPUMap {
239233
totalFragmentCapacity += fragmentCapacityMap[newFragmentCore.id]
240234

241235
fullCPUPlans := h.getFullCPUPlans(h.fullCores, full)
242-
capacity := min(len(fullCPUPlans), totalFragmentCapacity)
236+
capacity := utils.Min(len(fullCPUPlans), totalFragmentCapacity)
243237
if capacity > bestCapacity {
244238
bestCPUPlans[0] = fullCPUPlans
245239
bestCPUPlans[1] = h.getFragmentCPUPlans(h.fragmentCores, fragment)

0 commit comments

Comments
 (0)