addes support for matchExpressions
This commit is contained in:
parent
8c229f7a93
commit
852833764c
@ -54,10 +54,17 @@ type Network struct {
|
|||||||
Ports []Port `yaml:"ports,omitempty" validate:"dive,required"`
|
Ports []Port `yaml:"ports,omitempty" validate:"dive,required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MatchExpression struct {
|
||||||
|
Key string `json:"key" yaml:"key" validate:"required"`
|
||||||
|
Operator string `json:"operator" yaml:"operator" validate:"oneof=In NotIn Exists DoesNotExist"`
|
||||||
|
Values []string `json:"values" yaml:"values"`
|
||||||
|
}
|
||||||
|
|
||||||
type Application struct {
|
type Application struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
Ports []Port `yaml:"ports,omitempty"`
|
Ports []Port `yaml:"ports,omitempty"`
|
||||||
MatchLabels map[string]string `yaml:"matchLabels"`
|
MatchLabels map[string]string `yaml:"matchLabels"`
|
||||||
|
MatchExpressions []MatchExpression `yaml:"matchExpressions" validate:"omitempty,dive"`
|
||||||
Namespace *Namespace `yaml:"-" validate:"-"`
|
Namespace *Namespace `yaml:"-" validate:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,12 +145,12 @@ func (c Config) Validate() error {
|
|||||||
for _, communication := range c.Communications {
|
for _, communication := range c.Communications {
|
||||||
for _, from := range communication.From {
|
for _, from := range communication.From {
|
||||||
if !apps[from] {
|
if !apps[from] {
|
||||||
errs = append(errs, fmt.Errorf("Application does not exist: %s referenced in a communication (%+v)", from, communication))
|
errs = append(errs, fmt.Errorf("Application does not exist: '%s' referenced in a communication (%+v)", from, communication))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, to := range communication.To {
|
for _, to := range communication.To {
|
||||||
if !apps[to] {
|
if !apps[to] {
|
||||||
errs = append(errs, fmt.Errorf("Application does not exist: %s referenced in a communication (%+v)", to, communication))
|
errs = append(errs, fmt.Errorf("Application does not exist: '%s' referenced in a communication (%+v)", to, communication))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,11 @@ apiVersion: cilium.io/v2
|
|||||||
metadata:
|
metadata:
|
||||||
name: {{.app.Name}}-apiserver
|
name: {{.app.Name}}-apiserver
|
||||||
namespace: {{.app.Namespace.Name}}
|
namespace: {{.app.Namespace.Name}}
|
||||||
labels: {{ .labels | toYaml | nindent 4 }}
|
labels: {{ .labels | toJson }}
|
||||||
spec:
|
spec:
|
||||||
endpointSelector: {{ .app.MatchLabels | toYaml | nindent 4 }}
|
endpointSelector:
|
||||||
|
matchLabels: {{ .app.MatchLabels | toJson }}
|
||||||
|
matchExpressions: {{ .app.MatchExpressions | toJson }}
|
||||||
{{- if .ingress }}
|
{{- if .ingress }}
|
||||||
ingress:
|
ingress:
|
||||||
- fromEntities:
|
- fromEntities:
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# {{ .Application.Namespace.Name }}/{{ .Application.Name }}
|
# {{ .Application.Namespace.Name }}/{{ .Application.Name }}
|
||||||
- podSelector:
|
- podSelector:
|
||||||
matchLabels: {{ .Application.MatchLabels | toJson }}
|
matchLabels: {{ .Application.MatchLabels | toJson }}
|
||||||
|
matchExpressions: {{ .Application.MatchExpressions | toJson }}
|
||||||
namespaceSelector:
|
namespaceSelector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
kubernetes.io/metadata.name: {{ .Application.Namespace.Name }}
|
kubernetes.io/metadata.name: {{ .Application.Namespace.Name }}
|
||||||
@ -45,11 +46,12 @@ apiVersion: networking.k8s.io/v1
|
|||||||
metadata:
|
metadata:
|
||||||
name: "{{.app.Name}}"
|
name: "{{.app.Name}}"
|
||||||
namespace: "{{.app.Namespace.Name }}"
|
namespace: "{{.app.Namespace.Name }}"
|
||||||
labels: {{ .labels | toYaml | nindent 4 }}
|
labels: {{ .labels | toJson }}
|
||||||
spec:
|
spec:
|
||||||
# {{ .app.Namespace.Name }}/{{ .app.Name }}
|
# {{ .app.Namespace.Name }}/{{ .app.Name }}
|
||||||
podSelector:
|
podSelector:
|
||||||
matchLabels: {{ .app.MatchLabels | toJson }}
|
matchLabels: {{ .app.MatchLabels | toJson }}
|
||||||
|
matchExpressions: {{ .app.MatchExpressions | toJson }}
|
||||||
policyTypes:
|
policyTypes:
|
||||||
{{- if or .ingress.Applications .ingress.Networks }}
|
{{- if or .ingress.Applications .ingress.Networks }}
|
||||||
- Ingress
|
- Ingress
|
||||||
|
@ -28,6 +28,10 @@ namespaces:
|
|||||||
protocol: UDP
|
protocol: UDP
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: nexus-server
|
app: nexus-server
|
||||||
|
matchExpressions:
|
||||||
|
- key: jenkins/label
|
||||||
|
operator: Exists
|
||||||
|
|
||||||
|
|
||||||
- name: exposure
|
- name: exposure
|
||||||
open: false
|
open: false
|
||||||
|
Loading…
Reference in New Issue
Block a user