Skip to content

Commit

Permalink
Merge pull request #77 from utkarsh-pro/utkarsh-pro/feature/patterns-…
Browse files Browse the repository at this point in the history
…meshsync-interrelation

Add pattern resource ID to meshsync object
  • Loading branch information
kumarabd authored Jul 7, 2021
2 parents a477d64 + 3495c7b commit bd05fc2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
15 changes: 8 additions & 7 deletions internal/config/types.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
14 changes: 8 additions & 6 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model

import (
"github.com/google/uuid"
"gorm.io/gorm"
)

Expand All @@ -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"`
Expand Down
7 changes: 7 additions & 0 deletions pkg/model/model_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down

0 comments on commit bd05fc2

Please sign in to comment.