agent

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package agent contains the functions for sending nginx configuration to the agent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deployment

type Deployment struct {
	FileLock sync.RWMutex
	// contains filtered or unexported fields
}

Deployment represents an nginx Deployment. It contains its own nginx configuration files, a broadcaster for sending those files to all of its pods that are subscribed, and errors that may have occurred while applying configuration.

func (*Deployment) GetBroadcaster

func (d *Deployment) GetBroadcaster() broadcast.Broadcaster

GetBroadcaster returns the deployment's broadcaster.

func (*Deployment) GetConfigurationStatus

func (d *Deployment) GetConfigurationStatus() error

GetConfigurationStatus returns the current config status for this Deployment. It combines the most recent errors (if they exist) for all Pods in the Deployment into a single error.

func (*Deployment) GetFile

func (d *Deployment) GetFile(name, hash string) []byte

GetFile gets the requested file for the deployment and returns its contents. The deployment FileLock MUST already be locked before calling this function.

func (*Deployment) GetFileOverviews

func (d *Deployment) GetFileOverviews() ([]*pb.File, string)

GetFileOverviews returns the current list of fileOverviews and configVersion for the deployment. The deployment FileLock MUST already be locked before calling this function.

func (*Deployment) GetLatestConfigError

func (d *Deployment) GetLatestConfigError() error

GetLatestConfigError gets the latest config apply error for the deployment.

func (*Deployment) GetLatestUpstreamError

func (d *Deployment) GetLatestUpstreamError() error

GetLatestUpstreamError gets the latest upstream update error for the deployment.

func (*Deployment) GetNGINXPlusActions

func (d *Deployment) GetNGINXPlusActions() []*pb.NGINXPlusAction

GetNGINXPlusActions returns the current NGINX Plus API Actions for the deployment. The deployment FileLock MUST already be locked before calling this function.

func (*Deployment) RemovePodStatus

func (d *Deployment) RemovePodStatus(podName string)

RemovePodStatus deletes a pod from the pod status map.

func (*Deployment) SetFiles

func (d *Deployment) SetFiles(files []File) *broadcast.NginxAgentMessage

SetFiles updates the nginx files and fileOverviews for the deployment and returns the message to send. The deployment FileLock MUST already be locked before calling this function.

func (*Deployment) SetLatestConfigError

func (d *Deployment) SetLatestConfigError(err error)

SetLatestConfigError sets the latest config apply error for the deployment.

func (*Deployment) SetLatestUpstreamError

func (d *Deployment) SetLatestUpstreamError(err error)

SetLatestUpstreamError sets the latest upstream update error for the deployment.

func (*Deployment) SetNGINXPlusActions

func (d *Deployment) SetNGINXPlusActions(actions []*pb.NGINXPlusAction)

SetNGINXPlusActions updates the deployment's latest NGINX Plus Actions to perform if using NGINX Plus. Used by a Subscriber when it first connects. The deployment FileLock MUST already be locked before calling this function.

func (*Deployment) SetPodErrorStatus

func (d *Deployment) SetPodErrorStatus(pod string, err error)

SetPodErrorStatus sets the error status of a Pod in this Deployment if applying the config failed.

type DeploymentStore

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

DeploymentStore holds a map of all Deployments.

func NewDeploymentStore

func NewDeploymentStore(connTracker agentgrpc.ConnectionsTracker) *DeploymentStore

NewDeploymentStore returns a new instance of a DeploymentStore.

func (*DeploymentStore) Get

Get returns the desired deployment from the store.

func (*DeploymentStore) GetOrStore

func (d *DeploymentStore) GetOrStore(
	ctx context.Context,
	nsName types.NamespacedName,
	stopCh chan struct{},
) *Deployment

GetOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value.

func (*DeploymentStore) Remove

func (d *DeploymentStore) Remove(nsName types.NamespacedName)

Remove the deployment from the store.

func (*DeploymentStore) StoreWithBroadcaster

func (d *DeploymentStore) StoreWithBroadcaster(
	nsName types.NamespacedName,
	broadcaster broadcast.Broadcaster,
) *Deployment

StoreWithBroadcaster creates a new Deployment with the supplied broadcaster and stores it. Used in unit tests to provide a mock broadcaster.

type DeploymentStorer

type DeploymentStorer interface {
	Get(types.NamespacedName) *Deployment
	GetOrStore(context.Context, types.NamespacedName, chan struct{}) *Deployment
	Remove(types.NamespacedName)
}

DeploymentStorer is an interface to store Deployments.

type File

type File struct {
	Meta     *pb.FileMeta
	Contents []byte
}

File is an nginx configuration file that the nginx agent gets from the control plane after a ConfigApplyRequest.

type NginxUpdater

type NginxUpdater interface {
	UpdateConfig(deployment *Deployment, files []File)
	UpdateUpstreamServers(deployment *Deployment, conf dataplane.Configuration)
}

NginxUpdater is an interface for updating NGINX using the NGINX agent.

type NginxUpdaterImpl

type NginxUpdaterImpl struct {
	CommandService   *commandService
	FileService      *fileService
	NginxDeployments *DeploymentStore
	// contains filtered or unexported fields
}

NginxUpdaterImpl implements the NginxUpdater interface.

func NewNginxUpdater

func NewNginxUpdater(
	logger logr.Logger,
	reader client.Reader,
	statusQueue *status.Queue,
	resetConnChan <-chan struct{},
	plus bool,
) *NginxUpdaterImpl

NewNginxUpdater returns a new NginxUpdaterImpl instance.

func (*NginxUpdaterImpl) UpdateConfig

func (n *NginxUpdaterImpl) UpdateConfig(
	deployment *Deployment,
	files []File,
)

UpdateConfig sends the nginx configuration to the agent.

The flow of events is as follows: - Set the configuration files on the deployment. - Broadcast the message containing file metadata to all pods (subscriptions) for the deployment. - Agent receives a ConfigApplyRequest with the list of file metadata. - Agent calls GetFile for each file in the list, which we send back to the agent. - Agent updates nginx, and responds with a DataPlaneResponse. - Subscriber responds back to the broadcaster to inform that the transaction is complete. - If any errors occurred, they are set on the deployment for the handler to use in the status update.

func (*NginxUpdaterImpl) UpdateUpstreamServers

func (n *NginxUpdaterImpl) UpdateUpstreamServers(
	deployment *Deployment,
	conf dataplane.Configuration,
)

UpdateUpstreamServers sends an APIRequest to the agent to update upstream servers using the NGINX Plus API. Only applicable when using NGINX Plus.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.
Package broadcast contains the functions for creating a broadcaster to send updates to consumers.
Package broadcast contains the functions for creating a broadcaster to send updates to consumers.
broadcastfakes
Code generated by counterfeiter.
Code generated by counterfeiter.
Package grpc contains the functionality for the gRPC server for communicating with the nginx agent.
Package grpc contains the functionality for the gRPC server for communicating with the nginx agent.
context
Package context contains the functions for storing extra information in the gRPC context.
Package context contains the functions for storing extra information in the gRPC context.
filewatcher
Package filewatcher contains the functions to watch for TLS file updates for the gRPC server.
Package filewatcher contains the functions to watch for TLS file updates for the gRPC server.
grpcfakes
Code generated by counterfeiter.
Code generated by counterfeiter.
interceptor
Package interceptor contains the middleware for intercepting an RPC call.
Package interceptor contains the middleware for intercepting an RPC call.
messenger
Package messenger provides a wrapper around a gRPC stream with the nginx agent.
Package messenger provides a wrapper around a gRPC stream with the nginx agent.
messenger/messengerfakes
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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