Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2020-12-28 15:10:10 +00:00
parent e131979e83
commit 52e04ab29a
5 changed files with 54 additions and 7 deletions

View file

@ -0,0 +1,5 @@
---
title: Adds annotations as part of metadata for CiliumNetworkPolicies wrapper
merge_request: 50586
author:
type: changed

View file

@ -12,7 +12,7 @@ module Gitlab
# We are modeling existing kubernetes resource and don't have
# control over amount of parameters.
# rubocop:disable Metrics/ParameterLists
def initialize(name:, namespace:, selector:, ingress:, resource_version: nil, description: nil, labels: nil, creation_timestamp: nil, egress: nil)
def initialize(name:, namespace:, selector:, ingress:, resource_version: nil, description: nil, labels: nil, creation_timestamp: nil, egress: nil, annotations: nil)
@name = name
@description = description
@namespace = namespace
@ -22,6 +22,7 @@ module Gitlab
@resource_version = resource_version
@ingress = ingress
@egress = egress
@annotations = annotations
end
# rubocop:enable Metrics/ParameterLists
@ -37,6 +38,7 @@ module Gitlab
name: metadata[:name],
description: policy[:description],
namespace: metadata[:namespace],
annotations: metadata[:annotations],
resource_version: metadata[:resourceVersion],
labels: metadata[:labels],
selector: spec[:endpointSelector],
@ -57,6 +59,7 @@ module Gitlab
name: metadata[:name],
description: resource[:description],
namespace: metadata[:namespace],
annotations: metadata[:annotations]&.to_h,
resource_version: metadata[:resourceVersion],
labels: metadata[:labels]&.to_h,
creation_timestamp: metadata[:creationTimestamp],
@ -80,7 +83,7 @@ module Gitlab
private
attr_reader :name, :description, :namespace, :labels, :creation_timestamp, :resource_version, :ingress, :egress
attr_reader :name, :description, :namespace, :labels, :creation_timestamp, :resource_version, :ingress, :egress, :annotations
def selector
@selector ||= {}
@ -90,6 +93,7 @@ module Gitlab
meta = { name: name, namespace: namespace }
meta[:labels] = labels if labels
meta[:resourceVersion] = resource_version if resource_version
meta[:annotations] = annotations if annotations
meta
end

View file

@ -9,6 +9,7 @@ module Gitlab
production: "58dc0f06-936c-43b3-93bb-71693f1b6570"
}.freeze
UUID_V5_PATTERN = /\h{8}-\h{4}-5\h{3}-\h{4}-\h{4}\h{8}/.freeze
NAMESPACE_REGEX = /(\h{8})-(\h{4})-(\h{4})-(\h{4})-(\h{4})(\h{8})/.freeze
PACK_PATTERN = "NnnnnN".freeze
@ -17,6 +18,10 @@ module Gitlab
Digest::UUID.uuid_v5(namespace_id, name)
end
def v5?(string)
string.match(UUID_V5_PATTERN).present?
end
private
def default_namespace_id

View file

@ -12,7 +12,8 @@ RSpec.describe Gitlab::Kubernetes::CiliumNetworkPolicy do
ingress: ingress,
egress: egress,
labels: labels,
resource_version: resource_version
resource_version: resource_version,
annotations: annotations
)
end
@ -20,7 +21,7 @@ RSpec.describe Gitlab::Kubernetes::CiliumNetworkPolicy do
::Kubeclient::Resource.new(
apiVersion: Gitlab::Kubernetes::CiliumNetworkPolicy::API_VERSION,
kind: Gitlab::Kubernetes::CiliumNetworkPolicy::KIND,
metadata: { name: name, namespace: namespace, resourceVersion: resource_version },
metadata: { name: name, namespace: namespace, resourceVersion: resource_version, annotations: annotations },
spec: { endpointSelector: endpoint_selector, ingress: ingress, egress: egress },
description: description
)
@ -34,6 +35,7 @@ RSpec.describe Gitlab::Kubernetes::CiliumNetworkPolicy do
let(:description) { 'example-description' }
let(:partial_class_name) { described_class.name.split('::').last }
let(:resource_version) { 101 }
let(:annotations) { { 'app.gitlab.com/alert': 'true' } }
let(:ingress) do
[
{
@ -64,6 +66,8 @@ RSpec.describe Gitlab::Kubernetes::CiliumNetworkPolicy do
name: example-name
namespace: example-namespace
resourceVersion: 101
annotations:
app.gitlab.com/alert: "true"
spec:
endpointSelector:
matchLabels:
@ -157,7 +161,7 @@ RSpec.describe Gitlab::Kubernetes::CiliumNetworkPolicy do
description: description,
metadata: {
name: name, namespace: namespace, creationTimestamp: '2020-04-14T00:08:30Z',
labels: { app: 'foo' }, resourceVersion: resource_version
labels: { app: 'foo' }, resourceVersion: resource_version, annotations: annotations
},
spec: { endpointSelector: endpoint_selector, ingress: ingress, egress: nil, labels: nil }
)
@ -168,7 +172,7 @@ RSpec.describe Gitlab::Kubernetes::CiliumNetworkPolicy do
apiVersion: Gitlab::Kubernetes::CiliumNetworkPolicy::API_VERSION,
kind: Gitlab::Kubernetes::CiliumNetworkPolicy::KIND,
description: description,
metadata: { name: name, namespace: namespace, resourceVersion: resource_version, labels: { app: 'foo' } },
metadata: { name: name, namespace: namespace, resourceVersion: resource_version, labels: { app: 'foo' }, annotations: annotations },
spec: { endpointSelector: endpoint_selector, ingress: ingress }
)
end
@ -211,7 +215,7 @@ RSpec.describe Gitlab::Kubernetes::CiliumNetworkPolicy do
{
apiVersion: Gitlab::Kubernetes::CiliumNetworkPolicy::API_VERSION,
kind: Gitlab::Kubernetes::CiliumNetworkPolicy::KIND,
metadata: { name: name, namespace: namespace, resourceVersion: resource_version },
metadata: { name: name, namespace: namespace, resourceVersion: resource_version, annotations: annotations },
spec: { endpointSelector: endpoint_selector, ingress: ingress, egress: egress },
description: description
}
@ -248,5 +252,15 @@ RSpec.describe Gitlab::Kubernetes::CiliumNetworkPolicy do
it { is_expected.to eq(resource) }
end
context 'without annotations' do
let(:annotations) { nil }
before do
resource[:metadata].delete(:annotations)
end
it { is_expected.to eq(resource) }
end
end
end

View file

@ -49,4 +49,23 @@ RSpec.describe Gitlab::UUID do
it { is_expected.to eq(production_proper_uuid) }
end
end
describe 'v5?' do
using RSpec::Parameterized::TableSyntax
where(:test_string, :is_uuid_v5) do
'not even a uuid' | false
'this-seems-like-a-uuid' | false
'thislook-more-5lik-eava-liduuidbutno' | false
'9f470438-db0f-37b7-9ca9-1d47104c339a' | false
'9f470438-db0f-47b7-9ca9-1d47104c339a' | false
'9f470438-db0f-57b7-9ca9-1d47104c339a' | true
end
with_them do
subject { described_class.v5?(test_string) }
it { is_expected.to be(is_uuid_v5) }
end
end
end