diff --git a/apis/kubedb/v1alpha2/constants.go b/apis/kubedb/v1alpha2/constants.go index a96cabaee7..f247797e9e 100644 --- a/apis/kubedb/v1alpha2/constants.go +++ b/apis/kubedb/v1alpha2/constants.go @@ -1203,6 +1203,17 @@ var ( }, } + // DefaultResourcesCoreAndMemoryIntensive must be used for Solr + DefaultResourcesCoreAndMemoryIntensiveSolr = core.ResourceRequirements{ + Requests: core.ResourceList{ + core.ResourceCPU: resource.MustParse(".900"), + core.ResourceMemory: resource.MustParse("2Gi"), + }, + Limits: core.ResourceList{ + core.ResourceMemory: resource.MustParse("2Gi"), + }, + } + // DefaultResourcesMemoryIntensiveSDB must be used for Singlestore when enabled monitoring or version >= 8.5.x DefaultResourcesMemoryIntensiveSDB = core.ResourceRequirements{ Requests: core.ResourceList{ diff --git a/apis/kubedb/v1alpha2/openapi_generated.go b/apis/kubedb/v1alpha2/openapi_generated.go index 1cfc496c12..ea07f8eb65 100644 --- a/apis/kubedb/v1alpha2/openapi_generated.go +++ b/apis/kubedb/v1alpha2/openapi_generated.go @@ -636,6 +636,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.redisStatsService": schema_apimachinery_apis_kubedb_v1alpha2_redisStatsService(ref), "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.singlestoreApp": schema_apimachinery_apis_kubedb_v1alpha2_singlestoreApp(ref), "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.singlestoreStatsService": schema_apimachinery_apis_kubedb_v1alpha2_singlestoreStatsService(ref), + "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.solrStatsService": schema_apimachinery_apis_kubedb_v1alpha2_solrStatsService(ref), "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.zookeeperStatsService": schema_apimachinery_apis_kubedb_v1alpha2_zookeeperStatsService(ref), } } @@ -31219,6 +31220,12 @@ func schema_apimachinery_apis_kubedb_v1alpha2_SolrSpec(ref common.ReferenceCallb Ref: ref("kmodules.xyz/client-go/api/v1.HealthCheckSpec"), }, }, + "monitor": { + SchemaProps: spec.SchemaProps{ + Description: "Monitor is used monitor database instance", + Ref: ref("kmodules.xyz/monitoring-agent-api/api/v1.AgentSpec"), + }, + }, "podPlacementPolicy": { SchemaProps: spec.SchemaProps{ Description: "PodPlacementPolicy is the reference of the podPlacementPolicy", @@ -31230,7 +31237,7 @@ func schema_apimachinery_apis_kubedb_v1alpha2_SolrSpec(ref common.ReferenceCallb }, }, Dependencies: []string{ - "k8s.io/api/core/v1.LocalObjectReference", "k8s.io/api/core/v1.PersistentVolumeClaimSpec", "kmodules.xyz/client-go/api/v1.HealthCheckSpec", "kmodules.xyz/client-go/api/v1.ObjectReference", "kmodules.xyz/client-go/api/v1.TLSConfig", "kmodules.xyz/offshoot-api/api/v2.PodTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.NamedServiceTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.SolrClusterTopology"}, + "k8s.io/api/core/v1.LocalObjectReference", "k8s.io/api/core/v1.PersistentVolumeClaimSpec", "kmodules.xyz/client-go/api/v1.HealthCheckSpec", "kmodules.xyz/client-go/api/v1.ObjectReference", "kmodules.xyz/client-go/api/v1.TLSConfig", "kmodules.xyz/monitoring-agent-api/api/v1.AgentSpec", "kmodules.xyz/offshoot-api/api/v2.PodTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.NamedServiceTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.SolrClusterTopology"}, } } @@ -32171,6 +32178,26 @@ func schema_apimachinery_apis_kubedb_v1alpha2_singlestoreStatsService(ref common } } +func schema_apimachinery_apis_kubedb_v1alpha2_solrStatsService(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "Solr": { + SchemaProps: spec.SchemaProps{ + Ref: ref("kubedb.dev/apimachinery/apis/kubedb/v1alpha2.Solr"), + }, + }, + }, + Required: []string{"Solr"}, + }, + }, + Dependencies: []string{ + "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.Solr"}, + } +} + func schema_apimachinery_apis_kubedb_v1alpha2_zookeeperStatsService(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/apis/kubedb/v1alpha2/solr_helpers.go b/apis/kubedb/v1alpha2/solr_helpers.go index 00f53f6f28..681233b1b0 100644 --- a/apis/kubedb/v1alpha2/solr_helpers.go +++ b/apis/kubedb/v1alpha2/solr_helpers.go @@ -25,6 +25,7 @@ import ( "kubedb.dev/apimachinery/apis/kubedb" "kubedb.dev/apimachinery/crds" + promapi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "gomodules.xyz/pointer" v1 "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -34,6 +35,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" pslister "kubeops.dev/petset/client/listers/apps/v1" ) @@ -179,6 +181,51 @@ func (s *Solr) GetConnectionScheme() string { return scheme } +func (s *Solr) ServiceLabels(alias ServiceAlias, extraLabels ...map[string]string) map[string]string { + svcTemplate := GetServiceTemplate(s.Spec.ServiceTemplates, alias) + return s.offshootLabels(meta_util.OverwriteKeys(s.OffshootSelectors(), extraLabels...), svcTemplate.Labels) +} + +type solrStatsService struct { + *Solr +} + +func (s solrStatsService) GetNamespace() string { + return s.Solr.GetNamespace() +} + +func (s solrStatsService) ServiceName() string { + return s.OffshootName() + "-stats" +} + +func (s solrStatsService) ServiceMonitorName() string { + return s.ServiceName() +} + +func (s solrStatsService) ServiceMonitorAdditionalLabels() map[string]string { + return s.OffshootLabels() +} + +func (s solrStatsService) Path() string { + return DefaultStatsPath +} + +func (s solrStatsService) Scheme() string { + return "" +} + +func (s solrStatsService) TLSConfig() *promapi.TLSConfig { + return nil +} + +func (s *Solr) StatsService() mona.StatsAccessor { + return &solrStatsService{s} +} + +func (s *Solr) StatsServiceLabels() map[string]string { + return s.ServiceLabels(StatsServiceAlias, map[string]string{LabelRole: RoleStats}) +} + func (s *Solr) PVCName(alias string) string { return meta_util.NameWithSuffix(s.Name, alias) } @@ -224,13 +271,13 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) { if s.Spec.Topology.Data.Replicas == nil { s.Spec.Topology.Data.Replicas = pointer.Int32P(1) } - if s.Spec.Topology.Data.PodTemplate.Spec.SecurityContext == nil { s.Spec.Topology.Data.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{} } s.Spec.Topology.Data.PodTemplate.Spec.SecurityContext.FSGroup = slVersion.Spec.SecurityContext.RunAsUser s.setDefaultContainerSecurityContext(slVersion, &s.Spec.Topology.Data.PodTemplate) s.setDefaultContainerResourceLimits(&s.Spec.Topology.Data.PodTemplate) + } if s.Spec.Topology.Overseer != nil { @@ -240,7 +287,6 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) { if s.Spec.Topology.Overseer.Replicas == nil { s.Spec.Topology.Overseer.Replicas = pointer.Int32P(1) } - if s.Spec.Topology.Overseer.PodTemplate.Spec.SecurityContext == nil { s.Spec.Topology.Overseer.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{} } @@ -256,7 +302,6 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) { if s.Spec.Topology.Coordinator.Replicas == nil { s.Spec.Topology.Coordinator.Replicas = pointer.Int32P(1) } - if s.Spec.Topology.Coordinator.PodTemplate.Spec.SecurityContext == nil { s.Spec.Topology.Coordinator.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{} } @@ -265,15 +310,12 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) { s.setDefaultContainerResourceLimits(&s.Spec.Topology.Coordinator.PodTemplate) } } else { - if s.Spec.Replicas == nil { s.Spec.Replicas = pointer.Int32P(1) } - if s.Spec.PodTemplate.Spec.SecurityContext == nil { s.Spec.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{} } - s.Spec.PodTemplate.Spec.SecurityContext.FSGroup = slVersion.Spec.SecurityContext.RunAsUser s.setDefaultContainerSecurityContext(slVersion, &s.Spec.PodTemplate) s.setDefaultContainerResourceLimits(&s.Spec.PodTemplate) @@ -292,7 +334,6 @@ func (s *Solr) setDefaultContainerSecurityContext(slVersion *catalog.SolrVersion } s.assignDefaultContainerSecurityContext(slVersion, initContainer.SecurityContext) podTemplate.Spec.InitContainers = coreutil.UpsertContainer(podTemplate.Spec.InitContainers, *initContainer) - container := coreutil.GetContainerByName(podTemplate.Spec.Containers, SolrContainerName) if container == nil { container = &v1.Container{ @@ -329,7 +370,7 @@ func (s *Solr) assignDefaultContainerSecurityContext(slVersion *catalog.SolrVers func (s *Solr) setDefaultContainerResourceLimits(podTemplate *ofst.PodTemplateSpec) { dbContainer := coreutil.GetContainerByName(podTemplate.Spec.Containers, SolrContainerName) if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) { - apis.SetDefaultResourceLimits(&dbContainer.Resources, DefaultResourcesMemoryIntensive) + apis.SetDefaultResourceLimits(&dbContainer.Resources, DefaultResourcesCoreAndMemoryIntensiveSolr) } initContainer := coreutil.GetContainerByName(podTemplate.Spec.InitContainers, SolrInitContainerName) diff --git a/apis/kubedb/v1alpha2/solr_types.go b/apis/kubedb/v1alpha2/solr_types.go index 67105fad50..a952cbcd7f 100644 --- a/apis/kubedb/v1alpha2/solr_types.go +++ b/apis/kubedb/v1alpha2/solr_types.go @@ -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" ) @@ -122,6 +123,10 @@ type SolrSpec struct { // +kubebuilder:default={periodSeconds: 20, timeoutSeconds: 10, failureThreshold: 3} HealthChecker kmapi.HealthCheckSpec `json:"healthChecker"` + // Monitor is used monitor database instance + // +optional + Monitor *mona.AgentSpec `json:"monitor,omitempty"` + // PodPlacementPolicy is the reference of the podPlacementPolicy // +kubebuilder:default={name: "default"} // +optional diff --git a/apis/kubedb/v1alpha2/zz_generated.deepcopy.go b/apis/kubedb/v1alpha2/zz_generated.deepcopy.go index 3d2697dbad..1edb9868c4 100644 --- a/apis/kubedb/v1alpha2/zz_generated.deepcopy.go +++ b/apis/kubedb/v1alpha2/zz_generated.deepcopy.go @@ -5003,6 +5003,11 @@ func (in *SolrSpec) DeepCopyInto(out *SolrSpec) { } } in.HealthChecker.DeepCopyInto(&out.HealthChecker) + if in.Monitor != nil { + in, out := &in.Monitor, &out.Monitor + *out = new(monitoringagentapiapiv1.AgentSpec) + (*in).DeepCopyInto(*out) + } if in.PodPlacementPolicy != nil { in, out := &in.PodPlacementPolicy, &out.PodPlacementPolicy *out = new(corev1.LocalObjectReference) diff --git a/crds/kubedb.com_solrs.yaml b/crds/kubedb.com_solrs.yaml index a885d3333d..6925b2753f 100644 --- a/crds/kubedb.com_solrs.yaml +++ b/crds/kubedb.com_solrs.yaml @@ -84,6 +84,194 @@ spec: format: int32 type: integer type: object + monitor: + properties: + agent: + enum: + - prometheus.io/operator + - prometheus.io + - prometheus.io/builtin + type: string + prometheus: + properties: + exporter: + properties: + args: + items: + type: string + type: array + env: + items: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + configMapKeyRef: + properties: + key: + type: string + name: + type: string + optional: + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + fieldRef: + properties: + apiVersion: + type: string + fieldPath: + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + resourceFieldRef: + properties: + containerName: + type: string + divisor: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + secretKeyRef: + properties: + key: + type: string + name: + type: string + optional: + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + type: object + required: + - name + type: object + type: array + port: + default: 56790 + format: int32 + type: integer + resources: + properties: + claims: + items: + properties: + name: + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + type: object + securityContext: + properties: + allowPrivilegeEscalation: + type: boolean + capabilities: + properties: + add: + items: + type: string + type: array + drop: + items: + type: string + type: array + type: object + privileged: + type: boolean + procMount: + type: string + readOnlyRootFilesystem: + type: boolean + runAsGroup: + format: int64 + type: integer + runAsNonRoot: + type: boolean + runAsUser: + format: int64 + type: integer + seLinuxOptions: + properties: + level: + type: string + role: + type: string + type: + type: string + user: + type: string + type: object + seccompProfile: + properties: + localhostProfile: + type: string + type: + type: string + required: + - type + type: object + windowsOptions: + properties: + gmsaCredentialSpec: + type: string + gmsaCredentialSpecName: + type: string + hostProcess: + type: boolean + runAsUserName: + type: string + type: object + type: object + type: object + serviceMonitor: + properties: + interval: + type: string + labels: + additionalProperties: + type: string + type: object + type: object + type: object + type: object podPlacementPolicy: default: name: default