-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add app to support upgrade static pod
Signed-off-by: hxcGit <[email protected]>
- Loading branch information
1 parent
283d25d
commit 3ada9ba
Showing
8 changed files
with
803 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
# Copyright 2020 The OpenYurt 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. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
KUBERNETESVERSION ?=v1.22 | ||
TARGET_PLATFORMS ?= linux/amd64 | ||
IMAGE_REPO ?= openyurt | ||
IMAGE_TAG ?= $(shell git describe --abbrev=0 --tags) | ||
GIT_COMMIT = $(shell git rev-parse HEAD) | ||
ENABLE_AUTONOMY_TESTS ?=true | ||
CRD_OPTIONS ?= "crd:crdVersions=v1" | ||
BUILD_KUSTOMIZE ?= _output/manifest | ||
|
||
ifeq ($(shell git tag --points-at ${GIT_COMMIT}),) | ||
GIT_VERSION=$(IMAGE_TAG)-$(shell echo ${GIT_COMMIT} | cut -c 1-7) | ||
else | ||
GIT_VERSION=$(IMAGE_TAG) | ||
endif | ||
|
||
ifneq ($(IMAGE_TAG), $(shell git describe --abbrev=0 --tags)) | ||
GIT_VERSION=$(IMAGE_TAG) | ||
endif | ||
|
||
DOCKER_BUILD_ARGS = --build-arg GIT_VERSION=${GIT_VERSION} | ||
|
||
ifeq (${REGION}, cn) | ||
DOCKER_BUILD_ARGS += --build-arg GOPROXY=https://goproxy.cn --build-arg MIRROR_REPO=mirrors.aliyun.com | ||
endif | ||
|
||
ifneq (${http_proxy},) | ||
DOCKER_BUILD_ARGS += --build-arg http_proxy='${http_proxy}' | ||
endif | ||
|
||
ifneq (${https_proxy},) | ||
DOCKER_BUILD_ARGS += --build-arg https_proxy='${https_proxy}' | ||
endif | ||
|
||
.PHONY: clean all build test | ||
|
||
all: test build | ||
|
||
# Build binaries in the host environment | ||
build: | ||
bash hack/make-rules/build.sh $(WHAT) | ||
|
||
# Run test | ||
test: | ||
go test -v -short ./pkg/... ./cmd/... -coverprofile cover.out | ||
go test -v -coverpkg=./pkg/yurttunnel/... -coverprofile=yurttunnel-cover.out ./test/integration/yurttunnel_test.go | ||
|
||
clean: | ||
-rm -Rf _output | ||
|
||
# verify will verify the code. | ||
verify: verify-mod verify-license | ||
|
||
# verify-license will check if license has been added to files. | ||
verify-license: | ||
hack/make-rules/check_license.sh | ||
|
||
# verify-mod will check if go.mod has beed tidied. | ||
verify-mod: | ||
hack/make-rules/verify_mod.sh | ||
|
||
# Start up OpenYurt cluster on local machine based on a Kind cluster | ||
local-up-openyurt: | ||
KUBERNETESVERSION=${KUBERNETESVERSION} YURT_VERSION=$(GIT_VERSION) bash hack/make-rules/local-up-openyurt.sh | ||
|
||
# Build all OpenYurt components images and then start up OpenYurt cluster on local machine based on a Kind cluster | ||
# And you can run the following command on different env by specify TARGET_PLATFORMS, default platform is linux/amd64 | ||
# - on centos env: make docker-build-and-up-openyurt | ||
# - on MACBook Pro M1: make docker-build-and-up-openyurt TARGET_PLATFORMS=linux/arm64 | ||
docker-build-and-up-openyurt: docker-build | ||
KUBERNETESVERSION=${KUBERNETESVERSION} YURT_VERSION=$(GIT_VERSION) bash hack/make-rules/local-up-openyurt.sh | ||
|
||
# Start up e2e tests for OpenYurt | ||
# And you can run the following command on different env by specify TARGET_PLATFORMS, default platform is linux/amd64 | ||
# - on centos env: make e2e-tests | ||
# - on MACBook Pro M1: make e2e-tests TARGET_PLATFORMS=linux/arm64 | ||
e2e-tests: | ||
ENABLE_AUTONOMY_TESTS=${ENABLE_AUTONOMY_TESTS} TARGET_PLATFORMS=${TARGET_PLATFORMS} hack/make-rules/run-e2e-tests.sh | ||
|
||
install-golint: ## check golint if not exist install golint tools | ||
ifeq (, $(shell which golangci-lint)) | ||
@{ \ | ||
set -e ;\ | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] ;\ | ||
} | ||
GOLINT_BIN=$(shell go env GOPATH)/bin/golangci-lint | ||
else | ||
GOLINT_BIN=$(shell which golangci-lint) | ||
endif | ||
|
||
lint: install-golint ## Run go lint against code. | ||
$(GOLINT_BIN) run -v | ||
|
||
# Build the docker images only one arch(specify arch by TARGET_PLATFORMS env) | ||
# otherwise the platform of host will be used. | ||
# e.g. | ||
# - build linux/amd64 docker images: | ||
# $# make docker-build TARGET_PLATFORMS=linux/amd64 | ||
# - build linux/arm64 docker images: | ||
# $# make docker-build TARGET_PLATFORMS=linux/arm64 | ||
# - build a specific image: | ||
# $# make docker-build WHAT=yurthub | ||
# - build with proxy, maybe useful for Chinese users | ||
# $# REGION=cn make docker-build | ||
docker-build: | ||
TARGET_PLATFORMS=${TARGET_PLATFORMS} hack/make-rules/image_build.sh $(WHAT) | ||
|
||
|
||
# Build and Push the docker images with multi-arch | ||
docker-push: docker-push-yurthub docker-push-yurt-controller-manager docker-push-yurt-tunnel-server docker-push-yurt-tunnel-agent docker-push-node-servant docker-push-yurt-manager docker-push-yurt-static-pod-upgrade | ||
|
||
|
||
docker-buildx-builder: | ||
if ! docker buildx ls | grep -q container-builder; then\ | ||
docker buildx create --name container-builder --use;\ | ||
fi | ||
# enable qemu for arm64 build | ||
# https://github.com/docker/buildx/issues/464#issuecomment-741507760 | ||
docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-aarch64 | ||
docker run --rm --privileged tonistiigi/binfmt --install all | ||
|
||
docker-push-yurthub: docker-buildx-builder | ||
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.yurthub . -t ${IMAGE_REPO}/yurthub:${GIT_VERSION} | ||
|
||
docker-push-yurt-controller-manager: docker-buildx-builder | ||
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.yurt-controller-manager . -t ${IMAGE_REPO}/yurt-controller-manager:${GIT_VERSION} | ||
|
||
docker-push-yurt-tunnel-server: docker-buildx-builder | ||
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.yurt-tunnel-server . -t ${IMAGE_REPO}/yurt-tunnel-server:${GIT_VERSION} | ||
|
||
docker-push-yurt-tunnel-agent: docker-buildx-builder | ||
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.yurt-tunnel-agent . -t ${IMAGE_REPO}/yurt-tunnel-agent:${GIT_VERSION} | ||
|
||
docker-push-node-servant: docker-buildx-builder | ||
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.node-servant . -t ${IMAGE_REPO}/node-servant:${GIT_VERSION} | ||
|
||
docker-push-yurt-manager: docker-buildx-builder | ||
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.yurt-manager . -t ${IMAGE_REPO}/yurt-manager:${GIT_VERSION} | ||
|
||
docker-push-yurt-static-pod-upgrade: docker-buildx-builder | ||
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.yurt-static-pod-upgrade . -t ${IMAGE_REPO}/yurt-static-pod-upgrade:${GIT_VERSION} | ||
|
||
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. | ||
# hack/make-rule/generate_openapi.sh // TODO by kadisi | ||
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/apis/..." | ||
|
||
manifests: generate ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. | ||
rm -rf $(BUILD_KUSTOMIZE) | ||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=role webhook paths="./pkg/..." output:crd:artifacts:config=$(BUILD_KUSTOMIZE)/auto_generate/crd output:rbac:artifacts:config=$(BUILD_KUSTOMIZE)/auto_generate/rbac output:webhook:artifacts:config=$(BUILD_KUSTOMIZE)/auto_generate/webhook | ||
hack/make-rules/kustomize_to_chart.sh --crd $(BUILD_KUSTOMIZE)/auto_generate/crd --webhook $(BUILD_KUSTOMIZE)/auto_generate/webhook --rbac $(BUILD_KUSTOMIZE)/auto_generate/rbac --output $(BUILD_KUSTOMIZE)/kustomize --templateDir charts/openyurt/templates | ||
|
||
|
||
# newcontroller | ||
# .e.g | ||
# make newcontroller GROUP=apps VERSION=v1beta1 KIND=example SHORTNAME=examples SCOPE=Namespaced | ||
# make newcontroller GROUP=apps VERSION=v1beta1 KIND=example SHORTNAME=examples SCOPE=Cluster | ||
newcontroller: | ||
hack/make-rules/add_controller.sh --group $(GROUP) --version $(VERSION) --kind $(KIND) --shortname $(SHORTNAME) --scope $(SCOPE) | ||
|
||
|
||
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen | ||
controller-gen: ## Download controller-gen locally if necessary. | ||
ifeq ("$(shell $(CONTROLLER_GEN) --version 2> /dev/null)", "Version: v0.7.0") | ||
else | ||
rm -rf $(CONTROLLER_GEN) | ||
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) | ||
endif | ||
|
||
# go-get-tool will 'go get' any package $2 and install it to $1. | ||
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
define go-get-tool | ||
@[ -f $(1) ] || { \ | ||
set -e ;\ | ||
TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
echo "Downloading $(2)" ;\ | ||
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ | ||
rm -rf $$TMP_DIR ;\ | ||
} | ||
endef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright 2023 The OpenYurt 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. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
"k8s.io/klog/v2" | ||
|
||
"github.com/openyurtio/openyurt/pkg/projectinfo" | ||
upgrade "github.com/openyurtio/openyurt/pkg/static-pod-upgrade" | ||
) | ||
|
||
func main() { | ||
rand.Seed(time.Now().UnixNano()) | ||
version := fmt.Sprintf("%#v", projectinfo.Get()) | ||
cmd := &cobra.Command{ | ||
Use: "yurt-static-pod-upgrade", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Printf("yurt-static-pod-upgrade version: %#v\n", version) | ||
|
||
cmd.Flags().VisitAll(func(flag *pflag.Flag) { | ||
klog.Infof("FLAG: --%s=%q", flag.Name, flag.Value) | ||
}) | ||
|
||
if err := upgrade.Validate(); err != nil { | ||
klog.Fatalf("Fail to validate yurt static pod upgrade args, %v", err) | ||
} | ||
|
||
c, err := upgrade.GetClient() | ||
if err != nil { | ||
klog.Fatalf("Fail to get kubernetes client, %v", err) | ||
} | ||
|
||
ctrl, err := upgrade.New(c) | ||
if err != nil { | ||
klog.Fatal("Fail to create static-pod-upgrade controller, %v", err) | ||
} | ||
|
||
if err := ctrl.Upgrade(); err != nil { | ||
klog.Fatalf("Fail to upgrade static pod, %v", err) | ||
} | ||
klog.Info("Static pod upgrade Success") | ||
}, | ||
Version: version, | ||
} | ||
|
||
addFlags(cmd) | ||
|
||
if err := viper.BindPFlags(cmd.Flags()); err != nil { | ||
os.Exit(1) | ||
} | ||
|
||
if err := cmd.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func addFlags(cmd *cobra.Command) { | ||
cmd.Flags().String("kubeconfig", "", "The path to the kubeconfig file") | ||
cmd.Flags().String("name", "", "The name of static pod which needs be upgraded") | ||
cmd.Flags().String("namespace", "", "The namespace of static pod which needs be upgraded") | ||
cmd.Flags().String("manifest", "", "The manifest file name of static pod which needs be upgraded") | ||
cmd.Flags().String("hash", "", "The hash value of new static pod specification") | ||
cmd.Flags().String("mode", "", "The upgrade mode which is used") | ||
} |
13 changes: 13 additions & 0 deletions
13
hack/dockerfiles/release/Dockerfile.yurt-static-pod-upgrade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# multi-arch image building for yurt-static-pod-upgrade | ||
|
||
FROM --platform=${BUILDPLATFORM} golang:1.18 as builder | ||
ADD . /build | ||
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO | ||
WORKDIR /build/ | ||
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/yurt-static-pod-upgrade | ||
|
||
FROM --platform=${TARGETPLATFORM} alpine:3.17 | ||
ARG TARGETOS TARGETARCH MIRROR_REPO | ||
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \ | ||
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/* | ||
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-static-pod-upgrade /usr/local/bin/yurt-static-pod-upgrade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.