sparkles: Custom partitioning refactor config (#1180)

* Introduce config/collector package

to split the collection of config sources out of the config package.

Each consumer of the new package will take care of unmarshalling the
yaml to a specific Config struct, do validations etc.

* Add tests and remove garbage
* Follow all config_url chains and test it
* Add missing options file and refactor cmdline code
* Consolidate the way we merge configs no matter where they come from
* Allow and use only files with valid headers

Config is  specific to Kairos while Collector is generic. This
will allow us to do validations which are just related to Kairos at the
config level, while including every type of key and querying of the full
yaml at the Collector level splitting the responsibilities of each
package.

---------

Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
Mauro Morales
2023-03-29 16:25:38 +02:00
committed by Itxaka
parent b7ea097d35
commit b513c69a0c
6 changed files with 899 additions and 472 deletions

View File

@@ -0,0 +1,45 @@
package collector_test
import (
"context"
"net"
"net/http"
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestConfig(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Config Collector Suite")
}
type ServerCloseFunc func()
func startAssetServer(path string) (ServerCloseFunc, int, error) {
listener, err := net.Listen("tcp", ":0")
if err != nil {
return nil, 0, err
}
port := listener.Addr().(*net.TCPAddr).Port
ctx, cancelFunc := context.WithCancel(context.Background())
go func() {
defer GinkgoRecover()
err := http.Serve(listener, http.FileServer(http.Dir(path)))
select {
case <-ctx.Done(): // We closed it with the CancelFunc, ignore the error
return
default: // We didnt' close it, return the error
Expect(err).ToNot(HaveOccurred())
}
}()
stopFunc := func() {
cancelFunc()
listener.Close()
}
return stopFunc, port, nil
}