From a1b800f0bfc6c607fc04adf16ca1aec00158f626 Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Fri, 25 Feb 2022 09:26:13 -0800 Subject: [PATCH] Remove unnecessary copies of etcdconfig struct Signed-off-by: Brad Davidson --- pkg/cluster/bootstrap.go | 2 +- pkg/cluster/bootstrap_test.go | 6 ------ pkg/cluster/cluster.go | 7 +++---- pkg/cluster/storage.go | 7 +++---- pkg/daemons/control/server.go | 1 - pkg/secretsencrypt/controller.go | 2 +- pkg/server/secrets-encrypt.go | 6 +++--- 7 files changed, 11 insertions(+), 20 deletions(-) diff --git a/pkg/cluster/bootstrap.go b/pkg/cluster/bootstrap.go index d2ecd2dc09..3197645007 100644 --- a/pkg/cluster/bootstrap.go +++ b/pkg/cluster/bootstrap.go @@ -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) diff --git a/pkg/cluster/bootstrap_test.go b/pkg/cluster/bootstrap_test.go index 86d6e5f2c3..f19b9bd3a0 100644 --- a/pkg/cluster/bootstrap_test.go +++ b/pkg/cluster/bootstrap_test.go @@ -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, diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 47bb3f18c4..12c6323d00 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -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 diff --git a/pkg/cluster/storage.go b/pkg/cluster/storage.go index 0bf66024a6..f54ec741bb 100644 --- a/pkg/cluster/storage.go +++ b/pkg/cluster/storage.go @@ -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 } diff --git a/pkg/daemons/control/server.go b/pkg/daemons/control/server.go index b0a32c8d93..fc9d4eb920 100644 --- a/pkg/daemons/control/server.go +++ b/pkg/daemons/control/server.go @@ -262,7 +262,6 @@ func prepare(ctx context.Context, config *config.Control) error { } config.Runtime.ETCDReady = ready - config.Runtime.EtcdConfig = cluster.EtcdConfig return nil } diff --git a/pkg/secretsencrypt/controller.go b/pkg/secretsencrypt/controller.go index 422d160f7e..45fcb02e4b 100644 --- a/pkg/secretsencrypt/controller.go +++ b/pkg/secretsencrypt/controller.go @@ -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 } diff --git a/pkg/server/secrets-encrypt.go b/pkg/server/secrets-encrypt.go index ef20254e30..dff66836e1 100644 --- a/pkg/server/secrets-encrypt.go +++ b/pkg/server/secrets-encrypt.go @@ -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 {