Skip to content

Commit e0f67e3

Browse files
authored
Merge pull request #55 from Spground/feature/k8s-e2e-test
test(k8s): add sandbox-k8s-test workflow
2 parents 9034c30 + cddbeba commit e0f67e3

10 files changed

Lines changed: 122 additions & 11 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Sandbox K8S Tests
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
paths:
7+
- 'kubernetes/**'
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: '1.24.0'
20+
21+
- name: Run golint
22+
run: |
23+
cd kubernetes
24+
make lint
25+
26+
- name: Build binary
27+
run: |
28+
cd kubernetes
29+
make build
30+
make task-executor-build
31+
32+
- name: Run tests
33+
run: |
34+
cd kubernetes
35+
make test

kubernetes/.golangci.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
version: "2"
2+
run:
3+
concurrency: 4
4+
issues-exit-code: 1
5+
tests: true
6+
7+
# output configuration options
8+
output:
9+
formats:
10+
text:
11+
path: stdout
12+
colors: true
13+
linters:
14+
default: none
15+
enable:
16+
- depguard
17+
- govet
18+
- ineffassign
19+
- misspell
20+
- unconvert
21+
- unused
22+
settings:
23+
misspell:
24+
# Correct spellings using locale preferences for US or UK.
25+
# Default is to use a neutral variety of English.
26+
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
27+
locale: US
28+
depguard:
29+
rules:
30+
forbid-pkg-errors:
31+
deny:
32+
- pkg: "github.com/pkg/errors"
33+
desc: Should be replaced with standard lib errors or fmt.Errorf
34+
exclusions:
35+
generated: lax
36+
presets:
37+
- comments
38+
- common-false-positives
39+
- legacy
40+
- std-error-handling
41+
rules:
42+
- path: (.+)\.go$
43+
text: 'SA1019: package github.com/golang/protobuf/proto is deprecated: Use the "google.golang.org/protobuf/proto" package instead'
44+
paths:
45+
- third_party$
46+
- builtin$
47+
- examples$
48+
- apis
49+
- pkg/client
50+
- vendor
51+
- test
52+
formatters:
53+
enable:
54+
- gofmt
55+
- goimports
56+
settings:
57+
gofmt:
58+
simplify: true
59+
goimports:
60+
# put imports beginning with prefix after 3rd-party packages;
61+
local-prefixes:
62+
- github.com/alibaba/OpenSandbox/sandbox-k8s
63+
exclusions:
64+
generated: lax
65+
paths:
66+
- third_party$
67+
- builtin$
68+
- examples$
69+
- apis
70+
- pkg/client
71+
- vendor
72+
- test

kubernetes/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.18.0
293293
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
294294
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
295295
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
296-
GOLANGCI_LINT_VERSION ?= v2.1.0
296+
GOLANGCI_LINT_VERSION ?= v2.7.2
297297

298298
.PHONY: kustomize
299299
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.

kubernetes/cmd/task-executor/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import (
2222
"syscall"
2323
"time"
2424

25+
"k8s.io/klog/v2"
26+
2527
"github.com/alibaba/OpenSandbox/sandbox-k8s/internal/task-executor/config"
2628
"github.com/alibaba/OpenSandbox/sandbox-k8s/internal/task-executor/manager"
2729
"github.com/alibaba/OpenSandbox/sandbox-k8s/internal/task-executor/runtime"
2830
"github.com/alibaba/OpenSandbox/sandbox-k8s/internal/task-executor/server"
2931
store "github.com/alibaba/OpenSandbox/sandbox-k8s/internal/task-executor/storage"
30-
"k8s.io/klog/v2"
3132
)
3233

3334
func main() {

kubernetes/internal/controller/batchsandbox_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (r *BatchSandboxReconciler) Reconcile(ctx context.Context, req ctrl.Request
174174
},
175175
})
176176
obj := &sandboxv1alpha1.BatchSandbox{ObjectMeta: metav1.ObjectMeta{Namespace: batchSbx.Namespace, Name: batchSbx.Name}}
177-
if err := r.Patch(ctx, obj, client.RawPatch(types.MergePatchType, []byte(patchData))); err != nil {
177+
if err := r.Patch(ctx, obj, client.RawPatch(types.MergePatchType, patchData)); err != nil {
178178
klog.Errorf("failed to patch annotation %s, %s, body %s", AnnotationSandboxEndpoints, klog.KObj(batchSbx), patchData)
179179
aggErrors = append(aggErrors, err)
180180
}

kubernetes/internal/task-executor/manager/task_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func (m *taskManager) reconcileLoop(ctx context.Context) {
424424
klog.InfoS("reconcile loop stopped")
425425
return
426426
case <-ctx.Done():
427-
klog.InfoS("reconcile loop context cancelled")
427+
klog.InfoS("reconcile loop context canceled")
428428
return
429429
}
430430
}

kubernetes/internal/task-executor/runtime/process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (e *processExecutor) Start(ctx context.Context, task *types.Task) error {
9999
} else {
100100
// Host Logic: Direct execution
101101
// Use exec.Command instead of CommandContext to ensure the process survives
102-
// after the HTTP request context is cancelled.
102+
// after the HTTP request context is canceled.
103103
cmd = exec.Command("/bin/sh", "-c", shimScript)
104104
klog.InfoS("Starting host task", "name", task.Name, "cmd", safeCmdStr, "exitPath", exitPath)
105105
}

kubernetes/pkg/task-executor/client.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,19 @@ func (c *Client) Set(ctx context.Context, task *Task) (*Task, error) {
5656
if task == nil {
5757
// Delete request - send nil to clear tasks
5858
req, err = http.NewRequestWithContext(ctx, "POST", c.baseURL+"/setTasks", bytes.NewReader([]byte("[]")))
59+
if err != nil {
60+
return nil, fmt.Errorf("failed to create request: %w", err)
61+
}
5962
} else {
6063
// Create/Update request
6164
data, err := json.Marshal([]Task{*task})
6265
if err != nil {
6366
return nil, fmt.Errorf("failed to marshal task: %w", err)
6467
}
6568
req, err = http.NewRequestWithContext(ctx, "POST", c.baseURL+"/setTasks", bytes.NewReader(data))
66-
}
67-
68-
if err != nil {
69-
return nil, fmt.Errorf("failed to create request: %w", err)
69+
if err != nil {
70+
return nil, fmt.Errorf("failed to create request: %w", err)
71+
}
7072
}
7173

7274
req.Header.Set("Content-Type", "application/json")

kubernetes/pkg/task-executor/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
package task_executor
1616

1717
import (
18-
"github.com/alibaba/OpenSandbox/sandbox-k8s/api/v1alpha1"
1918
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19+
20+
"github.com/alibaba/OpenSandbox/sandbox-k8s/api/v1alpha1"
2021
)
2122

2223
// Task represents the internal local task resource (LocalTask)

kubernetes/test/e2e/e2e_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var _ = BeforeSuite(func() {
6161
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to build the manager(Operator) image")
6262

6363
By("building the task-executor image")
64-
makeArgs = []string{"docker-build-task-executor", fmt.Sprintf("IMG=%s", taskExecutorImage)}
64+
makeArgs = []string{"docker-build-task-executor", fmt.Sprintf("TASK_EXECUTOR_IMG=%s", taskExecutorImage)}
6565
if dockerBuildArgs != "" {
6666
makeArgs = append(makeArgs, fmt.Sprintf("DOCKER_BUILD_ARGS=%s", dockerBuildArgs))
6767
}

0 commit comments

Comments
 (0)