mirror of
https://github.com/helm/helm.git
synced 2026-04-20 21:56:55 -04:00
Demonstrate the impact of having Logger defined in kube package
Signed-off-by: Benoit Tigeot <benoit.tigeot@lifen.fr>
This commit is contained in:
parent
ede73860c1
commit
fae2345edf
5 changed files with 22 additions and 18 deletions
|
|
@ -20,7 +20,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
|
@ -96,7 +95,7 @@ type Configuration struct {
|
|||
// Capabilities describes the capabilities of the Kubernetes cluster.
|
||||
Capabilities *chartutil.Capabilities
|
||||
|
||||
Log func(string, ...interface{})
|
||||
Log kube.Logger
|
||||
|
||||
// HookOutputFunc called with container name and returns and expects writer that will receive the log output.
|
||||
HookOutputFunc func(namespace, pod, container string) io.Writer
|
||||
|
|
@ -270,8 +269,8 @@ func (cfg *Configuration) getCapabilities() (*chartutil.Capabilities, error) {
|
|||
apiVersions, err := GetVersionSet(dc)
|
||||
if err != nil {
|
||||
if discovery.IsGroupDiscoveryFailedError(err) {
|
||||
cfg.Log("WARNING: The Kubernetes server has an orphaned API service. Server reports: %s", err)
|
||||
cfg.Log("WARNING: To fix this, kubectl delete apiservice <service-name>")
|
||||
cfg.Log.Warn("The Kubernetes server has an orphaned API service. Server reports: %s", err)
|
||||
cfg.Log.Warn("To fix this, kubectl delete apiservice <service-name>")
|
||||
} else {
|
||||
return nil, errors.Wrap(err, "could not get apiVersions from Kubernetes")
|
||||
}
|
||||
|
|
@ -370,14 +369,14 @@ func GetVersionSet(client discovery.ServerResourcesInterface) (chartutil.Version
|
|||
// recordRelease with an update operation in case reuse has been set.
|
||||
func (cfg *Configuration) recordRelease(r *release.Release) {
|
||||
if err := cfg.Releases.Update(r); err != nil {
|
||||
cfg.Log("warning: Failed to update release %s: %s", r.Name, err)
|
||||
cfg.Log.Warn("Failed to update release %s: %s", r.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Init initializes the action configuration
|
||||
func (cfg *Configuration) Init(getter genericclioptions.RESTClientGetter, namespace, helmDriver string, log DebugLog) error {
|
||||
func (cfg *Configuration) Init(getter genericclioptions.RESTClientGetter, namespace, helmDriver string, log kube.Logger) error {
|
||||
kc := kube.New(getter)
|
||||
kc.Log = kube.NewSlogAdapter(slog.Default())
|
||||
kc.Log = log
|
||||
|
||||
lazyClient := &lazyClient{
|
||||
namespace: namespace,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package cmd
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
|
|
@ -28,6 +29,7 @@ import (
|
|||
"helm.sh/helm/v4/pkg/action"
|
||||
"helm.sh/helm/v4/pkg/cli/output"
|
||||
"helm.sh/helm/v4/pkg/cmd/require"
|
||||
"helm.sh/helm/v4/pkg/kube"
|
||||
release "helm.sh/helm/v4/pkg/release/v1"
|
||||
)
|
||||
|
||||
|
|
@ -61,6 +63,8 @@ flag with the '--offset' flag allows you to page through results.
|
|||
func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
||||
client := action.NewList(cfg)
|
||||
var outfmt output.Format
|
||||
slogger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
||||
adapter := kube.NewSlogAdapter(slogger)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "list",
|
||||
|
|
@ -71,7 +75,7 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|||
ValidArgsFunction: noMoreArgsCompFunc,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
if client.AllNamespaces {
|
||||
if err := cfg.Init(settings.RESTClientGetter(), "", os.Getenv("HELM_DRIVER"), Debug); err != nil {
|
||||
if err := cfg.Init(settings.RESTClientGetter(), "", os.Getenv("HELM_DRIVER"), adapter); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/validation"
|
||||
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
|
||||
"helm.sh/helm/v4/pkg/kube"
|
||||
rspb "helm.sh/helm/v4/pkg/release/v1"
|
||||
)
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ const ConfigMapsDriverName = "ConfigMap"
|
|||
// ConfigMapsInterface.
|
||||
type ConfigMaps struct {
|
||||
impl corev1.ConfigMapInterface
|
||||
Log func(string, ...interface{})
|
||||
Log kube.Logger
|
||||
}
|
||||
|
||||
// NewConfigMaps initializes a new ConfigMaps wrapping an implementation of
|
||||
|
|
@ -51,7 +52,6 @@ type ConfigMaps struct {
|
|||
func NewConfigMaps(impl corev1.ConfigMapInterface) *ConfigMaps {
|
||||
return &ConfigMaps{
|
||||
impl: impl,
|
||||
Log: func(_ string, _ ...interface{}) {},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/validation"
|
||||
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
|
||||
"helm.sh/helm/v4/pkg/kube"
|
||||
rspb "helm.sh/helm/v4/pkg/release/v1"
|
||||
)
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ const SecretsDriverName = "Secret"
|
|||
// SecretsInterface.
|
||||
type Secrets struct {
|
||||
impl corev1.SecretInterface
|
||||
Log func(string, ...interface{})
|
||||
Log kube.Logger
|
||||
}
|
||||
|
||||
// NewSecrets initializes a new Secrets wrapping an implementation of
|
||||
|
|
@ -51,7 +52,6 @@ type Secrets struct {
|
|||
func NewSecrets(impl corev1.SecretInterface) *Secrets {
|
||||
return &Secrets{
|
||||
impl: impl,
|
||||
Log: func(_ string, _ ...interface{}) {},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ func (secrets *Secrets) List(filter func(*rspb.Release) bool) ([]*rspb.Release,
|
|||
for _, item := range list.Items {
|
||||
rls, err := decodeRelease(string(item.Data["release"]))
|
||||
if err != nil {
|
||||
secrets.Log("list: failed to decode release: %v: %s", item, err)
|
||||
secrets.Log.Debug("list: failed to decode release: %v: %s", item, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ func (secrets *Secrets) Query(labels map[string]string) ([]*rspb.Release, error)
|
|||
for _, item := range list.Items {
|
||||
rls, err := decodeRelease(string(item.Data["release"]))
|
||||
if err != nil {
|
||||
secrets.Log("query: failed to decode release: %s", err)
|
||||
secrets.Log.Debug("query: failed to decode release: %s", err)
|
||||
continue
|
||||
}
|
||||
rls.Labels = item.ObjectMeta.Labels
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
// Import pq for postgres dialect
|
||||
_ "github.com/lib/pq"
|
||||
|
||||
"helm.sh/helm/v4/pkg/kube"
|
||||
rspb "helm.sh/helm/v4/pkg/release/v1"
|
||||
)
|
||||
|
||||
|
|
@ -87,7 +88,7 @@ type SQL struct {
|
|||
namespace string
|
||||
statementBuilder sq.StatementBuilderType
|
||||
|
||||
Log func(string, ...interface{})
|
||||
Log kube.Logger
|
||||
}
|
||||
|
||||
// Name returns the name of the driver.
|
||||
|
|
@ -108,13 +109,13 @@ func (s *SQL) checkAlreadyApplied(migrations []*migrate.Migration) bool {
|
|||
records, err := migrate.GetMigrationRecords(s.db.DB, postgreSQLDialect)
|
||||
migrate.SetDisableCreateTable(false)
|
||||
if err != nil {
|
||||
s.Log("checkAlreadyApplied: failed to get migration records: %v", err)
|
||||
s.Log.Debug("checkAlreadyApplied: failed to get migration records: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
for _, record := range records {
|
||||
if _, ok := migrationsIDs[record.Id]; ok {
|
||||
s.Log("checkAlreadyApplied: found previous migration (Id: %v) applied at %v", record.Id, record.AppliedAt)
|
||||
s.Log.Debug("checkAlreadyApplied: found previous migration (Id: %v) applied at %v", record.Id, record.AppliedAt)
|
||||
delete(migrationsIDs, record.Id)
|
||||
}
|
||||
}
|
||||
|
|
@ -276,7 +277,7 @@ type SQLReleaseCustomLabelWrapper struct {
|
|||
}
|
||||
|
||||
// NewSQL initializes a new sql driver.
|
||||
func NewSQL(connectionString string, logger func(string, ...interface{}), namespace string) (*SQL, error) {
|
||||
func NewSQL(connectionString string, logger kube.Logger, namespace string) (*SQL, error) {
|
||||
db, err := sqlx.Connect(postgreSQLDialect, connectionString)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Reference in a new issue