Skip to content

Commit ec34480

Browse files
authored
[agent] add sail-agent proxy logic (#791)
1 parent 7c0a581 commit ec34480

File tree

41 files changed

+2902
-64
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2902
-64
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ require (
4040
github.com/golang/protobuf v1.5.4
4141
github.com/google/go-cmp v0.7.0
4242
github.com/google/go-containerregistry v0.20.6
43+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2
4344
github.com/hashicorp/go-multierror v1.1.1
4445
github.com/heroku/color v0.0.6
4546
github.com/moby/term v0.5.2
@@ -53,6 +54,7 @@ require (
5354
golang.org/x/crypto v0.41.0
5455
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6
5556
golang.org/x/net v0.43.0
57+
golang.org/x/sys v0.35.0
5658
golang.org/x/term v0.34.0
5759
google.golang.org/grpc v1.74.2
5860
google.golang.org/protobuf v1.36.7
@@ -230,7 +232,6 @@ require (
230232
golang.org/x/mod v0.27.0 // indirect
231233
golang.org/x/oauth2 v0.30.0 // indirect
232234
golang.org/x/sync v0.16.0 // indirect
233-
golang.org/x/sys v0.35.0 // indirect
234235
golang.org/x/text v0.28.0 // indirect
235236
golang.org/x/time v0.12.0 // indirect
236237
google.golang.org/genproto/googleapis/api v0.0.0-20250811230008-5f3141c8851a // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
373373
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
374374
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA=
375375
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
376+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2 h1:sGm2vDRFUrQJO/Veii4h4zG2vvqG6uWNkBHSTqXOZk0=
377+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2/go.mod h1:wd1YpapPLivG6nQgbf7ZkG1hhSOXDhhn4MLTknx2aAc=
376378
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
377379
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
378380
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# inject grpc template

pkg/bootstrap/config.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package bootstrap
2+
3+
import (
4+
"fmt"
5+
"github.com/apache/dubbo-kubernetes/pkg/config/constants"
6+
"os"
7+
"strconv"
8+
"strings"
9+
)
10+
11+
type MetadataOptions struct {
12+
}
13+
14+
func ReadPodAnnotations(path string) (map[string]string, error) {
15+
if path == "" {
16+
path = constants.PodInfoAnnotationsPath
17+
}
18+
b, err := os.ReadFile(path)
19+
if err != nil {
20+
return nil, err
21+
}
22+
return ParseDownwardAPI(string(b))
23+
}
24+
25+
func ParseDownwardAPI(i string) (map[string]string, error) {
26+
res := map[string]string{}
27+
for _, line := range strings.Split(i, "\n") {
28+
sl := strings.SplitN(line, "=", 2)
29+
if len(sl) != 2 {
30+
continue
31+
}
32+
key := sl[0]
33+
// Strip the leading/trailing quotes
34+
val, err := strconv.Unquote(sl[1])
35+
if err != nil {
36+
return nil, fmt.Errorf("failed to unquote %v: %v", sl[1], err)
37+
}
38+
res[key] = val
39+
}
40+
return res, nil
41+
}
42+
43+
func GetNodeMetaData(options MetadataOptions) error {
44+
return nil
45+
}

pkg/cmd/cmd.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
package cmd
1919

2020
import (
21+
"context"
2122
"flag"
2223
"fmt"
2324
"github.com/spf13/cobra"
2425
"github.com/spf13/pflag"
26+
"os"
27+
"os/signal"
28+
"syscall"
2529
)
2630

2731
func AddFlags(rootCmd *cobra.Command) {
@@ -33,3 +37,10 @@ func PrintFlags(flags *pflag.FlagSet) {
3337
fmt.Printf("FLAG: --%s=%q\n", flag.Name, flag.Value)
3438
})
3539
}
40+
41+
func WaitSignalFunc(cancel context.CancelCauseFunc) {
42+
sigs := make(chan os.Signal, 1)
43+
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
44+
sig := <-sigs
45+
cancel(fmt.Errorf("received signal: %v", sig.String()))
46+
}

pkg/config/constants/constants.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ package constants
2020
const (
2121
DubboSystemNamespace = "dubbo-system"
2222
DefaultClusterLocalDomain = "cluster.local"
23+
KeyFilename = "key.pem"
24+
CertChainFilename = "cert-chain.pem"
2325
DefaultClusterName = "Kubernetes"
2426
ServiceClusterName = "dubbo-proxy"
2527
ConfigPathDir = "./etc/dubbo/proxy"
@@ -28,4 +30,10 @@ const (
2830
CertProviderKubernetesSignerPrefix = "k8s.io/"
2931

3032
CACertNamespaceConfigMapDataName = "root-cert.pem"
33+
34+
PodInfoAnnotationsPath = "./etc/dubbo/pod/annotations"
35+
CertProviderNone = "none"
36+
CertProviderCustom = "custom"
37+
38+
ThirdPartyJwtPath = "./var/run/secrets/tokens/dubbo-token"
3139
)

pkg/config/mesh/mesh.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ func DefaultProxyConfig() *meshconfig.ProxyConfig {
4848
TerminationDrainDuration: durationpb.New(5 * time.Second),
4949
ProxyAdminPort: 15000,
5050
// TODO authpolicy
51-
DiscoveryAddress: "dubbod.dubbo-system.svc:15012",
52-
StatNameLength: 189,
53-
StatusPort: 15020,
51+
DiscoveryAddress: "dubbod.dubbo-system.svc:15012",
52+
ControlPlaneAuthPolicy: meshconfig.AuthenticationPolicy_MUTUAL_TLS,
53+
StatNameLength: 189,
54+
StatusPort: 15020,
5455
}
5556
}
5657

@@ -125,6 +126,16 @@ func ApplyMeshConfig(yaml string, defaultConfig *meshconfig.MeshConfig) (*meshco
125126
return defaultConfig, nil
126127
}
127128

129+
func ApplyProxyConfig(yaml string, meshConfig *meshconfig.MeshConfig) (*meshconfig.MeshConfig, error) {
130+
mc := protomarshal.Clone(meshConfig)
131+
pc, err := MergeProxyConfig(yaml, mc.DefaultConfig)
132+
if err != nil {
133+
return nil, err
134+
}
135+
mc.DefaultConfig = pc
136+
return mc, nil
137+
}
138+
128139
// EmptyMeshNetworks configuration with no networks
129140
func EmptyMeshNetworks() meshconfig.MeshNetworks {
130141
return meshconfig.MeshNetworks{

0 commit comments

Comments
 (0)