Class: Metatron::Templates::VolumeSnapshotContent

Inherits:
Metatron::Template show all
Includes:
Concerns::Annotated, Concerns::Namespaced
Defined in:
lib/metatron/templates/volume_snapshot_content.rb

Overview

The VolumeSnapshotContent Kubernetes resource

Instance Attribute Summary collapse

Attributes inherited from Metatron::Template

#additional_labels, #api_version, #base_labels, #kind, #name

Instance Method Summary collapse

Methods included from Concerns::Namespaced

#formatted_namespace, included, #namespaced_initialize

Methods included from Concerns::Annotated

#annotated_initialize, #formatted_annotations, included

Methods inherited from Metatron::Template

initializer, initializers, metatron_template_class?, nearest_metatron_ancestor

Constructor Details

#initialize(name, driver:, source: {}, deletion_policy: "Delete", volume_snapshot_ref: nil, source_volume_mode: "Filesystem") ⇒ VolumeSnapshotContent

Returns a new instance of VolumeSnapshotContent.

[View source]

16
17
18
19
20
21
22
23
24
25
# File 'lib/metatron/templates/volume_snapshot_content.rb', line 16

def initialize(name, driver:, source: {}, deletion_policy: "Delete",
               volume_snapshot_ref: nil, source_volume_mode: "Filesystem")
  super(name)
  @api_version = "snapshot.storage.k8s.io/v1"
  @driver = driver
  @source = source
  @source_volume_mode = source_volume_mode
  @deletion_policy = deletion_policy
  @volume_snapshot_ref = volume_snapshot_ref
end

Instance Attribute Details

#deletion_policyObject Also known as: deletionPolicy

Returns the value of attribute deletion_policy.


10
11
12
# File 'lib/metatron/templates/volume_snapshot_content.rb', line 10

def deletion_policy
  @deletion_policy
end

#driverObject

Returns the value of attribute driver.


10
11
12
# File 'lib/metatron/templates/volume_snapshot_content.rb', line 10

def driver
  @driver
end

#sourceObject

Returns the value of attribute source.


10
11
12
# File 'lib/metatron/templates/volume_snapshot_content.rb', line 10

def source
  @source
end

#source_volume_modeObject Also known as: sourceVolumeMode

Returns the value of attribute source_volume_mode.


10
11
12
# File 'lib/metatron/templates/volume_snapshot_content.rb', line 10

def source_volume_mode
  @source_volume_mode
end

#volume_snapshot_refObject Also known as: volumeSnapshotRef

Returns the value of attribute volume_snapshot_ref.


10
11
12
# File 'lib/metatron/templates/volume_snapshot_content.rb', line 10

def volume_snapshot_ref
  @volume_snapshot_ref
end

Instance Method Details

#formatted_sourceObject

Raises:

  • (ArgumentError)
[View source]

43
44
45
46
47
48
# File 'lib/metatron/templates/volume_snapshot_content.rb', line 43

def formatted_source
  return {} unless source
  raise ArgumentError, "Invalid source type: #{source.class}." unless source.is_a?(Hash)

  { source: }
end

#formatted_volume_snapshot_refObject

[View source]

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/metatron/templates/volume_snapshot_content.rb', line 50

def formatted_volume_snapshot_ref
  return {} unless volume_snapshot_ref

  if volume_snapshot_ref.is_a?(Hash)
    { volumeSnapshotRef: }
  elsif volume_snapshot_ref.is_a?(VolumeSnapshot)
    {
      volumeSnapshotRef: {
        name: volume_snapshot_ref.name,
        namespace: volume_snapshot_ref.namespace
      }.compact
    }
  else
    raise ArgumentError,
          "Invalid volume_snapshot_ref type: #{volume_snapshot_ref.class}."
  end
end

#renderObject

[View source]

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/metatron/templates/volume_snapshot_content.rb', line 27

def render
  {
    apiVersion:,
    kind:,
    metadata: {
      name:,
      labels: base_labels.merge(additional_labels)
    }.merge(formatted_annotations).merge(formatted_namespace).compact,
    spec: {
      driver:,
      deletionPolicy:,
      sourceVolumeMode:
    }.merge(formatted_source).merge(formatted_volume_snapshot_ref).compact
  }.compact
end