---
apiVersion: template.openshift.io/v1
kind: Template
labels:
  template: cache-service
metadata:
  annotations:
    description: Red Hat Data Grid is an in-memory, distributed key/value store.
    iconClass: icon-datagrid
    openshift.io/display-name: Red Hat Cache Service
    openshift.io/documentation-url: https://access.redhat.com/documentation/en-us/red_hat_data_grid/7.3/html/red_hat_data_grid_for_openshift/
    openshift.io/long-description: Red Hat Data Grid Cache Service is an implementation
      of Data Grid for OpenShift that improves application speed and performance with
      minimal configuration required.
    openshift.io/provider-display-name: Red Hat, Inc.
    openshift.io/support-url: https://www.redhat.com/en/services/support
    samples.operator.openshift.io/version: 4.19.17
    tags: database,datagrid
  creationTimestamp: "2025-10-27T11:40:49Z"
  labels:
    samples.operator.openshift.io/managed: "true"
    template: cache-service
  managedFields:
  - apiVersion: template.openshift.io/v1
    fieldsType: FieldsV1
    fieldsV1:
      f:labels:
        .: {}
        f:template: {}
      f:metadata:
        f:annotations:
          .: {}
          f:description: {}
          f:iconClass: {}
          f:openshift.io/display-name: {}
          f:openshift.io/documentation-url: {}
          f:openshift.io/long-description: {}
          f:openshift.io/provider-display-name: {}
          f:openshift.io/support-url: {}
          f:samples.operator.openshift.io/version: {}
          f:tags: {}
        f:labels:
          .: {}
          f:samples.operator.openshift.io/managed: {}
          f:template: {}
      f:objects: {}
      f:parameters: {}
    manager: cluster-samples-operator
    operation: Update
    time: "2025-10-27T11:40:49Z"
  name: cache-service
  namespace: openshift
  resourceVersion: "19510"
  uid: 4ade1351-0ac9-4af3-b65c-0fe0363b9e6f
objects:
- apiVersion: v1
  kind: Secret
  metadata:
    labels:
      application: ${APPLICATION_NAME}
    name: ${APPLICATION_NAME}
  stringData:
    application-password: ${APPLICATION_PASSWORD}
    application-user: ${APPLICATION_USER}
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      description: Provides a ping service for clustered applications.
      service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
    labels:
      application: ${APPLICATION_NAME}
    name: ${APPLICATION_NAME}-ping
  spec:
    clusterIP: None
    ports:
    - name: ping
      port: 8888
    publishNotReadyAddresses: true
    selector:
      deploymentConfig: ${APPLICATION_NAME}
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      description: Provides a service for accessing the application over HTTPS or
        Hot Rod protocol.
      service.alpha.openshift.io/serving-cert-secret-name: service-certs
    labels:
      application: ${APPLICATION_NAME}
    name: ${APPLICATION_NAME}
  spec:
    ports:
    - name: hotrod
      port: 11222
      targetPort: 11222
    - name: https
      port: 8443
      targetPort: 8443
    selector:
      deploymentConfig: ${APPLICATION_NAME}
- apiVersion: apps/v1
  kind: StatefulSet
  metadata:
    labels:
      application: ${APPLICATION_NAME}
    name: ${APPLICATION_NAME}
  spec:
    replicas: ${{NUMBER_OF_INSTANCES}}
    selector:
      matchLabels:
        application: ${APPLICATION_NAME}
    serviceName: ${APPLICATION_NAME}-ping
    strategy:
      rollingParams:
        intervalSeconds: 20
        maxSurge: 1
        maxUnavailable: 1
        timeoutSeconds: 1200
        updatePeriodSeconds: 20
      type: Rolling
    template:
      metadata:
        labels:
          application: ${APPLICATION_NAME}
          deploymentConfig: ${APPLICATION_NAME}
        name: ${APPLICATION_NAME}
      spec:
        containers:
        - env:
          - name: SERVICE_NAME
            value: ${APPLICATION_NAME}
          - name: SERVICE_PROFILE
            value: cache-service
          - name: JGROUPS_PING_PROTOCOL
            value: openshift.DNS_PING
          - name: OPENSHIFT_DNS_PING_SERVICE_NAME
            value: ${APPLICATION_NAME}-ping
          - name: USERNAME
            valueFrom:
              secretKeyRef:
                key: application-user
                name: ${APPLICATION_NAME}
          - name: PASSWORD
            valueFrom:
              secretKeyRef:
                key: application-password
                name: ${APPLICATION_NAME}
          - name: REPLICATION_FACTOR
            value: ${REPLICATION_FACTOR}
          - name: EVICTION_POLICY
            value: ${EVICTION_POLICY}
          image: ${IMAGE}
          livenessProbe:
            exec:
              command:
              - /opt/datagrid/bin/livenessProbe.sh
            failureThreshold: 5
            initialDelaySeconds: 15
            periodSeconds: 20
            successThreshold: 1
            timeoutSeconds: 10
          name: ${APPLICATION_NAME}
          ports:
          - containerPort: 8443
            name: https
            protocol: TCP
          - containerPort: 8888
            name: ping
            protocol: TCP
          - containerPort: 11222
            name: hotrod
            protocol: TCP
          readinessProbe:
            exec:
              command:
              - /opt/datagrid/bin/readinessProbe.sh
            failureThreshold: 5
            initialDelaySeconds: 17
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10
          resources:
            limits:
              memory: ${TOTAL_CONTAINER_MEM}Mi
            requests:
              cpu: "0.5"
              memory: ${TOTAL_CONTAINER_MEM}Mi
          volumeMounts:
          - mountPath: /opt/datagrid/standalone/data
            name: srv-data
          - mountPath: /var/run/secrets/java.io/keystores
            name: keystore-volume
          - mountPath: /var/run/secrets/openshift.io/serviceaccount
            name: service-certs
        terminationGracePeriodSeconds: 60
        volumes:
        - empty-dir: {}
          name: keystore-volume
        - name: service-certs
          secret:
            secretName: service-certs
    triggers:
    - type: ConfigChange
    volumeClaimTemplates:
    - metadata:
        name: srv-data
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
parameters:
- description: Specifies a name for the application.
  displayName: Application Name
  name: APPLICATION_NAME
  required: true
  value: cache-service
- description: Sets an image to bootstrap the service.
  name: IMAGE
  required: true
  value: registry.redhat.io/jboss-datagrid-7/datagrid73-openshift
- description: Specifies how many instances of the application to create in the cluster.
  displayName: Number of Instances
  name: NUMBER_OF_INSTANCES
  required: true
  value: "1"
- description: Specifies the number of copies for each data entry.
  displayName: Replication Factor
  name: REPLICATION_FACTOR
  required: true
  value: "1"
- description: Defines the action to take when the cache size reaches the available
    memory.
  displayName: Eviction Policy
  name: EVICTION_POLICY
  required: true
  value: evict
- description: Sets the total memory, in MiB, available to the application.
  displayName: Total Memory
  name: TOTAL_CONTAINER_MEM
  value: "512"
- description: Specifies a username to authenticate client applications.
  displayName: Client User
  name: APPLICATION_USER
  required: true
- description: Sets a password to authenticate client applications.
  displayName: Client Password
  from: '[a-zA-Z0-9]{16}'
  generate: expression
  name: APPLICATION_PASSWORD
