installer: create namespaces with kube client
diff --git a/core/installer/welcome/env.go b/core/installer/welcome/env.go
index e871830..67e51d9 100644
--- a/core/installer/welcome/env.go
+++ b/core/installer/welcome/env.go
@@ -23,16 +23,18 @@
var createEnvFormHtml string
type EnvServer struct {
- port int
- ss *soft.Client
- repo installer.RepoIO
+ port int
+ ss *soft.Client
+ repo installer.RepoIO
+ nsCreator installer.NamespaceCreator
}
-func NewEnvServer(port int, ss *soft.Client, repo installer.RepoIO) *EnvServer {
+func NewEnvServer(port int, ss *soft.Client, repo installer.RepoIO, nsCreator installer.NamespaceCreator) *EnvServer {
return &EnvServer{
port,
ss,
repo,
+ nsCreator,
}
}
@@ -99,7 +101,7 @@
if repo == nil {
return err
}
- if err := initNewEnv(s.ss, installer.NewRepoIO(repo, s.ss.Signer), req); err != nil {
+ if err := initNewEnv(s.ss, installer.NewRepoIO(repo, s.ss.Signer), s.nsCreator, req); err != nil {
return err
}
}
@@ -124,8 +126,8 @@
return c.String(http.StatusOK, "OK")
}
-func initNewEnv(ss *soft.Client, r installer.RepoIO, req createEnvReq) error {
- appManager, err := installer.NewAppManager(r)
+func initNewEnv(ss *soft.Client, r installer.RepoIO, nsCreator installer.NamespaceCreator, req createEnvReq) error {
+ appManager, err := installer.NewAppManager(r, nsCreator)
if err != nil {
return err
}
@@ -152,18 +154,18 @@
return err
}
defer out.Close()
- _, err = out.Write([]byte(`
+ _, err = out.Write([]byte(fmt.Sprintf(`
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: GitRepository
metadata:
name: pcloud
- namespace: lekva
+ namespace: %s
spec:
interval: 1m0s
url: https://github.com/giolekva/pcloud
ref:
branch: main
-`))
+`, req.Name)))
if err != nil {
return err
}
@@ -178,12 +180,13 @@
return err
}
r.CommitAndPush("initialize config")
+ nsGen := installer.NewPrefixGenerator(req.Name + "-")
{
app, err := appsRepo.Find("metallb-config-env")
if err != nil {
return err
}
- if err := appManager.Install(*app, map[string]any{
+ if err := appManager.Install(*app, nsGen, map[string]any{
"IngressPrivate": "10.1.0.1",
"Headscale": "10.1.0.2",
"SoftServe": "10.1.0.3",
@@ -200,7 +203,7 @@
if err != nil {
return err
}
- if err := appManager.Install(*app, map[string]any{}); err != nil {
+ if err := appManager.Install(*app, nsGen, map[string]any{}); err != nil {
return err
}
}
@@ -209,7 +212,7 @@
if err != nil {
return err
}
- if err := appManager.Install(*app, map[string]any{}); err != nil {
+ if err := appManager.Install(*app, nsGen, map[string]any{}); err != nil {
return err
}
}
@@ -218,7 +221,7 @@
if err != nil {
return err
}
- if err := appManager.Install(*app, map[string]any{
+ if err := appManager.Install(*app, nsGen, map[string]any{
"Subdomain": "test", // TODO(giolekva): make core-auth chart actually use this
}); err != nil {
return err
@@ -229,7 +232,7 @@
if err != nil {
return err
}
- if err := appManager.Install(*app, map[string]any{
+ if err := appManager.Install(*app, nsGen, map[string]any{
"Subdomain": "headscale",
}); err != nil {
return err
@@ -251,7 +254,7 @@
if err != nil {
return err
}
- if err := appManager.Install(*app, map[string]any{
+ if err := appManager.Install(*app, nsGen, map[string]any{
"RepoAddr": ss.GetRepoAddress(req.Name),
"SSHPrivateKey": keys.Private,
}); err != nil {
diff --git a/core/installer/welcome/welcome.go b/core/installer/welcome/welcome.go
index 04e08f5..d34580f 100644
--- a/core/installer/welcome/welcome.go
+++ b/core/installer/welcome/welcome.go
@@ -20,14 +20,16 @@
var staticAssets embed.FS
type Server struct {
- port int
- repo installer.RepoIO
+ port int
+ repo installer.RepoIO
+ nsCreator installer.NamespaceCreator
}
-func NewServer(port int, repo installer.RepoIO) *Server {
+func NewServer(port int, repo installer.RepoIO, nsCreator installer.NamespaceCreator) *Server {
return &Server{
port,
repo,
+ nsCreator,
}
}
@@ -86,7 +88,15 @@
}
// TODO(giolekva): accounts-ui create user req
{
- appManager, err := installer.NewAppManager(s.repo)
+ config, err := s.repo.ReadConfig()
+ if err != nil {
+ return err
+ }
+ if err != nil {
+ return err
+ }
+ nsGen := installer.NewPrefixGenerator(config.Values.Id + "-")
+ appManager, err := installer.NewAppManager(s.repo, s.nsCreator)
if err != nil {
return err
}
@@ -96,7 +106,7 @@
if err != nil {
return err
}
- if err := appManager.Install(*app, map[string]any{
+ if err := appManager.Install(*app, nsGen, map[string]any{
"GandiAPIToken": req.GandiAPIToken,
}); err != nil {
return err
@@ -107,7 +117,7 @@
if err != nil {
return err
}
- if err := appManager.Install(*app, map[string]any{
+ if err := appManager.Install(*app, nsGen, map[string]any{
"Username": req.Username,
"IPSubnet": "10.1.0.0/24", // TODO(giolekva): this should be taken from the config generated during new env creation
}); err != nil {