Skip to content

Commit

Permalink
Merge pull request #2252 from tnozicka/propagate-loglevel-1.15
Browse files Browse the repository at this point in the history
[v1.15] Propagate operator loglevel
  • Loading branch information
scylla-operator-bot[bot] authored Dec 12, 2024
2 parents 1bd5543 + 4cc7b14 commit dca5d70
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
29 changes: 23 additions & 6 deletions pkg/cmdutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
package cmdutil

import (
"errors"
"flag"
"fmt"
"os"
"strconv"
"strings"

"github.com/scylladb/scylla-operator/pkg/helpers"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/errors"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/klog/v2"
)

Expand Down Expand Up @@ -55,7 +58,7 @@ func ReadFlagsFromEnv(prefix string, cmd *cobra.Command) error {
return
})

return errors.NewAggregate(errs)
return utilerrors.NewAggregate(errs)
}

func InstallKlog(cmd *cobra.Command) {
Expand All @@ -74,11 +77,25 @@ func InstallKlog(cmd *cobra.Command) {
}
}

func GetLoglevel() string {
func getLoglevelOrDefault() (int, error) {
f := flag.CommandLine.Lookup("v")
if f != nil {
return f.Value.String()
if f == nil {
return 0, errors.New(`can't lookup klog "v" flag`)
}

return ""
s := f.Value.String()
if len(s) == 0 {
return 0, nil
}

loglevel, err := strconv.Atoi(s)
if err != nil {
panic(fmt.Errorf("can't parse log level %q: %q", s, err))
}

return loglevel, nil
}

func GetLoglevelOrDefaultOrDie() int {
return helpers.Must(getLoglevelOrDefault())
}
3 changes: 2 additions & 1 deletion pkg/controller/nodeconfig/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

scyllav1alpha1 "github.com/scylladb/scylla-operator/pkg/api/scylla/v1alpha1"
"github.com/scylladb/scylla-operator/pkg/cmdutil"
"github.com/scylladb/scylla-operator/pkg/naming"
"github.com/scylladb/scylla-operator/pkg/pointer"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -370,7 +371,7 @@ exec chroot ./ /scylla-operator/usr/bin/scylla-operator node-setup-daemon \
--scylla-image=` + fmt.Sprintf("%q", scyllaImage) + ` \
--operator-image=` + fmt.Sprintf("%q", operatorImage) + ` \
--disable-optimizations=` + fmt.Sprintf("%t", nc.Spec.DisableOptimizations) + ` \
--loglevel=` + fmt.Sprintf("%d", 4) + `
` + fmt.Sprintf("--loglevel=%d", cmdutil.GetLoglevelOrDefaultOrDie()) + `
`},
Env: []corev1.EnvVar{
{
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/nodetune/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path"

"github.com/scylladb/scylla-operator/pkg/cmdutil"
"github.com/scylladb/scylla-operator/pkg/controllerhelpers"
"github.com/scylladb/scylla-operator/pkg/naming"
"github.com/scylladb/scylla-operator/pkg/pointer"
Expand Down Expand Up @@ -157,7 +158,7 @@ func makeRlimitsJobForContainer(controllerRef *metav1.OwnerReference, namespace,
"/usr/bin/scylla-operator",
"rlimits-job",
fmt.Sprintf("--pid=%d", scyllaHostPID),
"--loglevel=2",
fmt.Sprintf("--loglevel=%d", cmdutil.GetLoglevelOrDefaultOrDie()),
},
SecurityContext: &corev1.SecurityContext{
Privileged: pointer.Ptr(true),
Expand Down
15 changes: 15 additions & 0 deletions pkg/controller/scylladbdatacenter/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package scylladbdatacenter

import (
"flag"

"k8s.io/klog/v2"
)

func init() {
klog.InitFlags(flag.CommandLine)
err := flag.Set("alsologtostderr", "true")
if err != nil {
panic(err)
}
}
7 changes: 4 additions & 3 deletions pkg/controller/scylladbdatacenter/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
scylladbassets "github.com/scylladb/scylla-operator/assets/scylladb"
scyllav1 "github.com/scylladb/scylla-operator/pkg/api/scylla/v1"
scyllav1alpha1 "github.com/scylladb/scylla-operator/pkg/api/scylla/v1alpha1"
"github.com/scylladb/scylla-operator/pkg/cmdutil"
"github.com/scylladb/scylla-operator/pkg/controllerhelpers"
"github.com/scylladb/scylla-operator/pkg/features"
"github.com/scylladb/scylla-operator/pkg/helpers"
Expand Down Expand Up @@ -667,7 +668,7 @@ exec /mnt/shared/scylla-operator sidecar \
}() + ` \
--service-name=$(SERVICE_NAME) \
--cpu-count=$(CPU_COUNT) \
--loglevel=2 \
` + fmt.Sprintf("--loglevel=%d", cmdutil.GetLoglevelOrDefaultOrDie()) + ` \
` +
func() string {
var optionalArgs []string
Expand Down Expand Up @@ -860,7 +861,7 @@ wait
"scylladb-api-status",
fmt.Sprintf("--port=%d", naming.ScyllaDBAPIStatusProbePort),
"--service-name=$(SERVICE_NAME)",
"--loglevel=2",
fmt.Sprintf("--loglevel=%d", cmdutil.GetLoglevelOrDefaultOrDie()),
},
Env: []corev1.EnvVar{
{
Expand Down Expand Up @@ -913,7 +914,7 @@ wait
}
return scyllav1alpha1.BroadcastAddressTypeServiceClusterIP
}()),
"--loglevel=2",
fmt.Sprintf("--loglevel=%d", cmdutil.GetLoglevelOrDefaultOrDie()),
},
Env: []corev1.EnvVar{
{
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/scylladbdatacenter/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ exec /mnt/shared/scylla-operator sidecar \
--clients-broadcast-address-type=ServiceClusterIP \
--service-name=$(SERVICE_NAME) \
--cpu-count=$(CPU_COUNT) \
--loglevel=2 \
--loglevel=0 \
-- "$@"
`),
"--",
Expand Down Expand Up @@ -901,7 +901,7 @@ wait`),
"scylladb-api-status",
"--port=8080",
"--service-name=$(SERVICE_NAME)",
"--loglevel=2",
"--loglevel=0",
},
Env: []corev1.EnvVar{
{
Expand Down Expand Up @@ -944,7 +944,7 @@ wait`),
"--service-name=$(SERVICE_NAME)",
"--nodes-broadcast-address-type=ServiceClusterIP",
"--clients-broadcast-address-type=ServiceClusterIP",
"--loglevel=2",
"--loglevel=0",
},
Env: []corev1.EnvVar{
{
Expand Down

0 comments on commit dca5d70

Please sign in to comment.