-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add !-variants of request methods and improve yardocs #119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,8 @@ | |
|
||
module K8s | ||
# @param server [String] http/s URL | ||
# @param options [Hash] @see Transport.new | ||
# @param options [Hash] | ||
# @param (see Transport#initialize) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This syntax copies the params from the referenced method to this one. The link didn't work anyway. |
||
# @return [K8s::Client] | ||
def self.client(server, **options) | ||
Client.new(Transport.new(server, **options)) | ||
|
@@ -31,9 +32,11 @@ def self.client(server, **options) | |
# Uses a {Transport} instance to talk to the kube API. | ||
# Offers access to {APIClient} and {ResourceClient} instances. | ||
class Client | ||
extend K8s::Util::ExceptionlessBangMethod | ||
|
||
# @param config [Phraos::Kube::Config] | ||
# @param namespace [String] @see #initialize | ||
# @param options [Hash] @see Transport.config | ||
# @param namespace [String] default namespace for all operations | ||
# @param (see K8s::Transport.config) | ||
# @return [K8s::Client] | ||
def self.config(config, namespace: nil, **options) | ||
new( | ||
|
@@ -43,10 +46,9 @@ def self.config(config, namespace: nil, **options) | |
end | ||
|
||
# An K8s::Client instance from in-cluster config within a kube pod, using the kubernetes service envs and serviceaccount secrets | ||
# @see K8s::Transport#in_cluster_config | ||
# | ||
# @param namespace [String] default namespace for all operations | ||
# @param options [Hash] options passed to transport, @see Transport#in_cluster_config | ||
# @param (see K8s::Transport.in_cluster_config) | ||
# @return [K8s::Client] | ||
# @raise [K8s::Error::Config,Errno::ENOENT,Errno::EACCES] | ||
def self.in_cluster_config(namespace: nil, **options) | ||
|
@@ -64,7 +66,8 @@ def self.in_cluster_config(namespace: nil, **options) | |
# | ||
# Will raise when no means of configuration is available | ||
# | ||
# @param options [Hash] default namespace for all operations | ||
# @param namespace [String] default namespace for all operations | ||
# @param (see K8s::Transport.config) | ||
# @raise [K8s::Error::Config,Errno::ENOENT,Errno::EACCES] | ||
# @return [K8s::Client] | ||
def self.autoconfig(namespace: nil, **options) | ||
|
@@ -95,6 +98,7 @@ def self.autoconfig(namespace: nil, **options) | |
|
||
include MonitorMixin | ||
|
||
# @return [K8s::Transport] | ||
attr_reader :transport | ||
|
||
# @param transport [K8s::Transport] | ||
|
@@ -187,7 +191,7 @@ def resources(namespace: nil) | |
# Returns flattened array with mixed resource kinds. | ||
# | ||
# @param resources [Array<K8s::ResourceClient>] default is all listable resources for api | ||
# @param options @see K8s::ResourceClient#list | ||
# @param (see K8s::ResourceClient.list) | ||
# @return [Array<K8s::Resource>] | ||
def list_resources(resources = nil, **options) | ||
cached_clients = @api_clients.size.positive? | ||
|
@@ -218,12 +222,14 @@ def client_for_resource(resource, namespace: nil) | |
def create_resource(resource) | ||
client_for_resource(resource).create_resource(resource) | ||
end | ||
exceptionless_bang_method :create_resource | ||
|
||
# @param resource [K8s::Resource] | ||
# @return [K8s::Resource] | ||
def get_resource(resource) | ||
client_for_resource(resource).get_resource(resource) | ||
end | ||
exceptionless_bang_method :get_resource | ||
|
||
# Returns nils for any resources that do not exist. | ||
# This includes custom resources that were not yet defined. | ||
|
@@ -258,20 +264,22 @@ def get_resources(resources) | |
def update_resource(resource) | ||
client_for_resource(resource).update_resource(resource) | ||
end | ||
exceptionless_bang_method :update_resource | ||
|
||
# @param resource [K8s::Resource] | ||
# @param options [Hash] | ||
# @see ResourceClient#delete for options | ||
# @param (see ResourceClient.delete) | ||
# @return [K8s::Resource] | ||
def delete_resource(resource, **options) | ||
client_for_resource(resource).delete_resource(resource, **options) | ||
end | ||
exceptionless_bang_method :delete_resource | ||
|
||
# @param resource [K8s::Resource] | ||
# @param attrs [Hash] | ||
# @return [K8s::Client] | ||
def patch_resource(resource, attrs) | ||
client_for_resource(resource).json_patch(resource.metadata.name, attrs) | ||
end | ||
exceptionless_bang_method :patch_resource | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,7 +133,7 @@ def self.from_kubeconfig_env(kubeconfig = nil) | |
# | ||
# @param server [String] kubernetes server address | ||
# @param ca [String] server certificate authority data (base64 encoded) | ||
# @param token [String] access token | ||
# @param auth_token [String] access token | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong attribute name, yardoc warns about these when generating, we could add rubocop-like test step for yardoc validity. |
||
# @param cluster_name [String] cluster name | ||
# @param user [String] user name | ||
# @param context [String] context name | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,23 @@ | |
module K8s | ||
# Miscellaneous helpers | ||
module Util | ||
module ExceptionlessBangMethod | ||
private | ||
|
||
# @!macro [attach] exceptionless_bang_method | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This documents the dynamically generated |
||
# @method $1! | ||
# Same as $1 but all exceptions are suppressed | ||
def exceptionless_bang_method(meth) | ||
define_method(meth.to_s.concat('!')) do |*args, **options| | ||
begin | ||
send(meth, *args, **options) | ||
rescue StandardError | ||
nil | ||
end | ||
end | ||
end | ||
end | ||
|
||
module HashDeepMerge | ||
refine Hash do | ||
# @param other [Hash] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes all of the api struct docs get documentation for their attributes.
Before:
After: