Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix app config #545

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 7 additions & 7 deletions cmd/shell-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ package main

import (
"fmt"
app2 "github.com/flant/shell-operator/internal/app"
"math/rand"
"os"
"time"

"gopkg.in/alecthomas/kingpin.v2"

"github.com/flant/kube-client/klogtologrus"
"github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/debug"
"github.com/flant/shell-operator/pkg/jq"
shell_operator "github.com/flant/shell-operator/pkg/shell-operator"
utils_signal "github.com/flant/shell-operator/pkg/utils/signal"
)

func main() {
kpApp := kingpin.New(app.AppName, fmt.Sprintf("%s %s: %s", app.AppName, app.Version, app.AppDescription))
kpApp := kingpin.New(app2.AppName, fmt.Sprintf("%s %s: %s", app2.AppName, app2.Version, app2.AppDescription))

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

// Initialize klog wrapper when all values are parsed
kpApp.Action(func(c *kingpin.ParseContext) error {
klogtologrus.InitAdapter(app.DebugKubernetesAPI)
klogtologrus.InitAdapter(app2.DebugKubernetesAPI)
return nil
})

// print version
kpApp.Command("version", "Show version.").Action(func(c *kingpin.ParseContext) error {
fmt.Printf("%s %s\n", app.AppName, app.Version)
fmt.Printf("%s %s\n", app2.AppName, app2.Version)
fmt.Println(jq.FilterInfo())
return nil
})
Expand All @@ -39,7 +39,7 @@ func main() {
startCmd := kpApp.Command("start", "Start shell-operator.").
Default().
Action(func(c *kingpin.ParseContext) error {
app.AppStartMessage = fmt.Sprintf("%s %s", app.AppName, app.Version)
app2.AppStartMessage = fmt.Sprintf("%s %s", app2.AppName, app2.Version)

// Init rand generator.
rand.Seed(time.Now().UnixNano())
Expand All @@ -59,7 +59,7 @@ func main() {

return nil
})
app.DefineStartCommandFlags(kpApp, startCmd)
app2.DefineStartCommandFlags(kpApp, startCmd)

debug.DefineDebugCommands(kpApp)
debug.DefineDebugCommandsSelf(kpApp)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/debug/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"bytes"
"context"
"fmt"
"github.com/flant/shell-operator/internal/app"
"io"
"net"
"net/http"

"github.com/flant/shell-operator/pkg/app"
utils "github.com/flant/shell-operator/pkg/utils/file"
)

Expand Down
25 changes: 12 additions & 13 deletions pkg/debug/debug-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package debug

import (
"fmt"
app2 "github.com/flant/shell-operator/internal/app"
"time"

"gopkg.in/alecthomas/kingpin.v2"

"github.com/flant/shell-operator/pkg/app"
)

var (
Expand All @@ -16,7 +15,7 @@ var (

func DefineDebugCommands(kpApp *kingpin.Application) {
// Queue dump commands.
queueCmd := app.CommandWithDefaultUsageTemplate(kpApp, "queue", "Dump queues.")
queueCmd := app2.CommandWithDefaultUsageTemplate(kpApp, "queue", "Dump queues.")

queueListCmd := queueCmd.Command("list", "Dump tasks in all queues.").
Action(func(c *kingpin.ParseContext) error {
Expand All @@ -31,7 +30,7 @@ func DefineDebugCommands(kpApp *kingpin.Application) {
Default("false").
BoolVar(&showEmpty)
AddOutputJsonYamlTextFlag(queueListCmd)
app.DefineDebugUnixSocketFlag(queueListCmd)
app2.DefineDebugUnixSocketFlag(queueListCmd)

queueMainCmd := queueCmd.Command("main", "Dump tasks in the main queue.").
Action(func(c *kingpin.ParseContext) error {
Expand All @@ -43,10 +42,10 @@ func DefineDebugCommands(kpApp *kingpin.Application) {
return nil
})
AddOutputJsonYamlTextFlag(queueMainCmd)
app.DefineDebugUnixSocketFlag(queueMainCmd)
app2.DefineDebugUnixSocketFlag(queueMainCmd)

// Runtime config command.
configCmd := app.CommandWithDefaultUsageTemplate(kpApp, "config", "Manage runtime parameters.")
configCmd := app2.CommandWithDefaultUsageTemplate(kpApp, "config", "Manage runtime parameters.")

configListCmd := configCmd.Command("list", "List available runtime parameters.").
Action(func(c *kingpin.ParseContext) error {
Expand All @@ -58,7 +57,7 @@ func DefineDebugCommands(kpApp *kingpin.Application) {
return nil
})
AddOutputJsonYamlTextFlag(configListCmd)
app.DefineDebugUnixSocketFlag(configListCmd)
app2.DefineDebugUnixSocketFlag(configListCmd)

var paramName string
var paramValue string
Expand All @@ -75,11 +74,11 @@ func DefineDebugCommands(kpApp *kingpin.Application) {
configSetCmd.Arg("name", "A name of runtime parameter").Required().StringVar(&paramName)
configSetCmd.Arg("value", "A new value for the runtime parameter").Required().StringVar(&paramValue)
configSetCmd.Arg("duration", "Set value for a period of time, then return a previous value. Use Go notation: 10s, 15m30s, etc.").DurationVar(&paramDuration)
app.DefineDebugUnixSocketFlag(configSetCmd)
app2.DefineDebugUnixSocketFlag(configSetCmd)

// Raw request command
var rawUrl string
rawCommand := app.CommandWithDefaultUsageTemplate(kpApp, "raw", "Make a raw request to debug endpoint.").
rawCommand := app2.CommandWithDefaultUsageTemplate(kpApp, "raw", "Make a raw request to debug endpoint.").
Action(func(c *kingpin.ParseContext) error {
url := fmt.Sprintf("http://unix%s", rawUrl)
resp, err := DefaultClient().Get(url)
Expand All @@ -90,12 +89,12 @@ func DefineDebugCommands(kpApp *kingpin.Application) {
return nil
})
rawCommand.Arg("urlpath", "An url to send to debug endpoint. Example: /queue/list.json").StringVar(&rawUrl)
app.DefineDebugUnixSocketFlag(rawCommand)
app2.DefineDebugUnixSocketFlag(rawCommand)
}

func DefineDebugCommandsSelf(kpApp *kingpin.Application) {
// Get hook names
hookCmd := app.CommandWithDefaultUsageTemplate(kpApp, "hook", "Actions for hooks")
hookCmd := app2.CommandWithDefaultUsageTemplate(kpApp, "hook", "Actions for hooks")
hookListCmd := hookCmd.Command("list", "List all hooks.").
Action(func(c *kingpin.ParseContext) error {
outBytes, err := Hook(DefaultClient()).List(outputFormat)
Expand All @@ -106,7 +105,7 @@ func DefineDebugCommandsSelf(kpApp *kingpin.Application) {
return nil
})
AddOutputJsonYamlTextFlag(hookListCmd)
app.DefineDebugUnixSocketFlag(hookListCmd)
app2.DefineDebugUnixSocketFlag(hookListCmd)

// Get hook snapshots
var hookName string
Expand All @@ -121,7 +120,7 @@ func DefineDebugCommandsSelf(kpApp *kingpin.Application) {
})
hookSnapshotCmd.Arg("hook_name", "").Required().StringVar(&hookName)
AddOutputJsonYamlTextFlag(hookSnapshotCmd)
app.DefineDebugUnixSocketFlag(hookSnapshotCmd)
app2.DefineDebugUnixSocketFlag(hookSnapshotCmd)
}

func AddOutputJsonYamlTextFlag(cmd *kingpin.CmdClause) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package executor

import (
"encoding/json"
"github.com/flant/shell-operator/internal/app"
"os/exec"
"strings"
"syscall"
"time"

log "github.com/sirupsen/logrus"

"github.com/flant/shell-operator/pkg/app"
utils "github.com/flant/shell-operator/pkg/utils/labels"
)

Expand Down
3 changes: 1 addition & 2 deletions pkg/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package executor

import (
"bytes"
"github.com/flant/shell-operator/internal/app"
"io"
"math/rand"
"os"
Expand All @@ -12,8 +13,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/flant/shell-operator/pkg/app"
)

func TestRunAndLogLines(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/hook/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hook
import (
"context"
"fmt"
"github.com/flant/shell-operator/internal/app"
"os"
"path"
"path/filepath"
Expand All @@ -12,7 +13,6 @@ import (
"github.com/kennygrant/sanitize"
"golang.org/x/time/rate"

"github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/executor"
. "github.com/flant/shell-operator/pkg/hook/binding_context"
"github.com/flant/shell-operator/pkg/hook/config"
Expand Down
2 changes: 1 addition & 1 deletion pkg/hook/hook_manager_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package hook

import (
"github.com/flant/shell-operator/internal/app"
"path/filepath"
"strings"
"testing"

. "github.com/onsi/gomega"

"github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/hook/controller"
"github.com/flant/shell-operator/pkg/hook/types"
"github.com/flant/shell-operator/pkg/webhook/admission"
Expand Down
2 changes: 1 addition & 1 deletion pkg/kube/object_patch/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/flant/shell-operator/internal/app"
"io"

"gopkg.in/yaml.v3"
Expand All @@ -12,7 +13,6 @@ import (
k8yaml "sigs.k8s.io/yaml"

"github.com/flant/kube-client/manifest"
"github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/jq"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/kube_events_manager/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/flant/shell-operator/internal/app"
"reflect"
"runtime"
"runtime/trace"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

"github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/jq"
. "github.com/flant/shell-operator/pkg/kube_events_manager/types"
utils_checksum "github.com/flant/shell-operator/pkg/utils/checksum"
Expand Down
22 changes: 11 additions & 11 deletions pkg/shell-operator/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package shell_operator
import (
"context"
"fmt"
app2 "github.com/flant/shell-operator/internal/app"

log "github.com/sirupsen/logrus"

"github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/config"
"github.com/flant/shell-operator/pkg/debug"
"github.com/flant/shell-operator/pkg/hook"
Expand All @@ -24,18 +24,18 @@ import (
func Init() (*ShellOperator, error) {
runtimeConfig := config.NewConfig()
// Init logging subsystem.
app.SetupLogging(runtimeConfig)
app2.SetupLogging(runtimeConfig)
// Log version and jq filtering implementation.
log.Infof(app.AppStartMessage)
log.Infof(app2.AppStartMessage)
log.Debug(jq.FilterInfo())

hooksDir, err := utils.RequireExistingDirectory(app.HooksDir)
hooksDir, err := utils.RequireExistingDirectory(app2.HooksDir)
if err != nil {
log.Errorf("Fatal: hooks directory is required: %s", err)
return nil, err
}

tempDir, err := utils.EnsureTempDirectory(app.TempDir)
tempDir, err := utils.EnsureTempDirectory(app2.TempDir)
if err != nil {
log.Errorf("Fatal: temp directory: %s", err)
return nil, err
Expand All @@ -44,13 +44,13 @@ func Init() (*ShellOperator, error) {
op := NewShellOperator(context.Background())

// Debug server.
debugServer, err := RunDefaultDebugServer(app.DebugUnixSocket, app.DebugHttpServerAddr)
debugServer, err := RunDefaultDebugServer(app2.DebugUnixSocket, app2.DebugHttpServerAddr)
if err != nil {
log.Errorf("Fatal: start Debug server: %s", err)
return nil, err
}

err = op.AssembleCommonOperator(app.ListenAddress, app.ListenPort)
err = op.AssembleCommonOperator(app2.ListenAddress, app2.ListenPort)
if err != nil {
log.Errorf("Fatal: %s", err)
return nil, err
Expand Down Expand Up @@ -172,14 +172,14 @@ func (op *ShellOperator) SetupEventManagers() {
func (op *ShellOperator) setupHookManagers(hooksDir string, tempDir string) {
// Initialize admission webhooks manager.
op.AdmissionWebhookManager = admission.NewWebhookManager(op.KubeClient)
op.AdmissionWebhookManager.Settings = app.ValidatingWebhookSettings
op.AdmissionWebhookManager.Namespace = app.Namespace
op.AdmissionWebhookManager.Settings = app2.ValidatingWebhookSettings
op.AdmissionWebhookManager.Namespace = app2.Namespace

// Initialize conversion webhooks manager.
op.ConversionWebhookManager = conversion.NewWebhookManager()
op.ConversionWebhookManager.KubeClient = op.KubeClient
op.ConversionWebhookManager.Settings = app.ConversionWebhookSettings
op.ConversionWebhookManager.Namespace = app.Namespace
op.ConversionWebhookManager.Settings = app2.ConversionWebhookSettings
op.ConversionWebhookManager.Namespace = app2.Namespace

// Initialize Hook manager.
cfg := &hook.HookManagerConfig{
Expand Down
3 changes: 1 addition & 2 deletions pkg/shell-operator/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
"bytes"
"context"
"fmt"
"github.com/flant/shell-operator/internal/app"
"net/http"
"strings"
"time"

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
log "github.com/sirupsen/logrus"

"github.com/flant/shell-operator/pkg/app"
)

type baseHTTPServer struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/shell-operator/kube_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package shell_operator

import (
"fmt"
"github.com/flant/shell-operator/internal/app"

klient "github.com/flant/kube-client/client"
"github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/kube/object_patch"
"github.com/flant/shell-operator/pkg/metric_storage"
utils "github.com/flant/shell-operator/pkg/utils/labels"
Expand Down
2 changes: 1 addition & 1 deletion pkg/shell-operator/metrics_hooks.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package shell_operator

import (
"github.com/flant/shell-operator/internal/app"
"net/http"

"github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/metric_storage"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/shell-operator/metrics_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package shell_operator

import (
"context"
"github.com/flant/shell-operator/internal/app"

"github.com/flant/shell-operator/pkg/app"
"github.com/flant/shell-operator/pkg/metric_storage"
)

Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/file/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package utils

import (
"fmt"
"github.com/flant/shell-operator/internal/app"
"os"
"path/filepath"

"github.com/flant/shell-operator/pkg/app"
)

func RequireExistingDirectory(inDir string) (dir string, err error) {
Expand Down
Loading
Loading