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 14, 2023
1 parent 6f10571 commit b831233
Show file tree
Hide file tree
Showing 20 changed files with 788 additions and 711 deletions.
60 changes: 59 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,65 @@ Developers must follow these steps to make a change:
review process (effectively repeating steps 3-7 as needed).

## Developer Environment Installation
TODO

### 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

## Commits Per Pull Request

Expand Down
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
16 changes: 14 additions & 2 deletions controllers/topolvm_snapshotclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ 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"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/discovery"
cutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

Expand Down Expand Up @@ -52,6 +54,11 @@ func (s topolvmVolumeSnapshotClass) ensureCreated(r *LVMClusterReconciler, ctx c
// we anticipate no edits to volume snapshot class
result, err := cutil.CreateOrUpdate(ctx, r.Client, vsc, func() error { return nil })
if err != nil {
// this is necessary in case the VolumeSnapshotClass CRDs are not registered in the Distro, e.g. for OpenShift Local
if 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, "topolvm volume snapshot class reconcile failure", "name", vsc.Name)
return err
} else {
Expand All @@ -72,10 +79,15 @@ 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
}
// this is necessary in case the VolumeSnapshotClass CRDs are not registered in the Distro, e.g. for OpenShift Local
if 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
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 b831233

Please sign in to comment.