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

Syncing latest changes from main for ramen #383

Merged
merged 7 commits into from
Oct 28, 2024
Merged
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
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,21 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."


.PHONY: lint
lint: golangci-bin ## Run configured golangci-lint and pre-commit.sh linters against the code.
# golangci-lint has a limitation that it doesn't lint subdirectories if
# they are a different module.
# see https://github.com/golangci/golangci-lint/issues/828

.PHONY: lint
lint: golangci-bin lint-e2e lint-api ## Run configured golangci-lint and pre-commit.sh linters against the code.
testbin/golangci-lint run ./... --config=./.golangci.yaml
cd api && ../testbin/golangci-lint run ./... --config=../.golangci.yaml
cd e2e && ../testbin/golangci-lint run ./... --config=../.golangci.yaml
hack/pre-commit.sh

lint-e2e: golangci-bin ## Run configured golangci-lint for e2e module
cd e2e && ../testbin/golangci-lint run ./... --config=../.golangci.yaml

lint-api: golangci-bin ## Run configured golangci-lint for api module
cd api && ../testbin/golangci-lint run ./... --config=../.golangci.yaml

.PHONY: create-rdr-env
create-rdr-env: drenv-prereqs ## Create a new rdr environment.
./hack/dev-env.sh create
Expand Down Expand Up @@ -195,7 +200,7 @@ test-ramenctl: ## Run ramenctl tests.
$(MAKE) -C ramenctl

e2e-rdr: generate manifests ## Run rdr-e2e tests.
cd e2e && ./e2e-rdr.sh
cd e2e && ./run.sh

coverage:
go tool cover -html=cover.out
Expand Down
53 changes: 30 additions & 23 deletions e2e/dractions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ramendr/ramen/e2e/deployers"
"github.com/ramendr/ramen/e2e/util"
"github.com/ramendr/ramen/e2e/workloads"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -42,7 +43,7 @@ func EnableProtection(w workloads.Workload, d deployers.Deployer) error {
placementName := name
drpcName := name

placement, placementDecisionName, err := waitPlacementDecision(util.Ctx.Hub.CtrlClient, namespace, placementName)
placementDecisionName, err := waitPlacementDecision(util.Ctx.Hub.CtrlClient, namespace, placementName)
if err != nil {
return err
}
Expand All @@ -55,18 +56,22 @@ func EnableProtection(w workloads.Workload, d deployers.Deployer) error {
clusterName := placementDecision.Status.Decisions[0].ClusterName
util.Ctx.Log.Info("got clusterName " + clusterName + " from " + placementDecisionName)

// move update placement annotation after placement has been handled
// otherwise if we first add ocm disable annotation then it might not
// yet be handled by ocm and thus PlacementSatisfied=false
if placement.Annotations == nil {
placement.Annotations = make(map[string]string)
}
util.Ctx.Log.Info("update placement " + placementName + " annotation")

placement.Annotations[OcmSchedulingDisable] = "true"
err = retry.RetryOnConflict(retry.DefaultBackoff, func() error {
placement, err := getPlacement(util.Ctx.Hub.CtrlClient, namespace, placementName)
if err != nil {
return err
}

util.Ctx.Log.Info("update placement " + placementName + " annotation")
if placement.Annotations == nil {
placement.Annotations = make(map[string]string)
}
placement.Annotations[OcmSchedulingDisable] = "true"

if err = updatePlacement(util.Ctx.Hub.CtrlClient, placement); err != nil {
return updatePlacement(util.Ctx.Hub.CtrlClient, placement)
})
if err != nil {
return err
}

Expand Down Expand Up @@ -160,11 +165,6 @@ func waitAndUpdateDRPC(client client.Client, namespace, drpcName string, action
return err
}

drpc, err := getDRPC(client, namespace, drpcName)
if err != nil {
return err
}

drPolicyName := util.DefaultDRPolicyName

drpolicy, err := util.GetDRPolicy(client, drPolicyName)
Expand All @@ -177,16 +177,23 @@ func waitAndUpdateDRPC(client client.Client, namespace, drpcName string, action
return err
}

drpc.Spec.Action = action
if action == ramen.ActionFailover {
drpc.Spec.FailoverCluster = targetCluster
} else {
drpc.Spec.PreferredCluster = targetCluster
}

util.Ctx.Log.Info("update drpc " + drpcName + " " + strings.ToLower(string(action)) + " to " + targetCluster)

return updateDRPC(client, drpc)
return retry.RetryOnConflict(retry.DefaultBackoff, func() error {
drpc, err := getDRPC(client, namespace, drpcName)
if err != nil {
return err
}

drpc.Spec.Action = action
if action == ramen.ActionFailover {
drpc.Spec.FailoverCluster = targetCluster
} else {
drpc.Spec.PreferredCluster = targetCluster
}

return updateDRPC(client, drpc)
})
}

func GetNamespace(d deployers.Deployer, w workloads.Workload) string {
Expand Down
14 changes: 7 additions & 7 deletions e2e/dractions/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ import (
)

// nolint:gocognit
// return placement object, placementDecisionName, error
// return placementDecisionName, error
func waitPlacementDecision(client client.Client, namespace string, placementName string,
) (*v1beta1.Placement, string, error) {
) (string, error) {
startTime := time.Now()
placementDecisionName := ""

for {
placement, err := getPlacement(client, namespace, placementName)
if err != nil {
return nil, "", err
return "", err
}

for _, cond := range placement.Status.Conditions {
if cond.Type == "PlacementSatisfied" && cond.Status == "True" {
placementDecisionName = placement.Status.DecisionGroups[0].Decisions[0]
if placementDecisionName != "" {
return placement, placementDecisionName, nil
return placementDecisionName, nil
}
}
}
Expand All @@ -41,11 +41,11 @@ func waitPlacementDecision(client client.Client, namespace string, placementName
// so need query placementdecision by label
placementDecision, err := getPlacementDecisionFromPlacement(client, placement)
if err == nil && placementDecision != nil {
return placement, placementDecision.Name, nil
return placementDecision.Name, nil
}

if time.Since(startTime) > time.Second*time.Duration(util.Timeout) {
return nil, "", fmt.Errorf(
return "", fmt.Errorf(
"could not get placement decision for " + placementName + " before timeout, fail")
}

Expand Down Expand Up @@ -136,7 +136,7 @@ func waitDRPCPhase(client client.Client, namespace, name string, phase ramen.DRS
}

func getCurrentCluster(client client.Client, namespace string, placementName string) (string, error) {
_, placementDecisionName, err := waitPlacementDecision(client, namespace, placementName)
placementDecisionName, err := waitPlacementDecision(client, namespace, placementName)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func init() {
flag.StringVar(&util.ConfigFile, "configfile", "", "Path to the config file")
flag.StringVar(&util.ConfigFile, "config", "", "Path to the config file")
}

func TestMain(m *testing.M) {
Expand Down
File renamed without changes.
Loading