Skip to content

Commit

Permalink
Verify cluster name in remove cluster call (#3715)
Browse files Browse the repository at this point in the history
* Verify cluster name in remove cluster call
  • Loading branch information
yux0 committed Dec 21, 2022
1 parent 661880f commit b2c5357
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions service/frontend/operator_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,17 @@ func (h *OperatorHandlerImpl) RemoveRemoteCluster(
scope, startTime := h.startRequestProfile(metrics.OperatorRemoveRemoteClusterScope)
defer func() { scope.Timer(metrics.ServiceLatency.GetMetricName()).Record(time.Since(startTime)) }()

var isClusterNameExist bool
for clusterName := range h.clusterMetadata.GetAllClusterInfo() {
if clusterName == request.GetClusterName() {
isClusterNameExist = true
break
}
}
if !isClusterNameExist {
return nil, serviceerror.NewNotFound("The cluster to be deleted cannot be found in clusters cache.")
}

if err := h.clusterMetadataManager.DeleteClusterMetadata(
ctx,
&persistence.DeleteClusterMetadataRequest{ClusterName: request.GetClusterName()},
Expand Down
2 changes: 2 additions & 0 deletions service/frontend/operator_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ func (s *operatorHandlerSuite) Test_DeleteNamespace() {

func (s *operatorHandlerSuite) Test_RemoveRemoteCluster_Success() {
var clusterName = "cluster"
s.mockResource.ClusterMetadata.EXPECT().GetAllClusterInfo().Return(map[string]cluster.ClusterInformation{clusterName: {}})
s.mockResource.ClusterMetadataMgr.EXPECT().DeleteClusterMetadata(
gomock.Any(),
&persistence.DeleteClusterMetadataRequest{ClusterName: clusterName},
Expand All @@ -480,6 +481,7 @@ func (s *operatorHandlerSuite) Test_RemoveRemoteCluster_Success() {

func (s *operatorHandlerSuite) Test_RemoveRemoteCluster_Error() {
var clusterName = "cluster"
s.mockResource.ClusterMetadata.EXPECT().GetAllClusterInfo().Return(map[string]cluster.ClusterInformation{clusterName: {}})
s.mockResource.ClusterMetadataMgr.EXPECT().DeleteClusterMetadata(
gomock.Any(),
&persistence.DeleteClusterMetadataRequest{ClusterName: clusterName},
Expand Down

0 comments on commit b2c5357

Please sign in to comment.