mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-29 03:51:54 +08:00
fix: update vendor 20240919 3.11 (#21262)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
+2
-2
@@ -8,8 +8,8 @@ endif
|
||||
ModBaseName:=$(notdir $(ModName))
|
||||
|
||||
DockerImageRegistry?=registry.cn-beijing.aliyuncs.com
|
||||
DockerImageAlpineBuild?=$(DockerImageRegistry)/yunionio/alpine-build:3.16.0-go-1.18.2-0
|
||||
DockerImageCentOSBuild?=$(DockerImageRegistry)/yunionio/centos-build:go-1.18.3-0
|
||||
DockerImageAlpineBuild?=$(DockerImageRegistry)/yunionio/alpine-build:3.19.0-go-1.21.10-0
|
||||
DockerImageCentOSBuild?=$(DockerImageRegistry)/yunionio/centos-build:go-1.21.10-0
|
||||
|
||||
EnvIf=$(if $($(1)),$(1)=$($(1)))
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ require (
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
k8s.io/cri-api v0.22.17
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240918073337-2e6f00f18670
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240918093759-100bd85aef00
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
|
||||
yunion.io/x/jsonutils v1.0.1-0.20240203102553-4096f103b401
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
@@ -165,7 +165,7 @@ require (
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2 // indirect
|
||||
github.com/go-logfmt/logfmt v0.5.0 // indirect
|
||||
github.com/go-logr/logr v1.4.1 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/go-playground/locales v0.13.0 // indirect
|
||||
@@ -281,7 +281,7 @@ require (
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
k8s.io/klog/v2 v2.2.0 // indirect
|
||||
k8s.io/klog/v2 v2.20.0 // indirect
|
||||
k8s.io/utils v0.0.0-20200729134348-d5654de09c73 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.0.1 // indirect
|
||||
sigs.k8s.io/yaml v1.2.0 // indirect
|
||||
|
||||
@@ -293,9 +293,10 @@ github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih
|
||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
|
||||
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
|
||||
github.com/go-logr/logr v1.0.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
|
||||
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
@@ -1262,8 +1263,9 @@ k8s.io/cri-api v0.22.17 h1:lUY0gpQXQl1hFDMbuYb+eB94Vu/8QoLKYCb8ACnpAHE=
|
||||
k8s.io/cri-api v0.22.17/go.mod h1:uAw9CICQq20/1yB4ZnWT2TjJyMMROl4typFfWaURLwQ=
|
||||
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
||||
k8s.io/klog/v2 v2.2.0 h1:XRvcwJozkgZ1UQJmfMGpvRthQHOvihEhYtDfAaxMz/A=
|
||||
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
|
||||
k8s.io/klog/v2 v2.20.0 h1:tlyxlSvd63k7axjhuchckaRJm+a92z5GSOrTOQY5sHw=
|
||||
k8s.io/klog/v2 v2.20.0/go.mod h1:Gm8eSIfQN6457haJuPaMxZw4wyP5k+ykPFlrhQDvhvw=
|
||||
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6/go.mod h1:UuqjUnNftUyPE5H64/qeyjQoUZhGpeFDVdxjTeEVN2o=
|
||||
k8s.io/utils v0.0.0-20200729134348-d5654de09c73 h1:uJmqzgNWG7XyClnU/mLPBWwfKKF1K8Hf8whTseBgJcg=
|
||||
k8s.io/utils v0.0.0-20200729134348-d5654de09c73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
|
||||
@@ -1277,8 +1279,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240918073337-2e6f00f18670 h1:qVmW5LAX5CoHl8cXDP/ktqwX5QVfzLqBMipqHym5ax8=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240918073337-2e6f00f18670/go.mod h1:rj/pb3DitJlQaQD8UW1oxx/KD+PzDZqoywzqRJaFE9A=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240918093759-100bd85aef00 h1:nMEd+8zLw450BjvD0xrSUeOatPzE6LRaIRdvJDNmTJs=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240918093759-100bd85aef00/go.mod h1:rj/pb3DitJlQaQD8UW1oxx/KD+PzDZqoywzqRJaFE9A=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
# A minimal logging API for Go
|
||||
|
||||
[](https://pkg.go.dev/github.com/go-logr/logr)
|
||||
[](https://goreportcard.com/report/github.com/go-logr/logr)
|
||||
[](https://securityscorecards.dev/viewer/?platform=github.com&org=go-logr&repo=logr)
|
||||
|
||||
logr offers an(other) opinion on how Go programs and libraries can do logging
|
||||
|
||||
+94
-91
@@ -236,15 +236,14 @@ func newFormatter(opts Options, outfmt outputFormat) Formatter {
|
||||
// implementation. It should be constructed with NewFormatter. Some of
|
||||
// its methods directly implement logr.LogSink.
|
||||
type Formatter struct {
|
||||
outputFormat outputFormat
|
||||
prefix string
|
||||
values []any
|
||||
valuesStr string
|
||||
parentValuesStr string
|
||||
depth int
|
||||
opts *Options
|
||||
group string // for slog groups
|
||||
groupDepth int
|
||||
outputFormat outputFormat
|
||||
prefix string
|
||||
values []any
|
||||
valuesStr string
|
||||
depth int
|
||||
opts *Options
|
||||
groupName string // for slog groups
|
||||
groups []groupDef
|
||||
}
|
||||
|
||||
// outputFormat indicates which outputFormat to use.
|
||||
@@ -257,6 +256,13 @@ const (
|
||||
outputJSON
|
||||
)
|
||||
|
||||
// groupDef represents a saved group. The values may be empty, but we don't
|
||||
// know if we need to render the group until the final record is rendered.
|
||||
type groupDef struct {
|
||||
name string
|
||||
values string
|
||||
}
|
||||
|
||||
// PseudoStruct is a list of key-value pairs that gets logged as a struct.
|
||||
type PseudoStruct []any
|
||||
|
||||
@@ -264,76 +270,102 @@ type PseudoStruct []any
|
||||
func (f Formatter) render(builtins, args []any) string {
|
||||
// Empirically bytes.Buffer is faster than strings.Builder for this.
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
|
||||
if f.outputFormat == outputJSON {
|
||||
buf.WriteByte('{') // for the whole line
|
||||
buf.WriteByte('{') // for the whole record
|
||||
}
|
||||
|
||||
// Render builtins
|
||||
vals := builtins
|
||||
if hook := f.opts.RenderBuiltinsHook; hook != nil {
|
||||
vals = hook(f.sanitize(vals))
|
||||
}
|
||||
f.flatten(buf, vals, false, false) // keys are ours, no need to escape
|
||||
f.flatten(buf, vals, false) // keys are ours, no need to escape
|
||||
continuing := len(builtins) > 0
|
||||
|
||||
if f.parentValuesStr != "" {
|
||||
// Turn the inner-most group into a string
|
||||
argsStr := func() string {
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
|
||||
vals = args
|
||||
if hook := f.opts.RenderArgsHook; hook != nil {
|
||||
vals = hook(f.sanitize(vals))
|
||||
}
|
||||
f.flatten(buf, vals, true) // escape user-provided keys
|
||||
|
||||
return buf.String()
|
||||
}()
|
||||
|
||||
// Render the stack of groups from the inside out.
|
||||
bodyStr := f.renderGroup(f.groupName, f.valuesStr, argsStr)
|
||||
for i := len(f.groups) - 1; i >= 0; i-- {
|
||||
grp := &f.groups[i]
|
||||
if grp.values == "" && bodyStr == "" {
|
||||
// no contents, so we must elide the whole group
|
||||
continue
|
||||
}
|
||||
bodyStr = f.renderGroup(grp.name, grp.values, bodyStr)
|
||||
}
|
||||
|
||||
if bodyStr != "" {
|
||||
if continuing {
|
||||
buf.WriteByte(f.comma())
|
||||
}
|
||||
buf.WriteString(f.parentValuesStr)
|
||||
continuing = true
|
||||
}
|
||||
|
||||
groupDepth := f.groupDepth
|
||||
if f.group != "" {
|
||||
if f.valuesStr != "" || len(args) != 0 {
|
||||
if continuing {
|
||||
buf.WriteByte(f.comma())
|
||||
}
|
||||
buf.WriteString(f.quoted(f.group, true)) // escape user-provided keys
|
||||
buf.WriteByte(f.colon())
|
||||
buf.WriteByte('{') // for the group
|
||||
continuing = false
|
||||
} else {
|
||||
// The group was empty
|
||||
groupDepth--
|
||||
}
|
||||
}
|
||||
|
||||
if f.valuesStr != "" {
|
||||
if continuing {
|
||||
buf.WriteByte(f.comma())
|
||||
}
|
||||
buf.WriteString(f.valuesStr)
|
||||
continuing = true
|
||||
}
|
||||
|
||||
vals = args
|
||||
if hook := f.opts.RenderArgsHook; hook != nil {
|
||||
vals = hook(f.sanitize(vals))
|
||||
}
|
||||
f.flatten(buf, vals, continuing, true) // escape user-provided keys
|
||||
|
||||
for i := 0; i < groupDepth; i++ {
|
||||
buf.WriteByte('}') // for the groups
|
||||
buf.WriteString(bodyStr)
|
||||
}
|
||||
|
||||
if f.outputFormat == outputJSON {
|
||||
buf.WriteByte('}') // for the whole line
|
||||
buf.WriteByte('}') // for the whole record
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// flatten renders a list of key-value pairs into a buffer. If continuing is
|
||||
// true, it assumes that the buffer has previous values and will emit a
|
||||
// separator (which depends on the output format) before the first pair it
|
||||
// writes. If escapeKeys is true, the keys are assumed to have
|
||||
// non-JSON-compatible characters in them and must be evaluated for escapes.
|
||||
// renderGroup returns a string representation of the named group with rendered
|
||||
// values and args. If the name is empty, this will return the values and args,
|
||||
// joined. If the name is not empty, this will return a single key-value pair,
|
||||
// where the value is a grouping of the values and args. If the values and
|
||||
// args are both empty, this will return an empty string, even if the name was
|
||||
// specified.
|
||||
func (f Formatter) renderGroup(name string, values string, args string) string {
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
|
||||
needClosingBrace := false
|
||||
if name != "" && (values != "" || args != "") {
|
||||
buf.WriteString(f.quoted(name, true)) // escape user-provided keys
|
||||
buf.WriteByte(f.colon())
|
||||
buf.WriteByte('{')
|
||||
needClosingBrace = true
|
||||
}
|
||||
|
||||
continuing := false
|
||||
if values != "" {
|
||||
buf.WriteString(values)
|
||||
continuing = true
|
||||
}
|
||||
|
||||
if args != "" {
|
||||
if continuing {
|
||||
buf.WriteByte(f.comma())
|
||||
}
|
||||
buf.WriteString(args)
|
||||
}
|
||||
|
||||
if needClosingBrace {
|
||||
buf.WriteByte('}')
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// flatten renders a list of key-value pairs into a buffer. If escapeKeys is
|
||||
// true, the keys are assumed to have non-JSON-compatible characters in them
|
||||
// and must be evaluated for escapes.
|
||||
//
|
||||
// This function returns a potentially modified version of kvList, which
|
||||
// ensures that there is a value for every key (adding a value if needed) and
|
||||
// that each key is a string (substituting a key if needed).
|
||||
func (f Formatter) flatten(buf *bytes.Buffer, kvList []any, continuing bool, escapeKeys bool) []any {
|
||||
func (f Formatter) flatten(buf *bytes.Buffer, kvList []any, escapeKeys bool) []any {
|
||||
// This logic overlaps with sanitize() but saves one type-cast per key,
|
||||
// which can be measurable.
|
||||
if len(kvList)%2 != 0 {
|
||||
@@ -354,7 +386,7 @@ func (f Formatter) flatten(buf *bytes.Buffer, kvList []any, continuing bool, esc
|
||||
}
|
||||
v := kvList[i+1]
|
||||
|
||||
if i > 0 || continuing {
|
||||
if i > 0 {
|
||||
if f.outputFormat == outputJSON {
|
||||
buf.WriteByte(f.comma())
|
||||
} else {
|
||||
@@ -766,46 +798,17 @@ func (f Formatter) sanitize(kvList []any) []any {
|
||||
// startGroup opens a new group scope (basically a sub-struct), which locks all
|
||||
// the current saved values and starts them anew. This is needed to satisfy
|
||||
// slog.
|
||||
func (f *Formatter) startGroup(group string) {
|
||||
func (f *Formatter) startGroup(name string) {
|
||||
// Unnamed groups are just inlined.
|
||||
if group == "" {
|
||||
if name == "" {
|
||||
return
|
||||
}
|
||||
|
||||
// Any saved values can no longer be changed.
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
continuing := false
|
||||
|
||||
if f.parentValuesStr != "" {
|
||||
buf.WriteString(f.parentValuesStr)
|
||||
continuing = true
|
||||
}
|
||||
|
||||
if f.group != "" && f.valuesStr != "" {
|
||||
if continuing {
|
||||
buf.WriteByte(f.comma())
|
||||
}
|
||||
buf.WriteString(f.quoted(f.group, true)) // escape user-provided keys
|
||||
buf.WriteByte(f.colon())
|
||||
buf.WriteByte('{') // for the group
|
||||
continuing = false
|
||||
}
|
||||
|
||||
if f.valuesStr != "" {
|
||||
if continuing {
|
||||
buf.WriteByte(f.comma())
|
||||
}
|
||||
buf.WriteString(f.valuesStr)
|
||||
}
|
||||
|
||||
// NOTE: We don't close the scope here - that's done later, when a log line
|
||||
// is actually rendered (because we have N scopes to close).
|
||||
|
||||
f.parentValuesStr = buf.String()
|
||||
n := len(f.groups)
|
||||
f.groups = append(f.groups[:n:n], groupDef{f.groupName, f.valuesStr})
|
||||
|
||||
// Start collecting new values.
|
||||
f.group = group
|
||||
f.groupDepth++
|
||||
f.groupName = name
|
||||
f.valuesStr = ""
|
||||
f.values = nil
|
||||
}
|
||||
@@ -900,7 +903,7 @@ func (f *Formatter) AddValues(kvList []any) {
|
||||
|
||||
// Pre-render values, so we don't have to do it on each Info/Error call.
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
f.flatten(buf, vals, false, true) // escape user-provided keys
|
||||
f.flatten(buf, vals, true) // escape user-provided keys
|
||||
f.valuesStr = buf.String()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -15,5 +15,5 @@ approvers:
|
||||
- tallclair
|
||||
- piosz
|
||||
- brancz
|
||||
- DirectXMan12
|
||||
- lavalamp
|
||||
- serathius
|
||||
|
||||
+5
-1
@@ -27,7 +27,7 @@ Historical context is available here:
|
||||
|
||||
How to use klog
|
||||
===============
|
||||
- Replace imports for `github.com/golang/glog` with `k8s.io/klog`
|
||||
- Replace imports for `"github.com/golang/glog"` with `"k8s.io/klog/v2"`
|
||||
- Use `klog.InitFlags(nil)` explicitly for initializing global flags as we no longer use `init()` method to register the flags
|
||||
- You can now use `log_file` instead of `log_dir` for logging to a single file (See `examples/log_file/usage_log_file.go`)
|
||||
- If you want to redirect everything logged using klog somewhere else (say syslog!), you can use `klog.SetOutput()` method and supply a `io.Writer`. (See `examples/set_output/usage_set_output.go`)
|
||||
@@ -35,6 +35,10 @@ How to use klog
|
||||
|
||||
**NOTE**: please use the newer go versions that support semantic import versioning in modules, ideally go 1.11.4 or greater.
|
||||
|
||||
### Coexisting with klog/v2
|
||||
|
||||
See [this example](examples/coexist_klog_v1_and_v2/) to see how to coexist with both klog/v1 and klog/v2.
|
||||
|
||||
### Coexisting with glog
|
||||
This package can be used side by side with glog. [This example](examples/coexist_glog/coexist_glog.go) shows how to initialize and synchronize flags from the global `flag.CommandLine` FlagSet. In addition, the example makes use of stderr as combined output by setting `alsologtostderr` (or `logtostderr`) to `true`.
|
||||
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
# Security Policy
|
||||
|
||||
## Security Announcements
|
||||
|
||||
Join the [kubernetes-security-announce] group for security and vulnerability announcements.
|
||||
|
||||
You can also subscribe to an RSS feed of the above using [this link][kubernetes-security-announce-rss].
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Instructions for reporting a vulnerability can be found on the
|
||||
[Kubernetes Security and Disclosure Information] page.
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Information about supported Kubernetes versions can be found on the
|
||||
[Kubernetes version and version skew support policy] page on the Kubernetes website.
|
||||
|
||||
[kubernetes-security-announce]: https://groups.google.com/forum/#!forum/kubernetes-security-announce
|
||||
[kubernetes-security-announce-rss]: https://groups.google.com/forum/feed/kubernetes-security-announce/msgs/rss_v2_0.xml?num=50
|
||||
[Kubernetes version and version skew support policy]: https://kubernetes.io/docs/setup/release/version-skew-policy/#supported-versions
|
||||
[Kubernetes Security and Disclosure Information]: https://kubernetes.io/docs/reference/issues-security/security/#report-a-vulnerability
|
||||
+205
-90
@@ -81,6 +81,7 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -283,6 +284,7 @@ func (m *moduleSpec) Get() interface{} {
|
||||
|
||||
var errVmoduleSyntax = errors.New("syntax error: expect comma-separated list of filename=N")
|
||||
|
||||
// Set will sets module value
|
||||
// Syntax: -vmodule=recordio=2,file=1,gfs*=3
|
||||
func (m *moduleSpec) Set(value string) error {
|
||||
var filter []modulePat
|
||||
@@ -361,6 +363,7 @@ func (t *traceLocation) Get() interface{} {
|
||||
|
||||
var errTraceSyntax = errors.New("syntax error: expect file.go:234")
|
||||
|
||||
// Set will sets backtrace value
|
||||
// Syntax: -log_backtrace_at=gopherflakes.go:234
|
||||
// Note that unlike vmodule the file extension is included here.
|
||||
func (t *traceLocation) Set(value string) error {
|
||||
@@ -413,6 +416,7 @@ func init() {
|
||||
logging.skipHeaders = false
|
||||
logging.addDirHeader = false
|
||||
logging.skipLogHeaders = false
|
||||
logging.oneOutput = false
|
||||
go logging.flushDaemon()
|
||||
}
|
||||
|
||||
@@ -432,6 +436,7 @@ func InitFlags(flagset *flag.FlagSet) {
|
||||
flagset.Var(&logging.verbosity, "v", "number for the log level verbosity")
|
||||
flagset.BoolVar(&logging.addDirHeader, "add_dir_header", logging.addDirHeader, "If true, adds the file directory to the header of the log messages")
|
||||
flagset.BoolVar(&logging.skipHeaders, "skip_headers", logging.skipHeaders, "If true, avoid header prefixes in the log messages")
|
||||
flagset.BoolVar(&logging.oneOutput, "one_output", logging.oneOutput, "If true, only write logs to their native severity level (vs also writing to each lower severity level)")
|
||||
flagset.BoolVar(&logging.skipLogHeaders, "skip_log_headers", logging.skipLogHeaders, "If true, avoid headers when opening log files")
|
||||
flagset.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr")
|
||||
flagset.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
|
||||
@@ -504,7 +509,13 @@ type loggingT struct {
|
||||
addDirHeader bool
|
||||
|
||||
// If set, all output will be redirected unconditionally to the provided logr.Logger
|
||||
logr logr.Logger
|
||||
logr *logr.Logger
|
||||
|
||||
// If true, messages will not be propagated to lower severity log levels
|
||||
oneOutput bool
|
||||
|
||||
// If set, all output will be filtered through the filter.
|
||||
filter LogFilter
|
||||
}
|
||||
|
||||
// buffer holds a byte Buffer for reuse. The zero value is ready for use.
|
||||
@@ -687,91 +698,109 @@ func (buf *buffer) someDigits(i, d int) int {
|
||||
return copy(buf.tmp[i:], buf.tmp[j:])
|
||||
}
|
||||
|
||||
func (l *loggingT) println(s severity, logr logr.Logger, args ...interface{}) {
|
||||
func (l *loggingT) println(s severity, logger *logr.Logger, filter LogFilter, args ...interface{}) {
|
||||
buf, file, line := l.header(s, 0)
|
||||
// if logr is set, we clear the generated header as we rely on the backing
|
||||
// logr implementation to print headers
|
||||
if logr != nil {
|
||||
// if logger is set, we clear the generated header as we rely on the backing
|
||||
// logger implementation to print headers
|
||||
if logger != nil {
|
||||
l.putBuffer(buf)
|
||||
buf = l.getBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
args = filter.Filter(args)
|
||||
}
|
||||
fmt.Fprintln(buf, args...)
|
||||
l.output(s, logr, buf, file, line, false)
|
||||
l.output(s, logger, buf, 0 /* depth */, file, line, false)
|
||||
}
|
||||
|
||||
func (l *loggingT) print(s severity, logr logr.Logger, args ...interface{}) {
|
||||
l.printDepth(s, logr, 1, args...)
|
||||
func (l *loggingT) print(s severity, logger *logr.Logger, filter LogFilter, args ...interface{}) {
|
||||
l.printDepth(s, logger, filter, 1, args...)
|
||||
}
|
||||
|
||||
func (l *loggingT) printDepth(s severity, logr logr.Logger, depth int, args ...interface{}) {
|
||||
func (l *loggingT) printDepth(s severity, logger *logr.Logger, filter LogFilter, depth int, args ...interface{}) {
|
||||
buf, file, line := l.header(s, depth)
|
||||
// if logr is set, we clear the generated header as we rely on the backing
|
||||
// logr implementation to print headers
|
||||
if logr != nil {
|
||||
if logger != nil {
|
||||
l.putBuffer(buf)
|
||||
buf = l.getBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
args = filter.Filter(args)
|
||||
}
|
||||
fmt.Fprint(buf, args...)
|
||||
if buf.Bytes()[buf.Len()-1] != '\n' {
|
||||
buf.WriteByte('\n')
|
||||
}
|
||||
l.output(s, logr, buf, file, line, false)
|
||||
l.output(s, logger, buf, depth, file, line, false)
|
||||
}
|
||||
|
||||
func (l *loggingT) printf(s severity, logr logr.Logger, format string, args ...interface{}) {
|
||||
func (l *loggingT) printf(s severity, logger *logr.Logger, filter LogFilter, format string, args ...interface{}) {
|
||||
buf, file, line := l.header(s, 0)
|
||||
// if logr is set, we clear the generated header as we rely on the backing
|
||||
// logr implementation to print headers
|
||||
if logr != nil {
|
||||
if logger != nil {
|
||||
l.putBuffer(buf)
|
||||
buf = l.getBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
format, args = filter.FilterF(format, args)
|
||||
}
|
||||
fmt.Fprintf(buf, format, args...)
|
||||
if buf.Bytes()[buf.Len()-1] != '\n' {
|
||||
buf.WriteByte('\n')
|
||||
}
|
||||
l.output(s, logr, buf, file, line, false)
|
||||
l.output(s, logger, buf, 0 /* depth */, file, line, false)
|
||||
}
|
||||
|
||||
// printWithFileLine behaves like print but uses the provided file and line number. If
|
||||
// alsoLogToStderr is true, the log message always appears on standard error; it
|
||||
// will also appear in the log file unless --logtostderr is set.
|
||||
func (l *loggingT) printWithFileLine(s severity, logr logr.Logger, file string, line int, alsoToStderr bool, args ...interface{}) {
|
||||
func (l *loggingT) printWithFileLine(s severity, logger *logr.Logger, filter LogFilter, file string, line int, alsoToStderr bool, args ...interface{}) {
|
||||
buf := l.formatHeader(s, file, line)
|
||||
// if logr is set, we clear the generated header as we rely on the backing
|
||||
// logr implementation to print headers
|
||||
if logr != nil {
|
||||
if logger != nil {
|
||||
l.putBuffer(buf)
|
||||
buf = l.getBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
args = filter.Filter(args)
|
||||
}
|
||||
fmt.Fprint(buf, args...)
|
||||
if buf.Bytes()[buf.Len()-1] != '\n' {
|
||||
buf.WriteByte('\n')
|
||||
}
|
||||
l.output(s, logr, buf, file, line, alsoToStderr)
|
||||
l.output(s, logger, buf, 2 /* depth */, file, line, alsoToStderr)
|
||||
}
|
||||
|
||||
// if loggr is specified, will call loggr.Error, otherwise output with logging module.
|
||||
func (l *loggingT) errorS(err error, loggr logr.Logger, msg string, keysAndValues ...interface{}) {
|
||||
if loggr != nil {
|
||||
loggr.Error(err, msg, keysAndValues)
|
||||
func (l *loggingT) errorS(err error, logger *logr.Logger, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
|
||||
if filter != nil {
|
||||
msg, keysAndValues = filter.FilterS(msg, keysAndValues)
|
||||
}
|
||||
if logger != nil {
|
||||
logger.WithCallDepth(depth+2).Error(err, msg, keysAndValues...)
|
||||
return
|
||||
}
|
||||
l.printS(err, msg, keysAndValues...)
|
||||
l.printS(err, errorLog, depth+1, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// if loggr is specified, will call loggr.Info, otherwise output with logging module.
|
||||
func (l *loggingT) infoS(loggr logr.Logger, msg string, keysAndValues ...interface{}) {
|
||||
if loggr != nil {
|
||||
loggr.Info(msg, keysAndValues)
|
||||
func (l *loggingT) infoS(logger *logr.Logger, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
|
||||
if filter != nil {
|
||||
msg, keysAndValues = filter.FilterS(msg, keysAndValues)
|
||||
}
|
||||
if logger != nil {
|
||||
logger.WithCallDepth(depth+2).Info(msg, keysAndValues...)
|
||||
return
|
||||
}
|
||||
l.printS(nil, msg, keysAndValues...)
|
||||
l.printS(nil, infoLog, depth+1, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// printS is called from infoS and errorS if loggr is not specified.
|
||||
// if err arguments is specified, will output to errorLog severity
|
||||
func (l *loggingT) printS(err error, msg string, keysAndValues ...interface{}) {
|
||||
// set log severity by s
|
||||
func (l *loggingT) printS(err error, s severity, depth int, msg string, keysAndValues ...interface{}) {
|
||||
b := &bytes.Buffer{}
|
||||
b.WriteString(fmt.Sprintf("%q", msg))
|
||||
if err != nil {
|
||||
@@ -779,13 +808,7 @@ func (l *loggingT) printS(err error, msg string, keysAndValues ...interface{}) {
|
||||
b.WriteString(fmt.Sprintf("err=%q", err.Error()))
|
||||
}
|
||||
kvListFormat(b, keysAndValues...)
|
||||
var s severity
|
||||
if err == nil {
|
||||
s = infoLog
|
||||
} else {
|
||||
s = errorLog
|
||||
}
|
||||
l.printDepth(s, logging.logr, 2, b)
|
||||
l.printDepth(s, logging.logr, nil, depth+1, b)
|
||||
}
|
||||
|
||||
const missingValue = "(MISSING)"
|
||||
@@ -804,6 +827,8 @@ func kvListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
|
||||
switch v.(type) {
|
||||
case string, error:
|
||||
b.WriteString(fmt.Sprintf("%s=%q", k, v))
|
||||
case []byte:
|
||||
b.WriteString(fmt.Sprintf("%s=%+q", k, v))
|
||||
default:
|
||||
if _, ok := v.(fmt.Stringer); ok {
|
||||
b.WriteString(fmt.Sprintf("%s=%q", k, v))
|
||||
@@ -834,13 +859,26 @@ func (rb *redirectBuffer) Write(bytes []byte) (n int, err error) {
|
||||
// SetLogger will set the backing logr implementation for klog.
|
||||
// If set, all log lines will be suppressed from the regular Output, and
|
||||
// redirected to the logr implementation.
|
||||
// All log lines include the 'severity', 'file' and 'line' values attached as
|
||||
// structured logging values.
|
||||
// Use as:
|
||||
// ...
|
||||
// klog.SetLogger(zapr.NewLogger(zapLog))
|
||||
//
|
||||
// To remove a backing logr implemention, use ClearLogger. Setting an
|
||||
// empty logger with SetLogger(logr.Logger{}) does not work.
|
||||
func SetLogger(logr logr.Logger) {
|
||||
logging.logr = logr
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
|
||||
logging.logr = &logr
|
||||
}
|
||||
|
||||
// ClearLogger removes a backing logr implementation if one was set earlier
|
||||
// with SetLogger.
|
||||
func ClearLogger() {
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
|
||||
logging.logr = nil
|
||||
}
|
||||
|
||||
// SetOutput sets the output destination for all severities
|
||||
@@ -878,7 +916,7 @@ func LogToStderr(stderr bool) {
|
||||
}
|
||||
|
||||
// output writes the data to the log files and releases the buffer.
|
||||
func (l *loggingT) output(s severity, log logr.Logger, buf *buffer, file string, line int, alsoToStderr bool) {
|
||||
func (l *loggingT) output(s severity, log *logr.Logger, buf *buffer, depth int, file string, line int, alsoToStderr bool) {
|
||||
l.mu.Lock()
|
||||
if l.traceLocation.isSet() {
|
||||
if l.traceLocation.match(file, line) {
|
||||
@@ -890,9 +928,9 @@ func (l *loggingT) output(s severity, log logr.Logger, buf *buffer, file string,
|
||||
// TODO: set 'severity' and caller information as structured log info
|
||||
// keysAndValues := []interface{}{"severity", severityName[s], "file", file, "line", line}
|
||||
if s == errorLog {
|
||||
l.logr.Error(nil, string(data))
|
||||
l.logr.WithCallDepth(depth+3).Error(nil, string(data))
|
||||
} else {
|
||||
log.Info(string(data))
|
||||
log.WithCallDepth(depth + 3).Info(string(data))
|
||||
}
|
||||
} else if l.toStderr {
|
||||
os.Stderr.Write(data)
|
||||
@@ -919,18 +957,22 @@ func (l *loggingT) output(s severity, log logr.Logger, buf *buffer, file string,
|
||||
}
|
||||
}
|
||||
|
||||
switch s {
|
||||
case fatalLog:
|
||||
l.file[fatalLog].Write(data)
|
||||
fallthrough
|
||||
case errorLog:
|
||||
l.file[errorLog].Write(data)
|
||||
fallthrough
|
||||
case warningLog:
|
||||
l.file[warningLog].Write(data)
|
||||
fallthrough
|
||||
case infoLog:
|
||||
l.file[infoLog].Write(data)
|
||||
if l.oneOutput {
|
||||
l.file[s].Write(data)
|
||||
} else {
|
||||
switch s {
|
||||
case fatalLog:
|
||||
l.file[fatalLog].Write(data)
|
||||
fallthrough
|
||||
case errorLog:
|
||||
l.file[errorLog].Write(data)
|
||||
fallthrough
|
||||
case warningLog:
|
||||
l.file[warningLog].Write(data)
|
||||
fallthrough
|
||||
case infoLog:
|
||||
l.file[infoLog].Write(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1077,11 +1119,19 @@ func (sb *syncBuffer) rotateFile(now time.Time, startup bool) error {
|
||||
}
|
||||
var err error
|
||||
sb.file, _, err = create(severityName[sb.sev], now, startup)
|
||||
sb.nbytes = 0
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if startup {
|
||||
fileInfo, err := sb.file.Stat()
|
||||
if err != nil {
|
||||
return fmt.Errorf("file stat could not get fileinfo: %v", err)
|
||||
}
|
||||
// init file size
|
||||
sb.nbytes = uint64(fileInfo.Size())
|
||||
} else {
|
||||
sb.nbytes = 0
|
||||
}
|
||||
sb.Writer = bufio.NewWriterSize(sb.file, bufferSize)
|
||||
|
||||
if sb.logger.skipLogHeaders {
|
||||
@@ -1197,7 +1247,7 @@ func (lb logBridge) Write(b []byte) (n int, err error) {
|
||||
}
|
||||
// printWithFileLine with alsoToStderr=true, so standard log messages
|
||||
// always appear on standard error.
|
||||
logging.printWithFileLine(severity(lb), logging.logr, file, line, true, text)
|
||||
logging.printWithFileLine(severity(lb), logging.logr, logging.filter, file, line, true, text)
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
@@ -1231,14 +1281,16 @@ func (l *loggingT) setV(pc uintptr) Level {
|
||||
// See the documentation of V for more information.
|
||||
type Verbose struct {
|
||||
enabled bool
|
||||
logr logr.Logger
|
||||
logr *logr.Logger
|
||||
filter LogFilter
|
||||
}
|
||||
|
||||
func newVerbose(level Level, b bool) Verbose {
|
||||
if logging.logr == nil {
|
||||
return Verbose{b, nil}
|
||||
return Verbose{b, nil, logging.filter}
|
||||
}
|
||||
return Verbose{b, logging.logr.V(int(level))}
|
||||
v := logging.logr.V(int(level))
|
||||
return Verbose{b, &v, logging.filter}
|
||||
}
|
||||
|
||||
// V reports whether verbosity at the call site is at least the requested level.
|
||||
@@ -1265,7 +1317,7 @@ func V(level Level) Verbose {
|
||||
return newVerbose(level, true)
|
||||
}
|
||||
|
||||
// It's off globally but it vmodule may still be set.
|
||||
// It's off globally but vmodule may still be set.
|
||||
// Here is another cheap but safe test to see if vmodule is enabled.
|
||||
if atomic.LoadInt32(&logging.filterLength) > 0 {
|
||||
// Now we need a proper lock to use the logging structure. The pcs field
|
||||
@@ -1276,9 +1328,14 @@ func V(level Level) Verbose {
|
||||
if runtime.Callers(2, logging.pcs[:]) == 0 {
|
||||
return newVerbose(level, false)
|
||||
}
|
||||
v, ok := logging.vmap[logging.pcs[0]]
|
||||
// runtime.Callers returns "return PCs", but we want
|
||||
// to look up the symbolic information for the call,
|
||||
// so subtract 1 from the PC. runtime.CallersFrames
|
||||
// would be cleaner, but allocates.
|
||||
pc := logging.pcs[0] - 1
|
||||
v, ok := logging.vmap[pc]
|
||||
if !ok {
|
||||
v = logging.setV(logging.pcs[0])
|
||||
v = logging.setV(pc)
|
||||
}
|
||||
return newVerbose(level, v >= level)
|
||||
}
|
||||
@@ -1296,7 +1353,7 @@ func (v Verbose) Enabled() bool {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Info(args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.print(infoLog, v.logr, args...)
|
||||
logging.print(infoLog, v.logr, v.filter, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1304,7 +1361,7 @@ func (v Verbose) Info(args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Infoln(args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.println(infoLog, v.logr, args...)
|
||||
logging.println(infoLog, v.logr, v.filter, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1312,7 +1369,7 @@ func (v Verbose) Infoln(args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Infof(format string, args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.printf(infoLog, v.logr, format, args...)
|
||||
logging.printf(infoLog, v.logr, v.filter, format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1320,40 +1377,53 @@ func (v Verbose) Infof(format string, args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) InfoS(msg string, keysAndValues ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.infoS(v.logr, msg, keysAndValues...)
|
||||
logging.infoS(v.logr, v.filter, 0, msg, keysAndValues...)
|
||||
}
|
||||
}
|
||||
|
||||
// Error is equivalent to the global Error function, guarded by the value of v.
|
||||
// See the documentation of V for usage.
|
||||
// InfoSDepth acts as InfoS but uses depth to determine which call frame to log.
|
||||
// InfoSDepth(0, "msg") is the same as InfoS("msg").
|
||||
func InfoSDepth(depth int, msg string, keysAndValues ...interface{}) {
|
||||
logging.infoS(logging.logr, logging.filter, depth, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// Deprecated: Use ErrorS instead.
|
||||
func (v Verbose) Error(err error, msg string, args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.errorS(err, v.logr, msg, args...)
|
||||
logging.errorS(err, v.logr, v.filter, 0, msg, args...)
|
||||
}
|
||||
}
|
||||
|
||||
// ErrorS is equivalent to the global Error function, guarded by the value of v.
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) ErrorS(err error, msg string, keysAndValues ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.errorS(err, v.logr, v.filter, 0, msg, keysAndValues...)
|
||||
}
|
||||
}
|
||||
|
||||
// Info logs to the INFO log.
|
||||
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
|
||||
func Info(args ...interface{}) {
|
||||
logging.print(infoLog, logging.logr, args...)
|
||||
logging.print(infoLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// InfoDepth acts as Info but uses depth to determine which call frame to log.
|
||||
// InfoDepth(0, "msg") is the same as Info("msg").
|
||||
func InfoDepth(depth int, args ...interface{}) {
|
||||
logging.printDepth(infoLog, logging.logr, depth, args...)
|
||||
logging.printDepth(infoLog, logging.logr, logging.filter, depth, args...)
|
||||
}
|
||||
|
||||
// Infoln logs to the INFO log.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Infoln(args ...interface{}) {
|
||||
logging.println(infoLog, logging.logr, args...)
|
||||
logging.println(infoLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// Infof logs to the INFO log.
|
||||
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
|
||||
func Infof(format string, args ...interface{}) {
|
||||
logging.printf(infoLog, logging.logr, format, args...)
|
||||
logging.printf(infoLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// InfoS structured logs to the INFO log.
|
||||
@@ -1365,55 +1435,55 @@ func Infof(format string, args ...interface{}) {
|
||||
// output:
|
||||
// >> I1025 00:15:15.525108 1 controller_utils.go:116] "Pod status updated" pod="kubedns" status="ready"
|
||||
func InfoS(msg string, keysAndValues ...interface{}) {
|
||||
logging.infoS(logging.logr, msg, keysAndValues...)
|
||||
logging.infoS(logging.logr, logging.filter, 0, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// Warning logs to the WARNING and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
|
||||
func Warning(args ...interface{}) {
|
||||
logging.print(warningLog, logging.logr, args...)
|
||||
logging.print(warningLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// WarningDepth acts as Warning but uses depth to determine which call frame to log.
|
||||
// WarningDepth(0, "msg") is the same as Warning("msg").
|
||||
func WarningDepth(depth int, args ...interface{}) {
|
||||
logging.printDepth(warningLog, logging.logr, depth, args...)
|
||||
logging.printDepth(warningLog, logging.logr, logging.filter, depth, args...)
|
||||
}
|
||||
|
||||
// Warningln logs to the WARNING and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Warningln(args ...interface{}) {
|
||||
logging.println(warningLog, logging.logr, args...)
|
||||
logging.println(warningLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// Warningf logs to the WARNING and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
|
||||
func Warningf(format string, args ...interface{}) {
|
||||
logging.printf(warningLog, logging.logr, format, args...)
|
||||
logging.printf(warningLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// Error logs to the ERROR, WARNING, and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
|
||||
func Error(args ...interface{}) {
|
||||
logging.print(errorLog, logging.logr, args...)
|
||||
logging.print(errorLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// ErrorDepth acts as Error but uses depth to determine which call frame to log.
|
||||
// ErrorDepth(0, "msg") is the same as Error("msg").
|
||||
func ErrorDepth(depth int, args ...interface{}) {
|
||||
logging.printDepth(errorLog, logging.logr, depth, args...)
|
||||
logging.printDepth(errorLog, logging.logr, logging.filter, depth, args...)
|
||||
}
|
||||
|
||||
// Errorln logs to the ERROR, WARNING, and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Errorln(args ...interface{}) {
|
||||
logging.println(errorLog, logging.logr, args...)
|
||||
logging.println(errorLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// Errorf logs to the ERROR, WARNING, and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
|
||||
func Errorf(format string, args ...interface{}) {
|
||||
logging.printf(errorLog, logging.logr, format, args...)
|
||||
logging.printf(errorLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// ErrorS structured logs to the ERROR, WARNING, and INFO logs.
|
||||
@@ -1426,34 +1496,40 @@ func Errorf(format string, args ...interface{}) {
|
||||
// output:
|
||||
// >> E1025 00:15:15.525108 1 controller_utils.go:114] "Failed to update pod status" err="timeout"
|
||||
func ErrorS(err error, msg string, keysAndValues ...interface{}) {
|
||||
logging.errorS(err, logging.logr, msg, keysAndValues...)
|
||||
logging.errorS(err, logging.logr, logging.filter, 0, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// ErrorSDepth acts as ErrorS but uses depth to determine which call frame to log.
|
||||
// ErrorSDepth(0, "msg") is the same as ErrorS("msg").
|
||||
func ErrorSDepth(depth int, err error, msg string, keysAndValues ...interface{}) {
|
||||
logging.errorS(err, logging.logr, logging.filter, depth, msg, keysAndValues...)
|
||||
}
|
||||
|
||||
// Fatal logs to the FATAL, ERROR, WARNING, and INFO logs,
|
||||
// including a stack trace of all running goroutines, then calls os.Exit(255).
|
||||
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
|
||||
func Fatal(args ...interface{}) {
|
||||
logging.print(fatalLog, logging.logr, args...)
|
||||
logging.print(fatalLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// FatalDepth acts as Fatal but uses depth to determine which call frame to log.
|
||||
// FatalDepth(0, "msg") is the same as Fatal("msg").
|
||||
func FatalDepth(depth int, args ...interface{}) {
|
||||
logging.printDepth(fatalLog, logging.logr, depth, args...)
|
||||
logging.printDepth(fatalLog, logging.logr, logging.filter, depth, args...)
|
||||
}
|
||||
|
||||
// Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs,
|
||||
// including a stack trace of all running goroutines, then calls os.Exit(255).
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Fatalln(args ...interface{}) {
|
||||
logging.println(fatalLog, logging.logr, args...)
|
||||
logging.println(fatalLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs,
|
||||
// including a stack trace of all running goroutines, then calls os.Exit(255).
|
||||
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
|
||||
func Fatalf(format string, args ...interface{}) {
|
||||
logging.printf(fatalLog, logging.logr, format, args...)
|
||||
logging.printf(fatalLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// fatalNoStacks is non-zero if we are to exit without dumping goroutine stacks.
|
||||
@@ -1464,27 +1540,42 @@ var fatalNoStacks uint32
|
||||
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
|
||||
func Exit(args ...interface{}) {
|
||||
atomic.StoreUint32(&fatalNoStacks, 1)
|
||||
logging.print(fatalLog, logging.logr, args...)
|
||||
logging.print(fatalLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// ExitDepth acts as Exit but uses depth to determine which call frame to log.
|
||||
// ExitDepth(0, "msg") is the same as Exit("msg").
|
||||
func ExitDepth(depth int, args ...interface{}) {
|
||||
atomic.StoreUint32(&fatalNoStacks, 1)
|
||||
logging.printDepth(fatalLog, logging.logr, depth, args...)
|
||||
logging.printDepth(fatalLog, logging.logr, logging.filter, depth, args...)
|
||||
}
|
||||
|
||||
// Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
|
||||
func Exitln(args ...interface{}) {
|
||||
atomic.StoreUint32(&fatalNoStacks, 1)
|
||||
logging.println(fatalLog, logging.logr, args...)
|
||||
logging.println(fatalLog, logging.logr, logging.filter, args...)
|
||||
}
|
||||
|
||||
// Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
|
||||
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
|
||||
func Exitf(format string, args ...interface{}) {
|
||||
atomic.StoreUint32(&fatalNoStacks, 1)
|
||||
logging.printf(fatalLog, logging.logr, format, args...)
|
||||
logging.printf(fatalLog, logging.logr, logging.filter, format, args...)
|
||||
}
|
||||
|
||||
// LogFilter is a collection of functions that can filter all logging calls,
|
||||
// e.g. for sanitization of arguments and prevent accidental leaking of secrets.
|
||||
type LogFilter interface {
|
||||
Filter(args []interface{}) []interface{}
|
||||
FilterF(format string, args []interface{}) (string, []interface{})
|
||||
FilterS(msg string, keysAndValues []interface{}) (string, []interface{})
|
||||
}
|
||||
|
||||
func SetLogFilter(filter LogFilter) {
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
|
||||
logging.filter = filter
|
||||
}
|
||||
|
||||
// ObjectRef references a kubernetes object
|
||||
@@ -1510,6 +1601,13 @@ type KMetadata interface {
|
||||
|
||||
// KObj returns ObjectRef from ObjectMeta
|
||||
func KObj(obj KMetadata) ObjectRef {
|
||||
if obj == nil {
|
||||
return ObjectRef{}
|
||||
}
|
||||
if val := reflect.ValueOf(obj); val.Kind() == reflect.Ptr && val.IsNil() {
|
||||
return ObjectRef{}
|
||||
}
|
||||
|
||||
return ObjectRef{
|
||||
Name: obj.GetName(),
|
||||
Namespace: obj.GetNamespace(),
|
||||
@@ -1523,3 +1621,20 @@ func KRef(namespace, name string) ObjectRef {
|
||||
Namespace: namespace,
|
||||
}
|
||||
}
|
||||
|
||||
// KObjs returns slice of ObjectRef from an slice of ObjectMeta
|
||||
func KObjs(arg interface{}) []ObjectRef {
|
||||
s := reflect.ValueOf(arg)
|
||||
if s.Kind() != reflect.Slice {
|
||||
return nil
|
||||
}
|
||||
objectRefs := make([]ObjectRef, 0, s.Len())
|
||||
for i := 0; i < s.Len(); i++ {
|
||||
if v, ok := s.Index(i).Interface().(KMetadata); ok {
|
||||
objectRefs = append(objectRefs, KObj(v))
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return objectRefs
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -421,7 +421,7 @@ github.com/glycerine/go-unsnap-stream
|
||||
# github.com/go-logfmt/logfmt v0.5.0
|
||||
## explicit; go 1.13
|
||||
github.com/go-logfmt/logfmt
|
||||
# github.com/go-logr/logr v1.4.1
|
||||
# github.com/go-logr/logr v1.4.2
|
||||
## explicit; go 1.18
|
||||
github.com/go-logr/logr
|
||||
github.com/go-logr/logr/funcr
|
||||
@@ -1564,7 +1564,7 @@ k8s.io/cluster-bootstrap/token/util
|
||||
# k8s.io/cri-api v0.22.17
|
||||
## explicit; go 1.16
|
||||
k8s.io/cri-api/pkg/apis/runtime/v1
|
||||
# k8s.io/klog/v2 v2.2.0
|
||||
# k8s.io/klog/v2 v2.20.0
|
||||
## explicit; go 1.13
|
||||
k8s.io/klog/v2
|
||||
# k8s.io/utils v0.0.0-20200729134348-d5654de09c73
|
||||
@@ -1579,7 +1579,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240918073337-2e6f00f18670
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240918093759-100bd85aef00
|
||||
## explicit; go 1.21
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+13
-2
@@ -756,18 +756,20 @@ func (self *SRegion) CreateInstance(name string, image *SImage, instanceType str
|
||||
zoneId string, desc string, disks []cloudprovider.SDiskInfo, ipAddr string,
|
||||
keypair string, userData string, tags map[string]string, enableMonitorAgent bool,
|
||||
) (*SInstance, error) {
|
||||
params := map[string]string{}
|
||||
params, devNames := map[string]string{}, image.GetBlockDeviceNames()
|
||||
for i, disk := range disks {
|
||||
deviceName := image.RootDeviceName
|
||||
if i == 0 && len(deviceName) == 0 {
|
||||
deviceName = "/dev/sda1"
|
||||
devNames = append(devNames, deviceName)
|
||||
}
|
||||
if i > 0 {
|
||||
var err error
|
||||
deviceName, err = NextDeviceName(image.GetBlockDeviceNames())
|
||||
deviceName, err = NextDeviceName(devNames)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "NextDeviceName")
|
||||
}
|
||||
devNames = append(devNames, deviceName)
|
||||
}
|
||||
params[fmt.Sprintf("BlockDeviceMapping.%d.DeviceName", i+1)] = deviceName
|
||||
params[fmt.Sprintf("BlockDeviceMapping.%d.Ebs.DeleteOnTermination", i+1)] = "true"
|
||||
@@ -804,6 +806,15 @@ func (self *SRegion) CreateInstance(name string, image *SImage, instanceType str
|
||||
params[fmt.Sprintf("TagSpecification.1.Tag.%d.Value", tagIdx)] = v
|
||||
tagIdx++
|
||||
}
|
||||
|
||||
tagIdx = 1
|
||||
for k, v := range tags {
|
||||
params[fmt.Sprintf("TagSpecification.2.ResourceType")] = "volume"
|
||||
params[fmt.Sprintf("TagSpecification.2.Tag.%d.Key", tagIdx)] = k
|
||||
params[fmt.Sprintf("TagSpecification.2.Tag.%d.Value", tagIdx)] = v
|
||||
tagIdx++
|
||||
}
|
||||
|
||||
params["ImageId"] = image.ImageId
|
||||
params["InstanceType"] = instanceType
|
||||
params["MaxCount"] = "1"
|
||||
|
||||
+9
-21
@@ -84,32 +84,20 @@ func NextDeviceName(curDeviceNames []string) (string, error) {
|
||||
currents = append(currents, strings.ToLower(item))
|
||||
}
|
||||
|
||||
for i := 0; i < 25; i++ {
|
||||
device := fmt.Sprintf("/dev/sd%c", byte(98+i))
|
||||
found := false
|
||||
for _, item := range currents {
|
||||
if strings.HasPrefix(item, device) {
|
||||
found = true
|
||||
for _, prefix := range []string{"/dev/sd", "dev/vxd"} {
|
||||
for s := rune('a'); s < rune('z'); s++ {
|
||||
device := fmt.Sprintf("%s%c", prefix, s)
|
||||
found := false
|
||||
for _, item := range currents {
|
||||
if strings.HasPrefix(item, device) {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return device, nil
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 25; i++ {
|
||||
device := fmt.Sprintf("/dev/vxd%c", byte(98+i))
|
||||
found := false
|
||||
for _, item := range currents {
|
||||
if !strings.HasPrefix(item, device) {
|
||||
if !found {
|
||||
return device, nil
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return device, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("disk devicename out of index, current deivces: %s", currents)
|
||||
|
||||
+8
-23
@@ -576,6 +576,12 @@ func (region *SRegion) _createVM(zone string, desc *cloudprovider.SManagedVMCrea
|
||||
name = pinyinutils.Text2Pinyin(name)
|
||||
return strings.ToLower(name)
|
||||
}
|
||||
|
||||
labels := map[string]string{}
|
||||
for k, v := range desc.Tags {
|
||||
labels[encode.EncodeGoogleLabel(k)] = encode.EncodeGoogleLabel(v)
|
||||
}
|
||||
|
||||
disks = append(disks, map[string]interface{}{
|
||||
"boot": true,
|
||||
"initializeParams": map[string]interface{}{
|
||||
@@ -583,6 +589,7 @@ func (region *SRegion) _createVM(zone string, desc *cloudprovider.SManagedVMCrea
|
||||
"sourceImage": desc.ExternalImageId,
|
||||
"diskSizeGb": desc.SysDisk.SizeGB,
|
||||
"diskType": fmt.Sprintf("zones/%s/diskTypes/%s", zone, desc.SysDisk.StorageType),
|
||||
"labels": labels,
|
||||
},
|
||||
"autoDelete": true,
|
||||
})
|
||||
@@ -596,6 +603,7 @@ func (region *SRegion) _createVM(zone string, desc *cloudprovider.SManagedVMCrea
|
||||
"diskName": nameConv(disk.Name),
|
||||
"diskSizeGb": disk.SizeGB,
|
||||
"diskType": fmt.Sprintf("zones/%s/diskTypes/%s", zone, disk.StorageType),
|
||||
"labels": labels,
|
||||
},
|
||||
"autoDelete": true,
|
||||
})
|
||||
@@ -617,11 +625,6 @@ func (region *SRegion) _createVM(zone string, desc *cloudprovider.SManagedVMCrea
|
||||
"disks": disks,
|
||||
}
|
||||
|
||||
labels := map[string]string{}
|
||||
for k, v := range desc.Tags {
|
||||
labels[encode.EncodeGoogleLabel(k)] = encode.EncodeGoogleLabel(v)
|
||||
}
|
||||
|
||||
if len(labels) > 0 {
|
||||
params["labels"] = labels
|
||||
}
|
||||
@@ -649,24 +652,6 @@ func (region *SRegion) _createVM(zone string, desc *cloudprovider.SManagedVMCrea
|
||||
},
|
||||
}
|
||||
}
|
||||
//if len(serviceAccounts) > 0 {
|
||||
// params["serviceAccounts"] = []struct {
|
||||
// Email string
|
||||
// Scopes []string
|
||||
// }{
|
||||
// {
|
||||
// Email: serviceAccounts[0],
|
||||
// Scopes: []string{
|
||||
// "https://www.googleapis.com/auth/devstorage.read_only",
|
||||
// "https://www.googleapis.com/auth/logging.write",
|
||||
// "https://www.googleapis.com/auth/monitoring.write",
|
||||
// "https://www.googleapis.com/auth/servicecontrol",
|
||||
// "https://www.googleapis.com/auth/service.management.readonly",
|
||||
// "https://www.googleapis.com/auth/trace.append",
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
//}
|
||||
log.Debugf("create google instance params: %s", jsonutils.Marshal(params).String())
|
||||
instance := &SInstance{}
|
||||
resource := fmt.Sprintf("zones/%s/instances", zone)
|
||||
|
||||
Reference in New Issue
Block a user