BigW Consortium Gitlab

namespace.rb 558 Bytes
Newer Older
1 2 3 4 5 6
module Gitlab
  module Kubernetes
    class Namespace
      attr_accessor :name

      def initialize(name, client)
7
        @name = name
8 9 10 11 12 13 14
        @client = client
      end

      def exists?
        @client.get_namespace(name)
      rescue ::KubeException => ke
        raise ke unless ke.error_code == 404
15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
        false
      end

      def create!
        resource = ::Kubeclient::Resource.new(metadata: { name: name })

        @client.create_namespace(resource)
      end

      def ensure_exists!
        exists? || create!
      end
    end
  end
end