Skip to content

Commit 4efbb44

Browse files
Abirdcfly0xff-dev
authored andcommitted
fix: some cpl uninstall failed
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
1 parent 33aaa9f commit 4efbb44

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

config/samples/example-test.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function deleteComponentPlan() {
221221
componentPlanName=$2
222222
helmReleaseShouldDelete=$3
223223
START_TIME=$(date +%s)
224-
helmReleaseName=$(kubectl get ComponentPlan -n${namespace} ${componentPlanName} --ignore-not-found=true -ojson | jq -r '.spec.name')
224+
helmReleaseName=$(kubectl get ComponentPlan -n${namespace} ${componentPlanName%% *} --ignore-not-found=true -ojson | jq -r '.spec.name')
225225
if [[ $helmReleaseName == "" ]]; then
226226
info "componentPlan:${componentPlanName} has no release name"
227227
kubectl get ComponentPlan -n${namespace} ${componentPlanName} -oyaml
@@ -257,7 +257,7 @@ function deleteComponentPlan() {
257257
if [ $ELAPSED_TIME -gt $TimeoutSeconds ]; then
258258
error "Timeout reached"
259259
helm list -A -a
260-
helm status -n ${namespace} ${componentPlanName}
260+
helm status -n ${namespace} ${helmReleaseName}
261261
exit 1
262262
fi
263263
sleep 30
@@ -428,6 +428,7 @@ docker tag kubebb/core:latest kubebb/core:example-e2e
428428
kind load docker-image kubebb/core:example-e2e --name=$KindName
429429
make deploy IMG="kubebb/core:example-e2e"
430430
kubectl wait deploy -n kubebb-system kubebb-controller-manager --for condition=Available=True --timeout=$Timeout
431+
sleep 10
431432

432433
info "3 try to verify that the common steps are valid"
433434

@@ -479,6 +480,8 @@ sleep 10
479480
kubectl patch subscription -n kubebb-system grafana-sample --type='json' -p='[{"op": "replace", "path": "/spec/componentPlanInstallMethod", "value": "auto"}]'
480481
getPodImage "kubebb-system" "app.kubernetes.io/instance=grafana-sample,app.kubernetes.io/name=grafana" "192.168.1.1:5000/grafana-local/grafana"
481482
getHelmRevision "kubebb-system" "grafana-sample" "1"
483+
cplName=$(kubectl get cpl -n kubebb-system --no-headers=true | awk '{print $1}')
484+
deleteComponentPlan "kubebb-system" $cplName "true"
482485
kubectl delete -f config/samples/core_v1alpha1_grafana_subscription.yaml
483486

484487
info "5 try to verify that common use of componentPlan are valid"
@@ -510,8 +513,19 @@ waitPodReady "kubebb-system" "app.kubernetes.io/instance=my-nginx,app.kubernetes
510513
getHelmRevision "kubebb-system" "my-nginx" "4"
511514
validateComponentPlanStatusLatestValue "kubebb-system" "do-once-nginx-sample-15.1.0" "false"
512515
validateComponentPlanStatusLatestValue "kubebb-system" "do-once-nginx-sample-15.0.2" "true"
513-
deleteComponentPlan "kubebb-system" "do-once-nginx-sample-15.1.0" "false"
514-
deleteComponentPlan "kubebb-system" "do-once-nginx-sample-15.0.2" "true"
516+
rand=$(awk 'BEGIN{srand(); print rand()}')
517+
if [ $(echo "$rand < 0.33" | bc) -eq 1 ]; then
518+
info "remove older cpl first"
519+
deleteComponentPlan "kubebb-system" "do-once-nginx-sample-15.0.2" "true"
520+
deleteComponentPlan "kubebb-system" "do-once-nginx-sample-15.1.0" "true"
521+
elif [ $(echo "$rand < 0.66" | bc) -eq 1 ]; then
522+
info "remove newer cpl first"
523+
deleteComponentPlan "kubebb-system" "do-once-nginx-sample-15.1.0" "false"
524+
deleteComponentPlan "kubebb-system" "do-once-nginx-sample-15.0.2" "true"
525+
else
526+
info "remove these cpl both"
527+
deleteComponentPlan "kubebb-system" "do-once-nginx-sample-15.1.0 do-once-nginx-sample-15.0.2" "true"
528+
fi
515529

516530
info "5.5 Verify long running componentPlan install don not block others to install"
517531
kubectl apply -f config/samples/core_v1alpha1_nginx_componentplan_long_ready.yaml

pkg/helm/cpl_helm.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ func (c *CoreHelmWrapper) InstallOrUpgrade(ctx context.Context, chartName string
8686

8787
// Uninstall installs a helm chart to the cluster
8888
func (c *CoreHelmWrapper) Uninstall(ctx context.Context) (err error) {
89+
defer func() {
90+
if err != nil {
91+
if strings.HasPrefix(err.Error(), "uninstallation completed with 1 error(s): uninstall: Failed to purge the release: release: not found") { //nolint:dupword
92+
err = nil
93+
}
94+
}
95+
}()
8996
rel, err := c.GetLastRelease()
9097
if err != nil {
9198
return err

pkg/helm/cpl_helm_release_workpool.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"strconv"
2324
"strings"
2425
"sync"
2526
"time"
@@ -236,6 +237,15 @@ func (w *baseWorker) GetResult() (rel *release.Release, isRuuing bool, err error
236237
return w.release, w.isRunning, w.err
237238
}
238239

240+
func (w *baseWorker) logKV() []interface{} {
241+
res := []interface{}{"workername", w.name}
242+
if w.plan != nil {
243+
res = append(res, "planUID", string(w.plan.UID))
244+
res = append(res, "planGeneration", strconv.FormatInt(w.plan.Generation, 10))
245+
}
246+
return res
247+
}
248+
239249
type installWorker struct {
240250
baseWorker
241251
}
@@ -254,11 +264,11 @@ func newInstallWorker(ctx context.Context, name, chartName string, logger logr.L
254264
subCtx, cancel := context.WithCancel(ctx)
255265
w.cancel = cancel
256266
go func() {
257-
w.logger.V(1).Info("start install worker", "workername", w.name)
267+
w.logger.V(1).Info("start install worker", w.logKV()...)
258268
w.startTime = metav1.Now()
259269
defer func() {
260270
cost := time.Since(w.startTime.Time)
261-
w.logger.V(1).Info(fmt.Sprintf("stop install worker, cost %s", cost), "workername", w.name)
271+
w.logger.V(1).Info(fmt.Sprintf("stop install worker, cost %s", cost), w.logKV()...)
262272
w.isRunning = false
263273
}()
264274
w.status = release.StatusPendingInstall
@@ -314,10 +324,10 @@ func newUnInstallWorker(ctx context.Context, name string, logger logr.Logger, pl
314324
subCtx, cancel := context.WithCancel(ctx)
315325
w.cancel = cancel
316326
go func() {
317-
w.logger.V(1).Info("start uninstall worker", "workername", w.name)
327+
w.logger.V(1).Info("start uninstall worker", w.logKV()...)
318328
startTime := metav1.Now()
319329
defer func() {
320-
w.logger.V(1).Info(fmt.Sprintf("stop uninstall worker, cost %s", time.Since(startTime.Time)), "workername", w.name)
330+
w.logger.V(1).Info(fmt.Sprintf("stop uninstall worker, cost %s", time.Since(startTime.Time)), w.logKV()...)
321331
w.isRunning = false
322332
}()
323333
w.status = release.StatusUninstalling
@@ -362,10 +372,10 @@ func newRollBackWorker(ctx context.Context, name string, logger logr.Logger, pla
362372
subCtx, cancel := context.WithCancel(ctx)
363373
w.cancel = cancel
364374
go func() {
365-
w.logger.V(1).Info("start rollback worker", "workername", w.name)
375+
w.logger.V(1).Info("start rollback worker", w.logKV()...)
366376
startTime := metav1.Now()
367377
defer func() {
368-
w.logger.V(1).Info(fmt.Sprintf("stop rollback worker, cost %s", time.Since(startTime.Time)), "workername", w.name)
378+
w.logger.V(1).Info(fmt.Sprintf("stop rollback worker, cost %s", time.Since(startTime.Time)), w.logKV()...)
369379
w.isRunning = false
370380
}()
371381
w.status = release.StatusUninstalling

0 commit comments

Comments
 (0)