Skip to content

Commit

Permalink
refactor(dp-server): simplify by removing dataplane_callbacks
Browse files Browse the repository at this point in the history
Dataplane callbacks was an abstraction causing more complexity then
anything.
We now have a watchdog_callbacks which start the lifecycle and the
watchdog
We carefully ensure (and test) that there always a single watchdog running at once
even when DP reconnects.

part of #12881

Signed-off-by: Charly Molter <[email protected]>
  • Loading branch information
lahabana committed Feb 19, 2025
1 parent 4c72e6c commit 23c3094
Show file tree
Hide file tree
Showing 17 changed files with 697 additions and 843 deletions.
1 change: 1 addition & 0 deletions api/generic/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func GetSubscription[S Subscription, T interface{ GetSubscriptions() []S }](t T,
type Insight interface {
proto.Message
IsOnline() bool
// GetLastSubscription returns that last subscription or nil if there are no subscriptions
GetLastSubscription() Subscription
GetSubscription(id string) Subscription
AllSubscriptions() []Subscription
Expand Down
16 changes: 15 additions & 1 deletion pkg/core/resources/apis/mesh/proxy_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ func ProxyTypeFromResourceType(t core_model.ResourceType) (mesh_proto.ProxyType,
return mesh_proto.IngressProxyType, nil
case ZoneEgressType:
return mesh_proto.EgressProxyType, nil
default:
return "", errors.Errorf("%s does not have a corresponding proxy type", t)
}
}

func ResourceTypeDescriptorFromProxyType(proxyType mesh_proto.ProxyType) (core_model.ResourceTypeDescriptor, error) {
switch proxyType {
case mesh_proto.DataplaneProxyType:
return DataplaneResourceTypeDescriptor, nil
case mesh_proto.IngressProxyType:
return ZoneIngressResourceTypeDescriptor, nil
case mesh_proto.EgressProxyType:
return ZoneEgressResourceTypeDescriptor, nil
default:
return core_model.ResourceTypeDescriptor{}, errors.Errorf("%s does not have a corresponding resource type", proxyType)
}
return "", errors.Errorf("%s does not have a corresponding proxy type", t)
}
8 changes: 4 additions & 4 deletions pkg/core/resources/model/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,28 +253,28 @@ func (d ResourceTypeDescriptor) HasInsights() bool {

func (d ResourceTypeDescriptor) NewInsight() Resource {
if !d.HasInsights() {
panic("No insight type precondition broken")
panic(fmt.Sprintf("No insight for type %s precondition broken", d.Name))
}
return newObject(d.Insight)
}

func (d ResourceTypeDescriptor) NewInsightList() ResourceList {
if !d.HasInsights() {
panic("No insight type precondition broken")
panic(fmt.Sprintf("No insight for type %s precondition broken", d.Name))
}
return d.Insight.Descriptor().NewList()
}

func (d ResourceTypeDescriptor) NewOverview() Resource {
if !d.HasInsights() {
panic("No insight type precondition broken")
panic(fmt.Sprintf("No insight for type %s precondition broken", d.Name))
}
return newObject(d.Overview)
}

func (d ResourceTypeDescriptor) NewOverviewList() ResourceList {
if !d.HasInsights() {
panic("No insight type precondition broken")
panic(fmt.Sprintf("No insight for type %s precondition broken", d.Name))
}
return d.Overview.Descriptor().NewList()
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/xds/v3/watchdog_callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ type Watchdog interface {
Start(ctx context.Context)
}

type WatchdogFunc func(ctx context.Context)

func (f WatchdogFunc) Start(ctx context.Context) {
f(ctx)
}

type NewNodeWatchdogFunc func(ctx context.Context, node *envoy_core.Node, streamId int64) (Watchdog, error)

func NewWatchdogCallbacks(newNodeWatchdog NewNodeWatchdogFunc) envoy_xds.Callbacks {
Expand Down
156 changes: 0 additions & 156 deletions pkg/xds/server/callbacks/dataplane_callbacks.go

This file was deleted.

107 changes: 0 additions & 107 deletions pkg/xds/server/callbacks/dataplane_callbacks_test.go

This file was deleted.

Loading

0 comments on commit 23c3094

Please sign in to comment.