This is an automated email from the ASF dual-hosted git repository.

zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git


The following commit(s) were added to refs/heads/master by this push:
     new 5bf6e649 [operator] Add collection schemas logic
5bf6e649 is described below

commit 5bf6e64901ed6ff84ea452e975616b83194837dd
Author: mfordjody <[email protected]>
AuthorDate: Tue Dec 17 12:32:09 2024 +0800

    [operator] Add collection schemas logic
---
 operator/pkg/schema/schema.go  |  3 +--
 pkg/kube/collection/schemas.go | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/operator/pkg/schema/schema.go b/operator/pkg/schema/schema.go
index e03e0cc1..cc349f6b 100644
--- a/operator/pkg/schema/schema.go
+++ b/operator/pkg/schema/schema.go
@@ -26,8 +26,7 @@ func (s *schemaImpl) GroupVersionAliasKinds() 
[]config.GroupVersionKind {
 }
 
 func (s *schemaImpl) IsClusterScoped() bool {
-       //TODO implement me
-       panic("implement me")
+       return s.clusterScoped
 }
 
 func (s *schemaImpl) Kind() string {
diff --git a/pkg/kube/collection/schemas.go b/pkg/kube/collection/schemas.go
index 2a824e3a..8b4f72ba 100644
--- a/pkg/kube/collection/schemas.go
+++ b/pkg/kube/collection/schemas.go
@@ -1,7 +1,39 @@
 package collection
 
+import (
+       "fmt"
+       "github.com/apache/dubbo-kubernetes/operator/pkg/config"
+       "github.com/apache/dubbo-kubernetes/operator/pkg/schema"
+)
+
 type Schemas struct {
+       byCollection map[config.GroupVersionKind]schema.Schema
+       byAddOrder   []schema.Schema
 }
 
 type SchemasBuilder struct {
-}
\ No newline at end of file
+       schemas Schemas
+}
+
+func NewSchemasBuilder() *SchemasBuilder {
+       s := Schemas{
+               byCollection: make(map[config.GroupVersionKind]schema.Schema),
+       }
+       return &SchemasBuilder{schemas: s}
+}
+
+func (b *SchemasBuilder) Add(s schema.Schema) error {
+       if _, found := b.schemas.byCollection[s.GroupVersionKind()]; found {
+               return fmt.Errorf("collection already exists: %v", 
s.GroupVersionKind())
+       }
+       b.schemas.byCollection[s.GroupVersionKind()] = s
+       b.schemas.byAddOrder = append(b.schemas.byAddOrder, s)
+       return nil
+}
+
+func (b *SchemasBuilder) MustAdd(s schema.Schema) *SchemasBuilder {
+       if err := b.Add(s); err != nil {
+               panic(fmt.Sprintf("SchemasBuilder.MustAdd: %v", err))
+       }
+       return b
+}

Reply via email to