Sha256: ffee2d1a55c709214afb328a61510ea24eac2f5e28638813eb20a24db2f11587

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

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

      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
        }.compact
        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

2 entries across 2 versions & 1 rubygems

Version Path
kubec-0.3.1 lib/kubec/kubernetes/container.rb
kubec-0.3.0 lib/kubec/kubernetes/container.rb