# services/logging/opensearch-helmrelease.yaml
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: opensearch
  namespace: logging
spec:
  interval: 15m
  timeout: 20m
  install:
    remediation:
      retries: 3
  upgrade:
    cleanupOnFail: true
    remediation:
      retries: 3
      strategy: rollback
  postRenderers:
    - kustomize:
        patches:
          - target:
              kind: StatefulSet
              name: opensearch
            patch: |
              - op: add
                path: /spec/template/spec/containers/0/resources/limits/cpu
                value: "2"
              - op: replace
                path: /spec/template/spec/initContainers/0/resources
                value:
                  requests:
                    cpu: "10m"
                    memory: "32Mi"
                  limits:
                    cpu: "500m"
                    memory: "512Mi"
              - op: replace
                path: /spec/template/spec/initContainers/1/resources
                value:
                  requests:
                    cpu: "10m"
                    memory: "32Mi"
                  limits:
                    cpu: "500m"
                    memory: "512Mi"
              - op: replace
                path: /spec/template/spec/initContainers/2/resources
                value:
                  requests:
                    cpu: "10m"
                    memory: "32Mi"
                  limits:
                    cpu: "500m"
                    memory: "512Mi"
  chart:
    spec:
      chart: opensearch
      version: "~2.36.0"
      sourceRef:
        kind: HelmRepository
        name: opensearch
        namespace: flux-system
  values:
    fullnameOverride: opensearch
    clusterName: opensearch
    nodeGroup: master
    masterService: opensearch-master
    singleNode: true
    replicas: 1
    minimumMasterNodes: 1
    opensearchJavaOpts: "-Xms2g -Xmx2g"
    resources:
      requests:
        cpu: "25m"
        memory: "768Mi"
      limits:
        cpu: "2"
        memory: "4Gi"
    persistence:
      enabled: true
      storageClass: asteria
      size: 500Gi
    config:
      opensearch.yml: |
        cluster.name: opensearch
        network.host: 0.0.0.0
        discovery.type: single-node
        plugins.security.disabled: true
        node.store.allow_mmap: false
    nodeSelector:
      node-role.kubernetes.io/worker: "true"
      hardware: rpi5
      kubernetes.io/hostname: titan-05
    affinity:
      nodeAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
          nodeSelectorTerms:
            - matchExpressions:
                - key: hardware
                  operator: In
                  values:
                    - rpi5
    sysctlInit:
      enabled: true
