RemoveNamespace delete the specified namespace from store
(ctx context.Context, ns string)
| 108 | |
| 109 | // RemoveNamespace delete the specified namespace from store |
| 110 | func (s *ClusterStore) RemoveNamespace(ctx context.Context, ns string) error { |
| 111 | if has, _ := s.ExistsNamespace(ctx, ns); !has { |
| 112 | return consts.ErrNotFound |
| 113 | } |
| 114 | clusters, err := s.ListCluster(ctx, ns) |
| 115 | if err != nil { |
| 116 | return err |
| 117 | } |
| 118 | if len(clusters) != 0 { |
| 119 | return fmt.Errorf("%w: please delete clusters first", consts.ErrForbidden) |
| 120 | } |
| 121 | if err := s.e.Delete(ctx, appendPrefix(ns)); err != nil { |
| 122 | return err |
| 123 | } |
| 124 | s.EmitEvent(EventPayload{ |
| 125 | Namespace: ns, |
| 126 | Type: EventNamespace, |
| 127 | Command: CommandRemove, |
| 128 | }) |
| 129 | return nil |
| 130 | } |
| 131 | |
| 132 | func (s *ClusterStore) getLock(ns, cluster string) *sync.RWMutex { |
| 133 | value, _ := s.locks.LoadOrStore(fmt.Sprintf("%s/%s", ns, cluster), &sync.RWMutex{}) |