diff --git a/pkg/cluster/bootstrap.go b/pkg/cluster/bootstrap.go index 7ca3a2c570bc..c579842647dd 100644 --- a/pkg/cluster/bootstrap.go +++ b/pkg/cluster/bootstrap.go @@ -154,7 +154,7 @@ func (c *Cluster) certDirsExist() error { } // migrateBootstrapData migrates bootstrap data from the old format to the new format. -func migrateBootstrapData(ctx context.Context, data *bytes.Buffer, files bootstrap.PathsDataformat) error { +func migrateBootstrapData(ctx context.Context, data io.Reader, files bootstrap.PathsDataformat) error { logrus.Info("Migrating bootstrap data to new format") var oldBootstrapData map[string][]byte @@ -182,7 +182,7 @@ const systemTimeSkew = int64(3) // bootstrap data in the datastore is newer than on disk or different // and dependingon where the difference is, the newer data is written // to the older. -func (c *Cluster) ReconcileBootstrapData(ctx context.Context, buf *bytes.Buffer, crb *config.ControlRuntimeBootstrap) error { +func (c *Cluster) ReconcileBootstrapData(ctx context.Context, buf io.ReadSeeker, crb *config.ControlRuntimeBootstrap) error { logrus.Info("Reconciling bootstrap data between datastore and disk") if err := c.certDirsExist(); err != nil { @@ -243,11 +243,13 @@ RETRY: } files := make(bootstrap.PathsDataformat) + if err := json.NewDecoder(buf).Decode(&files); err != nil { // This will fail if data is being pulled from old an cluster since // older clusters used a map[string][]byte for the data structure. // Therefore, we need to perform a migration to the newer bootstrap // format; bootstrap.BootstrapFile. + buf.Seek(0, 0) if err := migrateBootstrapData(ctx, buf, files); err != nil { return err } @@ -395,7 +397,7 @@ func (c *Cluster) httpBootstrap(ctx context.Context) error { return err } - return c.ReconcileBootstrapData(ctx, bytes.NewBuffer(content), &c.config.Runtime.ControlRuntimeBootstrap) + return c.ReconcileBootstrapData(ctx, bytes.NewReader(content), &c.config.Runtime.ControlRuntimeBootstrap) } // bootstrap performs cluster bootstrapping, either via HTTP (for managed databases) or direct load from datastore. diff --git a/pkg/cluster/storage.go b/pkg/cluster/storage.go index 7827be71c25b..a139bf6544d4 100644 --- a/pkg/cluster/storage.go +++ b/pkg/cluster/storage.go @@ -132,8 +132,7 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error { return err } - return c.ReconcileBootstrapData(ctx, bytes.NewBuffer(data), &c.config.Runtime.ControlRuntimeBootstrap) - //return bootstrap.WriteToDiskFromStorage(bytes.NewBuffer(data), &c.runtime.ControlRuntimeBootstrap) + return c.ReconcileBootstrapData(ctx, bytes.NewReader(data), &c.config.Runtime.ControlRuntimeBootstrap) } // getBootstrapKeyFromStorage will list all keys that has prefix /bootstrap and will check for key that is