Skip to content

Commit

Permalink
support build with platform
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Oct 6, 2022
1 parent 399905a commit 653e64d
Show file tree
Hide file tree
Showing 15 changed files with 613 additions and 606 deletions.
4 changes: 1 addition & 3 deletions cluster/calcium/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *Calcium) buildFromSCM(ctx context.Context, node *types.Node, opts *type

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

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

refs = node.Engine.BuildRefs(ctx, toBuildRefOptions(opts))

imgID, err := node.Engine.ImageBuildFromExist(ctx, opts.ExistID, refs, opts.User)
if err != nil {
return nil, nil, nil, errors.WithStack(err)
Expand Down Expand Up @@ -182,7 +181,6 @@ func (c *Calcium) pushImageAndClean(ctx context.Context, resp io.ReadCloser, nod
// 无论如何都删掉build机器的
// 事实上他不会跟cached pod一样
// 一样就砍死
// TODO Maybe blocked !!!
_ = c.pool.Invoke(func() {
cleanupNodeImages(ctx, node, tags, c.config.GlobalTimeout)
})
Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestBuild(t *testing.T) {
engine.On("BuildContent", mock.Anything, mock.Anything, mock.Anything).Return("", b, nil)
// failed by ImageBuild
opts.BuildMethod = types.BuildFromRaw
engine.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrNilEngine).Once()
engine.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrNilEngine).Once()
ch, err = c.BuildImage(ctx, opts)
assert.Error(t, err)
// build from exist not implemented
Expand All @@ -130,7 +130,7 @@ func TestBuild(t *testing.T) {
ch, err = c.BuildImage(ctx, opts)
assert.Error(t, err)
// correct
engine.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything).Return(buildImageRespReader, nil)
engine.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(buildImageRespReader, nil)
engine.On("ImagePush", mock.Anything, mock.Anything).Return(buildImageRespReader2, nil)
engine.On("ImageRemove", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]string{}, nil)
engine.On("ImageBuildCachePrune", mock.Anything, mock.Anything).Return(uint64(1024), nil)
Expand Down
4 changes: 2 additions & 2 deletions core.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ scheduler:

resource_plugin:
dir: /etc/eru/plugins # optional, default /etc/eru/plugins
call_timeout: 30s # optional, if need to use plugin, set it
whitelist: # optional, if need plugins whitelist
call_timeout: 30s # optional, if need to use plugin, set it
whitelist: # optional, if need plugins whitelist
3 changes: 2 additions & 1 deletion engine/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (e *Engine) ImagePush(ctx context.Context, ref string) (io.ReadCloser, erro
}

// ImageBuild build image
func (e *Engine) ImageBuild(ctx context.Context, input io.Reader, refs []string) (io.ReadCloser, error) {
func (e *Engine) ImageBuild(ctx context.Context, input io.Reader, refs []string, platform string) (io.ReadCloser, error) {
authConfigs := map[string]dockertypes.AuthConfig{}
for domain, conf := range e.config.Docker.AuthConfigs {
b64auth, err := encodeAuthToBase64(conf)
Expand All @@ -107,6 +107,7 @@ func (e *Engine) ImageBuild(ctx context.Context, input io.Reader, refs []string)
Remove: true,
ForceRemove: true,
PullParent: true,
Platform: platform,
AuthConfigs: authConfigs,
}
resp, err := e.client.ImageBuild(ctx, input, buildOptions)
Expand Down
2 changes: 1 addition & 1 deletion engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type API interface {
ImagesPrune(ctx context.Context) error
ImagePull(ctx context.Context, ref string, all bool) (io.ReadCloser, error)
ImagePush(ctx context.Context, ref string) (io.ReadCloser, error)
ImageBuild(ctx context.Context, input io.Reader, refs []string) (io.ReadCloser, error)
ImageBuild(ctx context.Context, input io.Reader, refs []string, platform string) (io.ReadCloser, error)
ImageBuildCachePrune(ctx context.Context, all bool) (uint64, error)
ImageLocalDigests(ctx context.Context, image string) ([]string, error)
ImageRemoteDigest(ctx context.Context, image string) (string, error)
Expand Down
2 changes: 1 addition & 1 deletion engine/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (f *Engine) ImagePush(ctx context.Context, ref string) (io.ReadCloser, erro
}

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

Expand Down
14 changes: 7 additions & 7 deletions engine/mocks/API.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion engine/mocks/fakeengine/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func MakeClient(ctx context.Context, config coretypes.Config, nodename, endpoint
pushImageData := io.NopCloser(bytes.NewBufferString("{\"stream\":\"push something...\"}\n"))
e.On("ImagePush", mock.Anything, mock.Anything).Return(pushImageData, nil)
buildImageData := io.NopCloser(bytes.NewBufferString("{\"stream\":\"build something...\"}\n"))
e.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything).Return(buildImageData, nil)
e.On("ImageBuild", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(buildImageData, nil)
e.On("ImageBuildCachePrune", mock.Anything, mock.Anything).Return(uint64(0), nil)
imageDigest := utils.RandomString(64)
e.On("ImageLocalDigests", mock.Anything, mock.Anything).Return([]string{imageDigest}, nil)
Expand Down
2 changes: 1 addition & 1 deletion engine/virt/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (v *Virt) ImagePush(ctx context.Context, ref string) (rc io.ReadCloser, err
}

// ImageBuild captures from a guest.
func (v *Virt) ImageBuild(ctx context.Context, input io.Reader, refs []string) (rc io.ReadCloser, err error) {
func (v *Virt) ImageBuild(ctx context.Context, input io.Reader, refs []string, _ string) (rc io.ReadCloser, err error) {
log.Warnf(ctx, "imageBuild does not implement")
return
}
Expand Down
12 changes: 3 additions & 9 deletions resources/cpumem/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"

"github.com/projecteru2/core/resources/cpumem/types"
"github.com/projecteru2/core/utils"
)

type cpuCore struct {
Expand Down Expand Up @@ -67,13 +68,6 @@ type CPUPlan struct {
CPUMap types.CPUMap
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

// GetCPUPlans .
func GetCPUPlans(resourceInfo *types.NodeResourceInfo, originCPUMap types.CPUMap, shareBase int, maxFragmentCores int, resourceOpts *types.WorkloadResourceOpts) []*CPUPlan {
cpuPlans := []*CPUPlan{}
Expand Down Expand Up @@ -220,7 +214,7 @@ func (h *host) getCPUPlans(cpuRequest float64) []types.CPUMap {
fragmentCapacityMap := map[string]int{}
totalFragmentCapacity := 0 // for lazy loading
bestCPUPlans := [2][]types.CPUMap{h.getFullCPUPlans(h.fullCores, full), h.getFragmentCPUPlans(h.fragmentCores, fragment)}
bestCapacity := min(len(bestCPUPlans[0]), len(bestCPUPlans[1]))
bestCapacity := utils.Min(len(bestCPUPlans[0]), len(bestCPUPlans[1]))

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

fullCPUPlans := h.getFullCPUPlans(h.fullCores, full)
capacity := min(len(fullCPUPlans), totalFragmentCapacity)
capacity := utils.Min(len(fullCPUPlans), totalFragmentCapacity)
if capacity > bestCapacity {
bestCPUPlans[0] = fullCPUPlans
bestCPUPlans[1] = h.getFragmentCPUPlans(h.fragmentCores, fragment)
Expand Down
Loading

0 comments on commit 653e64d

Please sign in to comment.