Skip to content

Commit

Permalink
[fix] fix the problem that use environment name (#1473)
Browse files Browse the repository at this point in the history
Co-authored-by: songshiyuan 00649746 <[email protected]>
  • Loading branch information
tornado-ssy and songshiyuan 00649746 authored Jun 1, 2024
1 parent 8559214 commit b9e258c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions datasource/etcd/ms.go
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ func (ds *MetadataManager) RegisterEnvironment(ctx context.Context, request *ev.
if resp.Succeeded {
log.Info(fmt.Sprintf("create environment[%s][%s] successfully, operator: %s",
env.ID, envFlag, remoteIP))
disco.EnvMap.Store(request.Environment.Name, struct{}{})
disco.EnvMap.Store(request.Environment.ID, struct{}{})
return &ev.CreateEnvironmentResponse{
EnvId: env.ID,
}, nil
Expand All @@ -1790,7 +1790,7 @@ func (ds *MetadataManager) RegisterEnvironment(ctx context.Context, request *ev.
existEnvironmentID := util.BytesToStringWithNoCopy(resp.Kvs[0].Value)
log.Warn(fmt.Sprintf("create environment[%s][%s] failed, environment already exists, operator: %s",
existEnvironmentID, envFlag, remoteIP))
disco.EnvMap.Store(request.Environment.Name, struct{}{})
disco.EnvMap.Store(request.Environment.ID, struct{}{})
return &ev.CreateEnvironmentResponse{
EnvId: existEnvironmentID,
}, nil
Expand Down Expand Up @@ -1879,7 +1879,7 @@ func (ds *MetadataManager) UnregisterEnvironment(ctx context.Context, request *e
return pb.NewError(pb.ErrInternal, err.Error())
}

serviceEnvKey := path.GenerateServiceEnvIndexKey(domainProject, environment.Name)
serviceEnvKey := path.GenerateServiceEnvIndexKey(domainProject, environment.ID)
if serviceUtil.ServiceEnvExist(ctx, serviceEnvKey) {
log.Error(fmt.Sprintf("del environment[%s] failed, get environment file failed, operator: %s",
environmentId, remoteIP), errors.New("this env has services"))
Expand Down Expand Up @@ -1916,6 +1916,6 @@ func (ds *MetadataManager) UnregisterEnvironment(ctx context.Context, request *e
quotasvc.RemandEnvironment(ctx)

log.Info(fmt.Sprintf("del environment[%s] successfully, operator: %s", environmentId, remoteIP))
disco.EnvMap.Delete(environment.Name)
disco.EnvMap.Delete(environment.ID)
return nil
}
4 changes: 2 additions & 2 deletions datasource/etcd/path/key_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ func GetEnvironmentIndexRootKey(domainProject string) string {
}, SPLIT)
}

func GenerateServiceEnvIndexKey(domainProject string, name string) string {
func GenerateServiceEnvIndexKey(domainProject string, envId string) string {

Check warning on line 421 in datasource/etcd/path/key_generator.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func parameter envId should be envID (revive)
return util.StringJoin([]string{
GetServiceIndexRootKey(domainProject),
name,
envId,
}, SPLIT)
}

0 comments on commit b9e258c

Please sign in to comment.