forked from meshery/meshery-adapter-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.go
52 lines (46 loc) · 2.39 KB
/
adapter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2020 Layer5, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package adapter
import (
"context"
"sync"
"github.com/layer5io/meshery-adapter-library/meshes"
meshkitCfg "github.com/layer5io/meshkit/config"
"github.com/layer5io/meshkit/logger"
"github.com/layer5io/meshkit/utils/events"
)
// Interface Handler is extended by adapters, and used in package api/grpc that implements the MeshServiceServer.
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
}
// Adapter contains all handlers, channels, clients, and other parameters for an adapter.
// Use type embedding in a specific adapter to extend it.
type Adapter struct {
Config meshkitCfg.Handler
KubeconfigHandler meshkitCfg.Handler
Log logger.Handler
EventStreamer *events.EventStreamer
mx sync.Mutex
}