Documentation
¶
Index ¶
- Constants
- func ApiServerProxyPath(namespace, schema, svcname, port string) string
- func HeadersFrom(kvs map[string]string) http.Header
- func NewRestDecoder(r io.ReadCloser, newitemfunc func() client.Object) *restDecoder
- func QueryFrom(kvs map[string]string) url.Values
- func ResponseBodyRewriter(rewritefunc func(io.Reader, io.Writer) error) func(resp *http.Response) error
- func WrappedResponse(intodata interface{}) *httputil.Response
- type AuthInfo
- type ChainedProxy
- type Client
- type ClientMeta
- type ClientSet
- func (h *ClientSet) ClientOf(ctx context.Context, name string) (Client, error)
- func (h *ClientSet) Clusters() []string
- func (h ClientSet) ExecuteInEachCluster(ctx context.Context, f func(ctx context.Context, cli Client) error) error
- func (h *ClientSet) Initialize(db *gorm.DB) error
- func (h *ClientSet) Name() string
- type ConnInitResult
- type DelegateClient
- type ExtendClient
- func (c *ExtendClient) CheckAlertmanagerConfig(ctx context.Context, data *monitoringv1alpha1.AlertmanagerConfig) error
- func (c *ExtendClient) ClusterResourceStatistics(ctx context.Context, ret interface{}) error
- func (c *ExtendClient) ClusterWorkloadStatistics(ctx context.Context, ret interface{}) error
- func (c *ExtendClient) CommitRawLoggingAlertResource(ctx context.Context, raw *prometheus.RawLoggingAlertRule) error
- func (c *ExtendClient) CommitRawMonitorAlertResource(ctx context.Context, raw *prometheus.RawMonitorAlertResource) error
- func (c *ExtendClient) CreateOrUpdateAlertEmailSecret(ctx context.Context, namespace string, rec *prometheus.ReceiverConfig) error
- func (c *ExtendClient) CreateOrUpdateSilenceIfNotExist(ctx context.Context, info models.AlertInfo) error
- func (c *ExtendClient) CreateReceiver(ctx context.Context, rec prometheus.ReceiverConfig) error
- func (c *ExtendClient) DeleteAlertEmailSecret(ctx context.Context, namespace string, rec monitoringv1alpha1.Receiver) error
- func (c *ExtendClient) DeleteReceiver(ctx context.Context, rec prometheus.ReceiverConfig) error
- func (c *ExtendClient) DeleteSilenceIfExist(ctx context.Context, info models.AlertInfo) error
- func (c *ExtendClient) DisablePlugin(ctx context.Context, ptype, name string) error
- func (c *ExtendClient) EnablePlugin(ctx context.Context, ptype, name string) error
- func (c *ExtendClient) GetLokiAlertRules(ctx context.Context) (map[string]prometheus.RealTimeAlertRule, error)
- func (c *ExtendClient) GetOrCreateAlertmanagerConfig(ctx context.Context, namespace string, name string) (*monitoringv1alpha1.AlertmanagerConfig, error)
- func (c *ExtendClient) GetOrCreatePrometheusRule(ctx context.Context, namespace, name string) (*monitoringv1.PrometheusRule, error)
- func (c *ExtendClient) GetPromeAlertRules(ctx context.Context, name string) (map[string]prometheus.RealTimeAlertRule, error)
- func (c *ExtendClient) GetPrometheusLabelNames(ctx context.Context, match, start, end string) ([]string, error)
- func (c *ExtendClient) GetPrometheusLabelValues(ctx context.Context, match, label, start, end string) ([]string, error)
- func (c *ExtendClient) GetRawLoggingAlertResource(ctx context.Context, namespace string) (*prometheus.RawLoggingAlertRule, error)
- func (c *ExtendClient) GetRawMonitorAlertResource(ctx context.Context, namespace, name string, opts *prometheus.MonitorOptions) (*prometheus.RawMonitorAlertResource, error)
- func (c *ExtendClient) Healthy(ctx context.Context) error
- func (c *ExtendClient) ListLoggingAlertRules(ctx context.Context, namespace string, hasDetail bool) ([]prometheus.LoggingAlertRule, error)
- func (c *ExtendClient) ListMonitorAlertRules(ctx context.Context, namespace string, opts *prometheus.MonitorOptions, ...) ([]prometheus.MonitorAlertRule, error)
- func (c *ExtendClient) ListPlugins(ctx context.Context) (map[string]interface{}, error)
- func (c *ExtendClient) ListReceivers(ctx context.Context, namespace, scope, search string) ([]prometheus.ReceiverConfig, error)
- func (c *ExtendClient) ListSilences(ctx context.Context, labels map[string]string, commentPrefix string) ([]alertmanagertypes.Silence, error)
- func (c *ExtendClient) LokiQuery(ctx context.Context, logql string) (loki.QueryResponseData, error)
- func (c *ExtendClient) PrometheusQueryRange(ctx context.Context, query, start, end, step string) (prommodel.Matrix, error)
- func (c *ExtendClient) PrometheusVector(ctx context.Context, query string) (prommodel.Vector, error)
- func (c *ExtendClient) UpdateReceiver(ctx context.Context, rec prometheus.ReceiverConfig) error
- type PortForwarder
- type Request
- type ServerInfo
- type StatusTypedClient
- type TypedClient
- func (c TypedClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
- func (c TypedClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
- func (c TypedClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error
- func (c TypedClient) DialWebsocket(ctx context.Context, rpath string, headers http.Header) (*websocket.Conn, *http.Response, error)
- func (c TypedClient) DoRawRequest(ctx context.Context, clientreq Request) (*http.Response, error)
- func (c TypedClient) DoRequest(ctx context.Context, req Request) error
- func (c TypedClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object) error
- func (c TypedClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
- func (c TypedClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, ...) error
- func (c TypedClient) PortForward(ctx context.Context, obj client.Object, port int) (*PortForwarder, error)
- func (c TypedClient) Proxy(ctx context.Context, obj client.Object, port int, req *http.Request, ...) error
- func (c TypedClient) RESTMapper() meta.RESTMapper
- func (c TypedClient) Scheme() *runtime.Scheme
- func (c TypedClient) Status() client.StatusWriter
- func (c TypedClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error
- func (c TypedClient) Watch(ctx context.Context, obj client.ObjectList, opts ...client.ListOption) (watch.Interface, error)
- type WebsocketRoundTripper
Constants ¶
const (
AgentModeApiServer = "apiServerProxy"
AgentModeAHTTP = "http"
AgentModeHTTPS = "https"
)
Variables ¶
This section is empty.
Functions ¶
func ApiServerProxyPath ¶
func ApiServerProxyPath(namespace, schema, svcname, port string) string
func HeadersFrom ¶
func HeadersFrom(kvs map[string]string) http.Header
func NewRestDecoder ¶
func NewRestDecoder(r io.ReadCloser, newitemfunc func() client.Object) *restDecoder
func ResponseBodyRewriter ¶
func ResponseBodyRewriter(rewritefunc func(io.Reader, io.Writer) error) func(resp *http.Response) error
ResponseBodyRewriter 会正确处理 gzip 以及 deflate 的content-encodeing 以及response 的content-length 用于需要修改代理的响应体是非常有用
func WrappedResponse ¶
func WrappedResponse(intodata interface{}) *httputil.Response
Types ¶
type AuthInfo ¶
type AuthInfo struct {
ClientCertificate []byte `json:"clientCertificate,omitempty"`
ClientKey []byte `json:"clientKey,omitempty"`
Token string `json:"token,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
}
type ChainedProxy ¶
type ChainedProxy []func(*http.Request) (*url.URL, error)
type Client ¶
type Client interface {
client.WithWatch
DoRequest(ctx context.Context, req Request) error
DoRawRequest(ctx context.Context, clientreq Request) (*http.Response, error)
DialWebsocket(ctx context.Context, path string, headers http.Header) (*websocket.Conn, *http.Response, error)
Extend() *ExtendClient
Name() string
BaseAddr() url.URL
APIServerAddr() url.URL
APIServerVersion() string
// Deprecated: remove
Proxy(ctx context.Context, obj client.Object, port int, req *http.Request, writer http.ResponseWriter, rewritefunc func(r *http.Response) error) error
}
type ClientMeta ¶
type ClientMeta struct {
Name string
BaseAddr *url.URL
TLSConfig *tls.Config
Proxy func(req *http.Request) (*url.URL, error)
APIServerAddr *url.URL
APIServerVersion string
}
type ClientSet ¶
type ClientSet struct {
// contains filtered or unexported fields
}
func NewClientSet ¶
func NewClientSet(database *database.Database) (*ClientSet, error)
func (*ClientSet) ClientOf ¶
func (h *ClientSet) ClientOf(ctx context.Context, name string) (Client, error)
func (ClientSet) ExecuteInEachCluster ¶
func (h ClientSet) ExecuteInEachCluster(ctx context.Context, f func(ctx context.Context, cli Client) error) error
ExecuteInEachCluster Execute in each cluster concurrently
func (*ClientSet) Initialize ¶
func (h *ClientSet) Initialize(db *gorm.DB) error
Initialize for gorm plugin
type ConnInitResult ¶
type ConnInitResult struct {
Conn *websocket.Conn
Resp *http.Response
Err error
}
type DelegateClient ¶
type DelegateClient struct {
*TypedClient
// contains filtered or unexported fields
}
func (*DelegateClient) APIServerAddr ¶
func (c *DelegateClient) APIServerAddr() url.URL
func (*DelegateClient) APIServerVersion ¶
func (c *DelegateClient) APIServerVersion() string
type ExtendClient ¶
type ExtendClient struct {
*TypedClient
}
func (*ExtendClient) CheckAlertmanagerConfig ¶
func (c *ExtendClient) CheckAlertmanagerConfig(ctx context.Context, data *monitoringv1alpha1.AlertmanagerConfig) error
func (*ExtendClient) ClusterResourceStatistics ¶
func (c *ExtendClient) ClusterResourceStatistics(ctx context.Context, ret interface{}) error
func (*ExtendClient) ClusterWorkloadStatistics ¶
func (c *ExtendClient) ClusterWorkloadStatistics(ctx context.Context, ret interface{}) error
statistics.system/v1
func (*ExtendClient) CommitRawLoggingAlertResource ¶
func (c *ExtendClient) CommitRawLoggingAlertResource(ctx context.Context, raw *prometheus.RawLoggingAlertRule) error
func (*ExtendClient) CommitRawMonitorAlertResource ¶
func (c *ExtendClient) CommitRawMonitorAlertResource(ctx context.Context, raw *prometheus.RawMonitorAlertResource) error
func (*ExtendClient) CreateOrUpdateAlertEmailSecret ¶
func (c *ExtendClient) CreateOrUpdateAlertEmailSecret(ctx context.Context, namespace string, rec *prometheus.ReceiverConfig) error
func (*ExtendClient) CreateOrUpdateSilenceIfNotExist ¶
func (c *ExtendClient) CreateOrUpdateSilenceIfNotExist(ctx context.Context, info models.AlertInfo) error
use for blacklist
func (*ExtendClient) CreateReceiver ¶
func (c *ExtendClient) CreateReceiver(ctx context.Context, rec prometheus.ReceiverConfig) error
func (*ExtendClient) DeleteAlertEmailSecret ¶
func (c *ExtendClient) DeleteAlertEmailSecret(ctx context.Context, namespace string, rec monitoringv1alpha1.Receiver) error
func (*ExtendClient) DeleteReceiver ¶
func (c *ExtendClient) DeleteReceiver(ctx context.Context, rec prometheus.ReceiverConfig) error
func (*ExtendClient) DeleteSilenceIfExist ¶
func (c *ExtendClient) DeleteSilenceIfExist(ctx context.Context, info models.AlertInfo) error
use for blacklist
func (*ExtendClient) DisablePlugin ¶
func (c *ExtendClient) DisablePlugin(ctx context.Context, ptype, name string) error
func (*ExtendClient) EnablePlugin ¶
func (c *ExtendClient) EnablePlugin(ctx context.Context, ptype, name string) error
func (*ExtendClient) GetLokiAlertRules ¶
func (c *ExtendClient) GetLokiAlertRules(ctx context.Context) (map[string]prometheus.RealTimeAlertRule, error)
func (*ExtendClient) GetOrCreateAlertmanagerConfig ¶
func (c *ExtendClient) GetOrCreateAlertmanagerConfig(ctx context.Context, namespace string, name string) (*monitoringv1alpha1.AlertmanagerConfig, error)
func (*ExtendClient) GetOrCreatePrometheusRule ¶
func (c *ExtendClient) GetOrCreatePrometheusRule(ctx context.Context, namespace, name string) (*monitoringv1.PrometheusRule, error)
func (*ExtendClient) GetPromeAlertRules ¶
func (c *ExtendClient) GetPromeAlertRules(ctx context.Context, name string) (map[string]prometheus.RealTimeAlertRule, error)
func (*ExtendClient) GetPrometheusLabelNames ¶
func (c *ExtendClient) GetPrometheusLabelNames(ctx context.Context, match, start, end string) ([]string, error)
func (*ExtendClient) GetPrometheusLabelValues ¶
func (c *ExtendClient) GetPrometheusLabelValues(ctx context.Context, match, label, start, end string) ([]string, error)
func (*ExtendClient) GetRawLoggingAlertResource ¶
func (c *ExtendClient) GetRawLoggingAlertResource(ctx context.Context, namespace string) (*prometheus.RawLoggingAlertRule, error)
func (*ExtendClient) GetRawMonitorAlertResource ¶
func (c *ExtendClient) GetRawMonitorAlertResource(ctx context.Context, namespace, name string, opts *prometheus.MonitorOptions) (*prometheus.RawMonitorAlertResource, error)
GetRawMonitorAlertResource get specified namespace's alert
func (*ExtendClient) Healthy ¶
func (c *ExtendClient) Healthy(ctx context.Context) error
health.system/v1
func (*ExtendClient) ListLoggingAlertRules ¶
func (c *ExtendClient) ListLoggingAlertRules(ctx context.Context, namespace string, hasDetail bool) ([]prometheus.LoggingAlertRule, error)
func (*ExtendClient) ListMonitorAlertRules ¶
func (c *ExtendClient) ListMonitorAlertRules(ctx context.Context, namespace string, opts *prometheus.MonitorOptions, hasDetail bool) ([]prometheus.MonitorAlertRule, error)
func (*ExtendClient) ListPlugins ¶
func (c *ExtendClient) ListPlugins(ctx context.Context) (map[string]interface{}, error)
plugins.kubegems.io/v1alpha1
func (*ExtendClient) ListReceivers ¶
func (c *ExtendClient) ListReceivers(ctx context.Context, namespace, scope, search string) ([]prometheus.ReceiverConfig, error)
func (*ExtendClient) ListSilences ¶
func (c *ExtendClient) ListSilences(ctx context.Context, labels map[string]string, commentPrefix string) ([]alertmanagertypes.Silence, error)
func (*ExtendClient) LokiQuery ¶
func (c *ExtendClient) LokiQuery(ctx context.Context, logql string) (loki.QueryResponseData, error)
func (*ExtendClient) PrometheusQueryRange ¶
func (c *ExtendClient) PrometheusQueryRange(ctx context.Context, query, start, end, step string) (prommodel.Matrix, error)
func (*ExtendClient) PrometheusVector ¶
func (c *ExtendClient) PrometheusVector(ctx context.Context, query string) (prommodel.Vector, error)
func (*ExtendClient) UpdateReceiver ¶
func (c *ExtendClient) UpdateReceiver(ctx context.Context, rec prometheus.ReceiverConfig) error
type PortForwarder ¶
type PortForwarder struct {
// contains filtered or unexported fields
}
func (*PortForwarder) ListenAddr ¶
func (p *PortForwarder) ListenAddr() net.Addr
type Request ¶
type Request struct {
Method string
Path string // queries 可以放在 path 中
Query url.Values
Headers http.Header
Body interface{}
Into interface{}
}
type ServerInfo ¶
type ServerInfo struct {
Addr *url.URL `json:"addr,omitempty"` // addr with api path prefix
CA []byte `json:"ca,omitempty"`
AuthInfo AuthInfo `json:"authInfo,omitempty"`
Version string `json:"version"` // apiserver version
}
type StatusTypedClient ¶
type StatusTypedClient struct {
// contains filtered or unexported fields
}
type TypedClient ¶
type TypedClient struct {
ClientMeta
// contains filtered or unexported fields
}
func (TypedClient) Create ¶
func (c TypedClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
Create saves the object obj in the Kubernetes cluster.
func (TypedClient) Delete ¶
func (c TypedClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
Delete deletes the given obj from Kubernetes cluster.
func (TypedClient) DeleteAllOf ¶
func (c TypedClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error
DeleteAllOf deletes all objects of the given type matching the given options.
func (TypedClient) DialWebsocket ¶
func (c TypedClient) DialWebsocket(ctx context.Context, rpath string, headers http.Header) (*websocket.Conn, *http.Response, error)
func (TypedClient) DoRawRequest ¶
func (c TypedClient) DoRawRequest(ctx context.Context, clientreq Request) (*http.Response, error)
func (TypedClient) DoRequest ¶
func (c TypedClient) DoRequest(ctx context.Context, req Request) error
func (TypedClient) Get ¶
func (c TypedClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object) error
Get retrieves an obj for the given object key from the Kubernetes Cluster. obj must be a struct pointer so that obj can be updated with the response returned by the Server.
func (TypedClient) List ¶
func (c TypedClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
List retrieves list of objects for a given namespace and list options. On a successful call, Items field in the list will be populated with the result returned from the server.
func (TypedClient) Patch ¶
func (c TypedClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error
Patch patches the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.
func (TypedClient) PortForward ¶
func (c TypedClient) PortForward(ctx context.Context, obj client.Object, port int) (*PortForwarder, error)
PortForward
Deprecated: 无法使用,因 service 与 agent 中间还有一层 http proxy(apiserver). 无法直接使用 tcp 。
func (TypedClient) Proxy ¶
func (c TypedClient) Proxy(ctx context.Context, obj client.Object, port int, req *http.Request, writer http.ResponseWriter, rewritefunc func(r *http.Response) error) error
func (TypedClient) RESTMapper ¶
func (c TypedClient) RESTMapper() meta.RESTMapper
func (TypedClient) Update ¶
func (c TypedClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error
Update updates the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.
func (TypedClient) Watch ¶
func (c TypedClient) Watch(ctx context.Context, obj client.ObjectList, opts ...client.ListOption) (watch.Interface, error)
不知道如何正确使用 watch.Interface,参考k8s源码:
https://github.com/kubernetes/kubernetes/blob/release-1.20/pkg/volume/csi/csi_attacher.go#L444-L487
或者:
watcher, err := cli.Watch(ctx, objctList)
if err != nil {
return fmt.Errorf("watch error:%v", err)
}
defer watcher.Stop()
for {
select {
case event, ok := <-watcher.ResultChan():
if !ok {
log.Warningf("watch channel had been closed")
break
}
switch event.Type {
case watch.Added, watch.Modified:
...
case watch.Deleted:
...
case watch.Error:
log.Warningf("received watch error: %v", event)
}
case <-ctx.Done():
log.Warningf("watch channel closed")
break
}
}
type WebsocketRoundTripper ¶
type WebsocketRoundTripper struct {
Dialer *websocket.Dialer
Result chan ConnInitResult
}
func NewWebsocketRoundTripper ¶
func NewWebsocketRoundTripper(dialer *websocket.Dialer) *WebsocketRoundTripper