adapter

package
v0.0.0-...-5f85532 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: Apache-2.0 Imports: 32 Imported by: 2

Documentation

Overview

Package adapter provides the default implementation of an adapter Handler, called by the MeshServiceServer implementation.

It implements also common Kubernetes operations, leveraging the comparatively low-level client-go library, and handling of YAML-documents.

Index

Constants

View Source
const (
	ErrGetNameCode              = "1000"
	ErrCreateInstanceCode       = "1001"
	ErrMeshConfigCode           = "1002"
	ErrValidateKubeconfigCode   = "1003"
	ErrClientConfigCode         = "1004"
	ErrClientSetCode            = "1005"
	ErrStreamEventCode          = "1006"
	ErrOpInvalidCode            = "1007"
	ErrApplyOperationCode       = "1008"
	ErrListOperationsCode       = "1009"
	ErrNewSmiCode               = "1010"
	ErrRunSmiCode               = "1011"
	ErrNoResponseCode           = "1011"
	ErrOpenOAMDefintionFileCode = "1013"
	ErrOpenOAMRefFileCode       = "1014"
	ErrJSONMarshalCode          = "1015"
	ErrOAMRetryCode             = "1016"
	ErrSmiInitCode              = "1007"
	ErrInstallSmiCode           = "1008"
	ErrConnectSmiCode           = "1009"
	ErrDeleteSmiCode            = "1010"
	ErrGenerateComponentsCode   = "1011"
	ErrAuthInfosInvalidMsgCode  = "1012"
	ErrCreatingComponentsCode   = "1013"
)
View Source
const (
	ServerKey         = "server"
	MeshSpecKey       = "mesh"
	OperationsKey     = "operations"
	KubeconfigPathKey = "kubeconfig-path"
)

Variables

View Source
var (
	ErrGetName    = errors.New(ErrGetNameCode, errors.Alert, []string{"Unable to get mesh name"}, []string{}, []string{}, []string{})
	ErrOpInvalid  = errors.New(ErrOpInvalidCode, errors.Alert, []string{"Invalid operation"}, []string{}, []string{}, []string{})
	ErrNoResponse = errors.New(ErrNoResponseCode, errors.Alert, []string{"No response from the smi tool"}, []string{}, []string{}, []string{})
	// ErrAuthInfosInvalidMsg is the error message when the all of auth infos have invalid or inaccessible paths
	// as there certificate paths
	ErrAuthInfosInvalidMsg = errors.New(
		ErrAuthInfosInvalidMsgCode,
		errors.Alert,
		[]string{"none of the auth info is valid. Certificate path is invalid or is inaccessible"},
		[]string{"One or more Kubernetes authentication info is either invalid or the certificate paths are invalid causing Meshplay adapter setup failure"},
		[]string{"kubeconfig passed to Meshplay may be referring to a \"context\" whose auth info is a file path", "adapter may have cached a copy of kubeconfig"},
		[]string{"ensure kubeconfig passed to Meshplay is flattened", "if running adapter in Kubernetes, attempt to restart the pod; in development environment try deleting ~/.meshplay s"},
	)
)
View Source
var (
	Manifests  = "MANIFESTS"
	HelmCharts = "HELM_CHARTS"
)
View Source
var (
	NoneVersion  = []Version{"none"}
	NoneTemplate = []Template{"none"}
)
View Source
var AvailableVersions = map[string]bool{}

AvailableVersions denote the component versions available statically

View Source
var (
	MeshmodelComponents = filepath.Join(basePath, "templates", "meshmodel", "components")
)

Functions

func CreateComponents

func CreateComponents(scfg StaticCompConfig) error

CreateComponents generates components for a given configuration and stores them.

func ErrClientConfig

func ErrClientConfig(err error) error

func ErrClientSet

func ErrClientSet(err error) error

func ErrConnectSmi

func ErrConnectSmi(err error) error

ErrConnectSmi is the error for connecting to smi tool

func ErrCreateInstance

func ErrCreateInstance(err error) error

func ErrCreatingComponents

func ErrCreatingComponents(err error) error

ErrCreatingComponents

func ErrDeleteSmi

func ErrDeleteSmi(err error) error

ErrDeleteSmi is the error for deleting smi tool

func ErrGenerateComponents

func ErrGenerateComponents(err error) error

will be depracated

func ErrInstallSmi

func ErrInstallSmi(err error) error

ErrInstallSmi is the error for installing smi tool

func ErrJSONMarshal

func ErrJSONMarshal(err error) error

ErrJSONMarshal is the error for json marhal failure

func ErrListOperations

func ErrListOperations(err error) error

func ErrMeshConfig

func ErrMeshConfig(err error) error

func ErrNewSmi

func ErrNewSmi(err error) error

func ErrOAMRetry

func ErrOAMRetry(err error) error

func ErrOpenOAMDefintionFile

func ErrOpenOAMDefintionFile(err error) error

ErrOpenOAMDefintionFile is the error for opening OAM Definition file

func ErrOpenOAMRefFile

func ErrOpenOAMRefFile(err error) error

ErrOpenOAMRefFile is the error for opening OAM Schema Ref file

func ErrRegisterComponents

func ErrRegisterComponents(err error) error

func ErrRunSmi

func ErrRunSmi(err error) error

func ErrSmiInit

func ErrSmiInit(des string) error

ErrSmiInit is the error for smi init method

func ErrStreamEvent

func ErrStreamEvent(err error) error

func ErrValidateKubeconfig

func ErrValidateKubeconfig(err error) error

func RegisterMeshModelComponents

func RegisterMeshModelComponents(uuid, runtime, host, port string) error

Types

type Adapter

type Adapter struct {
	Config            meshkitCfg.Handler
	KubeconfigHandler meshkitCfg.Handler
	Log               logger.Handler
	EventStreamer     *events.EventStreamer
}

Adapter contains all handlers, channels, clients, and other parameters for an adapter. Use type embedding in a specific adapter to extend it.

func (*Adapter) ApplyOperation

func (h *Adapter) ApplyOperation(ctx context.Context, op OperationRequest, hchan *chan interface{}) error

Applies an adapter operation. This is adapter specific and needs to be implemented by each adapter.

func (*Adapter) GetComponentInfo

func (h *Adapter) GetComponentInfo(svc interface{}) error

func (*Adapter) GetName

func (h *Adapter) GetName() string

func (*Adapter) GetVersion

func (h *Adapter) GetVersion() string

func (*Adapter) ListOperations

func (h *Adapter) ListOperations() (Operations, error)

List all operations an adapter supports.

func (*Adapter) RunSMITest

func (h *Adapter) RunSMITest(opts SMITestOptions) (Response, error)

RunSMITest runs the SMI test on the adapter's service mesh

func (*Adapter) StreamErr

func (h *Adapter) StreamErr(e *meshes.EventsResponse, err error)

func (*Adapter) StreamInfo

func (h *Adapter) StreamInfo(e *meshes.EventsResponse)

type Detail

type Detail struct {
	SmiSpecification string `json:"smi_specification,omitempty"`
	SmiVersion       string `json:"smi_version,omitempty"`
	Time             string `json:"time,omitempty"`
	Assertions       string `json:"assertions,omitempty"`
	Result           string `json:"result,omitempty"`
	Reason           string `json:"reason,omitempty"`
	Capability       string `json:"capability,omitempty"`
	Status           string `json:"status,omitempty"`
}

type DynamicComponentsConfig

type DynamicComponentsConfig struct {
	TimeoutInMinutes time.Duration
	URL              string
	GenerationMethod string
	Config           manifests.Config
	Operation        string
}

This will be depracated once all adapters migrate to new method of component creation( using static config) and registeration

type Handler

type Handler interface {
	GetName() string                    // Returns the name of the adapter.
	GetComponentInfo(interface{}) error // Returns the component info.
	// CreateInstance(*chan interface{}) error                 // Instantiates clients used in deploying and managing mesh instances, e.g. Kubernetes clients.
	ApplyOperation(context.Context, OperationRequest) error // Applies an adapter operation. This is adapter specific and needs to be implemented by each adapter.
	ListOperations() (Operations, error)                    // List all operations an adapter supports.
	ProcessOAM(ctx context.Context, srv OAMRequest) (string, error)

	// Need not implement this method and can be reused
	StreamErr(*meshes.EventsResponse, error) // Streams an error event, e.g. to a channel
	StreamInfo(*meshes.EventsResponse)       // Streams an informational event, e.g. to a channel
}

Interface Handler is extended by adapters, and used in package api/grpc that implements the MeshServiceServer.

func AddLogger

func AddLogger(logger logger.Handler, h Handler) Handler

type MeshModelConfig

type MeshModelConfig struct {
	Category         string
	CategoryMetadata map[string]interface{}
	Metadata         map[string]interface{}
}

type MeshModelRegistrant

type MeshModelRegistrant struct {
	Paths        []MeshModelRegistrantDefinitionPath
	HTTPRegistry string
}

MeshModel provides utility functions for registering MeshModel components to a registry in a reliable way

func NewMeshModelRegistrant

func NewMeshModelRegistrant(paths []MeshModelRegistrantDefinitionPath, HTTPRegistry string) *MeshModelRegistrant

NewMeshModelRegistrant returns an instance of NewMeshModelRegistrant

func (*MeshModelRegistrant) Register

func (or *MeshModelRegistrant) Register(ctxID string) error

Register will register each capability individually to the OAM Capability registry

It sends a POST request to the endpoint in the "OAMHTTPRegistry", if the request fails then the request is retried. It uses exponential backoff algorithm to determine the interval between in the retries. It will retry only for 10 mins and will stop retrying after that.

Register function is a blocking function

type MeshModelRegistrantDefinitionPath

type MeshModelRegistrantDefinitionPath struct {
	// EntityDefinitionPath holds the path for Entity Definition file
	EntityDefintionPath string

	Type types.CapabilityType
	// Host is the address of the gRPC host capable of processing the request
	Host string
	Port int
}

MeshModelRegistrantDefinitionPath - Structure for configuring registrant paths

type OAMRequest

type OAMRequest struct {
	Username   string
	DeleteOp   bool
	OamComps   []string
	OamConfig  string
	K8sConfigs []string
}

type Operation

type Operation struct {
	Type                 int32             `json:"type,string,omitempty"`
	Description          string            `json:"description,omitempty"`
	Versions             []Version         `json:"versions,omitempty"`
	Templates            []Template        `json:"templates,omitempty"`
	Services             []Service         `json:"services,omitempty"`
	AdditionalProperties map[string]string `json:"additional_properties,omitempty"`
}

Operation represents an operation of a given Type (see meshes.OpCategory), with a set of properties.

type OperationRequest

type OperationRequest struct {
	OperationName     string // The identifier of the operation. It is used as key in the Operations map. Avoid using a verb as part of the name, as it designates both provisioning as deprovisioning operations.
	Namespace         string // The namespace to use in the environment, e.g. Kubernetes, where the operation is applied.
	Username          string // User to execute operation as, if any.
	CustomBody        string // Custom operation manifest, in the case of a custom operation (OpCategory_CUSTOM).
	IsDeleteOperation bool   // If true, the operation specified by OperationName is reverted, i.e. all resources created are deleted.
	OperationID       string // ID of the operation, if any. This identifies a specific operation invocation.
	K8sConfigs        []string
	Version           string // Service mesh version to be installed, defaults to latest version.
}

OperationRequest contains the request data from meshes.ApplyRuleRequest.

type Operations

type Operations map[string]*Operation

Operations contains all operations supported by an adapter.

type Response

type Response struct {
	ID                string    `json:"id,omitempty"`
	Date              string    `json:"date,omitempty"`
	MeshName          string    `json:"mesh_name,omitempty"`
	MeshVersion       string    `json:"mesh_version,omitempty"`
	CasesPassed       string    `json:"cases_passed,omitempty"`
	PassingPercentage string    `json:"passing_percentage,omitempty"`
	Status            string    `json:"status,omitempty"`
	MoreDetails       []*Detail `json:"more_details,omitempty"`
}

type SMITest

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

type SMITestOptions

type SMITestOptions struct {
	Ctx         context.Context
	OperationID string

	// Namespace is the namespace where the SMI conformance
	// must be installed
	//
	// Defaults to "meshplay"
	Namespace string

	// Manifest is the remote location of manifest
	Manifest string

	// Labels is the standard kubernetes labels
	Labels map[string]string

	// Annotations is the standard kubernetes annotations
	Annotations map[string]string

	Kubeconfigs []string
}

SMITestOptions describes the options for the SMI Test runner

type Service

type Service string

type Spec

type Spec struct {
	Name    string `json:"name"`
	Status  string `json:"status"`
	Version string `json:"version"`
}

type StaticCompConfig

type StaticCompConfig struct {
	MeshModelName   string //Used in Adding ModelName onto Core Meshmodel components. Pass it the same as meshName in OAM components
	URL             string //URL
	Method          string //Use the constants exported by package. Manifests or Helm
	MeshModelPath   string
	MeshModelConfig MeshModelConfig
	DirName         string           //The directory's name. By convention, it should be the version name
	Config          manifests.Config //Filters required to create definition and schema
	Force           bool             //When set to true, if the file with same name already exists, they will be overridden
}

StaticCompConfig is used to configure CreateComponents

type Template

type Template string

func (Template) String

func (t Template) String() string

type Version

type Version string

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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