New ๐ŸŒŠ wave for @helm

Commit 21bee7d1

21bee7d16ff8Merged

Dmitriy Zhilyaev <[email protected]> ยท 2 years ago ยท 2 files ยท ~2 modified

Description

fix: refactoring

Signed-off-by: Dmitriy Zhilyaev [email protected]

Details

Commit
21bee7d16ff8
Parent
798aed8fd09a

pkg/action/build.gomodifiedView file

@@ -32,6 +32,21 @@
3232 skipUnchanged bool
3333 }
3434
35+func (i *Build) CleanRemote(src, dest string) {
36+ srcPlandir := filepath.Join(src, i.plandir)
37+ destPlandir := filepath.Join(dest, i.plandir)
38+
39+ err := os.RemoveAll(destPlandir)
40+ if err != nil {
41+ log.WithError(err).Error("failed to clean plandir")
42+ }
43+
44+ err = helper.MoveFile(srcPlandir, destPlandir)
45+ if err != nil {
46+ log.WithError(err).Error("failed to move plandir")
47+ }
48+}
49+
3550 // Run is the main function for 'build' CLI command.
3651 //
3752 //nolint:funlen,gocognit,cyclop
@@ -41,6 +56,7 @@
4156 return fmt.Errorf("failed to get current directory: %w", err)
4257 }
4358
59+ // TODO: mv to func
4460 if i.remoteSource != "" {
4561 remoteSource, err := url.Parse(i.remoteSource)
4662 if err != nil {
@@ -61,18 +77,7 @@
6177 }
6278
6379 // we need to move plandir back to where it should be
64- defer func() {
65- srcPlandir := filepath.Join(downloadPath, i.plandir)
66- destPlandir := filepath.Join(wd, i.plandir)
67- err := os.RemoveAll(destPlandir)
68- if err != nil {
69- log.WithError(err).Error("failed to clean plandir")
70- }
71- err = helper.MoveFile(srcPlandir, destPlandir)
72- if err != nil {
73- log.WithError(err).Error("failed to move plandir")
74- }
75- }()
80+ defer i.CleanRemote(downloadPath, wd)
7681
7782 err = os.Chdir(downloadPath)
7883 if err != nil {
@@ -105,6 +110,24 @@
105110 // Show current plan
106111 newPlan.Logger().Info("๐Ÿ— Plan")
107112
113+ // Diff
114+ err = i.diffing(ctx, newPlan)
115+ if err != nil {
116+ return err
117+ }
118+
119+ // Save new plan
120+ err = newPlan.Export(ctx, i.skipUnchanged)
121+ if err != nil {
122+ return err
123+ }
124+
125+ log.Info("๐Ÿ— Planfile is ready!")
126+
127+ return nil
128+}
129+
130+func (i *Build) diffing(ctx context.Context, p *plan.Plan) error {
108131 switch i.diffMode {
109132 case DiffModeLocal:
110133 oldPlan := plan.New(i.plandir)
@@ -114,24 +137,17 @@
114137 return err
115138 }
116139
117- newPlan.DiffPlan(oldPlan, i.diff.Options)
140+ p.DiffPlan(oldPlan, i.diff.Options)
118141 }
119142
120143 case DiffModeLive:
121144 log.Info("๐Ÿ†š Diff manifests in the kubernetes cluster")
122- newPlan.DiffLive(ctx, i.diff.Options, i.diff.ThreeWayMerge)
145+ p.DiffLive(ctx, i.diff.Options, i.diff.ThreeWayMerge)
123146 case DiffModeNone:
124147 log.Info("๐Ÿ†š Skip diffing")
125148 default:
126149 log.Warnf("๐Ÿ†šโ”Unknown %q diff mode, skipping", i.diffMode)
127150 }
128-
129- err = newPlan.Export(ctx, i.skipUnchanged)
130- if err != nil {
131- return err
132- }
133-
134- log.Info("๐Ÿ— Planfile is ready!")
135151
136152 return nil
137153 }