module Cluster
Nested
Definitions
def self.resolve_table
Internal table mapping a bare kind to the group/version/Kind it should resolve to. Consulted first by Kube::Cluster.[] so a bare lookup lands on a pinned version instead of whatever the schema registry defaults to.
Implementation
def self.resolve_table
@resolve_table ||= {}
end
def self.config(&block)
Configure kind resolution:
Kube::Cluster.config do resolve "Perses", to: "perses.dev/v1alpha2/Perses" end
Ordering matters: Kube::Cluster.[] memoizes per kind, and the Standard
classes bind their superclass at definition time (e.g.
class Perses < Kube::Cluster["Perses"]). A resolve therefore only takes
effect for kinds looked up afterwards — so configure before requiring any
kube/cluster/standard class. If Standard is already loaded, warn: its
classes have already bound their (now stale) superclasses.
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
Config.instance_eval(&block) if block
Config
end
def self.[](kind)
Returns an anonymous subclass of Kube::Cluster::Resource for the given Kubernetes kind, mirroring Kube::Schema[kind] but with dirty tracking, persistence, and resource helper methods.
Kube::Cluster["Deployment"].new metadata.name = "web"
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