Class: Kdep::OldFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/kdep/old_format.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ OldFormat

Returns a new instance of OldFormat.



5
6
7
# File 'lib/kdep/old_format.rb', line 5

def initialize(path)
  @path = path
end

Instance Method Details

#app_nameObject



9
10
11
12
13
# File 'lib/kdep/old_format.rb', line 9

def app_name
  name_file = File.join(@path, ".app-name")
  raise "Missing .app-name file in #{@path}" unless File.exist?(name_file)
  File.read(name_file).strip
end

#configObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/kdep/old_format.rb', line 15

def config
  config_file = File.join(@path, "app.yml")
  raise "Missing app.yml in #{@path}" unless File.exist?(config_file)
  content = File.read(config_file)
  if RUBY_VERSION >= "3.1"
    YAML.safe_load(content, permitted_classes: [], permitted_symbols: [], aliases: false) || {}
  else
    YAML.safe_load(content, [], [], false) || {}
  end
end

#materialized_dirObject



32
33
34
35
36
37
38
39
# File 'lib/kdep/old_format.rb', line 32

def materialized_dir
  dir = File.join(@path, "materialized")
  return dir if File.directory?(dir)
  # Fallback to .rendered/ directory
  dir = File.join(@path, ".rendered")
  return dir if File.directory?(dir)
  nil
end

#materialized_filesObject



26
27
28
29
30
# File 'lib/kdep/old_format.rb', line 26

def materialized_files
  mat_dir = materialized_dir
  return [] unless mat_dir && File.directory?(mat_dir)
  Dir.glob(File.join(mat_dir, "*.yml")).sort
end

#to_kdep_configObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kdep/old_format.rb', line 41

def to_kdep_config
  old = config
  result = {}
  %w[preset namespace name image registry context port replicas
     command target env env_from resources probe domains
     image_pull_secrets schedule].each do |key|
    result[key] = old[key] if old.key?(key)
  end
  # Ensure name from .app-name if not in config
  result["name"] ||= app_name
  # Ensure image defaults to name
  result["image"] ||= result["name"]
  result
end