Skip to content

Commit 39d59f1

Browse files
author
Debakel Orakel
committed
Support creating simple NetworkPolicies
1 parent a8d8615 commit 39d59f1

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
lines changed

component/standalone.jsonnet

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ local route(instance) = if std.get(params.instances[instance], 'url', '') != ''
9898
namespace: namespacedName(instance).namespace,
9999
},
100100
spec: {
101-
rules: [{
101+
rules: [ {
102102
host: params.instances[instance].url,
103103
http: {
104-
paths: [{
104+
paths: [ {
105105
backend: {
106106
service: {
107107
name: 'splunk-%s-standalone-service' % namespacedName(instance).name,
@@ -112,14 +112,41 @@ local route(instance) = if std.get(params.instances[instance], 'url', '') != ''
112112
},
113113
path: '/',
114114
pathType: 'Prefix',
115-
}],
115+
} ],
116116
},
117-
}],
117+
} ],
118118
// tls: [{
119119
// hosts: [ 'splunk-traffic-vshn-tdr-infra-prod.apps.ocp4.acrevison.ch' ],
120120
// secretName: '%s-tls' % namespacedName(instance).name,
121121
// }]
122-
}
122+
},
123+
};
124+
125+
local netpol(instance) = if std.get(params.instances[instance], 'allowFrom', []) != [] then {
126+
apiVersion: 'networking.k8s.io/v1',
127+
kind: 'NetworkPolicy',
128+
metadata: {
129+
annotations: utils.commonAnnotations,
130+
labels: utils.commonLabelsWithInstance(namespacedName(instance).name),
131+
name: 'splunk-standalone-%s' % namespacedName(instance).name,
132+
namespace: namespacedName(instance).namespace,
133+
},
134+
spec: {
135+
podSelector: {},
136+
policyTypes: [ 'Ingress' ],
137+
ingress: [
138+
{
139+
from: [ {
140+
namespaceSelector: {
141+
matchLabels: {
142+
'kubernetes.io/metadata.name': namespace,
143+
},
144+
},
145+
} ],
146+
}
147+
for namespace in params.instances[instance].allowFrom
148+
],
149+
},
123150
};
124151

125152
// RABC
@@ -179,6 +206,7 @@ local namespace(instance) = if std.get(params.instances[instance], 'createNamesp
179206
namespace(instance),
180207
standalone(instance),
181208
route(instance),
209+
netpol(instance),
182210
serviceAccount(instance),
183211
roleBinding(instance),
184212
] + appConfigs(instance))

docs/modules/ROOT/pages/references/parameters.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ splunk_operator:
112112

113113
Creates the `Namespace` for the Splunk instance.
114114

115+
=== `instances.{}.allowFrom`
116+
117+
[horizontal]
118+
type:: list
119+
default:: []
120+
example::
121+
+
122+
[source]
123+
----
124+
splunk_operator:
125+
instances:
126+
my-namespace/my-instance:
127+
allowFrom:
128+
- openshift-logging
129+
----
130+
131+
Creates a `NetworkPolicy` allowing ingress from listed namespaces.
132+
115133
=== `instances.{}.url`
116134

117135
[horizontal]

tests/forwarder.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ parameters:
1414
instances:
1515
test1/heavyforwarder:
1616
createNamespace: true
17+
allowFrom:
18+
- openshift-logging
1719
url: my-splunk.example.com
1820
standalone:
1921
serviceAccount: splunk-forwarder

tests/golden/forwarder/splunk-operator/splunk-operator/50_instance_test1_heavyforwarder.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ spec:
5151
path: /
5252
pathType: Prefix
5353
---
54+
apiVersion: networking.k8s.io/v1
55+
kind: NetworkPolicy
56+
metadata:
57+
annotations:
58+
syn.tools/source: https://github.com/projectsyn/component-splunk-operator.git
59+
labels:
60+
app.kubernetes.io/component: splunk
61+
app.kubernetes.io/instance: heavyforwarder
62+
app.kubernetes.io/managed-by: commodore
63+
app.kubernetes.io/part-of: syn
64+
name: splunk-standalone-heavyforwarder
65+
namespace: test1
66+
spec:
67+
ingress:
68+
- from:
69+
- namespaceSelector:
70+
matchLabels:
71+
kubernetes.io/metadata.name: openshift-logging
72+
podSelector: {}
73+
policyTypes:
74+
- Ingress
75+
---
5476
apiVersion: v1
5577
kind: ServiceAccount
5678
metadata:

0 commit comments

Comments
 (0)