Skip to content

Commit

Permalink
retry saving missed secret after intial sync
Browse files Browse the repository at this point in the history
  • Loading branch information
vardhaman22 authored and brandond committed Sep 28, 2023
1 parent 0132d96 commit 0a2d8df
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions storage/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Load(ctx context.Context, secrets v1controller.SecretController, namespace,
namespace: namespace,
storage: backing,
ctx: ctx,
initSync: &sync.Once{},
}
storage.init(secrets)
return storage
Expand All @@ -37,6 +38,7 @@ func New(ctx context.Context, core CoreGetter, namespace, name string, backing d
namespace: namespace,
storage: backing,
ctx: ctx,
initSync: &sync.Once{},
}

// lazy init
Expand All @@ -62,6 +64,7 @@ type storage struct {
ctx context.Context
tls dynamiclistener.TLSFactory
initialized bool
initSync *sync.Once
}

func (s *storage) SetFactory(tls dynamiclistener.TLSFactory) {
Expand Down Expand Up @@ -161,6 +164,20 @@ func (s *storage) targetSecret() (*v1.Secret, error) {

func (s *storage) saveInK8s(secret *v1.Secret) (*v1.Secret, error) {
if !s.initComplete() {
// Start a goroutine to attempt to save the secret later, once init is complete.
// If this was already handled by initComplete, it should be a no-op, or at worst get
// merged with the Kubernetes secret.
go s.initSync.Do(func() {
if err := wait.Poll(100*time.Millisecond, 15*time.Minute, func() (bool, error) {
if !s.initComplete() {
return false, nil
}
_, err := s.saveInK8s(secret)
return true, err
}); err != nil {
logrus.Errorf("Failed to save TLS secret after controller init: %v", err)
}
})
return secret, nil
}

Expand Down

0 comments on commit 0a2d8df

Please sign in to comment.