Optimize ci and docs (#477)

Signed-off-by: Siyu Wang <FillZpp.pub@gmail.com>
This commit is contained in:
Siyu Wang 2020-12-11 02:58:48 +08:00 committed by GitHub
parent 860bbc95f2
commit d734546559
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 223 additions and 138 deletions

View File

@ -1,61 +0,0 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
markdownlint-misspell-shellcheck:
docker:
# this image is build from Dockerfile
# https://github.com/pouchcontainer/pouchlinter/blob/master/Dockerfile
- image: pouchcontainer/pouchlinter:v0.1.2
working_directory: /go/src/github.com/openkruise/kruise
steps:
- checkout
- run:
name: use markdownlint v0.5.0 to lint markdown file (https://github.com/markdownlint/markdownlint)
command: |
find ./ -name "*.md" | grep -v vendor | grep -v commandline | grep -v .github | grep -v swagger | grep -v api | xargs mdl -r ~MD010,~MD013,~MD022,~MD024,~MD029,~MD031,~MD032,~MD033,~MD036
- run:
name: use markdown-link-check(https://github.com/tcort/markdown-link-check) to check links in markdown files
command: |
set +e
for name in $(find . -name \*.md | grep -v vendor | grep -v CHANGELOG); do
if [ -f $name ]; then
markdown-link-check -q $name -c .circleci/markdown-link-check.config.json;
if [ $? -ne 0 ]; then
code=1
fi
fi
done
bash -c "exit $code";
- run:
name: use opensource tool client9/misspell to correct commonly misspelled English words
command: |
find ./* -name "*" | grep -v vendor | xargs misspell -error
- run:
name: use ShellCheck (https://github.com/koalaman/shellcheck) to check the validateness of shell scripts in pouch repo
command: |
find ./ -name "*.sh" | grep -v vendor | xargs shellcheck
code-check:
docker:
- image: golangci/golangci-lint:v1.21
working_directory: /go/src/github.com/openkruise/kruise
steps:
- checkout
- run:
name: validate go code with golangci-lint
command: |
golangci-lint run --skip-dirs=apis,pkg/client --disable-all -E gofmt -E goimports -E golint -E ineffassign -E misspell -E vet
- run:
name: detect deadcode without test folder
command: |
golangci-lint run --disable-all --skip-dirs=vendor,test,pkg/client -E deadcode
workflows:
version: 2
ci:
jobs:
- markdownlint-misspell-shellcheck
- code-check

148
.github/workflows/ci.yaml vendored Normal file
View File

@ -0,0 +1,148 @@
name: CI
on:
push:
branches:
- master
- release-*
pull_request: {}
workflow_dispatch: {}
env:
# Common versions
GO_VERSION: '1.14'
GOLANGCI_VERSION: 'v1.31'
DOCKER_BUILDX_VERSION: 'v0.4.2'
KIND_VERSION: 'v0.9.0'
KUSTOMIZE_VERSION: '3.1.0'
# Common users. We can't run a step 'if secrets.AWS_USR != ""' but we can run
# a step 'if env.AWS_USR' != ""', so we copy these to succinctly test whether
# credentials have been provided before trying to run steps that need them.
DOCKER_USR: ${{ secrets.DOCKER_USR }}
AWS_USR: ${{ secrets.AWS_USR }}
jobs:
golangci-lint:
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
- name: Cache Go Dependencies
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-
- name: Lint golang code
uses: golangci/golangci-lint-action@v2
with:
version: ${{ env.GOLANGCI_VERSION }}
args: --skip-dirs=apis,pkg/client,vendor,test --disable-all -E deadcode -E gofmt -E goimports -E golint -E ineffassign -E misspell -E vet --timeout=5m
markdownlint-misspell-shellcheck:
runs-on: ubuntu-18.04
# this image is build from Dockerfile
# https://github.com/pouchcontainer/pouchlinter/blob/master/Dockerfile
container: pouchcontainer/pouchlinter:v0.1.2
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run misspell
run: find ./* -name "*" | grep -v vendor | xargs misspell -error
- name: Run shellcheck
run: find ./ -name "*.sh" | grep -v vendor | xargs shellcheck
- name: Lint markdown files
run: find ./ -name "*.md" | grep -v vendor | grep -v commandline | grep -v .github | grep -v swagger | grep -v api | xargs mdl -r ~MD010,~MD013,~MD022,~MD024,~MD029,~MD031,~MD032,~MD033,~MD036
- name: Check markdown links
run: |
set +e
for name in $(find . -name \*.md | grep -v vendor | grep -v CHANGELOG); do
if [ -f $name ]; then
markdown-link-check -q $name -c .github/workflows/markdown-link-check.config.json;
if [ $? -ne 0 ]; then
code=1
fi
fi
done
bash -c "exit $code";
unit-tests:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Fetch History
run: git fetch --prune --unshallow
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: install Kubebuilder
uses: wonderflow/kubebuilder-action@v1.1
- name: Cache Go Dependencies
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-
- name: Run Unit Tests
run: make -j2 test
- name: Publish Unit Test Coverage
uses: codecov/codecov-action@v1
with:
flags: unittests
file: cover.out
- name: Check diff
run: '[[ -z $(git status -s) ]] || (printf "Existing modified/untracked files.\nPlease run \"make generate manifests\" and push again.\n"; exit 1)'
e2e-tests:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Setup Kind Cluster
uses: engineerd/setup-kind@v0.5.0
with:
version: ${{ env.KIND_VERSION }}
- name: Setup Kustomize
uses: imranismail/setup-kustomize@v1
with:
kustomize-version: ${{ env.KUSTOMIZE_VERSION }}
- name: Build image
run: |
export IMAGE="openkruise/kruise-manager:e2e-${GITHUB_RUN_ID}"
docker build --pull --no-cache . -t $IMAGE
kind load docker-image $IMAGE || { echo >&2 "kind not installed or error loading image: $IMAGE"; exit 1; }
- name: Install Kruise
run: |
set -ex
kubectl cluster-info
make deploy IMG=openkruise/kruise-manager:e2e-${GITHUB_RUN_ID}
for ((i=1;i<10;i++));
do
set +e
PODS=$(kubectl get pod -n kruise-system | grep '1/1')
set -e
if [ ! -z "$PODS" ]; then
break
fi
sleep 3
done
set +e
PODS=$(kubectl get pod -n kruise-system | grep '1/1')
set -e
if [ -z "$PODS" ]; then
echo "Timeout to wait for kruise-manager ready"
kubectl get all -n kruise-system -o yaml
exit 1
fi
- name: Run E2E Tests
run: |
export KUBECONFIG=/home/runner/.kube/config
go test ./test/e2e/ -timeout 30m -v

View File

@ -1,24 +0,0 @@
name: "Create cluster using KinD"
on: push
jobs:
kind:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: engineerd/setup-kind@v0.1.0
- name: setup-k8s and install kruise
run: |
export KUBECONFIG="$(kind get kubeconfig-path)"
echo $KUBECONFIG
kubectl cluster-info
kubectl get pods -n kube-system
kubectl apply -f ./config/crds/
kubectl apply -f ./config/manager/all_in_one.yaml
- name: e2e-test
run: |
APP_PATH=/home/runner/go/src/github.com/openkruise/kruise
mkdir -p $APP_PATH
cp -r ./ $APP_PATH
cd $APP_PATH
go test ./test/e2e/ -timeout 60m -v -args "-kubeconfig=/home/runner/.kube/kind-config-kind"

View File

@ -4,4 +4,4 @@
"pattern": "^https://codecov.io"
}
]
}
}

View File

@ -1,13 +0,0 @@
language: go
go:
- "1.14"
go_import_path: github.com/openkruise/kruise
script:
- ./scripts/travis-test.sh
after_success:
- ./hack/docker_build_daily.sh
- bash <(curl -s https://codecov.io/bash) || echo "Failed to report code coverage!"

View File

@ -1,4 +1,3 @@
# Image URL to use all building/pushing image targets
IMG ?= openkruise/kruise-manager:test
# Produce CRDs that work for API servers that supports v1beta1 CRD and conversion, requires k8s 1.13 or later.
@ -40,6 +39,7 @@ uninstall: manifests
deploy: manifests
cd config/manager && kustomize edit set image controller=${IMG}
kustomize build config/default | kubectl apply -f -
echo "resources:\n- manager.yaml" > config/manager/kustomization.yaml
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
@ -78,9 +78,9 @@ ifeq (, $(shell which controller-gen-kruise-2))
echo "replace sigs.k8s.io/controller-tools => github.com/openkruise/controller-tools v0.2.9-kruise.2" >> go.mod ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.9 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
mv $(GOPATH)/bin/controller-gen $(GOPATH)/bin/controller-gen-kruise-2 ;\
mv $(GOBIN)/controller-gen $(GOBIN)/controller-gen-kruise-2 ;\
}
CONTROLLER_GEN=$(GOPATH)/bin/controller-gen-kruise-2
CONTROLLER_GEN=$(GOBIN)/controller-gen-kruise-2
else
CONTROLLER_GEN=$(shell which controller-gen-kruise-2)
endif

View File

@ -19,7 +19,8 @@
## 介绍
Kruise 是 OpenKruise (官网: [https://openkruise.io](https://openkruise.io)) 中的核心项目之一,它提供一套在[Kubernetes核心控制器](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/)之外的扩展 workload 管理和实现。
OpenKruise (官网: [https://openkruise.io](https://openkruise.io)) 是托管在 [Cloud Native Computing Foundation](https://cncf.io/) (CNCF) 下的 Sandbox 项目。
它提供一套在 [Kubernetes核心控制器](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/) 之外的扩展 workload 管理和实现。
目前Kruise 提供了以下 workload 控制器:

View File

@ -19,7 +19,8 @@ English | [简体中文](./README-zh_CN.md)
## Introduction
Kruise is the core of the OpenKruise (official site: [https://openkruise.io](https://openkruise.io)) project. It consists of several controllers which extend and complement the [Kubernetes core controllers](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/) for workload management.
OpenKruise (official site: [https://openkruise.io](https://openkruise.io)) is now hosted by the [Cloud Native Computing Foundation](https://cncf.io/) (CNCF) as a Sandbox Level Project.
It consists of several controllers which extend and complement the [Kubernetes core controllers](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/) for workload management.
As of now, Kruise offers these workload controllers:

View File

@ -27,13 +27,30 @@ spec:
- /manager
args:
- --enable-leader-election
- --logtostderr=true
- --v=5
image: controller:latest
name: manager
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
readinessProbe:
httpGet:
path: readyz
port: 8000
resources:
limits:
cpu: 100m
memory: 30Mi
memory: 50Mi
requests:
cpu: 100m
memory: 20Mi
memory: 50Mi
terminationGracePeriodSeconds: 10
---
apiVersion: v1
kind: Secret
metadata:
name: webhook-certs
namespace: system

View File

@ -2,5 +2,8 @@ resources:
- manifests.yaml
- service.yaml
patchesStrategicMerge:
- patch_manifests.yaml
configurations:
- kustomizeconfig.yaml

View File

@ -0,0 +1,10 @@
apiVersion: admissionregistration.k8s.io/v1beta1
kind: MutatingWebhookConfiguration
metadata:
name: mutating-webhook-configuration
webhooks:
- name: mpod.kb.io
namespaceSelector:
matchExpressions:
- key: control-plane
operator: DoesNotExist

View File

@ -7,6 +7,6 @@ metadata:
spec:
ports:
- port: 443
targetPort: 9443
targetPort: 9876
selector:
control-plane: controller-manager

View File

@ -2,21 +2,7 @@
These tutorials walk through several examples to demonstrate how to use the Kruise Workloads to deploy and manage applications
## Install Kruise
Install Kruise with helm v3, which is a simple command-line tool and you can get it from [here](https://github.com/helm/helm/releases).
```bash
helm install kruise https://github.com/openkruise/kruise/releases/download/v0.5.0/kruise-chart.tgz
```
Verify Kruise-manager is running:
```bash
$ kubectl get pods -n kruise-system
NAME READY STATUS RESTARTS AGE
kruise-controller-manager-0 1/1 Running 0 4m11s
```
[Install Kruise](../../README.md)
## Add AppHub as your helm repo

View File

@ -44,8 +44,11 @@ var (
isNotNotFound = func(err error) bool { return !errors.IsNotFound(err) }
)
func Init(cfg *rest.Config) {
func init() {
_ = apis.AddToScheme(internalScheme)
}
func Init(cfg *rest.Config) {
discoveryClient = discovery.NewDiscoveryClientForConfigOrDie(cfg)
}

View File

@ -1,9 +1,12 @@
/*
Copyright 2020 The Kruise Authors.
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.
@ -14,17 +17,11 @@ limitations under the License.
package webhook
import (
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/util/gate"
"github.com/openkruise/kruise/pkg/webhook/advancedcronjob/mutating"
"github.com/openkruise/kruise/pkg/webhook/advancedcronjob/validating"
)
func init() {
if !gate.ResourceEnabled(&appsv1alpha1.AdvancedCronJob{}) {
return
}
addHandlers(mutating.HandlerMap)
addHandlers(validating.HandlerMap)
}

View File

@ -1,9 +1,12 @@
/*
Copyright 2020 The Kruise Authors.
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.

View File

@ -1,9 +1,12 @@
/*
Copyright 2020 The Kruise Authors.
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.

View File

@ -48,10 +48,14 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)
var (
const (
mutatingWebhookConfigurationName = "kruise-mutating-webhook-configuration"
validatingWebhookConfigurationName = "kruise-validating-webhook-configuration"
defaultResyncPeriod = time.Minute
)
var (
namespace = webhookutil.GetNamespace()
secretName = webhookutil.GetSecretName()
@ -211,6 +215,7 @@ func (c *Controller) processNextWorkItem() bool {
err := c.sync()
if err == nil {
c.queue.AddAfter(key, defaultResyncPeriod)
c.queue.Forget(key)
return true
}

View File

@ -64,9 +64,9 @@ check_at_least_version() {
# Compare versions
VERS_LEAST="$PROG_NAME version '$CUR_VERS' should be at least '$MIN_VERS'"
test "$CUR_MAJ" -gt $(expr "$MIN_MAJ" - 1) || die_upgrade "$VERS_LEAST"
test "$CUR_MAJ" -gt $(("$MIN_MAJ" - 1)) || die_upgrade "$VERS_LEAST"
test "$CUR_MAJ" -gt "$MIN_MAJ" || {
test "$CUR_MIN" -gt $(expr "$MIN_MIN" - 1) || die_upgrade "$VERS_LEAST"
test "$CUR_MIN" -gt $(("$MIN_MIN" - 1)) || die_upgrade "$VERS_LEAST"
test "$CUR_MIN" -gt "$MIN_MIN" || {
test "$CUR_FIX" -ge "$MIN_FIX" || die_upgrade "$VERS_LEAST"
}

View File

@ -584,7 +584,8 @@ var _ = SIGDescribe("StatefulSet", func() {
ss.Spec.UpdateStrategy = appsv1alpha1.StatefulSetUpdateStrategy{
Type: apps.RollingUpdateStatefulSetStrategyType,
RollingUpdate: &appsv1alpha1.RollingUpdateStatefulSetStrategy{
PodUpdatePolicy: appsv1alpha1.InPlaceIfPossiblePodUpdateStrategyType,
PodUpdatePolicy: appsv1alpha1.InPlaceIfPossiblePodUpdateStrategyType,
InPlaceUpdateStrategy: &appspub.InPlaceUpdateStrategy{GracePeriodSeconds: 10},
},
}
ss.Spec.Template.Spec.ReadinessGates = append(ss.Spec.Template.Spec.ReadinessGates, v1.PodReadinessGate{ConditionType: appspub.InPlaceUpdateReady})

View File

@ -30,12 +30,17 @@ import (
func init() {
// Register framework flags, then handle flags and Viper config.
framework.HandleFlags()
//framework.HandleFlags()
framework.AfterReadingAllFlags(&framework.TestContext)
//framework.AfterReadingAllFlags(&framework.TestContext)
}
func TestE2E(t *testing.T) {
// Register framework flags, then handle flags and Viper config.
framework.HandleFlags()
framework.AfterReadingAllFlags(&framework.TestContext)
err := kruiseapis.AddToScheme(scheme.Scheme)
if err != nil {
t.Fatal(err)

View File

@ -130,6 +130,7 @@ func (f *Framework) BeforeEach() {
if f.ClientSet == nil {
ginkgo.By("Creating a kubernetes client")
config, err := LoadConfig()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
testDesc := ginkgo.CurrentGinkgoTestDescription()
if len(testDesc.ComponentTexts) > 0 {
componentTexts := strings.Join(testDesc.ComponentTexts, " ")
@ -139,7 +140,6 @@ func (f *Framework) BeforeEach() {
componentTexts)
}
gomega.Expect(err).NotTo(gomega.HaveOccurred())
config.QPS = f.Options.ClientQPS
config.Burst = f.Options.ClientBurst
if f.Options.GroupVersion != nil {

View File

@ -751,7 +751,7 @@ func DeleteAllStatefulSets(c clientset.Interface, kc kruiseclientset.Interface,
// NewStatefulSetPVC returns a PersistentVolumeClaim named name, for testing StatefulSets.
func NewStatefulSetPVC(name string) v1.PersistentVolumeClaim {
quantity, _ := resource.ParseQuantity("20Gi")
//quantity, _ := resource.ParseQuantity("20Gi")
return v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: name,
@ -762,7 +762,7 @@ func NewStatefulSetPVC(name string) v1.PersistentVolumeClaim {
},
Resources: v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceStorage: quantity, //*resource.NewQuantity(1, resource.BinarySI),
v1.ResourceStorage: *resource.NewQuantity(1, resource.BinarySI),
},
},
},