Class: HubClustersCreator::Providers::AKS

Inherits:
Object
  • Object
show all
Includes:
Azure::ContainerService::Mgmt::V2019_04_01, Azure::Dns::Mgmt::V2017_10_01, Azure::Resources::Profiles::Latest::Mgmt, Azure::Resources::Profiles::Latest::Mgmt::Models, Errors, Logging, HubClustersCreator::Providers::Azure::Helpers, Utils::Template
Defined in:
lib/hub-clusters-creator/providers/aks/azure.rb

Overview

AKS is the AKS provider

Instance Method Summary collapse

Methods included from Logging

#error, #info, #warn

Constructor Details

#initialize(provider) ⇒ AKS

rubocop:disable Metrics/AbcSize



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/hub-clusters-creator/providers/aks/azure.rb', line 42

def initialize(provider)
  %i[client_id client_secret region subscription tenant].each do |x|
    raise ArgumentError, "you must specify the '#{x}' provider option" unless provider.key?(x)
  end

  @subscription = provider[:subscription]
  @tenant = provider[:tenant]
  @client_id = provider[:client_id]
  @client_secret = provider[:client_secret]
  @region = provider[:region]

  @provider = MsRestAzure::ApplicationTokenProvider.new(@tenant, @client_id, @client_secret)
  @credentials = MsRest::TokenCredentials.new(@provider)

  @containers = ::Azure::ContainerService::Mgmt::V2019_04_01::ContainerServiceClient.new(@credentials)
  @containers.subscription_id = @subscription

  @dns = ::Azure::Dns::Mgmt::V2017_10_01::DnsManagementClient.new(@credentials)
  @dns.subscription_id = @subscription

  options = {
    client_id: @client_id,
    client_secret: @client_secret,
    credentials: @credentials,
    subscription_id: @subscription,
    tenant_id: @tenant
  }

  @client = Client.new(options)
end

Instance Method Details

#create(name, config) ⇒ Object

create is responsible for creating the cluster



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/hub-clusters-creator/providers/aks/azure.rb', line 75

def create(name, config)
  # @step: validate the user defined options
  validate(config)

  # @step: create the infrastructure deployment
  begin
    provision_aks(name, config)
  rescue StandardError => e
    raise InfrastructureError, "failed to provision cluster, error: #{e}"
  end

  # @step: bootstrap the cluster
  begin
    provision_cluster(name, config)
  rescue StandardError => e
    raise InfrastructureError, "failed to bootstrap cluster, error: #{e}"
  end
end

#delete(name) ⇒ Object

delete is responsible for deleting the cluster via resource group



95
96
97
98
99
100
# File 'lib/hub-clusters-creator/providers/aks/azure.rb', line 95

def delete(name)
  return unless resource_group?(name)

  info "deleting the resource group: #{name}"
  @client.resource_groups.delete(name, name)
end