From 3495c7bb9982c2dadab008415830ef8388e10627 Mon Sep 17 00:00:00 2001 From: Utkarsh Srivastava Date: Fri, 2 Jul 2021 21:24:58 +0530 Subject: [PATCH] add pattern resource ID to meshsync object Signed-off-by: Utkarsh Srivastava --- internal/config/types.go | 15 ++++++++------- pkg/model/model.go | 14 ++++++++------ pkg/model/model_converter.go | 7 +++++++ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/internal/config/types.go b/internal/config/types.go index 16b69639..8ebc7929 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -1,13 +1,14 @@ package config const ( - ServerKey = "server-config" - PipelineNameKey = "meshsync-pipeline" - ResourcesKey = "resources" - GlobalResourceKey = "global" - LocalResourceKey = "local" - ListenersKey = "listeners" - LogStreamsKey = "log-streams" + ServerKey = "server-config" + PipelineNameKey = "meshsync-pipeline" + ResourcesKey = "resources" + GlobalResourceKey = "global" + LocalResourceKey = "local" + ListenersKey = "listeners" + LogStreamsKey = "log-streams" + PatternResourceIDLabelKey = "resource.pattern.meshery.io/id" BrokerURL = "broker-url" RequestStream = "request-stream" diff --git a/pkg/model/model.go b/pkg/model/model.go index b5599e07..a7947103 100644 --- a/pkg/model/model.go +++ b/pkg/model/model.go @@ -1,6 +1,7 @@ package model import ( + "github.com/google/uuid" "gorm.io/gorm" ) @@ -10,12 +11,13 @@ const ( ) type Object struct { - ID string `json:"id" gorm:"primarykey"` - APIVersion string `json:"apiVersion" gorm:"index"` - Kind string `json:"kind" gorm:"index"` - ObjectMeta *ResourceObjectMeta `json:"metadata" gorm:"foreignkey:ID;references:id;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` - Spec *ResourceSpec `json:"spec,omitempty" gorm:"foreignkey:ID;references:id;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` - Status *ResourceStatus `json:"status,omitempty" gorm:"foreignkey:ID;references:id;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` + ID string `json:"id" gorm:"primarykey"` + APIVersion string `json:"apiVersion" gorm:"index"` + Kind string `json:"kind" gorm:"index"` + ObjectMeta *ResourceObjectMeta `json:"metadata" gorm:"foreignkey:ID;references:id;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` + Spec *ResourceSpec `json:"spec,omitempty" gorm:"foreignkey:ID;references:id;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` + Status *ResourceStatus `json:"status,omitempty" gorm:"foreignkey:ID;references:id;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` + PatternResource *uuid.UUID `json:"pattern_resource"` // Secondary fields for configsmaps and secrets Immutable string `json:"immutable,omitempty"` diff --git a/pkg/model/model_converter.go b/pkg/model/model_converter.go index 8aa77af0..f180ea6c 100644 --- a/pkg/model/model_converter.go +++ b/pkg/model/model_converter.go @@ -7,6 +7,7 @@ import ( "github.com/buger/jsonparser" "github.com/google/uuid" "github.com/layer5io/meshkit/utils" + "github.com/layer5io/meshsync/internal/config" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -24,6 +25,12 @@ func ParseList(object unstructured.Unstructured) Object { Key: string(key), Value: string(value), }) + + if string(key) == config.PatternResourceIDLabelKey { + id, _ := uuid.FromBytes(value) + result.PatternResource = &id + } + return nil }, "metadata", "labels") result.ObjectMeta.Labels = labels