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

vrg: remove the use of captureStartConditionally #1532

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ DEFAULT_CHANNEL := alpha
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

include developer.mk

IMAGE_REGISTRY ?= quay.io
IMAGE_REPOSITORY ?= ramendr
IMAGE_NAME ?= ramen
Expand Down Expand Up @@ -217,6 +219,9 @@ run-dr-cluster: generate manifests ## Run DR manager controller from your host.
docker-build: ## Build docker image with the manager.
$(DOCKERCMD) build -t ${IMG} .

docker-build-x86-64: ## Build docker image with the manager.
$(DOCKERCMD) build -t ${IMG} --platform linux/amd64 .

docker-push: ## Push docker image with the manager.
$(DOCKERCMD) push ${IMG}

Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/drplacementcontrol_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ type DRPlacementControlStatus struct {
// +kubebuilder:printcolumn:JSONPath=".status.progression",name=progression,type=string,priority=2
// +kubebuilder:printcolumn:JSONPath=".status.actionStartTime",name=start time,type=string,priority=2
// +kubebuilder:printcolumn:JSONPath=".status.actionDuration",name=duration,type=string,priority=2
// +kubebuilder:printcolumn:JSONPath=".status.conditions[0].status",name=available,type=string,priority=2
// +kubebuilder:printcolumn:JSONPath=".status.conditions[1].status",name=peer ready,type=string,priority=2
// +kubebuilder:printcolumn:JSONPath=".status.conditions[2].status",name=protected,type=string,priority=2
// +kubebuilder:resource:shortName=drpc

// DRPlacementControl is the Schema for the drplacementcontrols API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@ spec:
name: duration
priority: 2
type: string
- jsonPath: .status.conditions[0].status
name: available
priority: 2
type: string
- jsonPath: .status.conditions[1].status
name: peer ready
priority: 2
type: string
- jsonPath: .status.conditions[2].status
name: protected
priority: 2
type: string
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down
2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
- command:
- /manager
image: controller
imagePullPolicy: IfNotPresent
imagePullPolicy: Always
name: manager
env:
- name: POD_NAMESPACE
Expand Down
7 changes: 7 additions & 0 deletions e2e/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ pvcspecs:
accessmodes: ReadWriteMany
- storageclassname: rook-ceph-block
accessmodes: ReadWriteOnce
Clusters:
c1:
kubeconfigpath: /Users/rtalur/.config/drenv/rdr-rdr/kubeconfigs/rdr-dr1
c2:
kubeconfigpath: /Users/rtalur/.config/drenv/rdr-rdr/kubeconfigs/rdr-dr2
hub:
kubeconfigpath: /Users/rtalur/.config/drenv/rdr-rdr/kubeconfigs/rdr-hub
35 changes: 28 additions & 7 deletions hack/check-drenv-prereqs.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#!/bin/bash
set -e

if ! groups "$USER" | grep -qw libvirt; then
echo "Error: User is not part of the libvirt group."
exit 1
os=$(uname -s)

if [[ "$os" == "Linux" ]]
then
if ! groups "$USER" | grep -qw libvirt; then
echo "Error: User is not part of the libvirt group."
exit 1
fi
fi

commands=("minikube" "kubectl" "clusteradm" "subctl" "velero" "helm" "virtctl"
"virt-host-validate" "kustomize" "mc")
"kustomize" "mc")

linux_only_commands=("virt-host-validate")

for cmd in "${commands[@]}"; do
if ! command -v "$cmd" &> /dev/null; then
Expand All @@ -16,9 +23,23 @@ for cmd in "${commands[@]}"; do
fi
done

if ! virt-host-validate qemu -q; then
echo "Error: 'virt-host-validate qemu' did not return 0."
exit 1

if [[ "$os" == "Linux" ]]
then
for cmd in "${linux_only_commands[@]}"; do
if ! command -v "$cmd" &> /dev/null; then
echo "Error: $cmd could not be found in PATH."
exit 1
fi
done
fi

if [[ "$os" == "Linux" ]]
then
if ! virt-host-validate qemu -q; then
echo "Error: 'virt-host-validate qemu' did not return 0."
exit 1
fi
fi

echo "All prerequisites met for drenv"
4 changes: 2 additions & 2 deletions hack/dev-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ cd "$script_dir"/..
cd test

if [[ $1 == "create" ]]; then
drenv start --name-prefix "${RDR_NAME_PREFIX}"- envs/regional-dr.yaml
drenv start -v --name-prefix "${RDR_NAME_PREFIX}"- envs/regional-dr.yaml
fi

if [[ $1 == "destroy" ]]; then
drenv delete --name-prefix "${RDR_NAME_PREFIX}"- envs/regional-dr.yaml
drenv delete -v --name-prefix "${RDR_NAME_PREFIX}"- envs/regional-dr.yaml
fi
24 changes: 22 additions & 2 deletions internal/controller/ramenconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package controllers_test
import (
"context"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
ramen "github.com/ramendr/ramen/api/v1alpha1"
controllers "github.com/ramendr/ramen/internal/controller"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/yaml"
Expand All @@ -26,10 +26,30 @@ func configMapCreate(ramenConfig *ramen.RamenConfig) {
configMap, err := controllers.ConfigMapNew(ramenNamespace, configMapName, ramenConfig)
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient.Create(context.TODO(), configMap)).To(Succeed())
DeferCleanup(k8sClient.Delete, context.TODO(), configMap)
}
}

func configMapDelete() error {
for _, configMapName := range configMapNames {
cm := &corev1.ConfigMap{}

err := k8sClient.Get(context.TODO(), types.NamespacedName{
Namespace: ramenNamespace,
Name: configMapName,
}, cm)
if err != nil && !errors.IsNotFound(err) {
return err
}

err = k8sClient.Delete(context.TODO(), cm)
if err != nil && !errors.IsNotFound(err) {
return err
}
}

return nil
}

func configMapUpdate() {
ramenConfigYaml, err := yaml.Marshal(ramenConfig)
Expect(err).NotTo(HaveOccurred())
Expand Down
45 changes: 44 additions & 1 deletion internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package controllers_test

import (
"context"
"log"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -89,6 +90,8 @@ var (
objectStorers [2]ramencontrollers.ObjectStorer

ramenNamespace = "ns-envtest"

skipCleanup bool
)

func TestAPIs(t *testing.T) {
Expand Down Expand Up @@ -146,6 +149,11 @@ var _ = BeforeSuite(func() {
ramenNamespace = rNs
}

skipCleanupEnv, set := os.LookupEnv("SKIP_CLEANUP")
if set && (skipCleanupEnv == "true" || skipCleanupEnv == "1") {
skipCleanup = true
}

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{
Expand All @@ -164,10 +172,25 @@ var _ = BeforeSuite(func() {
defer GinkgoRecover()
cfg, err = testEnv.Start()
DeferCleanup(func() error {
if skipCleanup {
By("skipping cleanup of the test environment")

return nil
}
By("tearing down the test environment")

return testEnv.Stop()
})
kubeConfigContent, err := ramencontrollers.ConvertRestConfigToKubeConfig(cfg)
if err != nil {
log.Fatalf("Failed to convert rest.Config to kubeconfig: %v", err)
}

filePath := "../../testbin/kubeconfig.yaml"
if err := ramencontrollers.WriteKubeConfigToFile(kubeConfigContent, filePath); err != nil {
log.Fatalf("Failed to write kubeconfig file: %v", err)
}

close(done)
}()
Eventually(done).WithTimeout(time.Minute).Should(BeClosed())
Expand Down Expand Up @@ -242,6 +265,15 @@ var _ = BeforeSuite(func() {
ramenConfig.DrClusterOperator.S3SecretDistributionEnabled = true
ramenConfig.MultiNamespace.FeatureEnabled = true
configMapCreate(ramenConfig)
DeferCleanup(func() error {
if skipCleanup {
By("skipping cleanup of the test environment")

return nil
}

return configMapDelete()
})

s3Secrets[0] = corev1.Secret{
ObjectMeta: metav1.ObjectMeta{Namespace: ramenNamespace, Name: "s3secret0"},
Expand Down Expand Up @@ -384,7 +416,18 @@ var _ = BeforeSuite(func() {
Expect(err).ToNot(HaveOccurred())

ctx, cancel = context.WithCancel(context.TODO())
DeferCleanup(cancel)
DeferCleanup(func() error {
if skipCleanup {
By("skipping cleanup of the test environment")

return nil
}

cancel()

return nil
})

go func() {
err = k8sManager.Start(ctx)
Expect(err).ToNot(HaveOccurred())
Expand Down
46 changes: 46 additions & 0 deletions internal/controller/testutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package controllers

import (
"os"

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/clientcmd/api"
)

const ownerReadWritePermission = 0o600

// WriteKubeConfigToFile writes the kubeconfig content to a specified file path.
func WriteKubeConfigToFile(kubeConfigContent, filePath string) error {
return os.WriteFile(filePath, []byte(kubeConfigContent), ownerReadWritePermission)
}

// ConvertRestConfigToKubeConfig converts a rest.Config to a kubeconfig string.
func ConvertRestConfigToKubeConfig(restConfig *rest.Config) (string, error) {
kubeConfig := api.NewConfig()

cluster := api.NewCluster()
cluster.Server = restConfig.Host
cluster.CertificateAuthorityData = restConfig.CAData

user := api.NewAuthInfo()
user.ClientCertificateData = restConfig.CertData
user.ClientKeyData = restConfig.KeyData
user.Token = restConfig.BearerToken

context := api.NewContext()
context.Cluster = "cluster"
context.AuthInfo = "user"

kubeConfig.Clusters["cluster"] = cluster
kubeConfig.AuthInfos["user"] = user
kubeConfig.Contexts["test"] = context
kubeConfig.CurrentContext = "test"

kubeConfigContent, err := clientcmd.Write(*kubeConfig)
if err != nil {
return "", err
}

return string(kubeConfigContent), nil
}
28 changes: 27 additions & 1 deletion internal/controller/volsync/volsync_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package volsync_test

import (
"context"
"log"
"os"
"path/filepath"
"testing"
Expand All @@ -19,6 +20,7 @@ import (
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
cfgpolicyv1 "open-cluster-management.io/config-policy-controller/api/v1"
policyv1 "open-cluster-management.io/governance-policy-propagator/api/v1"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -29,6 +31,7 @@ import (
metrics "sigs.k8s.io/controller-runtime/pkg/metrics/server"

volsyncv1alpha1 "github.com/backube/volsync/api/v1alpha1"
controllers "github.com/ramendr/ramen/internal/controller"
"github.com/ramendr/ramen/internal/controller/util"
)

Expand Down Expand Up @@ -56,6 +59,9 @@ var (
volumeSnapshotClassB *snapv1.VolumeSnapshotClass

totalVolumeSnapshotClassCount = 0

skipCleanup bool
cfg *rest.Config
)

func TestVolsync(t *testing.T) {
Expand All @@ -64,6 +70,8 @@ func TestVolsync(t *testing.T) {
}

var _ = BeforeSuite(func() {
var err error

logger = zap.New(zap.UseFlagOptions(&zap.Options{
Development: true,
DestWriter: GinkgoWriter,
Expand All @@ -85,6 +93,11 @@ var _ = BeforeSuite(func() {
Expect(os.Setenv("KUBEBUILDER_ASSETS", string(content))).To(Succeed())
}

skipCleanupEnv, set := os.LookupEnv("SKIP_CLEANUP")
if set && (skipCleanupEnv == "true" || skipCleanupEnv == "1") {
skipCleanup = true
}

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{
Expand All @@ -93,7 +106,7 @@ var _ = BeforeSuite(func() {
},
}

cfg, err := testEnv.Start()
cfg, err = testEnv.Start()
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())

Expand Down Expand Up @@ -217,6 +230,19 @@ var _ = BeforeSuite(func() {
})

var _ = AfterSuite(func() {
if skipCleanup {
kubeConfigContent, err := controllers.ConvertRestConfigToKubeConfig(cfg)
if err != nil {
log.Fatalf("Failed to convert rest.Config to kubeconfig: %v", err)
}

filePath := "../../../testbin/kubeconfig.yaml"
if err := controllers.WriteKubeConfigToFile(kubeConfigContent, filePath); err != nil {
log.Fatalf("Failed to write kubeconfig file: %v", err)
}

return
}
cancel()
By("tearing down the test environment")
err := testEnv.Stop()
Expand Down
Loading
Loading