Skip to content

Commit

Permalink
Update controller runtime (#154)
Browse files Browse the repository at this point in the history
* Move to v2 in progress

* Update tests and reporter

* Change report to junit

* Junit in front
  • Loading branch information
barchw authored Jan 4, 2023
1 parent 79e05ee commit 30396d2
Show file tree
Hide file tree
Showing 35 changed files with 353 additions and 288 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/apirule_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/kyma-incubator/api-gateway/api/v1beta1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

Expand Down
2 changes: 1 addition & 1 deletion controllers/api_controller_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"encoding/json"

gatewayv1beta1 "github.com/kyma-incubator/api-gateway/api/v1beta1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
rulev1alpha1 "github.com/ory/oathkeeper-maester/api/v1alpha1"
networkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
Expand Down
2 changes: 1 addition & 1 deletion controllers/api_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/kyma-incubator/api-gateway/internal/helpers"
"github.com/kyma-incubator/api-gateway/internal/processing"
istioint "github.com/kyma-incubator/api-gateway/internal/types/istio"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
rulev1alpha1 "github.com/ory/oathkeeper-maester/api/v1alpha1"
networkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"encoding/json"

gatewayv1beta1 "github.com/kyma-incubator/api-gateway/api/v1beta1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -54,8 +54,8 @@ var _ = Describe("APIRule Controller Reconciliation", func() {
Expect(err).NotTo(HaveOccurred())
})

It("Should update the apirule with error after the ConfigMap was changed to different one", func() {
Context("From Ory to Istio", func() {
Context("Handler in ConfigMap was changed to different one", func() {
It("Should update valid Ory APIRule with error when going from Ory to Istio", func() {
// given
apiRuleName := generateTestName(testNameBase, testIDLength)
testServiceHost := fmt.Sprintf("httpbin-%s.kyma.local", apiRuleName)
Expand Down Expand Up @@ -95,7 +95,7 @@ var _ = Describe("APIRule Controller Reconciliation", func() {
Expect(expectedApiRule.Status.APIRuleStatus.Code).To(Equal(gatewayv1beta1.StatusError))
})

Context("From Istio to Ory", func() {
It("Should update valid Istio APIRule with error from Istio to Ory", func() {
// given
By("Setting JWT handler config map to istio")
cm := testConfigMap("istio")
Expand Down
43 changes: 34 additions & 9 deletions controllers/api_controlller_reconciliation_test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package reconciliation_test
import (
"context"
"fmt"
"os"
"path/filepath"
"testing"
"time"
Expand All @@ -15,14 +16,15 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"

gatewayv1beta1 "github.com/kyma-incubator/api-gateway/api/v1beta1"
"github.com/kyma-incubator/api-gateway/controllers"
"github.com/kyma-incubator/api-gateway/internal/helpers"
"github.com/kyma-incubator/api-gateway/internal/processing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/reporters"
"github.com/onsi/ginkgo/v2/types"
. "github.com/onsi/gomega"

"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -53,12 +55,10 @@ var (
func TestAPIGatewayReconciliation(t *testing.T) {
RegisterFailHandler(Fail)

RunSpecsWithDefaultAndCustomReporters(t,
"Reconciliation Suite",
[]Reporter{printer.NewlineReporter{}, printer.NewProwReporter("api-gateway-controller-reconciliation")})
RunSpecs(t, "Reconciliation Suite")
}

var _ = BeforeSuite(func(done Done) {
var _ = BeforeSuite(func(specCtx SpecContext) {
logf.SetLogger(zap.New(zap.UseDevMode(true), zap.WriteTo(GinkgoWriter)))
ctx, cancel = context.WithCancel(context.TODO())

Expand Down Expand Up @@ -139,7 +139,7 @@ var _ = BeforeSuite(func(done Done) {
GeneratedObjectsLabels: map[string]string{},
Config: &helpers.Config{},

// Run the suite with period that won't interfere with tests
// Run the suite with small period so reconcilation should happen very often
ReconcilePeriod: time.Second,
OnErrorReconcilePeriod: time.Second,
}
Expand All @@ -155,15 +155,15 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).ToNot(HaveOccurred(), "failed to run manager")
}()

close(done)
}, 60)
}, NodeTimeout(timeout))

var _ = AfterSuite(func() {
/*
Provided solution for timeout issue waiting for kubeapiserver
https://github.com/kubernetes-sigs/controller-runtime/issues/1571#issuecomment-1005575071
*/
cancel()

By("tearing down the test environment,but I do nothing here.")
err := testEnv.Stop()
// Set 4 with random
Expand All @@ -175,6 +175,31 @@ var _ = AfterSuite(func() {

})

var _ = ReportAfterSuite("custom reporter", func(report types.Report) {
logger := zap.New(zap.UseDevMode(true), zap.WriteTo(GinkgoWriter))
if key, ok := os.LookupEnv("ARTIFACTS"); ok {
reportsFilename := fmt.Sprintf("%s/%s", key, "junit-reconciliation.xml")
logger.Info("Generating reports at", "location", reportsFilename)
err := reporters.GenerateJUnitReport(report, reportsFilename)

if err != nil {
logger.Error(err, "Junit Report Generation Error")
}
} else {
if err := os.MkdirAll("../../reports", 0755); err != nil {
logger.Error(err, "could not create directory")
}

reportsFilename := fmt.Sprintf("%s/%s", "../../reports", "junit-reconciliation.xml")
logger.Info("Generating reports at", "location", reportsFilename)
err := reporters.GenerateJUnitReport(report, reportsFilename)

if err != nil {
logger.Error(err, "Junit Report Generation Error")
}
}
})

// SetupTestReconcile returns a reconcile.Reconcile implementation that delegates to inner and
// writes the request to requests after Reconcile is finished.
func SetupTestReconcile(inner reconcile.Reconciler) (reconcile.Reconciler, chan reconcile.Request) {
Expand Down
41 changes: 33 additions & 8 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers_test
import (
"context"
"fmt"
"os"
"path/filepath"
"testing"
"time"
Expand All @@ -15,14 +16,15 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"

gatewayv1beta1 "github.com/kyma-incubator/api-gateway/api/v1beta1"
"github.com/kyma-incubator/api-gateway/controllers"
"github.com/kyma-incubator/api-gateway/internal/helpers"
"github.com/kyma-incubator/api-gateway/internal/processing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/reporters"
"github.com/onsi/ginkgo/v2/types"
. "github.com/onsi/gomega"

"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -53,12 +55,10 @@ var (
func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

RunSpecsWithDefaultAndCustomReporters(t,
"Controller Suite",
[]Reporter{printer.NewlineReporter{}, printer.NewProwReporter("api-gateway-controller-testsuite")})
RunSpecs(t, "Controller Suite")
}

var _ = BeforeSuite(func(done Done) {
var _ = BeforeSuite(func(specCtx SpecContext) {
logf.SetLogger(zap.New(zap.UseDevMode(true), zap.WriteTo(GinkgoWriter)))
ctx, cancel = context.WithCancel(context.TODO())

Expand Down Expand Up @@ -155,8 +155,7 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).ToNot(HaveOccurred(), "failed to run manager")
}()

close(done)
}, 60)
}, NodeTimeout(10*time.Second))

var _ = AfterSuite(func() {
/*
Expand All @@ -175,6 +174,32 @@ var _ = AfterSuite(func() {

})

var _ = ReportAfterSuite("custom reporter", func(report types.Report) {
logger := zap.New(zap.UseDevMode(true), zap.WriteTo(GinkgoWriter))

if key, ok := os.LookupEnv("ARTIFACTS"); ok {
reportsFilename := fmt.Sprintf("%s/%s", key, "junit-controller.xml")
logger.Info("Generating reports at", "location", reportsFilename)
err := reporters.GenerateJUnitReport(report, reportsFilename)

if err != nil {
logger.Error(err, "Junit Report Generation Error")
}
} else {
if err := os.MkdirAll("../reports", 0755); err != nil {
logger.Error(err, "could not create directory")
}

reportsFilename := fmt.Sprintf("%s/%s", "../reports", "junit-controller.xml")
logger.Info("Generating reports at", "location", reportsFilename)
err := reporters.GenerateJUnitReport(report, reportsFilename)

if err != nil {
logger.Error(err, "Junit Report Generation Error")
}
}
})

// SetupTestReconcile returns a reconcile.Reconcile implementation that delegates to inner and
// writes the request to requests after Reconcile is finished.
func SetupTestReconcile(inner reconcile.Reconciler) (reconcile.Reconciler, chan reconcile.Request) {
Expand Down
45 changes: 16 additions & 29 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,30 @@ go 1.19

require (
github.com/go-logr/logr v1.2.3
github.com/onsi/ginkgo v1.16.5
github.com/onsi/ginkgo/v2 v2.6.1
github.com/onsi/gomega v1.24.2
github.com/ory/oathkeeper-maester v0.1.7
istio.io/api v0.0.0-20221208070204-0528cb6ce63b
istio.io/client-go v1.16.1
k8s.io/apimachinery v0.26.0
k8s.io/client-go v0.25.4
sigs.k8s.io/controller-runtime v0.13.1
k8s.io/client-go v0.26.0
sigs.k8s.io/controller-runtime v0.14.1
)

require (
cloud.google.com/go v0.97.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -51,42 +40,40 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vrischmann/envconfig v1.3.0
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15
golang.org/x/net v0.4.0 // indirect
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220628213854-d9e0b6570c03 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.26.0
k8s.io/apiextensions-apiserver v0.25.4
k8s.io/component-base v0.25.4 // indirect
k8s.io/apiextensions-apiserver v0.26.0
k8s.io/component-base v0.26.0 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221123214604-86e75ddd809a // indirect
k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
Loading

0 comments on commit 30396d2

Please sign in to comment.