Skip to content

Commit

Permalink
Various fixes (#303)
Browse files Browse the repository at this point in the history
* various fixes
* fix language
* changelog
* fix changelog comment
  • Loading branch information
EItanya authored Oct 11, 2021
1 parent 84c61c3 commit f3fea52
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
6 changes: 6 additions & 0 deletions changelog/v0.21.0/dev-logging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: BREAKING_CHANGE
description: >
Change Logging options to be more clear. This will only affect bootstrap.Start() and
bootstrap.StartMulti() functions.
issueLink: https://github.com/solo-io/skv2/issues/304
16 changes: 11 additions & 5 deletions pkg/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ type Options struct {
// enables verbose mode
VerboseMode bool

// enables json logger (instead of table logger)
JSONLogger bool
// enables dev logger (instead of prod logger)
// NOTE: DO NOT set this to true in Prod, it will crash on DPanic
DevLogger bool

// ManagementContext if specified read the KubeConfig for the management cluster from this context. Only applies when running out of cluster.
ManagementContext string
Expand All @@ -83,6 +84,11 @@ func (opts *Options) AddToFlags(flags *pflag.FlagSet) {
flags.StringVar(&opts.ManagementContext, "context", "", "If specified, use this context from the selected KubeConfig to connect to the local (management) cluster.")
flags.StringVar(&opts.SettingsRef.Name, "settings-name", opts.SettingsRef.Name, "The name of the Settings object this controller should use.")
flags.StringVar(&opts.SettingsRef.Namespace, "settings-namespace", opts.SettingsRef.Namespace, "The namespace of the Settings object this controller should use.")

// This flag disables prod mode when set to false, in other words setting debug to true,
// Which will cause the app to panic on DPanic.
flags.BoolVar(&opts.DevLogger, "dev-logger", false, "Default: false. Set this value to true to enable debug panic logs for development.")
flags.MarkHidden("dev-logger")
}

// Start a controller with the given start func. The StartFunc will be called with a bootstrapped local manager. If localMode is false, the StartParameters will include initialized multicluster components.
Expand All @@ -92,7 +98,7 @@ func Start(ctx context.Context, start StartFunc, opts Options, schemes runtime.S

// Like Start, but runs multiple StartFuncs concurrently
func StartMulti(ctx context.Context, startFuncs map[string]StartFunc, opts Options, schemes runtime.SchemeBuilder, localMode bool, addStatsHandlers ...func(mux *http.ServeMux, profiles map[string]string)) error {
setupLogging(opts.VerboseMode, opts.JSONLogger)
setupLogging(opts.VerboseMode, opts.DevLogger)

mgr, err := makeMasterManager(opts, schemes)
if err != nil {
Expand Down Expand Up @@ -191,7 +197,7 @@ func makeMasterManager(opts Options, schemes runtime.SchemeBuilder) (manager.Man
return mgr, nil
}

func setupLogging(verboseMode, jsonLogging bool) {
func setupLogging(verboseMode, devLogging bool) {
level := zapcore.InfoLevel
if verboseMode {
level = zapcore.DebugLevel
Expand All @@ -200,7 +206,7 @@ func setupLogging(verboseMode, jsonLogging bool) {
zapOpts := []zaputil.Opts{
zaputil.Level(&atomicLevel),
}
if !jsonLogging {
if devLogging {
zapOpts = append(zapOpts,
// Only set debug mode if specified. This will use a non-json (human readable) encoder which makes it impossible
// to use any json parsing tools for the log. Should only be enabled explicitly
Expand Down
17 changes: 17 additions & 0 deletions pkg/ezkube/object_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ import (
)

func MakeObjectRef(resource ResourceId) *v1.ObjectRef {
if resource == nil {
return nil
}
return &v1.ObjectRef{
Name: resource.GetName(),
Namespace: resource.GetNamespace(),
}
}

func MakeClusterObjectRef(resource ClusterResourceId) *v1.ClusterObjectRef {
if resource == nil {
return nil
}
return &v1.ClusterObjectRef{
Name: resource.GetName(),
Namespace: resource.GetNamespace(),
Expand All @@ -21,17 +27,28 @@ func MakeClusterObjectRef(resource ClusterResourceId) *v1.ClusterObjectRef {
}

func RefsMatch(ref1, ref2 ResourceId) bool {
// If either ref is nil, return true if they are both nil
if ref1 == nil || ref2 == nil {
return ref1 == nil && ref2 == nil
}
return ref1.GetNamespace() == ref2.GetNamespace() &&
ref1.GetName() == ref2.GetName()
}

func ClusterRefsMatch(ref1, ref2 ClusterResourceId) bool {
// If either ref is nil, return true if they are both nil
if ref1 == nil || ref2 == nil {
return ref1 == nil && ref2 == nil
}
return ref1.GetNamespace() == ref2.GetNamespace() &&
ref1.GetName() == ref2.GetName() &&
ref1.GetClusterName() == ref2.GetClusterName()
}

func MakeClientObjectKey(ref ResourceId) client.ObjectKey {
if ref == nil {
return client.ObjectKey{}
}
return client.ObjectKey{
Namespace: ref.GetNamespace(),
Name: ref.GetName(),
Expand Down

0 comments on commit f3fea52

Please sign in to comment.