Skip to content

Commit 8b51be4

Browse files
MLE-11468: Implementation and unit test for Ingress (#36)
* Implementation and unit test for Ingress
1 parent 329fe71 commit 8b51be4

File tree

15 files changed

+1059
-16
lines changed

15 files changed

+1059
-16
lines changed

api/v1alpha1/common_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ type HAProxy struct {
100100
Resources corev1.ResourceList `json:"resources,omitempty"`
101101
Affinity *corev1.Affinity `json:"affinity,omitempty"`
102102
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
103+
Ingress Ingress `json:"ingress,omitempty"`
103104
}
104105

105106
type AppServers struct {
@@ -148,3 +149,14 @@ type TlsForHAProxy struct {
148149
SecretName string `json:"secretName,omitempty"`
149150
CertFileName string `json:"certFileName,omitempty"`
150151
}
152+
153+
type Ingress struct {
154+
// +kubebuilder:default:=false
155+
Enabled bool `json:"enabled,omitempty"`
156+
IngressClassName string `json:"ingressClassName,omitempty"`
157+
Labels map[string]string `json:"labels,omitempty"`
158+
Annotations map[string]string `json:"annotations,omitempty"`
159+
Host string `json:"host,omitempty"`
160+
TLS *networkingv1.IngressTLS `json:"tls,omitempty"`
161+
AdditionalHosts []networkingv1.IngressRule `json:"additionalHosts,omitempty"`
162+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/marklogic-operator/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec:
6363
}}
6464
securityContext: {{- toYaml .Values.controllerManager.manager.containerSecurityContext
6565
| nindent 10 }}
66-
securityContext:
67-
runAsNonRoot: true
66+
securityContext: {{- toYaml .Values.controllerManager.podSecurityContext | nindent
67+
8 }}
6868
serviceAccountName: {{ include "marklogic-operator.fullname" . }}-controller-manager
6969
terminationGracePeriodSeconds: 10

charts/marklogic-operator/templates/manager-rbac.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ rules:
8787
- get
8888
- patch
8989
- update
90+
- apiGroups:
91+
- networking.k8s.io
92+
resources:
93+
- ingresses
94+
verbs:
95+
- create
96+
- delete
97+
- get
98+
- list
99+
- patch
100+
- update
101+
- watch
90102
---
91103
apiVersion: rbac.authorization.k8s.io/v1
92104
kind: ClusterRoleBinding

charts/marklogic-operator/templates/marklogiccluster-crd.yaml

Lines changed: 381 additions & 0 deletions
Large diffs are not rendered by default.

charts/marklogic-operator/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ controllerManager:
4040
requests:
4141
cpu: 10m
4242
memory: 64Mi
43+
podSecurityContext:
44+
runAsNonRoot: true
4345
replicas: 1
4446
serviceAccount:
4547
annotations: {}

config/crd/bases/database.marklogic.com_marklogicclusters.yaml

Lines changed: 383 additions & 0 deletions
Large diffs are not rendered by default.

config/rbac/role.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,15 @@ rules:
8686
- get
8787
- patch
8888
- update
89+
- apiGroups:
90+
- networking.k8s.io
91+
resources:
92+
- ingresses
93+
verbs:
94+
- create
95+
- delete
96+
- get
97+
- list
98+
- patch
99+
- update
100+
- watch

config/samples/marklogiccluster.yaml

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ spec:
2323
## Uncomment the following lines to enable HAProxy configuration
2424
haproxy:
2525
enabled: false
26-
# pathBasedRouting: true
27-
# frontendPort: 8080
28-
# tcpPorts:
29-
# enabled: true
30-
# ports:
31-
# - name: odbc
32-
# type: TCP
33-
# port: 5432
26+
# pathBasedRouting: true
27+
# frontendPort: 8080
28+
# tcpPorts:
29+
# enabled: true
30+
# ports:
31+
# - name: odbc
32+
# type: TCP
33+
# port: 5432
3434
# appServers:
3535
# - name: "app-service"
3636
# port: 8000
@@ -41,16 +41,55 @@ spec:
4141
# - name: "manage"
4242
# port: 8002
4343
# path: "/manage"
44-
# stats:
45-
# enabled: true
46-
# port: 1024
44+
# stats:
45+
# enabled: true
46+
# port: 1024
4747
# resources:
4848
# requests:
4949
# memory: "4Gi"
5050
# cpu: "1"
5151
# limits:
5252
# memory: "4Gi"
5353
# cpu: "1"
54+
## Configure Ingress
55+
## ref: https://kubernetes.io/docs/concepts/services-networking/ingress/
56+
# ingress:
57+
# enabled: true
58+
# ingressClassName: "alb"
59+
60+
# ## Ingress labels
61+
# ## ref: https://kubernetes.io/docs/concepts/overvsiew/working-with-objects/labels/
62+
# labels:
63+
# app.kubernetes.io/name: marklogiccluster
64+
# app.kubernetes.io/instance: marklogiccluster-sample
65+
66+
# ## Ingress annotations
67+
# ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
68+
# annotations:
69+
# alb.ingress.kubernetes.io/healthcheck-port: '80'
70+
# alb.ingress.kubernetes.io/healthcheck-path: /adminUI
71+
# alb.ingress.kubernetes.io/success-codes: '200-401'
72+
# alb.ingress.kubernetes.io/load-balancer-name: mlingress
73+
# alb.ingress.kubernetes.io/scheme: internet-facing
74+
# alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":80}]'
75+
# alb.ingress.kubernetes.io/target-group-attributes: load_balancing.algorithm.type=least_outstanding_requests
76+
# # alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-west-2:XXXXXXXXXXX:certificate/XxXXXXXX-xxxx-XXXX-XXXX-XXXXXXXxxxxXXX
77+
# alb.ingress.kubernetes.io/target-type: ip
78+
# alb.ingress.kubernetes.io/group.name: mlingress-group
79+
# alb.ingress.kubernetes.io/load-balancer-attributes: idle_timeout.timeout_seconds=600,routing.http.xff_header_processing.mode=append
80+
81+
## Ingress hosts
82+
## add default hosts and additional hosts
83+
## ref: https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-rules
84+
# host: ""
85+
# additionalHosts: []
86+
87+
## Ingress TLS
88+
## ref: https://kubernetes.io/docs/concepts/services-networking/ingress/#tls
89+
# tls: {}
90+
# - secretName: your-certificate-name
91+
# hosts:
92+
# - marklogic.example.com
5493

5594
# logCollection:
5695
# enabled: true
@@ -115,4 +154,4 @@ spec:
115154
isBootstrap: true
116155
# - replicas: 1
117156
# name: enode
118-
# isBootstrap: false
157+
# isBootstrap: false

internal/controller/marklogiccluster_controller_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ var _ = Describe("MarklogicCluster Controller", func() {
8787
{Name: "AppServices", Type: "http", Port: 8000, TargetPort: 8000, Path: "/console"},
8888
{Name: "Admin", Type: "http", Port: 8001, TargetPort: 8001, Path: "/adminUI"},
8989
{Name: "Manage", Type: "http", Port: 8002, TargetPort: 8002, Path: "/manage"},
90+
},
91+
Ingress: databasev1alpha1.Ingress{
92+
Enabled: true,
93+
IngressClassName: "alb",
94+
Host: "marklogic-cluster-test.cluster.local",
9095
}},
9196
NetworkPolicy: databasev1alpha1.NetworkPolicy{
9297
Enabled: true,
@@ -143,6 +148,10 @@ var _ = Describe("MarklogicCluster Controller", func() {
143148
Expect(clusterCR.Spec.HAProxy.AppServers[0].Name).Should(Equal("AppServices"))
144149
Expect(clusterCR.Spec.HAProxy.AppServers[0].Type).Should(Equal("http"))
145150
Expect(clusterCR.Spec.HAProxy.AppServers[0].Port).Should(Equal(int32(8000)))
151+
// Validating if Ingress is created successfully
152+
Expect(clusterCR.Spec.HAProxy.Ingress.Enabled).Should(Equal(true))
153+
Expect(clusterCR.Spec.HAProxy.Ingress.IngressClassName).Should(Equal("alb"))
154+
Expect(clusterCR.Spec.HAProxy.Ingress.Host).Should(Equal("marklogic-cluster-test.cluster.local"))
146155
// Validating if NetworkPolicy is created successfully
147156
Expect(clusterCR.Spec.NetworkPolicy.PolicyTypes).Should(Equal(policy))
148157
Expect(clusterCR.Spec.NetworkPolicy.PodSelector).Should(Equal(metav1.LabelSelector{MatchLabels: map[string]string{"app.kubernetes.io/name": "marklogic", "app.kubernetes.io/instance": "dnode"}}))

0 commit comments

Comments
 (0)