Skip to content

Commit

Permalink
refactor: add ServiceRef in XlineCluster resource's status
Browse files Browse the repository at this point in the history
Signed-off-by: Phoeniix Zhao <[email protected]>
  • Loading branch information
Phoenix500526 committed Nov 28, 2023
1 parent 149d5a8 commit 06260b1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/xlinecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type XlineClusterRecStatus struct {
type XlineClusterSyncStatus struct {
Image string `json:"image,omitempty"`
StatefulSetRef NamespacedName `json:"statefulSetRef,omitempty"`
ServiceRef NamespacedName `json:"serviceRef,omitempty"`
Members []string `json:"members,omitempty"`
// ReadyMembers []string `json:"readyMembers,omitempty"`
Conditions []appv1.StatefulSetCondition `json:"conditions,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ spec:
items:
type: string
type: array
serviceRef:
description: NamespacedName is the name and namespace of the kubernetes
object
properties:
name:
type: string
namespace:
type: string
type: object
stage:
description: XlineClusterOprStage represents XlineCluster operator
stage
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module github.com/xline-kv/xline-operator
go 1.20

require (
github.com/go-logr/logr v1.2.4
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.10
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
sigs.k8s.io/controller-runtime v0.16.3
Expand All @@ -17,7 +19,6 @@ require (
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand Down Expand Up @@ -61,7 +62,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.28.3 // indirect
k8s.io/apiextensions-apiserver v0.28.3 // indirect
k8s.io/component-base v0.28.3 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
Expand Down
13 changes: 12 additions & 1 deletion internal/reconciler/cluster_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
xapi "github.com/xline-kv/xline-operator/api/v1alpha1"
tran "github.com/xline-kv/xline-operator/internal/transformer"
appv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)

// Sync all subcomponents status.
Expand All @@ -17,10 +18,20 @@ func (r *XlineClusterReconciler) Sync() (xapi.XlineClusterSyncStatus, error) {

// sync XlineCluster status
func (r *XlineClusterReconciler) syncXlineStatus(xlineStatus *xapi.XlineClusterSyncStatus) error {
svcRef := tran.GetServiceKey(r.CR.ObjKey())
svc := &corev1.Service{}
exist, err := r.Exist(svcRef, svc)
if err != nil {
return err
}
if exist {
xlineStatus.ServiceRef = xapi.NewNamespacedName(svcRef)
}

stsRef := tran.GetStatefulSetKey(r.CR.ObjKey())
// collect members status via ref statefulset
sts := &appv1.StatefulSet{}
exist, err := r.Exist(stsRef, sts)
exist, err = r.Exist(stsRef, sts)
if err != nil {
return err
}
Expand Down

0 comments on commit 06260b1

Please sign in to comment.