Skip to content

Commit

Permalink
Add install chart endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Anirudh M authored and kaustubhkurve committed Aug 6, 2020
1 parent d1d5110 commit 21325c1
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 98 deletions.
13 changes: 13 additions & 0 deletions cmd/endpoints/install/installcontract.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package install

type InstallRequest struct {
RequestID string
ReleaseName string
ReleaseNamespace string
ChartPath string
}

type InstallReponse struct {
Status bool
ReleaseStatus string
}
67 changes: 67 additions & 0 deletions cmd/endpoints/install/installhandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package install

import (
"encoding/json"
"fmt"
"net/http"

"helm.sh/helm/v3/cmd/servercontext"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
)

func Handler() http.Handler {
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {

res.Header().Set("Content-Type", "application/json")
defer req.Body.Close()

var request InstallRequest
decoder := json.NewDecoder(req.Body)
decoder.UseNumber()

if err := decoder.Decode(&request); err != nil {
fmt.Printf("error in request: %v", err)
return
}

request.RequestID = req.Header.Get("Request-Id")
request.ReleaseName = req.Header.Get("Release-Name")
request.ReleaseNamespace = req.Header.Get("Release-Namespace")
request.ChartPath = req.Header.Get("Chart-Path")

install := action.NewInstall(servercontext.App().ActionConfig)
install.ReleaseName = request.ReleaseName
install.Namespace = request.ReleaseNamespace

cp, err := install.ChartPathOptions.LocateChart(request.ChartPath, servercontext.App().Config)
if err != nil {
fmt.Printf("error in locating chart: %v", err)
return
}

var requestedChart *chart.Chart
if requestedChart, err = loader.Load(cp); err != nil {
fmt.Printf("error in loading chart: %v", err)
return
}

var vals map[string]interface{}
release, err := install.Run(requestedChart, vals)
if err != nil {
fmt.Printf("error in installing chart: %v", err)
return
}

response := InstallReponse{Status: true, ReleaseStatus: string(release.Info.Status)}

payload, err := json.Marshal(response)
if err != nil {
fmt.Printf("error parsing response %v", err)
return
}

res.Write(payload)
})
}
4 changes: 2 additions & 2 deletions cmd/endpoints/list/listhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"net/http"

"helm.sh/helm/v3/cmd/servercontext"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/servercontext"
)

func Handler() http.Handler {
Expand All @@ -31,7 +31,7 @@ func Handler() http.Handler {
list.SetStateMask()
results, err := list.Run()
if err != nil {
fmt.Print("error while running helm list")
fmt.Printf("error while running helm list %v", err)
}

var helmReleases []HelmRelease
Expand Down
2 changes: 2 additions & 0 deletions cmd/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"

"helm.sh/helm/v3/cmd/endpoints/install"
"helm.sh/helm/v3/cmd/endpoints/list"
"helm.sh/helm/v3/cmd/endpoints/ping"
"helm.sh/helm/v3/cmd/servercontext"
Expand All @@ -18,6 +19,7 @@ func startServer(appconfig *servercontext.Application) {
router := http.NewServeMux()
router.Handle("/ping", ping.Handler())
router.Handle("/list", list.Handler())
router.Handle("/install", install.Handler())

err := http.ListenAndServe(fmt.Sprintf(":%d", 8080), router)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
helm.sh/helm v1.2.1 h1:Jrn7kKQqQ/hnFWZEX+9pMFvYqFexkzrBnGqYBmIph7c=
helm.sh/helm v2.16.7+incompatible h1:3Hp8GLmr6uuBNYGmTQ4p3J4N6xKqxvFDswxHAOposlM=
helm.sh/helm v2.16.9+incompatible h1:31XFG6KPAbh2A/oDgIaQFR8L63vtyxN7tOt64URUJvY=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/values/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Options struct {
// MergeValues merges values from files specified via -f/--values and directly
// via --set, --set-string, or --set-file, marshaling them to YAML
func (opts *Options) MergeValues(p getter.Providers) (map[string]interface{}, error) {

base := map[string]interface{}{}

// User specified a values files via -f/--values
Expand Down
42 changes: 0 additions & 42 deletions pkg/http/install.go

This file was deleted.

54 changes: 0 additions & 54 deletions pkg/http/repo_update.go

This file was deleted.

0 comments on commit 21325c1

Please sign in to comment.