Skip to content

Commit

Permalink
redirect code that moved:
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Nichols committed Oct 6, 2020
1 parent 24f3a3d commit ff42410
Showing 1 changed file with 6 additions and 78 deletions.
84 changes: 6 additions & 78 deletions injection/sharedmain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,22 @@ package sharedmain

import (
"context"
"errors"
"flag"
"log"
"net/http"
"os"
"os/user"
"path/filepath"
"time"

"go.opencensus.io/stats/view"
_ "go.uber.org/automaxprocs" // automatically set GOMAXPROCS based on cgroups
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"

_ "go.uber.org/automaxprocs" // automatically set GOMAXPROCS based on cgroups
"go.uber.org/zap"

kubeclient "knative.dev/pkg/client/injection/kube/client"
"knative.dev/pkg/configmap"
Expand All @@ -65,36 +59,7 @@ import (
// 4. Fallback to the ~/.kube/config.
// Deprecated: use injection.GetRESTConfig
func GetConfig(serverURL, kubeconfig string) (*rest.Config, error) {
if kubeconfig == "" {
kubeconfig = os.Getenv("KUBECONFIG")
}

// We produce configs a bunch of ways, this gives us a single place
// to "decorate" them with common useful things (e.g. for debugging)
decorate := func(cfg *rest.Config) *rest.Config {
return cfg
}

// If we have an explicit indication of where the kubernetes config lives, read that.
if kubeconfig != "" {
c, err := clientcmd.BuildConfigFromFlags(serverURL, kubeconfig)
if err != nil {
return nil, err
}
return decorate(c), nil
}
// If not, try the in-cluster config.
if c, err := rest.InClusterConfig(); err == nil {
return decorate(c), nil
}
// If no in-cluster config, try the default location in the user's home directory.
if usr, err := user.Current(); err == nil {
if c, err := clientcmd.BuildConfigFromFlags("", filepath.Join(usr.HomeDir, ".kube", "config")); err == nil {
return decorate(c), nil
}
}

return nil, errors.New("could not create a valid kubeconfig")
return injection.GetRESTConfig(serverURL, kubeconfig)
}

// GetLoggingConfig gets the logging config from either the file system if present
Expand Down Expand Up @@ -132,31 +97,8 @@ func GetLeaderElectionConfig(ctx context.Context) (*leaderelection.Config, error
// Both Context and Config are optional.
// Deprecated: use injection.EnableInjectionOrDie
func EnableInjectionOrDie(ctx context.Context, cfg *rest.Config) context.Context {
if ctx == nil {
ctx = signals.NewContext()
}
if cfg == nil {
cfg = injection.ParseAndGetRESTConfigOrDie()
}

// Respect user provided settings, but if omitted customize the default behavior.
if cfg.QPS == 0 {
cfg.QPS = rest.DefaultQPS
}
if cfg.Burst == 0 {
cfg.Burst = rest.DefaultBurst
}
ctx = injection.WithConfig(ctx, cfg)

ctx, informers := injection.Default.SetupInformers(ctx, cfg)

go func() {
logging.FromContext(ctx).Info("Starting informers...")
if err := controller.StartInformers(ctx.Done(), informers...); err != nil {
logging.FromContext(ctx).Fatalw("Failed to start informers", zap.Error(err))
}
}()

ctx, startInformers := injection.EnableInjectionOrDie(ctx, cfg)
go startInformers()
return ctx
}

Expand Down Expand Up @@ -309,21 +251,7 @@ func flush(logger *zap.SugaredLogger) {
// dies by calling log.Fatalf.
// Deprecated: use injeciton.ParseAndGetRESTConfigOrDie
func ParseAndGetConfigOrDie() *rest.Config {
var (
serverURL = flag.String("server", "",
"The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
kubeconfig = flag.String("kubeconfig", "",
"Path to a kubeconfig. Only required if out-of-cluster.")
)
klog.InitFlags(flag.CommandLine)
flag.Parse()

cfg, err := injection.GetRESTConfig(*serverURL, *kubeconfig)
if err != nil {
log.Fatal("Error building kubeconfig: ", err)
}

return cfg
return injection.ParseAndGetRESTConfigOrDie()
}

// MemStatsOrDie sets up reporting on Go memory usage every 30 seconds or dies
Expand Down

0 comments on commit ff42410

Please sign in to comment.