diff --git a/api/v1alpha1/xlinecluster_types.go b/api/v1alpha1/xlinecluster_types.go index cfe66ff4..87d73725 100644 --- a/api/v1alpha1/xlinecluster_types.go +++ b/api/v1alpha1/xlinecluster_types.go @@ -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"` diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 74cd8f3e..02d68500 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -21,7 +21,7 @@ limitations under the License. package v1alpha1 import ( - "k8s.io/api/apps/v1" + v1 "k8s.io/api/apps/v1" runtime "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" ) @@ -166,6 +166,7 @@ func (in *XlineClusterStatus) DeepCopy() *XlineClusterStatus { func (in *XlineClusterSyncStatus) DeepCopyInto(out *XlineClusterSyncStatus) { *out = *in out.StatefulSetRef = in.StatefulSetRef + out.ServiceRef = in.ServiceRef if in.Members != nil { in, out := &in.Members, &out.Members *out = make([]string, len(*in)) diff --git a/config/crd/bases/xline.kvstore.datenlord.com_xlineclusters.yaml b/config/crd/bases/xline.kvstore.datenlord.com_xlineclusters.yaml index bf293da1..733d341c 100644 --- a/config/crd/bases/xline.kvstore.datenlord.com_xlineclusters.yaml +++ b/config/crd/bases/xline.kvstore.datenlord.com_xlineclusters.yaml @@ -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 diff --git a/go.mod b/go.mod index b5211be5..f9bc4ada 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 @@ -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 diff --git a/internal/reconciler/cluster_sync.go b/internal/reconciler/cluster_sync.go index 499bb211..ce79c334 100644 --- a/internal/reconciler/cluster_sync.go +++ b/internal/reconciler/cluster_sync.go @@ -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. @@ -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 }