mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
9a849b1bb7
* changing package to k3s-io Signed-off-by: Luther Monson <luther.monson@gmail.com> Co-authored-by: Derek Nola <derek.nola@suse.com>
36 lines
738 B
Go
36 lines
738 B
Go
package loadbalancer
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
|
|
"github.com/k3s-io/k3s/pkg/agent/util"
|
|
)
|
|
|
|
func (lb *LoadBalancer) writeConfig() error {
|
|
configOut, err := json.MarshalIndent(lb, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return util.WriteFile(lb.configFile, string(configOut))
|
|
}
|
|
|
|
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
|
|
}
|