Merge pull request #30603 from robertsirc/converting-to-slog

converting inline log to slog
pull/30534/merge
Matt Farina 6 months ago committed by GitHub
commit ab9f0c80b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -21,7 +21,7 @@ limitations under the License.
package sympath
import (
"log"
"log/slog"
"os"
"path/filepath"
"sort"
@ -72,7 +72,7 @@ func symwalk(path string, info os.FileInfo, walkFn filepath.WalkFunc) error {
return errors.Wrapf(err, "error evaluating symlink %s", path)
}
//This log message is to highlight a symlink that is being used within a chart, symlinks can be used for nefarious reasons.
log.Printf("found symbolic link in path: %s resolves to %s. Contents of linked file included and used", path, resolved)
slog.Info("found symbolic link in path. Contents of linked file included and used", "path", path, "resolved", resolved)
if info, err = os.Lstat(resolved); err != nil {
return err
}

@ -16,7 +16,7 @@ limitations under the License.
package util
import (
"log"
"log/slog"
"strings"
"github.com/mitchellh/copystructure"
@ -48,10 +48,10 @@ func processDependencyConditions(reqs []*chart.Dependency, cvals Values, cpath s
r.Enabled = bv
break
}
log.Printf("Warning: Condition path '%s' for chart %s returned non-bool value", c, r.Name)
slog.Warn("returned non-bool value", "path", c, "chart", r.Name)
} else if _, ok := err.(ErrNoValue); !ok {
// this is a real error
log.Printf("Warning: PathValue returned error %v", err)
slog.Warn("the method PathValue returned error", slog.Any("error", err))
}
}
}
@ -79,7 +79,7 @@ func processDependencyTags(reqs []*chart.Dependency, cvals Values) {
hasFalse = true
}
} else {
log.Printf("Warning: Tag '%s' for chart %s returned non-bool value", k, r.Name)
slog.Warn("returned non-bool value", "tag", k, "chart", r.Name)
}
}
}
@ -254,7 +254,7 @@ func processImportValues(c *chart.Chart, merge bool) error {
// get child table
vv, err := cvals.Table(r.Name + "." + child)
if err != nil {
log.Printf("Warning: ImportValues missing table from chart %s: %v", r.Name, err)
slog.Warn("ImportValues missing table from chart", "chart", r.Name, "error", err)
continue
}
// create value map from child to be merged into parent
@ -271,7 +271,7 @@ func processImportValues(c *chart.Chart, merge bool) error {
})
vm, err := cvals.Table(r.Name + "." + child)
if err != nil {
log.Printf("Warning: ImportValues missing table: %v", err)
slog.Warn("ImportValues missing table", slog.Any("error", err))
continue
}
if merge {

@ -18,7 +18,7 @@ package engine
import (
"fmt"
"log"
"log/slog"
"path"
"path/filepath"
"regexp"
@ -203,7 +203,7 @@ func (e Engine) initFunMap(t *template.Template) {
if val == nil {
if e.LintMode {
// Don't fail on missing required values when linting
log.Printf("[INFO] Missing required value: %s", warn)
slog.Warn("missing required value", "message", warn)
return "", nil
}
return val, errors.New(warnWrap(warn))
@ -211,7 +211,7 @@ func (e Engine) initFunMap(t *template.Template) {
if val == "" {
if e.LintMode {
// Don't fail on missing required values when linting
log.Printf("[INFO] Missing required value: %s", warn)
slog.Warn("missing required values", "message", warn)
return "", nil
}
return val, errors.New(warnWrap(warn))
@ -224,7 +224,7 @@ func (e Engine) initFunMap(t *template.Template) {
funcMap["fail"] = func(msg string) (string, error) {
if e.LintMode {
// Don't fail when linting
log.Printf("[INFO] Fail: %s", msg)
slog.Info("funcMap fail", "message", msg)
return "", nil
}
return "", errors.New(warnWrap(msg))

@ -18,7 +18,7 @@ package engine
import (
"context"
"log"
"log/slog"
"strings"
"github.com/pkg/errors"
@ -101,7 +101,7 @@ func getDynamicClientOnKind(apiversion string, kind string, config *rest.Config)
gvk := schema.FromAPIVersionAndKind(apiversion, kind)
apiRes, err := getAPIResourceForGVK(gvk, config)
if err != nil {
log.Printf("[ERROR] unable to get apiresource from unstructured: %s , error %s", gvk.String(), err)
slog.Error("unable to get apiresource", "groupVersionKind", gvk.String(), "error", err)
return nil, false, errors.Wrapf(err, "unable to get apiresource from unstructured: %s", gvk.String())
}
gvr := schema.GroupVersionResource{
@ -111,7 +111,7 @@ func getDynamicClientOnKind(apiversion string, kind string, config *rest.Config)
}
intf, err := dynamic.NewForConfig(config)
if err != nil {
log.Printf("[ERROR] unable to get dynamic client %s", err)
slog.Error("unable to get dynamic client", slog.Any("error", err))
return nil, false, err
}
res := intf.Resource(gvr)
@ -122,12 +122,12 @@ func getAPIResourceForGVK(gvk schema.GroupVersionKind, config *rest.Config) (met
res := metav1.APIResource{}
discoveryClient, err := discovery.NewDiscoveryClientForConfig(config)
if err != nil {
log.Printf("[ERROR] unable to create discovery client %s", err)
slog.Error("unable to create discovery client", slog.Any("error", err))
return res, err
}
resList, err := discoveryClient.ServerResourcesForGroupVersion(gvk.GroupVersion().String())
if err != nil {
log.Printf("[ERROR] unable to retrieve resource list for: %s , error: %s", gvk.GroupVersion().String(), err)
slog.Error("unable to retrieve resource list", "GroupVersion", gvk.GroupVersion().String(), "error", err)
return res, err
}
for _, resource := range resList.APIResources {

@ -20,7 +20,7 @@ import (
"bufio"
"bytes"
"io"
"log"
"log/slog"
"os"
"path/filepath"
"strings"
@ -102,7 +102,7 @@ func (r *Rules) Ignore(path string, fi os.FileInfo) bool {
}
for _, p := range r.patterns {
if p.match == nil {
log.Printf("ignore: no matcher supplied for %q", p.raw)
slog.Info("this will be ignored no matcher supplied", "patterns", p.raw)
return false
}
@ -177,7 +177,7 @@ func (r *Rules) parseRule(rule string) error {
rule = strings.TrimPrefix(rule, "/")
ok, err := filepath.Match(rule, n)
if err != nil {
log.Printf("Failed to compile %q: %s", rule, err)
slog.Error("failed to compile", "rule", rule, "error", err)
return false
}
return ok
@ -187,7 +187,7 @@ func (r *Rules) parseRule(rule string) error {
p.match = func(n string, _ os.FileInfo) bool {
ok, err := filepath.Match(rule, n)
if err != nil {
log.Printf("Failed to compile %q: %s", rule, err)
slog.Error("failed to compile", "rule", rule, "error", err)
return false
}
return ok
@ -199,7 +199,7 @@ func (r *Rules) parseRule(rule string) error {
n = filepath.Base(n)
ok, err := filepath.Match(rule, n)
if err != nil {
log.Printf("Failed to compile %q: %s", rule, err)
slog.Error("failed to compile", "rule", rule, "error", err)
return false
}
return ok

@ -20,6 +20,7 @@ import (
"bytes"
"compress/gzip"
"io"
"log/slog"
"os"
"path"
"path/filepath"
@ -144,7 +145,7 @@ func (i *HTTPInstaller) Install() error {
return err
}
debug("copying %s to %s", src, i.Path())
slog.Debug("copying", "source", src, "path", i.Path())
return fs.CopyDir(src, i.Path())
}

@ -16,8 +16,6 @@ limitations under the License.
package installer
import (
"fmt"
"log"
"net/http"
"os"
"path/filepath"
@ -125,11 +123,3 @@ func isPlugin(dirname string) bool {
_, err := os.Stat(filepath.Join(dirname, plugin.PluginFileName))
return err == nil
}
var logger = log.New(os.Stderr, "[debug] ", log.Lshortfile)
func debug(format string, args ...interface{}) {
if Debug {
logger.Output(2, fmt.Sprintf(format, args...))
}
}

@ -16,6 +16,7 @@ limitations under the License.
package installer // import "helm.sh/helm/v4/pkg/plugin/installer"
import (
"log/slog"
"os"
"path/filepath"
@ -57,12 +58,12 @@ func (i *LocalInstaller) Install() error {
if !isPlugin(i.Source) {
return ErrMissingMetadata
}
debug("symlinking %s to %s", i.Source, i.Path())
slog.Debug("symlinking", "source", i.Source, "path", i.Path())
return os.Symlink(i.Source, i.Path())
}
// Update updates a local repository
func (i *LocalInstaller) Update() error {
debug("local repository is auto-updated")
slog.Debug("local repository is auto-updated")
return nil
}

@ -16,6 +16,7 @@ limitations under the License.
package installer // import "helm.sh/helm/v4/pkg/plugin/installer"
import (
"log/slog"
"os"
"sort"
@ -88,13 +89,13 @@ func (i *VCSInstaller) Install() error {
return ErrMissingMetadata
}
debug("copying %s to %s", i.Repo.LocalPath(), i.Path())
slog.Debug("copying files", "source", i.Repo.LocalPath(), "destination", i.Path())
return fs.CopyDir(i.Repo.LocalPath(), i.Path())
}
// Update updates a remote repository
func (i *VCSInstaller) Update() error {
debug("updating %s", i.Repo.Remote())
slog.Debug("updating", "source", i.Repo.Remote())
if i.Repo.IsDirty() {
return errors.New("plugin repo was modified")
}
@ -128,7 +129,7 @@ func (i *VCSInstaller) solveVersion(repo vcs.Repo) (string, error) {
if err != nil {
return "", err
}
debug("found refs: %s", refs)
slog.Debug("found refs", "refs", refs)
// Convert and filter the list to semver.Version instances
semvers := getSemVers(refs)
@ -139,7 +140,7 @@ func (i *VCSInstaller) solveVersion(repo vcs.Repo) (string, error) {
if constraint.Check(v) {
// If the constraint passes get the original reference
ver := v.Original()
debug("setting to %s", ver)
slog.Debug("setting to version", "version", ver)
return ver, nil
}
}
@ -149,17 +150,17 @@ func (i *VCSInstaller) solveVersion(repo vcs.Repo) (string, error) {
// setVersion attempts to checkout the version
func (i *VCSInstaller) setVersion(repo vcs.Repo, ref string) error {
debug("setting version to %q", i.Version)
slog.Debug("setting version", "version", i.Version)
return repo.UpdateVersion(ref)
}
// sync will clone or update a remote repo.
func (i *VCSInstaller) sync(repo vcs.Repo) error {
if _, err := os.Stat(repo.LocalPath()); os.IsNotExist(err) {
debug("cloning %s to %s", repo.Remote(), repo.LocalPath())
slog.Debug("cloning", "source", repo.Remote(), "destination", repo.LocalPath())
return repo.Get()
}
debug("updating %s", repo.Remote())
slog.Debug("updating", "source", repo.Remote(), "destination", repo.LocalPath())
return repo.Update()
}

@ -17,7 +17,7 @@ limitations under the License.
package util
import (
"log"
"log/slog"
"path"
"sort"
"strconv"
@ -196,7 +196,7 @@ func (file *manifestFile) sort(result *result) error {
}
if isUnknownHook {
log.Printf("info: skipping unknown hook: %q", hookTypes)
slog.Info("skipping unknown hooks", "hookTypes", hookTypes)
continue
}

@ -22,7 +22,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"log/slog"
"net/url"
"os"
"path/filepath"
@ -343,7 +343,8 @@ func ResolveReferenceURL(baseURL, refURL string) (string, error) {
func (e *Entry) String() string {
buf, err := json.Marshal(e)
if err != nil {
log.Panic(err)
slog.Error("failed to marshal entry", slog.Any("error", err))
panic(err)
}
return string(buf)
}

Loading…
Cancel
Save