Module: Kube::Cluster

Includes:
ScriptCommands
Defined in:
lib/kube/cluster.rb,
lib/kube/cluster/version.rb,
lib/kube/cluster/instance.rb,
lib/kube/cluster/manifest.rb,
lib/kube/cluster/resource.rb,
lib/kube/cluster/container.rb,
lib/kube/cluster/connection.rb,
lib/kube/cluster/middleware.rb,
lib/kube/cluster/standard/job.rb,
lib/kube/cluster/standard/role.rb,
lib/kube/cluster/script_command.rb,
lib/kube/cluster/standard/secret.rb,
lib/kube/cluster/middleware/stack.rb,
lib/kube/cluster/standard/service.rb,
lib/kube/cluster/middleware/labels.rb,
lib/kube/cluster/standard/cron_job.rb,
lib/kube/cluster/standard/config_map.rb,
lib/kube/cluster/standard/daemon_set.rb,
lib/kube/cluster/middleware/namespace.rb,
lib/kube/cluster/resource/persistence.rb,
lib/kube/cluster/standard/forgejo/helm.rb,
lib/kube/cluster/standard/role_binding.rb,
lib/kube/cluster/middleware/annotations.rb,
lib/kube/cluster/standard/perses/perses.rb,
lib/kube/cluster/resource/dirty_tracking.rb,
lib/kube/cluster/standard/env_processing.rb,
lib/kube/cluster/middleware/set_namespace.rb,
lib/kube/cluster/standard/cdi/data_volume.rb,
lib/kube/cluster/standard/service_account.rb,
lib/kube/cluster/middleware/resource_preset.rb,
lib/kube/cluster/standard/volume_processing.rb,
lib/kube/cluster/middleware/security_context.rb,
lib/kube/cluster/middleware/pod_anti_affinity.rb,
lib/kube/cluster/middleware/set_reloader_auto.rb,
lib/kube/cluster/standard/eso/external_secret.rb,
lib/kube/cluster/middleware/hpa_for_deployment.rb,
lib/kube/cluster/standard/cloud_native_pg/helm.rb,
lib/kube/cluster/middleware/ingress_for_service.rb,
lib/kube/cluster/standard/gateway_api/http_route.rb,
lib/kube/cluster/standard/cloud_native_pg/cluster.rb,
lib/kube/cluster/standard/deployment_with_service.rb,
lib/kube/cluster/standard/persistent_volume_claim.rb,
lib/kube/cluster/middleware/service_for_deployment.rb,
lib/kube/cluster/standard/job_with_service_account.rb,
lib/kube/cluster/standard/perses/perses_datasource.rb,
lib/kube/cluster/standard/victoria_metrics/vm_rule.rb,
lib/kube/cluster/standard/kube_virt/virtual_machine.rb,
lib/kube/cluster/standard/service_account_with_role.rb,
lib/kube/cluster/standard/victoria_metrics/vl_agent.rb,
lib/kube/cluster/standard/victoria_metrics/vm_agent.rb,
lib/kube/cluster/standard/victoria_metrics/vm_alert.rb,
lib/kube/cluster/standard/custom_resource_definition.rb,
lib/kube/cluster/standard/victoria_metrics/vl_single.rb,
lib/kube/cluster/standard/victoria_metrics/vm_single.rb,
lib/kube/cluster/standard/cron_job_with_service_account.rb,
lib/kube/cluster/standard/cloud_native_pg/external_secret.rb,
lib/kube/cluster/standard/victoria_metrics/vm_node_scrape.rb,
lib/kube/cluster/standard/victoria_metrics/vm_service_scrape.rb,
lib/kube/cluster/standard/meta_controller/composite_controller.rb,
lib/kube/cluster/standard/meta_controller/decorator_controller.rb,
lib/kube/cluster/resource/extensions/custom_resource_definition.rb,
lib/kube/cluster/standard/cloud_native_pg/database_with_external_secret.rb

Defined Under Namespace

Modules: Config, ScriptCommands, Standard Classes: Connection, Container, Instance, Manifest, Middleware, Resource

Constant Summary collapse

VERSION =
"1.4.0"

Class Method Summary collapse

Class Method Details

.[](kind) ⇒ Object

Returns an anonymous subclass of Kube::Cluster::Resource for the given Kubernetes kind, mirroring Kube::Schema but with dirty tracking, persistence, and resource helper methods.

Kube::Cluster["Deployment"].new { .name = "web" }


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/kube/cluster.rb', line 65

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

.BashScriptObject

.config(&block) ⇒ Object

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.



42
43
44
45
46
47
48
49
# File 'lib/kube/cluster.rb', line 42

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

.connect(kubeconfig:) ⇒ Object



19
20
21
# File 'lib/kube/cluster.rb', line 19

def self.connect(kubeconfig:)
  Instance.new(kubeconfig: kubeconfig)
end

.PythonScriptObject

.resolve_tableObject

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.



26
27
28
# File 'lib/kube/cluster.rb', line 26

def self.resolve_table
  @resolve_table ||= {}
end

.RubyScriptObject

.ShScriptObject