Skip to content

Commit 655ce20

Browse files
authored
Merge pull request #13 from stakater/e2e
e2e tests. need to configure env in pipelines in order to run e2e
2 parents 05dbb30 + 8b496f6 commit 655ce20

15 files changed

+677
-132
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ go.work
2121

2222
# editor and IDE paraphernalia
2323
.idea
24-
.vscode
2524
*.swp
2625
*.swo
2726
*~

.golangci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ issues:
1616
linters:
1717
- dupl
1818
- lll
19+
- path: "test/*"
20+
linters:
21+
- dupl
22+
- lll
1923
linters:
2024
disable-all: true
2125
enable:
@@ -37,4 +41,4 @@ linters:
3741
- typecheck
3842
- unconvert
3943
- unparam
40-
- unused
44+
- unused

.vscode/launch.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Debug Go Tests",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "test",
12+
"program": "${fileDirname}", // Specifies that tests in the current directory's package should be run
13+
"args": ["-test.v", "--ginkgo.vv", "--ginkgo.focus", "${selectedText}"], // Verbose test output
14+
"preLaunchTask": "", // This should match the label of your pre-test task
15+
"env": {
16+
"GOFLAGS": "-count=1", // Avoid test caching
17+
},
18+
},
19+
{
20+
"name": "Debug E2E Tests",
21+
"type": "go",
22+
"request": "launch",
23+
"mode": "test",
24+
"program": "${fileDirname}", // Specifies that tests in the current directory's package should be run
25+
"args": ["-test.v", "--ginkgo.vv", "--ginkgo.focus", "${selectedText}"], // Verbose test output
26+
"preLaunchTask": "", // This should match the label of your pre-test task
27+
"env": {
28+
"GOFLAGS": "-count=1", // Avoid test caching
29+
"HOSTED_CLUSTER_NAME": "c7ked5y6v",
30+
"HOSTED_CLUSTER_NAMESPACE": "hypershift-c7ked5y6v",
31+
"SPOKE_ROUTE_NAMESPACE": "openshift-monitoring",
32+
"HUB_NAMESPACE": "c7ked5y6v",
33+
"ROUTE_NAME": "e2e-example-route",
34+
"ROUTE_LABELS": "app=example,env=prod",
35+
"PROBE_JOB_NAME": "e2e-uptime-probe-job",
36+
"PROBE_INTERVAL": "30s",
37+
"PROBE_TIMEOUT": "10s",
38+
"PROBE_MODULE": "http_2xx",
39+
"PROBER_URL": "e2e-blackbox-exporter.openshift-monitoring.svc.cluster.local:9115",
40+
"PROBER_SCHEME": "http",
41+
"PROBER_PATH": "/probe"
42+
},
43+
},
44+
]
45+
}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# To re-generate a bundle for another specific version without changing the standard setup, you can:
44
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
55
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6-
VERSION ?= 0.0.1
6+
VERSION ?= 0.0.2
77
OPERATOR_NAME ?= uptimeguardian
88
CATALOG_DIR_PATH ?= catalog
99
DOCKER_REPO_BASE ?= ghcr.io/stakater
@@ -115,7 +115,7 @@ vet: ## Run go vet against code.
115115

116116
.PHONY: test
117117
test: manifests generate fmt vet envtest ## Run tests.
118-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
118+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -v -ginkgo.v -coverprofile cover.out
119119

120120
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
121121
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.

README.md

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
1-
# uptimeguardian
2-
// TODO(user): Add simple overview of use/purpose
1+
# Uptime Guardian Operator
2+
UptimeGuardian is an OpenShift operator which runs in the Hub cluster and watches `Routes` in the Spoke clusters and creates corresponding Prometheus `Probes` in the Hub cluster.
33

44
## Description
5-
// TODO(user): An in-depth paragraph about your project and overview of use
5+
UptimeGuardian is designed to operate in a hub-spoke architecture, where it is installed on the hub (mothershift) cluster. The operator performs the following key functions:
6+
7+
1. Watches `HostedCluster` Custom Resources (CRs) in the hub cluster to discover and maintain connections with spoke (childshift) clusters
8+
2. Establishes secure connections to the spoke clusters using the credentials and configuration from the `HostedCluster` CRs
9+
3. Monitors `Routes` in the spoke clusters based on configured label selectors
10+
4. Creates and manages corresponding Prometheus `Probe` resources in the hub cluster
11+
12+
To use UptimeGuardian, you need to:
13+
1. Install the operator in your hub cluster
14+
2. Create an `UptimeProbe` CR in the hub cluster with configuration including:
15+
- Label selectors to identify which Routes to monitor in the spoke clusters
16+
- Target namespace where the Prometheus Probes will be created in the hub cluster
17+
- Any additional monitoring configuration like intervals, timeouts, etc.
18+
19+
The operator automatically handles the synchronization between spoke cluster Routes and hub cluster Probes, ensuring your routes are continuously monitored for availability.
620

721
## Getting Started
822

923
### Prerequisites
10-
- go version v1.21.0+
11-
- docker version 17.03+.
12-
- kubectl version v1.11.3+.
13-
- Access to a Kubernetes v1.11.3+ cluster.
24+
- go version v1.23.0+
25+
- docker version 20.10+.
26+
- kubectl version v1.23.0+.
27+
- Access to a OpenShift cluster v4.14+
1428

1529
### To Deploy on the cluster
1630
**Build and push your image to the location specified by `IMG`:**
1731

1832
```sh
19-
make docker-build docker-push IMG=<some-registry>/uptimeguardian:tag
33+
make docker-build docker-push IMG=ghcr.io/stakater/uptimeguardian:tag
2034
```
2135

22-
**NOTE:** This image ought to be published in the personal registry you specified.
23-
And it is required to have access to pull the image from the working environment.
24-
Make sure you have the proper permission to the registry if the above commands don’t work.
25-
2636
**Install the CRDs into the cluster:**
2737

2838
```sh
@@ -32,7 +42,7 @@ make install
3242
**Deploy the Manager to the cluster with the image specified by `IMG`:**
3343

3444
```sh
35-
make deploy IMG=<some-registry>/uptimeguardian:tag
45+
make deploy IMG=ghcr.io/stakater/uptimeguardian:tag
3646
```
3747

3848
> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin
@@ -66,31 +76,40 @@ make uninstall
6676
make undeploy
6777
```
6878

69-
## Project Distribution
79+
### Development
7080

71-
Following are the steps to build the installer and distribute this project to users.
81+
**Running the operator locally:**
7282

73-
1. Build the installer for the image built and published in the registry:
83+
Ensure you are connected to the Hub cluster and your kubeconfig is set to use the Hub cluster context.
84+
Install the CRDs as mentioned in the [To Deploy on the cluster](#to-deploy-on-the-cluster) section and run the operator locally.
7485

7586
```sh
76-
make build-installer IMG=<some-registry>/uptimeguardian:tag
87+
make run
7788
```
7889

79-
NOTE: The makefile target mentioned above generates an 'install.yaml'
80-
file in the dist directory. This file contains all the resources built
81-
with Kustomize, which are necessary to install this project without
82-
its dependencies.
90+
**Running E2E Tests:**
91+
Use the provided VSCode launch configuration to execute the end-to-end tests. The launch file contains the necessary configuration for running tests in your development environment. `Debug E2E Tests` is the launch configuration for running the end-to-end tests. It have environment variables which can be used to configure the test. To run the test in VSCode, you need to select the test name and then click on the `Debug E2E Tests` launch configuration.
8392

84-
2. Using the installer
93+
If you want to run the test outside of VSCode, you can run the following command (make sure you have all the environment variables set mentioned in the launch configuration `launch.json`):
8594

86-
Users can just run kubectl apply -f <URL for YAML BUNDLE> to install the project, i.e.:
95+
```sh
96+
make test-e2e
97+
```
98+
99+
**Running Unit Tests:**
100+
Apart from using the VSCode launch configuration (by selecting the any unit test name as regex and then clicking on the `Debug Unit Tests` launch configuration), you can also run the unit tests using the following command:
87101

88102
```sh
89-
kubectl apply -f https://raw.githubusercontent.com/<org>/uptimeguardian/<tag or branch>/dist/install.yaml
103+
make test
90104
```
91105

92-
## Contributing
93-
// TODO(user): Add detailed information on how you would like others to contribute to this project
106+
## Contributing to UptimeGuardian!
107+
108+
Before submitting a pull request:
109+
1. Ensure all tests pass locally
110+
2. Add tests / e2e tests for any new features
111+
3. Update documentation as needed
112+
4. Follow the existing code style and conventions
94113

95114
**NOTE:** Run `make help` for more information on all potential `make` targets
96115

catalog.Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
# /bin/opm (with a serve subcommand) and /bin/grpc_health_probe
33
FROM quay.io/operator-framework/opm:v1.50.0
44

5-
# Configure the entrypoint and command
6-
ENTRYPOINT ["/bin/opm"]
5+
# Configure the command
76
CMD ["serve", "/configs", "--cache-dir=/tmp/cache"]
87

98
# Copy declarative config root into image at /configs and pre-populate serve cache

catalog/channels.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ package: uptimeguardian
33
name: preview
44
entries:
55
- name: uptimeguardian.v0.0.1
6+
- name: uptimeguardian.v0.0.2
7+
skips:
8+
- uptimeguardian.v0.0.1

config/rbac/role.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ rules:
2020
- get
2121
- list
2222
- watch
23+
- apiGroups:
24+
- monitoring.coreos.com
25+
resources:
26+
- probes
27+
verbs:
28+
- create
29+
- delete
30+
- get
31+
- list
32+
- patch
33+
- update
34+
- watch
2335
- apiGroups:
2436
- networking.stakater.com
2537
resources:

config/samples/networking_v1alpha1_uptimeprobe.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,15 @@ metadata:
66
app.kubernetes.io/managed-by: kustomize
77
name: uptimeprobe-sample
88
spec:
9-
# TODO(user): Add fields here
9+
labelSelector:
10+
matchLabels:
11+
app.kubernetes.io/name: thanos-query
12+
probeConfig:
13+
module: http_2xx
14+
jobName: default-uptime-probe-job
15+
interval: 30s
16+
scrapeTimeout: 10s
17+
proberUrl: blackbox-exporter.openshift-monitoring.svc.cluster.local:9115
18+
proberScheme: http
19+
proberPath: /probe
20+
targetNamespace: test-1

generate-catalog-index.sh

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@ echo " catalog build start"
1717
SHOULD_RELEASE="false"
1818
for item in $CHANNEL_BUNDLES; do
1919
# Setup bundle from entries
20-
if [ -n "$GIT_TAG" ]; then
20+
latest="${OPERATOR_NAME}.v${VERSION}"
21+
if [ -n "$GIT_TAG" ] && [ "$latest" == "$item" ]; then
2122
bundle="${item//${OPERATOR_NAME}./${OPERATOR_NAME}-bundle:}${GIT_TAG}"
22-
release="${OPERATOR_NAME}-bundle:v${VERSION}${GIT_TAG}"
2323
else
2424
bundle="${item//${OPERATOR_NAME}./${OPERATOR_NAME}-bundle:}"
25-
release="${OPERATOR_NAME}-bundle:v${VERSION}"
2625
fi
2726

2827
# Check if next release is defined in any channel
29-
if [ "${bundle}" == "${release}" ]; then
28+
if [ "$latest" == "$item" ]; then
3029
SHOULD_RELEASE="true"
31-
else
32-
SHOULD_RELEASE="false"
3330
fi
3431

3532
opm render "$DOCKER_REPO/$bundle" --output=yaml >> "$CATALOG_DIR_PATH"/bundles.yaml
@@ -45,8 +42,5 @@ done
4542
echo " >> release is not defined in ${CATALOG_DIR_PATH}/channels.yaml, will not create catalog index"
4643
fi
4744

48-
rm -rf "$CATALOG_DIR_PATH"/bundles.yaml
45+
#rm -rf "$CATALOG_DIR_PATH"/bundles.yaml
4946
echo " catalog build done!"
50-
51-
## Delete entries
52-
#yq eval 'del(select(.schema == "olm.bundle"))' -i catalog/index.yaml

0 commit comments

Comments
 (0)