Skip to content

Commit

Permalink
[addon-operator] add sdk and batch hooks (#529)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Okhlopkov <[email protected]>
Co-authored-by: Pavel Okhlopkov <[email protected]>
  • Loading branch information
ldmonster and Pavel Okhlopkov authored Dec 4, 2024
1 parent 8c0b170 commit b6e8ee2
Show file tree
Hide file tree
Showing 49 changed files with 1,351 additions and 385 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ updates:
- dependency-name: "k8s.io/api"
- dependency-name: "k8s.io/apimachinery"
- dependency-name: "k8s.io/client-go"

- package-ecosystem: "docker"
directory: "/"
schedule:
Expand Down
10 changes: 5 additions & 5 deletions cmd/addon-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/flant/addon-operator/pkg/kube_config_manager/backend/configmap"
"github.com/flant/addon-operator/pkg/utils/stdliblogtolog"
"github.com/flant/kube-client/klogtolog"
sh_app "github.com/flant/shell-operator/pkg/app"
shapp "github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/debug"
utils_signal "github.com/flant/shell-operator/pkg/utils/signal"
)
Expand All @@ -39,10 +39,10 @@ func main() {
log.SetDefault(logger)

// override usage template to reveal additional commands with information about start command
kpApp.UsageTemplate(sh_app.OperatorUsageTemplate(app.AppName))
kpApp.UsageTemplate(shapp.OperatorUsageTemplate(app.AppName))

kpApp.Action(func(_ *kingpin.ParseContext) error {
klogtolog.InitAdapter(sh_app.DebugKubernetesAPI, logger.Named("klog"))
klogtolog.InitAdapter(shapp.DebugKubernetesAPI, logger.Named("klog"))
stdliblogtolog.InitAdapter(logger)
return nil
})
Expand All @@ -68,7 +68,7 @@ func main() {

func start(logger *log.Logger) func(_ *kingpin.ParseContext) error {
return func(_ *kingpin.ParseContext) error {
sh_app.AppStartMessage = fmt.Sprintf("%s %s, shell-operator %s", app.AppName, app.Version, sh_app.Version)
shapp.AppStartMessage = fmt.Sprintf("%s %s, shell-operator %s", app.AppName, app.Version, shapp.Version)

ctx := context.Background()

Expand All @@ -92,7 +92,7 @@ func start(logger *log.Logger) func(_ *kingpin.ParseContext) error {
}

func run(ctx context.Context, operator *addon_operator.AddonOperator) error {
bk := configmap.New(operator.KubeClient(), app.Namespace, app.ConfigMapName, operator.Logger.Named("kube-config-manager"))
bk := configmap.New(operator.KubeClient(), operator.DefaultNamespace, app.ConfigMapName, operator.Logger.Named("kube-config-manager"))
operator.SetupKubeConfigManager(bk)

if err := operator.Setup(); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions examples/700-go-hook/global-hooks/global-go-hook.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package global_hooks

import (
"github.com/flant/addon-operator/pkg/module_manager/go_hook"
gohook "github.com/flant/addon-operator/pkg/module_manager/go_hook"
"github.com/flant/addon-operator/sdk"
)

var _ = sdk.RegisterFunc(&go_hook.HookConfig{
OnStartup: &go_hook.OrderedConfig{Order: 10},
var _ = sdk.RegisterFunc(&gohook.HookConfig{
OnStartup: &gohook.OrderedConfig{Order: 10},
}, handler)

func handler(input *go_hook.HookInput) error {
func handler(input *gohook.HookInput) error {
input.Logger.Infof("Start Global Go hook")
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

"github.com/flant/addon-operator/pkg/module_manager/go_hook"
gohook "github.com/flant/addon-operator/pkg/module_manager/go_hook"
"github.com/flant/addon-operator/sdk"
)

var _ = sdk.RegisterFunc(&go_hook.HookConfig{
OnStartup: &go_hook.OrderedConfig{
var _ = sdk.RegisterFunc(&gohook.HookConfig{
OnStartup: &gohook.OrderedConfig{
Order: 10,
},

OnBeforeHelm: &go_hook.OrderedConfig{
OnBeforeHelm: &gohook.OrderedConfig{
Order: 10,
},

Kubernetes: []go_hook.KubernetesConfig{
Kubernetes: []gohook.KubernetesConfig{
{
Name: "pods",
ApiVersion: "v1",
Kind: "Pods",
FilterFunc: ObjFilter,
ExecuteHookOnSynchronization: go_hook.Bool(true),
ExecuteHookOnSynchronization: gohook.Bool(true),
},
},

Schedule: []go_hook.ScheduleConfig{
Schedule: []gohook.ScheduleConfig{
{
Name: "metrics",
Crontab: "*/5 * * * * *",
Expand All @@ -39,7 +39,7 @@ var _ = sdk.RegisterFunc(&go_hook.HookConfig{

type podSpecFilteredObj v1.PodSpec

func ObjFilter(obj *unstructured.Unstructured) (go_hook.FilterResult, error) {
func ObjFilter(obj *unstructured.Unstructured) (gohook.FilterResult, error) {
pod := &v1.Pod{}
err := sdk.FromUnstructured(obj, pod)
if err != nil {
Expand All @@ -51,7 +51,7 @@ func ObjFilter(obj *unstructured.Unstructured) (go_hook.FilterResult, error) {
return &podSpec, nil
}

func run(input *go_hook.HookInput) error {
func run(input *gohook.HookInput) error {
for _, o := range input.Snapshots["pods"] {
podSpec := o.(*podSpecFilteredObj)
input.Logger.Infof("Got podSpec: %+v", podSpec)
Expand Down
2 changes: 1 addition & 1 deletion examples/700-go-hook/register_go_hooks.go.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
_ "github.com/flant/addon-operator/sdk/registry"
_ "github.com/flant/addon-operator/sdk"

_ "github.com/flant/addon-operator/examples/700-go-hook/global-hooks"
_ "github.com/flant/addon-operator/examples/700-go-hook/modules/001-module-go-hooks/hooks"
Expand Down
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ go 1.22.8
require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241106140903-258b93b3334e
github.com/deckhouse/module-sdk v0.1.0
github.com/dominikbraun/graph v0.23.0
github.com/ettle/strcase v0.2.0
github.com/flant/kube-client v1.2.2
github.com/flant/shell-operator v1.5.1
github.com/flant/shell-operator v1.5.2
github.com/go-chi/chi/v5 v5.1.0
github.com/go-openapi/loads v0.19.5
github.com/go-openapi/spec v0.19.8
Expand All @@ -22,7 +23,7 @@ require (
github.com/kennygrant/sanitize v1.2.4
github.com/onsi/gomega v1.35.1
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/tidwall/gjson v1.14.4
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -60,7 +61,7 @@ require (
github.com/containerd/platforms v0.2.1 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/cli v27.1.0+incompatible // indirect
github.com/docker/cli v27.1.1+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v27.1.1+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
Expand All @@ -86,7 +87,7 @@ require (
github.com/go-stack/stack v1.8.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gojuno/minimock/v3 v3.4.1 // indirect
github.com/gojuno/minimock/v3 v3.4.3 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.0.1 // indirect
Expand Down Expand Up @@ -162,7 +163,7 @@ require (
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
Expand Down
22 changes: 12 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241106140903-258b93b3334e h1:QUQy+5Bv7/UzhfrytiG3c5gfLGhPppepVbRpbMisVIw=
github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241106140903-258b93b3334e/go.mod h1:Mk5HRzkc5pIcDIZ2JJ6DPuuqnwhXVkb3you8M8Mg+4w=
github.com/deckhouse/module-sdk v0.1.0 h1:YgMnr0vmjVLwIdQfTE1ytR2nPndO2SfQprcW45wsT34=
github.com/deckhouse/module-sdk v0.1.0/go.mod h1:0gxlSr0WRrGnB82J+45FBIXNP/fKl8+yEvRTzrygiAE=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/distribution/distribution/v3 v3.0.0-beta.1 h1:X+ELTxPuZ1Xe5MsD3kp2wfGUhc8I+MPfRis8dZ818Ic=
github.com/distribution/distribution/v3 v3.0.0-beta.1/go.mod h1:O9O8uamhHzWWQVTjuQpyYUVm/ShPHPUDgvQMpHGVBDs=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/cli v27.1.0+incompatible h1:P0KSYmPtNbmx59wHZvG6+rjivhKDRA1BvvWM0f5DgHc=
github.com/docker/cli v27.1.0+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v27.1.1+incompatible h1:goaZxOqs4QKxznZjjBWKONQci/MywhtRv2oNn0GkeZE=
github.com/docker/cli v27.1.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v27.1.1+incompatible h1:hO/M4MtV36kzKldqnA37IWhebRA+LnqqcqDja6kVaKY=
Expand Down Expand Up @@ -136,8 +138,8 @@ github.com/flant/kube-client v1.2.2 h1:27LBs+PKJEFnkQXjPU9eIps7a7iyI13AKcSYj897D
github.com/flant/kube-client v1.2.2/go.mod h1:eMa3aJ6V1PRWSQ/RCROkObDpY4S74uM84SJS4G/LINg=
github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee h1:evii83J+/6QGNvyf6tjQ/p27DPY9iftxIBb37ALJRTg=
github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee/go.mod h1:f+REaGl/+pZR97rbTcwHEka/MAipoQQ2Mc0iQUj4ak0=
github.com/flant/shell-operator v1.5.1 h1:FnNKEOUipM7eC87zP8QeFDkvRNcU6htUEhdwMKa3U68=
github.com/flant/shell-operator v1.5.1/go.mod h1:Kbq8JNtKfoT8aqbHxygvgd6WoMImne8/upAYx9QyHUA=
github.com/flant/shell-operator v1.5.2 h1:OPYveDCI1ZZDrtxORqarSIQIAcZEGW9ZUugCZtLmiZM=
github.com/flant/shell-operator v1.5.2/go.mod h1:2vTLeyYLaq4Tp0NPilCHZy22rDGSS4uBsbPONj9YGRY=
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/foxcpp/go-mockdns v1.0.0 h1:7jBqxd3WDWwi/6WhDvacvH1XsN3rOLXyHM1uhvIx6FI=
Expand Down Expand Up @@ -244,8 +246,8 @@ github.com/gofrs/uuid/v5 v5.3.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/gojuno/minimock/v3 v3.4.1 h1:Flf735K7TT45TKCUMG4fz1vwadW/cW0Q0wH8x7eJKos=
github.com/gojuno/minimock/v3 v3.4.1/go.mod h1:mpNkl275+w8a6CYjeCHIRfN8QzN2R7ejT6jEDUdweuo=
github.com/gojuno/minimock/v3 v3.4.3 h1:CGH14iGxTd6kW6ZetOA/teusRN710VQ2nq8SdEuI3OQ=
github.com/gojuno/minimock/v3 v3.4.3/go.mod h1:b+hbQhEU0Csi1eyzpvi0LhlmjDHyCDPzwhXbDaKTSrQ=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down Expand Up @@ -530,8 +532,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
Expand Down Expand Up @@ -699,8 +701,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
16 changes: 9 additions & 7 deletions pkg/addon-operator/bootstrap.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
package addon_operator

import (
"fmt"

"github.com/deckhouse/deckhouse/pkg/log"

"github.com/flant/addon-operator/pkg/app"
"github.com/flant/addon-operator/pkg/kube_config_manager"
"github.com/flant/addon-operator/pkg/kube_config_manager/backend"
"github.com/flant/addon-operator/pkg/module_manager"
sh_app "github.com/flant/shell-operator/pkg/app"
shapp "github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/debug"
shell_operator "github.com/flant/shell-operator/pkg/shell-operator"
)

// Bootstrap inits all dependencies for a full-fledged AddonOperator instance.
func (op *AddonOperator) bootstrap() error {
log.Info(sh_app.AppStartMessage)
log.Info(shapp.AppStartMessage)

log.Infof("Search modules in: %s", app.ModulesDir)

log.Infof("Addon-operator namespace: %s", app.Namespace)
log.Infof("Addon-operator namespace: %s", op.DefaultNamespace)

// Debug server.
// TODO: rewrite sh_app global variables to the addon-operator ones
// TODO: rewrite shapp global variables to the addon-operator ones
var err error
op.DebugServer, err = shell_operator.RunDefaultDebugServer(sh_app.DebugUnixSocket, sh_app.DebugHttpServerAddr, op.Logger.Named("debug-server"))
op.DebugServer, err = shell_operator.RunDefaultDebugServer(shapp.DebugUnixSocket, shapp.DebugHttpServerAddr, op.Logger.Named("debug-server"))
if err != nil {
log.Errorf("Fatal: start Debug server: %s", err)
return err
return fmt.Errorf("start Debug server: %w", err)
}

err = op.Assemble(op.DebugServer)
if err != nil {
log.Errorf("Fatal: %s", err)
return err
return fmt.Errorf("assemble Debug server: %w", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/addon-operator/debug_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (op *AddonOperator) RegisterDebugModuleRoutes(dbgSrv *debug.Server) {
deps := &modules.HelmModuleDependencies{
HelmClientFactory: op.Helm,
}
hm, err := modules.NewHelmModule(m, op.ModuleManager.TempDir, deps, nil, op.Logger.Named("helm-module"))
hm, err := modules.NewHelmModule(m, op.DefaultNamespace, op.ModuleManager.TempDir, deps, nil, op.Logger.Named("helm-module"))
if err != nil {
return nil, fmt.Errorf("failed to create helm module: %w", err)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/addon-operator/kube_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/flant/addon-operator/pkg/app"
"github.com/flant/addon-operator/pkg/helm_resources_manager"
klient "github.com/flant/kube-client/client"
sh_app "github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/metric_storage"
shapp "github.com/flant/shell-operator/pkg/app"
metricstorage "github.com/flant/shell-operator/pkg/metric_storage"
utils "github.com/flant/shell-operator/pkg/utils/labels"
)

Expand All @@ -19,17 +19,17 @@ import (
var DefaultHelmMonitorKubeClientMetricLabels = map[string]string{"component": "helm_monitor"}

// defaultHelmMonitorKubeClient initializes a Kubernetes client for helm monitor.
func defaultHelmMonitorKubeClient(metricStorage *metric_storage.MetricStorage, metricLabels map[string]string, logger *log.Logger) *klient.Client {
func defaultHelmMonitorKubeClient(metricStorage *metricstorage.MetricStorage, metricLabels map[string]string, logger *log.Logger) *klient.Client {
client := klient.New(klient.WithLogger(logger))
client.WithContextName(sh_app.KubeContext)
client.WithConfigPath(sh_app.KubeConfig)
client.WithContextName(shapp.KubeContext)
client.WithConfigPath(shapp.KubeConfig)
client.WithRateLimiterSettings(app.HelmMonitorKubeClientQps, app.HelmMonitorKubeClientBurst)
client.WithMetricStorage(metricStorage)
client.WithMetricLabels(utils.DefaultIfEmpty(metricLabels, DefaultHelmMonitorKubeClientMetricLabels))
return client
}

func InitDefaultHelmResourcesManager(ctx context.Context, metricStorage *metric_storage.MetricStorage, logger *log.Logger) (helm_resources_manager.HelmResourcesManager, error) {
func InitDefaultHelmResourcesManager(ctx context.Context, namespace string, metricStorage *metricstorage.MetricStorage, logger *log.Logger) (helm_resources_manager.HelmResourcesManager, error) {
kubeClient := defaultHelmMonitorKubeClient(metricStorage, DefaultHelmMonitorKubeClientMetricLabels, logger.Named("helm-monitor-kube-client"))
if err := kubeClient.Init(); err != nil {
return nil, fmt.Errorf("initialize Kubernetes client for Helm resources manager: %s\n", err)
Expand All @@ -38,6 +38,6 @@ func InitDefaultHelmResourcesManager(ctx context.Context, metricStorage *metric_
if err != nil {
return nil, fmt.Errorf("initialize Helm resources manager: %s\n", err)
}
mgr.WithDefaultNamespace(app.Namespace)
mgr.WithDefaultNamespace(namespace)
return mgr, nil
}
8 changes: 4 additions & 4 deletions pkg/addon-operator/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package addon_operator
import (
"time"

"github.com/flant/shell-operator/pkg/metric_storage"
metricstorage "github.com/flant/shell-operator/pkg/metric_storage"
"github.com/flant/shell-operator/pkg/task/queue"
)

Expand All @@ -17,7 +17,7 @@ var buckets_1msTo10s = []float64{
}

// registerHookMetrics register metrics specified for addon-operator
func registerHookMetrics(metricStorage *metric_storage.MetricStorage) {
func registerHookMetrics(metricStorage *metricstorage.MetricStorage) {
// configuration metrics
metricStorage.RegisterGauge(
"{PREFIX}binding_count",
Expand Down Expand Up @@ -124,7 +124,7 @@ func registerHookMetrics(metricStorage *metric_storage.MetricStorage) {
})
}

func StartLiveTicksUpdater(metricStorage *metric_storage.MetricStorage) {
func StartLiveTicksUpdater(metricStorage *metricstorage.MetricStorage) {
// Addon-operator live ticks.
go func() {
for {
Expand All @@ -134,7 +134,7 @@ func StartLiveTicksUpdater(metricStorage *metric_storage.MetricStorage) {
}()
}

func StartTasksQueueLengthUpdater(metricStorage *metric_storage.MetricStorage, tqs *queue.TaskQueueSet) {
func StartTasksQueueLengthUpdater(metricStorage *metricstorage.MetricStorage, tqs *queue.TaskQueueSet) {
go func() {
for {
// Gather task queues lengths.
Expand Down
Loading

0 comments on commit b6e8ee2

Please sign in to comment.