From a228f7659c3cdeea1003123150fd9c6a46003631 Mon Sep 17 00:00:00 2001 From: donggyu Date: Mon, 8 Apr 2024 15:28:44 +0900 Subject: [PATCH 1/2] bugfix. fix error handling --- internal/keycloak/keycloak.go | 23 +++++++++++++---------- internal/usecase/project.go | 15 +-------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/internal/keycloak/keycloak.go b/internal/keycloak/keycloak.go index 9332e946..7f99c050 100644 --- a/internal/keycloak/keycloak.go +++ b/internal/keycloak/keycloak.go @@ -4,7 +4,6 @@ import ( "context" "crypto/tls" "fmt" - "github.com/spf13/viper" "time" @@ -484,16 +483,20 @@ func (k *Keycloak) EnsureClientRoleWithClientName(ctx context.Context, organizat Name: gocloak.StringP(roleName), } - r, err := k.client.GetClientRole(context.Background(), token.AccessToken, organizationId, *targetClient.ID, roleName) + _, err = k.client.GetClientRole(context.Background(), token.AccessToken, organizationId, *targetClient.ID, roleName) if err != nil { - log.Error(ctx, "Getting Client Role is failed", err) - return err - } - - if r == nil { - _, err = k.client.CreateClientRole(context.Background(), token.AccessToken, organizationId, *targetClient.ID, role) - if err != nil { - log.Error(ctx, "Creating Client Role is failed", err) + if apiErr, ok := err.(*gocloak.APIError); ok { + if apiErr.Code == 404 { + _, err = k.client.CreateClientRole(context.Background(), token.AccessToken, organizationId, *targetClient.ID, role) + if err != nil { + log.Error(ctx, "Creating Client Role is failed", err) + return err + } + return nil + } else { + return err + } + } else { return err } } diff --git a/internal/usecase/project.go b/internal/usecase/project.go index 94d00b9b..6a02db3d 100644 --- a/internal/usecase/project.go +++ b/internal/usecase/project.go @@ -444,25 +444,12 @@ func (u *ProjectUsecase) GetAppCount(ctx context.Context, organizationId string, } func (u *ProjectUsecase) EnsureRequiredSetupForCluster(ctx context.Context, organizationId string, projectId string, stackId string) error { - pns, err := u.projectRepo.GetProjectNamespaces(ctx, organizationId, projectId, nil) + _, err := u.projectRepo.GetProjectNamespaces(ctx, organizationId, projectId, nil) if err != nil { log.Error(ctx, err) return errors.Wrap(err, "Failed to get project namespace in database.") } - var alreadySetUp bool - for _, pn := range pns { - if pn.StackId == stackId { - alreadySetUp = true - break - } - } - - // if already set up, it means that required setup is already done - if alreadySetUp { - return nil - } - if err := u.createK8SInitialResource(ctx, organizationId, projectId, stackId); err != nil { log.Error(ctx, err) return err From 1b1b7e149fe3b0fba7175fbfe37a8887c244273c Mon Sep 17 00:00:00 2001 From: donggyu Date: Mon, 8 Apr 2024 15:36:03 +0900 Subject: [PATCH 2/2] lint fix --- internal/usecase/system-notification.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/usecase/system-notification.go b/internal/usecase/system-notification.go index 6156896b..eca9e6c2 100644 --- a/internal/usecase/system-notification.go +++ b/internal/usecase/system-notification.go @@ -256,8 +256,8 @@ func (u *SystemNotificationUsecase) makeGrafanaUrl(ctx context.Context, primaryC } } - // check type - url = primaryGrafanaEndpoint + //// check type + //url = primaryGrafanaEndpoint // tks_node_dashboard/tks-kubernetes-view-nodes?orgId=1&refresh=30s&var-datasource=default&var-taco_cluster=c19rjkn4j&var-job=prometheus-node-exporter&var-hostname=All&var-node=10.0.168.71:9100&var-device=All&var-maxmount=%2F&var-show_hostname=prometheus-node-exporter-xt4vb