Module: Kube::Cluster::Standard::VolumeProcessing

Defined in:
lib/kube/cluster/standard/volume_processing.rb

Class Method Summary collapse

Class Method Details

.process(input) ⇒ Object

Convert a volume_mounts hash into Kubernetes volumes and volumeMounts arrays.

Hash values (mount path => source ref):

ExternalSecret::KeyRef  => secret volume with items, mount with subPath + readOnly
ExternalSecret          => secret volume, directory mount
PersistentVolumeClaim   => persistentVolumeClaim volume, plain mount

Legacy: if input is an Array, it is returned as-is for backwards compat.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/kube/cluster/standard/volume_processing.rb', line 19

def self.process(input)
  return { volumes: [], volume_mounts: input } if input.is_a?(Array)
  return { volumes: [], volume_mounts: [] } if input.nil? || input.empty?

  volumes = []
  mounts = []

  input.each do |mount_path, source|
    case source
    when ExternalSecret::KeyRef
      name = source.secret.secret_name
      key  = source.key_name
      volumes << {
        name: name,
        secret: {
          secretName: name,
          items: [{ key: key, path: key }]
        }
      }
      mounts << {
        name: name,
        mountPath: mount_path,
        subPath: key,
        readOnly: true
      }

    when ExternalSecret
      name = source.secret_name
      volumes << { name: name, secret: { secretName: name } }
      mounts  << { name: name, mountPath: mount_path }

    when PersistentVolumeClaim
      name = source.to_h.dig(:metadata, :name)
      volumes << { name: name, persistentVolumeClaim: { claimName: name } }
      mounts  << { name: name, mountPath: mount_path }

    when ConfigMap::KeyRef
      name = source.config_map.config_map_name
      key  = source.key_name
      volumes << {
        name: name,
        configMap: {
          name: name,
          items: [{ key: key, path: key }]
        }
      }
      mounts << {
        name: name,
        mountPath: mount_path,
        subPath: key,
        readOnly: true
      }

    when ConfigMap
      name = source.to_h.dig(:metadata, :name)
      volumes << { name: name, configMap: { name: name } }
      mounts  << { name: name, mountPath: mount_path, readOnly: true }
    end
  end

  { volumes: volumes, volume_mounts: mounts }
end