Skip to content

Commit 61234bc

Browse files
authored
Merge pull request #188 from red-hat-storage/sync_us--main
Syncing latest changes from upstream main for ramen
2 parents d428ff2 + 34891bf commit 61234bc

File tree

7 files changed

+126
-99
lines changed

7 files changed

+126
-99
lines changed

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
go-version: ${{ env.GO_VERSION }}
101101

102102
- name: Run unit tests
103-
run: GO_TEST_GINKGO_ARGS="" make test
103+
run: make test
104104

105105
drenv-test:
106106
name: drenv tests

Makefile

+56-64
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ else
7575
GOBIN=$(shell go env GOBIN)
7676
endif
7777

78-
# Setting SHELL to bash allows bash commands to be executed by recipes.
79-
# This is a requirement for 'setup-envtest.sh' in the test target.
80-
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
81-
SHELL = /usr/bin/env bash -o pipefail
82-
.SHELLFLAGS = -ec
83-
8478
# Set sed command appropriately
8579
SED_CMD:=sed
8680
ifeq ($(GOHOSTOS),darwin)
@@ -89,15 +83,9 @@ ifeq ($(GOHOSTOS),darwin)
8983
endif
9084
endif
9185

92-
GO_TEST_GINKGO_ARGS ?= -test.v -ginkgo.v -ginkgo.fail-fast
9386

9487
DOCKERCMD ?= podman
9588

96-
ENVTEST_K8S_VERSION = 1.25.0
97-
ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
98-
# Define to override the path to envtest executables.
99-
KUBEBUILDER_ASSETS ?= $(shell $(ENVTEST_ASSETS_DIR)/setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(ENVTEST_ASSETS_DIR) --print path)
100-
10189
all: build
10290

10391
##@ General
@@ -124,60 +112,64 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
124112
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
125113
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
126114

127-
.PHONY: golangci-bin
128-
golangci-bin:
129-
@hack/install-golangci-lint.sh
130115

131116
.PHONY: lint
132117
lint: golangci-bin ## Run configured golangci-lint and pre-commit.sh linters against the code.
133118
testbin/golangci-lint run ./... --config=./.golangci.yaml
134119
hack/pre-commit.sh
135120

136-
envtest:
137-
mkdir -p $(ENVTEST_ASSETS_DIR)
138-
test -s $(ENVTEST_ASSETS_DIR)/setup-envtest || GOBIN=$(ENVTEST_ASSETS_DIR) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
121+
##@ Tests
139122

140-
test: generate manifests envtest ## Run tests.
141-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -coverprofile cover.out $(GO_TEST_GINKGO_ARGS)
123+
test: generate manifests envtest ## Run all the tests.
124+
go test ./... -coverprofile cover.out
142125

143-
test-pvrgl: generate manifests envtest
144-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus ProtectedVolumeReplicationGroupList
126+
test-pvrgl: generate manifests envtest ## Run ProtectedVolumeReplicationGroupList tests.
127+
go test ./controllers -coverprofile cover.out -ginkgo.focus ProtectedVolumeReplicationGroupList
145128

146-
test-obj: generate manifests envtest
147-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus FakeObjectStorer
129+
test-obj: generate manifests envtest ## Run ObjectStorer tests.
130+
go test ./controllers -coverprofile cover.out -ginkgo.focus FakeObjectStorer
148131

149-
test-vs: generate manifests envtest
150-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers/volsync -coverprofile cover.out $(GO_TEST_GINKGO_ARGS)
132+
test-vs: generate manifests envtest ## Run VolumeSync tests.
133+
go test ./controllers/volsync -coverprofile cover.out
151134

152-
test-vrg: generate manifests envtest
153-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VolumeReplicationGroup
135+
test-vrg: generate manifests envtest ## Run VolumeReplicationGroup tests.
136+
go test ./controllers -coverprofile cover.out -ginkgo.focus VolumeReplicationGroup
154137

155-
test-vrg-pvc: generate manifests envtest
156-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VolumeReplicationGroupPVC
138+
test-vrg-pvc: generate manifests envtest ## Run VolumeReplicationGroupPVC tests.
139+
go test ./controllers -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupPVC
157140

158-
test-vrg-vr: generate manifests envtest
159-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VolumeReplicationGroupVolRep
141+
test-vrg-vr: generate manifests envtest ## Run VolumeReplicationGroupVolRep tests.
142+
go test ./controllers -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupVolRep
160143

161-
test-vrg-vs: generate manifests envtest
162-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VolumeReplicationGroupVolSync
144+
test-vrg-vs: generate manifests envtest ## Run VolumeReplicationGroupVolSync tests.
145+
go test ./controllers -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupVolSync
163146

164-
test-vrg-recipe: generate manifests envtest
165-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VolumeReplicationGroupRecipe
147+
test-vrg-recipe: generate manifests envtest ## Run VolumeReplicationGroupRecipe tests.
148+
go test ./controllers -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupRecipe
166149

167-
test-vrg-kubeobjects: generate manifests envtest
168-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus VRG_KubeObjectProtection
150+
test-vrg-kubeobjects: generate manifests envtest ## Run VolumeReplicationGroupKubeObjects tests.
151+
go test ./controllers -coverprofile cover.out -ginkgo.focus VRG_KubeObjectProtection
169152

170-
test-drpc: generate manifests envtest
171-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus DRPlacementControl
153+
test-drpc: generate manifests envtest ## Run DRPlacementControl tests.
154+
go test ./controllers -coverprofile cover.out -ginkgo.focus DRPlacementControl
172155

173-
test-drcluster: generate manifests envtest
174-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus DRClusterController
156+
test-drcluster: generate manifests envtest ## Run DRCluster tests.
157+
go test ./controllers -coverprofile cover.out -ginkgo.focus DRClusterController
158+
159+
test-util: generate manifests envtest ## Run util tests.
160+
go test ./controllers/util -coverprofile cover.out
161+
162+
test-util-pvc: generate manifests envtest ## Run util-pvc tests.
163+
go test ./controllers/util -coverprofile cover.out -ginkgo.focus PVCS_Util
164+
165+
test-drenv: ## Run drenv tests.
166+
$(MAKE) -C test
175167

176-
test-util: generate manifests envtest
177-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers/util -coverprofile cover.out $(GO_TEST_GINKGO_ARGS)
168+
test-ramenctl: ## Run ramenctl tests.
169+
$(MAKE) -C ramenctl
178170

179-
test-util-pvc: generate manifests envtest
180-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers/util -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus PVCS_Util
171+
e2e-rdr: generate manifests docker-build ## Run rdr-e2e tests.
172+
./e2e/rdr-e2e.sh
181173

182174
coverage:
183175
go tool cover -html=cover.out
@@ -186,15 +178,6 @@ coverage:
186178
venv:
187179
hack/make-venv
188180

189-
test-drenv:
190-
$(MAKE) -C test
191-
192-
test-ramenctl:
193-
$(MAKE) -C ramenctl
194-
195-
e2e-rdr: generate manifests docker-build
196-
./e2e/rdr-e2e.sh
197-
198181
##@ Build
199182

200183
# Build manager binary
@@ -258,21 +241,35 @@ undeploy-dr-cluster: kustomize ## Undeploy dr-cluster controller from the K8s cl
258241
##@ Tools
259242

260243
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
261-
controller-gen: ## Download controller-gen locally if necessary.
244+
controller-gen: ## Download controller-gen locally.
262245
@hack/install-controller-gen.sh
263246

264247
.PHONY: kustomize
265248
KUSTOMIZE = $(shell pwd)/bin/kustomize
266-
kustomize: ## Download kustomize locally if necessary.
249+
kustomize: ## Download kustomize locally.
267250
@hack/install-kustomize.sh
268251

269-
##@ Bundle
252+
.PHONY: opm
253+
OPM = ./bin/opm
254+
opm: ## Download opm locally.
255+
@./hack/install-opm.sh
270256

271257
.PHONY: operator-sdk
272258
OSDK = ./bin/operator-sdk
273-
operator-sdk: ## Download operator-sdk locally if necessary.
259+
operator-sdk: ## Download operator-sdk locally.
274260
@hack/install-operator-sdk.sh
275261

262+
.PHONY: golangci-bin
263+
golangci-bin: ## Download golangci-lint locally.
264+
@hack/install-golangci-lint.sh
265+
266+
.PHONY: envtest
267+
envtest: ## Download envtest locally.
268+
hack/install-setup-envtest.sh
269+
270+
271+
##@ Bundle
272+
276273
.PHONY: bundle
277274
bundle: bundle-hub bundle-dr-cluster ## Generate all bundle manifests and metadata, then validate generated files.
278275

@@ -327,11 +324,6 @@ bundle-dr-cluster-build: bundle-dr-cluster ## Build the dr-cluster bundle image.
327324
bundle-dr-cluster-push: ## Push the dr-cluster bundle image.
328325
$(MAKE) docker-push IMG=$(BUNDLE_IMG_DRCLUSTER)
329326

330-
.PHONY: opm
331-
OPM = ./bin/opm
332-
opm: ## Download opm locally if necessary.
333-
@./hack/install-opm.sh
334-
335327
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
336328
# These images MUST exist in a registry and be pull-able.
337329
BUNDLE_IMGS ?= $(BUNDLE_IMG_HUB),$(BUNDLE_IMG_DRCLUSTER)

controllers/drplacementcontrol_controller.go

+23-22
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,12 @@ func (r *DRPlacementControlReconciler) updateDRPCStatus(
16781678

16791679
clusterDecision := r.getClusterDecision(userPlacement)
16801680
if clusterDecision != nil && clusterDecision.ClusterName != "" && vrgNamespace != "" {
1681-
r.updateResourceCondition(ctx, drpc, clusterDecision.ClusterName, vrgNamespace, log)
1681+
r.updateResourceCondition(drpc, clusterDecision.ClusterName, vrgNamespace, log)
1682+
}
1683+
1684+
if err := r.setDRPCMetrics(ctx, drpc, log); err != nil {
1685+
// log the error but do not return the error
1686+
log.Info("failed to set drpc metrics", "errMSg", err)
16821687
}
16831688

16841689
for i, condition := range drpc.Status.Conditions {
@@ -1706,7 +1711,6 @@ func (r *DRPlacementControlReconciler) updateDRPCStatus(
17061711
}
17071712

17081713
func (r *DRPlacementControlReconciler) updateResourceCondition(
1709-
ctx context.Context,
17101714
drpc *rmn.DRPlacementControl,
17111715
clusterName, vrgNamespace string,
17121716
log logr.Logger,
@@ -1722,30 +1726,27 @@ func (r *DRPlacementControlReconciler) updateResourceCondition(
17221726
log.Info("Failed to get VRG from managed cluster", "errMsg", err.Error())
17231727

17241728
drpc.Status.ResourceConditions = rmn.VRGConditions{}
1725-
} else {
1726-
drpc.Status.ResourceConditions.ResourceMeta.Kind = vrg.Kind
1727-
drpc.Status.ResourceConditions.ResourceMeta.Name = vrg.Name
1728-
drpc.Status.ResourceConditions.ResourceMeta.Namespace = vrg.Namespace
1729-
drpc.Status.ResourceConditions.ResourceMeta.Generation = vrg.Generation
1730-
drpc.Status.ResourceConditions.Conditions = vrg.Status.Conditions
1731-
1732-
protectedPVCs := []string{}
1733-
for _, protectedPVC := range vrg.Status.ProtectedPVCs {
1734-
protectedPVCs = append(protectedPVCs, protectedPVC.Name)
1735-
}
17361729

1737-
drpc.Status.ResourceConditions.ResourceMeta.ProtectedPVCs = protectedPVCs
1730+
return
1731+
}
17381732

1739-
if vrg.Status.LastGroupSyncTime != nil || drpc.Spec.Action != rmn.ActionRelocate {
1740-
drpc.Status.LastGroupSyncTime = vrg.Status.LastGroupSyncTime
1741-
drpc.Status.LastGroupSyncDuration = vrg.Status.LastGroupSyncDuration
1742-
drpc.Status.LastGroupSyncBytes = vrg.Status.LastGroupSyncBytes
1743-
}
1733+
drpc.Status.ResourceConditions.ResourceMeta.Kind = vrg.Kind
1734+
drpc.Status.ResourceConditions.ResourceMeta.Name = vrg.Name
1735+
drpc.Status.ResourceConditions.ResourceMeta.Namespace = vrg.Namespace
1736+
drpc.Status.ResourceConditions.ResourceMeta.Generation = vrg.Generation
1737+
drpc.Status.ResourceConditions.Conditions = vrg.Status.Conditions
1738+
1739+
protectedPVCs := []string{}
1740+
for _, protectedPVC := range vrg.Status.ProtectedPVCs {
1741+
protectedPVCs = append(protectedPVCs, protectedPVC.Name)
17441742
}
17451743

1746-
if err := r.setDRPCMetrics(ctx, drpc, log); err != nil {
1747-
// log the error but do not return the error
1748-
log.Info("failed to set drpc metrics", "errMSg", err)
1744+
drpc.Status.ResourceConditions.ResourceMeta.ProtectedPVCs = protectedPVCs
1745+
1746+
if vrg.Status.LastGroupSyncTime != nil || drpc.Spec.Action != rmn.ActionRelocate {
1747+
drpc.Status.LastGroupSyncTime = vrg.Status.LastGroupSyncTime
1748+
drpc.Status.LastGroupSyncDuration = vrg.Status.LastGroupSyncDuration
1749+
drpc.Status.LastGroupSyncBytes = vrg.Status.LastGroupSyncBytes
17491750
}
17501751
}
17511752

controllers/suite_test.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ package controllers_test
55

66
import (
77
"context"
8-
"fmt"
98
"os"
109
"path/filepath"
11-
"runtime"
1210
"testing"
1311
"time"
1412

@@ -128,8 +126,15 @@ var _ = BeforeSuite(func() {
128126
ramencontrollers.ControllerType = ramendrv1alpha1.DRHubType
129127

130128
if _, set := os.LookupEnv("KUBEBUILDER_ASSETS"); !set {
131-
Expect(os.Setenv("KUBEBUILDER_ASSETS",
132-
fmt.Sprintf("../testbin/k8s/1.25.0-%s-%s", runtime.GOOS, runtime.GOARCH))).To(Succeed())
129+
testLog.Info("Setting up KUBEBUILDER_ASSETS for envtest")
130+
131+
// read content of the file ../testbin/testassets.txt
132+
// and set the content as the value of KUBEBUILDER_ASSETS
133+
// this is to avoid the need to set KUBEBUILDER_ASSETS
134+
// when running the test suite
135+
content, err := os.ReadFile("../testbin/testassets.txt")
136+
Expect(err).NotTo(HaveOccurred())
137+
Expect(os.Setenv("KUBEBUILDER_ASSETS", string(content))).To(Succeed())
133138
}
134139

135140
rNs, set := os.LookupEnv("POD_NAMESPACE")

controllers/util/util_suite_test.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ package util_test
55

66
import (
77
"context"
8-
"fmt"
98
"os"
109
"path/filepath"
11-
"runtime"
1210
"testing"
1311
"time"
1412

@@ -62,8 +60,15 @@ var _ = BeforeSuite(func() {
6260

6361
By("Setting up KUBEBUILDER_ASSETS for envtest")
6462
if _, set := os.LookupEnv("KUBEBUILDER_ASSETS"); !set {
65-
Expect(os.Setenv("KUBEBUILDER_ASSETS",
66-
fmt.Sprintf("../../testbin/k8s/1.25.0-%s-%s", runtime.GOOS, runtime.GOARCH))).To(Succeed())
63+
testLog.Info("Setting up KUBEBUILDER_ASSETS for envtest")
64+
65+
// read content of the file ../../testbin/testassets.txt
66+
// and set the content as the value of KUBEBUILDER_ASSETS
67+
// this is to avoid the need to set KUBEBUILDER_ASSETS
68+
// when running the test suite
69+
content, err := os.ReadFile("../../testbin/testassets.txt")
70+
Expect(err).NotTo(HaveOccurred())
71+
Expect(os.Setenv("KUBEBUILDER_ASSETS", string(content))).To(Succeed())
6772
}
6873

6974
By("Bootstrapping test environment")

controllers/volsync/volsync_suite_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ package volsync_test
55

66
import (
77
"context"
8-
"fmt"
98
"os"
109
"path/filepath"
11-
"runtime"
1210
"testing"
1311

1412
"github.com/go-logr/logr"
@@ -77,8 +75,14 @@ var _ = BeforeSuite(func() {
7775

7876
By("Setting up KUBEBUILDER_ASSETS for envtest")
7977
if _, set := os.LookupEnv("KUBEBUILDER_ASSETS"); !set {
80-
Expect(os.Setenv("KUBEBUILDER_ASSETS",
81-
fmt.Sprintf("../../testbin/k8s/1.25.0-%s-%s", runtime.GOOS, runtime.GOARCH))).To(Succeed())
78+
79+
// read content of the file ../../testbin/testassets.txt
80+
// and set the content as the value of KUBEBUILDER_ASSETS
81+
// this is to avoid the need to set KUBEBUILDER_ASSETS
82+
// when running the test suite
83+
content, err := os.ReadFile("../../testbin/testassets.txt")
84+
Expect(err).NotTo(HaveOccurred())
85+
Expect(os.Setenv("KUBEBUILDER_ASSETS", string(content))).To(Succeed())
8286
}
8387

8488
By("bootstrapping test environment")

hack/install-setup-envtest.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -e
3+
4+
script_dir="$(cd "$(dirname "$0")" && pwd)"
5+
6+
required_version="latest"
7+
source_url="sigs.k8s.io/controller-runtime/tools/setup-envtest@${required_version}"
8+
target_dir="${script_dir}/../testbin"
9+
target_path="${target_dir}/setup-envtest"
10+
k8s_version="1.29.0"
11+
12+
# The setup-envtest tool has no versioning, so we need to use the latest version.
13+
# The go install command is fast enough that it can be run every time.
14+
mkdir -p "${target_dir}"
15+
GOBIN="${target_dir}" go install "${source_url}"
16+
17+
# Storing the path to the assets in a file so that it can be used by the test files.
18+
# Making the name of the file version agnostic so that changing the version is easier.
19+
kubebuilder_assets=$("${target_path}" use "${k8s_version}" --bin-dir "${target_dir}" --print path)
20+
echo -n "${kubebuilder_assets}" > "${target_dir}/testassets.txt"

0 commit comments

Comments
 (0)