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

OCPVE-404: chore: adding some local helper scripts and makefile updates #362

Merged
merged 5 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
39 changes: 36 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ IMAGE_REGISTRY ?= quay.io
REGISTRY_NAMESPACE ?= lvms_dev
IMAGE_TAG ?= latest
IMAGE_NAME ?= lvms-operator
IMAGE_REPO ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(IMAGE_NAME)
# IMG defines the image used for the operator.
IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)
IMG ?= $(IMAGE_REPO):$(IMAGE_TAG)

# MUST_GATHER_IMG defines the image used for the must-gather.
MUST_GATHER_IMAGE_NAME ?= lvms-must-gather
Expand Down Expand Up @@ -120,7 +121,8 @@ BUNDLE_PACKAGE ?= lvms-operator

# BUNDLE_IMG defines the image used for the bundle.
BUNDLE_IMAGE_NAME ?= $(IMAGE_NAME)-bundle
BUNDLE_IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(BUNDLE_IMAGE_NAME):$(IMAGE_TAG)
BUNDLE_REPO ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(BUNDLE_IMAGE_NAME)
BUNDLE_IMG ?= $(BUNDLE_REPO):$(IMAGE_TAG)

# Each CSV has a replaces parameter that indicates which Operator it replaces.
# This builds a graph of CSVs that can be queried by OLM, and updates can be
Expand Down Expand Up @@ -258,7 +260,8 @@ BUNDLE_IMGS ?= $(BUNDLE_IMG)

# CATALOG_IMG defines the image used for the catalog.
CATALOG_IMAGE_NAME ?= $(IMAGE_NAME)-catalog
CATALOG_IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(CATALOG_IMAGE_NAME):$(IMAGE_TAG)
CATALOG_REPO ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(CATALOG_IMAGE_NAME)
CATALOG_IMG ?= $(CATALOG_REPO):$(IMAGE_TAG)

# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
ifneq ($(origin CATALOG_BASE_IMG), undefined)
Expand Down Expand Up @@ -346,3 +349,33 @@ operator-sdk: ## Download operator-sdk locally.
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/operator-sdk_$${OS}_$${ARCH};\
chmod +x $(OPERATOR_SDK) ;\

.PHONY: git-sanitize
git-sanitize:
hack/git-sanitize.sh

.PHONY: git-unsanitize
git-unsanitize:
CLEANUP="true" hack/git-sanitize.sh

.PHONY: release-local-operator
release-local-operator:
IMAGE_REPO=$(IMAGE_REPO) hack/release-local.sh

.PHONY: release-local-bundle
release-local-bundle:
IMAGE_REPO=$(IMAGE_REPO) \
BUNDLE_REPO=$(BUNDLE_REPO) hack/release-local.sh

.PHONY: release-local-catalog
release-local-catalog: opm
IMAGE_REPO=$(IMAGE_REPO) \
BUNDLE_REPO=$(BUNDLE_REPO) \
CATALOG_REPO=$(CATALOG_REPO) \
OPM=$(OPM) hack/release-local.sh

.PHONY: local-e2e
local-e2e:
hack/local-e2e.sh

# IMAGE_TAG=6f2d1d78d29d34b6732e24ef464fddb78102a065 lvmt make e2e-test
jeff-roche marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,29 @@ To perform a full cleanup, follow these steps:
make undeploy
```

## E2E Tests

There are a few steps require to run the end-to-end tests for LVMS.

You will need the following evironment variables set:
```bash
IMAGE_REGISTRY={{REGISTRY_URL}} # Ex: quay.io
REGISTRY_NAMESPACE={{REGISTRY_NAMESPACE}} # Ex: lvms-dev
```

Once the environment variables are set, you can run
```bash
$ make local-e2e
```

That command will:
- Do any repo sanitization needed (in case changes are made)
- Build the Operator and tag it with the git hash
- Build the Operator Bundle and tag it with the git hash
- Build the Operator Catalog adn tag it with the git hash
- Run the e2e tests against the built images
- Undo any sanitization that was needed for the repo

## Metrics

The LVM Operator runs a metrics exporter sidecar to export Prometheus metrics. To enable monitoring on OpenShift clusters, assign the `openshift.io/cluster-monitoring` label to the same namespace that you deployed LVMS to.
Expand Down
25 changes: 25 additions & 0 deletions hack/git-sanitize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -euo pipefail

TEMP_COMMIT_MSG="discard: Temporary"

CLEANUP="${CLEANUP:-}"
if [ -z "${CLEANUP}" ]; then
# Do a temp commit if the working dir is dirty
TEMP_COMMIT="false"
test -z "$(git status --porcelain)" || TEMP_COMMIT="true"

if [[ "${TEMP_COMMIT}" == "true" ]]; then
echo "Creating temp commit"
git add .
git commit -m "${TEMP_COMMIT_MSG}" || true
fi
else
# Cleanup a temp commit if one was needed
PREV_MSG=$(git log -1 --pretty=%B)

if [[ $PREV_MSG == *"${TEMP_COMMIT_MSG}"* ]]; then
echo "Cleaning up temp commit"
git reset --soft HEAD~1
fi
fi
17 changes: 17 additions & 0 deletions hack/local-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -euo pipefail

# Sanitize the local repo (there are probably changes if this is being run locally)
make git-sanitize

# Make sure the operater, bundle, and catalog are fresh
make release-local-catalog

# Run the tests
GITREV=$(git rev-parse HEAD)

export IMAGE_TAG="${GITREV}"
make e2e-test

# Cleanup any sanitization work
make git-unsanitize
47 changes: 47 additions & 0 deletions hack/release-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -euo pipefail

# Do a temp commit if the working dir is dirty
DIRTY_REPO="false"
test -z "$(git status --porcelain)" || DIRTY_REPO="true"
if [[ "${DIRTY_REPO}" == "true" ]]; then
echo "Dirty repository detected. Please run 'make git-sanitize' or commit your changes before running this command"
exit 1
fi

GITREV=$(git rev-parse HEAD)
BUILDER=$(command -v docker 2>&1 >/dev/null && echo docker || echo podman)

# Run the generate and bundle commands
export IMAGE_TAG="${GITREV}"
make generate bundle

# If IMAGE_REPO is defined, build the operator image
IMAGE_REPO="${IMAGE_REPO:-}"
if [ -n "$IMAGE_REPO" ]; then
${BUILDER} build -t ${IMAGE_REPO}:${GITREV} .
${BUILDER} push ${IMAGE_REPO}:${GITREV}
fi

# If BUNDLE_REPO is defined, build the bundle
BUNDLE_REPO="${BUNDLE_REPO:-}"
if [ -n "$BUNDLE_REPO" ]; then
BUNDLE_IMG=${BUNDLE_REPO}:${GITREV}
${BUILDER} build -f bundle.Dockerfile -t ${BUNDLE_IMG} .
${BUILDER} push ${BUNDLE_REPO}:${GITREV}

# If CATALOG_REPO is defined, build the catalog
CATALOG_REPO="${CATALOG_REPO:-}"
if [ -n "$CATALOG_REPO" ]; then
OPM="${OPM:-}"
if [ -z "$OPM" ]; then echo "ERROR: OPM is a required variable"; exit 1; fi
${OPM} index add --container-tool ${BUILDER} --mode semver --tag ${CATALOG_REPO}:${GITREV} --bundles ${BUNDLE_IMG}
${BUILDER} push ${CATALOG_REPO}:${GITREV}
fi
fi

echo
echo "Built and Pushed:"
if [ -n "$IMAGE_REPO" ]; then echo "${IMAGE_REPO}:${GITREV}"; fi
if [ -n "$BUNDLE_REPO" ]; then echo "${BUNDLE_REPO}:${GITREV}"; fi
if [ -n "$CATALOG_REPO" ]; then echo "${CATALOG_REPO}:${GITREV}"; fi
33 changes: 21 additions & 12 deletions test/e2e/lvmcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ func lvmClusterTest() {
// Make sure the storage class was configured properly
sc := storagev1.StorageClass{}

var err error
Eventually(func() bool {
err := crClient.Get(ctx, types.NamespacedName{Name: storageClassName, Namespace: installNamespace}, &sc)
if err != nil {
debug("Error getting StorageClass %s: %s\n", storageClassName, err.Error())
}
err = crClient.Get(ctx, types.NamespacedName{Name: storageClassName, Namespace: installNamespace}, &sc)

return err == nil
}, timeout, interval).Should(BeTrue())

if err != nil {
Fail(fmt.Sprintf("Error getting StorageClass %s: %s\n", storageClassName, err.Error()))
}

Expect(sc.Parameters["csi.storage.k8s.io/fstype"]).To(Equal(string(v1alpha1.FilesystemTypeXFS)))
})

Expand All @@ -163,14 +166,17 @@ func lvmClusterTest() {
// Make sure the storage class was configured properly
sc := storagev1.StorageClass{}

var err error
Eventually(func() bool {
err := crClient.Get(ctx, types.NamespacedName{Name: storageClassName, Namespace: installNamespace}, &sc)
if err != nil {
debug("Error getting StorageClass %s: %s\n", storageClassName, err.Error())
}
err = crClient.Get(ctx, types.NamespacedName{Name: storageClassName, Namespace: installNamespace}, &sc)

return err == nil
}, timeout, interval).Should(BeTrue())

if err != nil {
Fail(fmt.Sprintf("Error getting StorageClass %s: %s\n", storageClassName, err.Error()))
}

Expect(sc.Parameters["csi.storage.k8s.io/fstype"]).To(Equal(string(v1alpha1.FilesystemTypeXFS)))
})

Expand All @@ -184,14 +190,17 @@ func lvmClusterTest() {
// Make sure the storage class was configured properly
sc := storagev1.StorageClass{}

var err error
Eventually(func() bool {
err := crClient.Get(ctx, types.NamespacedName{Name: storageClassName, Namespace: installNamespace}, &sc)
if err != nil {
debug("Error getting StorageClass %s: %s\n", storageClassName, err.Error())
}
err = crClient.Get(ctx, types.NamespacedName{Name: storageClassName, Namespace: installNamespace}, &sc)

return err == nil
}, timeout, interval).Should(BeTrue())

if err != nil {
Fail(fmt.Sprintf("Error getting StorageClass %s: %s\n", storageClassName, err.Error()))
}

Expect(sc.Parameters["csi.storage.k8s.io/fstype"]).To(Equal(string(v1alpha1.FilesystemTypeExt4)))
})
})
Expand Down