diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..64debed --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,117 @@ +name: CI + +on: + push: + branches: + - master + - release-* + pull_request: {} + workflow_dispatch: {} + +env: + # Common versions + GO_VERSION: '1.16' + GOLANGCI_VERSION: 'v1.42.1' + DOCKER_BUILDX_VERSION: 'v0.4.2' + +jobs: + + check-license: + runs-on: ubuntu-18.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Run Check License + run: hack/make-rules/check_license.sh + + golangci-lint: + runs-on: ubuntu-18.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + - name: Lint golang code + uses: golangci/golangci-lint-action@v3 + with: + version: ${{ env.GOLANGCI_VERSION }} + args: -v + + 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 "*" | xargs misspell -error + - name: Lint markdown files + run: find ./ -name "*.md" | grep -v enhancements | grep -v .github | xargs mdl -r ~MD010,~MD013,~MD014,~MD022,~MD024,~MD029,~MD031,~MD032,~MD033,~MD034,~MD036 +# - name: Check markdown links +# run: | +# set +e +# for name in $(find . -name \*.md | 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: 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 test + - name: Publish Unit Test Coverage + uses: codecov/codecov-action@v3 + with: + name: codecov-umbrella + token: ${{ secrets.CODECOV_TOKEN }} + flags: unittests + files: ./cover.out + fail_ci_if_error: true + verbose: true + build-binaries: + 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: 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: Build All Binaries + run: make build diff --git a/.gitignore b/.gitignore index c953869..3cbf01f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ dockerbuild *.out logs +bin bin/controller-gen bin/kustomize diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..aba409c --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,48 @@ +# This file contains all available configuration options +# with their default values. + +# options for analysis running +run: + go: '1.16' + # default concurrency is a available CPU number + concurrency: 4 + + # timeout for analysis, e.g. 30s, 5m, default is 1m + timeout: 15m + + # exit code when at least one issue was found, default is 1 + issues-exit-code: 1 + + # include test files or not, default is true + tests: true + +# output configuration options +output: + # colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions + # default is "colored-line-number" + format: colored-line-number + + # print lines of code with issue, default is true + print-issued-lines: true + + # print linter name in the end of issue text, default is true + print-linter-name: true + + # make issues output unique by line, default is true + uniq-by-line: true + +# all available settings of specific linters +linters-settings: + gci: + local-prefixes: github.com/openyurtio + +linters: + disable-all: true + enable: + - deadcode + - gofmt + - goimports + - gci + - ineffassign + - misspell + - vet diff --git a/Makefile b/Makefile index 64e32ed..7589c99 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ ifneq (${https_proxy},) DOCKER_BUILD_ARGS += --build-arg https_proxy='${https_proxy}' endif -.PHONY: clean all release build +.PHONY: clean all build all: test build @@ -67,7 +67,6 @@ docker-push: clean: -rm -Rf _output - -rm -Rf dockerbuild generate: controller-gen manifests generate-goclient @@ -115,6 +114,9 @@ GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint golangci-lint: ## Download golangci-lint locally if necessary. $(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.42.1) +lint: golangci-lint ## Run go lint against code. + $(GOLANGCI_LINT) run -v + GINKGO = $(shell pwd)/bin/ginkgo ginkgo: ## Download ginkgo locally if necessary. $(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/ginkgo@v1.16.4) diff --git a/README.md b/README.md index a45f287..ddec519 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,21 @@ This repository contains 4 CRD/controllers: NodePool, YurtAppSet, YurtAppDaemon and YurtIngress. -The NodePool provides a convenient management experience for a pool of nodes within the same region or site. -The YurtAppSet defines a new edge application management methodology of using per node pool workload. -The YurtAppDaemon provides a similar K8S DaemonSet support for user app workload from the NodePool level. -The YurtIngress is responsible to deploy configurable ingress controller to the user specified NodePools. +The NodePool provides a convenient management experience for a pool of nodes within the same region or site. -For details of the design, please see the documents below: -NodePool and YurtAppSet: [document](https://github.com/openyurtio/openyurt/blob/master/docs/enhancements/20201211-nodepool_uniteddeployment.md). -YurtAppDaemon: [document](https://github.com/openyurtio/openyurt/blob/master/docs/enhancements/20210729-yurtappdaemon.md). -YurtIngress: [document](https://github.com/openyurtio/openyurt/blob/master/docs/proposals/20210628-nodepool-ingress-support.md). +The YurtAppSet defines a new edge application management methodology of using per node pool workload. + +The YurtAppDaemon provides a similar K8S DaemonSet support for user app workload from the NodePool level. + +The YurtIngress is responsible to deploy configurable ingress controller to the user specified NodePools. + +For details of the design, please see the documents below: + +NodePool and YurtAppSet: [document](https://github.com/openyurtio/openyurt/blob/master/docs/enhancements/20201211-nodepool_uniteddeployment.md). + +YurtAppDaemon: [document](https://github.com/openyurtio/openyurt/blob/master/docs/enhancements/20210729-yurtappdaemon.md). + +YurtIngress: [document](https://github.com/openyurtio/openyurt/blob/master/docs/proposals/20210628-nodepool-ingress-support.md). ## Getting Start @@ -21,7 +27,7 @@ For a complete example, please check out the [tutorial](docs/yurt-app-manager-tu ## Contributing -Contributions are welcome, whether by creating new issues or pull requests. See +Contributions are welcome, whether by creating new issues or pull requests. See our [contributing document](https://github.com/openyurtio/openyurt/blob/master/CONTRIBUTING.md) to get started. ## Contact @@ -35,8 +41,8 @@ our [contributing document](https://github.com/openyurtio/openyurt/blob/master/C ## License -Yurt-app-manager is under the Apache 2.0 license. See the [LICENSE](LICENSE) file -for details. Certain implementations in Yurt-app-manager rely on the existing code -from [Kubernetes](https://github.com/kubernetes/kubernetes) and -[OpenKruise](https://github.com/openkruise/kruise) the credits go to the +Yurt-app-manager is under the Apache 2.0 license. See the [LICENSE](LICENSE) file +for details. Certain implementations in Yurt-app-manager rely on the existing code +from [Kubernetes](https://github.com/kubernetes/kubernetes) and +[OpenKruise](https://github.com/openkruise/kruise) the credits go to the original authors. diff --git a/cmd/yurt-app-manager/app-manager.go b/cmd/yurt-app-manager/app-manager.go index eda349c..08f450c 100644 --- a/cmd/yurt-app-manager/app-manager.go +++ b/cmd/yurt-app-manager/app-manager.go @@ -21,9 +21,10 @@ import ( "math/rand" "time" - "github.com/openyurtio/yurt-app-manager/cmd/yurt-app-manager/app" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/klog" + + "github.com/openyurtio/yurt-app-manager/cmd/yurt-app-manager/app" ) func main() { diff --git a/cmd/yurt-app-manager/app/core.go b/cmd/yurt-app-manager/app/core.go index dd78b0a..1b8c9d0 100644 --- a/cmd/yurt-app-manager/app/core.go +++ b/cmd/yurt-app-manager/app/core.go @@ -23,14 +23,6 @@ import ( "net/http" "os" - "github.com/openyurtio/yurt-app-manager/cmd/yurt-app-manager/options" - "github.com/openyurtio/yurt-app-manager/pkg/projectinfo" - appsv1alpha1 "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/apis/apps/v1alpha1" - extclient "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/client" - "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/constant" - "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/controller" - "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/util/fieldindex" - "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/webhook" "github.com/spf13/cobra" "github.com/spf13/pflag" "k8s.io/apimachinery/pkg/runtime" @@ -41,7 +33,15 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log/zap" - // +kubebuilder:scaffold:imports + + "github.com/openyurtio/yurt-app-manager/cmd/yurt-app-manager/options" + "github.com/openyurtio/yurt-app-manager/pkg/projectinfo" + appsv1alpha1 "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/apis/apps/v1alpha1" + extclient "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/client" + "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/constant" + "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/controller" + "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/util/fieldindex" + "github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/webhook" ) var ( diff --git a/docs/YurtAppDaemon.md b/docs/YurtAppDaemon.md index 13c03f4..580a7ba 100644 --- a/docs/YurtAppDaemon.md +++ b/docs/YurtAppDaemon.md @@ -1,5 +1,3 @@ - - # Description
In edge scenarios,edge nodes from the same region are allocated to the same nodepool, generally it is necessary to deploy some system components at the nodepool level, such as CoreDNS. When a nodepool is created, we want these system components bo be created automatically without any manual actions. @@ -12,8 +10,8 @@ - Support Deployment and Statefulset as template - Support template update and trigger sub-resources update, such as image update of the Deployment template will trigger the child Deployment image update accordingly - Support auto distribution of the template resources from the nodepool level: - - When the nodepools match the corresponding label, sub-resources are created automatically - - When the nodepools delete the corresponding label, sub-resources are deleted automatically + - When the nodepools match the corresponding label, sub-resources are created automatically + - When the nodepools delete the corresponding label, sub-resources are deleted automatically ​
@@ -34,8 +32,6 @@ ## create nodepool test1 ```bash cat < ## create nodepool test2 ```bash @@ -155,7 +150,6 @@ kubectl get deployments.apps # Check the Pod ``` - ## remove nodepool label ```bash diff --git a/docs/yurt-app-manager-dev-tutorial.md b/docs/yurt-app-manager-dev-tutorial.md index 754d0fa..1e3c269 100644 --- a/docs/yurt-app-manager-dev-tutorial.md +++ b/docs/yurt-app-manager-dev-tutorial.md @@ -1,15 +1,15 @@ # Yurt-app-manager Tutorial for Developor -This document introduces how to build and install yurt-app-manager controller. +This document introduces how to build and install yurt-app-manager controller. ## Label cloud nodes and edge nodes ``` bash $ kubectl get nodes -o wide -NAME STATUS ROLES AGE VERSION INTERNAL-IP -k8s-node1 Ready 20d v1.16.2 10.48.115.9 -k8s-node2 Ready 20d v1.16.2 10.48.115.10 -master Ready master 20d v1.16.2 10.48.115.8 +NAME STATUS ROLES AGE VERSION INTERNAL-IP +k8s-node1 Ready 20d v1.16.2 10.48.115.9 +k8s-node2 Ready 20d v1.16.2 10.48.115.10 +master Ready master 20d v1.16.2 10.48.115.8 ``` and we will use node `master` as the cloud node. @@ -27,7 +27,7 @@ $ kubectl label node k8s-node2 openyurt.io/is-edge-worker=true k8s-node2 labeled ``` -## clone yurt-app-manger code +## clone yurt-app-manger code ``` # cd $GOPATH/src/github.com/openyurtio # git clone git@github.com:openyurtio/yurt-app-manager.git @@ -41,23 +41,22 @@ for example make push REPO=registry.cn-your-registry.com/edge-kubernetes ``` -if REPO value is assigned `registry.cn-your-registry.com/edge-kubernetes`, the `make push ` command will eventually build an image named registry.cn-your-registry.com/edge-kubernetes/yurt-app-manager:{git commit id} and push it into your own repository. And `make push` command will also create a file named `yurt-app-manager.yaml` in _output/yamls dir. You need to set the REPO variable correctly。 +if REPO value is assigned `registry.cn-your-registry.com/edge-kubernetes`, the `make push` command will eventually build an image named registry.cn-your-registry.com/edge-kubernetes/yurt-app-manager:{git commit id} and push it into your own repository. And `make push` command will also create a file named `yurt-app-manager.yaml` in _output/yamls dir. You need to set the REPO variable correctly。 ## install nodepool and yurtappset controller ``` kubectl apply -f _output/yamls/yurt-app-manager.yaml ``` -## check +## check -> use `kubectl get crd` command to check that the CRD is successfully installed +> use `kubectl get crd` command to check that the CRD is successfully installed ``` # kubectl get crd -nodepools.apps.openyurt.io 2021-04-23T08:54:31Z +nodepools.apps.openyurt.io 2021-04-23T08:54:31Z yurtappsets.apps.openyurt.io 2021-04-23T08:54:31Z ``` - -> use `kubectl get pod -n kube-system` command to check whether the yurt-app-manager pod is running +> use `kubectl get pod -n kube-system` command to check whether the yurt-app-manager pod is running ``` # kubectl get pod -n kube-system yurt-app-manager-78f657cbf4-c94gm 1/1 Running 0 5d2h diff --git a/docs/yurt-app-manager-tutorial.md b/docs/yurt-app-manager-tutorial.md index 4f5ea8b..40b9a83 100644 --- a/docs/yurt-app-manager-tutorial.md +++ b/docs/yurt-app-manager-tutorial.md @@ -1,8 +1,8 @@ -# Yurt-app-manager Tutorial +# Yurt-app-manager Tutorial -This document introduces how to install yurt-app-manager and use yurt-app-manager to manage edge nodes and workloads. +This document introduces how to install yurt-app-manager and use yurt-app-manager to manage edge nodes and workloads. -In this tutorial, we will show how the yurt-app-manager helps users manage +In this tutorial, we will show how the yurt-app-manager helps users manage there edge nodes and workload. Suppose you have a Kubernetes cluster in an Openyurt environment, or a native Kubernetes cluster with at least two nodes. @@ -10,10 +10,10 @@ Suppose you have a Kubernetes cluster in an Openyurt environment, or a native Ku ``` bash $ kubectl get nodes -o wide -NAME STATUS ROLES AGE VERSION INTERNAL-IP -k8s-node1 Ready 20d v1.16.2 10.48.115.9 -k8s-node2 Ready 20d v1.16.2 10.48.115.10 -master Ready master 20d v1.16.2 10.48.115.8 +NAME STATUS ROLES AGE VERSION INTERNAL-IP +k8s-node1 Ready 20d v1.16.2 10.48.115.9 +k8s-node2 Ready 20d v1.16.2 10.48.115.10 +master Ready master 20d v1.16.2 10.48.115.8 ``` and we will use node `master` as the cloud node. @@ -33,14 +33,14 @@ k8s-node2 labeled ## Install yurt-app-manager -### install yurt-app-manager operator -```bash -$ cd yurt-app-manager +### install yurt-app-manager operator +``` +$ cd yurt-app-manager $ kubectl apply -f config/setup/all_in_one.yaml ``` Wait for the yurt-app-manager operator to be created successfully -``` bash +``` $ kubectl get pod -n kube-system |grep yurt-app-manager ``` @@ -48,10 +48,10 @@ $ kubectl get pod -n kube-system |grep yurt-app-manager The Examples of NodePool and YurtAppSet are in `config/yurt-app-manager/samples/` directory -### NodePool +### NodePool -- 1 create an nodepool -```bash +- 1 create an nodepool +``` bash $ cat <