Skip to content
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

manager: new namespace manager based on etcd #13

Merged
merged 3 commits into from
Jul 26, 2022
Merged

manager: new namespace manager based on etcd #13

merged 3 commits into from
Jul 26, 2022

Conversation

xhebox
Copy link
Collaborator

@xhebox xhebox commented Jul 25, 2022

What problem does this PR solve?

Issue Number: ref #11

Problem Summary: A new, simplified namespace manager.

What is changed and how it works: Included in the commit message. Note that:

  1. auto creation of SSL certificates for server is removed for now to simplify PR. It will be added back later. Check util/security/tls.go.
  2. NewProxyConfig => NewConfig
  3. Removed manager/namespace/domain.go. I don't think there is a need of abstraction, if interface will only be implemented by one struct.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Notable changes

  • Has configuration change
  • Has HTTP API interfaces change (Don't forget to add the declarative for API)
  • Has weirctl change
  • Other user behavior changes

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Signed-off-by: xhe <xw897002528@gmail.com>
A completely refactor, or rewritten of the old double buffer management
of namespace. Also a preparetion for later proxy server refactor.

1. no need to prepare the namespace before commit. Now reloading
	namespaces be like:
	1. use HTTP api modify persisted namespace configs on etcd.
	2. commit will pull from etcd, and perform a swap of namespace state
	under the guard of mutex. Etcd serves as "dirty buffer" for the
	in-memory namespace manager. It is acceptable because client will
	connect etcd by local loopback network.
2. remove '/util/datastructure'
3. remove username to namespace mapping because username are removed in
	previous PR.

Signed-off-by: xhe <xw897002528@gmail.com>
Comment on lines -53 to -75
var minTLSVersion uint16 = tls.VersionTLS11
switch minTLSVer {
case "TLSv1.0":
minTLSVersion = tls.VersionTLS10
case "TLSv1.1":
minTLSVersion = tls.VersionTLS11
case "TLSv1.2":
minTLSVersion = tls.VersionTLS12
case "TLSv1.3":
minTLSVersion = tls.VersionTLS13
case "":
default:
logutil.BgLogger().Warn(
"Invalid TLS version, using default instead",
zap.String("tls-version", minTLSVer),
)
}
if minTLSVersion < tls.VersionTLS12 {
logutil.BgLogger().Warn(
"Minimum TLS version allows pre-TLSv1.2 protocols, this is not recommended",
)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaults to TLS12

@@ -90,28 +62,10 @@ func CreateServerTLSConfig(ca, key, cert, minTLSVer, path string, rsaKeySize int
}
}

// This excludes ciphers listed in tls.InsecureCipherSuites() and can be used to filter out more
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked source code, it is useless. CipherSuites() is secure and does not include suites from InsecureCipherSuites().

@@ -155,7 +155,7 @@ func NewServer(ctx context.Context, cfg *config.Config, logger *zap.Logger, name
return
}

err = srv.NamespaceManager.Init(nss, srv.ObserverClient)
err = srv.NamespaceManager.Init(logger.Named("nsmgr"), nss, srv.ObserverClient)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Namespaced logger.

@xhebox xhebox requested a review from djshow832 July 25, 2022 07:56
@xhebox xhebox mentioned this pull request Jul 25, 2022
5 tasks
Comment on lines -113 to -118
func (n *NamespaceWrapper) mustGetCurrentNamespace() Namespace {
ns, ok := n.nsmgr.getCurrentNamespaces().Get(n.name)
if !ok {
panic(errors.New("namespace not found"))
}
return ns
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is removed. We don't need to get namespace under nsmgr mutex everytime for latest namespace config.

The old connection is hard to follow new config anyway. For connection states that possibly will be attached to namespace dynamically, we could execute in-place reload:

ns := NewNamespaceFromConfig()
oldNS.Reload(ns)

oldNS could have an rwmutex, it will refresh config and take care of all old connection states. Thus reimplementing interface by a wrapper is not necessary.

Comment on lines +3 to +5
security:
cert: "./ttt"
key: "./ttt"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's its purpose? The cert to connect to the client?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, one for frontend, one for backend. And we can set the default cert or whatever in the global config.

pkg/manager/namespace/namespace.go Outdated Show resolved Hide resolved
pkg/manager/namespace/namespace.go Outdated Show resolved Hide resolved
Signed-off-by: xhe <xw897002528@gmail.com>
@xhebox xhebox requested a review from djshow832 July 26, 2022 02:51
@djshow832 djshow832 merged commit fe7b92e into pingcap:main Jul 26, 2022
@xhebox xhebox deleted the namespace branch July 26, 2022 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants