DBIO-MySQL

 view release on metacpan or  search on metacpan

xbin/dbio-mysql-k8s  view on Meta::CPAN

}

sub _wait_for_ready {
  my ($k8s, $ns, $name, $user) = @_;
  print STDERR "Waiting for pod $name to be ready";
  my $deadline = time + 300;
  my $last_phase = '';
  while (time < $deadline) {
    my $pod = eval { $k8s->get('Pod', name => $name, namespace => $ns) };
    if ($pod) {
      return _get_service_endpoint($k8s, $ns, $name) if _pod_ready($pod);
      my $phase = eval { $pod->status->phase } // '?';
      # Show phase changes and any waiting reason (e.g. ErrImagePull)
      my $reason = eval {
        my $cs = $pod->status->containerStatuses // [];
        @$cs ? ($cs->[0]->state->waiting // {})->{reason} // '' : ''
      } // '';
      my $status = $reason ? "$phase/$reason" : $phase;
      if ($status ne $last_phase) {
        print STDERR " [$status]";
        $last_phase = $status;

xbin/dbio-mysql-k8s  view on Meta::CPAN

  print STDERR "\n";
  die "Timed out waiting for pod $name\n";
}

sub _pod_ready {
  my ($pod) = @_;
  my $conditions = $pod->status->conditions // [];
  return grep { $_->type eq 'Ready' && $_->status eq 'True' } @$conditions;
}

sub _get_service_endpoint {
  my ($k8s, $ns, $name) = @_;
  my $svc       = $k8s->get('Service', name => $name, namespace => $ns);
  my $node_port = $svc->spec->ports->[0]->nodePort
    or die "No nodePort assigned to service $name\n";

  my $nodes  = $k8s->list('Node');
  my ($node) = grep { _node_ready($_) } @{ $nodes->items };
  die "No ready nodes found\n" unless $node;

  my ($addr) = grep { $_->type eq 'InternalIP' } @{ $node->status->addresses };



( run in 0.830 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )