Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Jun 4, 2024
1 parent cd4ad88 commit 30d5197
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ COPY pkg/ pkg/
# Build
RUN WASM_SHIM_SHA256=$(cat /opt/kuadrant/wasm-shim/kuadrant-ratelimit-wasm.sha256) \
&& CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags "-X github.com/kuadrant/kuadrant-operator/pkg/rlptools/wasm.WASM_SHIM_SHA256=${WASM_SHIM_SHA256}" \
-ldflags "-X github.com/kuadrant/kuadrant-operator/pkg/rlptools/wasm.WasmShimSha256=${WASM_SHIM_SHA256}" \
-a -o manager main.go

# Use distroless as minimal base image to package the manager binary
Expand Down
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,26 @@ test-unit: clean-cov generate fmt vet ## Run Unit tests.

##@ Build

WASM_SHIM = $(PROJECT_PATH)/kuadrant-ratelimit-wasm
WASM_SHIM_VERSION = v0.4.0-alpha.1
$(WASM_SHIM):
@{ \
ASSET_ID=$$(curl -s -H "Accept: application/vnd.github.v3.raw" \
https://api.github.com/repos/Kuadrant/wasm-shim/releases | \
jq ". | map(select(.tag_name == \"$(WASM_SHIM_VERSION)\"))[0].assets | map(select(.name == \"kuadrant-ratelimit-wasm-$(WASM_SHIM_VERSION)\"))[0].id" \
) \
&& echo "Downloading kuadrant-ratelimit-wasm@$(WASM_SHIM_VERSION) from https://api.github.com/repos/Kuadrant/wasm-shim/releases/assets/$${ASSET_ID}" \
&& curl -sSLo $@ -H "Accept: application/octet-stream" https://api.github.com/repos/Kuadrant/wasm-shim/releases/assets/$${ASSET_ID}; \
sha256sum $@; \
}

.PHONY: wasm-shim
wasm-shim: $(WASM_SHIM) ## Download opm locally if necessary.

build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go

docker-build: ## Build docker image with the manager.
docker-build: $(WASM_SHIM) ## Build docker image with the manager.
docker build -t $(IMG) .

docker-push: ## Push docker image with the manager.
Expand Down
4 changes: 3 additions & 1 deletion doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ make build

## Build docker image

TODO
```sh
make docker-build
```

## Deploy on local kubernetes cluster

Expand Down
11 changes: 6 additions & 5 deletions doc/rate-limiting.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ metadata:
namespace: istio-system
spec:
sha256: b101508ddd5fd40eb2116204e6c768332a359c21feb2dbb348956459349e7d71
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: istio-ingressgateway
url: http://kuadrant-operator-controller-manager-ratelimit-wasm-service.kuadrant-system.svc.cluster.local:8082/kuadrant-ratelimit-wasm
phase: STATS
pluginConfig:
failureMode: deny
Expand Down Expand Up @@ -476,9 +482,4 @@ spec:
key: limit.toystore_v1_website_unauthenticated__3f9c40c6
value: "1"
service: kuadrant-rate-limiting-service
selector:
matchLabels:
istio.io/gateway-name: istio-ingressgateway
TODO!!
url: oci://quay.io/kuadrant/wasm-shim:v0.3.0
```
25 changes: 9 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package main
import (
"flag"
"fmt"
"net"
"net/http"
"os"
"runtime"
"time"

certmanv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
authorinoopapi "github.com/kuadrant/authorino-operator/api/v1beta1"
Expand Down Expand Up @@ -99,7 +99,7 @@ func printControllerMetaInfo() {

setupLog.Info(fmt.Sprintf("go version: %s", runtime.Version()))
setupLog.Info(fmt.Sprintf("go os/arch: %s/%s", runtime.GOOS, runtime.GOARCH))
setupLog.Info("wasm-shim", "sha256", wasm.WASM_SHIM_SHA256)
setupLog.Info("wasm-shim", "sha256", wasm.SHA256())
}

func startWasmShimFileServer(wasmShimPort int) {
Expand All @@ -110,27 +110,20 @@ func startWasmShimFileServer(wasmShimPort int) {
return
}

lis, err := net.Listen("tcp", fmt.Sprintf(":%d", wasmShimPort))
if err != nil {
logger.Error(err, "failed to obtain port for the http wasm-shim file service")
os.Exit(1)
}

if lis == nil {
logger.Error(err, "failed to obtain listener for the http wasm-shim file service")
os.Exit(1)
}

mux := http.NewServeMux()

mux.Handle("/", http.FileServer(http.Dir("/opt/kuadrant/wasm-shim")))

go func() {
var err error

logger.Info("starting http wasm-shim file service", "port", wasmShimPort)

err = http.Serve(lis, mux)
server := &http.Server{
Addr: fmt.Sprintf(":%d", wasmShimPort),
ReadHeaderTimeout: 3 * time.Second,
Handler: mux,
}

err := server.ListenAndServe()

if err != nil {
logger.Error(err, "failed to start listener for the http wasm-shim file service")
Expand Down
24 changes: 16 additions & 8 deletions make/integration-tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,51 @@ INTEGRATION_TESTS_EXTRA_ARGS =
##@ Integration tests

.PHONY: test-bare-k8s-integration
test-bare-k8s-integration: clean-cov generate fmt vet ginkgo ## Requires only bare kubernetes cluster.
test-bare-k8s-integration: $(WASM_SHIM) clean-cov generate fmt vet ginkgo ## Requires only bare kubernetes cluster.
mkdir -p $(PROJECT_PATH)/coverage/bare-k8s-integration
# Check `ginkgo help run` for command line options. For example to filtering tests.
$(GINKGO) \
WASM_SHIM_SHA256=$$(sha256sum $(WASM_SHIM) | awk '{print $$1}') \
&& $(GINKGO) \
-ldflags "-X github.com/kuadrant/kuadrant-operator/pkg/rlptools/wasm.WasmShimSha256=$${WASM_SHIM_SHA256}" \
--coverpkg $(INTEGRATION_COVER_PKGS) \
--output-dir $(PROJECT_PATH)/coverage/bare-k8s-integration \
--coverprofile cover.out \
-tags integration \
$(INTEGRATION_TESTS_EXTRA_ARGS) ./tests/bare_k8s/...

.PHONY: test-gatewayapi-env-integration
test-gatewayapi-env-integration: clean-cov generate fmt vet ginkgo ## Requires kubernetes cluster with GatewayAPI installed.
test-gatewayapi-env-integration: $(WASM_SHIM) clean-cov generate fmt vet ginkgo ## Requires kubernetes cluster with GatewayAPI installed.
mkdir -p $(PROJECT_PATH)/coverage/gatewayapi-integration
# Check `ginkgo help run` for command line options. For example to filtering tests.
$(GINKGO) \
WASM_SHIM_SHA256=$$(sha256sum $(WASM_SHIM) | awk '{print $$1}') \
&& $(GINKGO) \
-ldflags "-X github.com/kuadrant/kuadrant-operator/pkg/rlptools/wasm.WasmShimSha256=$${WASM_SHIM_SHA256}" \
--coverpkg $(INTEGRATION_COVER_PKGS) \
--output-dir $(PROJECT_PATH)/coverage/gatewayapi-integration \
--coverprofile cover.out \
-tags integration \
$(INTEGRATION_TESTS_EXTRA_ARGS) ./tests/gatewayapi/...

.PHONY: test-istio-env-integration
test-istio-env-integration: clean-cov generate fmt vet ginkgo ## Requires kubernetes cluster with GatewayAPI and Istio installed.
test-istio-env-integration: $(WASM_SHIM) clean-cov generate fmt vet ginkgo ## Requires kubernetes cluster with GatewayAPI and Istio installed.
mkdir -p $(PROJECT_PATH)/coverage/istio-integration
# Check `ginkgo help run` for command line options. For example to filtering tests.
$(GINKGO) \
WASM_SHIM_SHA256=$$(sha256sum $(WASM_SHIM) | awk '{print $$1}') \
&& $(GINKGO) \
-ldflags "-X github.com/kuadrant/kuadrant-operator/pkg/rlptools/wasm.WasmShimSha256=$${WASM_SHIM_SHA256}" \
--coverpkg $(INTEGRATION_COVER_PKGS) \
--output-dir $(PROJECT_PATH)/coverage/istio-integration \
--coverprofile cover.out \
-tags integration \
$(INTEGRATION_TESTS_EXTRA_ARGS) tests/istio/...

.PHONY: test-integration
test-integration: clean-cov generate fmt vet ginkgo ## Requires kubernetes cluster with at least one GatewayAPI provider installed.
test-integration: $(WASM_SHIM) clean-cov generate fmt vet ginkgo ## Requires kubernetes cluster with at least one GatewayAPI provider installed.
mkdir -p $(PROJECT_PATH)/coverage/integration
# Check `ginkgo help run` for command line options. For example to filtering tests.
$(GINKGO) \
WASM_SHIM_SHA256=$$(sha256sum $(WASM_SHIM) | awk '{print $$1}') \
&& $(GINKGO) \
-ldflags "-X github.com/kuadrant/kuadrant-operator/pkg/rlptools/wasm.WasmShimSha256=$${WASM_SHIM_SHA256}" \
--coverpkg $(INTEGRATION_COVER_PKGS) \
--output-dir $(PROJECT_PATH)/coverage/integration \
--coverprofile cover.out \
Expand Down
17 changes: 0 additions & 17 deletions make/wasm-shim.mk

This file was deleted.

8 changes: 4 additions & 4 deletions pkg/rlptools/wasm/server_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package wasm
import "k8s.io/utils/env"

const (
SERVER_SERVICE_NAME = "kuadrant-operator-controller-manager-ratelimit-wasm-service"
ServerSvcName = "kuadrant-operator-controller-manager-ratelimit-wasm-service"
)

var (
WASM_SHIM_SHA256 = "not injected"
WasmShimSha256 = "not injected"
)

func ServerServiceName() string {
return SERVER_SERVICE_NAME
return ServerSvcName
}

func ServerServicePort() int {
Expand All @@ -23,5 +23,5 @@ func ServerServiceNamespace() string {
}

func SHA256() string {
return WASM_SHIM_SHA256
return WasmShimSha256
}

0 comments on commit 30d5197

Please sign in to comment.