-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #936 from steinliber/feat-plugin-optimize
feat: support helm plugin default value
- Loading branch information
Showing
18 changed files
with
362 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,20 @@ | ||
package argocd | ||
|
||
import ( | ||
"github.com/devstream-io/devstream/internal/pkg/plugininstaller" | ||
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/helm" | ||
helmCommon "github.com/devstream-io/devstream/pkg/util/helm" | ||
"github.com/devstream-io/devstream/pkg/util/types" | ||
) | ||
|
||
var ( | ||
defaultRepoURL = "https://argoproj.github.io/argo-helm" | ||
defaultRepoName = "argo" | ||
) | ||
|
||
func defaultMissedOption(options plugininstaller.RawOptions) (plugininstaller.RawOptions, error) { | ||
opts, err := helm.NewOptions(options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if opts.Repo.URL == "" { | ||
opts.Repo.URL = defaultRepoURL | ||
} | ||
if opts.Repo.Name == "" { | ||
opts.Repo.Name = defaultRepoName | ||
} | ||
return opts.Encode() | ||
var defaultHelmConfig = helm.Options{ | ||
Chart: helmCommon.Chart{ | ||
ChartName: "argo/argo-cd", | ||
Timeout: "5m", | ||
UpgradeCRDs: types.Bool(true), | ||
Wait: types.Bool(true), | ||
}, | ||
Repo: helmCommon.Repo{ | ||
URL: "https://argoproj.github.io/argo-helm", | ||
Name: "argo", | ||
}, | ||
} |
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
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,13 @@ | ||
package helm_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestPlanmanager(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "PluginInstaller Helm Suite") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package helm_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/devstream-io/devstream/internal/pkg/plugininstaller" | ||
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/helm" | ||
helmCommon "github.com/devstream-io/devstream/pkg/util/helm" | ||
) | ||
|
||
var _ = Describe("Options struct", func() { | ||
var ( | ||
testOpts helm.Options | ||
testChartName string | ||
testRepoName string | ||
testNameSpace string | ||
expectMap map[string]interface{} | ||
emptyBool *bool | ||
) | ||
|
||
BeforeEach(func() { | ||
testChartName = "test_chart" | ||
testRepoName = "test_repo" | ||
testNameSpace = "test_nameSpace" | ||
testOpts = helm.Options{ | ||
Chart: helmCommon.Chart{ | ||
ChartName: testChartName, | ||
Namespace: testNameSpace, | ||
}, | ||
Repo: helmCommon.Repo{ | ||
Name: testRepoName, | ||
}, | ||
} | ||
expectMap = map[string]interface{}{ | ||
"create_namespace": false, | ||
"repo": map[string]interface{}{ | ||
"name": "test_repo", | ||
"url": "", | ||
}, | ||
"chart": map[string]interface{}{ | ||
"version": "", | ||
"release_name": "", | ||
"wait": emptyBool, | ||
"chart_name": "test_chart", | ||
"namespace": "test_nameSpace", | ||
"create_namespace": emptyBool, | ||
"timeout": "", | ||
"upgradeCRDs": emptyBool, | ||
"values_yaml": "", | ||
}, | ||
} | ||
}) | ||
|
||
Context("GetHelmParam method", func() { | ||
It("should pass chart and repo field", func() { | ||
helmParam := testOpts.GetHelmParam() | ||
Expect(helmParam.Chart).Should(Equal(testOpts.Chart)) | ||
Expect(helmParam.Repo).Should(Equal(testOpts.Repo)) | ||
}) | ||
}) | ||
|
||
Context("CheckIfCreateNamespace method", func() { | ||
It("should equal opts config", func() { | ||
Expect(testOpts.CheckIfCreateNamespace()).Should(Equal(testOpts.CreateNamespace)) | ||
}) | ||
}) | ||
|
||
Context("GetNamespace method", func() { | ||
It("should return chart's nameSpace", func() { | ||
Expect(testOpts.GetNamespace()).Should(Equal(testOpts.Chart.Namespace)) | ||
}) | ||
}) | ||
|
||
Context("GetReleaseName method", func() { | ||
It("should return chart's ReleaseName", func() { | ||
Expect(testOpts.GetReleaseName()).Should(Equal(testOpts.Chart.ReleaseName)) | ||
}) | ||
}) | ||
|
||
Context("Encode method", func() { | ||
It("should return opts map", func() { | ||
result, err := testOpts.Encode() | ||
Expect(err).Error().ShouldNot(HaveOccurred()) | ||
Expect(result).Should(Equal(expectMap)) | ||
}) | ||
}) | ||
}) | ||
|
||
var _ = Describe("NewOptions func", func() { | ||
|
||
var ( | ||
inputOptions plugininstaller.RawOptions | ||
testRepoName string | ||
testChartName string | ||
) | ||
|
||
BeforeEach(func() { | ||
testRepoName = "test_repo" | ||
testChartName = "test_chart" | ||
inputOptions = map[string]interface{}{ | ||
"repo": map[string]interface{}{ | ||
"name": testRepoName, | ||
}, | ||
"chart": map[string]interface{}{ | ||
"chart_name": testChartName, | ||
}, | ||
} | ||
}) | ||
|
||
It("should work normal", func() { | ||
opts, err := helm.NewOptions(inputOptions) | ||
Expect(err).Error().ShouldNot(HaveOccurred()) | ||
Expect(opts.Chart.ChartName).Should(Equal(testChartName)) | ||
Expect(opts.Repo.Name).Should(Equal(testRepoName)) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package helm_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/devstream-io/devstream/internal/pkg/plugininstaller" | ||
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/helm" | ||
helmCommon "github.com/devstream-io/devstream/pkg/util/helm" | ||
"github.com/devstream-io/devstream/pkg/util/types" | ||
) | ||
|
||
var _ = Describe("Validate func", func() { | ||
var testOption plugininstaller.RawOptions | ||
|
||
When("options is not valid", func() { | ||
BeforeEach(func() { | ||
testOption = map[string]interface{}{ | ||
"chart": map[string]string{}, | ||
"repo": map[string]string{}, | ||
} | ||
}) | ||
It("should return error", func() { | ||
_, err := helm.Validate(testOption) | ||
Expect(err).Error().Should(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
When("options is valid", func() { | ||
BeforeEach(func() { | ||
testOption = map[string]interface{}{ | ||
"chart": map[string]string{ | ||
"chart_name": "test", | ||
}, | ||
"repo": map[string]string{ | ||
"url": "http://test.com", | ||
"name": "test", | ||
}, | ||
} | ||
}) | ||
It("should return success", func() { | ||
opt, err := helm.Validate(testOption) | ||
Expect(err).Error().ShouldNot(HaveOccurred()) | ||
Expect(opt).ShouldNot(BeEmpty()) | ||
}) | ||
}) | ||
}) | ||
|
||
var _ = Describe("SetDefaultConfig func", func() { | ||
var ( | ||
testChartName string | ||
testRepoURL string | ||
testRepoName string | ||
testBool *bool | ||
defaultConfig helm.Options | ||
testOptions plugininstaller.RawOptions | ||
expectChart map[string]interface{} | ||
expectRepo map[string]interface{} | ||
) | ||
BeforeEach(func() { | ||
testChartName = "test_chart" | ||
testRepoName = "test_repo" | ||
testRepoURL = "http://test.com" | ||
testBool = types.Bool(true) | ||
testOptions = map[string]interface{}{ | ||
"chart": map[string]string{}, | ||
"repo": map[string]string{}, | ||
} | ||
defaultConfig = helm.Options{ | ||
Chart: helmCommon.Chart{ | ||
ChartName: testChartName, | ||
Wait: testBool, | ||
UpgradeCRDs: testBool, | ||
CreateNamespace: testBool, | ||
}, | ||
Repo: helmCommon.Repo{ | ||
URL: testRepoURL, | ||
Name: testRepoName, | ||
}, | ||
} | ||
expectChart = map[string]interface{}{ | ||
"chart_name": testChartName, | ||
"wait": testBool, | ||
"namespace": "", | ||
"version": "", | ||
"release_name": "", | ||
"values_yaml": "", | ||
"timeout": "", | ||
"create_namespace": testBool, | ||
"upgradeCRDs": testBool, | ||
} | ||
expectRepo = map[string]interface{}{ | ||
"url": testRepoURL, | ||
"name": testRepoName, | ||
} | ||
}) | ||
It("should update default value", func() { | ||
updateFunc := helm.SetDefaultConfig(&defaultConfig) | ||
o, err := updateFunc(testOptions) | ||
Expect(err).Error().ShouldNot(HaveOccurred()) | ||
oRepo, exist := o["repo"] | ||
Expect(exist).Should(BeTrue()) | ||
oChart, exist := o["chart"] | ||
Expect(exist).Should(BeTrue()) | ||
Expect(oRepo).Should(Equal(expectRepo)) | ||
Expect(oChart).Should(Equal(expectChart)) | ||
}) | ||
}) |
Oops, something went wrong.