Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RUN GOOS=linux \
# Final image
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.23
ARG TARGETPLATFORM
ARG kubectlVersion=v1.33.8
ARG kubectlVersion=v1.33.12

# kubectl url has no variant (v7)
# helm url has dashes and no variant (v7)
Expand Down
71 changes: 42 additions & 29 deletions cmd/addon-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/deckhouse/deckhouse/pkg/log"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/spf13/cobra"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
Expand All @@ -34,50 +34,63 @@ const (
)

func main() {
kpApp := kingpin.New(app.AppName, fmt.Sprintf("%s %s: %s", app.AppName, app.Version, app.AppDescription))
cfg := app.NewConfig()
if err := app.ParseEnv(cfg); err != nil {
fmt.Fprintf(os.Stderr, "configuration error: %v\n", err)
os.Exit(1)
}

logger := log.NewLogger()
log.SetDefault(logger)

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

kpApp.Action(func(_ *kingpin.ParseContext) error {
klogtolog.InitAdapter(shapp.DebugKubernetesAPI, logger.Named("klog"))
stdliblogtolog.InitAdapter(logger)
rootCmd := &cobra.Command{
Use: app.AppName,
Short: fmt.Sprintf("%s %s: %s", app.AppName, app.Version, app.AppDescription),
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
klogtolog.InitAdapter(cfg.Debug.KubernetesAPI, logger.Named("klog"))
stdliblogtolog.InitAdapter(logger)

return nil
})
return nil
},
}

// print version
kpApp.Command("version", "Show version.").Action(func(_ *kingpin.ParseContext) error {
fmt.Printf("%s %s\n", app.AppName, app.Version)
return nil
rootCmd.AddCommand(&cobra.Command{
Use: "version",
Short: "Show version.",
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("%s %s\n", app.AppName, app.Version)
},
})

// start main loop
startCmd := kpApp.Command("start", "Start events processing.").
Default().
Action(start(logger))
startCmd := &cobra.Command{
Use: "start",
Short: "Start events processing.",
RunE: start(logger, cfg),
}
app.BindFlags(cfg, rootCmd, startCmd)
rootCmd.AddCommand(startCmd)

app.DefineStartCommandFlags(kpApp, startCmd)
debug.DefineDebugCommands(rootCmd)
app.DefineDebugCommands(rootCmd)

debug.DefineDebugCommands(kpApp)
app.DefineDebugCommands(kpApp)
// Make start the default command when no subcommand is given.
rootCmd.RunE = start(logger, cfg)

kingpin.MustParse(kpApp.Parse(os.Args[1:]))
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}

func start(logger *log.Logger) func(_ *kingpin.ParseContext) error {
return func(_ *kingpin.ParseContext) error {
func start(logger *log.Logger, cfg *app.Config) func(cmd *cobra.Command, args []string) error {
return func(_ *cobra.Command, _ []string) error {
app.ApplyConfig(cfg)

shapp.AppStartMessage = fmt.Sprintf("%s %s, shell-operator %s", app.AppName, app.Version, shapp.Version)

ctx := context.Background()

// Initialize metric names with the configured prefix
shmetrics.InitMetrics(shapp.PrometheusMetricsPrefix)
// Initialize addon-operator specific metrics
metrics.InitMetrics(shapp.PrometheusMetricsPrefix)
shmetrics.InitMetrics(cfg.App.PrometheusMetricsPrefix)
metrics.InitMetrics(cfg.App.PrometheusMetricsPrefix)

operator := addon_operator.NewAddonOperator(ctx, nil, nil, addon_operator.WithLogger(logger.Named("addon-operator")))

Expand Down Expand Up @@ -163,7 +176,7 @@ func runHAMode(ctx context.Context, operator *addon_operator.AddonOperator) {
OnStartedLeading: func(ctx context.Context) {
err := run(ctx, operator)
if err != nil {
operator.Logger.Fatal("run on stardet leading", log.Err(err))
operator.Logger.Fatal("run on started leading", log.Err(err))
}
},
OnStoppedLeading: func() {
Expand Down
51 changes: 27 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require (
github.com/deckhouse/module-sdk v0.10.4
github.com/dominikbraun/graph v0.23.0
github.com/ettle/strcase v0.2.0
github.com/flant/kube-client v1.6.0
github.com/flant/shell-operator v1.16.6
github.com/go-chi/chi/v5 v5.2.3
github.com/flant/kube-client v1.7.0
github.com/flant/shell-operator v1.17.0
github.com/go-chi/chi/v5 v5.2.5
github.com/go-openapi/loads v0.23.1
github.com/go-openapi/spec v0.22.0
github.com/go-openapi/strfmt v0.24.0
Expand All @@ -23,33 +23,38 @@ require (
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/go-multierror v1.1.1
github.com/kennygrant/sanitize v1.2.4
github.com/onsi/gomega v1.38.2
github.com/onsi/gomega v1.41.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.11.1
github.com/tidwall/gjson v1.18.0
github.com/werf/nelm v1.24.1-0.20260427093240-93080e63001a
google.golang.org/protobuf v1.36.11
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.15.4
k8s.io/api v0.33.8
k8s.io/apimachinery v0.33.8
k8s.io/cli-runtime v0.33.8
k8s.io/client-go v0.33.8
k8s.io/api v0.33.12
k8s.io/apimachinery v0.33.12
k8s.io/cli-runtime v0.33.12
k8s.io/client-go v0.33.12
k8s.io/kubectl v0.33.8
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
sigs.k8s.io/controller-runtime v0.20.4
sigs.k8s.io/kustomize/kyaml v0.19.0
sigs.k8s.io/yaml v1.4.0
sigs.k8s.io/yaml v1.6.0
)

require github.com/go-openapi/swag/loading v0.25.1

require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/goccy/go-json v0.10.6 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
)

require (
cel.dev/expr v0.25.1 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/caarlos0/env/v11 v11.3.1
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-openapi/swag/conv v0.25.1 // indirect
github.com/go-openapi/swag/fileutils v0.25.1 // indirect
Expand All @@ -61,7 +66,6 @@ require (
github.com/go-openapi/swag/yamlutils v0.25.1 // indirect
github.com/go-resty/resty/v2 v2.17.1 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/goccy/go-json v0.10.6 // indirect
github.com/gosimple/slug v1.15.0 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand All @@ -73,6 +77,7 @@ require (
github.com/yannh/kubeconform v0.6.7 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel/metric v1.43.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.43.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
k8s.io/component-helpers v0.33.8 // indirect
Expand All @@ -91,8 +96,6 @@ require (
github.com/Masterminds/squirrel v1.5.4 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/alecthomas/chroma/v2 v2.15.0 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/avelino/slugify v0.0.0-20180501145920-855f152bd774 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
Expand Down Expand Up @@ -179,7 +182,7 @@ require (
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/spdystream v0.5.0 // indirect
github.com/moby/spdystream v0.5.1 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -191,10 +194,10 @@ require (
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.22.0
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/prometheus/client_golang v1.23.2
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rubenv/sql-migrate v1.6.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand All @@ -204,8 +207,8 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.9.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.9
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/tetratelabs/wazero v1.8.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
Expand Down Expand Up @@ -243,9 +246,9 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.33.8 // indirect
k8s.io/apiserver v0.33.8 // indirect
k8s.io/component-base v0.33.8 // indirect
k8s.io/apiextensions-apiserver v0.33.12 // indirect
k8s.io/apiserver v0.33.12 // indirect
k8s.io/component-base v0.33.12 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
Expand Down
Loading
Loading