Skip to content

Commit

Permalink
added testing for prometheus serviceMonitor converter
Browse files Browse the repository at this point in the history
  • Loading branch information
f41gh7 committed Jul 30, 2020
1 parent 1eb0a84 commit e432b6f
Show file tree
Hide file tree
Showing 4 changed files with 1,071 additions and 3 deletions.
4 changes: 2 additions & 2 deletions controllers/factory/servicemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ func CreateVMServiceScrapeFromService(ctx context.Context, rclient client.Client
}
scrapeSvc := &victoriametricsv1beta1.VMServiceScrape{
ObjectMeta: metav1.ObjectMeta{
Name: service.Name,
Namespace: service.Namespace,
Name: service.Name,
Namespace: service.Namespace,
OwnerReferences: service.OwnerReferences,
},
Spec: victoriametricsv1beta1.VMServiceScrapeSpec{
Expand Down
9 changes: 8 additions & 1 deletion e2e/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
victoriametricsv1beta1 "github.com/VictoriaMetrics/operator/api/v1beta1"
"github.com/VictoriaMetrics/operator/manager"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -41,7 +42,10 @@ var _ = BeforeSuite(func(done Done) {

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
CRDDirectoryPaths: []string{
filepath.Join("..", "config", "crd", "bases"),
filepath.Join("..", "hack"),
},
UseExistingCluster: pointer.BoolPtr(true),
AttachControlPlaneOutput: true,
ErrorIfCRDPathMissing: true,
Expand All @@ -54,6 +58,9 @@ var _ = BeforeSuite(func(done Done) {

err = victoriametricsv1beta1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
//prometheus operator scheme for client
err = monitoringv1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

// +kubebuilder:scaffold:scheme

Expand Down
65 changes: 65 additions & 0 deletions e2e/prometheus_converter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package e2e

import (
"context"
victoriametricsv1beta1 "github.com/VictoriaMetrics/operator/api/v1beta1"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

var _ = Describe("test prometheusConverter Controller", func() {
Context("e2e prome converter", func() {

Context("crud", func() {
Context("create", func() {
name := "create-servicemonitor"
namespace := "default"
AfterEach(func() {
Expect(k8sClient.Delete(context.TODO(),
&monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
}})).To(Succeed())
Expect(k8sClient.Delete(context.TODO(),
&victoriametricsv1beta1.VMServiceScrape{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
}})).To(Succeed())

})

It("should create prometheusServiceMonitor", func() {
Expect(k8sClient.Create(context.TODO(), &monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
Spec: monitoringv1.ServiceMonitorSpec{
Endpoints: []monitoringv1.Endpoint{
{Port: "8081"},
},
Selector: metav1.LabelSelector{MatchLabels: map[string]string{"managed-by": "vm-operator"}},
},
})).To(Succeed())
Eventually(func() error {
return k8sClient.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: name}, &victoriametricsv1beta1.VMServiceScrape{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
})
}, 60, 1).Should(Succeed())
})
})

},
)

})
})
Loading

0 comments on commit e432b6f

Please sign in to comment.