Skip to content

Commit

Permalink
Rely on the NATS cluster connection status when reporting the Eventin…
Browse files Browse the repository at this point in the history
…g CR status
  • Loading branch information
marcobebway committed Dec 14, 2023
1 parent e7a0190 commit 601af6a
Show file tree
Hide file tree
Showing 10 changed files with 564 additions and 37 deletions.
8 changes: 8 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ linters-settings:
alias: istio$1$2
- pkg: github.com/nats-io/nats-server/v2/(\w+)$
alias: natsio$1
- pkg: github.com/nats-io/nats.go
alias: natsio
- pkg: github.com/kyma-project/eventing-manager/internal/controller/(\w+)$
alias: controller$1
- pkg: github.com/kyma-project/kyma/common/logging/logger
Expand All @@ -181,6 +183,12 @@ linters-settings:
alias: natsv1alpha1
- pkg: github.com/kyma-project/nats-manager/testutils
alias: natstestutils
- pkg: github.com/kyma-project/eventing-manager/internal/connection/nats
alias: natsconnection
- pkg: github.com/kyma-project/eventing-manager/internal/connection/nats/errors
alias: natsconnectionerrors
- pkg: github.com/kyma-project/eventing-manager/internal/connection/nats/mocks
alias: natsconnectionmocks
- pkg: github.com/kyma-project/eventing-manager/internal/controller/eventing/subscription/(\w+)$
alias: subscriptioncontroller$1
- pkg: github.com/kyma-project/eventing-manager/internal/controller/operator/eventing
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ RUN go mod download
# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/
COPY internal/label/ internal/label/
COPY internal/ internal/
COPY pkg/ pkg/
COPY testing/ testing/
COPY options/ options/
Expand Down
4 changes: 4 additions & 0 deletions api/operator/v1alpha1/eventing_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func (e *Eventing) SyncStatusActiveBackend() {
e.Status.ActiveBackend = e.Spec.Backend.Type
}

func (e *Eventing) IsPreviousBackendEmpty() bool {
return e.Status.ActiveBackend == ""
}

func (e *Eventing) IsSpecBackendTypeChanged() bool {
return e.Status.ActiveBackend != e.Spec.Backend.Type
}
12 changes: 12 additions & 0 deletions internal/connection/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package connection

type Interface interface {
// Connect connects and returns an error if it failed.
Connect() error

// IsConnected returns true if it is connected, otherwise returns false.
IsConnected() bool

// Disconnect disconnects the active connection.
Disconnect()
}
11 changes: 11 additions & 0 deletions internal/connection/nats/errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package errors

import (
"errors"
)

const (
errCannotConnect = "cannot connect to NATS"
)

var ErrCannotConnect = errors.New(errCannotConnect)
17 changes: 17 additions & 0 deletions internal/connection/nats/interfase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package nats

import (
natsio "github.com/nats-io/nats.go"

"github.com/kyma-project/eventing-manager/internal/connection"
)

//go:generate go run github.com/vektra/mockery/v2 --name Interface
type Interface interface {
connection.Interface

RegisterReconnectHandler(natsio.ConnHandler)
IsReconnectHandlerRegistered() bool
RegisterDisconnectErrHandler(natsio.ConnErrHandler)
IsDisconnectErrHandlerRegistered() bool
}
Loading

0 comments on commit 601af6a

Please sign in to comment.