Sha256: e23f20d5cc5aad9872c41e03071acc21679663b755a54ed00de3600839e64876

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module Kubec
  class Kubernetes
    # :nodoc:
    class Container < Hash
      include HasAttribute
      attribute :image
      attribute :name
      attribute :ports

      def initialize(name, &block)
        self[:name] = name
        instance_eval(&block)
      end

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

      def env(key, value)
        self[:env] ||= []
        self[:env].push name: key,
                        value: value.to_s
      end

      def mount(name, at:)
        self[:volumeMounts] ||= []
        self[:volumeMounts].push name: name,
                                 mountPath: at
      end

      # TODO: Auto setup config map volume
      def config_file(name, path:, from:)
        self[:volumeMounts] ||= []
        self[:volumeMounts].push name: from,
                                 mountPath: [path, name].join('/'),
                                 subPath: name
      end

      # TODO: Add object to check fields
      def port(container_port, host_port = nil,
               ip: nil, name: nil, protocol: nil)
        self[:ports] ||= []
        port = {
          containerPort: container_port,
          hostPort: host_port,
          hostIP: ip,
          name: name,
          protocol: protocol
        }.reject { |_, v| v.nil? }
        self[:ports].push port
      end

      def command(*args)
        args = args.flatten
        self[:command] = args.take(1)
        self[:args] = args.drop(1)
      end

      def args(*args)
        self[:args] = args.flatten
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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