@@ -35,7 +35,6 @@ import (
3535 log "github.com/sirupsen/logrus"
3636 corev1 "k8s.io/api/core/v1"
3737 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
38- "k8s.io/apimachinery/pkg/types"
3938 "k8s.io/client-go/kubernetes"
4039 "k8s.io/client-go/rest"
4140)
@@ -511,17 +510,15 @@ func setNamespaceOperatingMode() error {
511510// namespace. If any have an empty password, it generates a random password,
512511// Base64 encodes it, then stores it in the relevant PGO user's secret
513512func setRandomPgouserPasswords () {
514- ctx := context .TODO ()
515-
516513 selector := "pgo-pgouser=true,vendor=crunchydata"
517514 secrets , err := Clientset .CoreV1 ().Secrets (PgoNamespace ).
518- List (ctx , metav1.ListOptions {LabelSelector : selector })
515+ List (metav1.ListOptions {LabelSelector : selector })
519516 if err != nil {
520517 log .Warnf ("Could not get pgouser secrets in namespace: %s" , PgoNamespace )
521518 return
522519 }
523520
524- for _ , secret := range secrets .Items {
521+ for i , secret := range secrets .Items {
525522 // check if password is set. if it is, continue.
526523 if len (secret .Data ["password" ]) > 0 {
527524 continue
@@ -539,18 +536,11 @@ func setRandomPgouserPasswords() {
539536 continue
540537 }
541538
542- // create the password patch
543- patch , err := kubeapi .NewMergePatch ().Add ("stringData" , "password" )(generatedPassword ).Bytes ()
544-
545- if err != nil {
546- log .Errorf ("Could not generate password patch for pgouser secret %s for operator installation " +
547- "%s in namespace %s" , secret .Name , InstallationName , PgoNamespace )
548- continue
549- }
539+ // add the password to the secret
540+ secrets .Items [i ].Data ["password" ] = []byte (generatedPassword )
550541
551542 // patch the pgouser secret with the new password
552- if _ , err := Clientset .CoreV1 ().Secrets (PgoNamespace ).Patch (ctx , secret .Name , types .MergePatchType ,
553- patch , metav1.PatchOptions {}); err != nil {
543+ if _ , err := Clientset .CoreV1 ().Secrets (PgoNamespace ).Update (& secrets .Items [i ]); err != nil {
554544 log .Errorf ("Could not patch pgouser secret %s with generated password for operator installation " +
555545 "%s in namespace %s" , secret .Name , InstallationName , PgoNamespace )
556546 }
0 commit comments