Skip to content

Commit

Permalink
Replaced kyma/epp package with local EPP package and fixed lint issues (
Browse files Browse the repository at this point in the history
#15)

* Replaced kyma/epp pkg with local pkgs

* fixed lint issues
  • Loading branch information
mfaizanse authored Dec 13, 2023
1 parent cee372e commit 70cd4c8
Show file tree
Hide file tree
Showing 51 changed files with 271 additions and 230 deletions.
14 changes: 7 additions & 7 deletions cmd/event-publisher-proxy/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package main //nolint:cyclop // it is only starting required instances.

import (
golog "log"
Expand All @@ -7,12 +7,12 @@ import (
kymalogger "github.com/kyma-project/kyma/components/eventing-controller/logger"
"github.com/prometheus/client_golang/prometheus"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/commander"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/commander/eventmesh"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/commander/nats"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics/latency"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options"
"github.com/kyma-project/eventing-publisher-proxy/pkg/commander"
"github.com/kyma-project/eventing-publisher-proxy/pkg/commander/eventmesh"
"github.com/kyma-project/eventing-publisher-proxy/pkg/commander/nats"
"github.com/kyma-project/eventing-publisher-proxy/pkg/metrics"
"github.com/kyma-project/eventing-publisher-proxy/pkg/metrics/latency"
"github.com/kyma-project/eventing-publisher-proxy/pkg/options"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/kyma-project/kyma/components/event-publisher-proxy
module github.com/kyma-project/eventing-publisher-proxy

go 1.21

Expand Down
28 changes: 17 additions & 11 deletions pkg/application/clean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

applicationv1alpha1 "github.com/kyma-project/kyma/components/application-operator/pkg/apis/applicationconnector/v1alpha1"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/applicationtest"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application/applicationtest"
)

func TestCleanName(t *testing.T) {
Expand Down Expand Up @@ -69,12 +69,15 @@ func TestCleanName(t *testing.T) {

for _, tc := range testCases {
if gotName := GetCleanTypeOrName(tc.givenApplication); tc.wantName != gotName {
t.Errorf("Clean application name:[%s] failed, want:[%v] but got:[%v]", tc.givenApplication.Name, tc.wantName, gotName)
t.Errorf("Clean application name:[%s] failed, want:[%v] but got:[%v]",
tc.givenApplication.Name, tc.wantName, gotName)
}
}
}

func Test_GetTypeOrName(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
givenApplication *applicationv1alpha1.Application
Expand All @@ -87,9 +90,10 @@ func Test_GetTypeOrName(t *testing.T) {
wantName: "alphanumeric0123",
},
{
name: "Should return application name if label with right key does not exists",
givenApplication: applicationtest.NewApplication("alphanumeric0123", map[string]string{"ignore-me": "value"}),
wantName: "alphanumeric0123",
name: "Should return application name if label with right key does not exists",
givenApplication: applicationtest.NewApplication("alphanumeric0123",
map[string]string{"ignore-me": "value"}),
wantName: "alphanumeric0123",
},
{
name: "Should return application name as unclean",
Expand All @@ -98,14 +102,16 @@ func Test_GetTypeOrName(t *testing.T) {
},
// application type label is available, then use it instead of the application name
{
name: "Should return application label instead of name",
givenApplication: applicationtest.NewApplication("alphanumeric0123", map[string]string{TypeLabel: "apptype"}),
wantName: "apptype",
name: "Should return application label instead of name",
givenApplication: applicationtest.NewApplication("alphanumeric0123",
map[string]string{TypeLabel: "apptype"}),
wantName: "apptype",
},
{
name: "Should return application label as unclean",
givenApplication: applicationtest.NewApplication("alphanumeric0123", map[string]string{TypeLabel: "apptype=with.!@#none-$%^alphanumeric_&*-characters"}),
wantName: "apptype=with.!@#none-$%^alphanumeric_&*-characters",
name: "Should return application label as unclean",
givenApplication: applicationtest.NewApplication("alphanumeric0123",
map[string]string{TypeLabel: "apptype=with.!@#none-$%^alphanumeric_&*-characters"}),
wantName: "apptype=with.!@#none-$%^alphanumeric_&*-characters",
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/application/fake/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

applicationv1alpha1 "github.com/kyma-project/kyma/components/application-operator/pkg/apis/applicationconnector/v1alpha1"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application"
)

func NewApplicationListerOrDie(ctx context.Context, app *applicationv1alpha1.Application) *application.Lister {
Expand Down
2 changes: 1 addition & 1 deletion pkg/application/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"k8s.io/client-go/dynamic/dynamicinformer"
"k8s.io/client-go/tools/cache"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/informers"
"github.com/kyma-project/eventing-publisher-proxy/pkg/informers"
)

type Lister struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudevents/builder/eventmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/kyma-project/kyma/components/eventing-controller/logger"
"github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application"
)

// Perform a compile-time check.
Expand Down
8 changes: 4 additions & 4 deletions pkg/cloudevents/builder/eventmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

cloudevents "github.com/cloudevents/sdk-go/v2"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/applicationtest"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/fake"
testingutils "github.com/kyma-project/kyma/components/event-publisher-proxy/testing"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application/applicationtest"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application/fake"
testingutils "github.com/kyma-project/eventing-publisher-proxy/testing"
kymalogger "github.com/kyma-project/kyma/components/eventing-controller/logger"
"github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner"
"github.com/stretchr/testify/require"
Expand Down
10 changes: 6 additions & 4 deletions pkg/cloudevents/builder/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ import (
"github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner"
"go.uber.org/zap"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application"
)

// Perform a compile-time check.
var _ CloudEventBuilder = &GenericBuilder{}

var (
const (
// jsBuilderName used as the logger name.
genericBuilderName = "generic-type-builder"
)

func NewGenericBuilder(typePrefix string, cleaner cleaner.Cleaner, applicationLister *application.Lister, logger *logger.Logger) CloudEventBuilder {
func NewGenericBuilder(typePrefix string, cleaner cleaner.Cleaner, applicationLister *application.Lister,
logger *logger.Logger) CloudEventBuilder {
return &GenericBuilder{
typePrefix: typePrefix,
applicationLister: applicationLister,
Expand Down Expand Up @@ -84,7 +85,8 @@ func (gb *GenericBuilder) GetAppNameOrSource(source string, namedLogger *zap.Sug
if gb.isApplicationListerEnabled() {
if appObj, err := gb.applicationLister.Get(source); err == nil && appObj != nil {
appName = application.GetTypeOrName(appObj)
namedLogger.With("application", source).Debug("Using application name: %s as source.", appName)
namedLogger.With("application", source).Debug("Using application name: %s as source.",
appName)
} else {
namedLogger.With("application", source).Debug("Cannot find application.")
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cloudevents/builder/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"testing"

cloudevents "github.com/cloudevents/sdk-go/v2"
testingutils "github.com/kyma-project/kyma/components/event-publisher-proxy/testing"
testingutils "github.com/kyma-project/eventing-publisher-proxy/testing"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/applicationtest"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/fake"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application/applicationtest"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application/fake"
kymalogger "github.com/kyma-project/kyma/components/eventing-controller/logger"
"github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudevents/builder/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package builder

import (
cev2event "github.com/cloudevents/sdk-go/v2/event"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application"
"github.com/kyma-project/kyma/components/eventing-controller/logger"
"github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudevents/eventtype/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/kyma-project/kyma/components/eventing-controller/logger"
"go.uber.org/zap"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application"
)

var (
Expand Down
6 changes: 3 additions & 3 deletions pkg/cloudevents/eventtype/clean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

"github.com/stretchr/testify/require"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/applicationtest"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application/fake"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application/applicationtest"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application/fake"
)

//nolint:lll // we need long lines here as the event types can get very long
Expand Down
4 changes: 0 additions & 4 deletions pkg/cloudevents/eventtype/eventtypetest/eventtypetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ func (c CleanerStub) Clean(_ string) (string, error) {
func (cf CleanerFunc) Clean(eventType string) (string, error) {
return cf(eventType)
}

var DefaultCleaner = func(eventType string) (string, error) {
return eventType, nil
}
2 changes: 1 addition & 1 deletion pkg/cloudevents/eventtype/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/builder"
"github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/builder"
)

// parse splits the event-type using the given prefix and returns the application name, event and version
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudevents/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

cehttp "github.com/cloudevents/sdk-go/v2/protocol/http"

"github.com/kyma-project/kyma/components/event-publisher-proxy/internal"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/eventmesh"
"github.com/kyma-project/eventing-publisher-proxy/internal"
"github.com/kyma-project/eventing-publisher-proxy/pkg/eventmesh"
)

func TestWriteRequestWithHeaders(t *testing.T) {
Expand Down
32 changes: 16 additions & 16 deletions pkg/commander/eventmesh/eventmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"context"

"github.com/kelseyhightower/envconfig"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/builder"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/eventtype"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/handler"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/handler/health"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/informers"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/oauth"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/receiver"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender/eventmesh"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/signals"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/subscribed"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application"
"github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/builder"
"github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/eventtype"
"github.com/kyma-project/eventing-publisher-proxy/pkg/env"
"github.com/kyma-project/eventing-publisher-proxy/pkg/handler"
"github.com/kyma-project/eventing-publisher-proxy/pkg/handler/health"
"github.com/kyma-project/eventing-publisher-proxy/pkg/informers"
"github.com/kyma-project/eventing-publisher-proxy/pkg/legacy"
"github.com/kyma-project/eventing-publisher-proxy/pkg/metrics"
"github.com/kyma-project/eventing-publisher-proxy/pkg/oauth"
"github.com/kyma-project/eventing-publisher-proxy/pkg/options"
"github.com/kyma-project/eventing-publisher-proxy/pkg/receiver"
"github.com/kyma-project/eventing-publisher-proxy/pkg/sender/eventmesh"
"github.com/kyma-project/eventing-publisher-proxy/pkg/signals"
"github.com/kyma-project/eventing-publisher-proxy/pkg/subscribed"
"github.com/kyma-project/kyma/components/eventing-controller/logger"
"github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner"

Expand Down Expand Up @@ -101,7 +101,7 @@ func (c *Commander) Start() error {

// Configure Subscription Lister
subDynamicSharedInfFactory := subscribed.GenerateSubscriptionInfFactory(k8sConfig)
subLister := subDynamicSharedInfFactory.ForResource(subscribed.GVR).Lister()
subLister := subDynamicSharedInfFactory.ForResource(subscribed.SubscriptionGVR()).Lister()
subscribedProcessor := &subscribed.Processor{
SubscriptionLister: &subLister,
Prefix: c.envCfg.EventTypePrefix,
Expand Down
30 changes: 15 additions & 15 deletions pkg/commander/nats/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import (
"context"

"github.com/kelseyhightower/envconfig"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/application"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/builder"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/eventtype"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/handler"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/informers"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics"
pkgnats "github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/nats"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/receiver"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender/jetstream"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/signals"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/subscribed"
"github.com/kyma-project/eventing-publisher-proxy/pkg/application"
"github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/builder"
"github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/eventtype"
"github.com/kyma-project/eventing-publisher-proxy/pkg/env"
"github.com/kyma-project/eventing-publisher-proxy/pkg/handler"
"github.com/kyma-project/eventing-publisher-proxy/pkg/informers"
"github.com/kyma-project/eventing-publisher-proxy/pkg/legacy"
"github.com/kyma-project/eventing-publisher-proxy/pkg/metrics"
pkgnats "github.com/kyma-project/eventing-publisher-proxy/pkg/nats"
"github.com/kyma-project/eventing-publisher-proxy/pkg/options"
"github.com/kyma-project/eventing-publisher-proxy/pkg/receiver"
"github.com/kyma-project/eventing-publisher-proxy/pkg/sender/jetstream"
"github.com/kyma-project/eventing-publisher-proxy/pkg/signals"
"github.com/kyma-project/eventing-publisher-proxy/pkg/subscribed"
"github.com/kyma-project/kyma/components/eventing-controller/logger"
"github.com/kyma-project/kyma/components/eventing-controller/pkg/backend/cleaner"

Expand Down Expand Up @@ -108,7 +108,7 @@ func (c *Commander) Start() error {

// configure Subscription Lister
subDynamicSharedInfFactory := subscribed.GenerateSubscriptionInfFactory(k8sConfig)
subLister := subDynamicSharedInfFactory.ForResource(subscribed.GVR).Lister()
subLister := subDynamicSharedInfFactory.ForResource(subscribed.SubscriptionGVR()).Lister()
subscribedProcessor := &subscribed.Processor{
SubscriptionLister: &subLister,
Prefix: c.envCfg.ToConfig().EventTypePrefix,
Expand Down
26 changes: 14 additions & 12 deletions pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"strings"
"time"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/env"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/metrics"
"github.com/kyma-project/eventing-publisher-proxy/pkg/env"
"github.com/kyma-project/eventing-publisher-proxy/pkg/metrics"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy/api"
"github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/api"

"github.com/gorilla/mux"
"github.com/kyma-project/kyma/components/eventing-controller/logger"
Expand All @@ -21,15 +21,15 @@ import (
cev2event "github.com/cloudevents/sdk-go/v2/event"
cev2http "github.com/cloudevents/sdk-go/v2/protocol/http"

"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/builder"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/cloudevents/eventtype"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/handler/health"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/legacy"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/options"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/receiver"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/sender"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/subscribed"
"github.com/kyma-project/kyma/components/event-publisher-proxy/pkg/tracing"
"github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/builder"
"github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/eventtype"
"github.com/kyma-project/eventing-publisher-proxy/pkg/handler/health"
"github.com/kyma-project/eventing-publisher-proxy/pkg/legacy"
"github.com/kyma-project/eventing-publisher-proxy/pkg/options"
"github.com/kyma-project/eventing-publisher-proxy/pkg/receiver"
"github.com/kyma-project/eventing-publisher-proxy/pkg/sender"
"github.com/kyma-project/eventing-publisher-proxy/pkg/subscribed"
"github.com/kyma-project/eventing-publisher-proxy/pkg/tracing"
)

// EventingHandler is responsible for receiving HTTP requests and dispatching them to the Backend.
Expand Down Expand Up @@ -149,6 +149,7 @@ func (h *Handler) handlePublishLegacyEvent(w http.ResponseWriter, r *http.Reques
ceEvent, err := h.LegacyTransformer.TransformPublishRequestToCloudEvent(data)
if err != nil {
legacy.WriteJSONResponse(w, legacy.ErrorResponse(http.StatusInternalServerError, err))
//nolint:nilnil // this will be removed once subscription v1alpha1 is removed.
return nil, nil
}

Expand All @@ -175,6 +176,7 @@ func (h *Handler) handlePublishLegacyEventV1alpha1(w http.ResponseWriter, r *htt
event, _ := h.LegacyTransformer.WriteLegacyRequestsToCE(w, data)
if event == nil {
h.namedLogger().Error("Failed to transform legacy event to CloudEvent, event is nil")
//nolint:nilnil // this will be removed once subscription v1alpha1 is removed.
return nil, nil
}

Expand Down
Loading

0 comments on commit 70cd4c8

Please sign in to comment.