Skip to content

Commit

Permalink
Refactor(webhook): rename HOST and PORT to PISA_PROXY_ADMIN_LISTEN_HO…
Browse files Browse the repository at this point in the history
…ST and PISA_PROXY_ADMIN_LISTEN_PORT respectively (database-mesh#112)

* refactor(config): rename HOST and PORT into PISA_PROXY_ADMIN_LISTEN_HOST and PISA_PROXY_ADMIN_LISTEN_PORT respectively

Signed-off-by: mlycore <[email protected]>

* chore(Makefile): fix coloring build command

Signed-off-by: mlycore <[email protected]>

* refactor(webhook): update envs for pisa proxy host and port

Signed-off-by: mlycore <[email protected]>

* chore(ci): update check-license condition to both push and pull request

Signed-off-by: mlycore <[email protected]>

* chore(ci): update integration test condition to push

Signed-off-by: mlycore <[email protected]>

* fix(webhook): applyPodPatch parameters

Signed-off-by: mlycore <[email protected]>
  • Loading branch information
mlycore committed Jun 27, 2022
1 parent 01956b1 commit 6619875
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-license.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

name: check-license

on: push
on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@

name: integration test

on:
push:
branches:
- master
- ci
- release-v*
on: push


jobs:
run:
Expand Down
4 changes: 2 additions & 2 deletions pisa-controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ build:
-ldflags "-w -s -X main.branch=$(GIT_BRANCH) -X main.gitcommit=$(GIT_COMMIT) -X main.version=$(GIT_TAG)" \
-gcflags "-N -l" \
-o ../bin/controller cmd/pisa-controller/main.go
@echo -e "\033[33mbuild output to ./bin directory\033[0"
@echo -e "\033[33mbuild output to ./bin directory\033[0m"

darwin:
@go build \
-ldflags "-w -s -X main.branch=$(GIT_BRANCH) -X main.gitcommit=$(GIT_COMMIT) -X main.version=$(GIT_TAG)" \
-gcflags "-N -l" \
-o ../bin/controller cmd/pisa-controller/main.go
@echo -e "\033[33mbuild output to ./bin directory\033[0"
@echo -e "\033[33mbuild output to ./bin directory\033[0m"

docker:
sudo docker build --build-arg GIT_BRANCH=$(GIT_BRANCH) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg GIT_TAG=$(GIT_TAG) \
Expand Down
13 changes: 0 additions & 13 deletions pisa-controller/pkg/proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"fmt"
"net/http"
"strconv"

"github.com/database-mesh/pisanix/pisa-controller/pkg/kubernetes"

Expand Down Expand Up @@ -90,18 +89,6 @@ func getConfig(client dynamic.Interface, namespace, appname string) (interface{}
return nil, err
}

vdbmetedata := &metav1.ObjectMeta{}
vdbm, _ := json.Marshal(vdb.Object["metadata"])

_ = json.Unmarshal(vdbm, vdbmetedata)

port, err := strconv.Atoi(vdbmetedata.Annotations["database-mesh.io/metrics-port"])
if port <= 0 || err != nil {
proxyconfig.Admin.Port = 8888
} else {
proxyconfig.Admin.Port = uint32(port)
}

for _, service := range vdbSpec.Services {
ts, err := client.Resource(trafficstrategies).Namespace(namespace).Get(ctx, service.TrafficStrategy, metav1.GetOptions{})
if err != nil {
Expand Down
74 changes: 66 additions & 8 deletions pisa-controller/pkg/webhook/injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"net/http"
"os"
"strconv"
"strings"

"github.com/gin-gonic/gin"
Expand All @@ -30,23 +31,80 @@ import (
"k8s.io/apimachinery/pkg/util/json"
)

var pisanixProxyImage, pisaControllerService, pisaControllerNameSpace string
var (
pisaProxyImage, pisaControllerService, pisaControllerNamespace, pisaProxyAdminListenHost string
pisaProxyAdminListenPort uint32
)

const (
SidecarNamePisaProxy = "pisa-proxy"
SidecarNamePisaProxy = "pisa-proxy"
EnvPisaProxyAdminListenHost = "PISA_PROXY_ADMIN_LISTEN_HOST"
EnvPisaProxyAdminListenPort = "PISA_PROXY_ADMIN_LISTEN_PORT"
DefaultPisaProxyAdminListenHost = "0.0.0.0"
DefaultPisaProxyAdminListenPort = 5590
)

func init() {
pisanixProxyImage = os.Getenv("PISA_PROXY_IMAGE")
if pisanixProxyImage == "" {
pisanixProxyImage = "pisanixio/proxy:latest"
pisaProxyImage = os.Getenv("PISA_PROXY_IMAGE")
if pisaProxyImage == "" {
pisaProxyImage = "pisanixio/proxy:latest"
}
pisaControllerService = os.Getenv("PISA_CONTROLLER_SERVICE")
pisaControllerNameSpace = os.Getenv("PISA_CONTROLLER_NAMESPACE")
pisaControllerNamespace = os.Getenv("PISA_CONTROLLER_NAMESPACE")
if host := os.Getenv(EnvPisaProxyAdminListenHost); host == "" {
pisaProxyAdminListenHost = DefaultPisaProxyAdminListenHost
} else {
pisaProxyAdminListenHost = host
}
if port, err := strconv.Atoi(os.Getenv(EnvPisaProxyAdminListenPort)); port <= 0 || err != nil {
pisaProxyAdminListenPort = DefaultPisaProxyAdminListenPort
} else {
pisaProxyAdminListenPort = uint32(port)
}

}

const (
podsSidecarPatch = `[{"op":"add", "path":"/spec/containers/-","value":{"image":"%v","name":"%s","resources":{},"env": [{"name": "PISA_CONTROLLER_SERVICE","value": "%s"},{"name": "PISA_CONTROLLER_NAMESPACE","value": "%s"},{"name": "PISA_DEPLOYED_NAMESPACE","value": "%s"},{"name": "PISA_DEPLOYED_NAME","value": "%s"}]}}]`
podsSidecarPatch = `[
{
"op":"add",
"path":"/spec/containers/-",
"value":{
"image":"%v",
"name":"%s",
"ports": [
{
"containerPort": %d,
"name": "pisa-admin",
"protocol": "TCP"
}
]
"resources":{},
"env": [
{
"name": "PISA_CONTROLLER_SERVICE",
"value": "%s"
},{
"name": "PISA_CONTROLLER_NAMESPACE",
"value": "%s"
},{
"name": "PISA_DEPLOYED_NAMESPACE",
"value": "%s"
},{
"name": "PISA_DEPLOYED_NAME",
"value": "%s"
},{
"name": "PISA_PROXY_ADMIN_LISTEN_HOST",
"value": "%s"
},{
"name": "PISA_PROXY_ADMIN_LISTEN_PORT",
"value": "%d"
}
]
}
}
]`
)

var (
Expand Down Expand Up @@ -85,7 +143,7 @@ func InjectSidecar(ctx *gin.Context) {
_ = json.Unmarshal(ar.Request.Object.Raw, podinfo)
podSlice := strings.Split(podinfo.Metadata.GenerateName, "-")
podSlice = podSlice[:len(podSlice)-2]
ar.Response = applyPodPatch(ar, shouldPatchPod, fmt.Sprintf(podsSidecarPatch, pisanixProxyImage, SidecarNamePisaProxy, pisaControllerService, pisaControllerNameSpace, ar.Request.Namespace, strings.Join(podSlice, "-")))
ar.Response = applyPodPatch(ar, shouldPatchPod, fmt.Sprintf(podsSidecarPatch, pisaProxyImage, SidecarNamePisaProxy, pisaProxyAdminListenPort, pisaControllerService, pisaControllerNamespace, ar.Request.Namespace, strings.Join(podSlice, "-"), pisaProxyAdminListenHost, pisaProxyAdminListenPort))
log.Info("mutating Success")

ctx.JSON(http.StatusOK, ar)
Expand Down
4 changes: 2 additions & 2 deletions pisa-proxy/app/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const PISA_PROXY_DEFAULT_DEPLOYED_NAMESPACE: &str = "default";
const PISA_PROXY_DEFAULT_CONFIG_PATH: &str = "etc/config.toml";

const PISA_PROXY_CONFIG_ENV_LOCAL_CONFIG: &str = "LOCAL_CONFIG";
const PISA_PROXY_CONFIG_ENV_HOST: &str = "HOST";
const PISA_PROXY_CONFIG_ENV_PORT: &str = "PORT";
const PISA_PROXY_CONFIG_ENV_HOST: &str = "PISA_PROXY_ADMIN_LISTEN_HOST";
const PISA_PROXY_CONFIG_ENV_PORT: &str = "PISA_PROXY_ADMIN_LISTEN_PORT";
const PISA_PROXY_CONFIG_ENV_LOG_LEVEL: &str = "LOG_LEVEL";

const PISA_PROXY_VERSION_ENV_GIT_TAG: &str = "GIT_TAG";
Expand Down

0 comments on commit 6619875

Please sign in to comment.