Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha1/marklogiccluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type MarklogicGroups struct {
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Storage *Storage `json:"storage,omitempty"`
Service Service `json:"service,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions config/crd/bases/database.marklogic.com_marklogicclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8547,6 +8547,91 @@ spec:
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
service:
properties:
additionalPorts:
items:
description: ServicePort contains information on service's
port.
properties:
appProtocol:
description: |-
The application protocol for this port.
This is used as a hint for implementations to offer richer behavior for protocols that they understand.
This field follows standard Kubernetes label syntax.
Valid values are either:

* Un-prefixed protocol names - reserved for IANA standard service names (as per
RFC-6335 and https://www.iana.org/assignments/service-names).

* Kubernetes-defined prefixed names:
* '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-
* 'kubernetes.io/ws' - WebSocket over cleartext as described in https://www.rfc-editor.org/rfc/rfc6455
* 'kubernetes.io/wss' - WebSocket over TLS as described in https://www.rfc-editor.org/rfc/rfc6455

* Other protocols should use implementation-defined prefixed names such as
mycompany.com/my-custom-protocol.
type: string
name:
description: |-
The name of this port within the service. This must be a DNS_LABEL.
All ports within a ServiceSpec must have unique names. When considering
the endpoints for a Service, this must match the 'name' field in the
EndpointPort.
Optional if only one ServicePort is defined on this service.
type: string
nodePort:
description: |-
The port on each node on which this service is exposed when type is
NodePort or LoadBalancer. Usually assigned by the system. If a value is
specified, in-range, and not in use it will be used, otherwise the
operation will fail. If not specified, a port will be allocated if this
Service requires one. If this field is specified when creating a
Service which does not need it, creation will fail. This field will be
wiped when updating a Service to no longer need it (e.g. changing type
from NodePort to ClusterIP).
More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
format: int32
type: integer
port:
description: The port that will be exposed by this
service.
format: int32
type: integer
protocol:
default: TCP
description: |-
The IP protocol for this port. Supports "TCP", "UDP", and "SCTP".
Default is TCP.
type: string
targetPort:
anyOf:
- type: integer
- type: string
description: |-
Number or name of the port to access on the pods targeted by the service.
Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.
If this is a string, it will be looked up as a named port in the
target Pod's container ports. If this is not specified, the value
of the 'port' field is used (an identity map).
This field is ignored for services with clusterIP=None, and should be
omitted or set equal to the 'port' field.
More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service
x-kubernetes-int-or-string: true
required:
- port
type: object
type: array
annotations:
additionalProperties:
type: string
type: object
type:
default: ClusterIP
description: Service Type string describes ingress methods
for a service
type: string
type: object
storage:
description: Storage is the inteface to add pvc and pv support
in marklogic
Expand Down
26 changes: 26 additions & 0 deletions config/samples/marklogiccluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ spec:
groupConfig:
name: dnode
enableXdqpSsl: true
# service:
# ## service type could be ClusterIP, NodePort or LoadBalancer, default is ClusterIP
# type: ClusterIP
# # Uncomment the following lines to add additional ports to the service
# additionalPorts:
# - name: app1
# port: 8010
# targetPort: 8010
# protocol: TCP
# - name: app2
# port: 8011
# targetPort: 8011
# protocol: TCP
# # Uncomment the following lines to add annotations to the service
# annotations: {}
# storage:
# size: 10Gi
# resources:
Expand All @@ -170,3 +185,14 @@ spec:
name: enode
enableXdqpSsl: true
isBootstrap: false
# service:
# ## service type could be ClusterIP, NodePort or LoadBalancer, default is ClusterIP
# type: ClusterIP
# # Uncomment the following lines to add additional ports to the service
# additionalPorts:
# - name: app1
# port: 8010
# targetPort: 8010
# protocol: TCP
# # Uncomment the following lines to add annotations to the service
# annotations: {}
2 changes: 2 additions & 0 deletions internal/controller/marklogiccluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ var marklogicGroups = []*databasev1alpha1.MarklogicGroups{
{
Name: "dnode",
Replicas: &dnodeReplicas,
Service: databasev1alpha1.Service{Type: corev1.ServiceTypeClusterIP},
},
{
Name: "enode",
Replicas: &enodeReplicas,
Service: databasev1alpha1.Service{Type: corev1.ServiceTypeClusterIP},
},
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/k8sutil/marklogicServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package k8sutil

import (
"fmt"

"github.com/cisco-open/k8s-objectmatcher/patch"
"github.com/go-logr/logr"
databasev1alpha1 "github.com/marklogic/marklogic-kubernetes-operator/api/v1alpha1"
Expand All @@ -22,6 +23,7 @@ type MarkLogicGroupParameters struct {
ImagePullPolicy string
ImagePullSecrets []corev1.LocalObjectReference
License *databasev1alpha1.License
Service databasev1alpha1.Service
Storage *databasev1alpha1.Storage
Auth *databasev1alpha1.AdminAuth
TerminationGracePeriodSeconds *int64
Expand Down Expand Up @@ -116,6 +118,7 @@ func GenerateMarkLogicGroupDef(cr *databasev1alpha1.MarklogicCluster, index int,
Affinity: params.Affinity,
NodeSelector: params.NodeSelector,
Storage: params.Storage,
Service: params.Service,
LogCollection: params.LogCollection,
TopologySpreadConstraints: params.TopologySpreadConstraints,
PodSecurityContext: params.PodSecurityContext,
Expand Down Expand Up @@ -230,6 +233,7 @@ func generateMarkLogicGroupParams(cr *databasev1alpha1.MarklogicCluster, index i
Replicas: cr.Spec.MarkLogicGroups[index].Replicas,
Name: cr.Spec.MarkLogicGroups[index].Name,
GroupConfig: cr.Spec.MarkLogicGroups[index].GroupConfig,
Service: cr.Spec.MarkLogicGroups[index].Service,
Image: clusterParams.Image,
ImagePullPolicy: clusterParams.ImagePullPolicy,
ImagePullSecrets: clusterParams.ImagePullSecrets,
Expand Down
25 changes: 9 additions & 16 deletions pkg/k8sutil/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,15 @@ func generateServicePorts() []corev1.ServicePort {

func generateServiceDef(serviceMeta metav1.ObjectMeta, ownerRef metav1.OwnerReference, params serviceParameters) *corev1.Service {
var svcSpec corev1.ServiceSpec
svcSpec = corev1.ServiceSpec{
Selector: serviceMeta.GetLabels(),
Ports: append(params.Ports, generateServicePorts()...),
}
if strings.HasSuffix(serviceMeta.Name, "-cluster") {
svcSpec = corev1.ServiceSpec{
Selector: serviceMeta.GetLabels(),
Ports: append(params.Ports, generateServicePorts()...),
Type: params.Type,
}
svcSpec.Type = params.Type
} else {
svcSpec = corev1.ServiceSpec{
Selector: serviceMeta.GetLabels(),
Ports: generateServicePorts(),
ClusterIP: "None",
PublishNotReadyAddresses: true,
}
svcSpec.ClusterIP = "None"
svcSpec.PublishNotReadyAddresses = true
}
service := &corev1.Service{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -132,11 +128,8 @@ func (oc *OperatorContext) CreateOrUpdateService(namespace string, serviceMeta m
func generateService(svcName string, cr *databasev1alpha1.MarklogicGroup) *corev1.Service {
labels := getMarkLogicLabels(cr.Spec.Name)
var svcParams serviceParameters = serviceParameters{}
svcObjectMeta := generateObjectMeta(svcName, cr.Namespace, labels, map[string]string{})
if strings.HasSuffix(svcName, "-cluster") {
svcParams = generateServiceParams(cr)
svcObjectMeta = generateObjectMeta(svcName, cr.Namespace, labels, svcParams.Annotations)
}
svcObjectMeta := generateObjectMeta(svcName, cr.Namespace, labels, svcParams.Annotations)
svcParams = generateServiceParams(cr)
service := generateServiceDef(svcObjectMeta, marklogicServerAsOwner(cr), svcParams)
return service
}
Expand Down