mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 17:07:16 +00:00
* Move utils packages that are required for gitops engine under engine/pkg/utils package. Following changes were implemented: * util/health package is split into two parts: resource health assessement & resource health assessement and moved into engine/pkg/utils * utils packages moved: Closer and Close method of util package moved into engine/pkg/utils/io package * packages diff, errors, exec, json, kube and tracing moved into engine/pkg/utils * Move single cluster caching into engine/kube/cache package * move sync functionality to engine/kube/sync package * remove dependency on metrics package from engine/pkg/utils/kube/cache * move annotation label definitions into engine/pkg/utils/kube/sync * make sure engine/pkg has no dependencies on other argo-cd packages * allow importing engine as a go module * implement a high-level interface that might be consumed by flux * fix deadlock caused by cluster cache event handler * ClusterCache should return error if requested group kind not found * remove obsolete tests * apply reviewer notes
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package util
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/base64"
|
|
"time"
|
|
)
|
|
|
|
// Wait takes a check interval and timeout and waits for a function to return `true`.
|
|
// Wait will return `true` on success and `false` on timeout.
|
|
// The passed function, in turn, should pass `true` (or anything, really) to the channel when it's done.
|
|
// Pass `0` as the timeout to run infinitely until completion.
|
|
func Wait(timeout uint, f func(chan<- bool)) bool {
|
|
done := make(chan bool)
|
|
go f(done)
|
|
|
|
// infinite
|
|
if timeout == 0 {
|
|
return <-done
|
|
}
|
|
|
|
timedOut := time.After(time.Duration(timeout) * time.Second)
|
|
for {
|
|
select {
|
|
case <-done:
|
|
return true
|
|
case <-timedOut:
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
// MakeSignature generates a cryptographically-secure pseudo-random token, based on a given number of random bytes, for signing purposes.
|
|
func MakeSignature(size int) ([]byte, error) {
|
|
b := make([]byte, size)
|
|
_, err := rand.Read(b)
|
|
if err != nil {
|
|
b = nil
|
|
}
|
|
// base64 encode it so signing key can be typed into validation utilities
|
|
b = []byte(base64.StdEncoding.EncodeToString(b))
|
|
return b, err
|
|
}
|