1b9a70d089
This switches us back to an approach where we use the Pod "exec" API to grab the keys we need, rather than forcing our code to run on the control plane node. It will help us fail gracefully (or dynamically switch to alternate implementations) when the cluster is not self-hosted. Signed-off-by: Matt Moyer <moyerm@vmware.com> Co-authored-by: Ryan Richard <richardry@vmware.com>
74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
/*
|
|
Copyright 2020 VMware, Inc.
|
|
SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package testutil
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/go-logr/logr"
|
|
)
|
|
|
|
type TranscriptLogger struct {
|
|
t *testing.T
|
|
lock sync.Mutex
|
|
transcript []TranscriptLogMessage
|
|
}
|
|
|
|
var _ logr.Logger = &TranscriptLogger{}
|
|
|
|
type TranscriptLogMessage struct {
|
|
Level string
|
|
Message string
|
|
}
|
|
|
|
func NewTranscriptLogger(t *testing.T) *TranscriptLogger {
|
|
return &TranscriptLogger{t: t}
|
|
}
|
|
|
|
func (log *TranscriptLogger) Transcript() []TranscriptLogMessage {
|
|
log.lock.Lock()
|
|
defer log.lock.Unlock()
|
|
result := make([]TranscriptLogMessage, 0, len(log.transcript))
|
|
result = append(result, log.transcript...)
|
|
return result
|
|
}
|
|
|
|
func (log *TranscriptLogger) Info(msg string, keysAndValues ...interface{}) {
|
|
log.lock.Lock()
|
|
defer log.lock.Unlock()
|
|
log.transcript = append(log.transcript, TranscriptLogMessage{
|
|
Level: "info",
|
|
Message: fmt.Sprintf(msg, keysAndValues...),
|
|
})
|
|
}
|
|
|
|
func (log *TranscriptLogger) Error(err error, msg string, keysAndValues ...interface{}) {
|
|
log.lock.Lock()
|
|
defer log.lock.Unlock()
|
|
log.transcript = append(log.transcript, TranscriptLogMessage{
|
|
Level: "error",
|
|
Message: fmt.Sprintf("%s: %v -- %v", msg, err, keysAndValues),
|
|
})
|
|
}
|
|
|
|
func (*TranscriptLogger) Enabled() bool {
|
|
return true
|
|
}
|
|
|
|
func (log *TranscriptLogger) V(_ int) logr.Logger {
|
|
return log
|
|
}
|
|
|
|
func (log *TranscriptLogger) WithName(_ string) logr.Logger {
|
|
return log
|
|
}
|
|
|
|
func (log *TranscriptLogger) WithValues(_ ...interface{}) logr.Logger {
|
|
return log
|
|
}
|