mirror of https://github.com/k3s-io/k3s
Merge pull request #634 from erikwilson/enforce-type-on-bootstrap
Enforce explicit read or write for bootstrappull/637/head
commit
f6701bbe99
|
@ -72,12 +72,16 @@ func fetchBootstrapData(cfg *config.Control) error {
|
||||||
}
|
}
|
||||||
defer cli.Close()
|
defer cli.Close()
|
||||||
|
|
||||||
|
logrus.Info("Fetching bootstrap data from etcd")
|
||||||
gr, err := cli.Get(context.TODO(), k3sRuntimeEtcdPath)
|
gr, err := cli.Get(context.TODO(), k3sRuntimeEtcdPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(gr.Kvs) == 0 {
|
if len(gr.Kvs) == 0 {
|
||||||
return nil
|
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))
|
runtimeJSON, err := base64.URLEncoding.DecodeString(string(gr.Kvs[0].Value))
|
||||||
|
@ -118,18 +122,22 @@ func storeBootstrapData(cfg *config.Control) error {
|
||||||
}
|
}
|
||||||
defer cli.Close()
|
defer cli.Close()
|
||||||
|
|
||||||
gr, err := cli.Get(context.TODO(), k3sRuntimeEtcdPath)
|
if cfg.BootstrapType != bootstrapTypeWrite {
|
||||||
if err != nil {
|
gr, err := cli.Get(context.TODO(), k3sRuntimeEtcdPath)
|
||||||
return err
|
if err != nil {
|
||||||
}
|
return err
|
||||||
if len(gr.Kvs) > 0 && string(gr.Kvs[0].Value) != "" {
|
}
|
||||||
return nil
|
if len(gr.Kvs) > 0 && string(gr.Kvs[0].Value) != "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
certData, err := readRuntimeBootstrapData(cfg.Runtime)
|
certData, err := readRuntimeBootstrapData(cfg.Runtime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logrus.Info("Storing bootstrap data to etcd")
|
||||||
runtimeBase64 := base64.StdEncoding.EncodeToString(certData)
|
runtimeBase64 := base64.StdEncoding.EncodeToString(certData)
|
||||||
_, err = cli.Put(context.TODO(), k3sRuntimeEtcdPath, runtimeBase64)
|
_, err = cli.Put(context.TODO(), k3sRuntimeEtcdPath, runtimeBase64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue