Merge pull request #634 from erikwilson/enforce-type-on-bootstrap

Enforce explicit read or write for bootstrap
pull/637/head
Erik Wilson 5 years ago committed by GitHub
commit f6701bbe99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -72,13 +72,17 @@ func fetchBootstrapData(cfg *config.Control) error {
}
defer cli.Close()
logrus.Info("Fetching bootstrap data from etcd")
gr, err := cli.Get(context.TODO(), k3sRuntimeEtcdPath)
if err != nil {
return err
}
if len(gr.Kvs) == 0 {
if cfg.BootstrapType != bootstrapTypeRead {
return nil
}
return errors.New("Unable to read bootstrap data from server")
}
runtimeJSON, err := base64.URLEncoding.DecodeString(string(gr.Kvs[0].Value))
if err != nil {
@ -118,6 +122,7 @@ func storeBootstrapData(cfg *config.Control) error {
}
defer cli.Close()
if cfg.BootstrapType != bootstrapTypeWrite {
gr, err := cli.Get(context.TODO(), k3sRuntimeEtcdPath)
if err != nil {
return err
@ -125,11 +130,14 @@ func storeBootstrapData(cfg *config.Control) error {
if len(gr.Kvs) > 0 && string(gr.Kvs[0].Value) != "" {
return nil
}
}
certData, err := readRuntimeBootstrapData(cfg.Runtime)
if err != nil {
return err
}
logrus.Info("Storing bootstrap data to etcd")
runtimeBase64 := base64.StdEncoding.EncodeToString(certData)
_, err = cli.Put(context.TODO(), k3sRuntimeEtcdPath, runtimeBase64)
if err != nil {

Loading…
Cancel
Save