adapter

package
v0.1.24 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: Apache-2.0 Imports: 28 Imported by: 44

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"
)
View Source
const (
	// OAM Metadata constants
	OAMAdapterNameMetadataKey       = "adapter.meshery.io/name"
	OAMComponentCategoryMetadataKey = "ui.meshery.io/category"

	//Runtime generation methods
	Manifests  = "MANIFESTS"
	HelmCHARTS = "HELM_CHARTS"
)
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 = fmt.Errorf("none of the auth infos are valid either the certificate path is invalid or is inaccessible")
)
View Source
var (
	NoneVersion  = []Version{"none"}
	NoneTemplate = []Template{"none"}
)

Functions

func ErrClientConfig

func ErrClientConfig(err error) error

func ErrClientSet

func ErrClientSet(err error) error

func ErrConnectSmi added in v0.1.10

func ErrConnectSmi(err error) error

ErrConnectSmi is the error for connecting to smi tool

func ErrCreateInstance added in v0.1.4

func ErrCreateInstance(err error) error

func ErrDeleteSmi added in v0.1.10

func ErrDeleteSmi(err error) error

ErrDeleteSmi is the error for deleting smi tool

func ErrGenerateComponents added in v0.1.23

func ErrGenerateComponents(err error) error

func ErrInstallSmi added in v0.1.10

func ErrInstallSmi(err error) error

ErrInstallSmi is the error for installing smi tool

func ErrJSONMarshal added in v0.1.16

func ErrJSONMarshal(err error) error

ErrJSONMarshal is the error for json marhal failure

func ErrListOperations added in v0.1.2

func ErrListOperations(err error) error

func ErrMeshConfig

func ErrMeshConfig(err error) error

func ErrNewSmi added in v0.1.2

func ErrNewSmi(err error) error

func ErrOAMRetry added in v0.1.16

func ErrOAMRetry(err error) error

func ErrOpenOAMDefintionFile added in v0.1.16

func ErrOpenOAMDefintionFile(err error) error

ErrOpenOAMDefintionFile is the error for opening OAM Definition file

func ErrOpenOAMRefFile added in v0.1.16

func ErrOpenOAMRefFile(err error) error

ErrOpenOAMRefFile is the error for opening OAM Schema Ref file

func ErrRunSmi added in v0.1.2

func ErrRunSmi(err error) error

func ErrSmiInit added in v0.1.10

func ErrSmiInit(des string) error

ErrSmiInit is the error for smi init method

func ErrStreamEvent

func ErrStreamEvent(err error) error

func ErrValidateKubeconfig added in v0.1.4

func ErrValidateKubeconfig(err error) error

func RegisterWorkLoadsDynamically added in v0.1.23

func RegisterWorkLoadsDynamically(runtime, host string, dc *DynamicComponentsConfig) error

Types

type Adapter

type Adapter struct {
	Config meshkitCfg.Handler
	Log    logger.Handler

	KubeconfigHandler meshkitCfg.Handler
	Channel           *chan interface{}

	KubeClient        *kubernetes.Clientset
	DynamicKubeClient dynamic.Interface
	RestConfig        rest.Config
	ClientcmdConfig   *clientcmdapi.Config
	MesheryKubeclient *mesherykube.Client
}

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(context.Context, OperationRequest) error

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

func (*Adapter) CreateInstance

func (h *Adapter) CreateInstance(kubeconfig []byte, contextName string, ch *chan interface{}) error

Instantiates clients used in deploying and managing mesh instances, e.g. Kubernetes clients. This needs to be called before applying operations.

func (*Adapter) GetComponentInfo added in v0.1.14

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

func (*Adapter) GetName

func (h *Adapter) GetName() string

func (*Adapter) GetVersion added in v0.1.2

func (h *Adapter) GetVersion() string

func (*Adapter) ListOperations

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

List all operations an adapter supports.

func (*Adapter) ProcessOAM added in v0.1.13

func (h *Adapter) ProcessOAM(context.Context, OAMRequest) (string, error)

ProcessOAM processes OAM components. This is adapter specific and needs to be implemented by each adapter.

func (*Adapter) RunSMITest added in v0.1.10

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 *Event, err error)

func (*Adapter) StreamInfo

func (h *Adapter) StreamInfo(e *Event)

type Detail added in v0.1.10

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 added in v0.1.23

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

type Event

type Event struct {
	Operationid string `json:"operationid,omitempty"`
	EType       int32  `json:"type,string,omitempty"`
	Summary     string `json:"summary,omitempty"`
	Details     string `json:"details,omitempty"`
}

type Handler

type Handler interface {
	GetName() string                                        // Returns the name of the adapter.
	GetComponentInfo(interface{}) error                     // Returns the component info.
	CreateInstance([]byte, string, *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(*Event, error) // Streams an error event, e.g. to a channel
	StreamInfo(*Event)       // 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 OAMRegistrant added in v0.1.16

type OAMRegistrant struct {
	// Paths is a slice for holding the paths of OAMDefitions,
	// OAMRefSchema and Host on the filesystem
	//
	// OAMRegistrant will read the definitions from these
	// paths and will register them to the OAM registry
	Paths []OAMRegistrantDefinitionPath

	// OAMHTTPRegistry is the address of an OAM registry
	OAMHTTPRegistry string
}

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

func NewOAMRegistrant added in v0.1.16

func NewOAMRegistrant(paths []OAMRegistrantDefinitionPath, oamHTTPRegistry string) *OAMRegistrant

NewOAMRegistrant returns an instance of OAMRegistrant

func (*OAMRegistrant) Register added in v0.1.16

func (or *OAMRegistrant) Register() 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 OAMRegistrantData added in v0.1.16

type OAMRegistrantData struct {
	OAMDefinition interface{}       `json:"oam_definition,omitempty"`
	OAMRefSchema  string            `json:"oam_ref_schema,omitempty"`
	Host          string            `json:"host,omitempty"`
	Restricted    bool              `json:"restricted,omitempty"`
	Metadata      map[string]string `json:"metadata,omitempty"`
}

OAMRegistrantData struct defines the body of the POST request that is sent to the OAM registry (Meshery)

The body contains the 1. OAM definition, which is in accordance with the OAM spec 2. OAMRefSchema, which is json schema draft-4, draft-7 or draft-8 for the corresponding OAM object 3. Host is this service's grpc address in the form of `hostname:port` 4. Restricted should be set to true if the given capability is meant to be used internally 5. Metadata can be a map of key value pairs

type OAMRegistrantDefinitionPath added in v0.1.16

type OAMRegistrantDefinitionPath struct {
	// OAMDefinitionPath holds the path for OAM Definition file
	OAMDefintionPath string
	// OAMRefSchemaPath holds the path for the OAM Ref Schema file
	OAMRefSchemaPath string
	// Host is the address of the gRPC host capable of processing the request
	Host string
	// Restricted should be set to true if this capability should be restricted
	// only to the server and shouldn't be exposed to the user for direct usage
	Restricted bool
	// Metadata is the other data which can be attached to the post request body
	//
	// Metadata like name of the component, etc.
	Metadata map[string]string
}

OAMRegistrantDefinitionPath - Structure for configuring registrant paths

type OAMRequest added in v0.1.13

type OAMRequest struct {
	Username  string
	DeleteOp  bool
	OamComps  []string
	OamConfig 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.
}

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 added in v0.1.10

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 added in v0.1.10

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

type SMITestOptions added in v0.1.10

type SMITestOptions struct {
	Ctx         context.Context
	OperationID string

	// Namespace is the namespace where the SMI conformance
	// must be installed
	//
	// Defaults to "meshery"
	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
}

SMITestOptions describes the options for the SMI Test runner

type Service added in v0.1.8

type Service string

type Spec

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

type Template added in v0.1.4

type Template string

func (Template) String added in v0.1.4

func (t Template) String() string

type Version added in v0.1.4

type Version string

Jump to

Keyboard shortcuts

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