Skip to content

Commit

Permalink
Detect duplicate deployed helm releases (#360)
Browse files Browse the repository at this point in the history
* create a test to duplicate #330. Add a log message

* Made the test pass in case we want to keep it this way
  • Loading branch information
Andrew Suderman authored Jul 27, 2022
1 parent bc15132 commit 45c6ec2
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ require (
sigs.k8s.io/controller-runtime v0.12.3
)

require github.com/thoas/go-funk v0.9.2

require (
cloud.google.com/go/compute v1.7.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I=
github.com/thoas/go-funk v0.9.2 h1:oKlNYv0AY5nyf9g+/GhMgS/UO2ces0QRdPKwkhY3VCk=
github.com/thoas/go-funk v0.9.2/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
4 changes: 4 additions & 0 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"encoding/json"
"fmt"

"github.com/thoas/go-funk"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/releaseutil"
helmstoragev3 "helm.sh/helm/v3/pkg/storage"
Expand Down Expand Up @@ -127,6 +128,9 @@ func (h *Helm) getReleasesVersionThree() error {
if err != nil {
return fmt.Errorf("error converting helm r '%s/%s' to internal object\n %w", r.Namespace, r.Name, err)
}
if funk.Contains(h.Releases, rel) {
klog.Warningf("found duplicate release %s/%s in a deployed state - this may produce inconsistent results", rel.Namespace, rel.Name)
}
h.Releases = append(h.Releases, rel)
}
}
Expand Down
116 changes: 116 additions & 0 deletions pkg/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ var (
"release": []byte("H4sIAAAAAAAC/+xbaZOiyLr+Kwb3fLg3oqoasKwujZgPQiniQpWoLDk1MUEmCGiyjCyKHf3fb2TigkttfebE+TIdYbRCkvmuz/u8SdYPJrQCh2kxnoOD1ElS5obxw3nEtH4wc3+VpH/aToyjwrGZFsOzPHvL3t+y/JT73uL5Vv3h7v7x/jv7HTA3DLa+Mtp2sJPScfRHglZ+nPpRyLQYOUxSC+MaioKYDGJumCS10ixhWsxh/hsmjFKHXOLuapKT1lLPqVlxjH1kkXlqM3VYg0VtlYWhH7rkduKQKQMrtJPWa1irOZs4WqW1l+enP5X2qPPbv/53mUEHpbjmOmktjuykdntLzJPEFnJqtjO3MpzWbnHtlbHi+I6MXoVO6iR3fvSNDPyNWBF51opY8uZyjE80C1E5jox5ZWq3UW2RRGFspd5vr8yPOz91guR39o+7wEkt20qtOzLzz1fm/6jMyItqr4zmJ35a89I0bn37xvHf79g79o5rPbKPbC2Nalni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b4vBa3hzlqNWxBB5fq1Ojou8T7RgeeCn1Lj82Ww64fNz4d/9bI/aHjo2hvjcz3yr/uzteWZ4avDQ2s0HId+xYWrdqUOuM1TGIHUbV2KJi0alThZAedO5UDK0XesGqEr+j3eQ33Pt8vW3UV+YdPRfiaEF8x9MEu9MdJHijvBf7+gZOSUZH3x8/j9/03FIWp5YfOqqrYbe09Rd5b4nyZ6lLkH63VJF5o9W6dRk1lyMuBBbRqVRJQHUhqX3K29kHyNI1P71RUfYlI6jyy5wPiVZRGKMKt2lR8qd7Efu6ETpK8rCLonK1IVpKccxvUaoQstGrfLi7Ttc/FWzmW7f+HV9jxiivO+ioQXkE/K44J7v07kPcP1P0Ddf9A3T9Q9x+EuuofGXFlt0P/oon+nRj9mybm5/8HAAD//+BteWThNgAA"),
},
}
helmSecretDuplicateDeployedRelease = v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "sh.helm.release.v1.helmtest.v2",
Labels: map[string]string{
"createdAt": "1585859667",
"name": "helmtest",
"owner": "helm",
"status": "deployed",
"version": "2",
},
},
Data: map[string][]byte{
"release": []byte("H4sIAAAAAAAC/+xbaZOiyLr+Kwb3fLg3oqoasKwujZgPQiniQpWoLDk1MUEmCGiyjCyKHf3fb2TigkttfebE+TIdYbRCkvmuz/u8SdYPJrQCh2kxnoOD1ElS5obxw3nEtH4wc3+VpH/aToyjwrGZFsOzPHvL3t+y/JT73uL5Vv3h7v7x/jv7HTA3DLa+Mtp2sJPScfRHglZ+nPpRyLQYOUxSC+MaioKYDGJumCS10ixhWsxh/hsmjFKHXOLuapKT1lLPqVlxjH1kkXlqM3VYg0VtlYWhH7rkduKQKQMrtJPWa1irOZs4WqW1l+enP5X2qPPbv/53mUEHpbjmOmktjuykdntLzJPEFnJqtjO3MpzWbnHtlbHi+I6MXoVO6iR3fvSNDPyNWBF51opY8uZyjE80C1E5jox5ZWq3UW2RRGFspd5vr8yPOz91guR39o+7wEkt20qtOzLzz1fm/6jMyItqr4zmJ35a89I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eSO5vUCcnX5FvOQSe1Dpo8HWb4vBa3hzlqNWxBB5fq1Ojou8T7RgeeCn1Lj82Ww64fNz4d/9bI/aHjo2hvjcz3yr/uzteWZ4avDQ2s0HId+xYWrdqUOuM1TGIHUbV2KJi0alThZAedO5UDK0XesGqEr+j3eQ33Pt8vW3UV+YdPRfiaEF8x9MEu9MdJHijvBf7+gZOSUZH3x8/j9/03FIWp5YfOqqrYbe09Rd5b4nyZ6lLkH63VJF5o9W6dRk1lyMuBBbRqVRJQHUhqX3K29kHyNI1P71RUfYlI6jyy5wPiVZRGKMKt2lR8qd7Efu6ETpK8rCLonK1IVpKccxvUaoQstGrfLi7Ttc/FWzmW7f+HV9jxiivO+ioQXkE/K44J7v07kPcP1P0Ddf9A3T9Q9x+EuuofGXFlt0P/oon+nRj9mybm5/8HAAD//+BteWThNgAA"),
},
}
wantOutput = []*api.Output{
{
Name: "helmtest/helmtest-helmchartest-v1beta1",
Expand All @@ -82,6 +97,57 @@ var (
},
},
}

wantOutputDuplicateDeployedRelease = []*api.Output{
{
Name: "helmtest/helmtest-helmchartest-v1beta1",
Namespace: "default",
APIVersion: &api.Version{
Name: "extensions/v1beta1",
Kind: "Deployment",
DeprecatedIn: "v1.9.0",
RemovedIn: "v1.16.0",
ReplacementAPI: "apps/v1",
Component: "k8s",
},
},
{
Name: "helmtest/helmtest-helmchartest",
Namespace: "default",
APIVersion: &api.Version{
Name: "apps/v1",
Kind: "Deployment",
DeprecatedIn: "",
RemovedIn: "",
ReplacementAPI: "",
Component: "k8s",
},
},
{
Name: "helmtest/helmtest-helmchartest-v1beta1",
Namespace: "default",
APIVersion: &api.Version{
Name: "extensions/v1beta1",
Kind: "Deployment",
DeprecatedIn: "v1.9.0",
RemovedIn: "v1.16.0",
ReplacementAPI: "apps/v1",
Component: "k8s",
},
},
{
Name: "helmtest/helmtest-helmchartest",
Namespace: "default",
APIVersion: &api.Version{
Name: "apps/v1",
Kind: "Deployment",
DeprecatedIn: "",
RemovedIn: "",
ReplacementAPI: "",
Component: "k8s",
},
},
}
)

func newMockHelm(namespace string) *Helm {
Expand Down Expand Up @@ -210,6 +276,56 @@ func TestHelm_getManifestsVersionThree(t *testing.T) {
}
}

func TestHelm_getManifestsVersionThreeMultipleDeployed(t *testing.T) {
tests := []struct {
name string
wantErr bool
errMessage string
secrets []*v1.Secret
want []*api.Output
}{
{
name: "helm 3 duplicate deployed",
secrets: []*v1.Secret{&helmSecret, &helmSecretDuplicateDeployedRelease},
want: wantOutputDuplicateDeployedRelease,
},
}

for _, tt := range tests {
h := newMockHelm("")
if tt.secrets != nil {

ns := v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
}

_, err := h.Kube.Client.CoreV1().Namespaces().Create(context.TODO(), &ns, metav1.CreateOptions{})
if err != nil {
t.Errorf("failed creating default namespace. test: %s", tt.name)
}

for _, s := range tt.secrets {
_, err = h.Kube.Client.CoreV1().Secrets("default").Create(context.TODO(), s, metav1.CreateOptions{})
if err != nil {
t.Errorf("failed putting secret in mocked kube. test: %s: %s", tt.name, err)
}
}

}
t.Run(tt.name, func(t *testing.T) {
err := h.getReleasesVersionThree()
if tt.wantErr {
assert.EqualError(t, err, tt.errMessage)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.want, h.Instance.Outputs)
})
}
}

func TestHelm_getManifest_badClient(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 45c6ec2

Please sign in to comment.