mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Revert removal of EndpointName hooks (#2319)
* Revert "Remove dead EndpointName code"
This reverts commit 8025da5a8d
.
* Fix docstrings based on proper understanding of use
This commit is contained in:
parent
714227bdc7
commit
8262e23169
@ -6,9 +6,11 @@ package cluster
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rancher/k3s/pkg/cluster/managed"
|
||||
"github.com/rancher/kine/pkg/endpoint"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -62,11 +64,21 @@ func (c *Cluster) initClusterDB(ctx context.Context, handler http.Handler) (http
|
||||
return handler, nil
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(c.config.Datastore.Endpoint, c.managedDB.EndpointName()+"://") {
|
||||
c.config.Datastore = endpoint.Config{
|
||||
Endpoint: c.managedDB.EndpointName(),
|
||||
}
|
||||
}
|
||||
|
||||
return c.managedDB.Register(ctx, c.config, handler)
|
||||
}
|
||||
|
||||
// assignManagedDriver checks to see if any managed databases are already configured or should be created/joined.
|
||||
// If a driver has been initialized it is used, otherwise we create or join a cluster using the default driver.
|
||||
// assignManagedDriver assigns a driver based on a number of different configuration variables.
|
||||
// If a driver has been initialized it is used.
|
||||
// If the configured endpoint matches the name of a driver, that driver is used.
|
||||
// If no specific endpoint has been requested and creating or joining has been requested,
|
||||
// we use the default driver.
|
||||
// If none of the above are true, no managed driver is assigned.
|
||||
func (c *Cluster) assignManagedDriver(ctx context.Context) error {
|
||||
// Check all managed drivers for an initialized database on disk; use one if found
|
||||
for _, driver := range managed.Registered() {
|
||||
@ -78,6 +90,16 @@ func (c *Cluster) assignManagedDriver(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
// This is needed to allow downstreams to override driver selection logic by
|
||||
// setting ServerConfig.Datastore.Endpoint such that it will match a driver's EndpointName
|
||||
endpointType := strings.SplitN(c.config.Datastore.Endpoint, ":", 2)[0]
|
||||
for _, driver := range managed.Registered() {
|
||||
if endpointType == driver.EndpointName() {
|
||||
c.managedDB = driver
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// If we have been asked to initialize or join a cluster, do so using the default managed database.
|
||||
if c.config.Datastore.Endpoint == "" && (c.config.ClusterInit || (c.config.Token != "" && c.config.JoinURL != "")) {
|
||||
for _, driver := range managed.Registered() {
|
||||
|
Loading…
Reference in New Issue
Block a user