Skip to content

Commit dde697c

Browse files
MLE-15962: Implement Service for MarkLogicGroup (#23)
* implemented service for MarkLogicGroup
1 parent 142d1a2 commit dde697c

File tree

10 files changed

+320
-46
lines changed

10 files changed

+320
-46
lines changed

api/v1alpha1/common_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ type HugePages struct {
3030
MountPath string `json:"mountPath,omitempty"`
3131
}
3232

33+
type Service struct {
34+
// +kubebuilder:default:= ClusterIP
35+
Type corev1.ServiceType `json:"type,omitempty"`
36+
AdditionalPorts []corev1.ServicePort `json:"additionalPorts,omitempty"`
37+
Annotations map[string]string `json:"annotations,omitempty"`
38+
}
39+
3340
type VolumeMountWrapper struct {
3441
Volume []corev1.Volume `json:"volume,omitempty"`
3542
MountPath []corev1.VolumeMount `json:"mountPath,omitempty"`

api/v1alpha1/marklogicgroup_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ type MarklogicGroupSpec struct {
7878
BootstrapHost string `json:"bootstrapHost,omitempty"`
7979

8080
DoNotDelete *bool `json:"doNotDelete,omitempty"`
81+
82+
Service Service `json:"service,omitempty"`
8183
}
8284

8385
// InternalState defines the observed state of MarklogicGroup

api/v1alpha1/zz_generated.deepcopy.go

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

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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,93 @@ spec:
19021902
type: string
19031903
type: object
19041904
type: object
1905+
service:
1906+
properties:
1907+
additionalPorts:
1908+
items:
1909+
description: ServicePort contains information on service's
1910+
port.
1911+
properties:
1912+
appProtocol:
1913+
description: |-
1914+
The application protocol for this port.
1915+
This is used as a hint for implementations to offer richer behavior for protocols that they understand.
1916+
This field follows standard Kubernetes label syntax.
1917+
Valid values are either:
1918+
1919+
1920+
* Un-prefixed protocol names - reserved for IANA standard service names (as per
1921+
RFC-6335 and https://www.iana.org/assignments/service-names).
1922+
1923+
1924+
* Kubernetes-defined prefixed names:
1925+
* 'kubernetes.io/h2c' - HTTP/2 prior knowledge over cleartext as described in https://www.rfc-editor.org/rfc/rfc9113.html#name-starting-http-2-with-prior-
1926+
* 'kubernetes.io/ws' - WebSocket over cleartext as described in https://www.rfc-editor.org/rfc/rfc6455
1927+
* 'kubernetes.io/wss' - WebSocket over TLS as described in https://www.rfc-editor.org/rfc/rfc6455
1928+
1929+
1930+
* Other protocols should use implementation-defined prefixed names such as
1931+
mycompany.com/my-custom-protocol.
1932+
type: string
1933+
name:
1934+
description: |-
1935+
The name of this port within the service. This must be a DNS_LABEL.
1936+
All ports within a ServiceSpec must have unique names. When considering
1937+
the endpoints for a Service, this must match the 'name' field in the
1938+
EndpointPort.
1939+
Optional if only one ServicePort is defined on this service.
1940+
type: string
1941+
nodePort:
1942+
description: |-
1943+
The port on each node on which this service is exposed when type is
1944+
NodePort or LoadBalancer. Usually assigned by the system. If a value is
1945+
specified, in-range, and not in use it will be used, otherwise the
1946+
operation will fail. If not specified, a port will be allocated if this
1947+
Service requires one. If this field is specified when creating a
1948+
Service which does not need it, creation will fail. This field will be
1949+
wiped when updating a Service to no longer need it (e.g. changing type
1950+
from NodePort to ClusterIP).
1951+
More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
1952+
format: int32
1953+
type: integer
1954+
port:
1955+
description: The port that will be exposed by
1956+
this service.
1957+
format: int32
1958+
type: integer
1959+
protocol:
1960+
default: TCP
1961+
description: |-
1962+
The IP protocol for this port. Supports "TCP", "UDP", and "SCTP".
1963+
Default is TCP.
1964+
type: string
1965+
targetPort:
1966+
anyOf:
1967+
- type: integer
1968+
- type: string
1969+
description: |-
1970+
Number or name of the port to access on the pods targeted by the service.
1971+
Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.
1972+
If this is a string, it will be looked up as a named port in the
1973+
target Pod's container ports. If this is not specified, the value
1974+
of the 'port' field is used (an identity map).
1975+
This field is ignored for services with clusterIP=None, and should be
1976+
omitted or set equal to the 'port' field.
1977+
More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service
1978+
x-kubernetes-int-or-string: true
1979+
required:
1980+
- port
1981+
type: object
1982+
type: array
1983+
annotations:
1984+
additionalProperties:
1985+
type: string
1986+
type: object
1987+
type:
1988+
default: ClusterIP
1989+
description: Service Type string describes ingress methods
1990+
for a service
1991+
type: string
19051992
priorityClassName:
19061993
type: string
19071994
readinessProbe:

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,91 @@ spec:
18711871
type: string
18721872
type: object
18731873
type: object
1874+
service:
1875+
properties:
1876+
additionalPorts:
1877+
items:
1878+
description: ServicePort contains information on service's port.
1879+
properties:
1880+
appProtocol:
1881+
description: |-
1882+
The application protocol for this port.
1883+
This is used as a hint for implementations to offer richer behavior for protocols that they understand.
1884+
This field follows standard Kubernetes label syntax.
1885+
Valid values are either:
1886+
1887+
1888+
* Un-prefixed protocol names - reserved for IANA standard service names (as per
1889+
RFC-6335 and https://www.iana.org/assignments/service-names).
1890+
1891+
1892+
* Kubernetes-defined prefixed names:
1893+
* 'kubernetes.io/h2c' - HTTP/2 prior knowledge over cleartext as described in https://www.rfc-editor.org/rfc/rfc9113.html#name-starting-http-2-with-prior-
1894+
* 'kubernetes.io/ws' - WebSocket over cleartext as described in https://www.rfc-editor.org/rfc/rfc6455
1895+
* 'kubernetes.io/wss' - WebSocket over TLS as described in https://www.rfc-editor.org/rfc/rfc6455
1896+
1897+
1898+
* Other protocols should use implementation-defined prefixed names such as
1899+
mycompany.com/my-custom-protocol.
1900+
type: string
1901+
name:
1902+
description: |-
1903+
The name of this port within the service. This must be a DNS_LABEL.
1904+
All ports within a ServiceSpec must have unique names. When considering
1905+
the endpoints for a Service, this must match the 'name' field in the
1906+
EndpointPort.
1907+
Optional if only one ServicePort is defined on this service.
1908+
type: string
1909+
nodePort:
1910+
description: |-
1911+
The port on each node on which this service is exposed when type is
1912+
NodePort or LoadBalancer. Usually assigned by the system. If a value is
1913+
specified, in-range, and not in use it will be used, otherwise the
1914+
operation will fail. If not specified, a port will be allocated if this
1915+
Service requires one. If this field is specified when creating a
1916+
Service which does not need it, creation will fail. This field will be
1917+
wiped when updating a Service to no longer need it (e.g. changing type
1918+
from NodePort to ClusterIP).
1919+
More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
1920+
format: int32
1921+
type: integer
1922+
port:
1923+
description: The port that will be exposed by this service.
1924+
format: int32
1925+
type: integer
1926+
protocol:
1927+
default: TCP
1928+
description: |-
1929+
The IP protocol for this port. Supports "TCP", "UDP", and "SCTP".
1930+
Default is TCP.
1931+
type: string
1932+
targetPort:
1933+
anyOf:
1934+
- type: integer
1935+
- type: string
1936+
description: |-
1937+
Number or name of the port to access on the pods targeted by the service.
1938+
Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.
1939+
If this is a string, it will be looked up as a named port in the
1940+
target Pod's container ports. If this is not specified, the value
1941+
of the 'port' field is used (an identity map).
1942+
This field is ignored for services with clusterIP=None, and should be
1943+
omitted or set equal to the 'port' field.
1944+
More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service
1945+
x-kubernetes-int-or-string: true
1946+
required:
1947+
- port
1948+
type: object
1949+
type: array
1950+
annotations:
1951+
additionalProperties:
1952+
type: string
1953+
type: object
1954+
type:
1955+
default: ClusterIP
1956+
description: Service Type string describes ingress methods for
1957+
a service
1958+
type: string
18741959
priorityClassName:
18751960
type: string
18761961
readinessProbe:

config/samples/marklogicgroup.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ spec:
2121
updateStrategy: OnDelete
2222
groupConfig:
2323
name: "node"
24+
service:
25+
## service type could be ClusterIP, NodePort or LoadBalancer, default is ClusterIP
26+
type: ClusterIP
27+
## Uncomment the following lines to add additional ports to the service
28+
# additionalPorts:
29+
# - name: app1
30+
# port: 8010
31+
# targetPort: 8010
32+
# protocol: TCP
33+
## Uncomment the following lines to add annotations to the service
34+
# annotations: {}
35+
2436
## Uncomment the following lines to specify the podSecurityContext and containerSecurityContext
2537
## Note: Below values are set to default, please update them as per your requirements
2638
# podSecurityContext:

internal/controller/marklogicgroup_controller_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const resourceMemoryValue = int64(268435456)
5757
// 100Mi
5858
const resourceHugepageValue = int64(104857600)
5959

60+
var svcName = Name + "-cluster"
61+
var typeNamespaceNameSvc = types.NamespacedName{Name: svcName, Namespace: Namespace}
62+
6063
const fluentBitImage = "fluent/fluent-bit:3.1.1"
6164

6265
var groupConfig = databasev1alpha1.GroupConfig{
@@ -164,13 +167,23 @@ var _ = Describe("MarkLogicGroup controller", func() {
164167
Expect(sts.Name).Should(Equal(Name))
165168
Expect(sts.Spec.PodManagementPolicy).Should(Equal(appsv1.ParallelPodManagement))
166169

167-
// Validating if Service is created successfully
170+
// Validating if headless Service is created successfully
168171
createdSrv := &corev1.Service{}
169172
Eventually(func() bool {
170173
err := k8sClient.Get(ctx, typeNamespaceName, createdSrv)
171174
return err == nil
172175
}, timeout, interval).Should(BeTrue())
173176
Expect(createdSrv.Spec.Ports[0].TargetPort).Should(Equal(intstr.FromInt(int(7997))))
177+
178+
// Validating if Service is created successfully
179+
createdClusterSrv := &corev1.Service{}
180+
svcName := sts.Name + "-cluster"
181+
Eventually(func() bool {
182+
err := k8sClient.Get(ctx, typeNamespaceNameSvc, createdClusterSrv)
183+
return err == nil
184+
}, timeout, interval).Should(BeTrue())
185+
Expect(createdClusterSrv.Name).Should(Equal(svcName))
186+
Expect(createdClusterSrv.Spec.Type).Should(Equal(corev1.ServiceTypeClusterIP))
174187
})
175188

176189
It("Should create configmap for MarkLogic scripts", func() {

pkg/k8sutil/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
func (oc *OperatorContext) ReconsileHandler() (reconcile.Result, error) {
88
oc.ReqLogger.Info("handler::ReconsileHandler")
99

10-
if result := oc.ReconcileSrvices(); result.Completed() {
10+
if result := oc.ReconcileServices(); result.Completed() {
1111
return result.Output()
1212
}
1313
setOperatorInternalStatus(oc, "Created")

0 commit comments

Comments
 (0)