Skip to content

Commit 14d090a

Browse files
authored
Merge pull request #43 from darkstarmv/templates
update helm and helmdiff versions
2 parents 67a487b + f45a502 commit 14d090a

File tree

4 files changed

+65
-16
lines changed

4 files changed

+65
-16
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM golang:1.15-alpine as builder
2-
ENV DESIRED_VERSION=v3.8.0
3-
ENV HELM_DIFF_VERSION=v3.4.0
2+
ENV DESIRED_VERSION=v3.9.0
3+
ENV HELM_DIFF_VERSION=v3.5.0
44
WORKDIR /go/src/github.com/target/impeller
55
COPY . .
66
ENV GO111MODULE=on
@@ -21,7 +21,7 @@ RUN cd /tmp && \
2121
RUN /usr/local/bin/helm plugin install https://github.com/databus23/helm-diff --version ${HELM_DIFF_VERSION}
2222

2323
FROM alpine:latest
24-
ENV KUBECTL_VERSION=v1.23.4
24+
ENV KUBECTL_VERSION=v1.23.9
2525
RUN apk add ca-certificates
2626
RUN wget -O /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl && \
2727
chmod +x /usr/bin/kubectl

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,22 @@ Manages Helm charts running in Kubernetes clusters.
2626
## How to use
2727
### Command line
2828
1. Deployment command:
29-
`impeller --cluster-config-path=./clusters/my-cluster.yaml --kube-config="$(cat ~/.kube/config)" --kube-context my-kubernetes-context`
29+
30+
```bash
31+
impeller --cluster-config-path=./clusters/my-cluster.yaml --kube-config="$(cat ~/.kube/config)" --kube-context my-kubernetes-context
32+
```
33+
34+
or using `base64` encoded `kubeconfig`:
35+
36+
```bash
37+
impeller --cluster-config-path=./clusters/my-cluster.yaml --kube-config="$(base64 ~/.kube/config)" --kube-context my-kubernetes-context --kube-config-base64=true
38+
```
3039
2. Dry run command:
31-
`impeller --cluster-config-path=./clusters/my-cluster.yaml --kube-config="$(cat ~/.kube/config)" --kube-context my-kubernetes-context --dry-run`
40+
```bash
41+
impeller --cluster-config-path=./clusters/my-cluster.yaml --kube-config="$(cat ~/.kube/config)" --kube-context my-kubernetes-context --dry-run
42+
```
3243
By default override values are hidden with `--dry-run` option. You can add `showValue: true` to your release to enable printout:
33-
```
44+
```bash
3445
releases:
3546
- name: test-release
3647
namespace: kube-system
@@ -41,11 +52,17 @@ releases:
4152
value: 1.6.0
4253
```
4354
3. Diff run command:
44-
`impeller --cluster-config-path=./clusters/my-cluster.yaml --kube-config="$(cat ~/.kube/config)" --kube-context my-kubernetes-context --diff-run`
55+
```bash
56+
impeller --cluster-config-path=./clusters/my-cluster.yaml --kube-config="$(cat ~/.kube/config)" --kube-context my-kubernetes-context --diff-run
57+
```
4558
4. Generate Audit report file:
46-
`impeller --cluster-config-path=./clusters --audit=true`
59+
```bash
60+
impeller --cluster-config-path=./clusters --audit=true
61+
```
4762
or
48-
`impeller --cluster-config-path=./clusters --audit=true --audit-file=./myreport.csv`
63+
```bash
64+
impeller --cluster-config-path=./clusters --audit=true --audit-file=./myreport.csv
65+
```
4966

5067
### Drone pipeline
5168
#### Simple example

main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func main() {
3232
Usage: "Kubernetes configuration file",
3333
EnvVar: "KUBE_CONFIG,PLUGIN_KUBE_CONFIG,PARAMETER_KUBE_CONFIG",
3434
},
35+
cli.BoolFlag{
36+
Name: "kube-config-base64",
37+
Usage: "Flag true/false, base64 encoded kubeconfig",
38+
EnvVar: "KUBE_CONFIG_BASE64,PLUGIN_KUBE_CONFIG_BASE64,PARAMETER_KUBE_CONFIG_BASE64",
39+
},
3540
cli.StringFlag{
3641
Name: "kube-context",
3742
Usage: "Kubernetes configuration context to use",
@@ -105,6 +110,7 @@ func run(ctx *cli.Context) error {
105110
ClustersList: clist,
106111
ValueFiles: ctx.StringSlice("value-files"),
107112
KubeConfig: ctx.String("kube-config"),
113+
KubeConfigBase64: ctx.Bool("kube-config-base64"),
108114
KubeContext: ctx.String("kube-context"),
109115
Dryrun: ctx.Bool("dry-run"),
110116
Diffrun: ctx.Bool("diff-run"),

plugin.go

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"encoding/base64"
45
"fmt"
56
"io/ioutil"
67
"log"
@@ -30,6 +31,8 @@ type Plugin struct {
3031
ClustersList report.Clusters
3132
ValueFiles []string
3233
KubeConfig string
34+
KubeConfigFile string
35+
KubeConfigBase64 bool
3336
KubeContext string
3437
Dryrun bool
3538
Diffrun bool
@@ -336,22 +339,45 @@ func (p *Plugin) templateChart(release *types.Release) (string, error) {
336339
}
337340

338341
func (p *Plugin) setupKubeconfig() error {
339-
// Providing a Kubernetes config is mostly used for Drone support.
340-
// If not provided, the default `kubectl` search path is used.
341-
// WARNING: this may overwrite your config if it already exists.
342+
var err error
343+
byteData := []byte{}
344+
342345
if p.KubeConfig != "" {
343-
log.Println("Creating Kubernetes config")
344-
if err := ioutil.WriteFile(kubeConfig, []byte(p.KubeConfig), 0600); err != nil {
346+
p.KubeConfigFile = kubeConfig + "-" + p.KubeContext
347+
log.Println("Creating Kubernetes configfile" + p.KubeConfigFile)
348+
if p.KubeConfigBase64 {
349+
log.Println("configfile is base64 encoded")
350+
byteData, err = base64.StdEncoding.DecodeString(p.KubeConfig)
351+
if err != nil {
352+
log.Fatalf("err %v", err)
353+
}
354+
355+
} else {
356+
log.Println("configfile is not encoded")
357+
byteData = []byte(p.KubeConfig)
358+
}
359+
360+
if err := ioutil.WriteFile(p.KubeConfigFile, byteData, 0600); err != nil {
345361
return fmt.Errorf("error creating kube config file: %v", err)
346362
}
363+
log.Println("setting KUBECONFIG environment variable to: " + p.KubeConfigFile)
364+
err := os.Setenv("KUBECONFIG", p.KubeConfigFile)
365+
if err != nil {
366+
log.Fatalf("err %v", err)
367+
}
347368
}
348369

349370
// Providing a Kubernetes config context is mostly used for Drone support.
350371
// If not provided, the current context from Kubernetes config is used.
351372
if p.KubeContext != "" {
352373
log.Println("Setting Kubernetes context")
353-
cmd := exec.Command(kubectlBin, "config", "use-context", p.KubeContext)
354-
if err := utils.Run(cmd, true); err != nil {
374+
cb := commandbuilder.CommandBuilder{Name: kubectlBin}
375+
cb.Add(commandbuilder.Arg{Type: commandbuilder.ArgTypeRaw, Value: "config"})
376+
cb.Add(commandbuilder.Arg{Type: commandbuilder.ArgTypeRaw, Value: "use-context"})
377+
cb.Add(commandbuilder.Arg{Type: commandbuilder.ArgTypeRaw, Value: p.KubeContext})
378+
cb.Add(commandbuilder.Arg{Type: commandbuilder.ArgTypeLongParam, Name: "kubeconfig", Value: p.KubeConfigFile})
379+
cmd := cb.Command()
380+
if err := utils.Run(cmd, false); err != nil {
355381
return fmt.Errorf("error setting Kubernetes context: %v", err)
356382
}
357383
}

0 commit comments

Comments
 (0)