Skip to content

Commit

Permalink
Copy old bootstrap buffer data for use during migration (k3s-io#4215)
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Downs <brian.downs@gmail.com>
  • Loading branch information
briandowns committed Nov 10, 2021
1 parent 100fb59 commit 012c322
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 5 additions & 3 deletions pkg/cluster/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions pkg/cluster/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 012c322

Please sign in to comment.