Skip to content

Commit

Permalink
manager: new namespace manager based on etcd (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Jul 26, 2022
1 parent 2a653c3 commit fe7b92e
Show file tree
Hide file tree
Showing 24 changed files with 213 additions and 569 deletions.
2 changes: 1 addition & 1 deletion cmd/weirproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
return err
}

cfg, err := config.NewProxyConfig(proxyConfigData)
cfg, err := config.NewConfig(proxyConfigData)
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions conf/namespace/test_namespace.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
namespace: "test_namespace"
frontend:
security:
cert: "./ttt"
key: "./ttt"
backend:
instances:
- "127.0.0.1:4000"
selector_type: "random"
security:
cert: "./ttt"
key: "./ttt"
2 changes: 2 additions & 0 deletions pkg/config/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ type Namespace struct {
}

type FrontendNamespace struct {
Security TLSCert `yaml:"security"`
}

type BackendNamespace struct {
Instances []string `yaml:"instances"`
SelectorType string `yaml:"selector_type"`
Security TLSCert `yaml:"security"`
}

func NewNamespaceConfig(data []byte) (*Namespace, error) {
Expand Down
13 changes: 12 additions & 1 deletion pkg/config/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ import (

var testNamespaceConfig = Namespace{
Namespace: "test_ns",
Frontend: FrontendNamespace{},
Frontend: FrontendNamespace{
Security: TLSCert{
CA: "t",
Cert: "t",
Key: "t",
},
},
Backend: BackendNamespace{
Instances: []string{"127.0.0.1:4000", "127.0.0.1:4001"},
SelectorType: "random",
Security: TLSCert{
CA: "t",
Cert: "t",
Key: "t",
},
},
}

Expand Down
27 changes: 17 additions & 10 deletions pkg/config/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,26 @@ type LogFile struct {
MaxBackups int `yaml:"max_backups"`
}

type TLSCert struct {
CA string `toml:"ca" json:"ca"`
Cert string `toml:"cert" json:"cert"`
Key string `toml:"key" json:"key"`
}

func (c TLSCert) HasCert() bool {
return !(c.Cert == "" && c.Key == "")
}

func (c TLSCert) HasCA() bool {
return c.CA != ""
}

type Security struct {
SSLCA string `toml:"ssl-ca" json:"ssl-ca"`
SSLCert string `toml:"ssl-cert" json:"ssl-cert"`
SSLKey string `toml:"ssl-key" json:"ssl-key"`
ClusterSSLCA string `toml:"cluster-ssl-ca" json:"cluster-ssl-ca"`
ClusterSSLCert string `toml:"cluster-ssl-cert" json:"cluster-ssl-cert"`
ClusterSSLKey string `toml:"cluster-ssl-key" json:"cluster-ssl-key"`
ClusterVerifyCN []string `toml:"cluster-verify-cn" json:"cluster-verify-cn"`
MinTLSVersion string `toml:"tls-version" json:"tls-version"`
RSAKeySize int `toml:"rsa-key-size" json:"rsa-key-size"`
Server TLSCert `toml:"server" json:"server"`
Cluster TLSCert `toml:"cluster" json:"cluster"`
}

func NewProxyConfig(data []byte) (*Config, error) {
func NewConfig(data []byte) (*Config, error) {
var cfg Config
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, err
Expand Down
21 changes: 11 additions & 10 deletions pkg/config/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,23 @@ var testProxyConfig = Config{
},
},
Security: Security{
SSLCA: "a",
SSLCert: "b",
SSLKey: "c",
ClusterSSLCA: "d",
ClusterSSLCert: "e",
ClusterSSLKey: "f",
ClusterVerifyCN: []string{},
MinTLSVersion: "g",
RSAKeySize: 0,
Server: TLSCert{
CA: "a",
Cert: "b",
Key: "c",
},
Cluster: TLSCert{
CA: "a",
Cert: "b",
Key: "c",
},
},
}

func TestProxyConfig(t *testing.T) {
data, err := testProxyConfig.ToBytes()
require.NoError(t, err)
cfg, err := NewProxyConfig(data)
cfg, err := NewConfig(data)
require.NoError(t, err)
require.Equal(t, testProxyConfig, *cfg)
}
2 changes: 0 additions & 2 deletions pkg/manager/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ type ConfigManager struct {
kv clientv3.KV
basePath string
cfg config.ConfigManager

// TODO: remove namespace manager based on files
}

func NewConfigManager() *ConfigManager {
Expand Down
62 changes: 0 additions & 62 deletions pkg/manager/namespace/builder.go

This file was deleted.

26 changes: 0 additions & 26 deletions pkg/manager/namespace/domain.go

This file was deleted.

4 changes: 1 addition & 3 deletions pkg/manager/namespace/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

package namespace

import (
"github.com/pingcap/errors"
)
import "github.com/pingcap/TiProxy/pkg/util/errors"

var (
ErrDuplicatedUser = errors.New("duplicated user")
Expand Down
49 changes: 0 additions & 49 deletions pkg/manager/namespace/frontend.go

This file was deleted.

Loading

0 comments on commit fe7b92e

Please sign in to comment.