Sha256: 7c2286de3b1fd39275fc7244a22a37fc9c3a4aa79215d145c2d5bb724cf50011

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Kubec
  class Kubernetes
    # :nodoc:
    class Volume < Hash
      def initialize(name, &block)
        self[:name] = name
        instance_eval(&block)
      end

      # TODO: Refactor this feature
      def fetch(*args)
        Environment.instance.fetch(*args)
      end

      def empty(memory = false)
        self[:emptyDir] = if memory
                            { medium: true }
                          else
                            {}
                          end
      end

      def host_path(path, type = nil)
        self[:hostPath] = { path: path }
        self[:hostPath][:type] = type unless type.nil?
      end

      def gce(name, type: 'ext4', ro: false)
        self[:gcePersistentDisk] = {
          pdName: name,
          fsType: type,
          readOnly: ro
        }
      end

      # TODO: Check for should create a new class to handle
      def config(name, items)
        self[:configMap] = {
          name: name,
          items: items.map do |key, path|
            { key: key, path: path }
          end
        }
      end

      def secret(name, items = nil)
        self[:secret] = {
          secretName: name,
          items: items&.map do |key, path|
            { key: key, path: path }
          end
        }.reject { |_, v| v.nil? }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kubec-0.6.1 lib/kubec/kubernetes/volume.rb
kubec-0.6.0 lib/kubec/kubernetes/volume.rb
kubec-0.5.0 lib/kubec/kubernetes/volume.rb
kubec-0.4.1 lib/kubec/kubernetes/volume.rb
kubec-0.4.0 lib/kubec/kubernetes/volume.rb
kubec-0.3.6 lib/kubec/kubernetes/volume.rb