Skip to content

Commit

Permalink
Merge pull request #111 from lili-wan/master
Browse files Browse the repository at this point in the history
Fixed service account patch string format
  • Loading branch information
lili-wan authored Feb 2, 2023
2 parents 60651ef + db72d77 commit b41a855
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/k8s/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"encoding/json"
"errors"
"fmt"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

corev1 "k8s.io/api/core/v1"
apierr "k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/keikoproj/iam-manager/pkg/logging"
)
Expand Down Expand Up @@ -41,10 +40,12 @@ func (c *Client) CreateOrUpdateServiceAccount(ctx context.Context, saName string
log.Error(err, msg)
return errors.New(msg)
}
log.Info("Service account already exists. Trying to update", "serviceAccount", sa.Name, "namespace", ns)
annotationByte, _ := json.Marshal(sa.Annotations)
patchStr := fmt.Sprintf(`{"metadata":{"annotations":%s}}`, string(annotationByte))
log.Info("Service account already exists. Trying to update", "serviceAccount",
sa.Name, "namespace", ns, "annotation", patchStr)
// Use patch to avoid creating new token each reconcile
err = c.rCl.Patch(ctx, sa, client.RawPatch(types.MergePatchType, annotationByte))
err = c.rCl.Patch(ctx, sa, client.RawPatch(types.MergePatchType, []byte(patchStr)))
if err != nil {
msg := fmt.Sprintf("Failed to update service account %s due to %v", sa.Name, err)
log.Error(err, msg)
Expand Down

0 comments on commit b41a855

Please sign in to comment.