Repository: FairwindsOps/pluto
Pull request #22 (2020-03-27 22:01:05)

Fix bug with secrets list
There was a strange bug that only manifested in actual usage, not in unit tets. Secret list wires were getting crossed with pointers. I made them not pointers.

codecov[bot]: # [Codecov](https://codecov.io/gh/FairwindsOps/pluto/pull/22?src=pr&el=h1) Report
> Merging [#22](https://codecov.io/gh/FairwindsOps/pluto/pull/22?src=pr&el=desc) into [master](https://codecov.io/gh/FairwindsOps/pluto/commit/a9408005600df43e8fdf211128bc476ae824a081&el=desc) will **decrease** coverage by `0.19%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/FairwindsOps/pluto/pull/22/graphs/tree.svg?width=650&height=150&src=pr&token=A23F79JTNA)](https://codecov.io/gh/FairwindsOps/pluto/pull/22?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #22      +/-   ##
==========================================
- Coverage   71.92%   71.73%   -0.20%     
==========================================
  Files           5        5              
  Lines         285      283       -2     
==========================================
- Hits          205      203       -2     
  Misses         60       60              
  Partials       20       20              
```


| [Impacted Files](https://codecov.io/gh/FairwindsOps/pluto/pull/22?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/helm/helm.go](https://codecov.io/gh/FairwindsOps/pluto/pull/22/diff?src=pr&el=tree#diff-cGtnL2hlbG0vaGVsbS5nbw==) | `62.26% <100.00%> (-0.70%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/FairwindsOps/pluto/pull/22?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/FairwindsOps/pluto/pull/22?src=pr&el=footer). Last update [a940800...a762d18](https://codecov.io/gh/FairwindsOps/pluto/pull/22?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go
index cd9b61c..b1ee98a 100644
--- a/pkg/helm/helm.go
+++ b/pkg/helm/helm.go
@@ -26,7 +26,6 @@ import (
 
 	v1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-	"k8s.io/klog"
 
 	"github.com/fairwindsops/pluto/pkg/api"
 )
@@ -103,7 +102,7 @@ func (h *Helm) getManifestsVersionThree() error {
 	return nil
 }
 
-func (h *Helm) getReleases(secrets []*v1.Secret) ([]*Release, error) {
+func (h *Helm) getReleases(secrets []v1.Secret) ([]*Release, error) {
 	var releases []*Release
 	for _, secret := range secrets {
 		thisRelease, err := decodeReleaseSecret(string(secret.Data["release"]))
@@ -116,7 +115,7 @@ func (h *Helm) getReleases(secrets []*v1.Secret) ([]*Release, error) {
 	return releases, nil
 }
 
-func (h *Helm) getHelmSecrets() ([]*v1.Secret, error) {
+func (h *Helm) getHelmSecrets() ([]v1.Secret, error) {
 	if h.Version != "3" {
 		return nil, fmt.Errorf("helm 3 function called without helm 3 version set")
 	}
@@ -124,13 +123,11 @@ func (h *Helm) getHelmSecrets() ([]*v1.Secret, error) {
 	if err != nil {
 		return nil, err
 	}
-	helmSecrets := []*v1.Secret{}
+	helmSecrets := []v1.Secret{}
 	for _, secret := range secrets.Items {
-		if secret.Type != "helm.sh/release.v1" {
-			klog.V(8).Infof("skipping secret %s because it is not a helm release", secret.ObjectMeta.Name)
-			continue
+		if secret.Type == "helm.sh/release.v1" {
+			helmSecrets = append(helmSecrets, secret)
 		}
-		helmSecrets = append(helmSecrets, &secret)
 	}
 	return helmSecrets, nil
 }


Test patch:
diff --git a/pkg/helm/helm_test.go b/pkg/helm/helm_test.go
index af44f91..c3218c0 100644
--- a/pkg/helm/helm_test.go
+++ b/pkg/helm/helm_test.go
@@ -49,7 +49,7 @@ var (
 	decodedRelease              = &Release{
 		Manifest: "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: utilities\n  labels:\n    app: utilities\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: utilities\n  template:\n    metadata:\n      labels:\n        app: utilities\n    spec:\n      containers:\n      - name: utilities\n        image: quay.io/sudermanjr/utilities:latest\n        # Just spin & wait forever\n        command: [ \"/bin/bash\", \"-c\", \"--\" ]\n        args: [ \"while true; do sleep 30; done;\" ]\n        securityContext:\n          readOnlyRootFilesystem: true\n          allowPrivilegeEscalation: false\n          runAsNonRoot: true\n          runAsUser: 10324\n          capabilities:\n            drop:\n              - ALL\n        resources:\n          requests:\n            cpu: 30m\n            memory: 64Mi\n          limits:\n            cpu: 100m\n            memory: 128Mi",
 	}
-	kubeSecret = &v1.Secret{
+	kubeSecret = v1.Secret{
 		ObjectMeta: metav1.ObjectMeta{
 			Name:      "utilities",
 			Namespace: "test-namespace",
@@ -242,20 +242,20 @@ func TestHelm_getHelmSecrets(t *testing.T) {
 	tests := []struct {
 		name        string
 		helmVersion string
-		want        []*v1.Secret
+		want        []v1.Secret
 		mockSecrets []*v1.Secret
 		wantErr     bool
 	}{
 		{
 			name:        "basic",
 			helmVersion: "2",
-			want:        []*v1.Secret{},
+			want:        []v1.Secret{},
 			wantErr:     true,
 		},
 		{
 			name:        "empty",
 			helmVersion: "3",
-			want:        []*v1.Secret{&kubeSecretHelm},
+			want:        []v1.Secret{kubeSecretHelm},
 			mockSecrets: []*v1.Secret{&kubeSecretNonHelm, &kubeSecretHelm},
 			wantErr:     false,
 		},
@@ -289,25 +289,25 @@ func TestHelm_getHelmSecrets(t *testing.T) {
 func TestHelm_getReleases(t *testing.T) {
 	tests := []struct {
 		name    string
-		secrets []*v1.Secret
+		secrets []v1.Secret
 		want    []*Release
 		wantErr bool
 	}{
 		{
 			name:    "functional",
-			secrets: []*v1.Secret{kubeSecret},
+			secrets: []v1.Secret{kubeSecret},
 			want:    []*Release{&Release{Name: "utilities", Manifest: decodedRelease.Manifest}},
 			wantErr: false,
 		},
 		{
 			name:    "empty",
-			secrets: []*v1.Secret{},
+			secrets: []v1.Secret{},
 			want:    nil,
 			wantErr: false,
 		},
 		{
 			name: "error",
-			secrets: []*v1.Secret{&v1.Secret{
+			secrets: []v1.Secret{v1.Secret{
 				ObjectMeta: metav1.ObjectMeta{
 					Name: "bad",
 				},