Skip to content
Draft
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
10 changes: 10 additions & 0 deletions apis/kubedb/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2121,6 +2121,16 @@ var (
core.ResourceMemory: resource.MustParse("10Gi"),
},
}

DefaultResourcesNeo4j = core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse(".500"),
core.ResourceMemory: resource.MustParse("2Gi"),
},
Limits: core.ResourceList{
core.ResourceMemory: resource.MustParse("2Gi"),
},
}
)

func DefaultArbiter(computeOnly bool) core.ResourceRequirements {
Expand Down
79 changes: 79 additions & 0 deletions apis/kubedb/v1alpha2/neo4j_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import (
"fmt"
"slices"

"kubedb.dev/apimachinery/apis"
catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"
"kubedb.dev/apimachinery/apis/kubedb"
"kubedb.dev/apimachinery/crds"

promapi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
core "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -35,6 +37,7 @@ import (
meta_util "kmodules.xyz/client-go/meta"
"kmodules.xyz/client-go/policy/secomp"
appcat "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
mona "kmodules.xyz/monitoring-agent-api/api/v1"
ofst "kmodules.xyz/offshoot-api/api/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -131,6 +134,28 @@ func (r *Neo4j) SetDefaults(kc client.Client) {
}

r.setDefaultContainerSecurityContext(&neoVersion, &r.Spec.PodTemplate)
r.SetHealthCheckerDefaults()

if r.Spec.Monitor != nil {
if r.Spec.Monitor.Prometheus == nil {
r.Spec.Monitor.Prometheus = &mona.PrometheusSpec{}
}
if r.Spec.Monitor.Prometheus.Exporter.Port == 0 {
r.Spec.Monitor.Prometheus.Exporter.Port = kubedb.Neo4jPrometheusPort
}
r.Spec.Monitor.SetDefaults()
if r.Spec.Monitor.Prometheus.Exporter.SecurityContext.RunAsUser == nil {
r.Spec.Monitor.Prometheus.Exporter.SecurityContext.RunAsUser = neoVersion.Spec.SecurityContext.RunAsUser
}
if r.Spec.Monitor.Prometheus.Exporter.SecurityContext.RunAsGroup == nil {
r.Spec.Monitor.Prometheus.Exporter.SecurityContext.RunAsGroup = neoVersion.Spec.SecurityContext.RunAsUser
}
}

dbContainer := coreutil.GetContainerByName(r.Spec.PodTemplate.Spec.Containers, kubedb.Neo4jContainerName)
if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&dbContainer.Resources, kubedb.DefaultResourcesNeo4j)
}
}

func (r *Neo4j) setDefaultContainerSecurityContext(neoVersion *catalog.Neo4jVersion, podTemplate *ofst.PodTemplateSpec) {
Expand All @@ -143,13 +168,15 @@ func (r *Neo4j) setDefaultContainerSecurityContext(neoVersion *catalog.Neo4jVers
if podTemplate.Spec.SecurityContext.FSGroup == nil {
podTemplate.Spec.SecurityContext.FSGroup = neoVersion.Spec.SecurityContext.RunAsUser
}

container := coreutil.GetContainerByName(podTemplate.Spec.Containers, kubedb.Neo4jContainerName)
if container == nil {
container = &core.Container{
Name: kubedb.Neo4jContainerName,
}
podTemplate.Spec.Containers = coreutil.UpsertContainer(podTemplate.Spec.Containers, *container)
}

if container.SecurityContext == nil {
container.SecurityContext = &core.SecurityContext{}
}
Expand Down Expand Up @@ -236,6 +263,9 @@ func (r *Neo4j) AppBindingMeta() appcat.AppBindingMeta {

func (r *Neo4j) GetConnectionScheme() string {
scheme := "http" // TODO:()
if r.Spec.TLS != nil {
scheme = "https"
}
return scheme
}

Expand All @@ -250,3 +280,52 @@ func (r *Neo4j) SetHealthCheckerDefaults() {
r.Spec.HealthChecker.FailureThreshold = ptr.To(int32(3))
}
}

func (r *Neo4j) ServiceLabels(alias ServiceAlias, extraLabels ...map[string]string) map[string]string {
svcTemplate := GetServiceTemplate(r.Spec.ServiceTemplates, alias)
return r.offshootLabels(meta_util.OverwriteKeys(r.OffshootSelectors(), extraLabels...), svcTemplate.Labels)
}

type neo4jStatsService struct {
*Neo4j
}

func (r neo4jStatsService) GetNamespace() string {
return r.Neo4j.GetNamespace()
}

func (r neo4jStatsService) ServiceName() string {
return r.OffshootName() + "-stats"
}

func (r neo4jStatsService) ServiceMonitorName() string {
return r.ServiceName()
}

func (r neo4jStatsService) ServiceMonitorAdditionalLabels() map[string]string {
return r.OffshootLabels()
}

func (r neo4jStatsService) Path() string {
return kubedb.DefaultStatsPath
}

func (r neo4jStatsService) Scheme() string {
scheme := "http" // TODO:()
if r.Spec.TLS != nil {
scheme = "https"
}
return scheme
}

func (r neo4jStatsService) TLSConfig() *promapi.TLSConfig {
return nil
}

func (r *Neo4j) StatsService() mona.StatsAccessor {
return &neo4jStatsService{r}
}

func (r *Neo4j) StatsServiceLabels() map[string]string {
return r.ServiceLabels(StatsServiceAlias, map[string]string{kubedb.LabelRole: kubedb.RoleStats})
}
9 changes: 9 additions & 0 deletions apis/kubedb/v1alpha2/neo4j_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kmapi "kmodules.xyz/client-go/api/v1"
mona "kmodules.xyz/monitoring-agent-api/api/v1"
ofst "kmodules.xyz/offshoot-api/api/v2"
)

Expand Down Expand Up @@ -93,6 +94,14 @@ type Neo4jSpec struct {
// +optional
// +kubebuilder:default={periodSeconds: 10, timeoutSeconds: 10, failureThreshold: 3}
HealthChecker kmapi.HealthCheckSpec `json:"healthChecker"`

// Monitor is used monitor database instance
// +optional
Monitor *mona.AgentSpec `json:"monitor,omitempty"`

// TLS contains tls configurations
// +optional
TLS *kmapi.TLSConfig `json:"tls,omitempty"`
}

// Neo4jStatus defines the observed state of Neo4j.
Expand Down
35 changes: 34 additions & 1 deletion apis/kubedb/v1alpha2/openapi_generated.go

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

10 changes: 10 additions & 0 deletions apis/kubedb/v1alpha2/zz_generated.deepcopy.go

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

Loading
Loading