beta contoller implanted

This commit is contained in:
2026-04-09 17:50:12 +02:00
parent 29c4e5d674
commit 7bb0698f77
9 changed files with 133 additions and 45 deletions
+32 -15
View File
@@ -3,6 +3,7 @@ package config
import (
"errors"
"fmt"
"net/netip"
"os"
"path/filepath"
@@ -29,14 +30,17 @@ type Auth struct {
}
type Config struct {
Service Service `json:"service" yaml:"service"`
Auths []Auth `json:"auths" yaml:"auths"`
Hostname string `json:"hostname" yaml:"hostname"`
LogPath string `json:"logfile" yaml:"logfile"`
RunPath string `json:"runfile" yaml:"runfile"`
AsDaemon bool `json:"asDaemon" yaml:"asDaemon"`
LogLimit int64 `json:"logLimit" yaml:logLimit`
RunUser string `json:"runUser" yaml:runUser`
Service Service `json:"service" yaml:"service"`
Auths []Auth `json:"auths" yaml:"auths"`
Hostname string `json:"hostname" yaml:"hostname"`
LogPath string `json:"logfile" yaml:"logfile"`
RunPath string `json:"runfile" yaml:"runfile"`
AsDaemon bool `json:"asDaemon" yaml:"asDaemon"`
LogLimit int64 `json:"logLimit" yaml:"logLimit"`
RunUser string `json:"runUser" yaml:"runUser"`
KubeconfPath string `json:"kubeconfPath" yaml:"kubeconfPath"`
ExtAddress string `json:"extAddress" yaml:"extAddress"`
Kubeconf []byte `json:"-" yaml:"-"`
}
func NewConfig() (*Config, error) {
@@ -44,9 +48,11 @@ func NewConfig() (*Config, error) {
Service: Service{
Port: client.DefaultServicePort,
},
AsDaemon: false,
LogLimit: 1024 * 1024 * 10, // 10 Mb
RunUser: "daemon",
AsDaemon: false,
LogLimit: 1024 * 1024 * 10, // 10 Mb
RunUser: "daemon",
KubeconfPath: "kubeconf.yaml",
ExtAddress: "127.0.0.1",
}
hostname, err := os.Hostname()
if err != nil {
@@ -70,20 +76,31 @@ func (conf *Config) Read() error {
if err != nil {
return err
}
if !filepath.IsAbs(conf.KubeconfPath) {
conf.KubeconfPath = filepath.Join(confdirPath, conf.KubeconfPath)
}
kubeconfBytes, err := os.ReadFile(conf.KubeconfPath)
if err != nil {
err = fmt.Errorf("Cannot read kubeconf in path %s: %v", conf.KubeconfPath, err)
return err
}
conf.Kubeconf = kubeconfBytes
return err
}
func (conf *Config) Validate() error {
var err []error
var errs []error
for i := range conf.Auths {
if conf.Auths[i].Username == "" {
err = append(err, errors.New("Username must be set"))
errs = append(errs, errors.New("Username must be set"))
}
if conf.Auths[i].Password == "" {
err = append(err, errors.New("Password must be set"))
errs = append(errs, errors.New("Password must be set"))
}
}
return errors.Join(err...)
_, err := netip.ParseAddr(conf.ExtAddress)
errs = append(errs, err)
return errors.Join(errs...)
}
func (conf *Config) YAML() (string, error) {
+5 -5
View File
@@ -1,10 +1,10 @@
package config
const (
confdirPath = "/etc/minilb"
rundirPath = "/var/run/minilb"
logdirPath = "/var/log/minilb"
datadirPath = "/var/lib/minilb"
confdirPath = "/home/ziggi/Projects/minilb/etc/minilb"
rundirPath = "/home/ziggi/Projects/minilb/tmp/run"
logdirPath = "/home/ziggi/Projects/minilb/tmp/log"
datadirPath = "/home/ziggi/Projects/minilb/tmp/data"
pkgVersion = "0.0.1"
runUser = "daemon"
runUser = "ziggi"
)