Skip to content

Commit

Permalink
almost
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronoff97 committed Jul 10, 2023
1 parent 5749e12 commit 1552b1e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 13 deletions.
22 changes: 11 additions & 11 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var checkCmd = &cobra.Command{
for _, c := range args {
group := availableChecks[c]
results := map[string]steps.Result{}
conf := getConfig()
conf := GetConfig()
deps := steps.NewDependencies()
for _, step := range group.steps {
for _, dep := range step.Dependencies(conf) {
Expand All @@ -170,16 +170,6 @@ var checkCmd = &cobra.Command{
},
}

func getConfig() *steps.Config {
return &steps.Config{
Endpoint: endpoint,
Insecure: insecure,
Http: http,
Token: accessToken,
KubeConfig: kubeConfig,
}
}

func prettyPrintDependenciesResults(results []*checks.Check) {
t := table.NewWriter()
rowConfigAutoMerge := table.RowConfig{AutoMerge: true}
Expand Down Expand Up @@ -220,6 +210,16 @@ func prettyPrint(results map[string]steps.Result) {
t.Render()
}

func GetConfig() *steps.Config {
return &steps.Config{
Endpoint: endpoint,
Insecure: insecure,
Http: http,
Token: accessToken,
KubeConfig: kubeConfig,
}
}

func init() {
rootCmd.AddCommand(checkCmd)

Expand Down
70 changes: 70 additions & 0 deletions pkg/steps/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package steps

import (
"context"
"fmt"
)

var _ Step = Check{}

type Check struct {
name string
description string
steps []Step
conf *Config
}

func NewCheck(name string, description string, steps []Step, conf *Config) *Check {
return &Check{
name: name,
description: description,
steps: steps,
conf: conf,
}
}

func (c Check) Name() string {
return c.name
}

func (c Check) Description() string {
return c.description
}

func (c Check) Run(ctx context.Context, deps *Deps) (Option, Result) {
results := map[string]Result{}
for _, step := range c.steps {
depResults := c.initDeps(ctx, step, deps, c.conf)
for key, res := range depResults {
results[key] = res
}
opt, r := step.Run(ctx, deps)
results[step.Name()] = r
if !r.Successful() && !r.ShouldContinue() {
break
}
opt(deps)
}
return Empty, NewSuccessfulResult(fmt.Sprint(results))
}

func (c Check) Dependencies(conf *Config) []Step {
return nil
}

func (c Check) initDeps(ctx context.Context, s Step, deps *Deps, conf *Config) map[string]Result {
results := map[string]Result{}
for _, dep := range s.Dependencies(conf) {
depResults := c.initDeps(ctx, dep, deps, conf)
for key, res := range depResults {
results[key] = res
}
opt, r := dep.Run(ctx, deps)
results[dep.Name()] = r
if !r.Successful() && !r.ShouldContinue() {
return results
}
opt(deps)
}
return results
}
4 changes: 2 additions & 2 deletions pkg/steps/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func (c CreateKubeConfig) Run(ctx context.Context, deps *steps.Deps) (steps.Opti
if err != nil {
return steps.Empty, steps.NewFailureResult(err)
}
return steps.WithKubeConfig(config), steps.NewSuccessfulResult("initialize dynamic client")
return steps.WithKubeConfig(config), steps.NewSuccessfulResult("initialize Kube Config")
}

func (c CreateKubeConfig) Dependencies(config *steps.Config) []steps.Step {
return []steps.Step{NewCreateKubeConfigFromConfig(config)}
return nil
}

0 comments on commit 1552b1e

Please sign in to comment.