Skip to content

Commit

Permalink
handle db insert when first resource add cases
Browse files Browse the repository at this point in the history
  • Loading branch information
vramk23 committed May 30, 2024
1 parent 0f8e275 commit 2434d95
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion capten/agent/internal/api/container_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (a *Agent) AddContainerRegistry(ctx context.Context, request *captenplugins
Labels: request.Labels,
RegistryType: request.RegistryType,
}
if err := a.as.UpsertContainerRegistry(&ContainerRegistry); err != nil {
if err := a.as.AddContainerRegistry(&ContainerRegistry); err != nil {
a.log.Errorf("failed to store Container registry to DB, %v", err)
return &captenpluginspb.AddContainerRegistryResponse{
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion capten/agent/internal/api/plugin_cloud_provider_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (a *Agent) AddCloudProvider(ctx context.Context, request *captenpluginspb.A
CloudType: request.CloudType,
Labels: request.Labels,
}
if err := a.as.UpsertCloudProvider(&CloudProvider); err != nil {
if err := a.as.AddCloudProvider(&CloudProvider); err != nil {
a.log.Errorf("failed to store cloud provider to DB, %v", err)
return &captenpluginspb.AddCloudProviderResponse{
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion capten/agent/internal/api/plugin_git_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (a *Agent) AddGitProject(ctx context.Context, request *captenpluginspb.AddG
ProjectUrl: request.ProjectUrl,
Labels: request.Labels,
}
if err := a.as.UpsertGitProject(&gitProject); err != nil {
if err := a.as.AddGitProject(&gitProject); err != nil {
a.log.Errorf("failed to store git project to DB, %v", err)
return &captenpluginspb.AddGitProjectResponse{
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
Expand Down
10 changes: 10 additions & 0 deletions capten/common-pkg/capten-store/cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import (
"github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb"
)

func (a *Store) AddCloudProvider(config *captenpluginspb.CloudProvider) error {
provider := CloudProvider{
ID: uuid.MustParse(config.Id),
CloudType: config.CloudType,
Labels: config.Labels,
LastUpdateTime: time.Now(),
}
return a.dbClient.Create(&provider)
}

func (a *Store) UpsertCloudProvider(config *captenpluginspb.CloudProvider) error {
if config.Id == "" {
provider := CloudProvider{
Expand Down
11 changes: 11 additions & 0 deletions capten/common-pkg/capten-store/container_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import (
"github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb"
)

func (a *Store) AddContainerRegistry(config *captenpluginspb.ContainerRegistry) error {
registry := ContainerRegistry{
ID: uuid.MustParse(config.Id),
RegistryURL: config.RegistryUrl,
RegistryType: config.RegistryType,
Labels: config.Labels,
LastUpdateTime: time.Now(),
}
return a.dbClient.Create(&registry)
}

func (a *Store) UpsertContainerRegistry(config *captenpluginspb.ContainerRegistry) error {
if config.Id == "" {
registry := ContainerRegistry{
Expand Down
10 changes: 10 additions & 0 deletions capten/common-pkg/capten-store/git_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import (
"github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb"
)

func (a *Store) AddGitProject(config *captenpluginspb.GitProject) error {
project := GitProject{
ID: uuid.MustParse(config.Id),
ProjectURL: config.ProjectUrl,
Labels: config.Labels,
LastUpdateTime: time.Now(),
}
return a.dbClient.Create(&project)
}

func (a *Store) UpsertGitProject(config *captenpluginspb.GitProject) error {
if config.Id == "" {
project := GitProject{
Expand Down

0 comments on commit 2434d95

Please sign in to comment.