Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ci & e2e tests #3

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Build
run: make

- name: Lint
run: make lint

# - name: Test
# run: make test
Comment on lines +30 to +31
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warmup_controller test 会失败,先移除


e2e:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Set up kind
uses: helm/kind-action@v1
with:
config: test/e2e/config/kind-config.yaml
cluster_name: e2e

- name: Run e2e tests
env:
KIND_CLUSTER: e2e
run: make test-e2e
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test: manifests generate fmt vet envtest ## Run tests.
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
test-e2e:
go test ./test/e2e/ -v -ginkgo.v
go test -timeout 20m ./test/e2e/ -v -ginkgo.v

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
Expand Down
9 changes: 9 additions & 0 deletions api/v1/cachegroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ type CacheGroupWorkerTemplate struct {
// +optional
Volumes []corev1.Volume `json:"volumes,omitempty"`

// Set DNS policy for the pod.
// Defaults to "ClusterFirst".
// Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'.
// DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy.
// To have DNS options set along with hostNetwork, you have to specify DNS policy
// explicitly to 'ClusterFirstWithHostNet'.
// +optional
DNSPolicy *corev1.DNSPolicy `json:"dnsPolicy,omitempty"`

Opts []string `json:"opts,omitempty"`
}

Expand Down
5 changes: 5 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

4 changes: 4 additions & 0 deletions config/crd/bases/juicefs.io_cachegroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ spec:
overwrite:
items:
properties:
dnsPolicy:
type: string
env:
items:
properties:
Expand Down Expand Up @@ -1469,6 +1471,8 @@ spec:
type: array
template:
properties:
dnsPolicy:
type: string
env:
items:
properties:
Expand Down
1 change: 1 addition & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ spec:
containers:
- command:
- /manager
- controller
args:
- --leader-elect
- --health-probe-bind-address=:8081
Expand Down
4 changes: 4 additions & 0 deletions dist/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ spec:
overwrite:
items:
properties:
dnsPolicy:
type: string
env:
items:
properties:
Expand Down Expand Up @@ -1468,6 +1470,8 @@ spec:
type: array
template:
properties:
dnsPolicy:
type: string
env:
items:
properties:
Expand Down
6 changes: 6 additions & 0 deletions pkg/builder/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ func NewCacheGroupWorker(ctx context.Context, cg *juicefsiov1.CacheGroup, secret
} else {
worker.Spec.HostNetwork = true
}
if spec.DNSPolicy != nil {
worker.Spec.DNSPolicy = *spec.DNSPolicy
}
worker.Spec.Tolerations = spec.Tolerations
worker.Spec.SchedulerName = spec.SchedulerName
worker.Spec.ServiceAccountName = spec.ServiceAccountName
Expand Down Expand Up @@ -258,6 +261,9 @@ func MergeCacheGrouopWorkerTemplate(template *juicefsiov1.CacheGroupWorkerTempla
if overwrite.Opts != nil {
template.Opts = overwrite.Opts
}
if overwrite.DNSPolicy != nil {
template.DNSPolicy = overwrite.DNSPolicy
}
}

func genAuthCmdWithSecret(ctx context.Context, secrets map[string]string) []string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ func ValidateSecret(secrets *corev1.Secret) error {
return fmt.Errorf("token is missing")
}

// TOOD: validate other fields, like ak/sk, bucket, etc.
// TODO: validate other fields, like ak/sk, bucket, etc.
return nil
}
42 changes: 42 additions & 0 deletions test/e2e/config/e2e-test-cachegroup.overwrite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

apiVersion: juicefs.io/v1
kind: CacheGroup
metadata:
name: e2e-test-cachegroup
spec:
secretRef:
name: juicefs-secret
worker:
template:
nodeSelector:
juicefs.io/cg-worker: "true"
image: juicedata/mount:ee-5.1.1-1faf43b
dnsPolicy: ClusterFirstWithHostNet
hostNetwork: true
tolerations:
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 1
memory: 1Gi
opts:
- free-space-ratio=0.1
- group-weight=200
overwrite:
- nodes:
- e2e-worker2
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 2
memory: 2Gi
opts:
- free-space-ratio=0.01
- group-weight=100
26 changes: 26 additions & 0 deletions test/e2e/config/e2e-test-cachegroup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

apiVersion: juicefs.io/v1
kind: CacheGroup
metadata:
name: e2e-test-cachegroup
spec:
secretRef:
name: juicefs-secret
worker:
template:
nodeSelector:
juicefs.io/cg-worker: "true"
image: juicedata/mount:ee-5.1.1-1faf43b
dnsPolicy: ClusterFirstWithHostNet
hostNetwork: true
tolerations:
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 1
memory: 1Gi
6 changes: 6 additions & 0 deletions test/e2e/config/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
37 changes: 37 additions & 0 deletions test/e2e/config/minio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Deploys a new Namespace for the MinIO Pod
apiVersion: v1
kind: Pod
metadata:
labels:
app: minio
name: minio
namespace: default
spec:
containers:
- name: minio
image: quay.io/minio/minio:latest
command:
- /bin/bash
- -c
env:
- name: MINIO_ROOT_USER
value: minioadmin
- name: MINIO_ROOT_PASSWORD
value: minioadmin
args:
- minio server /data --console-address :9090
---
apiVersion: v1
kind: Service
metadata:
labels:
app: minio
name: minio
namespace: default
spec:
ports:
- port: 9000
protocol: TCP
targetPort: 9000
selector:
app: minio
Loading
Loading