Skip to content

Commit

Permalink
Merge pull request #353 from cho4036/develop
Browse files Browse the repository at this point in the history
bugfix. fix error handling
  • Loading branch information
cho4036 authored Apr 8, 2024
2 parents d2241f6 + 1b1b7e1 commit ea9e498
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
23 changes: 13 additions & 10 deletions internal/keycloak/keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/tls"
"fmt"

"github.com/spf13/viper"

"time"
Expand Down Expand Up @@ -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
}
}
Expand Down
15 changes: 1 addition & 14 deletions internal/usecase/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/usecase/system-notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ea9e498

Please sign in to comment.