node

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 46 Imported by: 10

Documentation

Overview

Package serviced - agent implements a service that runs on a serviced node. It is responsible for ensuring that a particular node is running the correct services and reporting the state and health of those services back to the master serviced.

This file implements the LoadBalancer interface aspect of the host agent.

Serviced is a PaaS runtime based on docker. The serviced package exposes the interfaces for the key parts of this runtime.

Copyright 2016 The Serviced Authors. 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.

Index

Constants

View Source
const (
	SERVICED_UI_ENDPOINT       = 5443
	SERVICED_UI_ENDPOINT_PROXY = 443
)

Variables

This section is empty.

Functions

func AddToEtcHosts

func AddToEtcHosts(host, ip string) error

In the container

func CreateDirectory

func CreateDirectory(path, username string, perm os.FileMode) error

CreateDirectory creates a directory using the given username as the owner and the given perm as the directory permission.

func CreateVolumeDir

func CreateVolumeDir(conn client.Connection, hostPath, containerSpec, imageSpec, userSpec, permissionSpec string) error

CreateVolumeDir() creates a directory on the running host using the user ids found within the specified image. For example, it can create a directory owned by the mysql user (as seen by the container) despite there being no mysql user on the host system. Assumes that the local docker image (imageSpec) exists and has been sync'd with the registry.

func ExecPath

func ExecPath() (string, string, error)

ExecPath returns the path to the currently running executable.

func GetDockerVersion

func GetDockerVersion() ([]int, error)

GetDockerVersion returns docker version number.

func GetInterfaceIPAddress

func GetInterfaceIPAddress(_interface string) (string, error)

GetInterfaceIPAddress attempts to find the IP address based on interface name

func IsValidOwnerSpec

func IsValidOwnerSpec(owner string) bool

IsValidOwnerSpec returns true if the owner is specified in owner:group format and the identifiers are valid POSIX.1-2008 username and group strings, respectively.

func NewReverseProxy

func NewReverseProxy(path string, targeturl *url.URL) *httputil.ReverseProxy

NewReverseProxy differs from httputil.NewSingleHostReverseProxy in that it rewrites the path so that it does /not/ include the incoming path. e.g. request for "/mysvc/thing" when proxy is served from "/mysvc" means target is targeturl.Path + "/thing"; vs. httputil.NewSingleHostReverseProxy, in which it would be targeturl.Path + "/mysvc/thing".

Types

type AgentClient

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

AgentClient is an interface that the serviced agent implements to provide information about the host it is running on.

func NewAgentClient

func NewAgentClient(addr string) (s *AgentClient, err error)

Create a new AgentClient.

type AgentOptions

type AgentOptions struct {
	IPAddress             string
	PoolID                string
	Master                string
	UIPort                string
	RPCPort               string
	RPCDisableTLS         bool // true if TLS should be disabled for RPC
	DockerDNS             []string
	VolumesPath           string
	Mount                 []string
	FSType                volume.DriverType
	Zookeepers            []string
	Mux                   *proxy.TCPMux
	MuxPort               string
	UseTLS                bool
	DockerRegistry        string
	MaxContainerAge       time.Duration // Maximum container age for a stopped container before being removed
	VirtualAddressSubnet  string
	ControllerBinary      string
	LogstashURL           string
	DockerLogDriver       string
	DockerLogConfig       map[string]string
	ZKSessionTimeout      int
	ZKConnectTimeout      int
	ZKPerHostConnectDelay int
	ZKReconnectStartDelay int
	ZKReconnectMaxDelay   int
	DelegateKeyFile       string
	TokenFile             string
	ConntrackFlush        bool
}

type ApplicationType

type ApplicationType string

A user defined string that describes an exposed application endpoint.

type ContainerState

type ContainerState struct {
	ID      string
	Created time.Time
	Path    string
	Args    []string
	Config  struct {
		Hostname        string
		User            string
		Memory          uint64
		MemorySwap      uint64
		CpuShares       int
		AttachStdin     bool
		AttachStdout    bool
		AttachStderr    bool
		PortSpecs       []string
		Tty             bool
		OpenStdin       bool
		StdinOnce       bool
		Env             []string
		Cmd             []string
		Dns             []string
		Image           string
		Volumes         map[string]struct{}
		VolumesFrom     string
		WorkingDir      string
		Entrypoint      []string
		NetworkDisabled bool
		Privileged      bool
		OomKillDisable  bool
		OomScoreAdj     int
	}
	State struct {
		Running   bool
		Pid       int
		ExitCode  int
		StartedAt string
		Ghost     bool
	}
	Image           string
	NetworkSettings struct {
		IPAddress   string
		IPPrefixLen int
		Gateway     string
		Bridge      string
		PortMapping map[string]map[string]string
		Ports       map[string][]domain.HostIPAndPort
	}
	SysInitPath    string
	ResolvConfPath string
	Volumes        map[string]string
	VolumesRW      map[string]bool
}

The state of a container as reported by Docker.

type EvaluateServiceRequest

type EvaluateServiceRequest struct {
	ServiceID  string
	InstanceID int
}

type EvaluateServiceResponse

type EvaluateServiceResponse struct {
	Service         service.Service
	TenantID        string
	ServiceNamePath string
}

type HealthCheckRequest

type HealthCheckRequest struct {
	ServiceID  string
	InstanceID int
}

type HostAgent

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

HostAgent is an instance of the control center Agent.

func NewHostAgent

func NewHostAgent(options AgentOptions, reg registry.Registry) (*HostAgent, error)

NewHostAgent creates a new HostAgent given a connection string

func (*HostAgent) AckProxySnapshotQuiece

func (a *HostAgent) AckProxySnapshotQuiece(snapshotId string, unused *interface{}) error

AckProxySnapshotQuiece is called by clients when the snapshot command has shown the service is quieced; the agent returns a response when the snapshot is complete

func (*HostAgent) AttachAndRun

func (a *HostAgent) AttachAndRun(dockerID string, command []string) ([]byte, error)

AttachAndRun implements zkdocker.ActionHandler; it attaches to a running container and performs a command as specified by the container's service definition

func (*HostAgent) AttachContainer

func (a *HostAgent) AttachContainer(state *zkservice.ServiceState, serviceID string, instanceID int) (<-chan time.Time, error)

AttachContainer returns a channel that monitors the run state of a given container.

func (*HostAgent) BindIP

func (a *HostAgent) BindIP(ipprefix, netmask, iface string) error

BindIP creates a virtual ip if it doesn't already exist.

func (*HostAgent) GetEvaluatedService

func (a *HostAgent) GetEvaluatedService(request EvaluateServiceRequest, response *EvaluateServiceResponse) (err error)

func (*HostAgent) GetHostID

func (a *HostAgent) GetHostID(_ string, hostID *string) error

GetHostID returns the agent's host id

func (*HostAgent) GetISvcEndpoints

func (a *HostAgent) GetISvcEndpoints(serviceId string, response *map[string][]applicationendpoint.ApplicationEndpoint) (err error)

func (*HostAgent) GetProxySnapshotQuiece

func (a *HostAgent) GetProxySnapshotQuiece(serviceId string, snapshotId *string) error

GetProxySnapshotQuiece blocks until there is a snapshot request to the service

func (*HostAgent) GetServiceBindMounts

func (a *HostAgent) GetServiceBindMounts(serviceID string, bindmounts *map[string]string) error

GetServiceBindMounts returns the service bindmounts

func (*HostAgent) GetZkInfo

func (a *HostAgent) GetZkInfo(_ string, zkInfo *ZkInfo) error

GetZkInfo returns the agent's zookeeper connection string and its poolID

func (*HostAgent) PauseContainer

func (a *HostAgent) PauseContainer(serviceID string, instanceID int) error

PauseContainer pauses a running container

func (*HostAgent) Ping

func (a *HostAgent) Ping(waitFor time.Duration, timestamp *time.Time) error

func (*HostAgent) ReleaseIP

func (a *HostAgent) ReleaseIP(ipprefix string) error

ReleaseIP releases a virtual ip if hasn't yet been released.

func (*HostAgent) ReportHealthStatus

func (a *HostAgent) ReportHealthStatus(req master.HealthStatusRequest, unused *int) error

ReportHealthStatus proxies ReportHealthStatus to the master server.

func (*HostAgent) ReportInstanceDead

func (a *HostAgent) ReportInstanceDead(req master.ServiceInstanceRequest, unused *int) error

ReportInstanceDead proxies ReportInstanceDead to the master server.

func (*HostAgent) RestartContainer

func (a *HostAgent) RestartContainer(cancel <-chan interface{}, serviceID string, instanceID int) error

RestartContainer asynchronously pulls the latest image of a running container before stopping the service. After the service has stopped, the listener will be notified by the event monitor.

func (*HostAgent) ResumeContainer

func (a *HostAgent) ResumeContainer(serviceID string, instanceID int) error

ResumeContainer resumes a paused container

func (*HostAgent) SendLogMessage

func (a *HostAgent) SendLogMessage(serviceLogInfo ServiceLogInfo, _ *struct{}) (err error)

func (*HostAgent) SetVIP

func (a *HostAgent) SetVIP(v VIP)

SetVIP allows you to update the default vip (primarily for testing)

func (*HostAgent) Start

func (a *HostAgent) Start(shutdown <-chan interface{})

main loop of the HostAgent

func (*HostAgent) StartContainer

func (a *HostAgent) StartContainer(cancel <-chan interface{}, serviceID string, instanceID int) (*zkservice.ServiceState, <-chan time.Time, error)

StartContainer creates a new container and starts. It returns info about the container, and an event monitor to track the running state of the service.

func (*HostAgent) StopContainer

func (a *HostAgent) StopContainer(serviceID string, instanceID int) error

StopContainer stops running container or returns nil if the container does not exist or has already stopped.

type IP

type IP struct {
	Addr   string
	Device string
	Label  string
}

IP describes an ip binding

func (*IP) Matches

func (ip *IP) Matches(ipaddr, device string) bool

Matches returns true if the address and device match

type LBClient

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

A LBClient implementation.

func NewLBClient

func NewLBClient(addr string) (*LBClient, error)

Create a new AgentClient.

func (*LBClient) AckProxySnapshotQuiece

func (a *LBClient) AckProxySnapshotQuiece(snapshotId string, unused *interface{}) error

AckProxySnapshotQuiece is called by clients when the snapshot command has shown the service is quieced; the agent returns a response when the snapshot is complete

func (*LBClient) Close

func (a *LBClient) Close() error

func (*LBClient) GetEvaluatedService

func (a *LBClient) GetEvaluatedService(request EvaluateServiceRequest, response *EvaluateServiceResponse) error

GetEvaluatedService returns a service where an evaluation has been executed against all templated properties.

func (*LBClient) GetHostID

func (a *LBClient) GetHostID(hostID *string) error

GetHostID returns the agent's host id

func (*LBClient) GetISvcEndpoints

func (a *LBClient) GetISvcEndpoints(serviceId string, endpoints *map[string][]applicationendpoint.ApplicationEndpoint) error

GetISvcEndpoints returns a list of controlplane endpoints for the given service endpoint request.

func (*LBClient) GetProxySnapshotQuiece

func (a *LBClient) GetProxySnapshotQuiece(serviceId string, snapshotId *string) error

GetProxySnapshotQuiece blocks until there is a snapshot request to the service

func (*LBClient) GetServiceBindMounts

func (a *LBClient) GetServiceBindMounts(serviceID string, bindmounts *map[string]string) error

GetServiceBindMounts returns the service

func (*LBClient) GetZkInfo

func (a *LBClient) GetZkInfo(zkInfo *ZkInfo) error

GetZkInfo returns the agent's zookeeper connection string

func (*LBClient) Ping

func (a *LBClient) Ping(waitFor time.Duration, timestamp *time.Time) error

Ping waits for the specified time then returns the server time

func (*LBClient) ReportHealthStatus

func (a *LBClient) ReportHealthStatus(req master.HealthStatusRequest, unused *int) error

ReportHealthStatus stores a health check result.

func (*LBClient) ReportInstanceDead

func (a *LBClient) ReportInstanceDead(req master.ServiceInstanceRequest, unused *int) error

ReportInstanceDead removes health check results for an instance.

func (*LBClient) SendLogMessage

func (a *LBClient) SendLogMessage(serviceLogInfo ServiceLogInfo, _ *struct{}) error

SendLogMessage simply outputs the ServiceLogInfo on the serviced master

type LoadBalancer

type LoadBalancer interface {
	// SendLogMessage allows the proxy to send messages/logs to the master (to be displayed on the serviced master)
	SendLogMessage(serviceLogInfo ServiceLogInfo, _ *struct{}) error

	GetISvcEndpoints(serviceId string, endpoints *map[string][]applicationendpoint.ApplicationEndpoint) error

	// GetProxySnapshotQuiece blocks until there is a snapshot request
	GetProxySnapshotQuiece(serviceId string, snapshotId *string) error

	// AckProxySnapshotQuiece is called by clients when the snapshot command has
	// shown the service is quieced; the agent returns a response when the snapshot is complete
	AckProxySnapshotQuiece(snapshotId string, unused *interface{}) error

	// ReportHealthStatus writes the health check status to the cache
	ReportHealthStatus(req master.HealthStatusRequest, unused *int) error

	// ReportInstanceDead removes all health checks for the provided instance from the
	// cache.
	ReportInstanceDead(req master.ServiceInstanceRequest, unused *int) error

	// GetEvaluatedService returns a service where an evaluation has been executed against all templated properties.
	GetEvaluatedService(request EvaluateServiceRequest, response *EvaluateServiceResponse) error

	// Ping waits for the specified time then returns the server time
	Ping(waitFor time.Duration, timestamp *time.Time) error
}

The API for a service proxy.

type ProtocolType

type ProtocolType string

Network protocol type.

type ServiceCache

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

func NewServiceCache

func NewServiceCache(master string) *ServiceCache

func (*ServiceCache) GetEvaluatedService

func (sc *ServiceCache) GetEvaluatedService(serviceID string, instanceID int) (*service.Service, string, string, error)

func (*ServiceCache) Invalidate

func (sc *ServiceCache) Invalidate(serviceID string, instanceID int)

type ServiceInstanceRequest

type ServiceInstanceRequest struct {
	ServiceID  string
	InstanceID int
}

type ServiceLogInfo

type ServiceLogInfo struct {
	ServiceID string
	Message   string
}

type VIP

type VIP interface {
	GetAll() []IP
	Find(ipprefix string) *IP
	Release(ipaddr, device string) error
	Bind(ipaddr, device string) error
}

VIP is the interface for managing virtual ips

type VirtualIPManager

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

VirtualIPManager manages virtual ip bindings

func NewVirtualIPManager

func NewVirtualIPManager(label string) *VirtualIPManager

NewVirtualIPManager instantiates an instance of the VirtualIPManager

func (*VirtualIPManager) Bind

func (v *VirtualIPManager) Bind(ipaddr, device string) error

Bind binds a virtual ip to a device

func (*VirtualIPManager) Find

func (v *VirtualIPManager) Find(ipprefix string) *IP

Find returns the matching binding for the given ip address

func (*VirtualIPManager) GetAll

func (v *VirtualIPManager) GetAll() (ips []IP)

GetAll returns all the bound virtual ips

func (*VirtualIPManager) Release

func (v *VirtualIPManager) Release(ipaddr, device string) error

Release releases the virtual ip binding

type ZkInfo

type ZkInfo struct {
	ZkDSN  string
	PoolID string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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