Skip to content

Commit

Permalink
Add hosts in immudb status
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuCesbron committed Feb 10, 2024
1 parent ebc0b05 commit b44e0c5
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 9 deletions.
19 changes: 17 additions & 2 deletions api/v1/immudb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,26 @@ type ImmudbVolumeSpec struct {
type ImmudbStatus struct {
// Important: Run "make" to regenerate code after modifying this file

// Number of ready replicas
// Number of ready replicas.
ReadyReplicas int32 `json:"readyReplicas"`

// Instance ready to accept connections
// Instance ready to accept connections.
Ready bool `json:"ready"`

// Hosts to connect to the database.
// +kubebuilder:validation:Optional
Hosts *HostsStatus `json:"hosts"`
}

type HostsStatus struct {
// +kubebuilder:validation:Required
HTTP string `json:"HTTP"`

// +kubebuilder:validation:Required
Metrics string `json:"Metrics"`

// +kubebuilder:validation:Required
GRPC string `json:"GRPC"`
}

//+kubebuilder:object:root=true
Expand Down
22 changes: 21 additions & 1 deletion api/v1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions charts/operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ apiVersion: v2
name: immudb-operator
description: Helm chart to deploy [unagex-immudb-operator](https://github.com/unagex/immudb-operator)
type: application
version: 0.0.4
appVersion: 0.0.4
version: 0.0.5
appVersion: 0.0.5
home: https://github.com/unagex/immudb-operator
18 changes: 16 additions & 2 deletions charts/operator/templates/crds/unagex.com_immudbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,25 @@ spec:
status:
description: ImmudbStatus defines the observed state of Immudb
properties:
hosts:
description: Hosts to connect to the database.
properties:
GRPC:
type: string
HTTP:
type: string
Metrics:
type: string
required:
- GRPC
- HTTP
- Metrics
type: object
ready:
description: Instance ready to accept connections
description: Instance ready to accept connections.
type: boolean
readyReplicas:
description: Number of ready replicas
description: Number of ready replicas.
format: int32
type: integer
required:
Expand Down
18 changes: 16 additions & 2 deletions config/crd/bases/unagex.com_immudbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,25 @@ spec:
status:
description: ImmudbStatus defines the observed state of Immudb
properties:
hosts:
description: Hosts to connect to the database.
properties:
GRPC:
type: string
HTTP:
type: string
Metrics:
type: string
required:
- GRPC
- HTTP
- Metrics
type: object
ready:
description: Instance ready to accept connections
description: Instance ready to accept connections.
type: boolean
readyReplicas:
description: Number of ready replicas
description: Number of ready replicas.
format: int32
type: integer
required:
Expand Down
8 changes: 8 additions & 0 deletions internal/controller/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ func (r *ImmudbReconciler) ManageDatabase(ctx context.Context, immudb *unagexcom
if diff {
immudb.Status.ReadyReplicas = sts.Status.ReadyReplicas
immudb.Status.Ready = false
immudb.Status.Hosts = nil

// TODO: instance is ready if quorum and not if different.
if immudb.Status.ReadyReplicas == *immudb.Spec.Replicas {
immudb.Status.Ready = true
immudb.Status.Hosts = &unagexcomv1.HostsStatus{
HTTP: fmt.Sprintf("%s-http.%s.svc.cluster.local:8080", immudb.Name, immudb.Namespace),
Metrics: fmt.Sprintf("%s-http.%s.svc.cluster.local:9497/metrics", immudb.Name, immudb.Namespace),
GRPC: fmt.Sprintf("%s-grpc.%s.svc.cluster.local:3322", immudb.Name, immudb.Namespace),
}
}

err = r.Status().Update(ctx, immudb)
if err != nil {
return fmt.Errorf("error updating immudb field status.readyReplicas: %w", err)
Expand Down

0 comments on commit b44e0c5

Please sign in to comment.