Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.

Commit 1cfe61d

Browse files
authored
Merge pull request #2 from moandersson/feature/excludedNamespaces
Add feature excludedNamespaces
2 parents 1b411cc + ac21be6 commit 1cfe61d

File tree

11 files changed

+42
-2
lines changed

11 files changed

+42
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [v0.1.1] - 2021-10-19
99

1010
- SelfLink is deprecated and disabled since kubernetes 1.20 [#1](https://github.com/blakelead/nsinjector/pull/1)
11+
- Add support for excludedNamespaces in CRD
1112

1213
## [v0.1.0] - 2020-06-20
1314

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ metadata:
3838
spec:
3939
namespaces:
4040
- dev-.*
41+
excludedNamespaces:
42+
- dev-excluded-.*
4143
resources:
4244
- |
4345
apiVersion: rbac.authorization.k8s.io/v1
@@ -69,6 +71,7 @@ spec:
6971
```
7072
7173
- `namespaces`: a list of namespace names or regex
74+
- `excludedNamespaces`: a list of namespace names or regex to be excluded
7275
- `resources`: a list of any Kubernetes resources
7376

7477
## Contributing

deploy/helm/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: nsinjector-controller
33
description: A Helm chart for Kubernetes
44
type: application
5-
version: 0.1.0
6-
appVersion: v0.1.0
5+
version: 0.1.1
6+
appVersion: v0.1.1

deploy/helm/crds/crd-v1beta1.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ spec:
2828
type: array
2929
items:
3030
type: string
31+
excludedNamespaces:
32+
description: 'Namespaces is a list of namespaces names or regex that will be excluded to be injected.'
33+
type: array
34+
items:
35+
type: string
3136
resources:
3237
description: 'Resources is the map of resources to be injected.'
3338
type: array

deploy/helm/templates/namespaceresourcesinjector.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ spec:
99
- |-
1010
{{ . | indent 4 }}
1111
{{- end }}
12+
excludedNamespaces:
13+
{{- range $injector.excludedNamespaces }}
14+
- |-
15+
{{ . | indent 4 }}
1216
resources:
1317
{{- range $injector.resources }}
1418
- |-

deploy/helm/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ injectors:
1616
- name: injector1
1717
namespaces:
1818
- dev-*
19+
excludedNamespaces:
20+
- dev-exclude-.*
1921
resources:
2022
- |
2123
apiVersion: rbac.authorization.k8s.io/v1
@@ -45,6 +47,8 @@ injectors:
4547
- name: injector2
4648
namespaces:
4749
- stg-*
50+
excludedNamespaces:
51+
- stg-excluded-.*
4852
resources:
4953
- |
5054
apiVersion: rbac.authorization.k8s.io/v1

deploy/k8s/crd/namespaceresourcesinjector-crd-1.16.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ spec:
2727
type: array
2828
items:
2929
type: string
30+
excludedNamespaces:
31+
description: 'Namespaces is a list of namespaces names or regex that will be excluded to be injected.'
32+
type: array
33+
items:
34+
type: string
3035
resources:
3136
description: 'Resources is the map of resources to be injected.'
3237
type: array

deploy/k8s/crd/namespaceresourcesinjector-crd.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ spec:
2828
type: array
2929
items:
3030
type: string
31+
excludedNamespaces:
32+
description: 'Namespaces is a list of namespaces names or regex that will be excluded to be injected.'
33+
type: array
34+
items:
35+
type: string
3136
resources:
3237
description: 'Resources is the map of resources to be injected.'
3338
type: array

deploy/k8s/namespaceresourcesinjector.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ metadata:
55
spec:
66
namespaces:
77
- dev-.*
8+
excludedNamespaces:
9+
- dev-excluded.*
810
resources:
911
- |
1012
apiVersion: rbac.authorization.k8s.io/v1

pkg/apis/namespaceresourcesinjector/v1alpha1/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ type NamespaceResourcesInjector struct {
2121
}
2222

2323
func (nri *NamespaceResourcesInjector) CanInject(namespace string) bool {
24+
for _, item := range nri.Spec.ExcludedNamespaces {
25+
if match, _ := regexp.MatchString(item, namespace); match {
26+
return false
27+
}
28+
}
2429
for _, item := range nri.Spec.Namespaces {
2530
if match, _ := regexp.MatchString(item, namespace); match {
2631
return true
@@ -40,6 +45,7 @@ func (nri *NamespaceResourcesInjector) Injected(namespace string) bool {
4045

4146
// NamespaceResourcesInjectorSpec is the spec for a NamespaceResourcesInjector resource
4247
type NamespaceResourcesInjectorSpec struct {
48+
ExcludedNamespaces []string `json:"excludedNamespaces"`
4349
Namespaces []string `json:"namespaces"`
4450
Resources []string `json:"resources"`
4551
}

0 commit comments

Comments
 (0)