module Cluster
Nested
Definitions
def self.resolve_table
Maps a bare kind to the group/version/Kind to resolve to.
Signature
-
returns
Hash the resolve table, consulted first by Kube::Cluster.[].
Implementation
def self.resolve_table
@resolve_table ||= {}
end
def self.config(&block)
Configures kind resolution; call before loading Standard classes.
Example.
Kube::Cluster.config do
resolve "Perses", to: "perses.dev/v1alpha2/Perses"
end
Signature
-
yields
{} evaluated against Config, to call #resolve.
-
returns
Config the resolution config module.
Implementation
def self.config(&block)
if const_defined?(:Standard, false)
warn "Kube::Cluster::Standard was loaded before Kube::Cluster.config — " \
"resolve overrides will not affect the already-bound Standard classes."
end
if block
Config.instance_eval(&block)
end
Config
end
def self.[](kind)
A Resource subclass for a kind, with dirty tracking.
Example.
Kube::Cluster["Deployment"].new { metadata.name = "web" }
Signature
-
parameter
kindString a Kubernetes kind, or a resolved GVK string.
-
returns
Class an anonymous subclass of Kube::Cluster::Resource.
Implementation
def self.[](kind)
kind = resolve_table.fetch(kind, kind)
@resource_classes ||= {}
@resource_classes[kind] ||= begin
schema_class = Kube::Schema[kind]
Class.new(Resource) do
@schema = schema_class.schema
@defaults = schema_class.defaults
@schema_properties = schema_class.schema_properties
def self.schema = @schema || superclass.schema
def self.defaults = @defaults || superclass.defaults
def self.schema_properties = @schema_properties || superclass.schema_properties
end
end
end