-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make drift check and apply with custom runner code (#2)
* chore(wip): wip * chore(evaluate): change function signature * feat: add compute hash func * chore(signature): again changing function signature * feat: add evaluate for isTerraformRunning and isPlanArtifactUpToDDate * feat(conditions): terraformFailure TerraformApplyUpToDate * feat: use const prefixes for cahce keys * chore(tests): add some units tests for conditions * build: generate deepcopy and manifests * feat: fix timestamp conversion * test: implement testing for all evaluate methods of terraform conditions * chore: rename structs * chore: uniformize every sub evaluate mehtod * test: start implementing terraform layer conditions tests * test: implement terraform layer conditions testing * chore: remove unused struct * feat: start working on job * feat: fix init default pod spec * feat: fix init default pod spec * chore(wip): runner * feat: finish cache logic for plan pod creation * feat: add command for apply pod * feat: implement redis cache * improvement(runner): add runner code, init cobra, move to cache package * feat: remove applied bin cahce key * feat(cobra): implement cobra launch * chore(runner): modify pod creation to use burrito binary * chore(docker): and crd generation * feat: use config to setup cahce in layer controller * feat: run exec on cotnrollers start * feat: use custom image for runeer and generate random name * fix: do not inpu error 2 times to logger * fix(runner): pod generation * fix(runner): pod generation remove command * fix: change prefix in pod env vars * feat: catch set lock error * feat: use commen generate key function for cahce keys * fix(all): add some logs on controller and runner, fix some cache deletion issues * feat(redis): implement delete func * improvement(runner): no sé * feat: make runner put last plan date in cache * fix: use unix timestamp as value for last plan date key in cache Co-authored-by: Alan <alanl@padok.fr>
- Loading branch information
Showing
30 changed files
with
2,251 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package burrito | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/padok-team/burrito/burrito/config" | ||
"github.com/padok-team/burrito/controllers" | ||
"github.com/padok-team/burrito/runner" | ||
) | ||
|
||
type App struct { | ||
Config *config.Config | ||
|
||
Runner Runner | ||
Controllers Controllers | ||
|
||
Out io.Writer | ||
Err io.Writer | ||
} | ||
|
||
type Runner interface { | ||
Exec() | ||
} | ||
|
||
type Controllers interface { | ||
Exec() | ||
} | ||
|
||
func New() (*App, error) { | ||
c := &config.Config{} | ||
app := &App{ | ||
Config: c, | ||
Runner: runner.New(c), | ||
Controllers: controllers.New(c), | ||
Out: os.Stdout, | ||
Err: os.Stderr, | ||
} | ||
return app, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"reflect" | ||
"strings" | ||
|
||
"github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type Config struct { | ||
Runner RunnerConfig `yaml:"runner"` | ||
Controller ControllerConfig `yaml:"controller"` | ||
Redis Redis `yaml:"redis"` | ||
} | ||
|
||
type ControllerConfig struct { | ||
WatchedNamespaces []string `yaml:"namespaces"` | ||
} | ||
|
||
type RepositoryConfig struct { | ||
URL string `yaml:"url"` | ||
SSH string `yaml:"ssh"` | ||
Username string `yaml:"username"` | ||
Password string `yaml:"password"` | ||
} | ||
|
||
type RunnerConfig struct { | ||
Path string `yaml:"path"` | ||
Branch string `yaml:"branch"` | ||
Version string `yaml:"version"` | ||
Action string `yaml:"action"` | ||
Repository RepositoryConfig `yaml:"repository"` | ||
Layer LayerConfig `yaml:"layer"` | ||
} | ||
|
||
type LayerConfig struct { | ||
Lock string `yaml:"lock"` | ||
PlanSum string `yaml:"planSum"` | ||
PlanBin string `yaml:"planBin"` | ||
ApplySum string `yaml:"applySum"` | ||
PlanDate string `yaml:"planDate"` | ||
} | ||
|
||
type Redis struct { | ||
URL string `yaml:"url"` | ||
Password string `yaml:"password"` | ||
Database int `yaml:"database"` | ||
} | ||
|
||
func (c *Config) Load(flags *pflag.FlagSet) error { | ||
v := viper.New() | ||
|
||
// burrito looks for configuration files called config.yaml, config.json, | ||
// config.toml, config.hcl, etc. | ||
v.SetConfigName("config") | ||
|
||
// burrito looks for configuration files in the common configuration | ||
// directories. | ||
v.AddConfigPath("/etc/burrito/") | ||
v.AddConfigPath("$HOME/.burrito/") | ||
|
||
// Viper logs the configuration file it uses, if any. | ||
if err := v.ReadInConfig(); err == nil { | ||
fmt.Fprintf(os.Stderr, "Using config file: %s\n", v.ConfigFileUsed()) | ||
} | ||
|
||
// burrito can be configured with environment variables that start with | ||
// burrito_. | ||
v.SetEnvPrefix("burrito") | ||
v.AutomaticEnv() | ||
|
||
// Options with dashes in flag names have underscores when set inside a | ||
// configuration file or with environment variables. | ||
flags.SetNormalizeFunc(func(fs *pflag.FlagSet, name string) pflag.NormalizedName { | ||
name = strings.ReplaceAll(name, "-", "_") | ||
return pflag.NormalizedName(name) | ||
}) | ||
v.BindPFlags(flags) | ||
|
||
// Nested configuration options set with environment variables use an | ||
// underscore as a separator. | ||
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) | ||
bindEnvironmentVariables(v, *c) | ||
|
||
return v.Unmarshal(c) | ||
} | ||
|
||
// bindEnvironmentVariables inspects iface's structure and recursively binds its | ||
// fields to environment variables. This is a workaround to a limitation of | ||
// Viper, found here: | ||
// https://github.com/spf13/viper/issues/188#issuecomment-399884438 | ||
func bindEnvironmentVariables(v *viper.Viper, iface interface{}, parts ...string) { | ||
ifv := reflect.ValueOf(iface) | ||
ift := reflect.TypeOf(iface) | ||
for i := 0; i < ift.NumField(); i++ { | ||
val := ifv.Field(i) | ||
typ := ift.Field(i) | ||
tv, ok := typ.Tag.Lookup("yaml") | ||
if !ok { | ||
continue | ||
} | ||
switch val.Kind() { | ||
case reflect.Struct: | ||
bindEnvironmentVariables(v, val.Interface(), append(parts, tv)...) | ||
default: | ||
v.BindEnv(strings.Join(append(parts, tv), ".")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package burrito | ||
|
||
func (app *App) StartController() error { | ||
app.Controllers.Exec() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package burrito | ||
|
||
func (app *App) StartRunner() { | ||
app.Runner.Exec() | ||
} |
Oops, something went wrong.