Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
chore: remove eventbroker from code (#229)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Kreuzberger <[email protected]>
  • Loading branch information
christian-kreuzberger-dtx authored Dec 14, 2021
1 parent abebaf4 commit b86311d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 64 deletions.
10 changes: 4 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ COPY go.mod go.sum ./
# Download dependencies
RUN go mod download

ARG debugBuild

# set buildflags for debug build
RUN if [ ! -z "$debugBuild" ]; then export BUILDFLAGS='-gcflags "all=-N -l"'; fi

# Copy local code to the container image.
COPY . .

# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
ARG SKAFFOLD_GO_GCFLAGS

# Build the command inside the container.
# (You may fetch or manage dependencies here, either manually or with a tool like "godep".)
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags '-linkmode=external' $BUILDFLAGS -v -o prometheus-service
RUN GOOS=linux go build -ldflags '-linkmode=external' -gcflags="${SKAFFOLD_GO_GCFLAGS}" -v -o prometheus-service

# Use a Docker multi-stage build to create a lean production image.
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
Expand Down
2 changes: 1 addition & 1 deletion deploy/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ spec:
- name: distributor
image: keptn/distributor:0.10.0
ports:
- containerPort: 8081
- containerPort: 8080
resources:
requests:
memory: "16Mi"
Expand Down
1 change: 1 addition & 0 deletions eventhandling/configureEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ func (eh ConfigureMonitoringEventHandler) sendConfigureMonitoringFinishedEvent(c
func (eh ConfigureMonitoringEventHandler) handleError(e *keptnevents.ConfigureMonitoringEventData, msg string) error {
//logger.Error(msg)
if err := eh.sendConfigureMonitoringFinishedEvent(e, keptnv2.StatusErrored, keptnv2.ResultFailed, msg); err != nil {
// an additional error occurred when trying to send configure monitoring finished back to Keptn
eh.logger.Error(err.Error())
}
return errors.New(msg)
Expand Down
18 changes: 2 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
)

const eventbroker = "EVENTBROKER"
const sliResourceURI = "prometheus/sli.yaml"
const serviceName = "prometheus-service"

Expand Down Expand Up @@ -112,15 +111,7 @@ func gotEvent(event cloudevents.Event) error {

logger := keptncommon.NewLogger(shkeptncontext, event.Context.GetID(), "prometheus-service")

eventBrokerURL, err := utils.GetEventBrokerURL()
if err != nil {
logger.Error(err.Error())
return err
}

keptnHandler, err := keptnv2.NewKeptn(&event, keptncommon.KeptnOpts{
EventBrokerURL: eventBrokerURL,
})
keptnHandler, err := keptnv2.NewKeptn(&event, keptncommon.KeptnOpts{})

if err != nil {
return fmt.Errorf("could not create Keptn handler: %v", err)
Expand Down Expand Up @@ -227,12 +218,7 @@ func retrieveMetrics(event cloudevents.Event, eventData *keptnv2.GetSLITriggered
return nil, err
}

eventBrokerURL := os.Getenv(eventbroker)
if eventBrokerURL == "" {
eventBrokerURL = "http://event-broker/keptn"
}

keptnHandler, err := keptnv2.NewKeptn(&event, keptncommon.KeptnOpts{EventBrokerURL: eventBrokerURL})
keptnHandler, err := keptnv2.NewKeptn(&event, keptncommon.KeptnOpts{})
if err != nil {
return nil, err
}
Expand Down
41 changes: 0 additions & 41 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,9 @@
package utils

import (
"fmt"
"net/url"
"os"
)

const eventbroker = "EVENTBROKER"

// GetServiceEndpoint retrieves an endpoint stored in an environment variable and sets http as default scheme
func GetServiceEndpoint(service string) (url.URL, error) {
url, err := url.Parse(os.Getenv(service))
if err != nil {
return *url, fmt.Errorf("Failed to retrieve value from ENVIRONMENT_VARIABLE: %s", service)
}

if url.Scheme == "" {
url.Scheme = "http"
}

return *url, nil
}

// GetEventBrokerURL godoc
func GetEventBrokerURL() (string, error) {
var eventBrokerURL string
endpoint, err := GetServiceEndpoint(eventbroker)
if err != nil {
eventBrokerURL = "http://localhost:8081/event"
return "", fmt.Errorf("Could not parse EVENTBROKER URL %s: %s. Using default: %s", os.Getenv(eventbroker), err.Error(), eventBrokerURL)
}
eventBrokerURL = endpoint.String()
return eventBrokerURL, nil
}

// EnvVarOrDefault returns the value of the environment variable named "envName" if found or "defaultVal" otherwise
func EnvVarOrDefault(envName, defaultVal string) string {
if val := os.Getenv(envName); val == "" {
Expand All @@ -42,14 +12,3 @@ func EnvVarOrDefault(envName, defaultVal string) string {
return val
}
}

// EnvVar returns the value of the environment variable named "envName" if found or empty string otherwise
func EnvVar(envName string) string {
return os.Getenv(envName)
}

// EnvVarEqualsTo compares the value of the environment variable named "envName" to "equalsTo"
// and returns true if they are equal, false otherwise
func EnvVarEqualsTo(envName, equalsTo string) bool {
return EnvVar(envName) == equalsTo
}

0 comments on commit b86311d

Please sign in to comment.