Skip to content

Commit

Permalink
OVA: manually remove PVs attacked to ova provider once it deleted.
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <[email protected]>
  • Loading branch information
bkhizgiy committed Dec 10, 2023
1 parent 5f52229 commit d251469
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/controller/provider/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/api/errors",
"//vendor/k8s.io/apimachinery/pkg/api/resource",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:meta",
"//vendor/k8s.io/apimachinery/pkg/labels",
"//vendor/k8s.io/apimachinery/pkg/util/intstr",
"//vendor/k8s.io/apiserver/pkg/storage/names",
"//vendor/sigs.k8s.io/controller-runtime/pkg/client",
Expand Down
25 changes: 25 additions & 0 deletions pkg/controller/provider/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"sync"
"time"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/base"
Expand All @@ -41,6 +43,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apiserver/pkg/storage/names"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -157,6 +160,28 @@ func (r Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (r
_ = r.DB().Close(true)
}
}

// Wait for the PV to release
time.Sleep(5 * time.Second)

// List all PVs with a specific prefix and label
labelSelector := labels.SelectorFromSet(labels.Set{"subapp": "ova-server"})
pvList := &v1.PersistentVolumeList{}
err = r.Client.List(context.TODO(), pvList, &client.ListOptions{
LabelSelector: labelSelector,
})
if err != nil {
r.Log.Error(err, "Failed to list PVs")
} else {
for _, pv := range pvList.Items {
if strings.HasPrefix(pv.Name, "ova-server-pv-") && pv.Status.Phase == v1.VolumeReleased {
err = r.Client.Delete(context.TODO(), &pv)
if err != nil {
r.Log.Error(err, "Failed to delete PV", "PV Name", pv.Name)
}
}
}
}
}
return
} else {
Expand Down

0 comments on commit d251469

Please sign in to comment.