Skip to content

Commit 3a49b48

Browse files
authored
delete secrets of system users too (#974)
1 parent 8ff7658 commit 3a49b48

File tree

2 files changed

+0
-40
lines changed

2 files changed

+0
-40
lines changed

pkg/cluster/cluster.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -822,10 +822,6 @@ func (c *Cluster) Delete() {
822822
}
823823

824824
for _, obj := range c.Secrets {
825-
if doDelete, user := c.shouldDeleteSecret(obj); !doDelete {
826-
c.logger.Warningf("not removing secret %q for the system user %q", obj.GetName(), user)
827-
continue
828-
}
829825
if err := c.deleteSecret(obj); err != nil {
830826
c.logger.Warningf("could not delete secret: %v", err)
831827
}
@@ -1300,11 +1296,6 @@ func (c *Cluster) Unlock() {
13001296
c.mu.Unlock()
13011297
}
13021298

1303-
func (c *Cluster) shouldDeleteSecret(secret *v1.Secret) (delete bool, userName string) {
1304-
secretUser := string(secret.Data["username"])
1305-
return (secretUser != c.OpConfig.ReplicationUsername && secretUser != c.OpConfig.SuperUsername), secretUser
1306-
}
1307-
13081299
type simpleActionWithResult func() error
13091300

13101301
type clusterObjectGet func(name string) (spec.NamespacedName, error)

pkg/cluster/cluster_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/zalando/postgres-operator/pkg/util/constants"
1313
"github.com/zalando/postgres-operator/pkg/util/k8sutil"
1414
"github.com/zalando/postgres-operator/pkg/util/teams"
15-
v1 "k8s.io/api/core/v1"
1615
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1716
"k8s.io/client-go/tools/record"
1817
)
@@ -334,36 +333,6 @@ func TestInitHumanUsersWithSuperuserTeams(t *testing.T) {
334333
}
335334
}
336335

337-
func TestShouldDeleteSecret(t *testing.T) {
338-
testName := "TestShouldDeleteSecret"
339-
340-
tests := []struct {
341-
secret *v1.Secret
342-
outcome bool
343-
}{
344-
{
345-
secret: &v1.Secret{Data: map[string][]byte{"username": []byte("foobar")}},
346-
outcome: true,
347-
},
348-
{
349-
secret: &v1.Secret{Data: map[string][]byte{"username": []byte(superUserName)}},
350-
351-
outcome: false,
352-
},
353-
{
354-
secret: &v1.Secret{Data: map[string][]byte{"username": []byte(replicationUserName)}},
355-
outcome: false,
356-
},
357-
}
358-
359-
for _, tt := range tests {
360-
if outcome, username := cl.shouldDeleteSecret(tt.secret); outcome != tt.outcome {
361-
t.Errorf("%s expects the check for deletion of the username %q secret to return %t, got %t",
362-
testName, username, tt.outcome, outcome)
363-
}
364-
}
365-
}
366-
367336
func TestPodAnnotations(t *testing.T) {
368337
testName := "TestPodAnnotations"
369338
tests := []struct {

0 commit comments

Comments
 (0)