Skip to content

Commit

Permalink
Add ready status field
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuCesbron committed Feb 14, 2024
1 parent 57c3357 commit 4aee521
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
12 changes: 11 additions & 1 deletion api/v1/metabase_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ type VolumeSpec struct {
type MetabaseStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Instance ready to accept connections.
// +kubebuilder:validation:default=false
// +kubebuilder:validation:Required
Ready bool `json:"ready"`

// Host to connect to the metabase.
// +kubebuilder:validation:Optional
Host *string `json:"host"`
}

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

// +kubebuilder:validation:Required
Spec MetabaseSpec `json:"spec"`
Spec MetabaseSpec `json:"spec"`

Status MetabaseStatus `json:"status,omitempty"`
}

Expand Down
7 changes: 6 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: metabase-operator
description: Helm chart to deploy [unagex-metabase-operator](https://github.com/unagex/metabase-operator)
type: application
version: 0.0.5
appVersion: 0.0.5
version: 0.0.6
appVersion: 0.0.6
home: https://github.com/unagex/metabase-operator
9 changes: 9 additions & 0 deletions charts/operator/templates/crds/unagex.com_metabases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ spec:
type: object
status:
description: MetabaseStatus defines the observed state of Metabase
properties:
host:
description: Host to connect to the database.
type: string
ready:
description: Instance ready to accept connections.
type: boolean
required:
- ready
type: object
required:
- spec
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/unagex.com_metabases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ spec:
type: object
status:
description: MetabaseStatus defines the observed state of Metabase
properties:
host:
description: Host to connect to the database.
type: string
ready:
description: Instance ready to accept connections.
type: boolean
required:
- ready
type: object
required:
- spec
Expand Down
19 changes: 19 additions & 0 deletions internal/controller/metabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ func (r *MetabaseReconciler) ManageMetabase(ctx context.Context, metabase *unage
return fmt.Errorf("error getting deployment: %w", err)
}

// update status if not sync with deployment
// metabase dep always have one pod
ready := dep.Status.ReadyReplicas == 1
if ready != metabase.Status.Ready {
metabase.Status.Ready = ready
metabase.Status.Host = nil
if ready {
host := fmt.Sprintf("%s-http.%s.svc.cluster.local:3000", metabase.Name, metabase.Namespace)
metabase.Status.Host = &host
}

err = r.Status().Update(ctx, metabase)
if err != nil {
return fmt.Errorf("error updating metabase field status.ready: %w", err)
}

r.Log.Info(fmt.Sprintf("updated metabase field status.ready to %t", ready))
}

return nil
}

Expand Down

0 comments on commit 4aee521

Please sign in to comment.