Skip to content

Commit

Permalink
fix: invalid memory address or nil pointer dereference during cluster… (
Browse files Browse the repository at this point in the history
argoproj#7445)

Signed-off-by: May Zhang <[email protected]>
  • Loading branch information
mayzhang2000 authored Oct 17, 2021
1 parent d7d8fe3 commit f0cd21a
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,26 @@ func (s *Server) Create(ctx context.Context, q *cluster.ClusterCreateRequest) (*
}

clust, err := s.db.CreateCluster(ctx, c)
if status.Convert(err).Code() == codes.AlreadyExists {
// act idempotent if existing spec matches new spec
existing, getErr := s.db.GetCluster(ctx, c.Server)
if getErr != nil {
return nil, status.Errorf(codes.Internal, "unable to check existing cluster details: %v", getErr)
}
if err != nil {
if status.Convert(err).Code() == codes.AlreadyExists {
// act idempotent if existing spec matches new spec
existing, getErr := s.db.GetCluster(ctx, c.Server)
if getErr != nil {
return nil, status.Errorf(codes.Internal, "unable to check existing cluster details: %v", getErr)
}

if existing.Equals(c) {
clust = existing
} else if q.Upsert {
return s.Update(ctx, &cluster.ClusterUpdateRequest{Cluster: c})
if existing.Equals(c) {
clust = existing
} else if q.Upsert {
return s.Update(ctx, &cluster.ClusterUpdateRequest{Cluster: c})
} else {
return nil, status.Errorf(codes.InvalidArgument, argo.GenerateSpecIsDifferentErrorMessage("cluster", existing, c))
}
} else {
return nil, status.Errorf(codes.InvalidArgument, argo.GenerateSpecIsDifferentErrorMessage("cluster", existing, c))
return nil, err
}
}

err = s.cache.SetClusterInfo(c.Server, &appv1.ClusterInfo{
ServerVersion: serverVersion,
ConnectionState: appv1.ConnectionState{
Expand Down

0 comments on commit f0cd21a

Please sign in to comment.