Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply(ctx context.Context, ctrlConfig *controller.ControllerConfig) error
Apply orchestrates GCP ILB integration on startup. It discovers the ILB backend service, validates required device flags, configures peer discovery, and sets tunnel mode for BPF hairpin redirect.
Steps: 1. Query instance metadata (project, zone, region, instance group) 2. Discover ILB backend service 3. Validate required device flags (ingress and egress) 4. Set tunnel mode to empty string for BPF hairpin (tunnel_mode = 0) 5. Configure peer discovery via GCP discovery with cluster-name tag
Returns error if any step fails (startup should abort).
func Cleanup ¶
Cleanup is called on shutdown to deregister from the GCP ILB backend service. For GCP ILB, there is no deregistration needed - instances stay in the instance group. Health check propagation (503 on /health) is sufficient for graceful draining.
Called by SIGTERM handler in cmd/root.go SetupSignalHandler.
func ParseInstanceGroupName ¶
ParseInstanceGroupName extracts the instance group name from the created-by attribute. Format: "projects/PROJECT_NUM/zones/ZONE/instanceGroupManagers/GROUP_NAME"
Returns:
- string: Instance group name
- error: Invalid format or missing segment
func SetMetricsCollector ¶
func SetMetricsCollector(mc *metrics.MetricsCollector)
SetMetricsCollector stores the metrics collector reference for registration status updates. Called from cmd/root.go after controller initialization.
Types ¶
type GCPMetadata ¶
type GCPMetadata struct {
ProjectID string
Zone string
Region string
InstanceGroupName string // Empty if single-instance (not in an instance group)
}
GCPMetadata holds the GCP instance metadata required for ILB backend discovery. It includes VM identity (project, zone, region) and instance group membership.
func QueryInstanceMetadata ¶
func QueryInstanceMetadata(ctx context.Context) (*GCPMetadata, error)
QueryInstanceMetadata queries the GCP metadata service for instance self-discovery. It retrieves project ID, zone, region, and instance group membership (if any).
The function wraps metadata queries with exponential backoff to handle: - Transient metadata service errors - Rate limits - Startup timing (metadata may not be ready immediately)
Instance group discovery strategy:
- First, try the "created-by" metadata attribute (set by GCP for Managed Instance Groups)
- If not available, query the GCP Compute API to find unmanaged instance groups containing this instance
Single-instance mode: If no instance group is found via either method, returns GCPMetadata with empty InstanceGroupName (graceful handling).
Returns:
- *GCPMetadata: Instance identity and group membership
- error: metadata service unavailable or parse failures
type ILBConfig ¶
type ILBConfig struct {
// From GCPMetadata
ProjectID string
Zone string
Region string
InstanceGroupName string
// From ILB backend service discovery
BackendServiceName string
BackendServiceURL string // Full ARM-style URL
}
ILBConfig holds the configuration for GCP Internal Load Balancer integration. It includes VM identity from metadata and discovered ILB backend service details.
func DiscoverILBBackendService ¶
func DiscoverILBBackendService(ctx context.Context, metadata *GCPMetadata) (*ILBConfig, error)
DiscoverILBBackendService discovers the GCP Internal Load Balancer backend service for this VM instance.
Discovery process: 1. Verify instance is in an instance group (InstanceGroupName not empty) 2. Create Compute API service (uses Application Default Credentials) 3. Build instance group URL 4. List regional backend services 5. Find backend service referencing this instance group
Rate limit handling: HTTP 429 errors are retried with exponential backoff.
Returns:
- *ILBConfig: Complete configuration for ILB integration
- error: discovery failure (not in instance group, credentials, API, not found)