topology

package
v1.4.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveServicePort

func ResolveServicePort(svcPort corev1.ServicePort, containerPorts []corev1.ContainerPort) (int32, bool)

ResolveServicePort resolves the given service port against the given container port list, as described in the Kubernetes documentation, and returns true if it has been successfully resolved, false otherwise.

The Kubernetes documentation says: Port definitions in Pods have names, and you can reference these names in the targetPort attribute of a Service. This works even if there is a mixture of Pods in the Service using a single configured name, with the same network protocol available via different port numbers.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder builds Topology objects based on the current state of a kubernetes cluster.

func NewBuilder

func NewBuilder(
	serviceLister listers.ServiceLister,
	endpointLister listers.EndpointsLister,
	podLister listers.PodLister,
	trafficTargetLister accesslister.TrafficTargetLister,
	trafficSplitLister splitlister.TrafficSplitLister,
	httpRouteGroupLister speclister.HTTPRouteGroupLister,
	tcpRoutesLister speclister.TCPRouteLister,
	logger logrus.FieldLogger,
) *Builder

NewBuilder creates and returns a new topology Builder instance.

func (*Builder) Build

func (b *Builder) Build(resourceFilter *mk8s.ResourceFilter) (*Topology, error)

Build builds a graph representing the possible interactions between Pods and Services based on the current state of the kubernetes cluster.

type Key

type Key struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
}

Key references a resource.

func (Key) MarshalText

func (k Key) MarshalText() ([]byte, error)

MarshalText marshals the Key.

func (Key) String

func (k Key) String() string

String stringifies the Key.

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the `json.Unmarshaler` interface. This is a temporary workaround for the bug described in this issue: https://github.com/golang/go/issues/38771.

func (*Key) UnmarshalText

func (k *Key) UnmarshalText(data []byte) error

UnmarshalText unmarshals the Key.

type Pod

type Pod struct {
	Name            string                 `json:"name"`
	Namespace       string                 `json:"namespace"`
	ServiceAccount  string                 `json:"serviceAccount"`
	OwnerReferences []v1.OwnerReference    `json:"ownerReferences,omitempty"`
	ContainerPorts  []corev1.ContainerPort `json:"containerPorts,omitempty"`
	IP              string                 `json:"ip"`

	SourceOf      []ServiceTrafficTargetKey `json:"sourceOf,omitempty"`
	DestinationOf []ServiceTrafficTargetKey `json:"destinationOf,omitempty"`
}

Pod is a node of the graph representing a kubernetes pod.

type Service

type Service struct {
	Name        string               `json:"name"`
	Namespace   string               `json:"namespace"`
	Selector    map[string]string    `json:"selector"`
	Annotations map[string]string    `json:"annotations"`
	Ports       []corev1.ServicePort `json:"ports,omitempty"`
	ClusterIP   string               `json:"clusterIp"`
	Pods        []Key                `json:"pods,omitempty"`

	// List of TrafficTargets that are targeting pods which are selected by this service.
	TrafficTargets []ServiceTrafficTargetKey `json:"trafficTargets,omitempty"`
	// List of TrafficSplits that are targeting this service.
	TrafficSplits []Key `json:"trafficSplits,omitempty"`
	// List of TrafficSplit mentioning this service as a backend.
	BackendOf []Key `json:"backendOf,omitempty"`

	Errors []string `json:"errors"`
}

Service is a node of the graph representing a kubernetes service.

func (*Service) AddError

func (s *Service) AddError(err error)

AddError adds the given error to this Service.

type ServiceTrafficTarget

type ServiceTrafficTarget struct {
	Service   Key    `json:"service"`
	Name      string `json:"name"`
	Namespace string `json:"namespace"`

	Sources     []ServiceTrafficTargetSource    `json:"sources,omitempty"`
	Destination ServiceTrafficTargetDestination `json:"destination"`
	Rules       []TrafficSpec                   `json:"rules,omitempty"`

	Errors []string `json:"errors"`
}

ServiceTrafficTarget represents a TrafficTarget applied a on Service. TrafficTargets have a Destination service account. This service account can be set on many pods, each of them, potentially accessible through different services. A ServiceTrafficTarget is a TrafficTarget for a Service which exposes a Pod which has the TrafficTarget Destination service-account.

func (*ServiceTrafficTarget) AddError

func (tt *ServiceTrafficTarget) AddError(err error)

AddError adds the given error to this ServiceTrafficTarget.

type ServiceTrafficTargetDestination

type ServiceTrafficTargetDestination struct {
	ServiceAccount string               `json:"serviceAccount"`
	Namespace      string               `json:"namespace"`
	Ports          []corev1.ServicePort `json:"ports,omitempty"`
	Pods           []Key                `json:"pods,omitempty"`
}

ServiceTrafficTargetDestination represents a destination of a ServiceTrafficTarget. In the SMI specification, a TrafficTarget has a destination service-account. ServiceTrafficTargetDestination holds the pods exposed by the Service which has this service-account.

type ServiceTrafficTargetKey

type ServiceTrafficTargetKey struct {
	Service       Key
	TrafficTarget Key
}

ServiceTrafficTargetKey references a TrafficTarget applied on a Service.

func (ServiceTrafficTargetKey) MarshalText

func (k ServiceTrafficTargetKey) MarshalText() ([]byte, error)

MarshalText marshals the ServiceTrafficTargetKey.

func (ServiceTrafficTargetKey) String

func (k ServiceTrafficTargetKey) String() string

String stringifies the ServiceTrafficTargetKey.

func (*ServiceTrafficTargetKey) UnmarshalJSON

func (k *ServiceTrafficTargetKey) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the `json.Unmarshaler` interface. This is a temporary workaround for the bug described in this issue: https://github.com/golang/go/issues/38771.

func (*ServiceTrafficTargetKey) UnmarshalText

func (k *ServiceTrafficTargetKey) UnmarshalText(data []byte) error

UnmarshalText unmarshals the ServiceTrafficTargetKey.

type ServiceTrafficTargetSource

type ServiceTrafficTargetSource struct {
	ServiceAccount string `json:"serviceAccount"`
	Namespace      string `json:"namespace"`
	Pods           []Key  `json:"pods,omitempty"`
}

ServiceTrafficTargetSource represents a source of a ServiceTrafficTarget. In the SMI specification, a TrafficTarget has a list of sources, each of them being a service-account name. ServiceTrafficTargetSource represents this service-account, populated with the pods having this Service.

type Topology

type Topology struct {
	Services              map[Key]*Service                                  `json:"services"`
	Pods                  map[Key]*Pod                                      `json:"pods"`
	ServiceTrafficTargets map[ServiceTrafficTargetKey]*ServiceTrafficTarget `json:"serviceTrafficTargets"`
	TrafficSplits         map[Key]*TrafficSplit                             `json:"trafficSplits"`
}

Topology holds the graph and represents the different paths a request can follow. Each Pods and services are nodes of the graph.

func NewTopology

func NewTopology() *Topology

NewTopology creates a new Topology.

type TrafficSpec

type TrafficSpec struct {
	HTTPRouteGroup *specs.HTTPRouteGroup `json:"httpRouteGroup,omitempty"`
	TCPRoute       *specs.TCPRoute       `json:"tcpRoute,omitempty"`

	// HTTPMatches is the list of HTTPMatch selected from the HTTPRouteGroup.
	HTTPMatches []*specs.HTTPMatch `json:"httpMatches,omitempty"`
}

TrafficSpec represents a Spec which can be used for restricting access to a route in a TrafficTarget or a TrafficSplit.

type TrafficSplit

type TrafficSplit struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`

	Service  Key                   `json:"service"`
	Backends []TrafficSplitBackend `json:"backends,omitempty"`
	Rules    []TrafficSpec         `json:"rules,omitempty"`

	// List of Pods that are explicitly allowed to pass through the TrafficSplit.
	Incoming []Key `json:"incoming,omitempty"`

	Errors []string `json:"errors"`
}

TrafficSplit represents a TrafficSplit applied on a Service.

func (*TrafficSplit) AddError

func (ts *TrafficSplit) AddError(err error)

AddError adds the given error to this TrafficSplit.

type TrafficSplitBackend

type TrafficSplitBackend struct {
	Weight  int `json:"weight"`
	Service Key `json:"service"`
}

TrafficSplitBackend is a backend of a TrafficSplit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL