Skip to content

Commit

Permalink
fix: refactor E2E tests to be context-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmoellerdev committed Aug 9, 2023
1 parent 6f10571 commit b9a4145
Show file tree
Hide file tree
Showing 21 changed files with 785 additions and 676 deletions.
34 changes: 0 additions & 34 deletions HACKING.md

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ jsonnet: ## Download jsonnet locally if necessary.

GINKGO = $(shell pwd)/bin/ginkgo
ginkgo: ## Download ginkgo and gomega locally if necessary.
$(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/[email protected].4)
$(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/[email protected].5)

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
Expand Down
3 changes: 2 additions & 1 deletion controllers/lvmcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func (r *LVMClusterReconciler) reconcile(ctx context.Context, instance *lvmv1alp
}
}
if err != nil {
return ctrl.Result{Requeue: true, RequeueAfter: time.Minute * 1}, err
// check every 10 seconds if there are still PVCs present or the LogicalVolumes are removed
return ctrl.Result{Requeue: true, RequeueAfter: time.Second * 10}, err
} else {
return reconcile.Result{}, nil
}
Expand Down
15 changes: 12 additions & 3 deletions controllers/topolvm_snapshotclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ package controllers

import (
"context"
"errors"
"fmt"

snapapi "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
lvmv1alpha1 "github.com/openshift/lvm-operator/api/v1alpha1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/discovery"
cutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

Expand Down Expand Up @@ -72,10 +75,16 @@ func (s topolvmVolumeSnapshotClass) ensureDeleted(r *LVMClusterReconciler, ctx c

if err != nil {
// already deleted in previous reconcile
if errors.IsNotFound(err) {
if k8serrors.IsNotFound(err) {
r.Log.Info("topolvm volume snapshot class is deleted", "VolumeSnapshotClass", vscName)
return nil
}
if runtime.IsNotRegisteredError(err) || meta.IsNoMatchError(err) ||
// this is necessary in case the VolumeSnapshotClass CRDs are not registered in the Distro, e.g. for OpenShift Local
discovery.IsGroupDiscoveryFailedError(err) || discovery.IsGroupDiscoveryFailedError(errors.Unwrap(err)) {
r.Log.Info("topolvm volume snapshot classes do not exist on the cluster, ignoring", "VolumeSnapshotClass", vscName)
return nil
}
r.Log.Error(err, "failed to retrieve topolvm volume snapshot class", "VolumeSnapshotClass", vscName)
return err
}
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
3. [The Volume Group Manager](design/vg-manager.md)
4. [Thin Provisioning](design/thin-provisioning.md)
5. [Troubleshooting Guide](troubleshooting.md)
6. [Hacking / Local Testing](debugging/hacking.md)
60 changes: 60 additions & 0 deletions docs/debugging/hacking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Logical Volume Manager Storage Operator Hacking

## Cluster builds
In order to build on the cluster you need to first have your kubeconfig configured. Once configured you can run the following steps to build on the cluster:

### Configure the build

```bash
$ make create-buildconfig
```

This will build from `https://github.com/openshift/lvm-operator` on branch `main` by default. This can be overridden by specifying the `GIT_URL` and `GIT_BRANCH` environment variables.
```bash
$ GIT_URL=https://github.com/my-user/lvm-operator.git \
GIT_BRANCH=my-feature-branch \
make create-buildconfig
```

### Run the build
Kickoff the build on the cluster. All output will be followed for the build.
```bash
$ make cluster-build
```

### Deploy the operator
To deploy the built operator run the following command:
```bash
$ make cluster-deploy
```

To undeploy the operator you can run
```bash
$ make undeploy
```


## Local E2E Testing

1. Download OpenShift Local from https://developers.redhat.com/products/openshift-local/overview
2. `crc setup` (once per machine)
3. `crc start`
4. ```shell
credentials=$(crc console --credentials -o json)
oc login -u $(echo $credentials | jq -r ".clusterConfig.adminCredentials.username") \
-p $(echo $credentials | jq -r ".clusterConfig.adminCredentials.password") \
$(echo $credentials | jq -r ".clusterConfig.url")
```
5. `oc config view --raw >> /tmp/crc-kubeconfig`
6. `export KUBECONFIG="/tmp/crc-kubeconfig"`
7. `make deploy`
8. `make e2e`

### Enable Snapshot Testing

Prerequisites: Ensure you have a running CRC Cluster (Step 6)

1. Make sure controller is undeployed with `make undeploy`
2. `oc apply -k https://github.com/kubernetes-csi/external-snapshotter//client/config/crd`
3. `oc apply -k https://github.com/kubernetes-csi/external-snapshotter//deploy/kubernetes/snapshot-controller`
4. Start again at Step 7
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
github.com/aws/aws-sdk-go v1.44.10
github.com/go-logr/logr v1.2.4
github.com/go-logr/zapr v1.2.4
github.com/google/go-cmp v0.5.9
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
github.com/onsi/ginkgo/v2 v2.9.5
Expand All @@ -18,6 +19,7 @@ require (
github.com/prometheus/client_golang v1.16.0
github.com/stretchr/testify v1.8.4
github.com/topolvm/topolvm v0.15.4-0.20221116041433-d58476400ff1
go.uber.org/zap v1.24.0
gotest.tools/v3 v3.0.3
k8s.io/api v0.27.4
k8s.io/apimachinery v0.27.4
Expand All @@ -41,7 +43,6 @@ require (
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
Expand Down Expand Up @@ -82,7 +83,6 @@ require (
github.com/subosito/gotenv v1.2.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.10.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func getKubeconfig(kubeconfig string) (*rest.Config, error) {
config, err = rest.InClusterConfig()
}
if err != nil {
return config, nil
return nil, err
}
return config, err
}
Loading

0 comments on commit b9a4145

Please sign in to comment.