feat: 🎉 complete maker nginx(app)
This commit is contained in:
15
internal/controller/installer/installer.check.go
Normal file
15
internal/controller/installer/installer.check.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package installer
|
||||
|
||||
import "context"
|
||||
|
||||
func (i *installer) Check(ctx context.Context) error {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
if err = i.targetOK(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,8 +1,39 @@
|
||||
package controller
|
||||
package installer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os/exec"
|
||||
|
||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
||||
)
|
||||
|
||||
type installer struct {
|
||||
target string
|
||||
}
|
||||
|
||||
func NewInstaller() *installer {
|
||||
return &installer{}
|
||||
func (i *installer) targetOK(ctx context.Context) error {
|
||||
if i.target == "" {
|
||||
logger.Debug("🎯 installer.targetOK: target = self")
|
||||
return nil
|
||||
}
|
||||
|
||||
// run ssh <target>, check if it's reachable, and it's root user
|
||||
cmd := exec.CommandContext(ctx, "ssh", i.target, "whoami")
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
logger.Debug("❌ installer.targetOK: check target %s failed, err = %v", i.target, err)
|
||||
return err
|
||||
}
|
||||
|
||||
if string(output) != "root\n" {
|
||||
logger.Debug("❌ installer.targetOK: check target %s failed, output = %s", i.target, string(output))
|
||||
return errors.New("target is not root user")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewInstaller(target string) *installer {
|
||||
return &installer{target: target}
|
||||
}
|
||||
|
||||
58
internal/controller/installer/installer.k0s.go
Normal file
58
internal/controller/installer/installer.k0s.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package installer
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
type K0sOpt func(*k0sOpt)
|
||||
type k0sOpt struct {
|
||||
Type string // controller, worker
|
||||
DisableWorker bool
|
||||
WorkerTokenFile string
|
||||
}
|
||||
|
||||
func WithK0sType(t string) K0sOpt {
|
||||
types := []string{"controller", "worker"}
|
||||
return func(o *k0sOpt) {
|
||||
if lo.Contains(types, t) {
|
||||
o.Type = t
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WithoutK0sWorker() K0sOpt {
|
||||
return func(o *k0sOpt) {
|
||||
o.DisableWorker = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithK0sWorkerTokenFile(filename string) K0sOpt {
|
||||
return func(o *k0sOpt) {
|
||||
if filename != "" {
|
||||
o.WorkerTokenFile = filename
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *installer) K0s(ctx context.Context, opts ...K0sOpt) error {
|
||||
var (
|
||||
err error
|
||||
o = &k0sOpt{
|
||||
Type: "controller",
|
||||
DisableWorker: false,
|
||||
WorkerTokenFile: "/etc/k0s/worker.token",
|
||||
}
|
||||
)
|
||||
|
||||
if err = i.targetOK(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, fn := range opts {
|
||||
fn(o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
15
internal/controller/installer/installer.prepare.go
Normal file
15
internal/controller/installer/installer.prepare.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package installer
|
||||
|
||||
import "context"
|
||||
|
||||
func (i *installer) Prepare(ctx context.Context) error {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
if err = i.targetOK(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
7
internal/controller/installer/installer.yosguard.go
Normal file
7
internal/controller/installer/installer.yosguard.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package installer
|
||||
|
||||
import "context"
|
||||
|
||||
func (i *installer) YosGuard(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user