-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
618e420
commit 8a940fa
Showing
13 changed files
with
294 additions
and
221 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
_dist/ | ||
bin/ | ||
vendor/ | ||
*.swp |
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,47 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"helm.sh/helm/v3/pkg/http/api/logger" | ||
) | ||
|
||
type InstallRequest struct { | ||
Name string `json:"name"` | ||
Namespace string `json:"namespace"` | ||
Chart string `json:"chart"` | ||
Values map[string]interface{} `json:"values"` | ||
} | ||
|
||
type InstallResponse struct { | ||
Error string `json:"error,omitempty"` | ||
Status string | ||
} | ||
|
||
// RODO: we could use interface as well if everything's in same package | ||
func Install(svc Service) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
|
||
var req InstallRequest | ||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil { | ||
logger.Errorf("[Install] error decoding request: %v", err) | ||
w.WriteHeader(http.StatusBadRequest) | ||
return | ||
} | ||
defer r.Body.Close() | ||
var response InstallResponse | ||
res, err := svc.Install(r.Context(), req.Chart, req.Values) | ||
if err != nil { | ||
response.Error = err.Error() | ||
logger.Errorf("[Install] error while installing chart: %v", err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
response.Status = res.status | ||
if err := json.NewEncoder(w).Encode(response); err != nil { | ||
logger.Errorf("[Install] error writing response %v", err) | ||
return | ||
} | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
package logger | ||
|
||
import ( | ||
"go.uber.org/zap" | ||
) | ||
|
||
var log *zap.SugaredLogger | ||
|
||
func Debugf(fmt string, args ...interface{}) { | ||
log.Debugf(fmt, args...) | ||
} | ||
|
||
func Fatalf(fmt string, args ...interface{}) { | ||
log.Fatalf(fmt, args...) | ||
} | ||
|
||
func Errorf(fmt string, args ...interface{}) { | ||
log.Errorf(fmt, args...) | ||
} | ||
|
||
func Infof(fmt string, args ...interface{}) { | ||
log.Infof(fmt, args...) | ||
} | ||
|
||
func Setup(level string) { | ||
//TODO: map from env config | ||
var zlog *zap.Logger | ||
switch level { | ||
case "debug": | ||
zlog, _ = zap.NewDevelopment() | ||
case "none": | ||
zlog = zap.NewNop() | ||
default: | ||
zlog, _ = zap.NewProduction() | ||
} | ||
// This condition is to avoid race conditions in test cases | ||
if log == nil { | ||
log = zlog.Sugar() | ||
} | ||
} |
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,71 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"helm.sh/helm/v3/pkg/action" | ||
"helm.sh/helm/v3/pkg/chart" | ||
"helm.sh/helm/v3/pkg/chart/loader" | ||
"helm.sh/helm/v3/pkg/cli" | ||
"helm.sh/helm/v3/pkg/cli/values" | ||
"helm.sh/helm/v3/pkg/getter" | ||
"helm.sh/helm/v3/pkg/servercontext" | ||
) | ||
|
||
type Service struct { | ||
config *cli.EnvSettings | ||
install *action.Install | ||
} | ||
|
||
type chartValues map[string]interface{} | ||
|
||
type installResult struct { | ||
status string | ||
} | ||
|
||
func (s Service) getValues(vals chartValues) (chartValues, error) { | ||
valueOpts := &values.Options{} | ||
//valueOpts.Values = append(valueOpts.Values, vals) | ||
return valueOpts.MergeValues(getter.All(servercontext.App().Config)) | ||
} | ||
|
||
func (s Service) Install(ctx context.Context, chartName string, values chartValues) (installResult, error) { | ||
var result installResult | ||
chart, err := s.loadChart(chartName) | ||
if err != nil { | ||
return result, err | ||
} | ||
vals, err := s.getValues(values) | ||
if err != nil { | ||
return result, fmt.Errorf("error merging values: %v", err) | ||
} | ||
release, err := s.install.Run(chart, vals) | ||
if err != nil { | ||
return result, fmt.Errorf("error in installing chart: %v", err) | ||
} | ||
if release.Info != nil { | ||
result.status = release.Info.Status.String() | ||
} | ||
return result, nil | ||
} | ||
|
||
func (s Service) loadChart(chartName string) (*chart.Chart, error) { | ||
cp, err := s.install.ChartPathOptions.LocateChart(chartName, s.config) | ||
if err != nil { | ||
return nil, fmt.Errorf("error in locating chart: %v", err) | ||
} | ||
var requestedChart *chart.Chart | ||
if requestedChart, err = loader.Load(cp); err != nil { | ||
return nil, fmt.Errorf("error loading chart: %v", err) | ||
} | ||
return requestedChart, nil | ||
} | ||
|
||
func NewService(cfg *cli.EnvSettings) Service { | ||
return Service{ | ||
config: cfg, | ||
//TODO: not sure why this's needed, but we can refactor later,could be passed as param | ||
install: action.NewInstall(servercontext.App().ActionConfig), | ||
} | ||
} |
Oops, something went wrong.