# Discovery

The Stackable Operator for Apache Hive publishes a discovery [ConfigMap](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#configmap-v1-core), which exposes a client configuration bundle that allows access to the Apache Hive cluster.

The bundle includes an Apache Thrift connection string to access the Hive Metastore service. This string may be used by other operators or tools to configure their products with access to Hive. Access is limited to services within the same Kubernetes cluster.

## Example

Given the following Hive cluster:

```yaml
apiVersion: hive.stackable.tech/v1alpha1
kind: HiveCluster
metadata:
  name: {clusterName} (1)
  namespace: {namespace} (2)
spec:
  clusterConfig:
    metadataDatabase:
      postgresql:
        host: postgresql
        database: hive
        credentialsSecretName: hive-credentials
  metastore:
    roleGroups:
      default: (3)
        replicas: 2
---
apiVersion: v1
kind: Secret
metadata:
  name: hive-credentials
type: Opaque
stringData:
  username: hive
  password: hive
```

(1) The name of the Hive cluster, which is also the name of the created discovery ConfigMap.
(2) The namespace of the discovery ConfigMap.
(3) A role group name of the metastore role.

The resulting discovery ConfigMap is `{namespace}/{clusterName}`.

## Contents

### Internal access

The `{namespace}/{clusterName}` discovery ConfigMap contains the following fields where `{clusterName}` represents the name, `{namespace}` the namespace of the cluster and `{roleGroup}` a role group of the `metastore` role:

`HIVE`

Contains the thrift protocol connection string for the Hive metastore service:

```
thrift://{clusterName}.{namespace}.svc.cluster.local:9083
```

> **Warning:** Using the Hive metastore in high availability mode (replicas > 1) does not work with Derby but instead requires a properly configured database like PostgreSQL or MySQL.

### External access

If `spec.clusterConfig.listenerClass` is set to `external-unstable` an additional ConfigMap is generated to expose external access to the cluster. This discovery ConfigMap is reachable via `{namespace}/{clusterName}-nodeport`.

Contains the thrift protocol connection string for the Hive metastore NodePort service:

```
thrift://<node-ip>:<nodeport>
thrift://<other-node-ip>:<nodeport>
```
