Commit a99e7c87 authored by Matt Kasa's avatar Matt Kasa

Add Kubernetes TlsSecret

Relates to https://gitlab.com/gitlab-org/gitlab/issues/33559
parent b84eb951
# frozen_string_literal: true
module Gitlab
module Kubernetes
class TlsSecret
attr_reader :name, :cert, :key, :namespace_name
def initialize(name, cert, key, namespace_name)
@name = name
@cert = cert
@key = key
@namespace_name = namespace_name
end
def generate
::Kubeclient::Resource.new(
type: tls_secret_type,
metadata: metadata,
data: data
)
end
private
def tls_secret_type
'kubernetes.io/tls'
end
def metadata
{
name: name,
namespace: namespace_name
}
end
def data
{
'tls.crt': Base64.strict_encode64(cert),
'tls.key': Base64.strict_encode64(key)
}
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Kubernetes::TlsSecret do
let(:secret) { described_class.new(name, cert, key, namespace) }
let(:name) { 'example-name' }
let(:cert) { 'example-cert' }
let(:key) { 'example-key' }
let(:namespace) { 'example-namespace' }
let(:data) do
{
'tls.crt': Base64.strict_encode64(cert),
'tls.key': Base64.strict_encode64(key)
}
end
describe '#generate' do
subject { secret.generate }
let(:resource) do
::Kubeclient::Resource.new(
type: 'kubernetes.io/tls',
metadata: { name: name, namespace: namespace },
data: data
)
end
it { is_expected.to eq(resource) }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment