Skip to content

NLB target group registration logic in Puppet #235

@akuzminsky

Description

@akuzminsky

Parent Epic

Part of #232 - Percona Server Puppet Integration

Migrated from infrahouse/terraform-aws-percona-server#30

Description

Implement Puppet logic to register instances with the appropriate NLB target group based on role.

Registration Rules

Role Target Group
Master Write TG
Replica Read TG

Puppet Implementation

class percona::target_group_registration {
  $role = $facts['percona_role']  # 'master' or 'replica'
  $write_tg = $facts['percona_write_tg_arn']
  $read_tg = $facts['percona_read_tg_arn']
  $instance_id = $facts['ec2_instance_id']
  
  if $role == 'master' {
    exec { 'register-write-tg':
      command => "aws elbv2 register-targets --target-group-arn ${write_tg} --targets Id=${instance_id}",
      unless  => "aws elbv2 describe-target-health --target-group-arn ${write_tg} | grep ${instance_id}",
    }
  } else {
    exec { 'register-read-tg':
      command => "aws elbv2 register-targets --target-group-arn ${read_tg} --targets Id=${instance_id}",
      unless  => "aws elbv2 describe-target-health --target-group-arn ${read_tg} | grep ${instance_id}",
    }
  }
}

Role Determination

Role is determined during bootstrap:

  1. Try to acquire master lock
  2. If won and no existing master -> become master
  3. Otherwise -> become replica

Events Handled by Puppet

Event Action
Initial master boot Register to write TG
Initial replica boot Register to read TG
Replica dies (replacement) Register to read TG

Note: Failover registration handled by Orchestrator hooks, not Puppet

Acceptance Criteria

  • Master registered to write TG
  • Replicas registered to read TG
  • Registration idempotent
  • Health checks pass after registration

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions