Skip to content

Commit

Permalink
Check s3 ready
Browse files Browse the repository at this point in the history
  • Loading branch information
malvads committed Jun 11, 2024
1 parent 6a3a6c6 commit f115ab6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 14 additions & 0 deletions resources/libraries/minio_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,19 @@ def self.check_remote_hosts(hosts)
end
all_alive
end

def self.s3_ready?
command_output = `serf members list`

nodes = command_output.split("\n")
leader_node = nodes.find { |node| node.include?('leader=ready') }

if leader_node
s3_tag = leader_node[/s3=([a-zA-Z0-9_-]+)/, 1]
return s3_tag == 'ready'
else
return false
end
end
end
end
7 changes: 1 addition & 6 deletions resources/providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
user = new_resource.user
s3_bucket = new_resource.s3_bucket
s3_endpoint = new_resource.s3_endpoint
s3_databag = Chef::DataBagItem.load('passwords','s3_secrets') rescue nil
im_solo = false

if s3_databag.nil?
if !Minio::Helpers.s3_ready?
s3_user = Minio::Helpers.generate_random_key(20)
s3_password = Minio::Helpers.generate_random_key(40)
im_solo = true
else
s3_user = new_resource.access_key_id
s3_password = new_resource.secret_key_id
Expand Down Expand Up @@ -60,7 +57,6 @@
s3_bucket: s3_bucket,
s3_endpoint: s3_endpoint
)
only_if { im_solo }
end

template '/root/.s3cfg_initial' do
Expand All @@ -70,7 +66,6 @@
s3_password: s3_password,
s3_endpoint: s3_endpoint
)
only_if { im_solo }
end

Chef::Log.info('Minio cookbook has been processed')
Expand Down

0 comments on commit f115ab6

Please sign in to comment.