Repository: grafana/tanka (go)

Issue:
tk diff -t requires the resource type to be lower case
when doing `tk show` it shows me resource types, such as `ConfigMap` in camel case. but when i try to do `tk diff` and use the `-t` parameter to select one specific resource i need to specify the resource type in lower case (`configmap`) for it to work, when i write it `ConfigMap` then `tk` seems to not find the resource. I think this should be case insensitive.

Pull request:
fix(cli): make -t case insensitive
was not before, but should be for better UX

Fixes #126 

Patch:
diff --git a/.drone/docker-manifest.tmpl b/.drone/docker-manifest.tmpl
index 688dc38b..2ec7d492 100644
--- a/.drone/docker-manifest.tmpl
+++ b/.drone/docker-manifest.tmpl
@@ -1,4 +1,4 @@
-image: grafana/tanka:{{#if build.tag}}{{build.tag}}{{else}}latest{{/if}}
+image: grafana/tanka:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
 {{#if build.tags}}
 tags:
 {{#each build.tags}}
@@ -6,16 +6,16 @@ tags:
 {{/each}}
 {{/if}}
 manifests:
-  - image: grafana/tanka:{{#if build.tag}}{{build.tag}}-{{/if}}amd64
+  - image: grafana/tanka:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64
     platform:
       architecture: amd64
       os: linux
-  - image: grafana/tanka:{{#if build.tag}}{{build.tag}}-{{/if}}arm64
+  - image: grafana/tanka:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64
     platform:
       architecture: arm64
       os: linux
       variant: v8
-  - image: grafana/tanka:{{#if build.tag}}{{build.tag}}-{{/if}}arm
+  - image: grafana/tanka:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm
     platform:
       architecture: arm
       os: linux
diff --git a/.drone/drone.yml b/.drone/drone.yml
index ce504245..56d62c82 100644
--- a/.drone/drone.yml
+++ b/.drone/drone.yml
@@ -62,7 +62,7 @@ steps:
     api_key:
       from_secret: GITHUB_TOKEN
     files: dist/*
-    note: "This is release ${DRONE_TAG} of Tanka (`tk`). Check out the [CHANGELOG](CHANGELOG.md) for detailed release notes.\n## Install instructions\n\n#### Binary:\n```bash\n# download the binary (adapt os and arch as needed)\n$ curl -fSL -o \"/usr/local/bin/tk\" \"https://github.com/sh0rez/tanka/releases/download/${DRONE_TAG}/tk-linux-amd64\"\n\n# make it executable\n$ chmod a+x \"/usr/local/bin/tk\"\n\n# have fun :)\n$ tk --help\n```\n\n#### Docker container:\nhttps://hub.docker.com/r/grafana/tanka\n```bash\n$ docker pull grafana/tanka:${DRONE_TAG}\n```\n"
+    note: "This is release ${DRONE_TAG} of Tanka (`tk`). Check out the [CHANGELOG](CHANGELOG.md) for detailed release notes.\n## Install instructions\n\n#### Binary:\n```bash\n# download the binary (adapt os and arch as needed)\n$ curl -fSL -o \"/usr/local/bin/tk\" \"https://github.com/sh0rez/tanka/releases/download/${DRONE_TAG}/tk-linux-amd64\"\n\n# make it executable\n$ chmod a+x \"/usr/local/bin/tk\"\n\n# have fun :)\n$ tk --help\n```\n\n#### Docker container:\nhttps://hub.docker.com/r/grafana/tanka\n```bash\n$ docker pull grafana/tanka:${DRONE_TAG#v}\n```\n"
     title: ${DRONE_TAG}
 
 volumes:
diff --git a/.drone/release-note.md b/.drone/release-note.md
index 19cd74d9..54ee25c2 100644
--- a/.drone/release-note.md
+++ b/.drone/release-note.md
@@ -16,5 +16,5 @@ $ tk --help
 #### Docker container:
 https://hub.docker.com/r/grafana/tanka
 ```bash
-$ docker pull grafana/tanka:${DRONE_TAG}
+$ docker pull grafana/tanka:${DRONE_TAG#v}
 ```
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2d7ab68f..df2f1abb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
 # Changelog
 
+## 0.6.1 (2020-01-06)
+First release of the new year! This one is a quick patch that lived on master
+for some time, fixing an issue with the recent "missing namespaces" enhancement
+leading to `apply` being impossible when no namespace is included in Jsonnet.
+
+More to come soon :D
+
 ## 0.6.0 (2019-11-27)
 It has been quite some time since the last release during which Tanka has become
 much more mature, especially regarding the code quality and structure.
diff --git a/cmd/tk/workflow.go b/cmd/tk/workflow.go
index 67aa6273..1fab26d8 100644
--- a/cmd/tk/workflow.go
+++ b/cmd/tk/workflow.go
@@ -5,13 +5,13 @@ import (
 	"log"
 	"os"
 	"regexp"
-	"strings"
 
 	"github.com/posener/complete"
 	"github.com/spf13/cobra"
 	"github.com/spf13/pflag"
 
 	"github.com/grafana/tanka/pkg/cli/cmp"
+	"github.com/grafana/tanka/pkg/kubernetes/util"
 	"github.com/grafana/tanka/pkg/tanka"
 )
 
@@ -136,17 +136,10 @@ func showCmd() *cobra.Command {
 	return cmd
 }
 
-// stringsToRegexps compiles each string to a regular expression
-func stringsToRegexps(strs []string) (exps []*regexp.Regexp) {
-	exps = make([]*regexp.Regexp, 0, len(strs))
-	for _, raw := range strs {
-		// surround the regular expression with start and end markers
-		s := fmt.Sprintf(`^%s$`, raw)
-		exp, err := regexp.Compile(s)
-		if err != nil {
-			log.Fatalf("%s.\nSee https://tanka.dev/targets/#regular-expressions for details on regular expressions.", strings.Title(err.Error()))
-		}
-		exps = append(exps, exp)
+func stringsToRegexps(exps []string) []*regexp.Regexp {
+	regexs, err := util.CompileTargetExps(exps)
+	if err != nil {
+		log.Fatalln(err)
 	}
-	return exps
+	return regexs
 }
diff --git a/pkg/kubernetes/reconcile.go b/pkg/kubernetes/reconcile.go
index 7babb897..78d1a8cc 100644
--- a/pkg/kubernetes/reconcile.go
+++ b/pkg/kubernetes/reconcile.go
@@ -39,7 +39,7 @@ func Reconcile(raw map[string]interface{}, spec v1alpha1.Spec, targets []*regexp
 		tmp := funk.Filter(out, func(i interface{}) bool {
 			p := objectspec(i.(manifest.Manifest))
 			for _, t := range targets {
-				if t.MatchString(strings.ToLower(p)) {
+				if t.MatchString(p) {
 					return true
 				}
 			}
diff --git a/pkg/kubernetes/util/targetexp.go b/pkg/kubernetes/util/targetexp.go
new file mode 100644
index 00000000..79f1d5c9
--- /dev/null
+++ b/pkg/kubernetes/util/targetexp.go
@@ -0,0 +1,40 @@
+package util
+
+import (
+	"fmt"
+	"regexp"
+	"strings"
+)
+
+type ErrBadTargetExp struct {
+	inner error
+}
+
+func (e ErrBadTargetExp) Error() string {
+	return fmt.Sprintf("%s.\nSee https://tanka.dev/targets/#regular-expressions for details on regular expressions.", strings.Title(e.inner.Error()))
+}
+
+// CompileTargetExps compiles the regular expression for each target
+func CompileTargetExps(strs []string) (exps []*regexp.Regexp, err error) {
+	exps = make([]*regexp.Regexp, 0, len(strs))
+	for _, raw := range strs {
+		// surround the regular expression with start and end markers
+		s := fmt.Sprintf(`(?i)^%s$`, raw)
+		exp, err := regexp.Compile(s)
+		if err != nil {
+			return nil, ErrBadTargetExp{err}
+		}
+		exps = append(exps, exp)
+	}
+	return exps, nil
+}
+
+// MustCompileTargetExps is like CompileTargetExps but panics on error
+// Meant for static code
+func MustCompileTargetExps(strs ...string) (exps []*regexp.Regexp) {
+	exps, err := CompileTargetExps(strs)
+	if err != nil {
+		panic(err)
+	}
+	return exps
+}


Test patch:
diff --git a/pkg/kubernetes/kubernetes_test.go b/pkg/kubernetes/kubernetes_test.go
index 0e621d16..09ae31b2 100644
--- a/pkg/kubernetes/kubernetes_test.go
+++ b/pkg/kubernetes/kubernetes_test.go
@@ -9,6 +9,7 @@ import (
 	"github.com/stretchr/testify/require"
 
 	"github.com/grafana/tanka/pkg/kubernetes/manifest"
+	"github.com/grafana/tanka/pkg/kubernetes/util"
 	"github.com/grafana/tanka/pkg/spec/v1alpha1"
 )
 
@@ -35,10 +36,10 @@ func TestReconcile(t *testing.T) {
 				testDataDeep().flat[".app.web.backend.server.nginx.deployment"],
 				testDataDeep().flat[".app.web.frontend.nodejs.express.service"],
 			},
-			targets: []*regexp.Regexp{
-				regexp.MustCompile("deployment/nginx"),
-				regexp.MustCompile("service/frontend"),
-			},
+			targets: util.MustCompileTargetExps(
+				`deployment/nginx`,
+				`service/frontend`,
+			),
 		},
 		{
 			name: "targets-regex",
@@ -47,7 +48,17 @@ func TestReconcile(t *testing.T) {
 				testDataDeep().flat[".app.web.backend.server.nginx.deployment"],
 				testDataDeep().flat[".app.web.frontend.nodejs.express.deployment"],
 			},
-			targets: []*regexp.Regexp{regexp.MustCompile("deployment/.*")},
+			targets: util.MustCompileTargetExps(`deployment/.*`),
+		},
+		{
+			name: "targets-caseInsensitive",
+			deep: testDataDeep().deep,
+			flat: manifest.List{
+				testDataDeep().flat[".app.web.backend.server.nginx.deployment"],
+			},
+			targets: util.MustCompileTargetExps(
+				`DePlOyMeNt/NgInX`,
+			),
 		},
 		{
 			name: "force-namespace",