Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign change #8

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/deployers/applicationset.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (a ApplicationSet) Undeploy(w workloads.Workload) error {
return err
}

err = deletePlacement(name, namespace)
err = util.DeletePlacement(name, namespace)
if err != nil {
return err
}
Expand Down
39 changes: 1 addition & 38 deletions e2e/deployers/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,6 @@ func createPlacement(name, namespace string) error {
return nil
}

func deletePlacement(name, namespace string) error {
placement := &ocmv1b1.Placement{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
}

err := util.Ctx.Hub.CtrlClient.Delete(context.Background(), placement)
if err != nil {
if !errors.IsNotFound(err) {
return err
}

util.Ctx.Log.Info("placement " + name + " not found")
}

return nil
}

func createSubscription(s Subscription, w workloads.Workload) error {
name := GetCombinedName(s, w)
namespace := name
Expand Down Expand Up @@ -182,25 +162,8 @@ func createSubscription(s Subscription, w workloads.Workload) error {

func deleteSubscription(s Subscription, w workloads.Workload) error {
name := GetCombinedName(s, w)
namespace := name

subscription := &subscriptionv1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
}

err := util.Ctx.Hub.CtrlClient.Delete(context.Background(), subscription)
if err != nil {
if !errors.IsNotFound(err) {
return err
}

util.Ctx.Log.Info("subscription " + name + " not found")
}

return nil
return util.DeleteSubscription(name, name)
}

func GetCombinedName(d Deployer, w workloads.Workload) string {
Expand Down
2 changes: 1 addition & 1 deletion e2e/deployers/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s Subscription) Undeploy(w workloads.Workload) error {
return err
}

err = deletePlacement(name, namespace)
err = util.DeletePlacement(name, namespace)
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions e2e/exhaustive_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package e2e_test

import (
"flag"
"fmt"
"testing"

Expand All @@ -17,6 +18,10 @@ import (
// Workloads = {"Deployment", "STS", "DaemonSet"}
// Classes = {"rbd", "cephfs"}

func init() {
flag.BoolVar(&util.CleanUp, "cleanUp", false, "Clean up required after tests are run")
}

const (
GITPATH = "workloads/deployment/base"
GITREVISION = "main"
Expand Down
11 changes: 11 additions & 0 deletions e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,15 @@ func TestSuites(t *testing.T) {
for _, suite := range Suites {
t.Run(suite.name, suite.test)
}

if util.CleanUp {
t.Cleanup(func() {
if err := util.CleanUpWorkloads(); err != nil {
t.Fatalf("failed to delete placement ")
}
if err := util.EnsureChannelDeleted(); err != nil {
t.Fatalf("failed to ensure channel deleted: %v", err)
}
})
}
}
5 changes: 4 additions & 1 deletion e2e/util/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import (
placementrule "open-cluster-management.io/multicloud-operators-subscription/pkg/apis/apps/placementrule/v1"
)

var ConfigFile string
var (
ConfigFile string
CleanUp bool
)

type Cluster struct {
K8sClientSet *kubernetes.Clientset
Expand Down
78 changes: 78 additions & 0 deletions e2e/util/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ocmv1b1 "open-cluster-management.io/api/cluster/v1beta1"
channelv1 "open-cluster-management.io/multicloud-operators-channel/pkg/apis/apps/v1"
subscriptionv1 "open-cluster-management.io/multicloud-operators-subscription/pkg/apis/apps/v1"
)

func CreateNamespace(client client.Client, namespace string) error {
Expand Down Expand Up @@ -154,3 +156,79 @@

return client.Update(context.Background(), objNs)
}

// Delete all the subscriptions that are associated with channel
func CleanUpWorkloads() error {
channel := GetChannelNamespace() + "/" + GetChannelName()
subList := &subscriptionv1.SubscriptionList{}

if err := Ctx.Hub.CtrlClient.List(context.Background(), subList); err != nil {
return err
}

for _, sub := range subList.Items {
if sub.Spec.Channel == channel {
// delete placement
pName := sub.Spec.Placement.PlacementRef.Name
pNamespace := sub.Namespace

if err := DeletePlacement(pName, pNamespace); err != nil {
Ctx.Log.Error(err, "error deleting placement")

return err
}
// delete subscription
err := DeleteSubscription(sub.Name, sub.Name)
if err != nil {
Ctx.Log.Error(err, "error deleting subscription")

return err
}
}
}

return nil
}

func DeletePlacement(name, namespace string) error {
placement := &ocmv1b1.Placement{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
}

err := Ctx.Hub.CtrlClient.Delete(context.Background(), placement)
if err != nil {
if !errors.IsNotFound(err) {
return err
}

Ctx.Log.Info("placement " + name + " not found")
}
Ctx.Log.Info("placement " + placement.Name + " is deleted")

Check failure on line 209 in e2e/util/crud.go

View workflow job for this annotation

GitHub Actions / Golangci Lint (e2e)

expressions should not be cuddled with blocks (wsl)

Check failure on line 209 in e2e/util/crud.go

View workflow job for this annotation

GitHub Actions / Golangci Lint (e2e)

expressions should not be cuddled with blocks (wsl)

return nil
}

func DeleteSubscription(name, ns string) error {
subscription := &subscriptionv1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
},
}

err := Ctx.Hub.CtrlClient.Delete(context.Background(), subscription)
if err != nil {
if !errors.IsNotFound(err) {
return err
}

Ctx.Log.Info("subscription " + name + " not found")
}

Ctx.Log.Info("subscription " + subscription.Name + " is deleted")

return nil
}
Loading