github.com/aclisp/heapster@v0.19.2-0.20160613100040-51756f899a96/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/uuid.go (about) 1 /* 2 Copyright 2014 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package util 18 19 import ( 20 "sync" 21 22 "github.com/pborman/uuid" 23 "k8s.io/kubernetes/pkg/types" 24 ) 25 26 var uuidLock sync.Mutex 27 var lastUUID uuid.UUID 28 29 func NewUUID() types.UID { 30 uuidLock.Lock() 31 defer uuidLock.Unlock() 32 result := uuid.NewUUID() 33 // The UUID package is naive and can generate identical UUIDs if the 34 // time interval is quick enough. 35 // The UUID uses 100 ns increments so it's short enough to actively 36 // wait for a new value. 37 for uuid.Equal(lastUUID, result) == true { 38 result = uuid.NewUUID() 39 } 40 lastUUID = result 41 return types.UID(result.String()) 42 }