drovedns

package module
v0.0.0-...-bc45342 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

README

DroveDNS

Name

drovedns - DNS answers for apps runing on drove

Description

The plugins can be used to implement service discovery through dns for apps running on drove. Plugin answers with SRV record for container discovery, optionally forward plugin can be used to add A record of drove-gateway

Compilation

This package will always be compiled as part of CoreDNS and not in a standalone way. It will require you to use go get or as a dependency on plugin.cfg.

The manual will have more information about how to configure and extend the server with external plugins.

A simple way to consume this plugin, is by adding the following on plugin.cfg, and recompile it as detailed on coredns.io.

drove:github.com/PhonePe/coredns-drove

Put this early in the plugin list, so that drovedns is executed before any of the other plugins.

After this you can compile coredns by:

go generate
go build

Or you can instead use make:

make

Syntax

drovedns {
  endpoint [URL]
  accesstoken [TOKEN]
  user_pass [USERNAME] [PASSWORD]
  skip_ssl_check
}
  • URL - Comma seperated list of drove controllers
  • TOKEN - In case drove controllers are using bearer auth Complete Authorization header "Bearer ..."
  • user pass - In case drove is using basic auth
  • skip_ssl_check - To skip client side ssl certificate validation

Ready

This plugin reports readiness to the ready plugin. It will be immediately ready.

Metrics

If monitoring is enabled (via the prometheus plugin) then the following metrics are exported:

  • coredns_drove_controller_health{host} - Exports the health of controller at any given point The following are client level metrics to monitor apiserver request latency & status codes. verb identifies the apiserver request type and host denotes the apiserver endpoint.
  • coredns_drove_sync_total - captures total app syncs from drove.
  • coredns_drove_sync_failure - captures failed app syncs from drove.
  • coredns_drove_api_total{status_code, method, host} - captures drove request grouped by status_code, method & host.

Examples

In this configuration, we resolve queries through the plugin and enrich the answers with A record from servers listed in local resolv.conf

example.drove.gateway.com {
  drovedns {
    endpoint "http://drove-control001.example.com:8080,http://drove-control002.example.com:8080"
    accesstoken "Bearer foo"
  }
  forward . /etc/resolv.conf
}

Docker

Docker image containing coredns compiled with the plugin are available on ghcr.

docker run  -p1053:1053/udp -p1053:1053 \
    -e DROVE_ENDPOINT="https://drovecontrol001.exmaple.com:8080,https://drovecontrol002.exmaple.com:8080,https://drovecontrol003.exmaple.com:8080"  \
    -e DROVE_USERNAME="<USERNAME>" -e DROVE_PASSWORD="<PASSWORD>"  \
    -it ghcr.io/phonepe/coredns-drove:<VERSION>

Alternatively you can provide your own Corefile

docker run  -p1053:1053/udp -p1053:1053 \
    -v /path/to/Corefile:/opt/Corefile  \
    -it ghcr.io/phonepe/coredns-drove:<VERSION>

Also See

See the manual.

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

View Source
const (
	FETCH_APP_TIMEOUT    time.Duration = time.Duration(5) * time.Second
	FETCH_EVENTS_TIMEOUT time.Duration = time.Duration(5) * time.Second
	PING_TIMEOUT         time.Duration = time.Duration(5) * time.Second
)

Variables

View Source
var (
	DroveQueryTotal = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: pluginName,
		Name:      "sync_total",
		Help:      "Counter of Drove sync successful",
	})

	DroveQueryFailure = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: pluginName,
		Name:      "sync_failure",
		Help:      "Counter of Drove syncs failed",
	})

	DroveApiRequests = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: pluginName,
		Name:      "api_total",
		Help:      "Drove api requests total",
	}, []string{"code", "method", "host"})

	DroveControllerHealth = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: plugin.Namespace,
		Subsystem: pluginName,
		Name:      "controller_health",
		Help:      "Drove controller health",
	}, []string{"host"})
)

Functions

This section is empty.

Types

type App

type App struct {
	ID     string
	Vhost  string
	Hosts  []Host
	Tags   map[string]string
	Groups map[string]HostGroup
}

App struct

type CombiningResponseWriter

type CombiningResponseWriter struct {
	dns.ResponseWriter
	// contains filtered or unexported fields
}

Name implements the Handler interface.

func (*CombiningResponseWriter) WriteMsg

func (w *CombiningResponseWriter) WriteMsg(res *dns.Msg) error

type CurrSyncPoint

type CurrSyncPoint struct {
	sync.RWMutex
	LastSyncTime int64
}

type DroveApp

type DroveApp struct {
	ID    string             `json:"appId"`
	Vhost string             `json:"vhost"`
	Tags  map[string]string  `json:"tags"`
	Hosts []DroveServiceHost `json:"hosts"`
}

type DroveAppsResponse

type DroveAppsResponse struct {
	Status  string     `json:"status"`
	Apps    []DroveApp `json:"data"`
	Message string     `json:"message"`
}

DroveAppsResponse struct for our apps nested with tasks.

type DroveAuthConfig

type DroveAuthConfig struct {
	User        string
	Pass        string
	AccessToken string
}

func (DroveAuthConfig) Validate

func (dc DroveAuthConfig) Validate() error

type DroveClient

type DroveClient struct {
	EndpointMutex sync.RWMutex
	Endpoint      []EndpointStatus
	Leader        *LeaderController
	AuthConfig    *DroveAuthConfig
	// contains filtered or unexported fields
}

func NewDroveClient

func NewDroveClient(config DroveConfig) DroveClient

func (*DroveClient) FetchApps

func (c *DroveClient) FetchApps() (*DroveAppsResponse, error)

func (*DroveClient) FetchRecentEvents

func (c *DroveClient) FetchRecentEvents(syncPoint *CurrSyncPoint) (*DroveEventSummary, error)

func (*DroveClient) Init

func (c *DroveClient) Init() error

func (*DroveClient) PollEvents

func (c *DroveClient) PollEvents(callback func(event *DroveEventSummary))

type DroveConfig

type DroveConfig struct {
	Endpoint   string
	AuthConfig DroveAuthConfig
	SkipSSL    bool
}

func NewDroveConfig

func NewDroveConfig() DroveConfig

func (DroveConfig) Validate

func (dc DroveConfig) Validate() error

type DroveEndpoints

type DroveEndpoints struct {
	AppsDB      *DroveAppsResponse
	DroveClient IDroveClient
	AppsByVhost map[string]DroveApp
	// contains filtered or unexported fields
}

type DroveEventSummary

type DroveEventSummary struct {
	EventsCount  map[string]interface{} `json:"eventsCount"`
	LastSyncTime int64                  `json:"lastSyncTime"`
}

type DroveEventsApiResponse

type DroveEventsApiResponse struct {
	Status       string            `json:"status"`
	EventSummary DroveEventSummary `json:"data"`
	Message      string            `json:"message"`
}

type DroveHandler

type DroveHandler struct {
	DroveEndpoints *DroveEndpoints
	Next           plugin.Handler
}

Example is an example plugin to show how to write a plugin.

func NewDroveHandler

func NewDroveHandler(droveClient IDroveClient) *DroveHandler

func (*DroveHandler) Name

func (e *DroveHandler) Name() string

func (*DroveHandler) Ready

func (e *DroveHandler) Ready() bool

Checks if apps data could be synced from drove cluster

func (*DroveHandler) ServeDNS

func (e *DroveHandler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

type DroveServiceHost

type DroveServiceHost struct {
	Host     string `json:"host"`
	Port     int32  `json:"port"`
	PortType string `json:"portType"`
}

type EndpointStatus

type EndpointStatus struct {
	Endpoint string
	Healthy  bool
	Message  string
}

type Host

type Host struct {
	Host     string
	Port     int32
	PortType string
}

Host struct

type HostGroup

type HostGroup struct {
	Hosts []Host
	Tags  map[string]string
}

type IDroveClient

type IDroveClient interface {
	FetchApps() (*DroveAppsResponse, error)
	FetchRecentEvents(syncPoint *CurrSyncPoint) (*DroveEventSummary, error)
	PollEvents(callback func(event *DroveEventSummary))
}

type LeaderController

type LeaderController struct {
	Endpoint string
	Host     string
	Port     int32
}

Jump to

Keyboard shortcuts

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