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 upstream main for ramen #188

Merged
merged 7 commits into from
Feb 9, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
go-version: ${{ env.GO_VERSION }}

- name: Run unit tests
run: GO_TEST_GINKGO_ARGS="" make test
run: make test

drenv-test:
name: drenv tests
Expand Down
120 changes: 56 additions & 64 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ else
GOBIN=$(shell go env GOBIN)
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

# Set sed command appropriately
SED_CMD:=sed
ifeq ($(GOHOSTOS),darwin)
Expand All @@ -89,15 +83,9 @@ ifeq ($(GOHOSTOS),darwin)
endif
endif

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

DOCKERCMD ?= podman

ENVTEST_K8S_VERSION = 1.25.0
ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
# Define to override the path to envtest executables.
KUBEBUILDER_ASSETS ?= $(shell $(ENVTEST_ASSETS_DIR)/setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(ENVTEST_ASSETS_DIR) --print path)

all: build

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

.PHONY: golangci-bin
golangci-bin:
@hack/install-golangci-lint.sh

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

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

test: generate manifests envtest ## Run tests.
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -coverprofile cover.out $(GO_TEST_GINKGO_ARGS)
test: generate manifests envtest ## Run all the tests.
go test ./... -coverprofile cover.out

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

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

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

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

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

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

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

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

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

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

test-drcluster: generate manifests envtest
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./controllers -coverprofile cover.out $(GO_TEST_GINKGO_ARGS) -ginkgo.focus DRClusterController
test-drcluster: generate manifests envtest ## Run DRCluster tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus DRClusterController

test-util: generate manifests envtest ## Run util tests.
go test ./controllers/util -coverprofile cover.out

test-util-pvc: generate manifests envtest ## Run util-pvc tests.
go test ./controllers/util -coverprofile cover.out -ginkgo.focus PVCS_Util

test-drenv: ## Run drenv tests.
$(MAKE) -C test

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

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

coverage:
go tool cover -html=cover.out
Expand All @@ -186,15 +178,6 @@ coverage:
venv:
hack/make-venv

test-drenv:
$(MAKE) -C test

test-ramenctl:
$(MAKE) -C ramenctl

e2e-rdr: generate manifests docker-build
./e2e/rdr-e2e.sh

##@ Build

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

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
controller-gen: ## Download controller-gen locally.
@hack/install-controller-gen.sh

.PHONY: kustomize
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
kustomize: ## Download kustomize locally.
@hack/install-kustomize.sh

##@ Bundle
.PHONY: opm
OPM = ./bin/opm
opm: ## Download opm locally.
@./hack/install-opm.sh

.PHONY: operator-sdk
OSDK = ./bin/operator-sdk
operator-sdk: ## Download operator-sdk locally if necessary.
operator-sdk: ## Download operator-sdk locally.
@hack/install-operator-sdk.sh

.PHONY: golangci-bin
golangci-bin: ## Download golangci-lint locally.
@hack/install-golangci-lint.sh

.PHONY: envtest
envtest: ## Download envtest locally.
hack/install-setup-envtest.sh


##@ Bundle

.PHONY: bundle
bundle: bundle-hub bundle-dr-cluster ## Generate all bundle manifests and metadata, then validate generated files.

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

.PHONY: opm
OPM = ./bin/opm
opm: ## Download opm locally if necessary.
@./hack/install-opm.sh

# 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).
# These images MUST exist in a registry and be pull-able.
BUNDLE_IMGS ?= $(BUNDLE_IMG_HUB),$(BUNDLE_IMG_DRCLUSTER)
Expand Down
45 changes: 23 additions & 22 deletions controllers/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,12 @@ func (r *DRPlacementControlReconciler) updateDRPCStatus(

clusterDecision := r.getClusterDecision(userPlacement)
if clusterDecision != nil && clusterDecision.ClusterName != "" && vrgNamespace != "" {
r.updateResourceCondition(ctx, drpc, clusterDecision.ClusterName, vrgNamespace, log)
r.updateResourceCondition(drpc, clusterDecision.ClusterName, vrgNamespace, log)
}

if err := r.setDRPCMetrics(ctx, drpc, log); err != nil {
// log the error but do not return the error
log.Info("failed to set drpc metrics", "errMSg", err)
}

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

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

drpc.Status.ResourceConditions = rmn.VRGConditions{}
} else {
drpc.Status.ResourceConditions.ResourceMeta.Kind = vrg.Kind
drpc.Status.ResourceConditions.ResourceMeta.Name = vrg.Name
drpc.Status.ResourceConditions.ResourceMeta.Namespace = vrg.Namespace
drpc.Status.ResourceConditions.ResourceMeta.Generation = vrg.Generation
drpc.Status.ResourceConditions.Conditions = vrg.Status.Conditions

protectedPVCs := []string{}
for _, protectedPVC := range vrg.Status.ProtectedPVCs {
protectedPVCs = append(protectedPVCs, protectedPVC.Name)
}

drpc.Status.ResourceConditions.ResourceMeta.ProtectedPVCs = protectedPVCs
return
}

if vrg.Status.LastGroupSyncTime != nil || drpc.Spec.Action != rmn.ActionRelocate {
drpc.Status.LastGroupSyncTime = vrg.Status.LastGroupSyncTime
drpc.Status.LastGroupSyncDuration = vrg.Status.LastGroupSyncDuration
drpc.Status.LastGroupSyncBytes = vrg.Status.LastGroupSyncBytes
}
drpc.Status.ResourceConditions.ResourceMeta.Kind = vrg.Kind
drpc.Status.ResourceConditions.ResourceMeta.Name = vrg.Name
drpc.Status.ResourceConditions.ResourceMeta.Namespace = vrg.Namespace
drpc.Status.ResourceConditions.ResourceMeta.Generation = vrg.Generation
drpc.Status.ResourceConditions.Conditions = vrg.Status.Conditions

protectedPVCs := []string{}
for _, protectedPVC := range vrg.Status.ProtectedPVCs {
protectedPVCs = append(protectedPVCs, protectedPVC.Name)
}

if err := r.setDRPCMetrics(ctx, drpc, log); err != nil {
// log the error but do not return the error
log.Info("failed to set drpc metrics", "errMSg", err)
drpc.Status.ResourceConditions.ResourceMeta.ProtectedPVCs = protectedPVCs

if vrg.Status.LastGroupSyncTime != nil || drpc.Spec.Action != rmn.ActionRelocate {
drpc.Status.LastGroupSyncTime = vrg.Status.LastGroupSyncTime
drpc.Status.LastGroupSyncDuration = vrg.Status.LastGroupSyncDuration
drpc.Status.LastGroupSyncBytes = vrg.Status.LastGroupSyncBytes
}
}

Expand Down
13 changes: 9 additions & 4 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ package controllers_test

import (
"context"
"fmt"
"os"
"path/filepath"
"runtime"
"testing"
"time"

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

if _, set := os.LookupEnv("KUBEBUILDER_ASSETS"); !set {
Expect(os.Setenv("KUBEBUILDER_ASSETS",
fmt.Sprintf("../testbin/k8s/1.25.0-%s-%s", runtime.GOOS, runtime.GOARCH))).To(Succeed())
testLog.Info("Setting up KUBEBUILDER_ASSETS for envtest")

// read content of the file ../testbin/testassets.txt
// and set the content as the value of KUBEBUILDER_ASSETS
// this is to avoid the need to set KUBEBUILDER_ASSETS
// when running the test suite
content, err := os.ReadFile("../testbin/testassets.txt")
Expect(err).NotTo(HaveOccurred())
Expect(os.Setenv("KUBEBUILDER_ASSETS", string(content))).To(Succeed())
}

rNs, set := os.LookupEnv("POD_NAMESPACE")
Expand Down
13 changes: 9 additions & 4 deletions controllers/util/util_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ package util_test

import (
"context"
"fmt"
"os"
"path/filepath"
"runtime"
"testing"
"time"

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

By("Setting up KUBEBUILDER_ASSETS for envtest")
if _, set := os.LookupEnv("KUBEBUILDER_ASSETS"); !set {
Expect(os.Setenv("KUBEBUILDER_ASSETS",
fmt.Sprintf("../../testbin/k8s/1.25.0-%s-%s", runtime.GOOS, runtime.GOARCH))).To(Succeed())
testLog.Info("Setting up KUBEBUILDER_ASSETS for envtest")

// read content of the file ../../testbin/testassets.txt
// and set the content as the value of KUBEBUILDER_ASSETS
// this is to avoid the need to set KUBEBUILDER_ASSETS
// when running the test suite
content, err := os.ReadFile("../../testbin/testassets.txt")
Expect(err).NotTo(HaveOccurred())
Expect(os.Setenv("KUBEBUILDER_ASSETS", string(content))).To(Succeed())
}

By("Bootstrapping test environment")
Expand Down
12 changes: 8 additions & 4 deletions controllers/volsync/volsync_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ package volsync_test

import (
"context"
"fmt"
"os"
"path/filepath"
"runtime"
"testing"

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

By("Setting up KUBEBUILDER_ASSETS for envtest")
if _, set := os.LookupEnv("KUBEBUILDER_ASSETS"); !set {
Expect(os.Setenv("KUBEBUILDER_ASSETS",
fmt.Sprintf("../../testbin/k8s/1.25.0-%s-%s", runtime.GOOS, runtime.GOARCH))).To(Succeed())

// read content of the file ../../testbin/testassets.txt
// and set the content as the value of KUBEBUILDER_ASSETS
// this is to avoid the need to set KUBEBUILDER_ASSETS
// when running the test suite
content, err := os.ReadFile("../../testbin/testassets.txt")
Expect(err).NotTo(HaveOccurred())
Expect(os.Setenv("KUBEBUILDER_ASSETS", string(content))).To(Succeed())
}

By("bootstrapping test environment")
Expand Down
20 changes: 20 additions & 0 deletions hack/install-setup-envtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -e

script_dir="$(cd "$(dirname "$0")" && pwd)"

required_version="latest"
source_url="sigs.k8s.io/controller-runtime/tools/setup-envtest@${required_version}"
target_dir="${script_dir}/../testbin"
target_path="${target_dir}/setup-envtest"
k8s_version="1.29.0"

# The setup-envtest tool has no versioning, so we need to use the latest version.
# The go install command is fast enough that it can be run every time.
mkdir -p "${target_dir}"
GOBIN="${target_dir}" go install "${source_url}"

# Storing the path to the assets in a file so that it can be used by the test files.
# Making the name of the file version agnostic so that changing the version is easier.
kubebuilder_assets=$("${target_path}" use "${k8s_version}" --bin-dir "${target_dir}" --print path)
echo -n "${kubebuilder_assets}" > "${target_dir}/testassets.txt"
Loading