Sha256: e0dc1c59f0a9bf2bd3bd4469c8a4de27ded064f155afbf838c2316d1ebe00639

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 KB

Contents

# typed: true

require 'kube-dsl'

module Kuby
  module Plugins
    class NginxIngress < ::Kuby::Plugin
      depends_on :kubernetes, '>= 1.20'

      class Config
        extend ::KubeDSL::ValueFields

        value_fields :provider
      end

      VERSION = '1.1.1'.freeze
      DEFAULT_PROVIDER = 'cloud'.freeze
      NAMESPACE = 'ingress-nginx'.freeze
      SERVICE_NAME = 'ingress-nginx-controller'.freeze

      SETUP_RESOURCES = [
        "https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v#{VERSION}/deploy/static/provider/%{provider}/deploy.yaml"
      ].freeze

      def configure(&block)
        @config.instance_eval(&block) if block
      end

      def setup
        Kuby.logger.info('Deploying nginx ingress resources')

        if already_deployed?
          Kuby.logger.info('Nginx ingress already deployed, skipping')
          return
        end

        SETUP_RESOURCES.each do |uri|
          uri = uri % { provider: @config.provider || DEFAULT_PROVIDER }
          kubernetes_cli.apply_uri(uri)
        end

        Kuby.logger.info('Nginx ingress resources deployed!')
      rescue => e
        Kuby.logger.fatal(e.message)
        raise
      end

      def namespace
        NAMESPACE
      end

      def service_name
        SERVICE_NAME
      end

      private

      def already_deployed?
        kubernetes_cli.get_object('Service', NAMESPACE, SERVICE_NAME)
        true
      rescue KubernetesCLI::GetResourceError
        return false
      end

      def after_initialize
        @config = Config.new
      end

      def kubernetes_cli
        environment.kubernetes.provider.kubernetes_cli
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kuby-core-0.20.2 lib/kuby/plugins/nginx_ingress.rb
kuby-core-0.20.1 lib/kuby/plugins/nginx_ingress.rb
kuby-core-0.20.0 lib/kuby/plugins/nginx_ingress.rb
kuby-core-0.19.0 lib/kuby/plugins/nginx_ingress.rb
kuby-core-0.18.0 lib/kuby/plugins/nginx_ingress.rb