Remove unnecessary copies of etcdconfig struct

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/5032/head
Brad Davidson 2022-02-25 09:26:13 -08:00 committed by Brad Davidson
parent 2989b8b2c5
commit a1b800f0bf
7 changed files with 11 additions and 20 deletions

View File

@ -386,7 +386,7 @@ func (c *Cluster) ReconcileBootstrapData(ctx context.Context, buf io.ReadSeeker,
if ec != nil {
etcdConfig = *ec
} else {
etcdConfig = c.EtcdConfig
etcdConfig = c.config.Runtime.EtcdConfig
}
storageClient, err := client.New(etcdConfig)

View File

@ -8,7 +8,6 @@ import (
"testing"
"time"
"github.com/k3s-io/kine/pkg/endpoint"
"github.com/rancher/k3s/pkg/bootstrap"
"github.com/rancher/k3s/pkg/clientaccess"
"github.com/rancher/k3s/pkg/cluster/managed"
@ -90,7 +89,6 @@ func TestCluster_certDirsExist(t *testing.T) {
clientAccessInfo *clientaccess.Info
config *config.Control
managedDB managed.Driver
etcdConfig endpoint.ETCDConfig
shouldBootstrap bool
storageStarted bool
saveBootstrap bool
@ -131,7 +129,6 @@ func TestCluster_certDirsExist(t *testing.T) {
clientAccessInfo: tt.fields.clientAccessInfo,
config: tt.fields.config,
managedDB: tt.fields.managedDB,
EtcdConfig: tt.fields.etcdConfig,
storageStarted: tt.fields.storageStarted,
saveBootstrap: tt.fields.saveBootstrap,
}
@ -152,7 +149,6 @@ func TestCluster_migrateBootstrapData(t *testing.T) {
clientAccessInfo *clientaccess.Info
config *config.Control
managedDB managed.Driver
etcdConfig endpoint.ETCDConfig
joining bool
storageStarted bool
saveBootstrap bool
@ -207,7 +203,6 @@ func TestCluster_Snapshot(t *testing.T) {
clientAccessInfo *clientaccess.Info
config *config.Control
managedDB managed.Driver
etcdConfig endpoint.ETCDConfig
joining bool
storageStarted bool
saveBootstrap bool
@ -238,7 +233,6 @@ func TestCluster_Snapshot(t *testing.T) {
clientAccessInfo: tt.fields.clientAccessInfo,
config: tt.fields.config,
managedDB: tt.fields.managedDB,
EtcdConfig: tt.fields.etcdConfig,
joining: tt.fields.joining,
storageStarted: tt.fields.storageStarted,
saveBootstrap: tt.fields.saveBootstrap,

View File

@ -19,7 +19,6 @@ type Cluster struct {
clientAccessInfo *clientaccess.Info
config *config.Control
managedDB managed.Driver
EtcdConfig endpoint.ETCDConfig
joining bool
storageStarted bool
saveBootstrap bool
@ -84,7 +83,7 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) {
// if necessary, store bootstrap data to datastore
if c.saveBootstrap {
if err := Save(ctx, c.config, c.EtcdConfig, false); err != nil {
if err := Save(ctx, c.config, false); err != nil {
return nil, err
}
}
@ -98,7 +97,7 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) {
for {
select {
case <-ready:
if err := Save(ctx, c.config, c.EtcdConfig, false); err != nil {
if err := Save(ctx, c.config, false); err != nil {
panic(err)
}
@ -138,7 +137,7 @@ func (c *Cluster) startStorage(ctx context.Context) error {
// Persist the returned etcd configuration. We decide if we're doing leader election for embedded controllers
// based on what the kine wrapper tells us about the datastore. Single-node datastores like sqlite don't require
// leader election, while basically all others (etcd, external database, etc) do since they allow multiple servers.
c.EtcdConfig = etcdConfig
c.config.Runtime.EtcdConfig = etcdConfig
c.config.Datastore.BackendTLSConfig = etcdConfig.TLSConfig
c.config.Datastore.Endpoint = strings.Join(etcdConfig.Endpoints, ",")
c.config.NoLeaderElect = !etcdConfig.LeaderElect

View File

@ -10,7 +10,6 @@ import (
"strings"
"github.com/k3s-io/kine/pkg/client"
"github.com/k3s-io/kine/pkg/endpoint"
"github.com/rancher/k3s/pkg/bootstrap"
"github.com/rancher/k3s/pkg/clientaccess"
"github.com/rancher/k3s/pkg/daemons/config"
@ -21,7 +20,7 @@ import (
// snapshot of the cluster's CA certs and keys, encryption passphrases, etc - encrypted with the join token.
// This is used when bootstrapping a cluster from a managed database or external etcd cluster.
// This is NOT used with embedded etcd, which bootstraps over HTTP.
func Save(ctx context.Context, config *config.Control, etcdConfig endpoint.ETCDConfig, override bool) error {
func Save(ctx context.Context, config *config.Control, override bool) error {
buf := &bytes.Buffer{}
if err := bootstrap.ReadFromDisk(buf, &config.Runtime.ControlRuntimeBootstrap); err != nil {
return err
@ -44,7 +43,7 @@ func Save(ctx context.Context, config *config.Control, etcdConfig endpoint.ETCDC
return err
}
storageClient, err := client.New(etcdConfig)
storageClient, err := client.New(config.Runtime.EtcdConfig)
if err != nil {
return err
}
@ -99,7 +98,7 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error {
return err
}
storageClient, err := client.New(c.EtcdConfig)
storageClient, err := client.New(c.config.Runtime.EtcdConfig)
if err != nil {
return err
}

View File

@ -262,7 +262,6 @@ func prepare(ctx context.Context, config *config.Control) error {
}
config.Runtime.ETCDReady = ready
config.Runtime.EtcdConfig = cluster.EtcdConfig
return nil
}

View File

@ -120,7 +120,7 @@ func (h *handler) onChangeNode(key string, node *corev1.Node) (*corev1.Node, err
h.recorder.Event(node, corev1.EventTypeWarning, secretsUpdateErrorEvent, err.Error())
return node, err
}
if err := cluster.Save(h.ctx, h.controlConfig, h.controlConfig.Runtime.EtcdConfig, true); err != nil {
if err := cluster.Save(h.ctx, h.controlConfig, true); err != nil {
h.recorder.Event(node, corev1.EventTypeWarning, secretsUpdateErrorEvent, err.Error())
return node, err
}

View File

@ -148,7 +148,7 @@ func encryptionEnable(ctx context.Context, server *config.Control, enable bool)
} else {
return fmt.Errorf("unable to enable/disable secrets encryption, unknown configuration")
}
return cluster.Save(ctx, server, server.Runtime.EtcdConfig, true)
return cluster.Save(ctx, server, true)
}
func encryptionConfigHandler(ctx context.Context, server *config.Control) http.Handler {
@ -217,7 +217,7 @@ func encryptionPrepare(ctx context.Context, server *config.Control, force bool)
if err = secretsencrypt.WriteEncryptionHashAnnotation(server.Runtime, node, secretsencrypt.EncryptionPrepare); err != nil {
return err
}
return cluster.Save(ctx, server, server.Runtime.EtcdConfig, true)
return cluster.Save(ctx, server, true)
}
func encryptionRotate(ctx context.Context, server *config.Control, force bool) error {
@ -246,7 +246,7 @@ func encryptionRotate(ctx context.Context, server *config.Control, force bool) e
if err := secretsencrypt.WriteEncryptionHashAnnotation(server.Runtime, node, secretsencrypt.EncryptionRotate); err != nil {
return err
}
return cluster.Save(ctx, server, server.Runtime.EtcdConfig, true)
return cluster.Save(ctx, server, true)
}
func encryptionReencrypt(ctx context.Context, server *config.Control, force bool, skip bool) error {