Skip to content

Commit

Permalink
Fix bug with setting last sync
Browse files Browse the repository at this point in the history
  • Loading branch information
dbason committed Oct 20, 2022
1 parent d86cad6 commit e500993
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
10 changes: 7 additions & 3 deletions plugins/logging/pkg/backend/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ func (b *LoggingBackend) Sync(ctx context.Context, req *node.SyncRequest) (*node
b.nodeStatusMu.RLock()
defer b.nodeStatusMu.RUnlock()

err = b.ClusterDriver.SetClusterStatus(ctx, id, enabled)
if err != nil {
return nil, err
if enabled {
err = b.ClusterDriver.SetClusterStatus(ctx, id, enabled)
if err != nil {
return nil, err
}
} else {
b.ClusterDriver.SetSyncTime()
}

var osConf *node.OpensearchConfig
Expand Down
1 change: 1 addition & 0 deletions plugins/logging/pkg/gateway/drivers/cluster_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ClusterDriver interface {
GetInstallStatus(context.Context) InstallState
SetClusterStatus(context.Context, string, bool) error
GetClusterStatus(context.Context, string) (*capabilityv1.NodeCapabilityStatus, error)
SetSyncTime()
}

var (
Expand Down
14 changes: 14 additions & 0 deletions plugins/logging/pkg/gateway/drivers/kubernetes_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (

type KubernetesManagerDriver struct {
KubernetesManagerDriverOptions

ephemeralSyncTime time.Time
}

type KubernetesManagerDriverOptions struct {
Expand Down Expand Up @@ -89,6 +91,7 @@ func NewKubernetesManagerDriver(opts ...KubernetesManagerDriverOption) (*Kuberne
}
return &KubernetesManagerDriver{
KubernetesManagerDriverOptions: options,
ephemeralSyncTime: time.Now(),
}, nil
}

Expand Down Expand Up @@ -241,6 +244,13 @@ func (d *KubernetesManagerDriver) GetClusterStatus(ctx context.Context, id strin
return nil, errors.ErrListingClustersFaled(err)
}

if len(loggingClusterList.Items) == 0 {
return &capabilityv1.NodeCapabilityStatus{
Enabled: false,
LastSync: timestamppb.New(d.ephemeralSyncTime),
}, nil
}

if len(loggingClusterList.Items) != 1 {
return nil, errors.ErrInvalidList
}
Expand All @@ -250,3 +260,7 @@ func (d *KubernetesManagerDriver) GetClusterStatus(ctx context.Context, id strin
LastSync: timestamppb.New(loggingClusterList.Items[0].Spec.LastSync.Time),
}, nil
}

func (d *KubernetesManagerDriver) SetSyncTime() {
d.ephemeralSyncTime = time.Now()
}

0 comments on commit e500993

Please sign in to comment.