Skip to content

Commit

Permalink
Merge pull request #9 from evoila/release-0.1.0
Browse files Browse the repository at this point in the history
release-0.1.0
  • Loading branch information
pgrafmueller authored Jun 28, 2022
2 parents 1a8535e + 4c16684 commit a01cfa0
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 28 deletions.
22 changes: 17 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
FROM centos:7
FROM golang:1.17.7-alpine3.15 as build

ENV GIN_MODE=release
RUN apk add --no-cache make gcc musl-dev

COPY *.go go.mod go.sum /build-dir/
COPY Makefile /build-dir/
WORKDIR /build-dir
RUN make build


FROM alpine:3

COPY config-example.yaml /config.yaml
COPY bin/helm-wrapper /helm-wrapper
WORKDIR /app

COPY --from=build build-dir/bin/helm-wrapper helm-wrapper
COPY config.yaml config.yaml

ENV GIN_MODE=release
CMD [ "./helm-wrapper" ]

CMD [ "/helm-wrapper" ]
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ build-windows:

# build docker image
build-docker:
GOOS=linux GOARCH=amd64 go build -ldflags ${LDFLAGS} -o bin/${BINARY_NAME}
docker build -t helm-wrapper:`git rev-parse --short HEAD` .

.PHONY: golangci-lint
Expand Down
35 changes: 16 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,22 @@ PUT Body (optional):
- `GET`
- `/api/namespaces/:namespace/releases`

Body:
| Params | Helm list equivalent | Default
| :- | :- | :- |
| all | `--all` | false |
| all_namespaces | `--all-namespaces` | false |
| by_date | `--date` | false |
| sort_reverse | `--reverse` | false |
| limit | `--max` | no limit |
| offset | `--offset` | no offset |
| filter | `--filter` | "" |
| uninstalled | `--uninstalled` | false |
| uninstalling | `--uninstalling` | false |
| superseded | `--superseded` | false |
| failed | `--failed` | false |
| deployed | `--deployed` | false |
| pending | `--pending` | false |

``` json
{
"all": false, // `--all`
"all_namespaces": false, // `--all-namespaces`
"by_date": false, // `--date`
"sort_reverse": false, // `--reverse`
"limit": , // `--max`
"offset": , // `--offset`
"filter": "", // `--filter`
"uninstalled": false, // `--uninstalled`
"uninstalling": false, // `--uninstalling`
"superseded": false, // `--superseded`
"failed": false, // `--failed`
"deployed": false, // `--deployed`
"pending": false // `--pending`
}
```

+ helm get
- `GET`
Expand Down Expand Up @@ -215,7 +212,7 @@ type respBody struct {
```
make build
make build-linux // build helm-wrapper Linux binary
make build-docker // build docker image with helm-wrapper
docker build -t helm-wrapper . // build docker image with helm-wrapper
```

#### helm-wrapper help
Expand Down
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uploadPath: /tmp/charts
108 changes: 105 additions & 3 deletions releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,21 @@ func uninstallRelease(c *gin.Context) {
respErr(c, err)
return
}

client := action.NewUninstall(actionConfig)
_, err = client.Run(name)

// run a dry run first to see if any errors pop up
// the dry run inside the helm client only checks if the release exists, i.e. not a "real" dry run
glog.Infoln("uninstall dry run")
err = uninstall(true, client, name)
if err != nil {
respErr(c, err)
return
}

glog.Infoln("actual uninstall")
// run the actual uninstall
err = uninstall(false, client, name)
if err != nil {
respErr(c, err)
return
Expand All @@ -425,6 +438,21 @@ func uninstallRelease(c *gin.Context) {
respOK(c, nil)
}

func uninstall(dryRun bool, client *action.Uninstall, name string) error {
client.DryRun = dryRun
_, helmErr := client.Run(name)

if helmErr != nil {
if dryRun {
return errors.New("dry run failed with: " + helmErr.Error())
}

return errors.New("actual uninstall failed with: " + helmErr.Error())
}

return helmErr
}

func rollbackRelease(c *gin.Context) {
name := c.Param("release")
namespace := c.Param("namespace")
Expand Down Expand Up @@ -562,11 +590,85 @@ func listReleases(c *gin.Context) {
namespace := c.Param("namespace")
kubeContext := c.Query("kube_context")
var options releaseListOptions
err := c.ShouldBindJSON(&options)
if err != nil && err != io.EOF {
var err error
options.All, err = strconv.ParseBool(c.DefaultQuery("all", "false"))
if err != nil {
respErr(c, err)
return
}

options.AllNamespaces, err = strconv.ParseBool(c.DefaultQuery("all_namespaces", "false"))
if err != nil {
respErr(c, err)
return
}

options.ByDate, err = strconv.ParseBool(c.DefaultQuery("by_date", "false"))
if err != nil {
respErr(c, err)
return
}

options.SortReverse, err = strconv.ParseBool(c.DefaultQuery("sort_reverse", "false"))
if err != nil {
respErr(c, err)
return
}

options.Limit, err = strconv.Atoi(c.DefaultQuery("limit", "0"))
if err != nil {
respErr(c, err)
return
}

options.Offset, err = strconv.Atoi(c.DefaultQuery("offset", "0"))
if err != nil {
respErr(c, err)
return
}

options.Filter = c.Query("filter")
if err != nil {
respErr(c, err)
return
}

options.Uninstalled, err = strconv.ParseBool(c.DefaultQuery("uninstalled", "false"))
if err != nil {
respErr(c, err)
return
}

options.Superseded, err = strconv.ParseBool(c.DefaultQuery("superseded", "false"))
if err != nil {
respErr(c, err)
return
}

options.Uninstalling, err = strconv.ParseBool(c.DefaultQuery("uninstalling", "false"))
if err != nil {
respErr(c, err)
return
}

options.Deployed, err = strconv.ParseBool(c.DefaultQuery("deployed", "false"))
if err != nil {
respErr(c, err)
return
}

options.Failed, err = strconv.ParseBool(c.DefaultQuery("failed", "false"))
if err != nil {
respErr(c, err)
return
}

options.Pending, err = strconv.ParseBool(c.DefaultQuery("pending", "false"))
if err != nil {
respErr(c, err)
return
}

actionConfig, err := actionConfigInit(InitKubeInformation(namespace, kubeContext))
if err != nil {
respErr(c, err)
Expand Down
1 change: 1 addition & 0 deletions version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0

0 comments on commit a01cfa0

Please sign in to comment.