| 1 | package Kubernetes::REST::CLI::Role::Connection; | ||||||||||||||||||||||
| 2 | 3 | our $VERSION = '1.108'; | |||||||||||||||||||||
| 3 | # ABSTRACT: Shared kubeconfig/auth options for CLI tools | ||||||||||||||||||||||
| 4 | 5 | ▶ | use Moo::Role; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 5 | ▶ | use MooX::Options; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 5 | ▶ | use Kubernetes::REST::Kubeconfig; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | # Deliberately without a default: an option that always has a value is always | ||||||||||||||||||||||
| 10 | # passed on, and Kubernetes::REST::Kubeconfig never reaches its own default of | ||||||||||||||||||||||
| 11 | # $ENV{KUBECONFIG} // ~/.kube/config. Leaving it undef when the user did not ask | ||||||||||||||||||||||
| 12 | # for a path is what lets the environment variable through. | ||||||||||||||||||||||
| 13 | 3 | option kubeconfig => ( | |||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||
| 15 | format => 's', | ||||||||||||||||||||||
| 16 | doc => 'Path to kubeconfig file (default: $KUBECONFIG, else ~/.kube/config)', | ||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | 3 | option context => ( | |||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||
| 22 | format => 's', | ||||||||||||||||||||||
| 23 | short => 'c', | ||||||||||||||||||||||
| 24 | doc => 'Kubernetes context to use', | ||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||
| 26 | |||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | has api => ( | ||||||||||||||||||||||
| 29 | is => 'lazy', | ||||||||||||||||||||||
| 30 | 0 | ▶ | builder => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=14.2
Subroutine
_build_api: called CC=3 SCAR=14.2
| |||||||||||||||||||||||
| 31 | 0 | my $self = shift; | |||||||||||||||||||||
| 32 | # kubeconfig_path is only passed when --kubeconfig was given, so an | ||||||||||||||||||||||
| 33 | # unset option falls through to Kubeconfig's own $ENV{KUBECONFIG} | ||||||||||||||||||||||
| 34 | # default rather than being overridden by a home-directory guess. | ||||||||||||||||||||||
| 35 | 0 | ▶ | my $kc = Kubernetes::REST::Kubeconfig->new( | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 36 | (defined $self->kubeconfig ? (kubeconfig_path => $self->kubeconfig) : ()), | ||||||||||||||||||||||
| 37 | ($self->context ? (context_name => $self->context) : ()), | ||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||
| 39 | 0 | return $kc->api; | |||||||||||||||||||||
| 40 | }, | ||||||||||||||||||||||
| 41 | 3 | ); | |||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | 3 | 1; | |||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | __END__ | ||||||||||||||||||||||
| 47 | |||||||||||||||||||||||
| 48 | =pod | ||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | =encoding UTF-8 | ||||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | =head1 NAME | ||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | Kubernetes::REST::CLI::Role::Connection - Shared kubeconfig/auth options for CLI tools | ||||||||||||||||||||||
| 55 | |||||||||||||||||||||||
| 56 | =head1 VERSION | ||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | version 1.108 | ||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | =head1 DESCRIPTION | ||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | Moo role providing C<--kubeconfig> and C<--context> options and a lazy C<api> attribute that builds a L<Kubernetes::REST> instance from the kubeconfig. | ||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | Consumed by L<Kubernetes::REST::CLI> and L<Kubernetes::REST::CLI::Watch>. | ||||||||||||||||||||||
| 65 | |||||||||||||||||||||||
| 66 | =head2 kubeconfig | ||||||||||||||||||||||
| 67 | |||||||||||||||||||||||
| 68 | Path to kubeconfig file. Without it the C<KUBECONFIG> environment variable is | ||||||||||||||||||||||
| 69 | used, and without that C<~/.kube/config> - the same precedence C<kubectl> and | ||||||||||||||||||||||
| 70 | L<Kubernetes::REST::Kubeconfig> apply. An explicitly given C<--kubeconfig> wins | ||||||||||||||||||||||
| 71 | over C<KUBECONFIG>. | ||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | C<KUBECONFIG> may name several files as the C<:>-separated list C<kubectl> | ||||||||||||||||||||||
| 74 | merges, in which case they are merged the same way - see | ||||||||||||||||||||||
| 75 | L<Kubernetes::REST::Kubeconfig/MERGING>. C<--kubeconfig> takes such a list too, | ||||||||||||||||||||||
| 76 | since it is passed straight through. | ||||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | =head2 context | ||||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | Kubernetes context to use from the kubeconfig. Defaults to the current-context. | ||||||||||||||||||||||
| 81 | |||||||||||||||||||||||
| 82 | Short option: C<-c> | ||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | =head2 api | ||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | Lazy L<Kubernetes::REST> instance built from the kubeconfig. | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | The kubeconfig it is built from is C<--kubeconfig> if given, otherwise | ||||||||||||||||||||||
| 89 | C<$ENV{KUBECONFIG}>, otherwise C<~/.kube/config>. Either of the first two may | ||||||||||||||||||||||
| 90 | be a C<:>-separated list of files, which is merged as C<kubectl> merges it. | ||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | =head1 SEE ALSO | ||||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | =over | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | =item * L<Kubernetes::REST::Kubeconfig> - Kubeconfig parser | ||||||||||||||||||||||
| 97 | |||||||||||||||||||||||
| 98 | =item * L<Kubernetes::REST::CLI> - CLI base class | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | =item * L<Kubernetes::REST::CLI::Watch> - Watch CLI tool | ||||||||||||||||||||||
| 101 | |||||||||||||||||||||||
| 102 | =back | ||||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | =head1 SUPPORT | ||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | =head2 Issues | ||||||||||||||||||||||
| 107 | |||||||||||||||||||||||
| 108 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||
| 109 | L<https://github.com/pplu/kubernetes-rest/issues>. | ||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | =head2 IRC | ||||||||||||||||||||||
| 112 | |||||||||||||||||||||||
| 113 | Join C<#kubernetes> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | =head1 CONTRIBUTING | ||||||||||||||||||||||
| 116 | |||||||||||||||||||||||
| 117 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | =head1 AUTHORS | ||||||||||||||||||||||
| 120 | |||||||||||||||||||||||
| 121 | =over 4 | ||||||||||||||||||||||
| 122 | |||||||||||||||||||||||
| 123 | =item * | ||||||||||||||||||||||
| 124 | |||||||||||||||||||||||
| 125 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||||
| 126 | |||||||||||||||||||||||
| 127 | =item * | ||||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | Jose Luis Martinez Torres <jlmartin@cpan.org> | ||||||||||||||||||||||
| 130 | |||||||||||||||||||||||
| 131 | =back | ||||||||||||||||||||||
| 132 | |||||||||||||||||||||||
| 133 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||
| 134 | |||||||||||||||||||||||
| 135 | This software is Copyright (c) 2019-2026 by Jose Luis Martinez Torres <jlmartin@cpan.org>. | ||||||||||||||||||||||
| 136 | |||||||||||||||||||||||
| 137 | This is free software, licensed under: | ||||||||||||||||||||||
| 138 | |||||||||||||||||||||||
| 139 | The Apache License, Version 2.0, January 2004 | ||||||||||||||||||||||
| 140 | |||||||||||||||||||||||
| 141 | =cut | ||||||||||||||||||||||