Skip to content

Commit

Permalink
kuma-cp: add a custom version of SnapshotCache that supports arbitrar…
Browse files Browse the repository at this point in the history
…y xDS resources
  • Loading branch information
yskopets committed Jan 8, 2020
1 parent 7d23199 commit 55a3175
Show file tree
Hide file tree
Showing 4 changed files with 487 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Changes:

* feature: add a custom version of SnapshotCache that supports arbitrary xDS resources
[#528](https://github.com/Kong/kuma/pull/528)
* feature: add proto definition for Monitoring Assignment Discovery Service (MADS)
[#525](https://github.com/Kong/kuma/pull/525)
* feature: enable Envoy Admin API by default with an option to opt out
Expand Down
73 changes: 73 additions & 0 deletions pkg/mads/cache/snapshot.go
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
}
}
5 changes: 5 additions & 0 deletions pkg/mads/types.go
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"
)
Loading

0 comments on commit 55a3175

Please sign in to comment.