-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kuma-cp: add a custom version of SnapshotCache that supports arbitrar…
…y xDS resources
- Loading branch information
Showing
4 changed files
with
487 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
|
||
envoy_cache "github.com/envoyproxy/go-control-plane/pkg/cache" | ||
|
||
"github.com/Kong/kuma/pkg/mads" | ||
util_xds "github.com/Kong/kuma/pkg/util/xds" | ||
) | ||
|
||
// NewSnapshot creates a snapshot from response types and a version. | ||
func NewSnapshot(version string, assignments []envoy_cache.Resource) Snapshot { | ||
return Snapshot{ | ||
MonitoringAssignments: envoy_cache.NewResources(version, assignments), | ||
} | ||
} | ||
|
||
// Snapshot is an internally consistent snapshot of xDS resources. | ||
type Snapshot struct { | ||
MonitoringAssignments envoy_cache.Resources | ||
} | ||
|
||
var _ util_xds.Snapshot = &Snapshot{} | ||
|
||
// GetSupportedTypes returns a list of xDS types supported by this snapshot. | ||
func (s *Snapshot) GetSupportedTypes() []string { | ||
return []string{mads.MonitoringAssignmentType} | ||
} | ||
|
||
// Consistent check verifies that the dependent resources are exactly listed in the | ||
// snapshot. | ||
func (s *Snapshot) Consistent() error { | ||
if s == nil { | ||
return errors.New("nil snapshot") | ||
} | ||
return nil | ||
} | ||
|
||
// GetResources selects snapshot resources by type. | ||
func (s *Snapshot) GetResources(typ string) map[string]envoy_cache.Resource { | ||
if s == nil { | ||
return nil | ||
} | ||
switch typ { | ||
case mads.MonitoringAssignmentType: | ||
return s.MonitoringAssignments.Items | ||
} | ||
return nil | ||
} | ||
|
||
// GetVersion returns the version for a resource type. | ||
func (s *Snapshot) GetVersion(typ string) string { | ||
if s == nil { | ||
return "" | ||
} | ||
switch typ { | ||
case mads.MonitoringAssignmentType: | ||
return s.MonitoringAssignments.Version | ||
} | ||
return "" | ||
} | ||
|
||
// SetVersion sets the version for a resource type. | ||
func (s *Snapshot) SetVersion(typ string, version string) { | ||
if s == nil { | ||
return | ||
} | ||
switch typ { | ||
case mads.MonitoringAssignmentType: | ||
s.MonitoringAssignments.Version = version | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package mads | ||
|
||
const ( | ||
MonitoringAssignmentType = "type.googleapis.com/kuma.observability.v1alpha1.MonitoringAssignment" | ||
) |
Oops, something went wrong.