-
Notifications
You must be signed in to change notification settings - Fork 0
feat: envoy control plane #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
05d7fec
9dd6a59
3462887
0a2711c
0563da7
d952af2
a629493
85b7732
a7390e1
8b8e742
e47c71d
b2e804a
8969b28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/MakeNowJust/heredoc" | ||
| "github.com/goto/shield/config" | ||
| "github.com/goto/shield/internal/proxy/envoy/xds" | ||
| "github.com/goto/shield/internal/store/postgres" | ||
| shieldlogger "github.com/goto/shield/pkg/logger" | ||
| "github.com/spf13/cobra" | ||
| cli "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func ProxyCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "proxy <command>", | ||
| Short: "Proxy management", | ||
| Long: "Server management commands.", | ||
| Example: heredoc.Doc(` | ||
| $ shield proxy envoy-xds start -c ./config.yaml | ||
| `), | ||
| } | ||
|
|
||
| cmd.AddCommand(proxyEnvoyXDSCommand()) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func proxyEnvoyXDSCommand() *cobra.Command { | ||
| c := &cli.Command{ | ||
| Use: "envoy-xds", | ||
| Short: "Envoy Agent xDS management", | ||
| Long: "Envoy Agent xDS management commands.", | ||
| Example: heredoc.Doc(` | ||
| $ shield proxy envoy-xds start | ||
| `), | ||
| } | ||
|
|
||
| c.AddCommand(envoyXDSStartCommand()) | ||
|
|
||
| return c | ||
| } | ||
|
|
||
| func envoyXDSStartCommand() *cobra.Command { | ||
| var configFile string | ||
|
|
||
| c := &cli.Command{ | ||
| Use: "start", | ||
| Short: "Start Envoy Agent xDS server", | ||
| Long: "Start Envoy Agent xDS server commands.", | ||
| Example: "shield proxy envoy-xds start", | ||
| RunE: func(cmd *cli.Command, args []string) error { | ||
| appConfig, err := config.Load(configFile) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| logger := shieldlogger.InitLogger(shieldlogger.Config{Level: appConfig.Log.Level}) | ||
|
|
||
| dbClient, err := setupDB(appConfig.DB, logger) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer func() { | ||
| logger.Info("cleaning up db") | ||
| dbClient.Close() | ||
| }() | ||
|
|
||
| ctx := cmd.Context() | ||
|
|
||
| pgRuleRepository := postgres.NewRuleRepository(dbClient) | ||
| if err := pgRuleRepository.InitCache(ctx); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| cbs, repositories, err := buildXDSDependencies(ctx, logger, appConfig.Proxy, pgRuleRepository) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer func() { | ||
| logger.Info("cleaning up rules proxy blob") | ||
| for _, f := range cbs { | ||
| if err := f(); err != nil { | ||
| logger.Warn("error occurred during shutdown rules proxy blob storages", "err", err) | ||
| } | ||
| } | ||
| }() | ||
|
|
||
| return xds.Serve(ctx, logger, appConfig.Proxy, repositories) | ||
| }, | ||
| } | ||
|
|
||
| c.Flags().StringVarP(&configFile, "config", "c", "", "Config file path") | ||
| return c | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,7 +179,13 @@ func StartServer(logger *log.Zap, cfg *config.Shield) error { | |
| } | ||
|
|
||
| // serving proxies | ||
| cbs, cps, err := serveProxies(ctx, logger, cfg.App.IdentityProxyHeader, cfg.App.UserIDHeader, cfg.Proxy, pgRuleRepository, deps.ResourceService, deps.RelationService, deps.UserService, deps.GroupService, deps.ProjectService, deps.RelationAdapter) | ||
| var cbs []func() error | ||
| var cps []func(context.Context) error | ||
| if cfg.Proxy.EnvoyAgent.XDS.Host != "" && cfg.Proxy.EnvoyAgent.XDS.Port != 0 { | ||
| cbs, err = serveXDS(ctx, logger, cfg.Proxy, pgRuleRepository) | ||
| } else { | ||
|
||
| cbs, cps, err = serveProxies(ctx, logger, cfg.App.IdentityProxyHeader, cfg.App.UserIDHeader, cfg.Proxy, pgRuleRepository, deps.ResourceService, deps.RelationService, deps.UserService, deps.GroupService, deps.ProjectService, deps.RelationAdapter) | ||
| } | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,20 @@ | ||
| package proxy | ||
|
|
||
| import "time" | ||
|
|
||
| type ServicesConfig struct { | ||
| Services []Config `yaml:"services" mapstructure:"services"` | ||
| EnvoyAgent EnvoyAgent `yaml:"envoy" mapstructure:"envoy"` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's update the config in https://github.com/goto/shield/blob/main/config/config.yaml with the example on how to use this envoy agent? |
||
| Services []Config `yaml:"services" mapstructure:"services"` | ||
| } | ||
|
|
||
| type EnvoyAgent struct { | ||
| XDS XDS `yaml:"xds" mapstructure:"xds"` | ||
| } | ||
|
|
||
| type XDS struct { | ||
| Host string `yaml:"host" mapstructure:"host"` | ||
| Port int `yaml:"port" mapstructure:"port"` | ||
| RefreshInterval time.Duration `yaml:"refresh_interval" mapstructure:"refresh_interval" default:"60s"` | ||
| } | ||
|
|
||
| type Config struct { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.