Skip to content

Commit 0193606

Browse files
committed
fix
Signed-off-by: Pavel Okhlopkov <[email protected]>
1 parent 9a5e74c commit 0193606

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

pkg/kube_config_manager/backend/configmap/configmap.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"k8s.io/client-go/tools/cache"
1818

1919
"github.com/flant/addon-operator/pkg/kube_config_manager/config"
20+
kcmcontext "github.com/flant/addon-operator/pkg/kube_config_manager/context"
2021
"github.com/flant/addon-operator/pkg/utils"
2122
"github.com/flant/kube-client/client"
2223
)
@@ -93,12 +94,7 @@ func (b Backend) saveGlobalConfigValues(ctx context.Context, values utils.Values
9394
}
9495

9596
func (b Backend) isDebugEnabled(ctx context.Context) bool {
96-
debug, ok := ctx.Value("kube-config-manager-debug").(bool)
97-
if !ok {
98-
return false
99-
}
100-
101-
return debug
97+
return kcmcontext.IsKubeConfigManagerDebug(ctx)
10298
}
10399

104100
// saveModuleConfigValues updates module section in ConfigMap.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package context
2+
3+
import "context"
4+
5+
type contextValue string
6+
7+
const (
8+
kubeConfigManagerDebug contextValue = "kube-config-manager-debug"
9+
)
10+
11+
func WithKubeConfigManagerDebug(ctx context.Context, value bool) context.Context {
12+
return context.WithValue(ctx, kubeConfigManagerDebug, value)
13+
}
14+
15+
func IsKubeConfigManagerDebug(ctx context.Context) bool {
16+
val := ctx.Value(kubeConfigManagerDebug)
17+
if val == nil {
18+
return false
19+
}
20+
debug, ok := val.(bool)
21+
return ok && debug
22+
}

pkg/kube_config_manager/kube_config_manager.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/flant/addon-operator/pkg/kube_config_manager/backend"
1414
"github.com/flant/addon-operator/pkg/kube_config_manager/config"
15+
kcmcontext "github.com/flant/addon-operator/pkg/kube_config_manager/context"
1516
"github.com/flant/addon-operator/pkg/utils"
1617
runtimeConfig "github.com/flant/shell-operator/pkg/config"
1718
)
@@ -53,8 +54,9 @@ func NewKubeConfigManager(ctx context.Context, bk backend.ConfigHandler, runtime
5354
if err != nil {
5455
return err
5556
}
56-
// nolint: revive,staticcheck // basic type is enough here
57-
cctx = context.WithValue(cctx, "kube-config-manager-debug", val)
57+
58+
cctx = kcmcontext.WithKubeConfigManagerDebug(cctx, val)
59+
5860
return nil
5961
},
6062
nil,

0 commit comments

Comments
 (0)