Skip to content

Commit

Permalink
workaround to #24 with envoy filter + adapter http endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
c0c0n3 committed Jan 29, 2020
1 parent c87c52a commit b3de583
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 5 deletions.
10 changes: 5 additions & 5 deletions container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# - https://dev.to/ivan/go-build-a-minimal-docker-image-in-just-three-steps-514i
#
# Build from repo root dir with:
#
#
# $ docker build -t boost/orionadapter -f container/Dockerfile .
#
FROM golang:1.13.4-stretch AS builder
Expand All @@ -14,7 +14,7 @@ ENV GO111MODULE=on \
# NOTES.
# 1. Modules. Without telling the complier explicitly, the build will fail.
# I wonder why I don't have to set that var when I build on MacOS though...
# 2. CGO. We're not using any C libs from our Go code so we disable CGO.
# 2. CGO. We're not using any C libs from our Go code so we disable CGO.
# Strangely enough, without doing this explicitly, I get this error when
# running the container:
#
Expand Down Expand Up @@ -55,12 +55,12 @@ FROM scratch
COPY --chown=0:0 --from=builder /dist /

# Set up the app to run as a non-root user inside the /data folder
# User ID 65534 is usually user 'nobody'.
# User ID 65534 is usually user 'nobody'.
# The executor of this image should still specify a user during setup.
COPY --chown=65534:0 --from=builder /data /data
USER 65534
WORKDIR /data

ENTRYPOINT ["/orionadapter"]
CMD [ "43210" ]
EXPOSE 43210
CMD [ "43210", "54321" ]
EXPOSE 43210 54321
52 changes: 52 additions & 0 deletions deployment/egress_filter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: orion-egress-filter
namespace: default
spec:
workloadSelector:
labels:
app: httpbin
configPatches:
# The first patch adds the lua filter to the listener/http connection manager
- applyTo: HTTP_FILTER
match:
context: SIDECAR_OUTBOUND
listener:
portNumber: 80
filterChain:
filter:
name: "envoy.http_connection_manager"
subFilter:
name: "envoy.router"
patch:
operation: INSERT_BEFORE
value: # lua filter specification
name: envoy.lua
config:
inlineCode: |
function envoy_on_request(request_handle)
local headers, body = request_handle:httpCall(
"lua_cluster", {
[":method"] = "GET",
[":path"] = "/",
[":authority"] = "lua_cluster"}, "", 5000)
request_handle:headers():add("header", body)
end
# The second patch adds the cluster that is referenced by the lua code
# cds match is omitted as a new cluster is being added
- applyTo: CLUSTER
# match:
# context: SIDECAR_OUTBOUND
patch:
operation: ADD
value: # cluster specification
name: "lua_cluster"
type: STRICT_DNS
connect_timeout: 5.5s
lb_policy: ROUND_ROBIN
hosts:
- socket_address:
protocol: TCP
address: "orionadapterservice.istio-system"
port_value: 54321
7 changes: 7 additions & 0 deletions deployment/orion_adapter_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ spec:
protocol: TCP
port: 43210
targetPort: 43210
- name: http
protocol: TCP
port: 54321
targetPort: 54321
selector:
app: orionadapter
---
Expand Down Expand Up @@ -41,3 +45,6 @@ spec:
imagePullPolicy: Never
ports:
- containerPort: 43210
name: grpc
- containerPort: 54321
name: http
23 changes: 23 additions & 0 deletions orionadapter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"fmt"
"log"
"net/http"
"os"
"strconv"

Expand All @@ -20,6 +22,9 @@ func main() {
go func() {
s.Run(shutdown)
}()

runHTTP()

_ = <-shutdown
}

Expand All @@ -31,3 +36,21 @@ func readPortArg() int {
}
return 0
}

// TODO: refactor this mess!!

func token(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "whoopsie.dapsie!!")
}

func runHTTPServerLoop(port string) {
http.HandleFunc("/", token)
addr := fmt.Sprintf(":%s", port)

log.Fatal(http.ListenAndServe(addr, nil))
}

func runHTTP() {
port := os.Args[2] // TODO let it bomb out if no arg?!
go runHTTPServerLoop(port)
}

0 comments on commit b3de583

Please sign in to comment.