Skip to content

Commit

Permalink
fix: Use the pluginhelper logging (#7)
Browse files Browse the repository at this point in the history
The hello-world code tries to use logging from the kube controller
API and CNPG's wrapper. These don't match what the pluginhelper
sets up.

Use the pluginhelper's logging instead, and let the pluginhelper
do the logging setup during server creation.

Signed-off-by: Craig Ringer <craig.ringer@enterprisedb.com>
  • Loading branch information
ringerc authored Jul 2, 2024
1 parent 4e1c3d6 commit 6da1a48
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/
.env
.vscode/
.idea/
cnpg-i-hello-world
5 changes: 5 additions & 0 deletions cmd/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func NewCmd() *cobra.Command {
return nil
})

// If you want to provide your own logr.Logger here, inject it into a context.Context
// with logr.NewContext(ctx, logger) and pass it to cmd.SetContext(ctx)

// Additional custom behaviour can be added by wrapping cmd.PersistentPreRun or cmd.Run

cmd.Use = "plugin"

return cmd
Expand Down
6 changes: 3 additions & 3 deletions internal/lifecycle/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"fmt"

"github.com/cloudnative-pg/cloudnative-pg/pkg/management/log"
"github.com/cloudnative-pg/cnpg-i-machinery/pkg/logging"
"github.com/cloudnative-pg/cnpg-i-machinery/pkg/pluginhelper"
"github.com/cloudnative-pg/cnpg-i/pkg/lifecycle"

Expand Down Expand Up @@ -75,7 +75,7 @@ func (impl Implementation) reconcileMetadata(
ctx context.Context,
request *lifecycle.OperatorLifecycleRequest,
) (*lifecycle.OperatorLifecycleResponse, error) {
logger := log.FromContext(ctx).WithName("cnpg_i_example_lifecyle")
logger := logging.FromContext(ctx).WithName("cnpg_i_example_lifecyle")
helper, err := pluginhelper.NewDataBuilder(
metadata.PluginName,
request.ClusterDefinition,
Expand Down Expand Up @@ -105,7 +105,7 @@ func (impl Implementation) reconcileMetadata(
return nil, err
}

logger.Debug("generated patch", "content", string(patch), "configuration", configuration)
logger.V(0).Info("generated patch", "content", string(patch), "configuration", configuration)

return &lifecycle.OperatorLifecycleResponse{
JsonPatch: patch,
Expand Down
6 changes: 0 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ import (
"os"

"github.com/spf13/cobra"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/cloudnative-pg/cnpg-i-hello-world/cmd/plugin"
)

func main() {
// TODO: customize with zap.UseFlagOptions(&zap.Options{}) and env variables
logger := zap.New()
log.SetLogger(logger)
rootCmd := &cobra.Command{
Use: "cnpg-i-hello-world",
Short: "A plugin example",
Expand Down

0 comments on commit 6da1a48

Please sign in to comment.