Skip to content

Commit

Permalink
Merge pull request #283 from finlaysawyer/02-14-env_allow_engine_conf…
Browse files Browse the repository at this point in the history
…ig_to_be_specified_on_cluster_creation

feat(env): allow engine config to be specified on cluster creation
  • Loading branch information
evghen1 authored Feb 15, 2025
2 parents 23f3a9c + 52656bc commit 2ca823a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
14 changes: 8 additions & 6 deletions cmd/overlock/environment/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
)

type createCmd struct {
Name string `arg:"" requried:"" help:"Name of environment."`
HttpPort int `optional:"" short:"p" help:"Http host port for mapping" default:"80"`
HttpsPort int `optional:"" short:"s" help:"Https host port for mapping" default:"443"`
Context string `optional:"" short:"c" help:"Kubernetes context where Environment will be created."`
Engine string `optional:"" short:"e" help:"Specifies the Kubernetes engine to use for the runtime environment." default:"kind"`
MountPath string `optional:"" help:"Path for mount to /storage host directory. By default no mounts."`
Name string `arg:"" requried:"" help:"Name of environment."`
HttpPort int `optional:"" short:"p" help:"Http host port for mapping" default:"80"`
HttpsPort int `optional:"" short:"s" help:"Https host port for mapping" default:"443"`
Context string `optional:"" short:"c" help:"Kubernetes context where Environment will be created."`
Engine string `optional:"" short:"e" help:"Specifies the Kubernetes engine to use for the runtime environment." default:"kind"`
EngineConfig string `optional:"" help:"Path to the configuration file for the engine. Currently supported for kind clusters."`
MountPath string `optional:"" help:"Path for mount to /storage host directory. By default no mounts."`
}

func (c *createCmd) Run(ctx context.Context, logger *zap.SugaredLogger) error {
Expand All @@ -23,5 +24,6 @@ func (c *createCmd) Run(ctx context.Context, logger *zap.SugaredLogger) error {
WithHttpsPort(c.HttpsPort).
WithContext(c.Context).
WithMountPath(c.MountPath).
WithEngineConfig(c.EngineConfig).
Create(ctx, logger)
}
20 changes: 13 additions & 7 deletions internal/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import (
)

type Environment struct {
name string
engine string
httpPort int
httpsPort int
mountPath string
context string
options EnvironmentOptions
name string
engine string
engineConfig string
httpPort int
httpsPort int
mountPath string
context string
options EnvironmentOptions
}

// New Environment entity
Expand Down Expand Up @@ -332,6 +333,11 @@ func (e *Environment) WithMountPath(path string) *Environment {
return e
}

func (e *Environment) WithEngineConfig(engineConfig string) *Environment {
e.engineConfig = engineConfig
return e
}

func SwitchContext(name string) (err error) {
newConfig := clientcmd.GetConfigFromFileOrDie(clientcmd.RecommendedHomeFile)
newConfig.CurrentContext = name
Expand Down
14 changes: 9 additions & 5 deletions internal/environment/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ type KindPortMapping struct {
}

func (e *Environment) CreateKindEnvironment(logger *zap.SugaredLogger) (string, error) {

clusterYaml := e.configYaml(logger)

cmd := exec.Command("kind", "create", "cluster", "--name", e.name, "--config", "-")
cmd.Stdin = strings.NewReader(clusterYaml)
var cmd *exec.Cmd

if e.engineConfig != "" {
cmd = exec.Command("kind", "create", "cluster", "--name", e.name, "--config", e.engineConfig)
} else {
clusterYaml := e.configYaml(logger)
cmd = exec.Command("kind", "create", "cluster", "--name", e.name, "--config", "-")
cmd.Stdin = strings.NewReader(clusterYaml)
}

stderr, err := cmd.StderrPipe()
if err != nil {
Expand Down

0 comments on commit 2ca823a

Please sign in to comment.