|
1 | 1 | package action |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | | - "strings" |
6 | | - "time" |
7 | | - |
8 | 4 | "github.com/redhat-cop/oc-helm/pkg/client" |
9 | | - "github.com/redhat-cop/oc-helm/pkg/utils" |
10 | | - "helm.sh/helm/v3/pkg/repo" |
11 | 5 |
|
12 | 6 | "github.com/redhat-cop/oc-helm/pkg/options" |
13 | 7 | ) |
@@ -43,85 +37,13 @@ func (i *InstallAction) BuildHelmChartClient() error { |
43 | 37 |
|
44 | 38 | func (i *InstallAction) Run(releaseName string, chartReference string) error { |
45 | 39 |
|
46 | | - index, err := i.helmChartClient.GetIndex() |
47 | | - |
48 | | - if err != nil { |
49 | | - return err |
50 | | - } |
51 | | - |
52 | | - index.SortEntries() |
53 | | - |
54 | | - chartReferenceParts := strings.Split(chartReference, "/") |
55 | | - |
56 | | - repository := chartReferenceParts[0] |
57 | | - chartName := chartReferenceParts[1] |
58 | | - |
59 | | - consoleChartName := utils.CreateRepositoryIndexKey(repository, chartName) |
60 | | - |
61 | | - charts := index.Entries[consoleChartName] |
62 | | - |
63 | | - if charts == nil { |
64 | | - return fmt.Errorf("Error: Chart '%s' does not exist", chartReference) |
| 40 | + helmChartInstall := &HelmChartInstall{ |
| 41 | + releaseName: releaseName, |
| 42 | + chartReference: chartReference, |
| 43 | + commandLineOptions: i.commandLineOptions, |
| 44 | + helmChartClient: i.helmChartClient, |
65 | 45 | } |
66 | 46 |
|
67 | | - chartVersion := i.getChartVersion(charts) |
68 | | - |
69 | | - if chartVersion == nil { |
70 | | - |
71 | | - if i.commandLineOptions.Version != "" { |
72 | | - return fmt.Errorf("Chart '%s' with version '%s' not found", chartReference, i.commandLineOptions.Version) |
73 | | - } else { |
74 | | - return fmt.Errorf("Chart '%s' not found", chartReference) |
75 | | - } |
76 | | - |
77 | | - } |
78 | | - |
79 | | - if len(chartVersion.URLs) == 0 { |
80 | | - return fmt.Errorf("Unable to locate Chart URL") |
81 | | - } |
82 | | - |
83 | | - chartURL := chartVersion.URLs[0] |
84 | | - |
85 | | - values, err := utils.MergeValues(i.commandLineOptions) |
86 | | - |
87 | | - if err != nil { |
88 | | - return err |
89 | | - } |
90 | | - |
91 | | - release, err := i.helmChartClient.CreateRelease(releaseName, chartURL, values) |
92 | | - |
93 | | - if err != nil { |
94 | | - return err |
95 | | - } |
96 | | - |
97 | | - fmt.Fprintf(i.commandLineOptions.Streams.Out, "NAME: %s\n", release.Name) |
98 | | - fmt.Fprintf(i.commandLineOptions.Streams.Out, "NAMESPACE: %s\n", release.Namespace) |
99 | | - if !release.Info.LastDeployed.IsZero() { |
100 | | - fmt.Fprintf(i.commandLineOptions.Streams.Out, "LAST DEPLOYED: %s\n", release.Info.LastDeployed.Format(time.ANSIC)) |
101 | | - } |
102 | | - fmt.Fprintf(i.commandLineOptions.Streams.Out, "STATUS: %s\n", release.Info.Status.String()) |
103 | | - fmt.Fprintf(i.commandLineOptions.Streams.Out, "REVISION: %d\n", release.Version) |
104 | | - |
105 | | - return nil |
106 | | - |
107 | | -} |
108 | | - |
109 | | -func (i *InstallAction) getChartVersion(charts repo.ChartVersions) *repo.ChartVersion { |
110 | | - |
111 | | - if len(charts) == 0 { |
112 | | - return nil |
113 | | - } |
114 | | - |
115 | | - if i.commandLineOptions.Version == "" { |
116 | | - return charts[0] |
117 | | - } |
118 | | - |
119 | | - for _, chart := range charts { |
120 | | - if chart.Version == i.commandLineOptions.Version { |
121 | | - return chart |
122 | | - } |
123 | | - } |
124 | | - |
125 | | - return nil |
| 47 | + return installChart(helmChartInstall) |
126 | 48 |
|
127 | 49 | } |
0 commit comments