-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from vitobotta:hetzner-software-installation-…
…refactoring Refactor Kubernetes::Installer to extract software installation into a separate classes
- Loading branch information
Showing
5 changed files
with
108 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/kubernetes/software/hetzner/cloud_controller_manager.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class Kubernetes::Software::Hetzner::CloudControllerManager | ||
getter configuration : Configuration::Loader | ||
getter settings : Configuration::Main { configuration.settings } | ||
|
||
def initialize(@configuration, @settings) | ||
end | ||
|
||
def install | ||
puts "\n[Hetzner Cloud Controller] Installing Hetzner Cloud Controller Manager..." | ||
|
||
response = Crest.get(settings.cloud_controller_manager_manifest_url) | ||
|
||
unless response.success? | ||
puts "Failed to download CCM manifest from #{settings.cloud_controller_manager_manifest_url}" | ||
puts "Server responded with status #{response.status_code}" | ||
exit 1 | ||
end | ||
|
||
ccm_manifest = response.body.to_s.gsub(/--cluster-cidr=[^"]+/, "--cluster-cidr=#{settings.cluster_cidr}") | ||
|
||
command = <<-BASH | ||
kubectl apply -f - <<-EOF | ||
#{ccm_manifest} | ||
EOF | ||
BASH | ||
|
||
result = Util::Shell.run(command, configuration.kubeconfig_path, settings.hetzner_token, prefix: "Hetzner Cloud Controller") | ||
|
||
unless result.success? | ||
puts "Failed to deploy Cloud Controller Manager:" | ||
puts result.output | ||
exit 1 | ||
end | ||
|
||
puts "[Hetzner Cloud Controller] Hetzner Cloud Controller Manager installed" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Kubernetes::Software::Hetzner::CSIDriver | ||
getter configuration : Configuration::Loader | ||
getter settings : Configuration::Main { configuration.settings } | ||
|
||
def initialize(@configuration, @settings) | ||
end | ||
|
||
def install | ||
puts "\n[Hetzner CSI Driver] Installing Hetzner CSI Driver..." | ||
|
||
command = "kubectl apply -f #{settings.csi_driver_manifest_url}" | ||
|
||
result = Util::Shell.run(command, configuration.kubeconfig_path, settings.hetzner_token, prefix: "Hetzner CSI Driver") | ||
|
||
unless result.success? | ||
puts "Failed to deploy CSI Driver:" | ||
puts result.output | ||
exit 1 | ||
end | ||
|
||
puts "[Hetzner CSI Driver] ...CSI Driver installed" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class Kubernetes::Software::Hetzner::Secret | ||
HETZNER_CLOUD_SECRET_MANIFEST = {{ read_file("#{__DIR__}/../../../../templates/hetzner_cloud_secret_manifest.yaml") }} | ||
|
||
getter configuration : Configuration::Loader | ||
getter settings : Configuration::Main { configuration.settings } | ||
|
||
def initialize(@configuration, @settings) | ||
end | ||
|
||
def create | ||
puts "\n[Hetzner Cloud Secret] Creating secret for Hetzner Cloud token..." | ||
|
||
secret_manifest = Crinja.render(HETZNER_CLOUD_SECRET_MANIFEST, { | ||
network: (settings.existing_network || settings.cluster_name), | ||
token: settings.hetzner_token | ||
}) | ||
|
||
command = <<-BASH | ||
kubectl apply -f - <<-EOF | ||
#{secret_manifest} | ||
EOF | ||
BASH | ||
|
||
result = Util::Shell.run(command, configuration.kubeconfig_path, settings.hetzner_token, prefix: "Hetzner Cloud Secret") | ||
|
||
unless result.success? | ||
puts "Failed to create Hetzner Cloud secret:" | ||
puts result.output | ||
exit 1 | ||
end | ||
|
||
puts "[Hetzner Cloud Secret] ...secret created" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters