Method: KubernetesCLI#apply

Defined in:
lib/kubernetes-cli.rb

#apply(res, dry_run: false) ⇒ Object

T::Sig::WithoutRuntime.sig { params(res: ::KubeDSL::DSLObject, dry_run: T::Boolean).void }


163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/kubernetes-cli.rb', line 163

def apply(res, dry_run: false)
  cmd = [executable, '--kubeconfig', kubeconfig_path, 'apply', '--validate']
  cmd << '--dry-run=client' if dry_run
  cmd += ['-f', '-']

  open3_w(env, cmd) do |stdin|
    stdin.puts(res.to_resource.to_yaml)
  end

  on_last_status_failure do |last_status|
    err = InvalidResourceError.new("Could not apply #{res.kind_sym} "\
      "'#{res..name}': kubectl exited with status code #{last_status.exitstatus}"
    )

    err.resource = res
    raise err
  end
end