generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into sourceranges
- Loading branch information
Showing
11 changed files
with
233 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"strconv" | ||
"syscall" | ||
|
||
"k8s.io/component-base/logs" | ||
"k8s.io/klog/v2" | ||
|
||
"sigs.k8s.io/cloud-provider-kind/pkg/config" | ||
"sigs.k8s.io/cloud-provider-kind/pkg/controller" | ||
kindcmd "sigs.k8s.io/kind/pkg/cmd" | ||
) | ||
|
||
var ( | ||
flagV int | ||
enableLogDump bool | ||
logDumpDir string | ||
) | ||
|
||
func init() { | ||
flag.IntVar(&flagV, "v", 2, "Verbosity level") | ||
flag.BoolVar(&enableLogDump, "enable-log-dumping", false, "store logs to a temporal directory or to the directory specified using the logs-dir flag") | ||
flag.StringVar(&logDumpDir, "logs-dir", "", "store logs to the specified directory") | ||
|
||
flag.Usage = func() { | ||
fmt.Fprint(os.Stderr, "Usage: cloud-provider-kind [options]\n\n") | ||
flag.PrintDefaults() | ||
} | ||
} | ||
|
||
func Main() { | ||
// Parse command line flags and arguments | ||
flag.Parse() | ||
flag.VisitAll(func(flag *flag.Flag) { | ||
klog.Infof("FLAG: --%s=%q", flag.Name, flag.Value) | ||
}) | ||
|
||
// trap Ctrl+C and call cancel on the context | ||
ctx := context.Background() | ||
ctx, cancel := context.WithCancel(ctx) | ||
|
||
// Enable signal handler | ||
signalCh := make(chan os.Signal, 2) | ||
defer func() { | ||
close(signalCh) | ||
cancel() | ||
}() | ||
|
||
signal.Notify(signalCh, syscall.SIGTERM, syscall.SIGINT) | ||
go func() { | ||
select { | ||
case <-signalCh: | ||
klog.Infof("Exiting: received signal") | ||
cancel() | ||
case <-ctx.Done(): | ||
// cleanup | ||
} | ||
}() | ||
|
||
// initialize loggers, kind logger and klog | ||
logger := kindcmd.NewLogger() | ||
type verboser interface { | ||
SetVerbosity(int) | ||
} | ||
v, ok := logger.(verboser) | ||
if ok { | ||
v.SetVerbosity(flagV) | ||
} | ||
|
||
_, err := logs.GlogSetter(strconv.Itoa(flagV)) | ||
if err != nil { | ||
logger.Errorf("error setting klog verbosity to %d : %v", flagV, err) | ||
} | ||
|
||
// initialize log directory | ||
if enableLogDump { | ||
if logDumpDir == "" { | ||
dir, err := os.MkdirTemp(os.TempDir(), "kind-provider-") | ||
if err != nil { | ||
klog.Fatal(err) | ||
} | ||
logDumpDir = dir | ||
} | ||
|
||
if _, err := os.Stat(logDumpDir); os.IsNotExist(err) { | ||
if err := os.MkdirAll(logDumpDir, 0755); err != nil { | ||
klog.Fatalf("directory %s does not exist: %v", logDumpDir, err) | ||
} | ||
} | ||
config.DefaultConfig.EnableLogDump = true | ||
config.DefaultConfig.LogDir = logDumpDir | ||
klog.Infof("**** Dumping load balancers logs to: %s", logDumpDir) | ||
} | ||
|
||
controller.New(logger).Run(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
cloud-provider: | ||
build: . | ||
network_mode: "${NET_MODE-host}" | ||
volumes: | ||
- /var/run/docker.sock:/var/run/docker.sock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"strconv" | ||
"syscall" | ||
|
||
"k8s.io/component-base/logs" | ||
|
||
"sigs.k8s.io/cloud-provider-kind/pkg/controller" | ||
|
||
kindcmd "sigs.k8s.io/kind/pkg/cmd" | ||
"sigs.k8s.io/cloud-provider-kind/cmd" | ||
) | ||
|
||
var ( | ||
flagV int | ||
) | ||
|
||
func init() { | ||
flag.IntVar(&flagV, "v", 2, "Verbosity level") | ||
|
||
flag.Usage = func() { | ||
fmt.Fprint(os.Stderr, "Usage: cloud-provider-kind [options]\n\n") | ||
flag.PrintDefaults() | ||
} | ||
} | ||
|
||
func main() { | ||
// Parse command line flags and arguments | ||
flag.Parse() | ||
|
||
// trap Ctrl+C and call cancel on the context | ||
ctx := context.Background() | ||
ctx, cancel := context.WithCancel(ctx) | ||
|
||
// Enable signal handler | ||
signalCh := make(chan os.Signal, 2) | ||
defer func() { | ||
close(signalCh) | ||
cancel() | ||
}() | ||
|
||
signal.Notify(signalCh, syscall.SIGTERM, syscall.SIGINT) | ||
go func() { | ||
select { | ||
case <-signalCh: | ||
log.Printf("Exiting: received signal") | ||
cancel() | ||
case <-ctx.Done(): | ||
// cleanup | ||
} | ||
}() | ||
|
||
logger := kindcmd.NewLogger() | ||
type verboser interface { | ||
SetVerbosity(int) | ||
} | ||
v, ok := logger.(verboser) | ||
if ok { | ||
v.SetVerbosity(flagV) | ||
} | ||
|
||
_, err := logs.GlogSetter(strconv.Itoa(flagV)) | ||
if err != nil { | ||
logger.Errorf("error setting klog verbosity to %d : %v", flagV, err) | ||
} | ||
controller.New(logger).Run(ctx) | ||
cmd.Main() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package config | ||
|
||
// DefaultConfig is a global variable that is initialized at startup with the flags options. | ||
// It can not be modified after that. | ||
var DefaultConfig = &Config{} | ||
|
||
type Config struct { | ||
EnableLogDump bool | ||
LogDir string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.