Skip to content

Commit 4aee521

Browse files
Add ready status field
1 parent 57c3357 commit 4aee521

File tree

6 files changed

+56
-4
lines changed

6 files changed

+56
-4
lines changed

api/v1/metabase_types.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ type VolumeSpec struct {
9797
type MetabaseStatus struct {
9898
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
9999
// Important: Run "make" to regenerate code after modifying this file
100+
101+
// Instance ready to accept connections.
102+
// +kubebuilder:validation:default=false
103+
// +kubebuilder:validation:Required
104+
Ready bool `json:"ready"`
105+
106+
// Host to connect to the metabase.
107+
// +kubebuilder:validation:Optional
108+
Host *string `json:"host"`
100109
}
101110

102111
//+kubebuilder:object:root=true
@@ -108,7 +117,8 @@ type Metabase struct {
108117
metav1.ObjectMeta `json:"metadata,omitempty"`
109118

110119
// +kubebuilder:validation:Required
111-
Spec MetabaseSpec `json:"spec"`
120+
Spec MetabaseSpec `json:"spec"`
121+
112122
Status MetabaseStatus `json:"status,omitempty"`
113123
}
114124

api/v1/zz_generated.deepcopy.go

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/operator/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ apiVersion: v2
22
name: metabase-operator
33
description: Helm chart to deploy [unagex-metabase-operator](https://github.com/unagex/metabase-operator)
44
type: application
5-
version: 0.0.5
6-
appVersion: 0.0.5
5+
version: 0.0.6
6+
appVersion: 0.0.6
77
home: https://github.com/unagex/metabase-operator

charts/operator/templates/crds/unagex.com_metabases.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ spec:
204204
type: object
205205
status:
206206
description: MetabaseStatus defines the observed state of Metabase
207+
properties:
208+
host:
209+
description: Host to connect to the database.
210+
type: string
211+
ready:
212+
description: Instance ready to accept connections.
213+
type: boolean
214+
required:
215+
- ready
207216
type: object
208217
required:
209218
- spec

config/crd/bases/unagex.com_metabases.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ spec:
204204
type: object
205205
status:
206206
description: MetabaseStatus defines the observed state of Metabase
207+
properties:
208+
host:
209+
description: Host to connect to the database.
210+
type: string
211+
ready:
212+
description: Instance ready to accept connections.
213+
type: boolean
214+
required:
215+
- ready
207216
type: object
208217
required:
209218
- spec

internal/controller/metabase.go

+19
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ func (r *MetabaseReconciler) ManageMetabase(ctx context.Context, metabase *unage
4242
return fmt.Errorf("error getting deployment: %w", err)
4343
}
4444

45+
// update status if not sync with deployment
46+
// metabase dep always have one pod
47+
ready := dep.Status.ReadyReplicas == 1
48+
if ready != metabase.Status.Ready {
49+
metabase.Status.Ready = ready
50+
metabase.Status.Host = nil
51+
if ready {
52+
host := fmt.Sprintf("%s-http.%s.svc.cluster.local:3000", metabase.Name, metabase.Namespace)
53+
metabase.Status.Host = &host
54+
}
55+
56+
err = r.Status().Update(ctx, metabase)
57+
if err != nil {
58+
return fmt.Errorf("error updating metabase field status.ready: %w", err)
59+
}
60+
61+
r.Log.Info(fmt.Sprintf("updated metabase field status.ready to %t", ready))
62+
}
63+
4564
return nil
4665
}
4766

0 commit comments

Comments
 (0)