diff --git a/api/proxy.go b/api/proxy.go index 92d8eef..3b124bc 100644 --- a/api/proxy.go +++ b/api/proxy.go @@ -338,7 +338,7 @@ func serverPrint(items []interface{}) interface{} { indexMap := map[string]int{} for i, item := range items { if oo, ok := item.(v1.Object); ok { - indexesStr := oo.GetAnnotations()["anno.dsm.daocloud.io/indexes"] + indexesStr := oo.GetAnnotations()[constants.IndexAnno] if len(indexesStr) == 0 { continue } diff --git a/common/constants/ckube.go b/common/constants/ckube.go index ed9c777..82abf0b 100644 --- a/common/constants/ckube.go +++ b/common/constants/ckube.go @@ -11,6 +11,7 @@ const ( SearchPartsSep = ';' DSMClusterAnno = "ckube.doacloud.io/cluster" ClusterPrefix = "dsm-cluster-" + IndexAnno = "ckube.daocloud.io/indexes" ) var ( @@ -24,4 +25,5 @@ var ( _ = SearchPartsSep _ = DSMClusterAnno _ = ClusterPrefix + _ = IndexAnno ) diff --git a/store/memory/memory.go b/store/memory/memory.go index f29f474..dd2079c 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -357,7 +357,7 @@ func (m *memoryStore) buildResourceWithIndex(gvr store.GroupVersionResource, clu } anno := oo.GetAnnotations() index, _ := json.Marshal(s.Index) - anno["anno.dsm.daocloud.io/indexes"] = string(index) // todo constants + anno[constants.IndexAnno] = string(index) // todo constants oo.SetAnnotations(anno) s.Obj = oo } diff --git a/store/memory/memory_test.go b/store/memory/memory_test.go index 4ddf148..2f44b53 100644 --- a/store/memory/memory_test.go +++ b/store/memory/memory_test.go @@ -79,6 +79,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "test", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test1\",\"namespace\":\"test\",\"uid\":\"test\"}", }, }, }), @@ -117,6 +118,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "test", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test2\",\"namespace\":\"test\",\"uid\":\"test\"}", }, }, }), @@ -160,6 +162,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "test", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"hello\",\"namespace\":\"test\",\"uid\":\"test\"}", }, }, }, &v1.Pod{ @@ -169,6 +172,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "test", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"llo\",\"namespace\":\"test\",\"uid\":\"test\"}", }, }, }), @@ -212,6 +216,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "test", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"llo\",\"namespace\":\"test\",\"uid\":\"test\"}", }, }, }), @@ -288,6 +293,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "test", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"hello\",\"namespace\":\"test\",\"uid\":\"test\"}", }, }, }, &v1.Pod{ @@ -297,6 +303,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "test", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"l1lo\",\"namespace\":\"test\",\"uid\":\"test\"}", }, }, }), @@ -394,6 +401,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "1", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test5\",\"namespace\":\"test\",\"uid\":\"1\"}", }, }, }, &v1.Pod{ @@ -403,6 +411,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "2", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test1\",\"namespace\":\"test\",\"uid\":\"2\"}", }, }, }, &v1.Pod{ @@ -412,6 +421,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "3", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test3\",\"namespace\":\"test\",\"uid\":\"3\"}", }, }, }), @@ -455,6 +465,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "3", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test3\",\"namespace\":\"test\",\"uid\":\"3\"}", }, }, }, &v1.Pod{ @@ -464,6 +475,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "2", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test1\",\"namespace\":\"test\",\"uid\":\"2\"}", }, }, }, &v1.Pod{ @@ -473,6 +485,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "1", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test5\",\"namespace\":\"test\",\"uid\":\"1\"}", }, }, }), @@ -543,6 +556,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "3", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test3\",\"namespace\":\"test\",\"uid\":\"3\"}", }, }, }, &v1.Pod{ @@ -552,6 +566,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "2", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test1\",\"namespace\":\"test\",\"uid\":\"2\"}", }, }, }, &v1.Pod{ @@ -561,6 +576,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "1", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test5\",\"namespace\":\"test1\",\"uid\":\"1\"}", }, }, }), @@ -604,6 +620,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "2", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test5\",\"namespace\":\"test\",\"uid\":\"2\"}", }, }, }, &v1.Pod{ @@ -613,6 +630,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "3", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test3\",\"namespace\":\"test\",\"uid\":\"3\"}", }, }, }, &v1.Pod{ @@ -622,6 +640,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "11", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test1\",\"namespace\":\"test\",\"uid\":\"11\"}", }, }, }), @@ -692,6 +711,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "3", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test3\",\"namespace\":\"test\",\"uid\":\"3\"}", }, }, }, &v1.Pod{ @@ -701,6 +721,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "11", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test1\",\"namespace\":\"test\",\"uid\":\"11\"}", }, }, }, &v1.Pod{ @@ -710,6 +731,7 @@ func TestMemoryStore_Query(t *testing.T) { UID: "20", Annotations: map[string]string{ constants.DSMClusterAnno: "", + constants.IndexAnno: "{\"cluster\":\"\",\"is_deleted\":\"false\",\"name\":\"test13\",\"namespace\":\"test1\",\"uid\":\"20\"}", }, }, }),