Skip to content

Commit

Permalink
handel skip
Browse files Browse the repository at this point in the history
  • Loading branch information
RidRisR committed Aug 26, 2024
1 parent c4c2953 commit 81fc174
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 56 deletions.
77 changes: 23 additions & 54 deletions hack/local-up-operator.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
#!/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
Expand All @@ -37,8 +20,8 @@ Usage: hack/local-up-operator.sh [-hd]
Environments:
PROVIDER Kubernetes provider. Defaults: kind.
CLUSTER the name of e2e cluster. Defaults to kind for kind provider.
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.
Expand All @@ -62,8 +45,7 @@ while getopts "h?i" opt; do
esac
done

PROVIDER=${PROVIDER:-kind}
CLUSTER=${CLUSTER:-}
PROVIDER=${PROVIDER:-k3s}
KUBECONFIG=${KUBECONFIG:-~/.kube/config}
KUBECONTEXT=${KUBECONTEXT:-}
NAMESPACE=${NAMESPACE:-pingcap}
Expand All @@ -72,23 +54,22 @@ IMAGE_TAG=${IMAGE_TAG:-latest}
SKIP_IMAGE_BUILD=${SKIP_IMAGE_BUILD:-}

hack::ensure_kubectl
hack::ensure_kind
hack::ensure_helm

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

function hack::create_namespace() {
local ns="$1"
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
}

Expand All @@ -110,28 +91,20 @@ function hack::wait_for_deploy() {
return 1
}

function hack::cluster_exists() {
local c="$1"
for n in $($KIND_BIN get clusters); do
if [ "$n" == "$c" ]; then
return 0
fi
done
return 1
}
if [[ "$installOnly" == "true" ]]; then
exit 0
fi

echo "info: checking clusters"

if [ "$PROVIDER" == "kind" ]; then
if [ -z "$CLUSTER" ]; then
CLUSTER=kind
fi
if ! hack::cluster_exists "$CLUSTER"; then
echo "error: kind cluster '$CLUSTER' not found, please create it or specify the right cluster name with CLUSTER environment"
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 "erorr: only kind PROVIDER is supported"
echo "error: only k3s PROVIDER is supported"
exit 1
fi

Expand All @@ -143,20 +116,16 @@ 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: loading images into cluster"
images=(
$DOCKER_REGISTRY/pingcap/tidb-operator:${IMAGE_TAG}
$DOCKER_REGISTRY/pingcap/tidb-backup-manager:${IMAGE_TAG}
)
for n in ${images[@]}; do
echo "info: loading image $n"
$KIND_BIN load docker-image --name $CLUSTER $n
done

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
Expand Down Expand Up @@ -188,5 +157,5 @@ deploys=(
)
for deploy in ${deploys[@]}; do
echo "info: waiting for $NAMESPACE/$deploy to be ready"
hack::wait_for_deploy "$NAMESPACE" "$deploy"
hack::wait_for_deploy "$NAMESPACE" "$deploy"
done
11 changes: 11 additions & 0 deletions pkg/apis/pingcap/v1alpha1/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,14 @@ func IsLogBackupAlreadyTruncate(backup *Backup) bool {
func IsLogBackupAlreadyStop(backup *Backup) bool {
return backup.Spec.Mode == BackupModeLog && backup.Status.Phase == BackupStopped
}

// IsLogBackupAlreadyStop return whether log backup has already paused.
//TODO: (Ris) deal with task stopped
func IsLogBackupAlreadyPaused(backup *Backup) bool {
return backup.Spec.Mode == BackupModeLog && backup.Status.Phase == BackupPaused
}

// IsLogBackupAlreadyRestart return whether log backup has already resumed.
func IsLogBackupAlreadyResumed(backup *Backup) bool {
return backup.Spec.Mode == BackupModeLog && backup.Status.Phase == BackupRestart
}
8 changes: 6 additions & 2 deletions pkg/backup/backup/backup_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,12 @@ func (bm *backupManager) skipLogBackupSync(backup *v1alpha1.Backup) (bool, error
switch command {
case v1alpha1.LogStartCommand:
skip = v1alpha1.IsLogBackupAlreadyStart(backup)
case v1alpha1.LogStopCommand:
skip = v1alpha1.IsLogBackupAlreadyStop(backup)
case v1alpha1.LogPauseCommand:
skip = v1alpha1.IsLogBackupAlreadyPaused(backup)
case v1alpha1.LogResumeCommand:
skip = !v1alpha1.IsLogBackupAlreadyResumed(backup)
case v1alpha1.LogTruncateCommand:
if v1alpha1.IsLogBackupAlreadyTruncate(backup) {
skip = true
Expand All @@ -1105,8 +1111,6 @@ func (bm *backupManager) skipLogBackupSync(backup *v1alpha1.Backup) (bool, error
Status: corev1.ConditionTrue,
}, updateStatus)
}
case v1alpha1.LogStopCommand:
skip = v1alpha1.IsLogBackupAlreadyStop(backup)
default:
return false, nil
}
Expand Down

0 comments on commit 81fc174

Please sign in to comment.