Commit 864549ea authored by engow's avatar engow
Browse files

init kstone

Showing with 1515 additions and 0 deletions
+1515 -0
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore all files which are not go type
!**/*.go
!**/*.mod
!**/*.sum
.gitignore 0 → 100644
# OSX leaves these everywhere on SMB shares
._*
# OSX trash
.DS_Store
# Eclipse files
.classpath
.project
.settings/**
# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA
.idea/
*.iml
# Vscode files
.vscode
# This is where the result of the go build goes
/output*/
/_output*/
/_output
# Emacs save files
*~
\#*\#
.\#*
# Vim-related files
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
# cscope-related files
cscope.*
# Go test binaries
*.test
/hack/.test-cmd-auth
# JUnit test output from ginkgo e2e tests
/junit*.xml
# Mercurial files
**/.hg
**/.hg*
# Vagrant
.vagrant
network_closure.sh
# Local cluster env variables
/cluster/env.sh
# Compiled binaries in third_party
/third_party/pkg
# Also ignore etcd installed by hack/install-etcd.sh
/default.etcd
# User cluster configs
.kubeconfig
.tags*
# Version file for dockerized build
.dockerized-kube-version-defs
# Web UI
/www/master/node_modules/
/www/master/npm-debug.log
/www/master/shared/config/development.json
# Karma output
/www/test_out
# precommit temporary directories created by ./hack/verify-generated-docs.sh and ./hack/lib/util.sh
/_tmp/
/doc_tmp/
# Test artifacts produced by Jenkins jobs
/_artifacts/
# Go dependencies installed on Jenkins
/_gopath/
# Config directories created by gcloud and gsutil on Jenkins
/.config/gcloud*/
/.gsutil/
# CoreOS stuff
/cluster/libvirt-coreos/coreos_*.img
# Downloaded kstone binary release
/kstone/
*.exe
*.exe~
*.dll
*.so
*.dylib
bin
testbin/*
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# direnv .envrc files
.envrc
# Downloaded kstone binary release tar ball
kstone.tar.gz
# generated files in any directory
# TODO(thockin): uncomment this when we stop committing the generated files.
#zz_generated.*
zz_generated.openapi.go
zz_generated_*_test.go
# make-related metadata
/.make/
# Just in time generated data in the source, should never be committed
/test/e2e/generated/bindata.go
# This file used by some vendor repos (e.g. github.com/go-openapi/...) to store secret variables and should not be ignored
!\.drone\.sec
/bazel-*
*.pyc
# generated by verify-vendor.sh
vendor
vendordiff.patch
/bin
/127.0.0.1.etcd
/docker/build
\ No newline at end of file
run:
# timeout for analysis, e.g. 30s, 5m
deadline: 10m
# include test files or not
tests: true
# disallowed from the implicit automatic updating of go.mod described above
modules-download-mode: readonly
# which dirs to skip: they won't be analyzed;
skip-dirs:
- third_party
- api
- web
- pkg/gateway/apis/config
- pkg/gateway/apis/config/v1
- pkg/registry/apis/config
- pkg/registry/apis/config/v1
- pkg/registry/harbor/client
- pkg/registry/harbor/helmClient
- pkg/monitor/apis/config
- pkg/monitor/apis/config/v1
linters:
disable-all: true
enable:
- unused
- gofmt
- ineffassign
- govet
- deadcode
- structcheck
- varcheck
- typecheck
- golint
- unconvert
- staticcheck
- gosimple
issues:
exclude-rules:
- linters:
- staticcheck
text: "SA1019:"
service:
golangci-lint-version: 1.20.x
LICENSE 0 → 100644
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.
Makefile 0 → 100644
.PHONY: all
all: lint build
# ==============================================================================
# Build options
ROOT_PACKAGE=tkestack.io/kstone
VERSION_PACKAGE=tkestack.io/kstone/pkg/app/version
# ==============================================================================
# Includes
include build/lib/common.mk
include build/lib/golang.mk
include build/lib/image.mk
include build/lib/gen.mk
# ==============================================================================
# Usage
define USAGE_OPTIONS
Options:
DEBUG Whether to generate debug symbols. Default is 0.
BINS The binaries to build. Default is all of cmd.
This option is available when using: make build/build.multiarch
Example: make build BINS="kstone-api kstone-controller"
IMAGES Backend images to make. Default is all of cmd starting with kstone-.
This option is available when using: make image/image.multiarch/push/push.multiarch
Example: make image.multiarch IMAGES="kstone-api kstone-controller"
PLATFORMS The multiple platforms to build. Default is linux_amd64 and linux_arm64.
This option is available when using: make build.multiarch/image.multiarch/push.multiarch
Example: make image.multiarch IMAGES="kstone-api kstone-controller" PLATFORMS="linux_amd64 linux_arm64"
VERSION The version information compiled into binaries.
The default is obtained from git.
V Set to 1 enable verbose build. Default is 0.
endef
export USAGE_OPTIONS
# ==============================================================================
# Targets
## gen: Generate codes for API definitions.
.PHONY: gen
gen:
@$(MAKE) gen.run
## build: Build source code for host platform.
.PHONY: build
build:
@$(MAKE) go.build
## build.multiarch: Build source code for multiple platforms. See option PLATFORMS.
.PHONY: build.multiarch
build.multiarch:
@$(MAKE) go.build.multiarch
## image: Build docker images for host arch.
.PHONY: image
image:
@$(MAKE) image.build
## image.multiarch: Build docker images for multiple platforms. See option PLATFORMS.
.PHONY: image.multiarch
image.multiarch:
@$(MAKE) image.build.multiarch
## push: Build docker images for host arch and push images to registry.
.PHONY: push
push:
@$(MAKE) image.push
## push.multiarch: Build docker images for multiple platforms and push images to registry.
.PHONY: push.multiarch
push.multiarch:
@$(MAKE) image.push.multiarch
## manifest: Build docker images for host arch and push manifest list to registry.
.PHONY: manifest
manifest:
@$(MAKE) image.manifest.push
## manifest.multiarch: Build docker images for multiple platforms and push manifest lists to registry.
.PHONY: manifest.multiarch
manifest.multiarch:
@$(MAKE) image.manifest.push.multiarch
## clean: Remove all files that are created by building.
.PHONY: clean
clean:
@$(MAKE) go.clean
## lint: Check syntax and styling of go sources.
.PHONY: lint
lint:
@$(MAKE) go.lint
## test: Run unit test.
.PHONY: test
test:
@$(MAKE) go.test
## release-test: test release
.PHONY: release-test
release-test:
@go test -v -timeout=1200m tkestack.io/kstone/test/e2e
## help: Show this help info.
.PHONY: help
help: Makefile
@echo -e "\nUsage: make <TARGETS> <OPTIONS> ...\n\nTargets:"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo "$$USAGE_OPTIONS"
README.md 0 → 100644
# Kstone
<div align=center><img width=800 hight=300 src="docs/images/icon.png" /></div>
------
[中文](README_CN.md)
Kstone is an [etcd](https://github.com/etcd-io/etcd) management platform, providing cluster management, monitoring, backup, inspection, data migration, visual viewing of etcd data, and intelligent diagnosis.
Kstone will help you efficiently manage etcd clusters, significantly reduce operation and maintenance costs, discover potential hazards in time, and improve the stability and user experience of k8s etcd storage.
------
## Features
* Supports registration of existing clusters and creation of new etcd clusters.
* Support prometheus monitoring, built-in rich etcd grafana panel diagram.
* Support multiple data backup methods (minute-level backup to object storage, real-time backup by deploying learner).
* Support multiple inspection strategies (data consistency, health, hot write requests, number of resource objects, etc.).
* Built-in web console and visual view etcd data.
* Lightweight, easy to install.
* Support data migration(to do list).
* Support intelligent diagnosis(to do list).
## Architecture
Kstone consists of 5 components: kstone-etcdcluster-controller,kstone-etcd-operator,kstone-etcdinspection-controller,kstone-api, kstone-dashboard.
![Architecture Of Kstone](docs/images/kstone-arch.png)
## Components
### [kstone](https://github.com/tkestack/kstone)
kstone consists of kstone-etcdcluster-controller,kstone-etcdinspection-controller,kstone-api.
### [kstone-etcd-operator](https://github.com/tkestack/kstone-etcd-operator)
kstone-etcd-operator provides rich etcd cluster management capabilities.It will also be open source soon.
### [kstone-dashboard](https://github.com/tkestack/kstone-dashboard)
The web management system provided by kstone is as follows:
![kstone-ui](docs/images/kstone-ui.png)
## Installation
Please read [the detailed installation document](charts),
You can quickly install kstone through helm.
## Developing
### Build
``` shell
mkdir -p ~/tkestack
cd ~/tkestack
git clone https://github.com/tkestack/kstone
cd kstone
make
```
## Community
* You are encouraged to communicate most things via GitHub [issues](https://github.com/tkestack/kstone/issues/new/choose) or [pull requests](https://github.com/tkestack/kstone/pulls).
## Licensing
Kstone is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text.
# Kstone
<div align=center><img width=800 hight=300 src="docs/images/icon.png" /></div>
------
[English](README.md)
Kstone 是一个针对 [etcd](https://github.com/etcd-io/etcd) 的全方位运维解决方案,提供集群管理(关联已有集群、创建新集群等)、监控、备份、巡检、数据迁移、数据可视化、智能诊断等一系列特性。
Kstone 将帮助你高效管理etcd集群,显著降低运维成本、及时发现潜在隐患、提升k8s etcd存储的稳定性和用户体验。
------
## 特性
Kstone 是一个 [etcd](https://github.com/etcd-io/etcd) 的治理平台,它有以下特点.
* 轻量,安装方便
* 支持导入已有集群、创建新etcd集群
* 支持Prometheus监控,内置丰富的etcd Grafana面板图
* 支持多种数据备份方式(分钟级备份到对象存储、部署Learner实时备份)
* 支持多种巡检策略(数据一致性、健康度、写请求、资源对象数等)
* 支持可视化查看etcd数据(特别支持Kubernetes资源对象数据的可视化查看)
* 极大简化运维成本,在集群导入、创建完成时,即可自动开启监控、备份、巡检等特性
## 核心架构
Kstone 由5个组件组成:kstone-etcdcluster-controller,kstone-etcd-operator,kstone-etcdinspection-controller,kstone-api, kstone-dashboard.
![Architecture Of Kstone](docs/images/kstone-arch.png)
## 组件
### kstone-etcdcluster-controller
* 关联已有集群,如已有的kubernetes集群etcd
* 根据EtcdCluster资源所描述的集群元信息,调用ClusterProvider,创建、更新、删除etcd集群
* 根据EtcdCluster资源所描述的特性开关,开启或关闭监控、备份、巡检等特性(创建EtcdInspection资源)
### kstone-etcdinspection-controller
* 实时监听EtcdInspection资源,调用后端FeatureProvider执行巡检
### kstone-api
* 提供了一系列etcd集群管理的api给web前端使用
## [kstone-dashboard](https://github.com/tkestack/kstone-dashboard)
Kstone 提供的WEB管理系统如下:
![kstone-ui](docs/images/kstone-ui.png)
### [kstone-etcd-operator](https://github.com/tkestack/kstone-etcd-operator)
kstone-etcd-operator提供丰富的集群管理能力(此组件也即将开源)。
## 安装
请阅读[部署文档](charts/README_CN.md),
你可通过Helm快速安装Kstone。
## 开发
### 构建
```
mkdir -p ~/tkestack
cd ~/tkestack
git clone https://github.com/tkestack/kstone
cd kstone
make
```
## 社区
欢迎大家提交issue和pull request来一起完善、提升Kstone.
## License
Kstone is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text.
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
FROM BASE_IMAGE
RUN echo "hosts: files dns" >> /etc/nsswitch.conf
WORKDIR /app
ADD kstone-api /app/bin/
ENTRYPOINT ["/app/bin/kstone-api"]
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
FROM BASE_IMAGE
RUN echo "hosts: files dns" >> /etc/nsswitch.conf
WORKDIR /app
ADD kstone-controller /app/bin/
ENTRYPOINT ["/app/bin/kstone-controller"]
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
FROM golang:1.16-alpine
RUN apk add --update --no-cache autoconf automake libtool zlib-dev build-base curl git
# Install the protobuf
ENV PROTOBUF_VERSION 3.17.3
ENV PROTOBUF_URL=https://github.com/protocolbuffers/protobuf/archive/v${PROTOBUF_VERSION}.tar.gz
RUN curl -L ${PROTOBUF_URL} -o - | tar -xz -C /tmp
RUN cd /tmp/protobuf-* && \
./autogen.sh && \
./configure --disable-shared --enable-static && \
make --silent -j `nproc` install-strip
RUN cd /tmp && rm -rf protobuf-$PROTOBUF_VERSION \
&& protoc --version
ENV GOPATH=/go
ENV GO111MODULE=off
# Clone the kubernetes
ENV KUBERNETES_VERSION 1.21.3
RUN mkdir -p $GOPATH/src/k8s.io \
&& git clone -b v$KUBERNETES_VERSION --single-branch https://github.com/kubernetes/kubernetes.git $GOPATH/src/k8s.io/kubernetes
RUN apk add --update --no-cache rsync file patch
RUN cd $GOPATH/src/k8s.io/kubernetes \
&& make WHAT="cmd/genswaggertypedocs vendor/k8s.io/code-generator/cmd/defaulter-gen vendor/k8s.io/code-generator/cmd/client-gen vendor/k8s.io/code-generator/cmd/lister-gen vendor/k8s.io/code-generator/cmd/informer-gen vendor/k8s.io/code-generator/cmd/deepcopy-gen vendor/k8s.io/code-generator/cmd/conversion-gen vendor/k8s.io/code-generator/cmd/go-to-protobuf vendor/k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo"
RUN ln -s $GOPATH/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery $GOPATH/src/k8s.io/apimachinery \
&& ln -s $GOPATH/src/k8s.io/kubernetes/vendor/k8s.io/api $GOPATH/src/k8s.io/api
# work around 64MB tmpfs size in Docker 1.6
ENV TMPDIR /tmp.k8s
RUN mkdir $TMPDIR \
&& chmod a+rwx $TMPDIR \
&& chmod o+t $TMPDIR
# Get the code coverage tool and goimports
RUN go get golang.org/x/tools/cmd/cover \
golang.org/x/tools/cmd/goimports \
&& go clean -cache
WORKDIR "$GOPATH/src/k8s.io/kubernetes"
ADD code.sh /root/
ADD openapi.sh /root/
ADD boilerplate.go.txt /root/
RUN chmod +x /root/code.sh
RUN chmod +x /root/openapi.sh
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
VERSION = v1.21.3
REGISTRY_PREFIX ?= tkestack
IMAGE_NAME ?= code-generator
.PHONY: all
all: build push
.PHONY: build
build:
@echo "===========> Building $(IMAGE_NAME) $(VERSION) docker image"
docker build --pull -t $(REGISTRY_PREFIX)/$(IMAGE_NAME):$(VERSION) -f ./Dockerfile .
.PHONY: push
push:
@echo "===========> Pushing $(IMAGE_NAME) $(VERSION) image to $(REGISTRY_PREFIX)"
docker push $(REGISTRY_PREFIX)/$(IMAGE_NAME):$(VERSION)
/*
* Tencent is pleased to support the open source community by making TKEStack
* available.
*
* Copyright (C) 2012-2023 Tencent. All Rights Reserved.
*
* 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
*
* https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#!/usr/bin/env bash
#
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
set -o errexit
set -o nounset
set -o pipefail
# generate-groups generates everything for a project with external types only, e.g. a project based
# on CustomResourceDefinitions.
if [[ "$#" -lt 4 ]] || [[ "${1}" == "--help" ]]; then
cat <<EOF
Usage: $(basename "$0") <generators> <output-package> <internal-apis-package> <extensiona-apis-package> <groups-versions> ...
<generators> the generators comma separated to run (e.g. deepcopy-external,defaulter-external,client-external,
lister-external,informer-external,deepcopy-internal,defaulter-internal,client-internal,
lister-internal,informer-internal or all-external,all-internal,all).
<output-package> the output package name (e.g. github.com/example/project/pkg/generated).
<int-apis-package> the internal types dir (e.g. github.com/example/project/pkg/apis).
<ext-apis-package> the external types dir (e.g. github.com/example/project/pkg/apis or githubcom/example/apis).
<groups-versions> the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative
to <api-package>.
... arbitrary flags passed to all generator binaries.
Examples:
$(basename "$0") all-external github.com/example/project/pkg/client github.com/example/project/pkg/apis github.com/example/project/apis "foo:v1 bar:v1alpha1,v1beta1"
$(basename "$0") deepcopy-external,client-external github.com/example/project/pkg/client github.com/example/project/pkg/apis github.com/example/project/apis "foo:v1 bar:v1alpha1,v1beta1"
$(basename "$0") all-internal github.com/example/project/pkg/client github.com/example/project/pkg/apis github.com/example/project/apis "foo:v1 bar:v1alpha1,v1beta1"
$(basename "$0") deepcopy-internal,defaulter-internal,conversion-internal github.com/example/project/pkg/client github.com/example/project/pkg/apis github.com/example/project/apis "foo:v1 bar:v1alpha1,v1beta1"
EOF
exit 0
fi
GENS="$1"
OUTPUT_PKG="$2"
INT_APIS_PKG="$3"
EXT_APIS_PKG="$4"
GROUPS_WITH_VERSIONS="$5"
shift 5
GOPATH=${GOPATH:-/go}
K8S_ROOT=${K8S_ROOT:-/go/src/k8s.io/kubernetes}
K8S_BIN=${K8S_ROOT}/_output/bin
PATH=${K8S_BIN}:${PATH}
function codegen_join() { local IFS="$1"; shift; echo "$*"; }
# enumerate group versions
ALL_FQ_APIS=(${ALL_FQ_APIS:-}) # e.g. k8s.io/kubernetes/pkg/apis/apps k8s.io/api/apps/v1
INT_FQ_APIS=(${INT_FQ_APIS:-}) # e.g. k8s.io/kubernetes/pkg/apis/apps
EXT_FQ_APIS=(${EXT_FQ_APIS:-}) # e.g. k8s.io/api/apps/v1
EXT_PB_APIS=(${EXT_PB_APIS:-}) # e.g. k8s.io/api/apps/v1
for GVs in ${GROUPS_WITH_VERSIONS}; do
IFS=: read -r G Vs <<<"${GVs}"
if [[ -n "${INT_APIS_PKG}" ]]; then
ALL_FQ_APIS+=("${INT_APIS_PKG}/${G}")
INT_FQ_APIS+=("${INT_APIS_PKG}/${G}")
fi
# enumerate versions
for V in ${Vs//,/ }; do
ALL_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
EXT_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
done
done
if [[ "${GENS}" = "all" ]] || [[ "${GENS}" = "all-external" ]] || grep -qw "deepcopy-external" <<<"${GENS}"; then
echo "===========> Generating external deepcopy funcs"
"${K8S_BIN}"/deepcopy-gen \
--go-header-file /root/boilerplate.go.txt \
--input-dirs "$(codegen_join , "${EXT_FQ_APIS[@]}")" \
-O zz_generated.deepcopy \
--bounding-dirs "${EXT_APIS_PKG}" \
"$@"
fi
if [[ "${GENS}" = "all" ]] || [[ "${GENS}" = "all-external" ]] || grep -qw "client-external" <<<"${GENS}"; then
echo "===========> Generating external clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/clientset"
"${K8S_BIN}"/client-gen \
--go-header-file /root/boilerplate.go.txt \
--clientset-name versioned \
--input-base "" \
--input "$(codegen_join , "${EXT_FQ_APIS[@]}")" \
--output-package "${OUTPUT_PKG}"/clientset \
"$@"
fi
if [[ "${GENS}" = "all" ]] || [[ "${GENS}" = "all-external" ]] || grep -qw "lister-external" <<<"${GENS}"; then
echo "===========> Generating external listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
"${K8S_BIN}"/lister-gen \
--go-header-file /root/boilerplate.go.txt \
--input-dirs "$(codegen_join , "${EXT_FQ_APIS[@]}")" \
--output-package "${OUTPUT_PKG}"/listers \
"$@"
fi
if [[ "${GENS}" = "all" ]] || [[ "${GENS}" = "all-external" ]] || grep -qw "informer-external" <<<"${GENS}"; then
echo "===========> Generating external informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
"${K8S_BIN}"/informer-gen \
--go-header-file /root/boilerplate.go.txt \
--input-dirs "$(codegen_join , "${EXT_FQ_APIS[@]}")" \
--versioned-clientset-package "${OUTPUT_PKG}"/clientset/versioned \
--listers-package "${OUTPUT_PKG}"/listers \
--output-package "${OUTPUT_PKG}"/informers \
"$@"
fi
if [[ "${GENS}" = "all" ]] || [[ "${GENS}" = "all-external" ]] || grep -qw "defaulter-external" <<<"${GENS}"; then
echo "===========> Generating external defaulters"
"${K8S_BIN}"/defaulter-gen \
--go-header-file /root/boilerplate.go.txt \
--input-dirs "$(codegen_join , "${EXT_FQ_APIS[@]}")" \
-O zz_generated.defaults \
"$@"
fi
if [[ "${GENS}" = "all" ]] || [[ "${GENS}" = "all-external" ]] || grep -qw "conversion-external" <<<"${GENS}"; then
echo "===========> Generating external conversions"
"${K8S_BIN}"/conversion-gen \
--go-header-file /root/boilerplate.go.txt \
--input-dirs "$(codegen_join , "${ALL_FQ_APIS[@]}")" \
-O zz_generated.conversion \
"$@"
fi
\ No newline at end of file
#!/usr/bin/env bash
#
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
set -o errexit
set -o nounset
set -o pipefail
# generate-groups generates openapi for a project with external types only.
if [[ "$#" -lt 2 ]]; then
cat <<EOF
Usage: $(basename "$0") <output-package> <apis-package>
<output-package> the output package name (e.g. github.com/example/project/pkg/openapi).
<apis-package> the types dir (e.g. github.com/example/project/pkg/apis).
Examples:
$(basename "$0") openapi github.com/example/project/pkg github.com/example/project/pkg/apis
EOF
exit 0
fi
OUTPUT_PKG="$1"
APIS_PKG="$2"
GOPATH=${GOPATH:-/go}
K8S_ROOT=${K8S_ROOT:-/go/src/k8s.io/kubernetes}
K8S_BIN=${K8S_ROOT}/_output/bin
PATH=${K8S_BIN}:${PATH}
echo "===========> Generating external openapi codes"
"${K8S_BIN}"/openapi-gen \
-O zz_generated.openapi \
--go-header-file "/root/boilerplate.go.txt" \
--input-dirs "${APIS_PKG}" \
--output-package "${OUTPUT_PKG}"
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
SHELL := /bin/bash
# include the common make file
COMMON_SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
ifeq ($(origin ROOT_DIR),undefined)
ROOT_DIR := $(abspath $(shell cd $(COMMON_SELF_DIR)/../.. && pwd -P))
endif
ifeq ($(origin OUTPUT_DIR),undefined)
OUTPUT_DIR := $(ROOT_DIR)/_output
$(shell mkdir -p $(OUTPUT_DIR))
endif
ifeq ($(origin TOOLS_DIR),undefined)
TOOLS_DIR := $(OUTPUT_DIR)/tools
$(shell mkdir -p $(TOOLS_DIR))
endif
ifeq ($(origin TMP_DIR),undefined)
TMP_DIR := $(OUTPUT_DIR)/tmp
$(shell mkdir -p $(TMP_DIR))
endif
# set the version number. you should not need to do this
# for the majority of scenarios.
ifeq ($(origin VERSION), undefined)
VERSION := $(shell git describe --dirty --always --tags | sed 's/-/./g')
endif
# Check if the tree is dirty. default to dirty
GIT_TREE_STATE:="dirty"
ifeq (, $(shell git status --porcelain 2>/dev/null))
GIT_TREE_STATE="clean"
endif
GIT_COMMIT:=$(shell git rev-parse HEAD)
# The OS must be linux when building docker images
PLATFORMS ?= linux_amd64 linux_arm64
# The OS can be linux/windows/darwin when building binaries
# PLATFORMS ?= darwin_amd64 windows_amd64 linux_amd64 linux_arm64
# Set a specific PLATFORM
ifeq ($(origin PLATFORM), undefined)
ifeq ($(origin GOOS), undefined)
GOOS := $(shell go env GOOS)
endif
ifeq ($(origin GOARCH), undefined)
GOARCH := $(shell go env GOARCH)
endif
PLATFORM := $(GOOS)_$(GOARCH)
# Use linux as the default OS when building images
IMAGE_PLAT := linux_$(GOARCH)
else
GOOS := $(word 1, $(subst _, ,$(PLATFORM)))
GOARCH := $(word 2, $(subst _, ,$(PLATFORM)))
IMAGE_PLAT := $(PLATFORM)
endif
COMMA := ,
SPACE :=
SPACE +=
#!/usr/bin/env bash
#
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
set -o errexit
set -o nounset
set -o pipefail
REGISTRY_PREFIX=${REGISTRY_PREFIX:-"tkestack"}
PLATFORMS=${PLATFORMS:-"linux_amd64 linux_arm64"}
if [ -z ${IMAGE} ]; then
echo "Please provide IMAGE."
exit 1
fi
if [ -z ${VERSION} ]; then
echo "Please provide VERSION."
exit 1
fi
rm -rf ${HOME}/.docker/manifests/docker.io_${REGISTRY_PREFIX}_${IMAGE}-${VERSION}
DES_REGISTRY=${REGISTRY_PREFIX}/${IMAGE}
for platform in ${PLATFORMS}; do
os=${platform%_*}
arch=${platform#*_}
variant=""
if [ ${arch} == "arm64" ]; then
variant="--variant v8"
fi
docker manifest create --amend ${DES_REGISTRY}:${VERSION} \
${DES_REGISTRY}-${arch}:${VERSION}
docker manifest annotate ${DES_REGISTRY}:${VERSION} \
${DES_REGISTRY}-${arch}:${VERSION} \
--os ${os} --arch ${arch} ${variant}
done
docker manifest push --purge ${DES_REGISTRY}:${VERSION}
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# ==============================================================================
################################################
## Makefile helper functions for docker buildx
## Please set VERSION and WORK_DIR before use
## Example: VERSION=$(VERSION) WORK_DIR=$(Dockerfile_DIR) make docker.buildx.linux_amd64.keepalived
################################################
DOCKER := docker
DOCKER_SUPPORTED_API_VERSION ?= 1.40
DOCKER_VERSION ?= 19.03
REGISTRY_PREFIX ?= tkestack
EXTRA_ARGS ?=
_DOCKER_BUILD_EXTRA_ARGS :=
ifdef HTTP_PROXY
_DOCKER_BUILD_EXTRA_ARGS += --build-arg HTTP_PROXY=${HTTP_PROXY}
endif
ifneq ($(EXTRA_ARGS), )
_DOCKER_BUILD_EXTRA_ARGS += $(EXTRA_ARGS)
endif
.PHONY: docker.verify
docker.verify:
$(eval API_VERSION := $(shell $(DOCKER) version | grep -E 'API version: {6}[0-9]' | awk '{print $$3} END { if (NR==0) print 0}' ))
$(eval PASS := $(shell echo "$(API_VERSION) >= $(DOCKER_SUPPORTED_API_VERSION)" | bc))
@if [ $(PASS) -ne 1 ]; then \
$(DOCKER) -v ;\
echo "Unsupported docker version. Docker API version should be greater than $(DOCKER_SUPPORTED_API_VERSION) (Or docker version: $(DOCKER_VERSION))"; \
exit 1; \
fi
.PHONY: docker.buildx.%
docker.buildx.%: docker.verify
$(eval IMAGE := $(word 2,$(subst ., ,$*)))
$(eval PLATFORM := $(word 1,$(subst ., ,$*)))
$(eval OS := $(word 1,$(subst _, ,$(PLATFORM))))
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
$(eval IMAGE_PLAT := $(subst _,/,$(PLATFORM)))
$(eval IMAGE_NAME := $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION))
@echo "===========> Building docker image $(IMAGE) $(VERSION) for $(IMAGE_PLAT)"
DOCKER_CLI_EXPERIMENTAL=enabled $(DOCKER) buildx build --pull --platform $(IMAGE_PLAT) --load \
-t $(IMAGE_NAME) $(_DOCKER_BUILD_EXTRA_ARGS) $(WORK_DIR)
.PHONY: docker.build.%
docker.build.%: docker.verify
$(eval IMAGE := $(word 2,$(subst ., ,$*)))
$(eval PLATFORM := $(word 1,$(subst ., ,$*)))
$(eval OS := $(word 1,$(subst _, ,$(PLATFORM))))
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
$(eval IMAGE_PLAT := $(subst _,/,$(PLATFORM)))
$(eval IMAGE_NAME := $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION))
@echo "===========> Building docker image $(IMAGE) $(VERSION) for $(IMAGE_PLAT)"
$(eval BUILD_SUFFIX := $(_DOCKER_BUILD_EXTRA_ARGS) --pull -t $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION) $(WORK_DIR))
$(DOCKER) build --platform $(IMAGE_PLAT) $(BUILD_SUFFIX)
.PHONY: docker.push.%
docker.push.%: docker.build.%
@echo "===========> Pushing image $(IMAGE_NAME)"
$(DOCKER) push $(IMAGE_NAME)
.PHONY: docker.manifest.%
docker.manifest.%: export DOCKER_CLI_EXPERIMENTAL := enabled
docker.manifest.%: docker.push.% docker.manifest.remove.%
$(eval MANIFEST_NAME := $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION))
@echo "===========> Pushing manifest $(MANIFEST_NAME) and then remove the local manifest list"
@$(DOCKER) manifest create $(MANIFEST_NAME) \
$(IMAGE_NAME)
@$(DOCKER) manifest annotate $(MANIFEST_NAME) \
$(IMAGE_NAME) \
--os $(OS) --arch ${ARCH}
@$(DOCKER) manifest push --purge $(MANIFEST_NAME)
# Docker cli has a bug: https://github.com/docker/cli/issues/954
# If you find your manifests were not updated,
# Please manually delete them in $HOME/.docker/manifests/
# and re-run.
.PHONY: docker.manifest.remove.%
docker.manifest.remove.%:
@rm -rf ${HOME}/.docker/manifests/docker.io_$(REGISTRY_PREFIX)_$(IMAGE)-$(VERSION)
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# set the kubernetes apimachinery package dir
K8S_APIMACHINERY_DIR = $(shell go list -f '{{ .Dir }}' -m k8s.io/apimachinery)
# set the kubernetes api package dir
K8S_API_DIR = $(shell go list -f '{{ .Dir }}' -m k8s.io/api)
# set the gogo protobuf package dir
GOGO_PROTOBUF_DIR = $(shell go list -f '{{ .Dir }}' -m github.com/gogo/protobuf)
EXT_PB_APIS = "k8s.io/api/core/v1 k8s.io/api/apps/v1"
# set the code generator image version
CODE_GENERATOR_VERSION := v1.21.3
.PHONY: gen.run
gen.run: gen.api
# ==============================================================================
# Generator
.PHONY: gen.api
gen.api:
@$(DOCKER) run -it --rm \
-v $(ROOT_DIR):/go/src/$(ROOT_PACKAGE) \
-e EXT_PB_APIS=$(EXT_PB_APIS)\
$(REGISTRY_PREFIX)/code-generator:$(CODE_GENERATOR_VERSION) \
/root/code.sh \
all \
$(ROOT_PACKAGE)/pkg/generated \
$(ROOT_PACKAGE)/pkg/apis \
$(ROOT_PACKAGE)/pkg/apis \
"kstone:v1alpha1"
\ No newline at end of file
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# ==============================================================================
# Makefile helper functions for golang
#
GO := go
GO_SUPPORTED_VERSIONS ?= 1.13|1.14|1.15|1.16|1.17
GO_LDFLAGS += -X $(VERSION_PACKAGE).GitVersion=$(VERSION) \
-X $(VERSION_PACKAGE).GitCommit=$(GIT_COMMIT) \
-X $(VERSION_PACKAGE).GitTreeState=$(GIT_TREE_STATE) \
-X $(VERSION_PACKAGE).BuildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
ifeq ($(GOOS),windows)
GO_OUT_EXT := .exe
endif
ifeq ($(ROOT_PACKAGE),)
$(error the variable ROOT_PACKAGE must be set prior to including golang.mk)
endif
GOPATH := $(shell go env GOPATH)
ifeq ($(origin GOBIN), undefined)
GOBIN := $(GOPATH)/bin
endif
COMMANDS ?= $(filter-out %.md, $(wildcard ${ROOT_DIR}/cmd/*))
BINS ?= $(foreach cmd,${COMMANDS},$(notdir ${cmd}))
ifeq (${COMMANDS},)
$(error Could not determine COMMANDS, set ROOT_DIR or run in source dir)
endif
ifeq (${BINS},)
$(error Could not determine BINS, set ROOT_DIR or run in source dir)
endif
.PHONY: go.build.verify
go.build.verify:
ifneq ($(shell $(GO) version | grep -q -E '\bgo($(GO_SUPPORTED_VERSIONS))\b' && echo 0 || echo 1), 0)
$(error unsupported go version. Please make install one of the following supported version: '$(GO_SUPPORTED_VERSIONS)')
endif
.PHONY: go.build.%
go.build.%:
$(eval COMMAND := $(word 2,$(subst ., ,$*)))
$(eval PLATFORM := $(word 1,$(subst ., ,$*)))
$(eval OS := $(word 1,$(subst _, ,$(PLATFORM))))
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
@echo "===========> Building binary $(COMMAND) $(VERSION) for $(OS) $(ARCH)"
@mkdir -p $(OUTPUT_DIR)/$(OS)/$(ARCH)
@CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build -o $(OUTPUT_DIR)/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) -ldflags "$(GO_LDFLAGS)" $(ROOT_PACKAGE)/cmd/$(COMMAND)
.PHONY: go.build
go.build: go.build.verify $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))
.PHONY: go.build.multiarch
go.build.multiarch: go.build.verify $(foreach p,$(PLATFORMS),$(addprefix go.build., $(addprefix $(p)., $(BINS))))
.PHONY: go.clean
go.clean:
@echo "===========> Cleaning all build output"
@rm -rf $(OUTPUT_DIR)
.PHONY: go.lint.verify
go.lint.verify: go.build.verify
ifeq (,$(shell which golangci-lint))
@echo "===========> Installing golangci lint"
@GO111MODULE=off $(GO) get -u github.com/golangci/golangci-lint/cmd/golangci-lint
endif
.PHONY: go.lint
go.lint: go.lint.verify
@echo "===========> Run golangci to lint source codes"
@golangci-lint run $(ROOT_DIR)/...
.PHONY: go.test.verify
go.test.verify: go.build.verify
ifeq ($(shell which go-junit-report), )
@echo "===========> Installing go-junit-report"
@GO111MODULE=off $(GO) get -u github.com/jstemmer/go-junit-report
endif
.PHONY: go.test
go.test: go.test.verify
@echo "===========> Run unit test"
$(GO) test -count=1 -timeout=10m -short -v `go list ./...|grep -v tkestack.io/kstone/test` 2>&1 | tee >(go-junit-report --set-exit-code >$(OUTPUT_DIR)/report.xml)
# Tencent is pleased to support the open source community by making TKEStack
# available.
#
# Copyright (C) 2012-2023 Tencent. All Rights Reserved.
#
# 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
#
# https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# ==============================================================================
# Makefile helper functions for docker image
#
DOCKER := docker
DOCKER_SUPPORTED_API_VERSION ?= 1.32
REGISTRY_PREFIX ?= tkestack
BASE_IMAGE = alpine:3.14
EXTRA_ARGS ?=
_DOCKER_BUILD_EXTRA_ARGS :=
ifdef HTTP_PROXY
_DOCKER_BUILD_EXTRA_ARGS += --build-arg HTTP_PROXY=${HTTP_PROXY}
endif
ifneq ($(EXTRA_ARGS), )
_DOCKER_BUILD_EXTRA_ARGS += $(EXTRA_ARGS)
endif
# Determine image files by looking into build/docker/*/Dockerfile
IMAGES_DIR ?= $(wildcard ${ROOT_DIR}/build/docker/*)
# Determine images names by stripping out the dir names
IMAGES ?= $(filter-out tools,$(foreach image,${IMAGES_DIR},$(notdir ${image})))
ifeq (${IMAGES},)
$(error Could not determine IMAGES, set ROOT_DIR or run in source dir)
endif
.PHONY: image.verify
image.verify:
$(eval API_VERSION := $(shell $(DOCKER) version | grep -E 'API version: {1,6}[0-9]' | head -n1 | awk '{print $$3} END { if (NR==0) print 0}' ))
$(eval PASS := $(shell echo "$(API_VERSION) > $(DOCKER_SUPPORTED_API_VERSION)" | bc))
@if [ $(PASS) -ne 1 ]; then \
$(DOCKER) -v ;\
echo "Unsupported docker version. Docker API version should be greater than $(DOCKER_SUPPORTED_API_VERSION)"; \
exit 1; \
fi
.PHONY: image.daemon.verify
image.daemon.verify:
$(eval PASS := $(shell $(DOCKER) version | grep -q -E 'Experimental: {1,5}true' && echo 1 || echo 0))
@if [ $(PASS) -ne 1 ]; then \
echo "Experimental features of Docker daemon is not enabled. Please add \"experimental\": true in '/etc/docker/daemon.json' and then restart Docker daemon."; \
exit 1; \
fi
.PHONY: image.build
image.build: image.verify go.build.verify $(addprefix image.build., $(addprefix $(IMAGE_PLAT)., $(IMAGES)))
.PHONY: image.build.multiarch
image.build.multiarch: image.verify go.build.verify $(foreach p,$(PLATFORMS),$(addprefix image.build., $(addprefix $(p)., $(IMAGES))))
.PHONY: image.build.%
image.build.%: go.build.%
$(eval IMAGE := $(COMMAND))
$(eval IMAGE_PLAT := $(subst _,/,$(PLATFORM)))
@echo "===========> Building docker image $(IMAGE) $(VERSION) for $(IMAGE_PLAT)"
@mkdir -p $(TMP_DIR)/$(IMAGE)
@cat $(ROOT_DIR)/build/docker/$(IMAGE)/Dockerfile\
| sed "s#BASE_IMAGE#$(BASE_IMAGE)#g" >$(TMP_DIR)/$(IMAGE)/Dockerfile
@cp $(OUTPUT_DIR)/$(IMAGE_PLAT)/$(IMAGE) $(TMP_DIR)/$(IMAGE)/
@DST_DIR=$(TMP_DIR)/$(IMAGE) $(ROOT_DIR)/build/docker/$(IMAGE)/build.sh 2>/dev/null || true
$(eval BUILD_SUFFIX := $(_DOCKER_BUILD_EXTRA_ARGS) --pull -t $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION) $(TMP_DIR)/$(IMAGE))
#$(MAKE) image.daemon.verify
$(DOCKER) build --platform $(IMAGE_PLAT) $(BUILD_SUFFIX)
@rm -rf $(TMP_DIR)/$(IMAGE)
.PHONY: image.push
image.push: image.verify go.build.verify $(addprefix image.push., $(addprefix $(IMAGE_PLAT)., $(IMAGES)))
.PHONY: image.push.multiarch
image.push.multiarch: image.verify go.build.verify $(foreach p,$(PLATFORMS),$(addprefix image.push., $(addprefix $(p)., $(IMAGES))))
.PHONY: image.push.%
image.push.%: image.build.%
@echo "===========> Pushing image $(IMAGE) $(VERSION) to $(REGISTRY_PREFIX)"
$(DOCKER) push $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION)
.PHONY: image.manifest.push
image.manifest.push: export DOCKER_CLI_EXPERIMENTAL := enabled
image.manifest.push: image.verify go.build.verify \
$(addprefix image.manifest.push., $(addprefix $(IMAGE_PLAT)., $(IMAGES)))
.PHONY: image.manifest.push.%
image.manifest.push.%: image.push.% image.manifest.remove.%
@echo "===========> Pushing manifest $(IMAGE) $(VERSION) to $(REGISTRY_PREFIX) and then remove the local manifest list"
@$(DOCKER) manifest create $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION) \
$(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION)
@$(DOCKER) manifest annotate $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION) \
$(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION) \
--os $(OS) --arch ${ARCH}
@$(DOCKER) manifest push --purge $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION)
# Docker cli has a bug: https://github.com/docker/cli/issues/954
# If you find your manifests were not updated,
# Please manually delete them in $HOME/.docker/manifests/
# and re-run.
.PHONY: image.manifest.remove.%
image.manifest.remove.%:
@rm -rf ${HOME}/.docker/manifests/docker.io_$(REGISTRY_PREFIX)_$(IMAGE)-$(VERSION)
.PHONY: image.manifest.push.multiarch
image.manifest.push.multiarch: image.push.multiarch $(addprefix image.manifest.push.multiarch., $(IMAGES))
.PHONY: image.manifest.push.multiarch.%
image.manifest.push.multiarch.%:
@echo "===========> Pushing manifest $* $(VERSION) to $(REGISTRY_PREFIX) and then remove the local manifest list"
REGISTRY_PREFIX=$(REGISTRY_PREFIX) PLATFROMS="$(PLATFORMS)" IMAGE=$* VERSION=$(VERSION) DOCKER_CLI_EXPERIMENTAL=enabled \
$(ROOT_DIR)/build/lib/create-manifest.sh
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment