Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with setting last sync #694

Merged
merged 2 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}