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
12 changes: 12 additions & 0 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type HAProxy struct {
Resources corev1.ResourceList `json:"resources,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Ingress Ingress `json:"ingress,omitempty"`
}

type AppServers struct {
Expand Down Expand Up @@ -148,3 +149,14 @@ type TlsForHAProxy struct {
SecretName string `json:"secretName,omitempty"`
CertFileName string `json:"certFileName,omitempty"`
}

type Ingress struct {
// +kubebuilder:default:=false
Enabled bool `json:"enabled,omitempty"`
IngressClassName string `json:"ingressClassName,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Host string `json:"host,omitempty"`
TLS *networkingv1.IngressTLS `json:"tls,omitempty"`
AdditionalHosts []networkingv1.IngressRule `json:"additionalHosts,omitempty"`
}
42 changes: 42 additions & 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.

4 changes: 2 additions & 2 deletions charts/marklogic-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ spec:
}}
securityContext: {{- toYaml .Values.controllerManager.manager.containerSecurityContext
| nindent 10 }}
securityContext:
runAsNonRoot: true
securityContext: {{- toYaml .Values.controllerManager.podSecurityContext | nindent
8 }}
serviceAccountName: {{ include "marklogic-operator.fullname" . }}-controller-manager
terminationGracePeriodSeconds: 10
12 changes: 12 additions & 0 deletions charts/marklogic-operator/templates/manager-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ rules:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
- ingresses
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
381 changes: 381 additions & 0 deletions charts/marklogic-operator/templates/marklogiccluster-crd.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions charts/marklogic-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ controllerManager:
requests:
cpu: 10m
memory: 64Mi
podSecurityContext:
runAsNonRoot: true
replicas: 1
serviceAccount:
annotations: {}
Expand Down
383 changes: 383 additions & 0 deletions config/crd/bases/database.marklogic.com_marklogicclusters.yaml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,15 @@ rules:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
- ingresses
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
63 changes: 51 additions & 12 deletions config/samples/marklogiccluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ spec:
## Uncomment the following lines to enable HAProxy configuration
haproxy:
enabled: false
# pathBasedRouting: true
# frontendPort: 8080
# tcpPorts:
# enabled: true
# ports:
# - name: odbc
# type: TCP
# port: 5432
# pathBasedRouting: true
# frontendPort: 8080
# tcpPorts:
# enabled: true
# ports:
# - name: odbc
# type: TCP
# port: 5432
# appServers:
# - name: "app-service"
# port: 8000
Expand All @@ -41,16 +41,55 @@ spec:
# - name: "manage"
# port: 8002
# path: "/manage"
# stats:
# enabled: true
# port: 1024
# stats:
# enabled: true
# port: 1024
# resources:
# requests:
# memory: "4Gi"
# cpu: "1"
# limits:
# memory: "4Gi"
# cpu: "1"
## Configure Ingress
## ref: https://kubernetes.io/docs/concepts/services-networking/ingress/
# ingress:
# enabled: true
# ingressClassName: "alb"

# ## Ingress labels
# ## ref: https://kubernetes.io/docs/concepts/overvsiew/working-with-objects/labels/
# labels:
# app.kubernetes.io/name: marklogiccluster
# app.kubernetes.io/instance: marklogiccluster-sample

# ## Ingress annotations
# ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
# annotations:
# alb.ingress.kubernetes.io/healthcheck-port: '80'
# alb.ingress.kubernetes.io/healthcheck-path: /adminUI
# alb.ingress.kubernetes.io/success-codes: '200-401'
# alb.ingress.kubernetes.io/load-balancer-name: mlingress
# alb.ingress.kubernetes.io/scheme: internet-facing
# alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":80}]'
# alb.ingress.kubernetes.io/target-group-attributes: load_balancing.algorithm.type=least_outstanding_requests
# # alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-west-2:XXXXXXXXXXX:certificate/XxXXXXXX-xxxx-XXXX-XXXX-XXXXXXXxxxxXXX
# alb.ingress.kubernetes.io/target-type: ip
# alb.ingress.kubernetes.io/group.name: mlingress-group
# alb.ingress.kubernetes.io/load-balancer-attributes: idle_timeout.timeout_seconds=600,routing.http.xff_header_processing.mode=append

## Ingress hosts
## add default hosts and additional hosts
## ref: https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-rules
# host: ""
# additionalHosts: []

## Ingress TLS
## ref: https://kubernetes.io/docs/concepts/services-networking/ingress/#tls
# tls: {}
# - secretName: your-certificate-name
# hosts:
# - marklogic.example.com

# logCollection:
# enabled: true
Expand Down Expand Up @@ -115,4 +154,4 @@ spec:
isBootstrap: true
# - replicas: 1
# name: enode
# isBootstrap: false
# isBootstrap: false
9 changes: 9 additions & 0 deletions internal/controller/marklogiccluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ var _ = Describe("MarklogicCluster Controller", func() {
{Name: "AppServices", Type: "http", Port: 8000, TargetPort: 8000, Path: "/console"},
{Name: "Admin", Type: "http", Port: 8001, TargetPort: 8001, Path: "/adminUI"},
{Name: "Manage", Type: "http", Port: 8002, TargetPort: 8002, Path: "/manage"},
},
Ingress: databasev1alpha1.Ingress{
Enabled: true,
IngressClassName: "alb",
Host: "marklogic-cluster-test.cluster.local",
}},
NetworkPolicy: databasev1alpha1.NetworkPolicy{
Enabled: true,
Expand Down Expand Up @@ -143,6 +148,10 @@ var _ = Describe("MarklogicCluster Controller", func() {
Expect(clusterCR.Spec.HAProxy.AppServers[0].Name).Should(Equal("AppServices"))
Expect(clusterCR.Spec.HAProxy.AppServers[0].Type).Should(Equal("http"))
Expect(clusterCR.Spec.HAProxy.AppServers[0].Port).Should(Equal(int32(8000)))
// Validating if Ingress is created successfully
Expect(clusterCR.Spec.HAProxy.Ingress.Enabled).Should(Equal(true))
Expect(clusterCR.Spec.HAProxy.Ingress.IngressClassName).Should(Equal("alb"))
Expect(clusterCR.Spec.HAProxy.Ingress.Host).Should(Equal("marklogic-cluster-test.cluster.local"))
// Validating if NetworkPolicy is created successfully
Expect(clusterCR.Spec.NetworkPolicy.PolicyTypes).Should(Equal(policy))
Expect(clusterCR.Spec.NetworkPolicy.PodSelector).Should(Equal(metav1.LabelSelector{MatchLabels: map[string]string{"app.kubernetes.io/name": "marklogic", "app.kubernetes.io/instance": "dnode"}}))
Expand Down
1 change: 1 addition & 0 deletions internal/controller/marklogicgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
//+kubebuilder:rbac:groups=database.marklogic.com,resources=marklogicgroups/finalizers,verbs=update
//+kubebuilder:rbac:groups=apps,resources=statefulsets;replicasets;deployments;daemonsets,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=core,resources=pods;services;secrets;configmaps,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch;create;update;patch;delete

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
Expand Down
3 changes: 2 additions & 1 deletion pkg/k8sutil/haProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package k8sutil
import (
"crypto/sha256"
"encoding/hex"
"sort"

"github.com/cisco-open/k8s-objectmatcher/patch"
databasev1alpha1 "github.com/marklogic/marklogic-kubernetes-operator/api/v1alpha1"
"github.com/marklogic/marklogic-kubernetes-operator/pkg/result"
Expand All @@ -13,7 +15,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"sort"
)

func (cc *ClusterContext) ReconcileHAProxy() result.ReconcileResult {
Expand Down
1 change: 0 additions & 1 deletion pkg/k8sutil/haProxyHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ backend marklogic-{{ .PortNumber}}-backend
}
result += getBackendServerConfigs(data)
}
result += "/n"
}
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/k8sutil/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func (cc *ClusterContext) ReconsileMarklogicClusterHandler() (reconcile.Result,
if result := cc.ReconcileHAProxy(); result.Completed() {
return result.Output()
}
if cc.MarklogicCluster.Spec.HAProxy.Ingress.Enabled {
if result := cc.ReconcileIngress(); result.Completed() {
return result.Output()
}
}
}
return result, err
}
Loading