From 642a5e3b0b15bf8a260dcda728eb0f3e5cad35bf Mon Sep 17 00:00:00 2001 From: Lency Qian Date: Tue, 30 Jul 2024 14:17:29 +0800 Subject: [PATCH] schema reference --- k8s/apis/federation/v1/catalog_webhook.go | 7 +++++-- test/integration/scenarios/05.catalog/catalogs/config.yaml | 2 +- .../scenarios/05.catalog/catalogs/wrongconfig.yaml | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/k8s/apis/federation/v1/catalog_webhook.go b/k8s/apis/federation/v1/catalog_webhook.go index 443c7f23f..c6a3dc990 100644 --- a/k8s/apis/federation/v1/catalog_webhook.go +++ b/k8s/apis/federation/v1/catalog_webhook.go @@ -12,9 +12,11 @@ import ( "gopls-workspace/apis/metrics/v1" commoncontainer "gopls-workspace/apis/model/v1" "gopls-workspace/configutils" + "gopls-workspace/utils" "time" - "github.com/eclipse-symphony/symphony/api/pkg/apis/v1alpha1/utils" + api_utils "github.com/eclipse-symphony/symphony/api/pkg/apis/v1alpha1/utils" + "github.com/eclipse-symphony/symphony/k8s/constants" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -170,6 +172,7 @@ func (r *Catalog) validateCreateCatalog() error { func (r *Catalog) checkSchema() *field.Error { if r.Spec.Metadata != nil { if schemaName, ok := r.Spec.Metadata["schema"]; ok { + schemaName = utils.ReplaceLastSeperator(schemaName, ":", constants.ResourceSeperator) cataloglog.Info("Find schema name", "name", schemaName) var catalogs CatalogList err := myCatalogReaderClient.List(context.Background(), &catalogs, client.InNamespace(r.ObjectMeta.Namespace), client.MatchingFields{"metadata.name": schemaName}, client.Limit(1)) @@ -186,7 +189,7 @@ func (r *Catalog) checkSchema() *field.Error { return field.Invalid(field.NewPath("spec").Child("properties"), schemaName, "invalid catalog properties") } if spec, ok := properties["spec"]; ok { - var schemaObj utils.Schema + var schemaObj api_utils.Schema jData, _ := json.Marshal(spec) err := json.Unmarshal(jData, &schemaObj) if err != nil { diff --git a/test/integration/scenarios/05.catalog/catalogs/config.yaml b/test/integration/scenarios/05.catalog/catalogs/config.yaml index 05c65c7d5..1da62d0f1 100644 --- a/test/integration/scenarios/05.catalog/catalogs/config.yaml +++ b/test/integration/scenarios/05.catalog/catalogs/config.yaml @@ -6,6 +6,6 @@ spec: rootResource: config catalogType: config metadata: - schema: schema-v-v1 + schema: schema:v1 properties: email: "sample@sample.com" \ No newline at end of file diff --git a/test/integration/scenarios/05.catalog/catalogs/wrongconfig.yaml b/test/integration/scenarios/05.catalog/catalogs/wrongconfig.yaml index ed258f93e..f97a2a883 100644 --- a/test/integration/scenarios/05.catalog/catalogs/wrongconfig.yaml +++ b/test/integration/scenarios/05.catalog/catalogs/wrongconfig.yaml @@ -5,6 +5,6 @@ metadata: spec: catalogType: config metadata: - schema: schema-v-v1 + schema: schema:v1 properties: email: "this is an invalid email" \ No newline at end of file