Class: Kubes::Compiler::Dsl::Syntax::Resource

Inherits:
Core::Base
  • Object
show all
Includes:
Util::Normalize
Defined in:
lib/kubes/compiler/dsl/syntax/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Normalize

#extract_type, #normalize_kind

Instance Attribute Details

#kind_from_blockObject

Returns the value of attribute kind_from_block.



16
17
18
# File 'lib/kubes/compiler/dsl/syntax/resource.rb', line 16

def kind_from_block
  @kind_from_block
end

Instance Method Details

#default_apiVersionObject



45
46
47
# File 'lib/kubes/compiler/dsl/syntax/resource.rb', line 45

def default_apiVersion
  "v1"
end

#default_kindObject Also known as: resource_kind



58
59
60
61
# File 'lib/kubes/compiler/dsl/syntax/resource.rb', line 58

def default_kind
  return @kind_from_block if @kind_from_block
  normalize_kind(@path)
end

#default_metadataObject



49
50
51
52
53
54
55
56
# File 'lib/kubes/compiler/dsl/syntax/resource.rb', line 49

def 
  {
    annotations: annotations,
    name: name,
    labels: labels,
    namespace: namespace,
  }
end

#default_resultObject

top-level of resource is quite common



19
20
21
22
23
24
# File 'lib/kubes/compiler/dsl/syntax/resource.rb', line 19

def default_result
  data = top.merge(default_top)
  Kubes.deep_merge!(data, default_result_append)
  data.deep_stringify_keys!
  HashSqueezer.squeeze(data)
end

#default_result_appendObject

can be overridden by subclasses. IE: secret



41
42
43
# File 'lib/kubes/compiler/dsl/syntax/resource.rb', line 41

def default_result_append
  {}
end

#default_topObject



31
32
33
34
35
36
37
38
# File 'lib/kubes/compiler/dsl/syntax/resource.rb', line 31

def default_top
  {
    apiVersion: apiVersion,
    kind: kind,
    metadata: ,
    spec: spec,
  }
end

#field(name, data) ⇒ Object

For generic kind



65
66
67
# File 'lib/kubes/compiler/dsl/syntax/resource.rb', line 65

def field(name, data)
  Kubes.deep_merge!(top, {name => data})
end

#topObject

Where to set fields for generic kind



27
28
29
# File 'lib/kubes/compiler/dsl/syntax/resource.rb', line 27

def top
  @top ||= {}
end