Documentation
¶
Overview ¶
Package example is a CoreDNS plugin that prints "example" to stdout on every packet received.
It serves as an example CoreDNS plugin with numerous code comments.
Index ¶
- Constants
- func CustomLevelEncoder(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func GetDefaultLogger() (*zap.SugaredLogger, error)
- func GetLogger(name string) (*zap.SugaredLogger, error)
- func InitLogger(logPath string, logLevel zapcore.Level, enableStdOut bool)
- func InitStdOutLogger(logLevel zapcore.Level)
- func SendRequest(method string, uri string, paramMap map[string]string, body []byte, ...) (int, []byte, error)
- func SendRequestWithFullReturn(method string, uri string, paramMap map[string]string, body []byte, ...) (int, http.Header, []byte, error)
- func SendRequestWithTimeout(method string, uri string, paramMap map[string]string, body []byte, ...) (int, []byte, error)
- func SendRequestWithTlsBypass(method string, uri string, paramMap map[string]string, body []byte, ...) (int, []byte, error)
- func SyslogTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- type CertificateConfig
- type Client
- type Configuration
- type DefaultHttpRequestSender
- func (se *DefaultHttpRequestSender) SendRequest(method string, uri string, paramMap map[string]string, body []byte, ...) (int, []byte, error)
- func (se *DefaultHttpRequestSender) SendRequestWithFullReturn(method string, uri string, paramMap map[string]string, body []byte, ...) (int, http.Header, []byte, error)
- func (se *DefaultHttpRequestSender) SendRequestWithTimeout(method string, uri string, paramMap map[string]string, body []byte, ...) (int, []byte, error)
- func (se *DefaultHttpRequestSender) SendRequestWithTlsBypass(method string, uri string, paramMap map[string]string, body []byte, ...) (int, []byte, error)
- type DefaultTlsBypassHttpsClient
- type DownstreamTokenConfig
- type DrainConfig
- type Example
- func (e *Example) BackgroundLoop()
- func (e *Example) GetEnvConfig(envVar string, default_val int) (int, error)
- func (e *Example) GetRecords() []*PodRecord
- func (e *Example) GetUserPodRecords(pods []v1.Pod) []*PodRecord
- func (e *Example) Name() string
- func (e *Example) QueryForPodRecord(name string, state request.Request, ctx context.Context, w dns.ResponseWriter, ...) (int, error)
- func (e Example) Ready() bool
- func (e *Example) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)
- func (e *Example) ServeDNS_Example(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)
- func (e *Example) ServeDNS_WhoAmI(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)
- func (e *Example) UpdateRecords(records []*PodRecord)
- type FlightConfig
- type HealthStatusGetter
- type HttpRequestSender
- type KubeletConfig
- type LogConfig
- type ManyModelConfig
- type MyError
- type PodInfoGetter
- type PodRecord
- type PodRetryLimitConfig
- type PodSpecConfig
- type PodSpecImageFetcherConfig
- type PodSpecManyModelConfig
- type PodSpecModelMountConfig
- type QuotaSettingConfig
- type ResponsePrinter
- type RunningPodsGetter
- type ScheduledEventsConfig
- type SendHttpRequestFunc
- type SendHttpRequestWithTimeoutFunc
- type ServerConfig
- type TlsBypassHttpsClient
- type UpstreamTokenConfig
- type XdsConfig
Constants ¶
const DefaultTimeoutInSec = 2
const (
// INSTANCE_ID key for hostname in os env
INSTANCE_ID = "INSTANCE_ID"
)
Variables ¶
This section is empty.
Functions ¶
func CustomLevelEncoder ¶
func CustomLevelEncoder(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
func GetDefaultLogger ¶
func GetDefaultLogger() (*zap.SugaredLogger, error)
GetDefaultLogger get a default logger
func GetLogger ¶
func GetLogger(name string) (*zap.SugaredLogger, error)
GetLogger get a named logger, if name is empty, use the default logger
func InitLogger ¶
InitLogger initializes a thread-safe singleton logger This would be called from a main method when the application starts up
func InitStdOutLogger ¶
InitStdOutLogger initialize a stdout logger, just for UT
func SendRequest ¶
func SendRequest(method string, uri string, paramMap map[string]string, body []byte, headerMap map[string]string) (int, []byte, error)
SendRequest send given http request with a 2s timeout
func SendRequestWithFullReturn ¶
func SendRequestWithFullReturn(method string, uri string, paramMap map[string]string, body []byte, headerMap map[string]string, timeoutInSec int64, isTlsBypass bool) (int, http.Header, []byte, error)
SendRequestWithFullReturn encapsulate error handling of http request. Return HTTP status code, response header, pointer of response body byte slice and error. A non-2xx status code doesn't cause an error.
func SendRequestWithTimeout ¶
func SendRequestWithTimeout(method string, uri string, paramMap map[string]string, body []byte, headerMap map[string]string, timeoutInSec int64) (int, []byte, error)
SendRequest encapsulate error handling of http request. Return HTTP status code, response header, pointer of response body byte slice and error. A non-2xx status code doesn't cause an error.
func SendRequestWithTlsBypass ¶
func SendRequestWithTlsBypass(method string, uri string, paramMap map[string]string, body []byte, headerMap map[string]string) (int, []byte, error)
SendRequest send given http request with TLS bypass
func SyslogTimeEncoder ¶
func SyslogTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
Types ¶
type CertificateConfig ¶
CertificateConfig certificates related config
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client kubelet client interface
func NewClient ¶
func NewClient(kubeletConfig *KubeletConfig, tlsBypassHttpsClient TlsBypassHttpsClient) *Client
NewClient create a kubelet client
func (*Client) GetHealthStatus ¶
GetHealthStatus get kubelet healthz status from kubelet "/healthz" api return true if kubelet is in good health
func (*Client) GetPodsInfo ¶
GetPodsInfo get kubelet pods info from kubelet "/pods" api
type Configuration ¶
type Configuration struct {
Server ServerConfig
PodSpecSetting PodSpecConfig
Log LogConfig
Kubelet KubeletConfig
ScheduledEvents ScheduledEventsConfig
ManyModel ManyModelConfig
Xds XdsConfig
UpstreamToken UpstreamTokenConfig
DownstreamToken DownstreamTokenConfig
Drain DrainConfig
Certificate CertificateConfig
Flight FlightConfig
DefaultEnvVars map[string]string
}
Configuration vmagent configuration definition
func GetDefaultConfig ¶
func GetDefaultConfig() *Configuration
func InitConfig ¶
func InitConfig(configPath string) (*Configuration, error)
type DefaultHttpRequestSender ¶
type DefaultHttpRequestSender struct {
Logger *zap.SugaredLogger
}
func NewDefaultHttpRequestSender ¶
func NewDefaultHttpRequestSender() *DefaultHttpRequestSender
func (*DefaultHttpRequestSender) SendRequest ¶
func (*DefaultHttpRequestSender) SendRequestWithFullReturn ¶
func (*DefaultHttpRequestSender) SendRequestWithTimeout ¶
type DefaultTlsBypassHttpsClient ¶
type DefaultTlsBypassHttpsClient struct {
Logger *zap.SugaredLogger
Client *http.Client
}
func NewDefaultTlsBypassHttpsClient ¶
func NewDefaultTlsBypassHttpsClient() *DefaultTlsBypassHttpsClient
type DownstreamTokenConfig ¶
type DownstreamTokenConfig struct {
// DownstreamMsiTokenEndpoint is endpoint of MSI of VMAgent.
DownstreamMsiTokenEndpoint string
// DownstreamAcrTokenEndpoint is endpoint of ACR of VMAgent.
DownstreamAcrTokenEndpoint string
// DownstreamBlobKeyEndpoint is endpoint of BLOB of VMAgent.
DownstreamBlobKeyEndpoint string
DownstreamSecretArtifactEndpoint string
}
type DrainConfig ¶
type Example ¶
type Example struct {
Next plugin.Handler
KubeClient *Client
Logger *zap.SugaredLogger
Records []*PodRecord
// contains filtered or unexported fields
}
Example is an example plugin to show how to write a plugin.
func (*Example) BackgroundLoop ¶
func (e *Example) BackgroundLoop()
func (*Example) GetEnvConfig ¶
func (*Example) GetRecords ¶
func (*Example) QueryForPodRecord ¶
func (Example) Ready ¶
Ready implements the ready.Readiness interface, once this flips to true CoreDNS assumes this plugin is ready for queries; it is not checked again.
func (*Example) ServeDNS_Example ¶
func (e *Example) ServeDNS_Example(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)
ServeDNS implements the plugin.Handler interface. This method gets called when example is used in a Server.
func (*Example) ServeDNS_WhoAmI ¶
func (*Example) UpdateRecords ¶
type FlightConfig ¶
type FlightConfig struct {
// EnableParallelInitContainers whether to enable parallel mode for customer init container(image fetch and model mount)
EnableParallelInitContainers bool
}
FlightConfig flight related config
type HealthStatusGetter ¶
HealthStatusGetter is a interface that help to get kubelet healthz status
type HttpRequestSender ¶
type HttpRequestSender interface {
// SendRequestWithFullReturn encapsulate error handling of http request.
// Return HTTP status code, response header, pointer of response body byte slice and error.
// A non-2xx status code doesn't cause an error.
SendRequestWithFullReturn(method string, uri string, paramMap map[string]string, body []byte, headerMap map[string]string, timeoutInSec int64, isTlsBypass bool) (int, http.Header, []byte, error)
// SendRequest encapsulate error handling of http request.
// Return HTTP status code, response header, pointer of response body byte slice and error.
// A non-2xx status code doesn't cause an error.
SendRequestWithTimeout(method string, uri string, paramMap map[string]string, body []byte, headerMap map[string]string, timeoutInSec int64) (int, []byte, error)
// SendRequest send given http request with a DefaultTimeoutInSec timeout
SendRequest(method string, uri string, paramMap map[string]string, body []byte, headerMap map[string]string) (int, []byte, error)
// SendRequest send given http request with TLS bypass and with a DefaultTimeoutInSec timeout
SendRequestWithTlsBypass(method string, uri string, paramMap map[string]string, body []byte, headerMap map[string]string) (int, []byte, error)
}
type KubeletConfig ¶
type KubeletConfig struct {
// ServiceAddr kubelet endpoint
ServiceAddr string
// PodsAPI api path for getting pod info
PodsAPI string
// HealthzAPI api path for getting kubelet health info
HealthzAPI string
// RunningPodsAPI api path for getting running pods
RunningPodsAPI string
// StatsSummaryAPI api path for getting states summary
StatsSummaryAPI string
// ManifestsFolderPath path for kubelet pod manifests folder
ManifestsFolderPath string
}
KubeletConfig vmagent kubelet config
type LogConfig ¶
type LogConfig struct {
// The server log file path
LogPath string
// The server log level(debug", "info", "warn",
// "error", "dpanic", "panic", and "fatal")
LogLevel string
// Enable writing to standard output
EnableStdOut bool
}
LogConfig vmagent log config
type ManyModelConfig ¶
type ManyModelConfig struct {
// ManyModelUpdateTimerInterval update timer interval
ManyModelUpdateTimerInterval int
}
manyModelConfig many model config section
type PodInfoGetter ¶
PodInfoGetter is a interface that help to get kubelet pods info
type PodRetryLimitConfig ¶
type PodSpecConfig ¶
type PodSpecConfig struct {
// CustomerPodKey customer pod key in pod annotations map
CustomerPodKey string
// CustomerPodValue customer pod value in pod annotations map to indicate a customer pod
CustomerPodValue string
// LabelMsiTokenKey is the key of MSI token of label.
LabelMsiTokenKey string
// LabelMsiTokenValue is the value of MSI token of label.
LabelMsiTokenValue string
// LabelMdsdCertKey Label key for msds cert
LabelMdsdCertKey string
// LabelMdsdCertValue label value for mdsd cert
LabelMdsdCertValue string
// LabelInitContainerAsPodKey Label key for init container pod
LabelInitContainerAsPodKey string
// LabelInitContainerAsPodValue Label value for init container pod
LabelInitContainerAsPodValue string
// LabelSkipQuotaValidation Label key for skip quota validation pod
LabelSkipQuotaValidationKey string
// LabelSkipQuotaValidation Label value for skip quota validation pod
LabelSkipQuotaValidationValue string
// The folder where built in agent podspecs locate.
BuiltInPodSpecFolder string
// Namespace for Infra pods
InfraNamespace string
// Namespace for Customer pods
CustomerNamespace string
// Name for VMAgent pod
VMAgentPodName string
// ModelMount model mount podspec config
ModelMount PodSpecModelMountConfig
// ImageFetcher image fetcher podspec config
ImageFetcher PodSpecImageFetcherConfig
// ManyModel many model podspec config
ManyModel PodSpecManyModelConfig
// QuotaSettings a map of container quota setting
QuotaSettings map[string]QuotaSettingConfig
// Pod retry limit config
PodRetryLimit PodRetryLimitConfig
// CuratedImageAcr list
CuratedAcrList []string
}
PodSpecConfig vmagent podspec config
type PodSpecImageFetcherConfig ¶
type PodSpecImageFetcherConfig struct {
// VolumeName name of image fatcher volume name
VolumeName string
// VolumeMountpath mount path of image fetcher
VolumeMountpath string
// InitContainerName name of image fetcher init container
InitContainerName string
// InitContainerImage image of image fetcher init container
InitContainerImage string
// pod name for standalone image fetcher pod
PodName string
// host containerd grpc address
ContainerdAddress string
}
PodSpecImageFetcherConfig image fetcher pod spec config
type PodSpecManyModelConfig ¶
type PodSpecManyModelConfig struct {
// ManyModelSideCarImageUrl side car image url
SideCarImageUrl string
SideCarPort int32
}
PodSpecManyModelConfig many model side car container config
type PodSpecModelMountConfig ¶
type PodSpecModelMountConfig struct {
// InitContainerName name of model mount init container
InitContainerName string
// InitContainerImage image of model mount init container
InitContainerImage string
// PodName name for standalone storage initializer pod
PodName string
// HostModelDir dir on the vm to store the downloaded model files
HostModelDir string
}
PodSpecModelMountConfig model mount pod spec config
type QuotaSettingConfig ¶
type QuotaSettingConfig struct {
// CpuResourceInPercent container cpu resource limit in percentage
CpuResourceInPercent float64
// MemoryResourceInGb container memory resource limit
MemoryResourceInGb float64
// NeedResourceLimit if container need resource limit
NeedResourceLimit bool
}
QuotaSettingConfig podspec quota setting config
type ResponsePrinter ¶
type ResponsePrinter struct {
dns.ResponseWriter
}
ResponsePrinter wrap a dns.ResponseWriter and will write example to standard output when WriteMsg is called.
func NewResponsePrinter ¶
func NewResponsePrinter(w dns.ResponseWriter) *ResponsePrinter
NewResponsePrinter returns ResponseWriter.
type RunningPodsGetter ¶
RunningPodsGetter interface for getting all running pods
type ScheduledEventsConfig ¶
type ScheduledEventsConfig struct {
// MetadataUrl Url of scheduled events Metadata Service
MetadataUrl string
// SchduleEventsUpdateTimerInterval update timer interval
SchduleEventsUpdateTimerInterval int
// FreezeAckMinWaitTimeInSec is the minimum wait second for acknowledging Freeze event in Pause State
FreezeAckMinWaitTimeInSec int
}
ScheduledEventsConfig vmagent scheduled events config section
type SendHttpRequestFunc ¶
type ServerConfig ¶
type ServerConfig struct {
// The port the server listens to
Port int `json:",string"`
DeploymentTimerInterval int
DeploymentHealthMaxRetries int
DeploymentTimeout int
DeploymentHealthSystemPath string
DeploymentHealthUserPath string
DeploymentDataPath string
DeploymentDefaultPodsHealthyThreshold int
DeploymentCustomerPodsWithoutLivenessProbeHealthyThreshold int
DeploymentHealthCheckIntervalInMilliSec int
RecoveringStateCustomerContainerRestartLimit int
VMStatePersistPath string
VMUnusableFilePath string
VMRebootSignalFilePath string
}
ServerConfig vmagent server config section
type TlsBypassHttpsClient ¶
type UpstreamTokenConfig ¶
type UpstreamTokenConfig struct {
// UpstreamMsiTokenEndpoint is endpoint of MSI of token server.
UpstreamMsiTokenEndpoint string
// UpstreamAcrTokenEndpoint is endpoint of ACR of token server.
UpstreamAcrTokenEndpoint string
// UpstreamAcrTokenEndpoint is endpoint of Blob key of token server
UpstreamBlobKeyEndpoint string
// upstreamCertEndpoint is endpoint of cert server
UpstreamSecretArtifactEndpoint string
}
type XdsConfig ¶
type XdsConfig struct {
// Port is xds server listening port
Port int `json:",string"`
// EnvoyMeshPort is the port of mesh listener
EnvoyMeshPort int `json:",string"`
// EnvoyNodeID is the envoy node_id of mesh first layer
EnvoyNodeID string
// EnvoyLayer2NodeID is the envoy node_id of mesh second layer
EnvoyLayer2NodeID string
// DefaultEnvoySDSTlsSecretName is the SDS config name defined in Envoy configuration file
DefaultEnvoySDSTlsSecretName string
// DefaultEnvoySDSHttpValidationSecretName is the SDS config name defined in Envoy configuration file
DefaultEnvoySDSHttpValidationSecretName string
// DefaultEnvoySDSDiagValidationSecretName is the SDS config name defined in Envoy configuration file
DefaultEnvoySDSDiagValidationSecretName string
// EnvoyHealthCheckPath is the health check path defined in Envoy configuration file
EnvoyHealthCheckPath string
// EnvoyHealthCheckClusterName is the CDS config name defined in Envoy configuration file
EnvoyHealthCheckClusterName string
// EnvoyHealthCheckEndpointName is the EDS config name defined in Envoy configuration file
EnvoyHealthCheckEndpointName string
// EnvoyHealthCheckPort is the port of health check listener
EnvoyHealthCheckPort int
// EnvoyFDMeshClusterName
EnvoyFDMeshClusterName string
// EnvoyFDMeshEndpointName is the EDS config name defined in Envoy configuration file
EnvoyFDMeshEndpointName string
// EnvoyMeshRouteConfigName is the RDS config name defined in Envoy configuration file
EnvoyMeshRouteConfigName string
// HealthCheckTimeoutMilliseconds defines health check route timeout in milliseconds
HealthCheckTimeoutMilliseconds int
// RouteTimeoutMilliseconds defines the route request timeout in milliseconds
RouteTimeoutMilliseconds int
// UpstreamClusterConnectTimeoutMilliseconds defines the connection timeout to an upstream cluster
UpstreamClusterConnectTimeoutMilliseconds int
// EnvoyMeshEndpointUpdateTimerInterval time interval config for update envoy mesh endpoints
EnvoyMeshEndpointUpdateTimerInterval int
// CACertificateFileName is the CA certificates file used by envoy mTLS validation
CACertificateFileName string
// CertificateChainSortingEnabled indicates whether to sort certificate chain on exporting public key from PEM or PFX
CertificateChainSortingEnabled bool
// RequestHeadersToRemove contains a list of header names that need to remove before sending to custom container
RequestHeadersToRemove []string
// RequestHeadersToPassBy contains a list of header names that need to pass by sending to custom container, add back to response.
RequestHeadersToPassBy []string
// EnvoyManyModelRouteConfigName used for triton manymodel flight.
EnvoyManyModelRouteConfigName string
// EnvoyManyModelDirectRouteHeaderName used for triton manymodel flight.
EnvoyManyModelDirectRouteHeaderName string
// EnvoyManyModelDirectRouteHeaderName used for triton manymodel flight.
EnvoyManyModelDirectRouteHeaderValue string
// EnvoyManyModelRequestPathPattern used for triton manymodel flight.
EnvoyManyModelRequestPathPattern string
// ModelConcurrencyThresholdToDisableLogs
ModelConcurrencyThresholdToDisableLogs int
}
XdsConfig vmagent envoy xds server config section