Skip to content

Commit 5ac9c8d

Browse files
authored
internal: more flexible and isolated logging (#14)
The `internal/pkg/log` is moved to be an internal implementation detail of the `cmd` package; Also action structs in package `internal/pkg/actions` that log now have configurable Logf fields and no longer log by default when used as a library.
1 parent 8f89a93 commit 5ac9c8d

File tree

14 files changed

+36
-24
lines changed

14 files changed

+36
-24
lines changed

internal/cmd/catalog_add.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import (
88
"github.com/sirupsen/logrus"
99
"github.com/spf13/cobra"
1010

11+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
1112
"github.com/operator-framework/kubectl-operator/internal/pkg/action"
12-
"github.com/operator-framework/kubectl-operator/internal/pkg/log"
1313
)
1414

1515
func newCatalogAddCmd(cfg *action.Configuration) *cobra.Command {
1616
a := action.NewCatalogAdd(cfg)
17+
a.Logf = log.Printf
1718

1819
cmd := &cobra.Command{
1920
Use: "add <name> <index_image>",

internal/cmd/catalog_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
v1 "k8s.io/api/core/v1"
1111
"k8s.io/apimachinery/pkg/util/duration"
1212

13+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
1314
"github.com/operator-framework/kubectl-operator/internal/pkg/action"
14-
"github.com/operator-framework/kubectl-operator/internal/pkg/log"
1515
)
1616

1717
func newCatalogListCmd(cfg *action.Configuration) *cobra.Command {

internal/cmd/catalog_remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package cmd
33
import (
44
"github.com/spf13/cobra"
55

6+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
67
"github.com/operator-framework/kubectl-operator/internal/pkg/action"
7-
"github.com/operator-framework/kubectl-operator/internal/pkg/log"
88
)
99

1010
func newCatalogRemoveCmd(cfg *action.Configuration) *cobra.Command {
File renamed without changes.

internal/cmd/operator_install.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import (
55

66
"github.com/spf13/cobra"
77

8+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
89
"github.com/operator-framework/kubectl-operator/internal/pkg/action"
9-
"github.com/operator-framework/kubectl-operator/internal/pkg/log"
1010
)
1111

1212
func newOperatorInstallCmd(cfg *action.Configuration) *cobra.Command {
1313
i := action.NewOperatorInstall(cfg)
14+
i.Logf = log.Printf
15+
1416
cmd := &cobra.Command{
1517
Use: "install <operator>",
1618
Short: "Install an operator",

internal/cmd/operator_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
v1 "k8s.io/api/core/v1"
1313
"k8s.io/apimachinery/pkg/util/duration"
1414

15+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
1516
"github.com/operator-framework/kubectl-operator/internal/pkg/action"
16-
"github.com/operator-framework/kubectl-operator/internal/pkg/log"
1717
)
1818

1919
func newOperatorListCmd(cfg *action.Configuration) *cobra.Command {

internal/cmd/operator_list_available.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
v1 "k8s.io/api/core/v1"
1313
"k8s.io/apimachinery/pkg/util/duration"
1414

15+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
1516
"github.com/operator-framework/kubectl-operator/internal/pkg/action"
16-
"github.com/operator-framework/kubectl-operator/internal/pkg/log"
1717
)
1818

1919
func newOperatorListAvailableCmd(cfg *action.Configuration) *cobra.Command {

internal/cmd/operator_uninstall.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package cmd
33
import (
44
"github.com/spf13/cobra"
55

6+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
67
"github.com/operator-framework/kubectl-operator/internal/pkg/action"
7-
"github.com/operator-framework/kubectl-operator/internal/pkg/log"
88
)
99

1010
func newOperatorUninstallCmd(cfg *action.Configuration) *cobra.Command {
1111
u := action.NewOperatorUninstall(cfg)
12+
u.Logf = log.Printf
13+
1214
cmd := &cobra.Command{
1315
Use: "uninstall <operator>",
1416
Short: "Uninstall an operator",

internal/cmd/operator_upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55

66
"github.com/spf13/cobra"
77

8+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
89
"github.com/operator-framework/kubectl-operator/internal/pkg/action"
9-
"github.com/operator-framework/kubectl-operator/internal/pkg/log"
1010
)
1111

1212
func newOperatorUpgradeCmd(cfg *action.Configuration) *cobra.Command {

internal/cmd/root.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ package cmd
33
import (
44
"github.com/spf13/cobra"
55

6+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
67
"github.com/operator-framework/kubectl-operator/internal/pkg/action"
78
)
89

9-
func New() *cobra.Command {
10+
func Execute() {
11+
if err := newCmd().Execute(); err != nil {
12+
log.Fatal(err)
13+
}
14+
}
15+
func newCmd() *cobra.Command {
1016
cmd := &cobra.Command{
1117
Use: "operator",
1218
Short: "Manage operators in a cluster from the command line",

0 commit comments

Comments
 (0)