Skip to content

Commit

Permalink
Add a helpful comment explaining when/why we create a ServiceAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancoleman committed Sep 24, 2024
1 parent 365b2c2 commit ac64e83
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions control-plane/api-gateway/gatekeeper/serviceaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
)

func (g *Gatekeeper) upsertServiceAccount(ctx context.Context, gateway gwv1beta1.Gateway, config common.HelmConfig) error {
// We only create a ServiceAccount if it's needed for RBAC or image pull secrets;
// otherwise, we clean up if one was previously created.
if config.AuthMethod == "" && !config.EnableOpenShift && len(config.ImagePullSecrets) == 0 {
return g.deleteServiceAccount(ctx, types.NamespacedName{Namespace: gateway.Namespace, Name: gateway.Name})
}
Expand Down Expand Up @@ -51,11 +53,8 @@ func (g *Gatekeeper) upsertServiceAccount(ctx context.Context, gateway gwv1beta1
if err := ctrl.SetControllerReference(&gateway, serviceAccount, g.Client.Scheme()); err != nil {
return err
}
if err := g.Client.Create(ctx, serviceAccount); err != nil {
return err
}

return nil
return g.Client.Create(ctx, serviceAccount)
}

func (g *Gatekeeper) deleteServiceAccount(ctx context.Context, gwName types.NamespacedName) error {
Expand Down

0 comments on commit ac64e83

Please sign in to comment.