From bc29bf637ae21dc5ad811c341b1700f1b4ae4595 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Fri, 1 Dec 2023 17:02:39 +0530 Subject: [PATCH] fixed: update unique validation of namespace from across all clusters to specific cluster --- pkg/cluster/EnvironmentService.go | 2 +- pkg/cluster/repository/EnvironmentRepository.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/cluster/EnvironmentService.go b/pkg/cluster/EnvironmentService.go index 849d9d6957..6206478347 100644 --- a/pkg/cluster/EnvironmentService.go +++ b/pkg/cluster/EnvironmentService.go @@ -141,7 +141,7 @@ func (impl EnvironmentServiceImpl) Create(mappings *EnvironmentBean, userId int3 identifier := clusterBean.ClusterName + "__" + mappings.Namespace - model, err := impl.environmentRepository.FindByEnvNameOrIdentifierOrNamespace(mappings.Environment, identifier, mappings.Namespace) + model, err := impl.environmentRepository.FindByEnvNameOrIdentifierOrNamespace(mappings.ClusterId, mappings.Environment, identifier, mappings.Namespace) if err != nil && err != pg.ErrNoRows { impl.logger.Errorw("error in finding environment for update", "err", err) return mappings, err diff --git a/pkg/cluster/repository/EnvironmentRepository.go b/pkg/cluster/repository/EnvironmentRepository.go index a9dbc32cb5..19b9c9c3d5 100644 --- a/pkg/cluster/repository/EnvironmentRepository.go +++ b/pkg/cluster/repository/EnvironmentRepository.go @@ -63,7 +63,7 @@ type EnvironmentRepository interface { FindByName(name string) (*Environment, error) FindByIdentifier(identifier string) (*Environment, error) FindByNameOrIdentifier(name string, identifier string) (*Environment, error) - FindByEnvNameOrIdentifierOrNamespace(envName string, identifier string, namespace string) (*Environment, error) + FindByEnvNameOrIdentifierOrNamespace(clusterId int, envName string, identifier string, namespace string) (*Environment, error) FindByClusterId(clusterId int) ([]*Environment, error) FindByIds(ids []*int) ([]*Environment, error) FindByNamespaceAndClusterName(namespaces string, clusterName string) (*Environment, error) @@ -183,14 +183,15 @@ func (repositoryImpl EnvironmentRepositoryImpl) FindByNameOrIdentifier(name stri return environment, err } -func (repositoryImpl EnvironmentRepositoryImpl) FindByEnvNameOrIdentifierOrNamespace(envName string, identifier string, namespace string) (*Environment, error) { +func (repositoryImpl EnvironmentRepositoryImpl) FindByEnvNameOrIdentifierOrNamespace(clusterId int, envName string, identifier string, namespace string) (*Environment, error) { environment := &Environment{} err := repositoryImpl.dbConnection. Model(environment). Where("active = ?", true). WhereGroup(func(query *orm.Query) (*orm.Query, error) { - query = query.Where("environment_identifier = ?", identifier).WhereOr("environment_name = ?", envName). - WhereOr("namespace = ?", namespace) + query = query.Where("environment_identifier = ?", identifier). + WhereOr("environment_name = ?", envName). + WhereOr("cluster_id = ? AND namespace = ?", clusterId, namespace) return query, nil }). Limit(1).