13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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/volume_sweeper/core.rb', line 13
def self.process
opts = VolumeSweeper::Cli.run
cloud = opts.cloud
mode = opts.mode&.to_sym
options = {
config_path: opts.config_path,
account_id: opts.account_id,
region: opts.region,
mode: opts.mode,
kube_api_url: opts.kube_api_url,
kube_api_ca_path: opts.kube_api_ca_path,
kube_api_token: opts.kube_api_token,
notification_subject: opts.notification_subject,
smtp_host: opts.smtp_host,
smtp_port: opts.smtp_port,
smtp_username: opts.smtp_username,
smtp_password: opts.smtp_password,
smtp_tls: opts.smtp_tls,
smtp_sender: opts.smtp_sender,
smtp_receiver: opts.smtp_receiver,
ms_teams_webhook: opts.ms_teams_webhook
}
unless cloud.nil? || %w{oci aws}.include?(cloud)
Utils::Log.instance.msg "No could provider is chosen", level: :fatal
exit
end
klass = cloud.capitalize
provider = "VolumeSweeper::Providers::#{klass}".constantize.new **options
active_count, block_vols = provider.scan_block_volumes
block_vols.map! { |v| v[:id] }
kube_client = VolumeSweeper::Kube::Client.new **options
cluster_vols = kube_client.fetch_pesistent_volumes
notifier = VolumeSweeper::Utils::Notification.new **options
formatter = VolumeSweeper::Utils::NotificationFormatter.new provider.base_link, mode
results = Comparer.process block_vols, cluster_vols
message = formatter.formlate_meessage results, active_count: active_count
notifier.send_ms_teams_notice message
notifier.send_mail message if results[:unused_ids]&.any?
provider.delete_block_volumes results[:unused_ids]
sleep 30
VolumeSweeper::Utils::Log.instance.msg "Done !"
end
|