Skip to content

Commit 39d1c49

Browse files
authored
Merge pull request #245 from shalb/tainted-graph-ref
Tainted units, graph refactoring, fixes
2 parents 46444aa + 70d4822 commit 39d1c49

File tree

31 files changed

+1165
-657
lines changed

31 files changed

+1165
-657
lines changed

.github/workflows/pr_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
git fetch --prune --unshallow --tags && make && cp ./bin/linux-amd64/cdev /usr/local/bin/
3030
3131
- name: Run tests
32-
run: cd tests/test-project/ && cdev plan --tf-plan -l debug && cdev apply --force -l debug && cdev destroy --force -l debug
32+
run: cd tests/test-project/ && cdev apply --force -l debug && cdev destroy --force -l debug
3333
env:
3434
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
3535
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

docs/images/cdev-tainted.png

54.8 KB
Loading

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ require (
3939
require (
4040
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
4141
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0 // indirect
42+
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
4243
github.com/mattn/go-ieproxy v0.0.1 // indirect
4344
)
4445

@@ -94,7 +95,6 @@ require (
9495
github.com/fatih/color v1.15.0 // indirect
9596
github.com/getsops/gopgagent v0.0.0-20170926210634-4d7ea76ff71a // indirect
9697
github.com/go-errors/errors v1.5.1 // indirect
97-
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
9898
github.com/go-logr/logr v1.2.4 // indirect
9999
github.com/go-logr/stdr v1.2.2 // indirect
100100
github.com/go-openapi/jsonpointer v0.20.0 // indirect

pkg/cmd/cdev/apply.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var applyCmd = &cobra.Command{
1616
Short: "Deploys or updates infrastructure according to project configuration",
1717
RunE: func(cmd *cobra.Command, args []string) error {
1818
project, err := project.LoadProjectFull()
19-
if utils.GetEnv("CDEV_COLLECT_USAGE_STATS", "false") == "true" {
19+
if utils.GetEnv("CDEV_COLLECT_USAGE_STATS", "true") != "false" {
2020
log.Infof("Sending usage statistic. To disable statistics collection, export the CDEV_COLLECT_USAGE_STATS=false environment variable")
2121
}
2222
if err != nil {
@@ -31,11 +31,11 @@ var applyCmd = &cobra.Command{
3131
if err != nil {
3232
return NewCmdErr(project, "apply", err)
3333
}
34+
log.Info("The project was successfully applied")
3435
err = project.PrintOutputs()
3536
if err != nil {
3637
return NewCmdErr(project, "apply", err)
3738
}
38-
project.UnLockState()
3939
return NewCmdErr(project, "apply", nil)
4040
},
4141
}
@@ -44,4 +44,5 @@ func init() {
4444
rootCmd.AddCommand(applyCmd)
4545
applyCmd.Flags().BoolVar(&config.Global.IgnoreState, "ignore-state", false, "Apply even if the state has not changed.")
4646
applyCmd.Flags().BoolVar(&config.Global.Force, "force", false, "Skip interactive approval.")
47+
applyCmd.Flags().StringArrayVarP(&config.Global.Targets, "target", "t", []string{}, "Units and stack that will be applied. All others will not apply.")
4748
}

pkg/cmd/cdev/destroy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cdev
22

33
import (
4+
"github.com/apex/log"
45
"github.com/shalb/cluster.dev/pkg/config"
56
"github.com/shalb/cluster.dev/pkg/project"
67
"github.com/spf13/cobra"
@@ -26,6 +27,7 @@ var destroyCmd = &cobra.Command{
2627
project.UnLockState()
2728
return NewCmdErr(project, "destroy", err)
2829
}
30+
log.Info("The project was successfully destroyed")
2931
project.UnLockState()
3032
return NewCmdErr(project, "destroy", nil)
3133
},
@@ -35,4 +37,5 @@ func init() {
3537
rootCmd.AddCommand(destroyCmd)
3638
destroyCmd.Flags().BoolVar(&config.Global.IgnoreState, "ignore-state", false, "Destroy current configuration and ignore state.")
3739
destroyCmd.Flags().BoolVar(&config.Global.Force, "force", false, "Skip interactive approval.")
40+
destroyCmd.Flags().StringArrayVarP(&config.Global.Targets, "target", "t", []string{}, "Units and stack that will be destroyed. All others will not destroy.")
3841
}

pkg/cmd/cdev/output.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ var outputCmd = &cobra.Command{
2020
if err != nil {
2121
log.Fatalf("Fatal error: outputs: lock state: %v", err.Error())
2222
}
23-
stProject, err := project.LoadState()
24-
if err != nil {
25-
project.UnLockState()
26-
log.Fatalf("Fatal error: outputs: load state: %v", err.Error())
27-
}
28-
err = stProject.PrintOutputs()
23+
err = project.OwnState.PrintOutputs()
2924
if err != nil {
3025
log.Fatalf("Fatal error: outputs: print %v", err.Error())
3126
}

pkg/cmd/cdev/plan.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package cdev
22

33
import (
4+
"fmt"
5+
46
"github.com/apex/log"
57
"github.com/shalb/cluster.dev/pkg/config"
68
"github.com/shalb/cluster.dev/pkg/project"
@@ -16,19 +18,19 @@ var planCmd = &cobra.Command{
1618
RunE: func(cmd *cobra.Command, args []string) error {
1719
project, err := project.LoadProjectFull()
1820
if err != nil {
19-
return NewCmdErr(nil, "plan", err)
21+
return NewCmdErr(nil, "plan", fmt.Errorf("load project configuration: %w", err))
2022
}
2123
log.Info("Planning...")
2224
_, err = project.Plan()
2325
if err != nil {
24-
return NewCmdErr(project, "plan", err)
26+
return NewCmdErr(project, "plan", fmt.Errorf("build plan: %w", err))
2527
}
2628
return NewCmdErr(project, "plan", nil)
2729
},
2830
}
2931

3032
func init() {
3133
rootCmd.AddCommand(planCmd)
32-
planCmd.Flags().BoolVar(&config.Global.ShowTerraformPlan, "tf-plan", false, "Also show units terraform plan if possible.")
34+
// planCmd.Flags().BoolVar(&config.Global.ShowTerraformPlan, "tf-plan", false, "Also show units terraform plan if possible.")
3335
planCmd.Flags().BoolVar(&config.Global.IgnoreState, "force", false, "Show plan (if set tf-plan) even if the state has not changed.")
3436
}

pkg/cmd/cdev/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var projectLs = &cobra.Command{
3333
Run: func(cmd *cobra.Command, args []string) {
3434
p, err := project.LoadProjectFull()
3535
if err != nil {
36-
log.Errorf("No project found in the current directory. Configuration error: %v", err.Error())
36+
log.Errorf("Project configuration error: %v", err.Error())
3737
return
3838
}
3939
log.Info("Project info:")

pkg/cmd/cdev/state.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var stateUnlockCmd = &cobra.Command{
1818
Use: "unlock",
1919
Short: "Unlock state force",
2020
Run: func(cmd *cobra.Command, args []string) {
21+
config.Global.IgnoreState = true
2122
project, err := project.LoadProjectFull()
2223
if err != nil {
2324
log.Fatalf("Fatal error: state unlock: %v", err.Error())
@@ -35,7 +36,7 @@ var stateUpdateCmd = &cobra.Command{
3536
Use: "update",
3637
Short: "Updates the state of the current project to version %v. Make sure that the state of the project is consistent (run cdev apply with the old version before)",
3738
Run: func(cmd *cobra.Command, args []string) {
38-
config.Global.NotLoadState = true
39+
config.Global.IgnoreState = true
3940
project, err := project.LoadProjectFull()
4041
if err != nil {
4142
log.Fatalf("Fatal error: state update: %v", err.Error())
@@ -61,7 +62,7 @@ var statePullCmd = &cobra.Command{
6162
Use: "pull",
6263
Short: "Downloads the remote state",
6364
Run: func(cmd *cobra.Command, args []string) {
64-
config.Global.NotLoadState = true
65+
config.Global.IgnoreState = true
6566
project, err := project.LoadProjectFull()
6667
if err != nil {
6768
log.Fatalf("Fatal error: state pull: %v", err.Error())

pkg/colors/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const (
3939
LightWhiteBold
4040
LightRedBold
4141
PurpleBold
42+
Orange
43+
OrangeBold
4244
)
4345

4446
var colored = true
@@ -65,6 +67,8 @@ var colorsMap map[Color]ColoredFmt = map[Color]ColoredFmt{
6567
WhiteBold: color.New(color.FgWhite, color.BgDefault, color.OpBold),
6668
Yellow: color.New(color.FgYellow, color.BgDefault),
6769
YellowBold: color.New(color.FgYellow, color.BgDefault, color.OpBold),
70+
Orange: color.RGB(255, 153, 51),
71+
OrangeBold: color.NewRGBStyle(color.RGB(255, 153, 51)).SetOpts(color.Opts{color.OpBold}),
6872
}
6973

7074
// SetColored set all colors to default, if colored == false.

pkg/config/config.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ type ConfSpec struct {
5555
UseCache bool
5656
OptFooTest bool
5757
IgnoreState bool
58-
NotLoadState bool
59-
ShowTerraformPlan bool
60-
StateCacheDir string
61-
TemplatesCacheDir string
62-
CacheDir string
63-
NoColor bool
64-
Force bool
65-
Interactive bool
66-
OutputJSON bool
58+
// ShowTerraformPlan bool
59+
StateCacheDir string
60+
TemplatesCacheDir string
61+
CacheDir string
62+
NoColor bool
63+
Force bool
64+
Interactive bool
65+
OutputJSON bool
66+
Targets []string
6767
}
6868

6969
// Global config for executor.
@@ -102,13 +102,8 @@ func InitConfig() {
102102
log.Fatal(err.Error())
103103
}
104104
}
105-
Interrupted = false
106-
}
107-
108-
// getEnv Helper for args parse.
109-
func getEnv(key string, defaultVal string) string {
110-
if envVal, ok := os.LookupEnv(key); ok {
111-
return envVal
105+
if Global.MaxParallel == 0 {
106+
log.Fatal("Parallelism should be greater then 0.")
112107
}
113-
return defaultVal
108+
Interrupted = false
114109
}

pkg/config/targetcheck.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package config
2+
3+
import "strings"
4+
5+
type TargetUnits []string
6+
7+
func NewTargetsChecker(tg []string) *TargetUnits {
8+
res := TargetUnits{}
9+
res = append(res, tg...)
10+
return &res
11+
}
12+
13+
func (t *TargetUnits) Check(unitKey string) bool {
14+
for _, target := range *t {
15+
tgSplitted := strings.Split(target, ".")
16+
uKeySplitted := strings.Split(unitKey, ".")
17+
if len(tgSplitted) == 0 || len(tgSplitted) > 2 || len(uKeySplitted) != 2 {
18+
return false
19+
}
20+
if len(tgSplitted) == 1 {
21+
// Target is whole stack, check unit stack name only.
22+
if uKeySplitted[0] == tgSplitted[0] {
23+
return true
24+
}
25+
continue
26+
}
27+
// The target is unit, compare unit name and stack name.
28+
if uKeySplitted[0] == tgSplitted[0] && uKeySplitted[1] == tgSplitted[1] {
29+
return false
30+
}
31+
}
32+
return false
33+
}

0 commit comments

Comments
 (0)