Skip to content

Commit 36ea086

Browse files
committed
Add rule group e2e test
1 parent 562510b commit 36ea086

File tree

154 files changed

+368
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+368
-40
lines changed

.github/workflows/e2e-tests.yaml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,29 @@ jobs:
1616
tests:
1717
name: Tests
1818
runs-on: ubuntu-latest
19+
env:
20+
IMG: tests.com/coralogix-operator:v0.0.1
21+
CORALOGIX_REGION: ${{ secrets.CORALOGIX_REGION }}
22+
CORALOGIX_API_KEY: ${{ secrets.CORALOGIX_API_KEY }}
1923
steps:
2024
- name: Checkout
2125
uses: actions/checkout@v2
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v2
28+
- name: Build the controller-manager Docker image
29+
run: |
30+
make docker-build
2231
- name: Create k8s Kind Cluster
2332
uses: helm/kind-action@v1.4.0
24-
- name: Install kuttl
33+
- name: Load the controller-manager image into Kind
2534
run: |
26-
curl -Lo /usr/local/bin/kubectl-kuttl https://github.com/kudobuilder/kuttl/releases/download/v0.12.1/kubectl-kuttl_0.12.1_linux_x86_64
27-
chmod +x /usr/local/bin/kubectl-kuttl
35+
kind load docker-image ${{ env.IMG }} --name chart-testing
2836
- name: Install CRDs
2937
run: make install
30-
- name: Install Go
31-
uses: actions/setup-go@37335c7bb261b353407cff977110895fa0b4f7d8
32-
with:
33-
go-version: 1.22.x
34-
- name: Running operator and Tests
38+
- name: Deploy the controller-manager
39+
run: |
40+
make deploy
41+
- name: Run e2e Tests
3542
env:
36-
CORALOGIX_REGION: ${{ secrets.CORALOGIX_REGION }}
37-
CORALOGIX_API_KEY: ${{ secrets.CORALOGIX_API_KEY }}
3843
run: |
39-
go run -ldflags="-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn" main.go &
40-
sleep 30s
41-
make e2e
44+
make e2e-tests
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: integration-tests
2+
on:
3+
schedule:
4+
- cron: 0 0 * * *
5+
push:
6+
branches:
7+
- main
8+
paths-ignore:
9+
- "charts/**"
10+
pull_request:
11+
branches:
12+
- main
13+
paths-ignore:
14+
- "charts/**"
15+
jobs:
16+
tests:
17+
name: Tests
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
- name: Create k8s Kind Cluster
23+
uses: helm/kind-action@v1.4.0
24+
- name: Install kuttl
25+
run: |
26+
curl -Lo /usr/local/bin/kubectl-kuttl https://github.com/kudobuilder/kuttl/releases/download/v0.12.1/kubectl-kuttl_0.12.1_linux_x86_64
27+
chmod +x /usr/local/bin/kubectl-kuttl
28+
- name: Install CRDs
29+
run: make install
30+
- name: Install Go
31+
uses: actions/setup-go@37335c7bb261b353407cff977110895fa0b4f7d8
32+
with:
33+
go-version: 1.22.x
34+
- name: Running operator and Tests
35+
env:
36+
CORALOGIX_REGION: ${{ secrets.CORALOGIX_REGION }}
37+
CORALOGIX_API_KEY: ${{ secrets.CORALOGIX_API_KEY }}
38+
run: |
39+
go run -ldflags="-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn" main.go &
40+
sleep 30s
41+
make integration-tests

.github/workflows/unit-tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: unit
1+
name: unit-tests
22
on:
33
pull_request:
44
paths-ignore:
@@ -21,7 +21,7 @@ jobs:
2121
uses: helm/kind-action@v1.4.0
2222
- name: Install CRDs
2323
run: make install
24-
- run: make test
24+
- run: make unit-tests
2525
- name: Patch Coverage
2626
uses: seriousben/go-patch-cover-action@v1
2727
with:

CONTRIBUTING.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,27 @@ When creating or updating CRDs remember to run
9090
make manifests
9191
````
9292
93-
Tests
93+
Running E2E Tests
9494
---------------------
95-
We use [kuttl](https://kuttl.dev/) for end-to-end tests.
96-
The test files are located at [./tests/e2e/](./tests/e2e)
97-
In order to run the full suite of `kuttl` tests, run -
95+
The test files are located at [./tests/e2e/](./tests/e2e).
96+
In order to run the full e2e tests suite:
97+
1. Add the api key and region as environment variables:
9898
```sh
99-
$ make e2e
99+
$ export CORALOGIX_API_KEY="<api-key>"
100+
$ export CORALOGIX_REGION="<region>"
101+
```
102+
2. Run the tests:
103+
```sh
104+
$ make e2e-tests
105+
````
106+
107+
Running Integration Tests
108+
---------------------
109+
We use [kuttl](https://kuttl.dev/) for integration tests.
110+
The test files are located at [./tests/integration/](./tests/integration).
111+
In order to run the full integration tests suite, run:
112+
```sh
113+
$ make integration-tests
100114
````
101115
102116
*Note:* `kuttl` tests create real resources and in a case of failure some resources may not be removed.

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ fmt: ## Run go fmt against code.
5555
vet: ## Run go vet against code.
5656
go vet ./...
5757

58-
.PHONY: test
59-
test: manifests generate fmt vet envtest ## Run tests.
60-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -ldflags $(LDFLAGS) -coverprofile cover.out
58+
.PHONY: unit-tests
59+
unit-tests: manifests generate fmt vet envtest ## Run tests.
60+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./controllers/ -ldflags $(LDFLAGS) -coverprofile cover.out
6161

6262
##@ Documentation
6363
.PHONY: generate-api-docs
@@ -122,7 +122,7 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
122122
.PHONY: deploy
123123
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
124124
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
125-
$(KUSTOMIZE) build config/default | kubectl apply -f -
125+
$(KUSTOMIZE) build config/default | envsubst |kubectl apply -f -
126126

127127
.PHONY: undeploy
128128
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
@@ -166,9 +166,14 @@ crdoc: $(CRDOC) ## Download crdoc locally if necessary.
166166
$(CRDOC): $(LOCALBIN)
167167
test -s $(LOCALBIN)/crdoc || GOBIN=$(LOCALBIN) go install fybrik.io/crdoc@latest
168168

169-
e2e:
169+
.PHONY: integration-tests
170+
integration-tests:
170171
kubectl kuttl test
171172

173+
.PHONY: e2e-tests
174+
e2e-tests:
175+
go test ./tests/e2e/ -ldflags $(LDFLAGS) -v -ginkgo.v
176+
172177
.PHONY: helm-check-crd-version
173178
helm-check-crd-version:
174179
sh scripts/helm-check-crd-version.sh

config/default/manager_auth_proxy_patch.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,3 @@ spec:
4848
requests:
4949
cpu: 5m
5050
memory: 64Mi
51-
- name: manager
52-
args:
53-
- "--health-probe-bind-address=:8081"
54-
- "--metrics-bind-address=127.0.0.1:8080"
55-
- "--leader-elect"
56-
- "--api-key=xxx"
57-
- "--region=EU2"

config/manager/manager.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ metadata:
1818
namespace: system
1919
labels:
2020
control-plane: controller-manager
21-
app.kubernetes.io/name: deployment
21+
app.kubernetes.io/name: coralogix-operator-controller-manager
2222
app.kubernetes.io/instance: controller-manager
2323
app.kubernetes.io/component: manager
2424
app.kubernetes.io/created-by: coralogix-operator
@@ -70,6 +70,10 @@ spec:
7070
- /manager
7171
args:
7272
- --leader-elect
73+
- --health-probe-bind-address=:8081
74+
- --metrics-bind-address=127.0.0.1:8080
75+
- --api-key=${CORALOGIX_API_KEY}
76+
- --region=${CORALOGIX_REGION}
7377
image: controller:latest
7478
name: manager
7579
securityContext:

kuttl-test.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apiVersion: kuttl.dev/v1beta1
22
kind: TestSuite
33
testDirs:
4-
- tests/e2e/alerts
5-
- tests/e2e/rulegroups
6-
- tests/e2e/recordingrulegroupsets
7-
- tests/e2e/prometheusrules
8-
- tests/e2e/outboundwebhooks
9-
- tests/e2e/alertmangerconfigs
4+
- tests/integration/alerts
5+
- tests/integration/rulegroups
6+
- tests/integration/recordingrulegroupsets
7+
- tests/integration/prometheusrules
8+
- tests/integration/outboundwebhooks
9+
- tests/integration/alertmangerconfigs
1010
namespace: default
11-
timeout: 60
11+
timeout: 60

tests/e2e/client.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
prometheus "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
21+
"k8s.io/client-go/kubernetes"
22+
"sigs.k8s.io/controller-runtime/pkg/client"
23+
"sigs.k8s.io/controller-runtime/pkg/client/config"
24+
25+
cxsdk "github.com/coralogix/coralogix-management-sdk/go"
26+
27+
coralogixv1alpha1 "github.com/coralogix/coralogix-operator/apis/coralogix/v1alpha1"
28+
)
29+
30+
var ClientsInstance = &Clients{}
31+
32+
type Clients struct {
33+
CxClientSet *cxsdk.ClientSet
34+
CrClient client.Client
35+
K8sClient *kubernetes.Clientset
36+
}
37+
38+
func (c *Clients) InitCoralogixClientSet(targetURL, teamsLevelAPIKey string, userLevelAPIKey string) {
39+
if c.CxClientSet == nil {
40+
c.CxClientSet = cxsdk.NewClientSet(targetURL, teamsLevelAPIKey, userLevelAPIKey)
41+
}
42+
}
43+
44+
func (c *Clients) InitControllerRuntimeClient() error {
45+
if c.CrClient == nil {
46+
crClient, err := client.New(config.GetConfigOrDie(), client.Options{})
47+
if err != nil {
48+
return err
49+
}
50+
if err = prometheus.AddToScheme(crClient.Scheme()); err != nil {
51+
return err
52+
}
53+
if err = coralogixv1alpha1.AddToScheme(crClient.Scheme()); err != nil {
54+
return err
55+
}
56+
c.CrClient = crClient
57+
}
58+
return nil
59+
}
60+
61+
func (c *Clients) InitK8sClient() error {
62+
if c.K8sClient == nil {
63+
k8sClient, err := kubernetes.NewForConfig(config.GetConfigOrDie())
64+
if err != nil {
65+
return err
66+
}
67+
c.K8sClient = k8sClient
68+
}
69+
return nil
70+
}
71+
72+
func (c *Clients) GetCoralogixClientSet() *cxsdk.ClientSet {
73+
return c.CxClientSet
74+
}
75+
76+
func (c *Clients) GetControllerRuntimeClient() client.Client {
77+
return c.CrClient
78+
}
79+
80+
func (c *Clients) GetK8sClient() *kubernetes.Clientset {
81+
return c.K8sClient
82+
}

tests/e2e/e2e_suite_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"context"
21+
"os"
22+
"strings"
23+
"testing"
24+
"time"
25+
26+
. "github.com/onsi/ginkgo/v2"
27+
. "github.com/onsi/gomega"
28+
corev1 "k8s.io/api/core/v1"
29+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
31+
cxsdk "github.com/coralogix/coralogix-management-sdk/go"
32+
)
33+
34+
func TestE2E(t *testing.T) {
35+
RegisterFailHandler(Fail)
36+
RunSpecs(t, "Coralogix operator E2E test suite")
37+
}
38+
39+
var _ = BeforeSuite(func(ctx context.Context) {
40+
region := strings.ToLower(os.Getenv("CORALOGIX_REGION"))
41+
apiKey := os.Getenv("CORALOGIX_API_KEY")
42+
43+
By("Initializing clients")
44+
ClientsInstance.InitCoralogixClientSet(cxsdk.CoralogixGrpcEndpointFromRegion(region), apiKey, apiKey)
45+
Expect(ClientsInstance.InitControllerRuntimeClient()).To(Succeed())
46+
Expect(ClientsInstance.InitK8sClient()).To(Succeed())
47+
48+
By("Validating that the controller-manager pod is running")
49+
Eventually(func() corev1.PodPhase {
50+
k8sClient := ClientsInstance.GetK8sClient()
51+
podList, err := k8sClient.CoreV1().
52+
Pods("coralogix-operator-system").
53+
List(ctx, metav1.ListOptions{LabelSelector: "control-plane=controller-manager"})
54+
Expect(err).NotTo(HaveOccurred())
55+
return podList.Items[0].Status.Phase
56+
}, time.Minute, time.Second).Should(Equal(corev1.PodRunning))
57+
})

0 commit comments

Comments
 (0)