Skip to content

Commit

Permalink
Moves RunDaemon method just after New method.
Browse files Browse the repository at this point in the history
Signed-off-by: JU4N98 <[email protected]>
  • Loading branch information
JU4N98 committed Nov 13, 2023
1 parent 93c7681 commit 4160fe9
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions pkg/sidecar/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,48 @@ func New(configPath string, log logrus.FieldLogger) (*Sidecar, error) {
}, nil
}

// RunDaemon starts the main loop
// Starts the workload API client to listen for new SVID updates
// When a new SVID is received on the updateChan, the SVID certificates
// are stored in disk and a restart signal is sent to the proxy's process
func (s *Sidecar) RunDaemon(ctx context.Context) error {
var wg sync.WaitGroup

if s.config.SvidFileName != "" && s.config.SvidKeyFileName != "" && s.config.SvidBundleFileName != "" {
wg.Add(1)
go func() {
defer wg.Done()
err := workloadapi.WatchX509Context(ctx, &x509Watcher{sidecar: s}, s.getWorkloadAPIAdress())
if err != nil && status.Code(err) != codes.Canceled {
s.config.Log.Errorf("Error watching X.509 context: %v", err)
}
}()
}

if s.config.JWTBundleFilename != "" {
wg.Add(1)
go func() {
defer wg.Done()
err := workloadapi.WatchJWTBundles(ctx, &JWTBundlesWatcher{sidecar: s}, s.getWorkloadAPIAdress())
if err != nil && status.Code(err) != codes.Canceled {
s.config.Log.Errorf("Error watching JWT bundle updates: %v", err)
}
}()
}

if s.config.JWTSvidFilename != "" && s.config.JWTAudience != "" {
wg.Add(1)
go func() {
defer wg.Done()
s.updateJWTSVID(ctx, s.getWorkloadAPIAdress())
}()
}

wg.Wait()

return nil
}

// CertReadyChan returns a channel to know when the certificates are ready
func (s *Sidecar) CertReadyChan() <-chan struct{} {
return s.certReadyChan
Expand Down Expand Up @@ -384,45 +426,3 @@ func (w JWTBundlesWatcher) OnJWTBundlesWatchError(err error) {
w.sidecar.config.Log.Errorf("Error while watching JWT bundles: %v", err)
}
}

// RunDaemon starts the main loop
// Starts the workload API client to listen for new SVID updates
// When a new SVID is received on the updateChan, the SVID certificates
// are stored in disk and a restart signal is sent to the proxy's process
func (s *Sidecar) RunDaemon(ctx context.Context) error {
var wg sync.WaitGroup

if s.config.SvidFileName != "" && s.config.SvidKeyFileName != "" && s.config.SvidBundleFileName != "" {
wg.Add(1)
go func() {
defer wg.Done()
err := workloadapi.WatchX509Context(ctx, &x509Watcher{sidecar: s}, s.getWorkloadAPIAdress())
if err != nil && status.Code(err) != codes.Canceled {
s.config.Log.Errorf("Error watching X.509 context: %v", err)
}
}()
}

if s.config.JWTBundleFilename != "" {
wg.Add(1)
go func() {
defer wg.Done()
err := workloadapi.WatchJWTBundles(ctx, &JWTBundlesWatcher{sidecar: s}, s.getWorkloadAPIAdress())
if err != nil && status.Code(err) != codes.Canceled {
s.config.Log.Errorf("Error watching JWT bundle updates: %v", err)
}
}()
}

if s.config.JWTSvidFilename != "" && s.config.JWTAudience != "" {
wg.Add(1)
go func() {
defer wg.Done()
s.updateJWTSVID(ctx, s.getWorkloadAPIAdress())
}()
}

wg.Wait()

return nil
}

0 comments on commit 4160fe9

Please sign in to comment.