chore: import upstream snapshot with attribution
SDK Tests / changes (push) Successful in 2m29s
Real E2E Tests / changes (push) Successful in 2m29s
Deploy Docs Pages / build (push) Has been cancelled
Deploy Docs Pages / deploy (push) Has been cancelled
Real E2E Tests / JavaScript E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Python E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Java E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / C# E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Go E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Real E2E CI (push) Has been cancelled
SDK Tests / SDK CI (push) Has been cancelled
SDK Tests / CLI Tests (push) Has been cancelled
SDK Tests / Python SDK Quality (code-interpreter) (push) Has been cancelled
SDK Tests / Python SDK Quality (sandbox) (push) Has been cancelled
SDK Tests / Python SDK Tests (code-interpreter) (push) Has been cancelled
SDK Tests / JavaScript SDK Quality And Tests (code-interpreter) (push) Has been cancelled
SDK Tests / JavaScript SDK Quality And Tests (sandbox) (push) Has been cancelled
SDK Tests / Python SDK Tests (sandbox) (push) Has been cancelled
SDK Tests / CLI Quality (push) Has been cancelled
SDK Tests / Kotlin SDK Quality And Tests (sandbox) (push) Has been cancelled
SDK Tests / Kotlin SDK Quality And Tests (code-interpreter) (push) Has been cancelled
SDK Tests / C# SDK Quality And Tests (code-interpreter) (push) Has been cancelled
SDK Tests / C# SDK Quality And Tests (sandbox) (push) Has been cancelled
SDK Tests / Go SDK Quality And Tests (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:39:33 +08:00
commit e0e362d700
1949 changed files with 375388 additions and 0 deletions
@@ -0,0 +1,40 @@
// Copyright 2025 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package algorithm
// Algorithm determines how available pods are distributed among sandbox requests.
type Algorithm interface {
// Schedule distributes available pods among sandbox requests and returns the allocation action.
Schedule(availablePods []string, allRequest []*SandboxRequest) *AllocAction
}
// SandboxRequest describes a sandbox's allocation need.
type SandboxRequest struct {
SandboxName string
CurAllocation []string
CurReleased []string
PodSupplement int32
ToRelease []string
}
// AllocAction represents the result of a scheduling decision.
type AllocAction struct {
// allocate pods to sandbox (sandbox -> pods)
ToAllocate map[string][]string
// release pods from sandbox (sandbox -> pods)
ToRelease map[string][]string
// pod request count
PodSupplement int32
}
@@ -0,0 +1,50 @@
// Copyright 2025 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package algorithm
// PackedSchedule allocates pods to each sandbox in order, fully satisfying one before moving to the next.
// This is the default algorithm and provides the simplest packing strategy.
type PackedSchedule struct{}
func (p *PackedSchedule) Schedule(availablePods []string, allRequest []*SandboxRequest) *AllocAction {
action := &AllocAction{
ToAllocate: make(map[string][]string),
ToRelease: make(map[string][]string),
PodSupplement: int32(0),
}
for _, req := range allRequest {
if len(req.ToRelease) > 0 {
action.ToRelease[req.SandboxName] = req.ToRelease
}
need := req.PodSupplement
if need <= 0 {
continue
}
if int32(len(availablePods)) >= need {
action.ToAllocate[req.SandboxName] = availablePods[:need]
availablePods = availablePods[need:]
} else if len(availablePods) > 0 {
action.ToAllocate[req.SandboxName] = availablePods
action.PodSupplement += need - int32(len(availablePods))
availablePods = nil
} else {
action.PodSupplement += need
}
}
return action
}
@@ -0,0 +1,116 @@
// Copyright 2025 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package algorithm
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPackedSchedule(t *testing.T) {
tests := []struct {
name string
availablePods []string
allRequest []*SandboxRequest
wantAllocate map[string][]string
wantRelease map[string][]string
wantSupplement int32
}{
{
name: "AllocateNormally",
availablePods: []string{"pod1", "pod2"},
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 1},
{SandboxName: "sbx2", PodSupplement: 1},
},
wantAllocate: map[string][]string{"sbx1": {"pod1"}, "sbx2": {"pod2"}},
wantRelease: map[string][]string{},
wantSupplement: 0,
},
{
name: "NotEnoughPods",
availablePods: []string{"pod1"},
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 2},
},
wantAllocate: map[string][]string{"sbx1": {"pod1"}},
wantRelease: map[string][]string{},
wantSupplement: 1,
},
{
name: "NoAvailablePods",
availablePods: nil,
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 2},
},
wantAllocate: map[string][]string{},
wantRelease: map[string][]string{},
wantSupplement: 2,
},
{
name: "WithRelease",
availablePods: []string{"pod3"},
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 1, ToRelease: []string{"pod1", "pod2"}},
},
wantAllocate: map[string][]string{"sbx1": {"pod3"}},
wantRelease: map[string][]string{"sbx1": {"pod1", "pod2"}},
wantSupplement: 0,
},
{
name: "NoNeed",
availablePods: []string{"pod1"},
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 0},
},
wantAllocate: map[string][]string{},
wantRelease: map[string][]string{},
wantSupplement: 0,
},
{
name: "PartialAllocation",
availablePods: []string{"pod1"},
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 2},
{SandboxName: "sbx2", PodSupplement: 1},
},
wantAllocate: map[string][]string{"sbx1": {"pod1"}},
wantRelease: map[string][]string{},
wantSupplement: 2, // 1 remaining for sbx1 + 1 for sbx2
},
{
name: "PackedAllocation",
availablePods: []string{"pod1", "pod2", "pod3", "pod4"},
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 3},
{SandboxName: "sbx2", PodSupplement: 2},
{SandboxName: "sbx3", PodSupplement: 2},
},
wantAllocate: map[string][]string{"sbx1": {"pod1", "pod2", "pod3"}, "sbx2": {"pod4"}},
wantRelease: map[string][]string{},
wantSupplement: 3, // 1 remaining for sbx2 + 2 for sbx3
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
action := (&PackedSchedule{}).Schedule(tt.availablePods, tt.allRequest)
assert.Equal(t, tt.wantAllocate, action.ToAllocate)
assert.Equal(t, tt.wantRelease, action.ToRelease)
assert.Equal(t, tt.wantSupplement, action.PodSupplement)
})
}
}
@@ -0,0 +1,71 @@
// Copyright 2025 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package algorithm
// SpreadSchedule distributes pods evenly across sandboxes in a round-robin fashion,
// like water filling — each sandbox gets one pod per round until its need is met.
type SpreadSchedule struct{}
func (s *SpreadSchedule) Schedule(availablePods []string, allRequest []*SandboxRequest) *AllocAction {
action := &AllocAction{
ToAllocate: make(map[string][]string),
ToRelease: make(map[string][]string),
PodSupplement: int32(0),
}
// Process ToRelease first.
for _, req := range allRequest {
if len(req.ToRelease) > 0 {
action.ToRelease[req.SandboxName] = req.ToRelease
}
}
// Build a list of sandboxes that still need pods, with their remaining counts.
type needEntry struct {
sandboxName string
remaining int32
}
var needs []needEntry
for _, req := range allRequest {
if req.PodSupplement > 0 {
needs = append(needs, needEntry{sandboxName: req.SandboxName, remaining: req.PodSupplement})
}
}
// Round-robin: each round give one pod to each sandbox that still needs pods.
podIdx := 0
for podIdx < len(availablePods) && len(needs) > 0 {
var nextRound []needEntry
for _, n := range needs {
if podIdx >= len(availablePods) {
break
}
action.ToAllocate[n.sandboxName] = append(action.ToAllocate[n.sandboxName], availablePods[podIdx])
podIdx++
n.remaining--
if n.remaining > 0 {
nextRound = append(nextRound, n)
}
}
needs = nextRound
}
// Calculate PodSupplement: any remaining unmet need across all sandboxes.
for _, n := range needs {
action.PodSupplement += n.remaining
}
return action
}
@@ -0,0 +1,117 @@
// Copyright 2025 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package algorithm
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSpreadSchedule(t *testing.T) {
tests := []struct {
name string
availablePods []string
allRequest []*SandboxRequest
wantAllocate map[string][]string
wantRelease map[string][]string
wantSupplement int32
}{
{
name: "AllocateEvenly",
availablePods: []string{"pod1", "pod2", "pod3", "pod4"},
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 2},
{SandboxName: "sbx2", PodSupplement: 2},
},
wantAllocate: map[string][]string{"sbx1": {"pod1", "pod3"}, "sbx2": {"pod2", "pod4"}},
wantRelease: map[string][]string{},
wantSupplement: 0,
},
{
name: "UnevenNeed",
availablePods: []string{"pod1", "pod2", "pod3"},
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 1},
{SandboxName: "sbx2", PodSupplement: 2},
},
wantAllocate: map[string][]string{"sbx1": {"pod1"}, "sbx2": {"pod2", "pod3"}},
wantRelease: map[string][]string{},
wantSupplement: 0,
},
{
name: "NotEnoughPods",
availablePods: []string{"pod1"},
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 2},
},
wantAllocate: map[string][]string{"sbx1": {"pod1"}},
wantRelease: map[string][]string{},
wantSupplement: 1,
},
{
name: "WithRelease",
availablePods: []string{"pod3"},
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 1, ToRelease: []string{"pod1"}},
},
wantAllocate: map[string][]string{"sbx1": {"pod3"}},
wantRelease: map[string][]string{"sbx1": {"pod1"}},
wantSupplement: 0,
},
{
name: "NoAvailablePods",
availablePods: nil,
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 3},
{SandboxName: "sbx2", PodSupplement: 2},
},
wantAllocate: map[string][]string{},
wantRelease: map[string][]string{},
wantSupplement: 5,
},
{
name: "EmptyRequests",
availablePods: []string{"pod1"},
allRequest: nil,
wantAllocate: map[string][]string{},
wantRelease: map[string][]string{},
wantSupplement: 0,
},
{
name: "SpreadAllocation",
availablePods: []string{"pod1", "pod2", "pod3", "pod4", "pod5"},
allRequest: []*SandboxRequest{
{SandboxName: "sbx1", PodSupplement: 3},
{SandboxName: "sbx2", PodSupplement: 2},
{SandboxName: "sbx3", PodSupplement: 1},
},
// Round 1: sbx1→pod1, sbx2→pod2, sbx3→pod3
// Round 2: sbx1→pod4, sbx2→pod5
wantAllocate: map[string][]string{"sbx1": {"pod1", "pod4"}, "sbx2": {"pod2", "pod5"}, "sbx3": {"pod3"}},
wantRelease: map[string][]string{},
wantSupplement: 1, // 1 remaining for sbx1
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
action := (&SpreadSchedule{}).Schedule(tt.availablePods, tt.allRequest)
assert.Equal(t, tt.wantAllocate, action.ToAllocate)
assert.Equal(t, tt.wantRelease, action.ToRelease)
assert.Equal(t, tt.wantSupplement, action.PodSupplement)
})
}
}