Puppet Class: kubecm::deploy

Defined in:
manifests/deploy.pp

Summary

Puppet entrypoint for the kubecm::deploy plan

Overview

This defines the following variables for use in your Hiera hierarchy and data, and declares other classes for your own custom variables.

* kubecm::deploy::release
* kubecm::deploy::chart
* kubecm::deploy::chart_source
* kubecm::deploy::namespace
* kubecm::deploy::parent
* kubecm::deploy::version

Parameters:

  • include_key (String)

    Hiera key mapping a list of custom classes to declare

  • resources_key (String)

    Hiera key mapping a hash of resources to deploy

  • values_key (String)

    Hiera key mapping a hash of values to apply to the chart

  • patches_key (String)

    Hiera key mapping a hash of Kustomize patches to apply, ordered by key.

  • release_build_dir (Stdlib::Absolutepath)

    Deployment-specific place to compile manifests. Will be purged!

  • remove_resources (Array[String]) (defaults to: [])

    Resource keys to remove from deployment

  • remove_patches (Array[String]) (defaults to: [])

    Patch keys to remove from kustomization

  • subchart_manifests (Array[String]) (defaults to: [])

    List of already-generated subchart manifests to deploy



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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'manifests/deploy.pp', line 22

class kubecm::deploy (
  String               $include_key,
  String               $resources_key,
  String               $values_key,
  String               $patches_key,
  Stdlib::Absolutepath $release_build_dir,
  Array[String]        $remove_resources   = [],
  Array[String]        $remove_patches     = [],
  Array[String]        $subchart_manifests = [],
) {
  # Bring plan variables into class scope for lookups
  # (class parameters can't be used in lookups until after it's fully loaded)
  # lint:ignore:top_scope_facts
  $release      = $::release
  $chart        = $::chart
  $chart_source = $::chart_source
  $namespace    = pick_default($::namespace, 'default')
  $parent       = $::parent
  $version      = $::version
  # lint:endignore

  # Include custom classes that define other variables for lookups
  lookup($include_key, Array[String], 'unique', []).reverse.include

  # Perform a second lookup since the first can change the hierarchy
  lookup($include_key, Array[String], 'unique', []).reverse.include

  $resources = lookup($resources_key, Hash, 'hash', {}) - $remove_resources
  $values    = lookup($values_key, Hash, 'deep', {})
  $patches   = lookup($patches_key, Hash, 'hash', {}) - $remove_patches

  file {
    $release_build_dir:
      ensure  => directory,
      purge   => true, # clean out old files
      recurse => true; # recursively

    $subchart_manifests.map |$manifest| { "${release_build_dir}/${manifest}" }:
      ensure => present;  # don't purge subcharts

    "${release_build_dir}/helm.yaml":
      ensure => present;  # don't purge helm manifest (it will be overwritten)

    "${release_build_dir}/resources.yaml":
      content => $resources.values.flatten.map |$r| { if $r.empty { '' } else { $r.stdlib::to_yaml } }.join;

    "${release_build_dir}/values.yaml":
      content => $values.stdlib::to_yaml;

    "${release_build_dir}/kustomization.yaml":
      content => {
        'resources' => $subchart_manifests + ['resources.yaml', 'helm.yaml'],
        'patches'   => $patches.keys.sort.map |$k| { $patches[$k] }.flatten.map |$p| {
          if $p['patch'] =~ String {
            $p
          } else {
            $p + { 'patch' => $p['patch'].stdlib::to_yaml }
          }
        },
      }.stdlib::to_yaml;

    "${release_build_dir}/kustomize.sh":
      mode   => '0755',
      source => 'puppet:///modules/kubecm/kustomize.sh';
  }

  if !$chart_source {
    if $version {
      $fake_chart_version = $version
    } else {
      $fake_chart_version = '0.1.0' # just something
    }

    file {
      "${release_build_dir}/chart":
        ensure  => directory;

      "${release_build_dir}/chart/Chart.yaml":
        content => {
          'apiVersion'  => 'v2',
          'name'        => $chart,
          'description' => 'KubeCM deployment',
          'type'        => 'application',
          'version'     => $fake_chart_version,
        }.stdlib::to_yaml;
    }
  } elsif $chart_source =~ Stdlib::Filesource {
    file { "${release_build_dir}/chart":
      ensure  => directory,
      recurse => true,
      source  => $chart_source,
    }
  }
}