Skip to content

Commit

Permalink
refactor: remove use of k8s serivce account (#2544)
Browse files Browse the repository at this point in the history
## Description

This change removes the k8s service account code and replaces it with
direct use of the client set instead.

## Related Issue

Relates to #2512

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [ ] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/.github/CONTRIBUTING.md#developer-workflow)
followed

Co-authored-by: razzle <razzle@defenseunicorns.com>
Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
  • Loading branch information
2 people authored and AustinAbro321 committed Jul 23, 2024
1 parent b33708a commit 1c58bb8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 65 deletions.
24 changes: 23 additions & 1 deletion src/pkg/cluster/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/fatih/color"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/defenseunicorns/pkg/helpers"
Expand Down Expand Up @@ -115,7 +116,28 @@ func (c *Cluster) InitZarfState(ctx context.Context, initOptions types.ZarfInitO
// The default SA is required for pods to start properly.
saCtx, cancel := context.WithTimeout(ctx, 2*time.Minute)
defer cancel()
if _, err := c.WaitForServiceAccount(saCtx, ZarfNamespaceName, "default"); err != nil {
err = func(ctx context.Context, ns, name string) error {
timer := time.NewTimer(0)
defer timer.Stop()
for {
select {
case <-ctx.Done():
return fmt.Errorf("failed to get service account %s/%s: %w", ns, name, ctx.Err())
case <-timer.C:
_, err := c.Clientset.CoreV1().ServiceAccounts(ns).Get(ctx, name, metav1.GetOptions{})
if err != nil && !kerrors.IsNotFound(err) {
return err
}
if kerrors.IsNotFound(err) {
c.Log("Service account %s/%s not found, retrying...", ns, name)
timer.Reset(1 * time.Second)
continue
}
return nil
}
}
}(saCtx, ZarfNamespaceName, "default")
if err != nil {
return fmt.Errorf("unable get default Zarf service account: %w", err)
}

Expand Down
64 changes: 0 additions & 64 deletions src/pkg/k8s/sa.go

This file was deleted.

0 comments on commit 1c58bb8

Please sign in to comment.