Lightweight Kubernetes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

38 lines
784 B

package loadbalancer
import (
"encoding/json"
"io/ioutil"
"github.com/rancher/k3s/pkg/agent/util"
)
func (lb *LoadBalancer) writeConfig() error {
configOut, err := json.MarshalIndent(lb, "", " ")
if err != nil {
return err
}
if err := util.WriteFile(lb.configFile, string(configOut)); err != nil {
return err
}
return nil
}
func (lb *LoadBalancer) updateConfig() error {
writeConfig := true
if configBytes, err := ioutil.ReadFile(lb.configFile); err == nil {
config := &LoadBalancer{}
if err := json.Unmarshal(configBytes, config); err == nil {
if config.ServerURL == lb.ServerURL {
writeConfig = false
lb.setServers(config.ServerAddresses)
}
}
}
if writeConfig {
if err := lb.writeConfig(); err != nil {
return err
}
}
return nil
}