Skip to content

Commit

Permalink
feat:support inject java agent to user pod (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Jan 23, 2024
1 parent 4485468 commit 9d7e5dc
Show file tree
Hide file tree
Showing 19 changed files with 1,603 additions and 294 deletions.
17 changes: 11 additions & 6 deletions cmd/polaris-controller/app/polaris-controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ import (
"github.com/polarismesh/polaris-controller/pkg/util"
utilflag "github.com/polarismesh/polaris-controller/pkg/util/flag"
"github.com/polarismesh/polaris-controller/pkg/version"

_ "github.com/polarismesh/polaris-controller/pkg/inject/pkg/kube/inject/apply/javaagent"
_ "github.com/polarismesh/polaris-controller/pkg/inject/pkg/kube/inject/apply/mesh"
)

const (
Expand All @@ -62,12 +65,13 @@ const (
DefaultLockObjectName = "polaris-controller"
DefaultLeaderElectionName = "polaris-controller"

MeshConfigFile = "/etc/polaris-inject/inject/mesh-config"
DnsConfigFile = "/etc/polaris-inject/inject/dns-config"
ValuesFile = "/etc/polaris-inject/inject/values"
MeshFile = "/etc/polaris-inject/config/mesh"
CertFile = "/etc/polaris-inject/certs/cert.pem"
KeyFile = "/etc/polaris-inject/certs/key.pem"
MeshConfigFile = "/etc/polaris-inject/inject/mesh-config"
DnsConfigFile = "/etc/polaris-inject/inject/dns-config"
JavaAgentConfigFile = "/etc/polaris-inject/inject/java-agent-config"
ValuesFile = "/etc/polaris-inject/inject/values"
MeshFile = "/etc/polaris-inject/config/mesh"
CertFile = "/etc/polaris-inject/certs/cert.pem"
KeyFile = "/etc/polaris-inject/certs/key.pem"
)

var (
Expand Down Expand Up @@ -248,6 +252,7 @@ func initPolarisSidecarInjector(c *options.CompletedConfig) error {
DefaultSidecarMode: util.ParseSidecarMode(c.ComponentConfig.PolarisController.SidecarMode),
MeshConfigFile: MeshConfigFile,
DnsConfigFile: DnsConfigFile,
JavaAgentConfigFile: JavaAgentConfigFile,
ValuesFile: ValuesFile,
MeshFile: MeshFile,
CertFile: CertFile,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: plugin-default.properties
namespace: polaris-system
labels:
app: sidecar-injector
data:
springcloud2020-default-properties: |+
# 应用名称
spring.application.name={{ .MicroserviceName }}
# 配置北极星服务端地址
spring.cloud.polaris.address=grpc\://{{ .PolarisServerIP }}\:{{ .PolarisDiscoverPort }}
spring.cloud.polaris.enabled=true
# 启用 Java Agent 的 Spring Cloud Tencent 注册发现能力
spring.cloud.discovery.enabled=true
# 配置服务注册发现的命名空间信息
spring.cloud.polaris.discovery.namespace=default
# 启用从北极星
spring.cloud.polaris.discovery.enabled=true
spring.cloud.polaris.discovery.register=true
## 是否启用北极星的 LoadBalancer
spring.cloud.polaris.loadbalancer.enabled=true
#spring.cloud.polaris.loadbalancer.discoveryType=POLARIS
#spring.cloud.polaris.loadbalancer.strategy=random
## 是否启用北极星服务路由能力
spring.cloud.polaris.router.enabled=false
# 是否启用北极星的自定义路由能力
spring.cloud.polaris.router.rule-router.enabled=false
# 是否启用北极星的元数据路由能力
spring.cloud.polaris.router.metadata-router.enabled=false
# 是否启用北极星的就近路由能力
spring.cloud.polaris.router.nearby-router.enabled=false
## 是否启用北极星的服务限流能力
spring.cloud.polaris.ratelimit.enabled=false
# 设置触发限流时的提示信息
# spring.cloud.polaris.ratelimit.rejectRequestTips=""
# 设置触发限流时的响应码
spring.cloud.polaris.ratelimit.rejectHttpCode=429
# 设置限流匀速排队最大排队时间
spring.cloud.polaris.ratelimit.maxQueuingTime=1000
## RPC 调用增强
spring.cloud.tencent.rpc-enhancement.enabled=false
# 开启 RPC 调用结果上报
spring.cloud.tencent.rpc-enhancement.reporter.enabled=false
# 配置北极星监控指标上报
spring.cloud.polaris.stat.enabled=false
# 指标上报监听端口
spring.cloud.polaris.stat.port=0
# 指标上报暴露的 http path
spring.cloud.polaris.stat.path=/metrics
springcloud2021-default-properties: |+
# 应用名称
spring.application.name={{ .MicroserviceName }}
# 配置北极星服务端地址
spring.cloud.polaris.address=grpc\://{{ .PolarisServerIP }}\:{{ .PolarisDiscoverPort }}
spring.cloud.polaris.enabled=true
# 启用 Java Agent 的 Spring Cloud Tencent 注册发现能力
spring.cloud.discovery.enabled=true
# 配置服务注册发现的命名空间信息
spring.cloud.polaris.discovery.namespace=default
# 启用从北极星
spring.cloud.polaris.discovery.enabled=true
spring.cloud.polaris.discovery.register=true
## 是否启用北极星的 LoadBalancer
spring.cloud.polaris.loadbalancer.enabled=true
#spring.cloud.polaris.loadbalancer.discoveryType=POLARIS
#spring.cloud.polaris.loadbalancer.strategy=random
## 是否启用北极星服务路由能力
spring.cloud.polaris.router.enabled=false
# 是否启用北极星的自定义路由能力
spring.cloud.polaris.router.rule-router.enabled=false
# 是否启用北极星的元数据路由能力
spring.cloud.polaris.router.metadata-router.enabled=false
# 是否启用北极星的就近路由能力
spring.cloud.polaris.router.nearby-router.enabled=false
## 是否启用北极星的服务限流能力
spring.cloud.polaris.ratelimit.enabled=false
# 设置触发限流时的提示信息
# spring.cloud.polaris.ratelimit.rejectRequestTips=""
# 设置触发限流时的响应码
spring.cloud.polaris.ratelimit.rejectHttpCode=429
# 设置限流匀速排队最大排队时间
spring.cloud.polaris.ratelimit.maxQueuingTime=1000
## RPC 调用增强
spring.cloud.tencent.rpc-enhancement.enabled=false
# 开启 RPC 调用结果上报
spring.cloud.tencent.rpc-enhancement.reporter.enabled=false
# 配置北极星监控指标上报
spring.cloud.polaris.stat.enabled=false
# 指标上报监听端口
spring.cloud.polaris.stat.port=0
# 指标上报暴露的 http path
spring.cloud.polaris.stat.path=/metrics
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,51 @@ data:
- name: polaris-log
emptyDir: {}
java-agent-config: |-
policy: enabled
alwaysInjectSelector:
[]
neverInjectSelector:
[]
template: |
initContainers:
- name: polaris-javaagent-init
image: polarismesh/polaris-javaagent-init:#JAVA_AGENT_INIT#
imagePullPolicy: Always
env:
- name: JAVA_AGENT_DIR
value: /app/lib/.polaris/java_agent
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 10m
memory: 10Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- NET_ADMIN
- NET_RAW
drop:
- ALL
privileged: false
readOnlyRootFilesystem: false
runAsGroup: 0
runAsNonRoot: false
runAsUser: 0
volumeMounts:
- mountPath: /app/lib/.polaris/java_agent
name: java-agent-dir
volumes:
- name: java-agent-dir
emptyDir: {}
mesh-config: |-
policy: enabled
alwaysInjectSelector:
Expand Down
43 changes: 43 additions & 0 deletions deploy/kubernetes_v1.21/kubernetes/injector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,49 @@ data:
- name: polaris-log
emptyDir: {}
java-agent-config: |-
policy: enabled
alwaysInjectSelector:
[]
neverInjectSelector:
[]
template: |
initContainers:
- name: polaris-javaagent-init
image: polarismesh/polaris-javaagent-init:#JAVA_AGENT_INIT#
imagePullPolicy: Always
env:
- name: JAVA_AGENT_DIR
value: /app/lib/.polaris/java_agent
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 10m
memory: 10Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- NET_ADMIN
- NET_RAW
drop:
- ALL
privileged: false
readOnlyRootFilesystem: false
runAsGroup: 0
runAsNonRoot: false
runAsUser: 0
volumeMounts:
- mountPath: /app/lib/.polaris/java_agent
name: java-agent-dir
volumes:
- name: java-agent-dir
emptyDir: {}
mesh-config: |+
policy: enabled
alwaysInjectSelector:
Expand Down
107 changes: 107 additions & 0 deletions deploy/kubernetes_v1.21/kubernetes/javaagent-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: plugin-default.properties
namespace: polaris-system
labels:
app: sidecar-injector
data:
springcloud2020-default-properties: |+
# 应用名称
spring.application.name={{ .MicroserviceName }}
# 配置北极星服务端地址
spring.cloud.polaris.address=grpc\://{{ .PolarisServerIP }}\:{{ .PolarisDiscoverPort }}
spring.cloud.polaris.enabled=true
# 启用 Java Agent 的 Spring Cloud Tencent 注册发现能力
spring.cloud.discovery.enabled=true
# 配置服务注册发现的命名空间信息
spring.cloud.polaris.discovery.namespace=default
# 启用从北极星
spring.cloud.polaris.discovery.enabled=true
spring.cloud.polaris.discovery.register=true
## 是否启用北极星的 LoadBalancer
spring.cloud.polaris.loadbalancer.enabled=true
#spring.cloud.polaris.loadbalancer.discoveryType=POLARIS
#spring.cloud.polaris.loadbalancer.strategy=random
## 是否启用北极星服务路由能力
spring.cloud.polaris.router.enabled=false
# 是否启用北极星的自定义路由能力
spring.cloud.polaris.router.rule-router.enabled=false
# 是否启用北极星的元数据路由能力
spring.cloud.polaris.router.metadata-router.enabled=false
# 是否启用北极星的就近路由能力
spring.cloud.polaris.router.nearby-router.enabled=false
## 是否启用北极星的服务限流能力
spring.cloud.polaris.ratelimit.enabled=false
# 设置触发限流时的提示信息
# spring.cloud.polaris.ratelimit.rejectRequestTips=""
# 设置触发限流时的响应码
spring.cloud.polaris.ratelimit.rejectHttpCode=429
# 设置限流匀速排队最大排队时间
spring.cloud.polaris.ratelimit.maxQueuingTime=1000
## RPC 调用增强
spring.cloud.tencent.rpc-enhancement.enabled=false
# 开启 RPC 调用结果上报
spring.cloud.tencent.rpc-enhancement.reporter.enabled=false
# 配置北极星监控指标上报
spring.cloud.polaris.stat.enabled=false
# 指标上报监听端口
spring.cloud.polaris.stat.port=0
# 指标上报暴露的 http path
spring.cloud.polaris.stat.path=/metrics
springcloud2021-default-properties: |+
# 应用名称
spring.application.name={{ .MicroserviceName }}
# 配置北极星服务端地址
spring.cloud.polaris.address=grpc\://{{ .PolarisServerIP }}\:{{ .PolarisDiscoverPort }}
spring.cloud.polaris.enabled=true
# 启用 Java Agent 的 Spring Cloud Tencent 注册发现能力
spring.cloud.discovery.enabled=true
# 配置服务注册发现的命名空间信息
spring.cloud.polaris.discovery.namespace=default
# 启用从北极星
spring.cloud.polaris.discovery.enabled=true
spring.cloud.polaris.discovery.register=true
## 是否启用北极星的 LoadBalancer
spring.cloud.polaris.loadbalancer.enabled=true
#spring.cloud.polaris.loadbalancer.discoveryType=POLARIS
#spring.cloud.polaris.loadbalancer.strategy=random
## 是否启用北极星服务路由能力
spring.cloud.polaris.router.enabled=false
# 是否启用北极星的自定义路由能力
spring.cloud.polaris.router.rule-router.enabled=false
# 是否启用北极星的元数据路由能力
spring.cloud.polaris.router.metadata-router.enabled=false
# 是否启用北极星的就近路由能力
spring.cloud.polaris.router.nearby-router.enabled=false
## 是否启用北极星的服务限流能力
spring.cloud.polaris.ratelimit.enabled=false
# 设置触发限流时的提示信息
# spring.cloud.polaris.ratelimit.rejectRequestTips=""
# 设置触发限流时的响应码
spring.cloud.polaris.ratelimit.rejectHttpCode=429
# 设置限流匀速排队最大排队时间
spring.cloud.polaris.ratelimit.maxQueuingTime=1000
## RPC 调用增强
spring.cloud.tencent.rpc-enhancement.enabled=false
# 开启 RPC 调用结果上报
spring.cloud.tencent.rpc-enhancement.reporter.enabled=false
# 配置北极星监控指标上报
spring.cloud.polaris.stat.enabled=false
# 指标上报监听端口
spring.cloud.polaris.stat.port=0
# 指标上报暴露的 http path
spring.cloud.polaris.stat.path=/metrics
Loading

0 comments on commit 9d7e5dc

Please sign in to comment.