From 1707b380e2862837c8cc841901fa7fe0f79ec8ff Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Mar 2023 05:17:15 +0000 Subject: [PATCH] Bump github.com/vmware-tanzu/velero from 1.10.0 to 1.10.2 Bumps [github.com/vmware-tanzu/velero](https://github.com/vmware-tanzu/velero) from 1.10.0 to 1.10.2. - [Release notes](https://github.com/vmware-tanzu/velero/releases) - [Changelog](https://github.com/vmware-tanzu/velero/blob/main/CHANGELOG.md) - [Commits](https://github.com/vmware-tanzu/velero/compare/v1.10.0...v1.10.2) --- updated-dependencies: - dependency-name: github.com/vmware-tanzu/velero dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../pkg/util/logging/log_counter_hook.go | 67 +++++++++++++++---- .../velero/pkg/util/results/result.go | 67 +++++++++++++++++++ vendor/modules.txt | 3 +- 5 files changed, 127 insertions(+), 16 deletions(-) create mode 100644 vendor/github.com/vmware-tanzu/velero/pkg/util/results/result.go diff --git a/go.mod b/go.mod index 5de35de2..81d50c5a 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/sirupsen/logrus v1.9.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.1 - github.com/vmware-tanzu/velero v1.10.0 + github.com/vmware-tanzu/velero v1.10.2 k8s.io/api v0.24.2 k8s.io/apimachinery v0.25.4 k8s.io/client-go v12.0.0+incompatible diff --git a/go.sum b/go.sum index 7b484b8c..6634834a 100644 --- a/go.sum +++ b/go.sum @@ -833,8 +833,8 @@ github.com/uber/jaeger-lib v2.2.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6 github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= -github.com/vmware-tanzu/velero v1.10.0 h1:32A6yxH9zmMnNUT9HO7P5Y3GscUNZVqozDEb+mC2jCg= -github.com/vmware-tanzu/velero v1.10.0/go.mod h1:k/1NPNxfhAeUeBuIL6HJuKtTFPgmpiWP+cHa3zi3ZQM= +github.com/vmware-tanzu/velero v1.10.2 h1:Vxao3R4wjmw6iR2W7ihdreKpqjuMA7Kjxne7ByjUQfQ= +github.com/vmware-tanzu/velero v1.10.2/go.mod h1:FZJMmwYCeiE3lu/SBL/pP1bRGdju6zK4/vCE4s3A3Wo= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= diff --git a/vendor/github.com/vmware-tanzu/velero/pkg/util/logging/log_counter_hook.go b/vendor/github.com/vmware-tanzu/velero/pkg/util/logging/log_counter_hook.go index d8d53359..a14b790f 100644 --- a/vendor/github.com/vmware-tanzu/velero/pkg/util/logging/log_counter_hook.go +++ b/vendor/github.com/vmware-tanzu/velero/pkg/util/logging/log_counter_hook.go @@ -17,45 +17,88 @@ limitations under the License. package logging import ( + "errors" + "fmt" "sync" "github.com/sirupsen/logrus" + + "github.com/vmware-tanzu/velero/pkg/util/results" ) -// LogCounterHook is a logrus hook that counts the number of log -// statements that have been written at each logrus level. -type LogCounterHook struct { - mu sync.RWMutex - counts map[logrus.Level]int +// LogHook is a logrus hook that counts the number of log +// statements that have been written at each logrus level. It also +// maintains log entries at each logrus level in result structure. +type LogHook struct { + mu sync.RWMutex + counts map[logrus.Level]int + entries map[logrus.Level]*results.Result } -// NewLogCounterHook returns a pointer to an initialized LogCounterHook. -func NewLogCounterHook() *LogCounterHook { - return &LogCounterHook{ - counts: make(map[logrus.Level]int), +// NewLogHook returns a pointer to an initialized LogHook. +func NewLogHook() *LogHook { + return &LogHook{ + counts: make(map[logrus.Level]int), + entries: make(map[logrus.Level]*results.Result), } } // Levels returns the logrus levels that the hook should be fired for. -func (h *LogCounterHook) Levels() []logrus.Level { +func (h *LogHook) Levels() []logrus.Level { return logrus.AllLevels } // Fire executes the hook's logic. -func (h *LogCounterHook) Fire(entry *logrus.Entry) error { +func (h *LogHook) Fire(entry *logrus.Entry) error { h.mu.Lock() defer h.mu.Unlock() h.counts[entry.Level]++ + if h.entries[entry.Level] == nil { + h.entries[entry.Level] = &results.Result{} + } + + namespace, isNamespacePresent := entry.Data["namespace"] + errorField, isErrorFieldPresent := entry.Data["error"] + resourceField, isResourceFieldPresent := entry.Data["resource"] + nameField, isNameFieldPresent := entry.Data["name"] + + entryMessage := "" + if isResourceFieldPresent { + entryMessage = fmt.Sprintf("%s resource: /%s", entryMessage, resourceField.(string)) + } + if isNameFieldPresent { + entryMessage = fmt.Sprintf("%s name: /%s", entryMessage, nameField.(string)) + } + if isErrorFieldPresent { + entryMessage = fmt.Sprintf("%s error: /%s", entryMessage, errorField.(error).Error()) + } + if isNamespacePresent { + h.entries[entry.Level].Add(namespace.(string), errors.New(entryMessage)) + } else { + h.entries[entry.Level].AddVeleroError(errors.New(entryMessage)) + } return nil } // GetCount returns the number of log statements that have been // written at the specific level provided. -func (h *LogCounterHook) GetCount(level logrus.Level) int { +func (h *LogHook) GetCount(level logrus.Level) int { h.mu.RLock() defer h.mu.RUnlock() return h.counts[level] } + +// GetEntries returns the log statements that have been +// written at the specific level provided. +func (h *LogHook) GetEntries(level logrus.Level) results.Result { + h.mu.RLock() + defer h.mu.RUnlock() + response, isPresent := h.entries[level] + if isPresent { + return *response + } + return results.Result{} +} diff --git a/vendor/github.com/vmware-tanzu/velero/pkg/util/results/result.go b/vendor/github.com/vmware-tanzu/velero/pkg/util/results/result.go new file mode 100644 index 00000000..f211b8b1 --- /dev/null +++ b/vendor/github.com/vmware-tanzu/velero/pkg/util/results/result.go @@ -0,0 +1,67 @@ +/* +Copyright 2019, 2020 the Velero contributors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package results + +// Result is a collection of messages that were generated during +// execution of a backup or restore. This will typically store either +// warning or error messages. +type Result struct { + // Velero is a slice of messages related to the operation of Velero + // itself (for example, messages related to connecting to the + // cloud, reading a backup file, etc.) + Velero []string `json:"velero,omitempty"` + + // Cluster is a slice of messages related to backup or restore of + // cluster-scoped resources. + Cluster []string `json:"cluster,omitempty"` + + // Namespaces is a map of namespace name to slice of messages + // related to backup or restore namespace-scoped resources. + Namespaces map[string][]string `json:"namespaces,omitempty"` +} + +// Merge combines two Result objects into one +// by appending the corresponding lists to one another. +func (r *Result) Merge(other *Result) { + r.Cluster = append(r.Cluster, other.Cluster...) + r.Velero = append(r.Velero, other.Velero...) + for k, v := range other.Namespaces { + if r.Namespaces == nil { + r.Namespaces = make(map[string][]string) + } + r.Namespaces[k] = append(r.Namespaces[k], v...) + } +} + +// AddVeleroError appends an error to the provided Result's Velero list. +func (r *Result) AddVeleroError(err error) { + r.Velero = append(r.Velero, err.Error()) +} + +// Add appends an error to the provided Result, either within +// the cluster-scoped list (if ns == "") or within the provided namespace's +// entry. +func (r *Result) Add(ns string, e error) { + if ns == "" { + r.Cluster = append(r.Cluster, e.Error()) + } else { + if r.Namespaces == nil { + r.Namespaces = make(map[string][]string) + } + r.Namespaces[ns] = append(r.Namespaces[ns], e.Error()) + } +} diff --git a/vendor/modules.txt b/vendor/modules.txt index a8ec0c23..46c4bb8c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -204,7 +204,7 @@ github.com/spf13/pflag # github.com/stretchr/testify v1.8.1 ## explicit; go 1.13 github.com/stretchr/testify/assert -# github.com/vmware-tanzu/velero v1.10.0 +# github.com/vmware-tanzu/velero v1.10.2 ## explicit; go 1.18 github.com/vmware-tanzu/velero/pkg/apis/velero/v1 github.com/vmware-tanzu/velero/pkg/cmd/util/flag @@ -221,6 +221,7 @@ github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1 github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1 github.com/vmware-tanzu/velero/pkg/util/collections github.com/vmware-tanzu/velero/pkg/util/logging +github.com/vmware-tanzu/velero/pkg/util/results github.com/vmware-tanzu/velero/third_party/kubernetes/pkg/kubectl/cmd/util # golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 ## explicit; go 1.17