Release releases the use of an ID associated with the provided key. After the last user has released the ID, the key is removed in the KVstore and the returned lastUse value is true.
(ctx context.Context, key AllocatorKey)
| 916 | // the last user has released the ID, the key is removed in the KVstore and |
| 917 | // the returned lastUse value is true. |
| 918 | func (a *Allocator) Release(ctx context.Context, key AllocatorKey) (lastUse bool, err error) { |
| 919 | if a.operatorIDManagement { |
| 920 | a.logger.Debug("Skipping key release when cilium-operator ID management is enabled", logfields.Key, key) |
| 921 | return false, nil |
| 922 | } |
| 923 | |
| 924 | a.logger.Debug("Releasing key", logfields.Key, key) |
| 925 | |
| 926 | select { |
| 927 | case <-a.initialListDone: |
| 928 | case <-ctx.Done(): |
| 929 | return false, fmt.Errorf("release was cancelled while waiting for initial key list to be received: %w", ctx.Err()) |
| 930 | } |
| 931 | |
| 932 | k := key.GetKey() |
| 933 | |
| 934 | a.slaveKeysMutex.Lock() |
| 935 | defer a.slaveKeysMutex.Unlock() |
| 936 | |
| 937 | // release the key locally, if it was the last use, remove the node |
| 938 | // specific value key to remove the global reference mark |
| 939 | var id idpool.ID |
| 940 | lastUse, id, err = a.localKeys.release(k) |
| 941 | if err != nil { |
| 942 | return lastUse, err |
| 943 | } |
| 944 | if lastUse { |
| 945 | // Since in CRD mode we don't have a way to map which identity is being |
| 946 | // used by a node, we need to also pass the ID to the release function. |
| 947 | // This allows the CRD store to find the right identity by its ID and |
| 948 | // remove the node reference on that identity. |
| 949 | a.backend.Release(ctx, id, key) |
| 950 | } |
| 951 | |
| 952 | return lastUse, err |
| 953 | } |
| 954 | |
| 955 | // RunGC scans the kvstore for unused master keys and removes them |
| 956 | func (a *Allocator) RunGC(ctx context.Context, rateLimit *rate.Limiter, staleKeysPrevRound map[string]uint64) (map[string]uint64, *GCStats, error) { |