| 227 | } |
| 228 | |
| 229 | func (s *ClusterStore) CreateCluster(ctx context.Context, ns string, clusterInfo *Cluster) error { |
| 230 | lock := s.getLock(ns, clusterInfo.Name) |
| 231 | lock.Lock() |
| 232 | defer lock.Unlock() |
| 233 | |
| 234 | if exists, _ := s.existsCluster(ctx, ns, clusterInfo.Name); exists { |
| 235 | return fmt.Errorf("cluster: %w", consts.ErrAlreadyExists) |
| 236 | } |
| 237 | clusterBytes, err := json.Marshal(clusterInfo) |
| 238 | if err != nil { |
| 239 | return fmt.Errorf("cluster: %w", err) |
| 240 | } |
| 241 | if err := s.e.Set(ctx, buildClusterKey(ns, clusterInfo.Name), clusterBytes); err != nil { |
| 242 | return err |
| 243 | } |
| 244 | s.EmitEvent(EventPayload{ |
| 245 | Namespace: ns, |
| 246 | Cluster: clusterInfo.Name, |
| 247 | Type: EventCluster, |
| 248 | Command: CommandCreate, |
| 249 | }) |
| 250 | return nil |
| 251 | } |
| 252 | |
| 253 | func (s *ClusterStore) RemoveCluster(ctx context.Context, ns, cluster string) error { |
| 254 | lock := s.getLock(ns, cluster) |