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

e2e: adding testcases with recipe #1736

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6ab815a
e2e: adding testcases with recipe
asn1809 Jan 2, 2025
59eb075
e2e: adding volumes section to recipe
asn1809 Jan 8, 2025
637e9a8
e2e: add a sample config file as config.yaml.sample
raghavendra-talur Jan 3, 2025
5d4f75c
Enable VolSync protection for any PVC type via DRPC annotation
Dec 17, 2024
d173ef8
Restrict ReadOnlyMany accessMode to CephFS PVCs only
Dec 17, 2024
0b89d36
Support original accessModes for non-CephFS source PVCs
Dec 18, 2024
ab2c18f
Delay temporary PVC creation until scheduled time on fresh deploy
Dec 18, 2024
80465f7
Clean up unit test
Dec 19, 2024
be376f8
vrg: always get complete RecipeElements if recipe exists
raghavendra-talur Jan 7, 2025
d912252
vrg: RecipeElementsGet should return RecipeElements
raghavendra-talur Jan 7, 2025
20a07d0
tests: fix the tests
raghavendra-talur Jan 8, 2025
8d6e098
Fix typos in drplacementcontroller
nirs Jan 13, 2025
94f96c1
Fix typos in drplacementcontrol tests
nirs Jan 13, 2025
36c10d2
vrg: cleanup rd when vrg is secondary
raghavendra-talur Jan 7, 2025
3bc86fa
e2e: enable discovered app tests for cephfs
raghavendra-talur Jan 7, 2025
c285a16
golangci-lint: remove if-return from the linters
raghavendra-talur Jan 9, 2025
ac85abf
vrg: return nil on error
raghavendra-talur Jan 10, 2025
3bbc759
Update macOS setup instructions
nirs Dec 4, 2024
2975b36
ci: Timeout gather job after 3 minutes
nirs Jan 14, 2025
f4677aa
Update ramen to use csi-addons 0.11.0
nirs Jan 13, 2025
078f770
ci: Fix gather timeout
nirs Jan 14, 2025
8f8ada6
ramenctl: enable volsync
raghavendra-talur Jan 14, 2025
30dc1db
vrg: use reader instead of client for check hooks
raghavendra-talur Jan 9, 2025
cb53056
e2e: some additional changes
asn1809 Jan 22, 2025
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
225 changes: 224 additions & 1 deletion e2e/deployers/discoveredapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,36 @@
package deployers

import (
"context"
"fmt"
"os"
"os/exec"

"github.com/ramendr/ramen/e2e/types"
"github.com/ramendr/ramen/e2e/util"
recipe "github.com/ramendr/recipe/api/v1alpha1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8stypes "k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type DiscoveredApp struct{}
const timeout = 300

type DiscoveredApp struct {
IncludeRecipe bool
IncludeHooks bool
}

func (d DiscoveredApp) GetName() string {
if d.IncludeRecipe {
if d.IncludeHooks {
return "disapp-recipe-hooks"
}

return "disapp-recipe"
}

return "disapp"
}

Expand Down Expand Up @@ -68,6 +87,16 @@ func (d DiscoveredApp) Deploy(ctx types.Context) error {

log.Info("Workload deployed")

// recipe needs to be created based on flags
if d.IncludeRecipe {
recipeName := ctx.Name() + "-recipe"
if err := createRecipe(recipeName, appNamespace, d.IncludeHooks); err != nil {
log.Info("recipe creation failed")
}

log.Info("recipe created on both dr clusters")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be part of the workload, not of the deployer.


return nil
}

Expand Down Expand Up @@ -96,6 +125,22 @@ func (d DiscoveredApp) Undeploy(ctx types.Context) error {
return err
}

if d.IncludeRecipe {
recipeName := ctx.Name() + "-recipe"

log.Infof("Deleting recipe on cluster %q", drpolicy.Spec.DRClusters[0])

if err := deleteRecipe(util.Ctx.C1.Client, recipeName, appNamespace); err != nil {
return err
}

log.Infof("Deleting recipe on cluster %q", drpolicy.Spec.DRClusters[1])

if err := deleteRecipe(util.Ctx.C2.Client, recipeName, appNamespace); err != nil {
return err
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, part of the workload.


log.Infof("Deleting namespace %q on cluster %q", appNamespace, drpolicy.Spec.DRClusters[0])

// delete namespace on both clusters
Expand All @@ -117,3 +162,181 @@ func (d DiscoveredApp) Undeploy(ctx types.Context) error {
func (d DiscoveredApp) IsDiscovered() bool {
return true
}

func createRecipe(name, namespace string, includeHooks bool) error {
var recipe *recipe.Recipe
if includeHooks {
recipe = getRecipeWithHooks(name, namespace)
} else {
recipe = getRecipeWithoutHooks(name, namespace)
}

err := util.Ctx.C1.Client.Create(context.Background(), recipe)
if err != nil {
if !errors.IsAlreadyExists(err) {
return err
}

util.Ctx.Log.Info("recipe " + name + " already exists" + " in the cluster " + "C1")
}

err = util.Ctx.C2.Client.Create(context.Background(), recipe)
if err != nil {
if !errors.IsAlreadyExists(err) {
return err
}

util.Ctx.Log.Info("recipe " + name + " already exists" + " in the cluster " + "C2")
}

return nil
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functions for creating recipes should move to recipes package or maybe workloads since recipes are part of a workload.

func getRecipeWithoutHooks(name, namespace string) *recipe.Recipe {
return &recipe.Recipe{
TypeMeta: metav1.TypeMeta{
Kind: "Recipe",
APIVersion: "ramendr.openshift.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: recipe.RecipeSpec{
AppType: "busybox",
Groups: []*recipe.Group{
{
Name: "rg1",
Type: "resource",
BackupRef: "rg1",
IncludedNamespaces: []string{
namespace,
},
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "appname",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"busybox"},
},
},
},
},
},
Workflows: []*recipe.Workflow{
{
Name: "backup",
Sequence: []map[string]string{
{
"group": "rg1",
},
},
},
{
Name: "restore",
Sequence: []map[string]string{
{
"group": "rg1",
},
},
},
},
},
}
}

func getRecipeWithHooks(name, namespace string) *recipe.Recipe {
return &recipe.Recipe{
TypeMeta: metav1.TypeMeta{
Kind: "Recipe",
APIVersion: "ramendr.openshift.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: recipe.RecipeSpec{
AppType: "busybox",
Groups: []*recipe.Group{
{
Name: "rg1",
Type: "resource",
BackupRef: "rg1",
IncludedNamespaces: []string{
namespace,
},
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "appname",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"busybox"},
},
},
},
},
},
Hooks: []*recipe.Hook{
getHookSpec(namespace, "backup"),
getHookSpec(namespace, "restore"),
},
Workflows: []*recipe.Workflow{
{
Name: "backup",
Sequence: []map[string]string{
{
"hook": "backup/check-replicas",
},
{
"group": "rg1",
},
},
},
{
Name: "restore",
Sequence: []map[string]string{
{
"group": "rg1",
},
{
"hook": "restore/check-replicas",
},
},
},
},
},
}
}

func getHookSpec(namespace, hookType string) *recipe.Hook {
return &recipe.Hook{
Name: hookType,
Type: "check",
Namespace: namespace,
NameSelector: "busybox",
SelectResource: "deployment",
Timeout: timeout,
Chks: []*recipe.Check{
{
Name: "check-replicas",
Condition: "{$.spec.replicas} == {$.status.readyReplicas}",
},
},
}
}

func deleteRecipe(client client.Client, name, namespace string) error {
r := &recipe.Recipe{}
key := k8stypes.NamespacedName{Namespace: namespace, Name: name}

err := client.Get(context.Background(), key, r)
if err != nil {
if !errors.IsNotFound(err) {
return err
}

return nil
}

return client.Delete(context.Background(), r)
}
11 changes: 11 additions & 0 deletions e2e/dractions/discovered.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ func EnableProtectionDiscoveredApps(ctx types.Context) error {

drpc := generateDRPCDiscoveredApps(
name, managementNamespace, clusterName, drPolicyName, placementName, appname, appNamespace)

if v, ok := ctx.Deployer().(deployers.DiscoveredApp); ok {
if v.IncludeRecipe {
recipeName := name + "-recipe"
drpc.Spec.KubeObjectProtection.RecipeRef = &ramen.RecipeRef{
Namespace: appNamespace,
Name: recipeName,
}
}
}

if err = createDRPC(util.Ctx.Hub.Client, drpc); err != nil {
return err
}
Expand Down
15 changes: 10 additions & 5 deletions e2e/exhaustive_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ const (
)

var (
Workloads = []types.Workload{}
subscription = &deployers.Subscription{}
appset = &deployers.ApplicationSet{}
discoveredApps = &deployers.DiscoveredApp{}
Deployers = []types.Deployer{subscription, appset, discoveredApps}
Workloads = []types.Workload{}
subscription = &deployers.Subscription{}
appset = &deployers.ApplicationSet{}
discoveredApps = &deployers.DiscoveredApp{}
discoveredAppsWithoutHook = &deployers.DiscoveredApp{IncludeRecipe: true, IncludeHooks: false}
discoveredAppsWithHook = &deployers.DiscoveredApp{IncludeRecipe: true, IncludeHooks: true}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to keep discoveredApps deployer and add workloads including a recipe with/without hooks.

Also we don't want to add so many tests - this add 2 new deployers, which adds 4 new tests. Why do w need to test recipe without hook and recipe with hook with both rbd and ceph storage? Does recipe/hooks care about the storage which is handled by ramen anyway?

Deployers = []types.Deployer{
subscription, appset, discoveredApps, discoveredAppsWithoutHook,
discoveredAppsWithHook,
}
)

func generateWorkloads([]types.Workload) {
Expand Down
13 changes: 7 additions & 6 deletions e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.22.7

require (
github.com/ramendr/ramen/api v0.0.0-00010101000000-000000000000
github.com/ramendr/recipe v0.0.0-20241009174526-5cecfd571447
github.com/spf13/viper v1.19.0
go.uber.org/zap v1.27.0
k8s.io/api v0.31.1
Expand All @@ -21,7 +22,7 @@ require (

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
Expand Down Expand Up @@ -57,22 +58,22 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/component-base v0.31.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240411171206-dc4e619f62f3 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
k8s.io/kube-openapi v0.0.0-20240903163716-9e1beecbcb38 // indirect
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
Expand Down
Loading
Loading