From 88698784f131b9e974f7499fe69f3722c741af9b Mon Sep 17 00:00:00 2001 From: Terance Edmonds Date: Fri, 22 Nov 2024 10:00:10 +0530 Subject: [PATCH 1/3] Fix APK Adapter Fails to Build on Windows --- adapter/Dockerfile | 16 +++++++++----- adapter/README.md | 20 ++++++++++------- adapter/build.gradle | 8 ++++++- adapter/go.mod | 2 +- .../gateway-api/envoy/shutdown_manager.go | 6 ++--- common-gradle-scripts/go.gradle | 22 +++++++++++++++++-- .../{.bazelversion => .bazelversion} | 0 helm-charts/values.yaml | 4 ++-- 8 files changed, 55 insertions(+), 23 deletions(-) rename gateway/router/envoy-filters/mgw-source/filters/http/mgw-wasm-websocket/{.bazelversion => .bazelversion} (100%) diff --git a/adapter/Dockerfile b/adapter/Dockerfile index 7a54e505ad..e6e2af306c 100644 --- a/adapter/Dockerfile +++ b/adapter/Dockerfile @@ -33,11 +33,11 @@ ARG GRPC_HEALTH_PROBE_PATH=/bin/grpc_health_probe ARG TARGETARCH ARG MOTD="\n\ - Welcome to WSO2 Docker Resources \n\ - --------------------------------- \n\ - This Docker container comprises of a WSO2 product, running with its latest GA release \n\ - which is under the Apache License, Version 2.0. \n\ - Read more about Apache License, Version 2.0 here @ http://www.apache.org/licenses/LICENSE-2.0.\n" + Welcome to WSO2 Docker Resources \n\ + --------------------------------- \n\ + This Docker container comprises of a WSO2 product, running with its latest GA release \n\ + which is under the Apache License, Version 2.0. \n\ + Read more about Apache License, Version 2.0 here @ http://www.apache.org/licenses/LICENSE-2.0.\n" RUN \ addgroup -S -g ${APK_USER_GROUP_ID} ${APK_USER_GROUP} \ @@ -50,7 +50,7 @@ RUN \ wget -q https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.34/grpc_health_probe-linux-${TARGETARCH} \ && mv grpc_health_probe-linux-${TARGETARCH} ${GRPC_HEALTH_PROBE_PATH} \ && if [ "${TARGETARCH}" = "amd64" ]; then echo "${CHECKSUM_AMD64} ${GRPC_HEALTH_PROBE_PATH}" | sha256sum -c -; fi - + RUN \ chmod +x ${GRPC_HEALTH_PROBE_PATH} \ && chown ${APK_USER}:${APK_USER_GROUP} ${GRPC_HEALTH_PROBE_PATH} \ @@ -61,7 +61,11 @@ WORKDIR ${APK_USER_HOME} USER ${APK_USER_ID} COPY resources/conf/config.toml conf/ + COPY resources/check_health.sh . +# Remove the Windows line endings (carriage returns) +RUN sed -i 's/\r//' check_health.sh + COPY resources/conf/log_config.toml conf/ COPY ./${TARGETARCH}/main adapter diff --git a/adapter/README.md b/adapter/README.md index d859184e2b..b0075b1425 100644 --- a/adapter/README.md +++ b/adapter/README.md @@ -9,7 +9,7 @@ The following should be installed in your dev machine. - [Gradle](https://gradle.org/install/) >= 7.5.1 version - [Docker](https://docs.docker.com/engine/install/ubuntu/) >= 17.03 version - [Golang](https://go.dev/doc/install) >= 1.23 version -- [Revive](https://github.com/mgechev/revive#installation) latest version +- [Revive](https://github.com/mgechev/revive#installation) = 1.3.4 version - [Kubebuilder](https://book.kubebuilder.io/quick-start.html#installation) ## Setting up @@ -39,18 +39,22 @@ Code for the operator lies in `{PROJECT_HOME}/adapter/internal/operator`. This w Following are some tasks with the steps that a developer might do in operator development: -- [Adding a new Kind](#adding-a-new-kind) -- [Adding a new property to an existing Kind](#adding-a-new-property-to-an-existing-kind) -- [Adding validating and defaulting logic](#adding-validating-and-defaulting-logic) +- [WSO2 APK - Adapter](#wso2-apk---adapter) + - [Prerequisites](#prerequisites) + - [Setting up](#setting-up) + - [Operator](#operator) + - [Adding a new Kind](#adding-a-new-kind) + - [Adding a new property to an existing Kind](#adding-a-new-property-to-an-existing-kind) + - [Adding validating and defaulting logic](#adding-validating-and-defaulting-logic) ### Adding a new Kind 1. Decide what the k8s resource group will be depending on whether the CRD is for the control-plane or for the data-plane. - | Plane | k8s group | - | ------------- | ------------- | - | Data Plane | dp | - | Control Plane | cp | + | Plane | k8s group | + | ------------- | --------- | + | Data Plane | dp | + | Control Plane | cp | 2. Decide the version for the CRD. Current version for all the CRDs are used as `v1alpha1`. diff --git a/adapter/build.gradle b/adapter/build.gradle index e3b674c40f..2a15244295 100644 --- a/adapter/build.gradle +++ b/adapter/build.gradle @@ -59,7 +59,13 @@ tasks.register('go_test', Exec) { environment "APK_test_test_uint32array", "100" environment "APK_test_test_uint64array", "42949672959" environment "APK_test_test_uintarray2", "-50" - commandLine 'sh', '-c', "go test -race -coverprofile=coverage.out -covermode=atomic ./..." + + def osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH) + if (osName.contains("windows")) { + commandLine 'cmd', '/c', 'set', 'CGO_ENABLED=1', "go test -race -coverprofile=coverage.out -covermode=atomic ./..." + } else { + commandLine 'sh', '-c', "go test -race -coverprofile=coverage.out -covermode=atomic ./..." + } } tasks.named('go_revive_run').configure { diff --git a/adapter/go.mod b/adapter/go.mod index c2a095c622..1c44139756 100644 --- a/adapter/go.mod +++ b/adapter/go.mod @@ -82,6 +82,7 @@ require ( go.uber.org/zap v1.26.0 // indirect golang.org/x/net v0.30.0 // indirect golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/sys v0.26.0 // indirect golang.org/x/term v0.25.0 // indirect golang.org/x/text v0.19.0 // indirect golang.org/x/time v0.5.0 // indirect @@ -105,7 +106,6 @@ replace github.com/wso2/apk/common-go-libs => ../common-go-libs require ( github.com/ghodss/yaml v1.0.0 github.com/stretchr/testify v1.9.0 - golang.org/x/sys v0.26.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 sigs.k8s.io/gateway-api v1.2.0 ) diff --git a/adapter/internal/operator/gateway-api/envoy/shutdown_manager.go b/adapter/internal/operator/gateway-api/envoy/shutdown_manager.go index 94dc8b8c37..d519a5363c 100644 --- a/adapter/internal/operator/gateway-api/envoy/shutdown_manager.go +++ b/adapter/internal/operator/gateway-api/envoy/shutdown_manager.go @@ -30,11 +30,10 @@ import ( "net/http" "os" "os/signal" + "strconv" "syscall" "time" - "golang.org/x/sys/unix" - "github.com/wso2/apk/adapter/internal/loggers" "github.com/wso2/apk/adapter/internal/operator/gateway-api/bootstrap" ) @@ -76,7 +75,8 @@ func ShutdownManager(readyTimeout time.Duration) error { signal.Notify(s, os.Interrupt, syscall.SIGTERM) r := <-s - loggers.LoggerAPKOperator.Info(fmt.Sprintf("received %s", unix.SignalName(r.(syscall.Signal)))) + // loggers.LoggerAPKOperator.Info(fmt.Sprintf("received %s", unix.SignalName(r.(syscall.Signal)))) + loggers.LoggerAPKOperator.Info(fmt.Sprintf("received %s", strconv.Itoa(int(r.(syscall.Signal))))) // Shutdown HTTP server without interrupting active connections if err := srv.Shutdown(context.Background()); err != nil { diff --git a/common-gradle-scripts/go.gradle b/common-gradle-scripts/go.gradle index 8d4347f1e9..5155bee835 100644 --- a/common-gradle-scripts/go.gradle +++ b/common-gradle-scripts/go.gradle @@ -45,8 +45,13 @@ tasks.register('go_tidy', Exec) { tasks.register('go_build') { group 'go' description 'Compiles the packages named by the import paths, along with their dependencies. AMD64 Archtecture' - dependsOn go_mac_os_build - dependsOn go_linux_build + + if(osName.contains("windows")) { + dependsOn go_windows_build + } else { + dependsOn go_mac_os_build + dependsOn go_linux_build + } } tasks.register('go_mac_os_build', Exec) { group 'go' @@ -67,3 +72,16 @@ tasks.register('go_linux_build', Exec) { throw new StopExecutionException('Missing "file" property') } } +tasks.register('go_windows_build', Exec) { + group 'go' + description 'Compiles the packages named by the import paths, along with their dependencies. AMD64 Archtecture' + if (project.hasProperty('file')) { + environment 'GOOS', 'linux' + environment 'GOARCH', 'amd64' + environment 'CGO_ENABLED', '0' + + commandLine 'go', 'build', '-o', 'amd64/main', file + } else { + throw new StopExecutionException('Missing "file" property') + } +} \ No newline at end of file diff --git a/gateway/router/envoy-filters/mgw-source/filters/http/mgw-wasm-websocket/.bazelversion b/gateway/router/envoy-filters/mgw-source/filters/http/mgw-wasm-websocket/.bazelversion similarity index 100% rename from gateway/router/envoy-filters/mgw-source/filters/http/mgw-wasm-websocket/.bazelversion rename to gateway/router/envoy-filters/mgw-source/filters/http/mgw-wasm-websocket/.bazelversion diff --git a/helm-charts/values.yaml b/helm-charts/values.yaml index 93d57b2da1..c90859747d 100644 --- a/helm-charts/values.yaml +++ b/helm-charts/values.yaml @@ -122,8 +122,8 @@ wso2: failureThreshold: 5 strategy: RollingUpdate replicas: 1 - imagePullPolicy: Always - image: wso2/apk-adapter:1.2.0 + imagePullPolicy: IfNotPresent + image: apk-adapter:1.2.0-SNAPSHOT security: sslHostname: "adapter" logging: From d6bdd6062af5b2162203047c50c4b1f04fef7a3c Mon Sep 17 00:00:00 2001 From: Terance Edmonds Date: Fri, 22 Nov 2024 12:18:19 +0530 Subject: [PATCH 2/3] Update helm chart to 1.2.0 GA release --- helm-charts/values.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helm-charts/values.yaml b/helm-charts/values.yaml index c90859747d..93d57b2da1 100644 --- a/helm-charts/values.yaml +++ b/helm-charts/values.yaml @@ -122,8 +122,8 @@ wso2: failureThreshold: 5 strategy: RollingUpdate replicas: 1 - imagePullPolicy: IfNotPresent - image: apk-adapter:1.2.0-SNAPSHOT + imagePullPolicy: Always + image: wso2/apk-adapter:1.2.0 security: sslHostname: "adapter" logging: From f8601ec6e3a63d256f640553652b986ac0bbf304 Mon Sep 17 00:00:00 2001 From: Terance Edmonds Date: Fri, 22 Nov 2024 15:38:44 +0530 Subject: [PATCH 3/3] Fix APK Common Controller Fails to Build on Windows --- common-controller/Dockerfile | 16 ++++++++++------ common-controller/build.gradle | 8 +++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/common-controller/Dockerfile b/common-controller/Dockerfile index 575d2ce9e6..2e3c882e1f 100644 --- a/common-controller/Dockerfile +++ b/common-controller/Dockerfile @@ -36,11 +36,11 @@ ENV COMMON_CONTROLLER_PRIVATE_KEY_PATH=/home/wso2/security/keystore/mg.key ENV COMMON_CONTROLLER_PUBLIC_CERT_PATH=/home/wso2/security/keystore/mg.pem ARG MOTD="\n\ - Welcome to WSO2 Docker Resources \n\ - --------------------------------- \n\ - This Docker container comprises of a WSO2 product, running with its latest GA release \n\ - which is under the Apache License, Version 2.0. \n\ - Read more about Apache License, Version 2.0 here @ http://www.apache.org/licenses/LICENSE-2.0.\n" + Welcome to WSO2 Docker Resources \n\ + --------------------------------- \n\ + This Docker container comprises of a WSO2 product, running with its latest GA release \n\ + which is under the Apache License, Version 2.0. \n\ + Read more about Apache License, Version 2.0 here @ http://www.apache.org/licenses/LICENSE-2.0.\n" RUN \ addgroup -S -g ${APK_USER_GROUP_ID} ${APK_USER_GROUP} \ @@ -53,7 +53,7 @@ RUN \ wget -q https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.34/grpc_health_probe-linux-${TARGETARCH} \ && mv grpc_health_probe-linux-${TARGETARCH} ${GRPC_HEALTH_PROBE_PATH} \ && if [ "${TARGETARCH}" = "amd64" ]; then echo "${CHECKSUM_AMD64} ${GRPC_HEALTH_PROBE_PATH}" | sha256sum -c -; fi - + RUN \ chmod +x ${GRPC_HEALTH_PROBE_PATH} \ && chown ${APK_USER}:${APK_USER_GROUP} ${GRPC_HEALTH_PROBE_PATH} @@ -64,7 +64,11 @@ USER ${APK_USER_ID} COPY resources/security security COPY resources/conf/config.toml conf/ + COPY resources/check_health.sh . +# Remove the Windows line endings (carriage returns) +RUN sed -i 's/\r//' check_health.sh + COPY resources/conf/log_config.toml conf/ COPY ./${TARGETARCH}/main common-controller diff --git a/common-controller/build.gradle b/common-controller/build.gradle index 7982534fc1..358c04d939 100644 --- a/common-controller/build.gradle +++ b/common-controller/build.gradle @@ -60,7 +60,13 @@ tasks.register('go_test', Exec) { environment "APK_test_test_uint32array", "100" environment "APK_test_test_uint64array", "42949672959" environment "APK_test_test_uintarray2", "-50" - commandLine 'sh', '-c', "go test -race -coverprofile=coverage.out -covermode=atomic ./..." + + def osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH) + if (osName.contains("windows")) { + commandLine 'cmd', '/c', 'set', 'CGO_ENABLED=1', "go test -race -coverprofile=coverage.out -covermode=atomic ./..." + } else { + commandLine 'sh', '-c', "go test -race -coverprofile=coverage.out -covermode=atomic ./..." + } } tasks.named('go_revive_run').configure {