werf / kubedog

Library to watch and follow kubernetes resources in CI/CD deploy pipelines
Apache License 2.0
635 stars 45 forks source link

Bug: not enough arguments in call to restmapper.NewShortcutExpander #319

Closed very-doge-wow closed 6 months ago

very-doge-wow commented 7 months ago

I'm trying to use the library as specified in: https://github.com/werf/kubedog/blob/main/doc/usage.md#examples-of-using-trackers

However I always receive this error:

/go/pkg/mod/github.com/werf/kubedog@v0.11.0/pkg/kube/kube.go:402:48: not enough arguments in call to restmapper.NewShortcutExpander have (restmapper.DeferredDiscoveryRESTMapper, discovery.CachedDiscoveryInterface) want (meta.RESTMapper, discovery.DiscoveryInterface, func(string)) /go/pkg/mod/github.com/werf/kubedog@v0.11.0/pkg/kube/kube_config_getter.go:134:53: not enough arguments in call to restmapper.NewShortcutExpander have (restmapper.DeferredDiscoveryRESTMapper, discovery.CachedDiscoveryInterface) want (meta.RESTMapper, discovery.DiscoveryInterface, func(string)

This is my code:

// init kubedog to watch resources
err = kube.Init(kube.InitOptions{})
if err != nil {
    fmt.Fprintf(os.Stderr, "Unable to initialize kube: %s\n", err)
    os.Exit(1)
}

err = multitrack.Multitrack(
    kube.Kubernetes,
    multitrack.MultitrackSpecs{
        Deployments: []multitrack.MultitrackSpec{
            multitrack.MultitrackSpec{
                ResourceName: h.Configuration.ApplicationName,
                Namespace:    h.Configuration.Namespace,
            },
        },
    },
    multitrack.MultitrackOptions{},
)

if err != nil {
    log.Errorf("ERROR: resources have not reached ready state: %s", err)
    return err
}

I am using the most current version v0.11.0. Any help would be appreciated.

very-doge-wow commented 7 months ago

Seems to be because we use v0.29.0 of client-go and kubedog uses v0.26.2, so the signature of the function has changed. How often do you integrate updates of dependencies here?

distorhead commented 7 months ago

Hi, thanks for the report!

I think we can arrange client-go upgrade asap during this week.

distorhead commented 7 months ago

@very-doge-wow Hi!

Just updated client-go to 1.29 https://github.com/werf/kubedog/pull/320, check it out!

very-doge-wow commented 7 months ago

Thanks, will try it after the holidays.

very-doge-wow commented 6 months ago

Have tested and it works now, thanks. Still the question, how often do you integrate updates?

very-doge-wow commented 6 months ago

I am also receiving the following warning, not sure how to fix this:

W0102 12:29:23.926279 59 reflector.go:462] pkg/mod/k8s.io/client-go@v0.29.0/tools/cache/reflector.go:229: watch of *v1.Event ended with: an error on the server ("unable to decode an event from the watch stream: context canceled") has prevented the request from succeeding

Any advice? 🤔

distorhead commented 6 months ago

how often do you integrate updates

@very-doge-wow Hi! As for your question: we are about to setup our periodical routine to update dependencies once in 3 or 4 weeks (security updates should be merged asap of course).

It is important to know that kubedog project being used by such projects as: werf/werf and werf/nelm, and sometimes some dependencies updates may be blocked by these projects, but we are currently on a way to cleanup some old stuff from werf and keep dependencies as fresh as possible.

W0102 12:29:23.926279 59 reflector.go:462] pkg/mod/k8s.io/client-go@v0.29.0/tools/cache/reflector.go:229: watch of *v1.Event ended with: an error on the server ("unable to decode an event from the watch stream: context canceled") has prevented the request from succeeding

This is just harmless warning from inside client-go internals, which is part of it normal operation. However if you want to suppress these messages see this logger initialization snippet:

func SilenceKlogV2(ctx context.Context) error {
    fs := flag.NewFlagSet("klog", flag.PanicOnError)
    klog_v2.InitFlags(fs)

    if err := fs.Set("logtostderr", "false"); err != nil {
        return err
    }
    if err := fs.Set("alsologtostderr", "false"); err != nil {
        return err
    }
    if err := fs.Set("stderrthreshold", "5"); err != nil {
        return err
    }

    // Suppress info and warnings from client-go reflector
    klog_v2.SetOutputBySeverity("INFO", ioutil.Discard)
    klog_v2.SetOutputBySeverity("WARNING", ioutil.Discard)
    klog_v2.SetOutputBySeverity("ERROR", ioutil.Discard)
    klog_v2.SetOutputBySeverity("FATAL", logboek.Context(ctx).ErrStream())

    return nil
}

func SilenceKlog(ctx context.Context) error {
    fs := flag.NewFlagSet("klog", flag.PanicOnError)
    klog.InitFlags(fs)

    if err := fs.Set("logtostderr", "false"); err != nil {
        return err
    }
    if err := fs.Set("alsologtostderr", "false"); err != nil {
        return err
    }
    if err := fs.Set("stderrthreshold", "5"); err != nil {
        return err
    }

    // Suppress info and warnings from client-go reflector
    klog.SetOutputBySeverity("INFO", ioutil.Discard)
    klog.SetOutputBySeverity("WARNING", ioutil.Discard)
    klog.SetOutputBySeverity("ERROR", ioutil.Discard)
    klog.SetOutputBySeverity("FATAL", logboek.Context(ctx).ErrStream())

    return nil
}

https://github.com/werf/kubedog/blob/main/cmd/kubedog/main.go#L72C13-L72C24