daemonset

package
v0.37.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Pod environment variables
	POSTMAN_INSIGHTS_PROJECT_ID         = "POSTMAN_INSIGHTS_PROJECT_ID"
	POSTMAN_INSIGHTS_API_KEY            = "POSTMAN_INSIGHTS_API_KEY"
	POSTMAN_INSIGHTS_DISABLE_REPRO_MODE = "POSTMAN_INSIGHTS_DISABLE_REPRO_MODE"
	POSTMAN_INSIGHTS_DROP_NGINX_TRAFFIC = "POSTMAN_INSIGHTS_DROP_NGINX_TRAFFIC"
	POSTMAN_INSIGHTS_AGENT_RATE_LIMIT   = "POSTMAN_INSIGHTS_AGENT_RATE_LIMIT"

	// Daemonset environment variables
	POSTMAN_INSIGHTS_ENV                = "POSTMAN_ENV" // This is same as root POSTMAN_ENV
	POSTMAN_INSIGHTS_VERIFICATION_TOKEN = "POSTMAN_INSIGHTS_VERIFICATION_TOKEN"
	POSTMAN_INSIGHTS_CLUSTER_NAME       = "POSTMAN_INSIGHTS_CLUSTER_NAME"

	// Workers intervals
	DefaultTelemetryInterval      = 5 * time.Minute
	DefaultPodHealthCheckInterval = 5 * time.Minute
)

Variables

This section is empty.

Functions

func StartDaemonset

func StartDaemonset(args DaemonsetArgs) error

Types

type Daemonset

type Daemonset struct {
	ClusterName              string
	InsightsEnvironment      string
	InsightsReproModeEnabled bool
	InsightsRateLimit        float64

	KubeClient  kube_apis.KubeClient
	CRIClient   *cri_apis.CriClient
	FrontClient rest.FrontClient

	// Note: Only filtered pods are stored in this map, i.e., they have required env vars
	// and do not have the agent sidecar container
	PodArgsByNameMap sync.Map

	// WaitGroup to wait for all apidump processes to stop
	ApidumpProcessesWG sync.WaitGroup

	PodHealthCheckInterval time.Duration
	TelemetryInterval      time.Duration
}

func (*Daemonset) KubernetesPodEventsWorker

func (d *Daemonset) KubernetesPodEventsWorker(done <-chan struct{})

KubernetesPodEventsWorker listens for Kubernetes events and handles them accordingly. It runs indefinitely until the provided done channel is closed.

func (*Daemonset) PodsHealthWorker

func (d *Daemonset) PodsHealthWorker(done <-chan struct{})

PodsHealthWorker periodically checks the health of the pods and prunes stopped processes. It runs until the provided done channel is closed.

func (*Daemonset) Run

func (d *Daemonset) Run() error

Run starts the Daemonset and its workers, and waits for a termination signal. It performs the following steps: 1. Starts all the workers. 4. Starts the process in the existing pods. 5. Waits for a termination signal (SIGINT or SIGTERM). 6. Signals all workers to stop. 7. Stops all apidump processes. 8. Exits the daemonset agent.

func (*Daemonset) SignalApiDumpProcessToStop added in v0.37.3

func (d *Daemonset) SignalApiDumpProcessToStop(podUID types.UID, stopErr error) error

SignalApiDumpProcessToStop signals the API dump process to stop for a given pod identified by its UID. It retrieves the process's stop channel object from a map and sends a stop signal to trigger apidump shutdown.

func (*Daemonset) StartApiDumpProcess

func (d *Daemonset) StartApiDumpProcess(podUID types.UID) error

StartApiDumpProcess initiates the API dump process for a given pod identified by its UID. It retrieves the pod arguments, changes the pod's traffic monitoring state, and starts the API dump process in a separate goroutine. The goroutine handles errors and state changes, and ensures the process is stopped properly.

func (*Daemonset) StartProcessInExistingPods

func (d *Daemonset) StartProcessInExistingPods() error

StartProcessInExistingPods starts apidump process in existing pods that do not have the agent sidecar container and required env vars.

func (*Daemonset) StopAllApiDumpProcesses

func (d *Daemonset) StopAllApiDumpProcesses()

StopAllApiDumpProcesses stops all API dump processes for the Daemonset. It iterates over the PodArgsByNameMap and performs the following actions for each pod: 1. Changes the pod's traffic monitor state to DaemonSetShutdown. 2. Stops the API dump process for the pod. 3. Logs any errors encountered during the state change or stopping process. 4. Removes the pod from the PodArgsByNameMap. 5. Wait for all the apidump processes to stop.

func (*Daemonset) TelemetryWorker

func (d *Daemonset) TelemetryWorker(done <-chan struct{})

TelemetryWorker starts a worker that periodically sends telemetry data and dumps the state of the Pods API dump process. The worker runs until the provided done channel is closed.

type DaemonsetArgs added in v0.35.0

type DaemonsetArgs struct {
	ReproMode bool
	RateLimit float64
}

type PodArgs

type PodArgs struct {
	// apidump related fields
	InsightsProjectID akid.ServiceID
	TraceTags         tags.SingletonTags
	ReproMode         bool
	DropNginxTraffic  bool
	AgentRateLimit    float64

	// Pod related fields
	PodName       string
	ContainerUUID string
	PodCreds      PodCreds

	// for state management
	PodTrafficMonitorState PodTrafficMonitorState
	StateChangeMutex       sync.Mutex `json:"-"`

	// send stop signal to apidump process
	StopChan chan error `json:"-"`
}

func NewPodArgs

func NewPodArgs(podName string) *PodArgs

type PodCreds

type PodCreds struct {
	InsightsAPIKey      string
	InsightsEnvironment string
}

type PodTrafficMonitorState

type PodTrafficMonitorState string
const (
	// Pod Lifecycle states
	PodPending       PodTrafficMonitorState = "PodPending"       // When agent will receive pod added event
	PodRunning       PodTrafficMonitorState = "PodRunning"       // When the pod is running and agent can start the apidump process
	PodSucceeded     PodTrafficMonitorState = "PodSucceeded"     // When the pod is terminated successfully, agent will receive pod deleted event
	PodFailed        PodTrafficMonitorState = "PodFailed"        // When the pod is terminated with failure, agent will receive pod deleted event
	PodTerminated    PodTrafficMonitorState = "PodTerminated"    // custom: When the pod is terminated with unknown status
	RemovePodFromMap PodTrafficMonitorState = "RemovePodFromMap" // custom: Final state after which pod will be removed from the map

	// Traffic monitoring states
	TrafficMonitoringRunning PodTrafficMonitorState = "TrafficMonitoringRunning" // When apidump process is running for the pod
	TrafficMonitoringFailed  PodTrafficMonitorState = "TrafficMonitoringFailed"  // When apidump process is errored for the pod
	TrafficMonitoringEnded   PodTrafficMonitorState = "TrafficMonitoringEnded"   // When apidump process is ended without any issue for the pod

	// Daemonset shutdown state
	DaemonSetShutdown PodTrafficMonitorState = "DaemonSetShutdown" // When the daemonset agent starts the shutdown process
)

Different states of pod traffic monitoring The state transition is as follows: State diagram: https://whimsical.com/pod-monitoring-state-diagram-Ny5HqFJxz2fntz6ZM6bj2k

Jump to

Keyboard shortcuts

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