Skip to content

Commit 1a3da59

Browse files
authored
Merge pull request #500 from kube-tarian/postgres-fix
handle db insert when first resource add cases
2 parents 0f8e275 + 943f687 commit 1a3da59

File tree

15 files changed

+89
-14
lines changed

15 files changed

+89
-14
lines changed

capten/agent/internal/api/container_registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (a *Agent) AddContainerRegistry(ctx context.Context, request *captenplugins
6363
Labels: request.Labels,
6464
RegistryType: request.RegistryType,
6565
}
66-
if err := a.as.UpsertContainerRegistry(&ContainerRegistry); err != nil {
66+
if err := a.as.AddContainerRegistry(&ContainerRegistry); err != nil {
6767
a.log.Errorf("failed to store Container registry to DB, %v", err)
6868
return &captenpluginspb.AddContainerRegistryResponse{
6969
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,

capten/agent/internal/api/plugin_cloud_provider_apis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (a *Agent) AddCloudProvider(ctx context.Context, request *captenpluginspb.A
3636
CloudType: request.CloudType,
3737
Labels: request.Labels,
3838
}
39-
if err := a.as.UpsertCloudProvider(&CloudProvider); err != nil {
39+
if err := a.as.AddCloudProvider(&CloudProvider); err != nil {
4040
a.log.Errorf("failed to store cloud provider to DB, %v", err)
4141
return &captenpluginspb.AddCloudProviderResponse{
4242
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,

capten/agent/internal/api/plugin_crossplane_provider_apis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (a *Agent) AddCrossplanProvider(ctx context.Context, request *captenplugins
4747
Status: string(model.CrossPlaneProviderOutofSynch),
4848
}
4949

50-
if err := a.as.UpsertCrossplaneProvider(&provider); err != nil {
50+
if err := a.as.AddCrossplaneProvider(&provider); err != nil {
5151
a.log.Errorf("failed to store crossplane provider to DB, %v", err)
5252
return &captenpluginspb.AddCrossplanProviderResponse{
5353
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,

capten/agent/internal/api/plugin_git_apis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (a *Agent) AddGitProject(ctx context.Context, request *captenpluginspb.AddG
5050
ProjectUrl: request.ProjectUrl,
5151
Labels: request.Labels,
5252
}
53-
if err := a.as.UpsertGitProject(&gitProject); err != nil {
53+
if err := a.as.AddGitProject(&gitProject); err != nil {
5454
a.log.Errorf("failed to store git project to DB, %v", err)
5555
return &captenpluginspb.AddGitProjectResponse{
5656
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,

capten/common-pkg/capten-store/cloud_provider.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import (
88
"github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb"
99
)
1010

11+
func (a *Store) AddCloudProvider(config *captenpluginspb.CloudProvider) error {
12+
provider := CloudProvider{
13+
ID: uuid.MustParse(config.Id),
14+
CloudType: config.CloudType,
15+
Labels: config.Labels,
16+
LastUpdateTime: time.Now(),
17+
}
18+
return a.dbClient.Create(&provider)
19+
}
20+
1121
func (a *Store) UpsertCloudProvider(config *captenpluginspb.CloudProvider) error {
1222
if config.Id == "" {
1323
provider := CloudProvider{

capten/common-pkg/capten-store/container_registry.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ import (
88
"github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb"
99
)
1010

11+
func (a *Store) AddContainerRegistry(config *captenpluginspb.ContainerRegistry) error {
12+
registry := ContainerRegistry{
13+
ID: uuid.MustParse(config.Id),
14+
RegistryURL: config.RegistryUrl,
15+
RegistryType: config.RegistryType,
16+
Labels: config.Labels,
17+
LastUpdateTime: time.Now(),
18+
}
19+
return a.dbClient.Create(&registry)
20+
}
21+
1122
func (a *Store) UpsertContainerRegistry(config *captenpluginspb.ContainerRegistry) error {
1223
if config.Id == "" {
1324
registry := ContainerRegistry{

capten/common-pkg/capten-store/crossplane_provider.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ import (
1111
"github.com/kube-tarian/kad/capten/model"
1212
)
1313

14+
func (a *Store) AddCrossplaneProvider(crossplaneProvider *model.CrossplaneProvider) error {
15+
provider := CrossplaneProvider{
16+
ID: uuid.MustParse(crossplaneProvider.Id),
17+
ProviderName: crossplaneProvider.ProviderName,
18+
CloudProviderID: crossplaneProvider.CloudProviderId,
19+
CloudType: crossplaneProvider.CloudType,
20+
Status: crossplaneProvider.Status,
21+
LastUpdateTime: time.Now(),
22+
}
23+
return a.dbClient.Create(&provider)
24+
}
25+
1426
func (a *Store) UpsertCrossplaneProvider(crossplaneProvider *model.CrossplaneProvider) error {
1527
if crossplaneProvider.Id == "" {
1628
provider := CrossplaneProvider{

capten/common-pkg/capten-store/git_projects.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import (
88
"github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb"
99
)
1010

11+
func (a *Store) AddGitProject(config *captenpluginspb.GitProject) error {
12+
project := GitProject{
13+
ID: uuid.MustParse(config.Id),
14+
ProjectURL: config.ProjectUrl,
15+
Labels: config.Labels,
16+
LastUpdateTime: time.Now(),
17+
}
18+
return a.dbClient.Create(&project)
19+
}
20+
1121
func (a *Store) UpsertGitProject(config *captenpluginspb.GitProject) error {
1222
if config.Id == "" {
1323
project := GitProject{

capten/common-pkg/capten-store/managed_cluster.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ import (
88
"github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb"
99
)
1010

11+
func (a *Store) AddManagedCluster(managedCluster *captenpluginspb.ManagedCluster) error {
12+
cluster := ManagedCluster{
13+
ID: uuid.MustParse(managedCluster.Id),
14+
ClusterName: managedCluster.ClusterName,
15+
ClusterEndpoint: managedCluster.ClusterEndpoint,
16+
ClusterDeployStatus: managedCluster.ClusterDeployStatus,
17+
AppDeployStatus: managedCluster.AppDeployStatus,
18+
LastUpdateTime: time.Now(),
19+
}
20+
return a.dbClient.Create(&cluster)
21+
}
22+
1123
func (a *Store) UpsertManagedCluster(managedCluster *captenpluginspb.ManagedCluster) error {
1224
if managedCluster.Id == "" {
1325
cluster := ManagedCluster{

capten/common-pkg/capten-store/model.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (CrossplaneProject) TableName() string {
189189
}
190190

191191
type PluginStoreConfig struct {
192-
StoreType int `json:"id" gorm:"column:store_type;primaryKey"`
192+
StoreType int `json:"store_type" gorm:"column:store_type;primaryKey"`
193193
GitProjectID uuid.UUID `json:"git_project_id" gorm:"column:git_project_id"`
194194
GitProjectURL string `json:"git_project_url" gorm:"column:git_project_url"`
195195
Status string `json:"status" gorm:"column:status"`
@@ -201,7 +201,7 @@ func (PluginStoreConfig) TableName() string {
201201
}
202202

203203
type PluginStoreData struct {
204-
StoreType int `json:"id" gorm:"column:store_type;primaryKey"`
204+
StoreType int `json:"store_type" gorm:"column:store_type;primaryKey"`
205205
GitProjectID uuid.UUID `json:"git_project_id" gorm:"column:git_project_id"`
206206
PluginName string `json:"plugin_name" gorm:"column:plugin_name"`
207207
Category string `json:"category" gorm:"column:category"`

0 commit comments

Comments
 (0)