Skip to content

Commit

Permalink
core: Add context parameter for updating device configmap
Browse files Browse the repository at this point in the history
This commit adds context parameter to the updateDeviceCM() function and other top
level calling functions. This will allow us to handle cancellations
while talking to the k8s API.

Closes: rook#8701
Signed-off-by: Divyansh Kamboj <dkamboj@redhat.com>
  • Loading branch information
weirdwiz committed Jan 31, 2022
1 parent 2f867c0 commit eb8d42b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/rook/discover.go
Expand Up @@ -51,8 +51,9 @@ func startDiscover(cmd *cobra.Command, args []string) error {
rook.LogStartupInfo(discoverCmd.Flags())

context := rook.NewContext()
ctx := cmd.Context()

err := discover.Run(context, discoverDevicesInterval, usesCVInventory)
err := discover.Run(ctx, context, discoverDevicesInterval, usesCVInventory)
if err != nil {
rook.TerminateFatal(err)
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/daemon/discover/discover.go
Expand Up @@ -74,7 +74,7 @@ type CephVolumeInventory struct {
}

// Run is the entry point of that package execution
func Run(context *clusterd.Context, probeInterval time.Duration, useCV bool) error {
func Run(ctx context.Context, context *clusterd.Context, probeInterval time.Duration, useCV bool) error {
if context == nil {
return fmt.Errorf("nil context")
}
Expand All @@ -87,7 +87,7 @@ func Run(context *clusterd.Context, probeInterval time.Duration, useCV bool) err
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGTERM)

err := updateDeviceCM(context)
err := updateDeviceCM(ctx, context)
if err != nil {
logger.Infof("failed to update device configmap: %v", err)
return err
Expand All @@ -101,13 +101,13 @@ func Run(context *clusterd.Context, probeInterval time.Duration, useCV bool) err
logger.Infof("shutdown signal received, exiting...")
return nil
case <-time.After(probeInterval):
if err := updateDeviceCM(context); err != nil {
if err := updateDeviceCM(ctx, context); err != nil {
logger.Errorf("failed to update device configmap during probe interval. %v", err)
}
case _, ok := <-udevEvents:
if ok {
logger.Info("trigger probe from udev event")
if err := updateDeviceCM(context); err != nil {
if err := updateDeviceCM(ctx, context); err != nil {
logger.Errorf("failed to update device configmap triggered from udev event. %v", err)
}
} else {
Expand Down Expand Up @@ -323,8 +323,7 @@ func DeviceListsEqual(old, new string) (bool, error) {
return checkDeviceListsEqual(oldDevs, newDevs), nil
}

func updateDeviceCM(clusterdContext *clusterd.Context) error {
ctx := context.TODO()
func updateDeviceCM(ctx context.Context, clusterdContext *clusterd.Context) error {
logger.Infof("updating device configmap")
devices, err := probeDevices(clusterdContext)
if err != nil {
Expand Down

0 comments on commit eb8d42b

Please sign in to comment.