-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
manifest_install: Move manifest install to repo
Move installation methods enum from helm repo Move Manifest-related functionality from helm repo Refs: #2105 Signed-off-by: Konstantin Yarovoy <[email protected]>
- Loading branch information
Konstantin Yarovoy
committed
Jul 18, 2024
1 parent
7f8c910
commit 3e4001c
Showing
8 changed files
with
125 additions
and
67 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
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
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,29 @@ | ||
module CNFInstall | ||
enum InstallMethod | ||
HelmChart | ||
HelmDirectory | ||
ManifestDirectory | ||
Invalid | ||
end | ||
|
||
def self.install_method_by_config_src(config_src : String) : InstallMethod | ||
Log.info { "install_method_by_config_src" } | ||
Log.info { "config_src: #{config_src}" } | ||
helm_chart_file = "#{config_src}/#{Helm::CHART_YAML}" | ||
Log.info { "looking for potential helm_chart_file: #{helm_chart_file}: file exists?: #{File.exists?(helm_chart_file)}" } | ||
|
||
if !Dir.exists?(config_src) | ||
Log.info { "install_method_by_config_src helm_chart selected" } | ||
InstallMethod::HelmChart | ||
elsif File.exists?(helm_chart_file) | ||
Log.info { "install_method_by_config_src helm_directory selected" } | ||
InstallMethod::HelmDirectory | ||
elsif Dir.exists?(config_src) | ||
Log.info { "install_method_by_config_src manifest_directory selected" } | ||
InstallMethod::ManifestDirectory | ||
else | ||
puts "Error: #{config_src} is neither a helm_chart, helm_directory, or manifest_directory.".colorize(:red) | ||
exit 1 | ||
end | ||
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,51 @@ | ||
module CNFInstall | ||
module Manifest | ||
def self.parse_manifest_as_ymls(template_file_name="cnfs/temp_template.yml") | ||
Log.info { "parse_manifest_as_ymls template_file_name: #{template_file_name}" } | ||
templates = File.read(template_file_name) | ||
split_template = templates.split(/(\s|^)---(\s|$)/) | ||
ymls = split_template.map { | template | | ||
#TODO strip out NOTES | ||
YAML.parse(template) | ||
# compact seems to have problems with yaml::any | ||
}.reject{|x|x==nil} | ||
Log.debug { "read_template ymls: #{ymls}" } | ||
ymls | ||
end | ||
|
||
def self.manifest_ymls_from_file_list(manifest_file_list) | ||
ymls = manifest_file_list.map do |x| | ||
parse_manifest_as_ymls(x) | ||
end | ||
ymls.flatten | ||
end | ||
|
||
def self.manifest_file_list(manifest_directory, silent=false) | ||
Log.info { "manifest_file_list" } | ||
Log.info { "manifest_directory: #{manifest_directory}" } | ||
if manifest_directory && !manifest_directory.empty? && manifest_directory != "/" | ||
cmd = "find #{manifest_directory}/ -name \"*.yml\" -o -name \"*.yaml\"" | ||
Log.info { cmd } | ||
Process.run( | ||
cmd, | ||
shell: true, | ||
output: find_resp = IO::Memory.new, | ||
error: find_err = IO::Memory.new | ||
) | ||
manifests = find_resp.to_s.split("\n").select{|x| x.empty? == false} | ||
Log.info { "find response: #{manifests}" } | ||
if manifests.size == 0 && !silent | ||
raise "No manifest ymls found in the #{manifest_directory} directory!" | ||
end | ||
manifests | ||
else | ||
[] of String | ||
end | ||
end | ||
|
||
def self.manifest_containers(manifest_yml) | ||
Log.debug { "manifest_containers: #{manifest_yml}" } | ||
manifest_yml.dig?("spec", "template", "spec", "containers") | ||
end | ||
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
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
Oops, something went wrong.