Commit a1b800f0 authored by Brad Davidson's avatar Brad Davidson Committed by Brad Davidson

Remove unnecessary copies of etcdconfig struct

parent 2989b8b2
...@@ -386,7 +386,7 @@ func (c *Cluster) ReconcileBootstrapData(ctx context.Context, buf io.ReadSeeker, ...@@ -386,7 +386,7 @@ func (c *Cluster) ReconcileBootstrapData(ctx context.Context, buf io.ReadSeeker,
if ec != nil { if ec != nil {
etcdConfig = *ec etcdConfig = *ec
} else { } else {
etcdConfig = c.EtcdConfig etcdConfig = c.config.Runtime.EtcdConfig
} }
storageClient, err := client.New(etcdConfig) storageClient, err := client.New(etcdConfig)
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/k3s-io/kine/pkg/endpoint"
"github.com/rancher/k3s/pkg/bootstrap" "github.com/rancher/k3s/pkg/bootstrap"
"github.com/rancher/k3s/pkg/clientaccess" "github.com/rancher/k3s/pkg/clientaccess"
"github.com/rancher/k3s/pkg/cluster/managed" "github.com/rancher/k3s/pkg/cluster/managed"
...@@ -90,7 +89,6 @@ func TestCluster_certDirsExist(t *testing.T) { ...@@ -90,7 +89,6 @@ func TestCluster_certDirsExist(t *testing.T) {
clientAccessInfo *clientaccess.Info clientAccessInfo *clientaccess.Info
config *config.Control config *config.Control
managedDB managed.Driver managedDB managed.Driver
etcdConfig endpoint.ETCDConfig
shouldBootstrap bool shouldBootstrap bool
storageStarted bool storageStarted bool
saveBootstrap bool saveBootstrap bool
...@@ -131,7 +129,6 @@ func TestCluster_certDirsExist(t *testing.T) { ...@@ -131,7 +129,6 @@ func TestCluster_certDirsExist(t *testing.T) {
clientAccessInfo: tt.fields.clientAccessInfo, clientAccessInfo: tt.fields.clientAccessInfo,
config: tt.fields.config, config: tt.fields.config,
managedDB: tt.fields.managedDB, managedDB: tt.fields.managedDB,
EtcdConfig: tt.fields.etcdConfig,
storageStarted: tt.fields.storageStarted, storageStarted: tt.fields.storageStarted,
saveBootstrap: tt.fields.saveBootstrap, saveBootstrap: tt.fields.saveBootstrap,
} }
...@@ -152,7 +149,6 @@ func TestCluster_migrateBootstrapData(t *testing.T) { ...@@ -152,7 +149,6 @@ func TestCluster_migrateBootstrapData(t *testing.T) {
clientAccessInfo *clientaccess.Info clientAccessInfo *clientaccess.Info
config *config.Control config *config.Control
managedDB managed.Driver managedDB managed.Driver
etcdConfig endpoint.ETCDConfig
joining bool joining bool
storageStarted bool storageStarted bool
saveBootstrap bool saveBootstrap bool
...@@ -207,7 +203,6 @@ func TestCluster_Snapshot(t *testing.T) { ...@@ -207,7 +203,6 @@ func TestCluster_Snapshot(t *testing.T) {
clientAccessInfo *clientaccess.Info clientAccessInfo *clientaccess.Info
config *config.Control config *config.Control
managedDB managed.Driver managedDB managed.Driver
etcdConfig endpoint.ETCDConfig
joining bool joining bool
storageStarted bool storageStarted bool
saveBootstrap bool saveBootstrap bool
...@@ -238,7 +233,6 @@ func TestCluster_Snapshot(t *testing.T) { ...@@ -238,7 +233,6 @@ func TestCluster_Snapshot(t *testing.T) {
clientAccessInfo: tt.fields.clientAccessInfo, clientAccessInfo: tt.fields.clientAccessInfo,
config: tt.fields.config, config: tt.fields.config,
managedDB: tt.fields.managedDB, managedDB: tt.fields.managedDB,
EtcdConfig: tt.fields.etcdConfig,
joining: tt.fields.joining, joining: tt.fields.joining,
storageStarted: tt.fields.storageStarted, storageStarted: tt.fields.storageStarted,
saveBootstrap: tt.fields.saveBootstrap, saveBootstrap: tt.fields.saveBootstrap,
......
...@@ -19,7 +19,6 @@ type Cluster struct { ...@@ -19,7 +19,6 @@ type Cluster struct {
clientAccessInfo *clientaccess.Info clientAccessInfo *clientaccess.Info
config *config.Control config *config.Control
managedDB managed.Driver managedDB managed.Driver
EtcdConfig endpoint.ETCDConfig
joining bool joining bool
storageStarted bool storageStarted bool
saveBootstrap bool saveBootstrap bool
...@@ -84,7 +83,7 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) { ...@@ -84,7 +83,7 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) {
// if necessary, store bootstrap data to datastore // if necessary, store bootstrap data to datastore
if c.saveBootstrap { 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 return nil, err
} }
} }
...@@ -98,7 +97,7 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) { ...@@ -98,7 +97,7 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) {
for { for {
select { select {
case <-ready: case <-ready:
if err := Save(ctx, c.config, c.EtcdConfig, false); err != nil { if err := Save(ctx, c.config, false); err != nil {
panic(err) panic(err)
} }
...@@ -138,7 +137,7 @@ func (c *Cluster) startStorage(ctx context.Context) error { ...@@ -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 // 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 // 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. // 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.BackendTLSConfig = etcdConfig.TLSConfig
c.config.Datastore.Endpoint = strings.Join(etcdConfig.Endpoints, ",") c.config.Datastore.Endpoint = strings.Join(etcdConfig.Endpoints, ",")
c.config.NoLeaderElect = !etcdConfig.LeaderElect c.config.NoLeaderElect = !etcdConfig.LeaderElect
......
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
"strings" "strings"
"github.com/k3s-io/kine/pkg/client" "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/bootstrap"
"github.com/rancher/k3s/pkg/clientaccess" "github.com/rancher/k3s/pkg/clientaccess"
"github.com/rancher/k3s/pkg/daemons/config" "github.com/rancher/k3s/pkg/daemons/config"
...@@ -21,7 +20,7 @@ import ( ...@@ -21,7 +20,7 @@ import (
// snapshot of the cluster's CA certs and keys, encryption passphrases, etc - encrypted with the join token. // 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 used when bootstrapping a cluster from a managed database or external etcd cluster.
// This is NOT used with embedded etcd, which bootstraps over HTTP. // 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{} buf := &bytes.Buffer{}
if err := bootstrap.ReadFromDisk(buf, &config.Runtime.ControlRuntimeBootstrap); err != nil { if err := bootstrap.ReadFromDisk(buf, &config.Runtime.ControlRuntimeBootstrap); err != nil {
return err return err
...@@ -44,7 +43,7 @@ func Save(ctx context.Context, config *config.Control, etcdConfig endpoint.ETCDC ...@@ -44,7 +43,7 @@ func Save(ctx context.Context, config *config.Control, etcdConfig endpoint.ETCDC
return err return err
} }
storageClient, err := client.New(etcdConfig) storageClient, err := client.New(config.Runtime.EtcdConfig)
if err != nil { if err != nil {
return err return err
} }
...@@ -99,7 +98,7 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error { ...@@ -99,7 +98,7 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error {
return err return err
} }
storageClient, err := client.New(c.EtcdConfig) storageClient, err := client.New(c.config.Runtime.EtcdConfig)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -262,7 +262,6 @@ func prepare(ctx context.Context, config *config.Control) error { ...@@ -262,7 +262,6 @@ func prepare(ctx context.Context, config *config.Control) error {
} }
config.Runtime.ETCDReady = ready config.Runtime.ETCDReady = ready
config.Runtime.EtcdConfig = cluster.EtcdConfig
return nil return nil
} }
......
...@@ -120,7 +120,7 @@ func (h *handler) onChangeNode(key string, node *corev1.Node) (*corev1.Node, err ...@@ -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()) h.recorder.Event(node, corev1.EventTypeWarning, secretsUpdateErrorEvent, err.Error())
return node, err 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()) h.recorder.Event(node, corev1.EventTypeWarning, secretsUpdateErrorEvent, err.Error())
return node, err return node, err
} }
......
...@@ -148,7 +148,7 @@ func encryptionEnable(ctx context.Context, server *config.Control, enable bool) ...@@ -148,7 +148,7 @@ func encryptionEnable(ctx context.Context, server *config.Control, enable bool)
} else { } else {
return fmt.Errorf("unable to enable/disable secrets encryption, unknown configuration") 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 { func encryptionConfigHandler(ctx context.Context, server *config.Control) http.Handler {
...@@ -217,7 +217,7 @@ func encryptionPrepare(ctx context.Context, server *config.Control, force bool) ...@@ -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 { if err = secretsencrypt.WriteEncryptionHashAnnotation(server.Runtime, node, secretsencrypt.EncryptionPrepare); err != nil {
return err 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 { 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 ...@@ -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 { if err := secretsencrypt.WriteEncryptionHashAnnotation(server.Runtime, node, secretsencrypt.EncryptionRotate); err != nil {
return err 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 { func encryptionReencrypt(ctx context.Context, server *config.Control, force bool, skip bool) error {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment