Skip to content

Commit

Permalink
Add exitOnWait flag
Browse files Browse the repository at this point in the history
This enables the exitOnWait behavior from the commandline so most
users don't need to define two different config files.

Signed-off-by: Kevin Fox <[email protected]>
  • Loading branch information
kfox1111 committed Jan 6, 2024
1 parent a9e9743 commit 8e10f2f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ The SPIFFE Helper is a simple utility for fetching X.509 SVID certificates from

If `-config` is not specified, the default value `helper.conf` is assumed.

The flag `-exitWhenReady` is also supported.

## Configuration
The configuration file is an [HCL](https://github.com/hashicorp/hcl) formatted file that defines the following configurations:

Expand Down
7 changes: 4 additions & 3 deletions cmd/spiffe-helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@ func main() {
// 2. Run Sidecar's Daemon

configFile := flag.String("config", "helper.conf", "<configFile> Configuration file path")
exitWhenReady := flag.Bool("exitWhenReady", false, "Exit once the requested objects are retrieved")
flag.Parse()

log := logrus.WithField("system", "spiffe-helper")
log.Infof("Using configuration file: %q\n", *configFile)

if err := startSidecar(*configFile, log); err != nil {
if err := startSidecar(*configFile, *exitWhenReady, log); err != nil {
log.WithError(err).Error("Exiting due this error")
os.Exit(1)
}

log.Infof("Exiting")
}

func startSidecar(configPath string, log logrus.FieldLogger) error {
func startSidecar(configPath string, exitWhenReady bool, log logrus.FieldLogger) error {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()

spiffeSidecar, err := sidecar.New(configPath, log)
spiffeSidecar, err := sidecar.New(configPath, exitWhenReady, log)
if err != nil {
return fmt.Errorf("Failed to create sidecar: %w", err)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/sidecar/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Sidecar struct {
}

// New creates a new SPIFFE sidecar
func New(configPath string, log logrus.FieldLogger) (*Sidecar, error) {
func New(configPath string, exitWhenReady bool, log logrus.FieldLogger) (*Sidecar, error) {
config, err := ParseConfig(configPath)
if err != nil {
return nil, fmt.Errorf("failed to parse %q: %w", configPath, err)
Expand All @@ -68,6 +68,8 @@ func New(configPath string, log logrus.FieldLogger) (*Sidecar, error) {
config.Log.Warn("No cmd defined to execute.")
}

config.ExitWhenReady = config.ExitWhenReady || exitWhenReady

return &Sidecar{
config: config,
certReadyChan: make(chan struct{}, 1),
Expand Down

0 comments on commit 8e10f2f

Please sign in to comment.