Skip to content

Commit

Permalink
Merge branch 'master' into subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
RidRisR authored Sep 25, 2024
2 parents a8a4f42 + 6acb110 commit 7ee8579
Show file tree
Hide file tree
Showing 27 changed files with 504 additions and 236 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST_COVER_PACKAGES := go list ./cmd/... ./pkg/... $(foreach mod, $(GO_SUBMODULE

# NOTE: coverage report generated for E2E tests (with `-c`) may not stable, see
# https://github.com/golang/go/issues/23883#issuecomment-381766556
GO_TEST := $(GO) test -cover -covermode=atomic -coverpkg=$$($(TEST_COVER_PACKAGES))
GO_TEST := CGO_ENABLED=0 $(GO) test -cover -covermode=atomic -coverpkg=$$($(TEST_COVER_PACKAGES))

default: build

Expand Down Expand Up @@ -160,7 +160,7 @@ endif
cp -r charts/tidb-operator tests/images/e2e
cp -r charts/tidb-drainer tests/images/e2e
cp -r manifests tests/images/e2e
docker build -t "${DOCKER_REPO}/tidb-operator-e2e:${IMAGE_TAG}" tests/images/e2e
docker build -t "${DOCKER_REPO}/tidb-operator-e2e:${IMAGE_TAG}" --build-arg=TARGETARCH=$(GOARCH) tests/images/e2e

e2e-build: ## Build binaries for test
$(GO_BUILD) -ldflags '$(LDFLAGS)' -o tests/images/e2e/bin/ginkgo github.com/onsi/ginkgo/ginkgo
Expand Down
2 changes: 1 addition & 1 deletion ci/e2e_eks.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kind: Pod
spec:
containers:
- name: main
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v7-go1.22.5
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v8-go1.23.1
command:
- runner.sh
- sleep
Expand Down
2 changes: 1 addition & 1 deletion ci/e2e_gke.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kind: Pod
spec:
containers:
- name: main
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v7-go1.22.5
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v8-go1.23.1
command:
- runner.sh
- sleep
Expand Down
2 changes: 1 addition & 1 deletion ci/e2e_kind.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metadata:
spec:
containers:
- name: main
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v7-go1.22.5
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v8-go1.23.1
command:
- runner.sh
- exec
Expand Down
2 changes: 1 addition & 1 deletion ci/pull_e2e_kind.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ metadata:
spec:
containers:
- name: main
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v7-go1.22.5
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v8-go1.23.1
command:
- runner.sh
- exec
Expand Down
2 changes: 1 addition & 1 deletion ci/pull_e2e_release.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ metadata:
spec:
containers:
- name: main
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v7-go1.22.5
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v8-go1.23.1
command:
- runner.sh
- exec
Expand Down
2 changes: 1 addition & 1 deletion ci/vm.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kind: Pod
spec:
containers:
- name: main
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v7-go1.22.5
image: hub.pingcap.net/tidb-operator/kubekins-e2e:v8-go1.23.1
command:
- runner.sh
- sleep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ spec:
pingcap.com/aws-local-ssd: "true"
serviceAccountName: local-storage-admin
containers:
- image: "quay.io/external_storage/local-volume-provisioner:v2.3.2"
- image: "registry.k8s.io/sig-storage/local-volume-provisioner:v2.6.0"
name: provisioner
securityContext:
privileged: true
Expand All @@ -58,7 +58,7 @@ spec:
fieldRef:
fieldPath: metadata.namespace
- name: JOB_CONTAINER_IMAGE
value: "quay.io/external_storage/local-volume-provisioner:v2.3.2"
value: "registry.k8s.io/sig-storage/local-volume-provisioner:v2.6.0"
resources:
requests:
cpu: 100m
Expand Down
8 changes: 4 additions & 4 deletions examples/advanced/tidb-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ spec:
# app.kubernetes.io/component: pump
# annotations:
# node.kubernetes.io/instance-type: some-vm-type
# tolerations: {}
# tolerations: []
# configUpdateStrategy: RollingUpdate
# statefulSetUpdateStrategy: RollingUpdate
# podSecurityContext: {}
Expand Down Expand Up @@ -868,7 +868,7 @@ spec:
# app.kubernetes.io/component: ticdc
# annotations:
# node.kubernetes.io/instance-type: some-vm-type
# tolerations: {}
# tolerations: []
# configUpdateStrategy: RollingUpdate
# statefulSetUpdateStrategy: RollingUpdate
# podSecurityContext: {}
Expand Down Expand Up @@ -918,7 +918,7 @@ spec:
# app.kubernetes.io/component: tiflash
# annotations:
# node.kubernetes.io/instance-type: some-vm-type
# tolerations: {}
# tolerations: []
# configUpdateStrategy: RollingUpdate
# statefulSetUpdateStrategy: RollingUpdate
# podSecurityContext: {}
Expand Down Expand Up @@ -970,7 +970,7 @@ spec:
# # configure the configuration file for TiFlash Proxy process
# proxy: |
# [security]
# cert-allowed-cn = "CNNAME"
# cert-allowed-cn = ["CNNAME"]
# # TopologySpreadConstraints for pod scheduling, will overwrite the cluster level spread constraints setting
# # Ref: pkg/apis/pingcap/v1alpha1/types.go#TopologySpreadConstraint
# topologySpreadConstraints:
Expand Down
4 changes: 2 additions & 2 deletions examples/local-pv/local-volume-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ spec:
spec:
serviceAccountName: local-storage-admin
containers:
- image: "quay.io/external_storage/local-volume-provisioner:v2.3.4"
- image: "registry.k8s.io/sig-storage/local-volume-provisioner:v2.6.0"
name: provisioner
securityContext:
privileged: true
Expand All @@ -81,7 +81,7 @@ spec:
fieldRef:
fieldPath: metadata.namespace
- name: JOB_CONTAINER_IMAGE
value: "quay.io/external_storage/local-volume-provisioner:v2.3.4"
value: "registry.k8s.io/sig-storage/local-volume-provisioner:v2.6.0"
resources:
requests:
cpu: 100m
Expand Down
179 changes: 179 additions & 0 deletions hack/local-up-by-k3s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#!/usr/bin/env bash

# Copyright 2020 PingCAP, Inc.
#
# 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,
# See the License for the specific language governing permissions and
# limitations under the License.

#
# This command runs tidb-operator in Kubernetes.
#

set -o errexit
set -o nounset
set -o pipefail

ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
cd $ROOT

source "${ROOT}/hack/lib.sh"

function usage() {
cat <<'EOF'
This commands run tidb-operator in Kubernetes.
Usage: hack/local-up-operator.sh [-hd]
-h show this message and exit
-i install dependencies only
Environments:
PROVIDER Kubernetes provider. Defaults: k3s.
CLUSTER the name of e2e cluster.
KUBECONFIG path to the kubeconfig file, defaults: ~/.kube/config
KUBECONTEXT context in kubeconfig file, defaults to current context
NAMESPACE Kubernetes namespace in which we run our tidb-operator.
DOCKER_REGISTRY image docker registry
IMAGE_TAG image tag
SKIP_IMAGE_BUILD skip build and push images
EOF
}

installOnly=false
while getopts "h?i" opt; do
case "$opt" in
h|\?)
usage
exit 0
;;
i)
installOnly=true
;;
esac
done

PROVIDER=${PROVIDER:-k3s}
KUBECONFIG=${KUBECONFIG:-~/.kube/config}
KUBECONTEXT=${KUBECONTEXT:-}
NAMESPACE=${NAMESPACE:-pingcap}
DOCKER_REGISTRY=${DOCKER_REGISTRY:-localhost:5000}
IMAGE_TAG=${IMAGE_TAG:-latest}
SKIP_IMAGE_BUILD=${SKIP_IMAGE_BUILD:-}

hack::ensure_kubectl
hack::ensure_helm

function hack::create_namespace() {
local ns="$1" # The namespace to create
# Create the namespace
$KUBECTL_BIN create namespace $ns
# Wait for the namespace to become active
for ((i=0; i < 30; i++)); do
local phase=$(kubectl get ns $ns -ojsonpath='{.status.phase}')
if [ "$phase" == "Active" ]; then
echo "info: namespace $ns is active"
return 0
fi
sleep 1
done
echo "error: timed out waiting for namespace $ns to become active"
return 1
}

function hack::wait_for_deploy() {
local ns="$1"
local name="$2"
local retries="${3:-300}"
echo "info: waiting for pods of deployment $ns/$name are ready (retries: $retries, interval: 1s)"
for ((i = 0; i < retries; i++)) {
read a b <<<$($KUBECTL_BIN --context $KUBECONTEXT -n $ns get deploy/$name -ojsonpath='{.spec.replicas} {.status.readyReplicas}{"\n"}')
if [[ "$a" -gt 0 && "$a" -eq "$b" ]]; then
echo "info: all pods of deployment $ns/$name are ready (desired: $a, ready: $b)"
return 0
fi
echo "info: pods of deployment $ns/$name (desired: $a, ready: $b)"
sleep 1
}
echo "info: timed out waiting for pods of deployment $ns/$name are ready"
return 1
}

if [[ "$installOnly" == "true" ]]; then
exit 0
fi

echo "info: checking clusters"

if [ "$PROVIDER" == "k3s" ]; then
echo "info: using k3s provider"
if ! kubectl cluster-info &>/dev/null; then
echo "error: k3s cluster not found, please ensure it is running"
exit 1
fi
else
echo "error: only k3s PROVIDER is supported"
exit 1
fi

if [ -z "$KUBECONTEXT" ]; then
KUBECONTEXT=$(kubectl config current-context)
echo "info: KUBECONTEXT is not set, current context $KUBECONTEXT is used"
fi

if [ -z "$SKIP_IMAGE_BUILD" ]; then
echo "info: building docker images"
DOCKER_REGISTRY=$DOCKER_REGISTRY IMAGE_TAG=$IMAGE_TAG make docker

# Push images to the local registry
echo "info: pushing images to the local registry"

docker push ${DOCKER_REGISTRY}/pingcap/tidb-operator:${IMAGE_TAG}
docker push ${DOCKER_REGISTRY}/pingcap/tidb-backup-manager:${IMAGE_TAG}
else
echo "info: skip building docker images"
fi

echo "info: uninstall tidb-operator"
$KUBECTL_BIN -n "$NAMESPACE" delete deploy -l app.kubernetes.io/name=tidb-operator
$KUBECTL_BIN -n "$NAMESPACE" delete pods -l app.kubernetes.io/name=tidb-operator

echo "info: create namespace '$NAMESPACE' if absent"
if ! $KUBECTL_BIN get ns "$NAMESPACE" &>/dev/null; then
hack::create_namespace "$NAMESPACE"
fi

echo "info: installing crds"
if ! $KUBECTL_BIN create -f manifests/crd.yaml &>/dev/null; then
$KUBECTL_BIN replace -f manifests/crd.yaml
fi

echo "info: deploying tidb-operator"
helm_template_args=(
--namespace "$NAMESPACE"
--set-string operatorImage=$DOCKER_REGISTRY/pingcap/tidb-operator:${IMAGE_TAG}
--set-string tidbBackupManagerImage=$DOCKER_REGISTRY/pingcap/tidb-backup-manager:${IMAGE_TAG}
--set-string controllerManager.logLevel=4
--set-string scheduler.logLevel=4
--set imagePullPolicy=Always
)

$HELM_BIN template tidb-operator-dev ./charts/tidb-operator/ ${helm_template_args[@]} | kubectl -n "$NAMESPACE" apply -f -

deploys=(
tidb-controller-manager
# tidb-scheduler
)
for deploy in ${deploys[@]}; do
echo "info: waiting for $NAMESPACE/$deploy to be ready"
hack::wait_for_deploy "$NAMESPACE" "$deploy"
done
Loading

0 comments on commit 7ee8579

Please sign in to comment.