Skip to content

Commit

Permalink
Merge pull request #527 from adrianchiris/align-config-daemon-loggin
Browse files Browse the repository at this point in the history
Remove glog
  • Loading branch information
adrianchiris authored Oct 31, 2023
2 parents 108eef9 + 37924ef commit f00830a
Show file tree
Hide file tree
Showing 37 changed files with 755 additions and 617 deletions.
2 changes: 1 addition & 1 deletion api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func IsSupportedModel(vendorID, deviceID string) bool {
return true
}
}
log.Info("IsSupportedModel():", "Unsupported model:", "vendorId:", vendorID, "deviceId:", deviceID)
log.Info("IsSupportedModel(): found unsupported model", "vendorId:", vendorID, "deviceId:", deviceID)
return false
}

Expand Down
1 change: 0 additions & 1 deletion bindata/manifests/webhook/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ spec:
- -port=6443
- -tls-private-key-file=/etc/tls/tls.key
- -tls-cert-file=/etc/tls/tls.crt
- -alsologtostderr=true
- -insecure=true
env:
- name: NAMESPACE
Expand Down
7 changes: 5 additions & 2 deletions cmd/sriov-network-config-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package main
import (
"flag"

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

snolog "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/log"
)

const (
Expand All @@ -35,11 +37,12 @@ var (
)

func init() {
snolog.BindFlags(flag.CommandLine)
rootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
}

func main() {
if err := rootCmd.Execute(); err != nil {
glog.Exitf("Error executing mcd: %v", err)
log.Log.Error(err, "error executing sriov-network-config-daemon")
}
}
48 changes: 25 additions & 23 deletions cmd/sriov-network-config-daemon/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ package main

import (
"errors"
"flag"
"fmt"
"os"

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

sriovv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host"
Expand All @@ -32,6 +31,8 @@ import (
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/systemd"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/version"

snolog "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/log"
)

var (
Expand All @@ -48,23 +49,24 @@ func init() {
}

func runServiceCmd(cmd *cobra.Command, args []string) error {
flag.Set("logtostderr", "true")
flag.Parse()
// init logger
snolog.InitLog()
setupLog := log.Log.WithName("sriov-config-service")

// To help debugging, immediately log version
glog.V(2).Infof("Version: %+v", version.Version)
setupLog.V(2).Info("sriov-config-service", "version", version.Version)

glog.V(0).Info("Starting sriov-config-service")
setupLog.V(0).Info("Starting sriov-config-service")
supportedNicIds, err := systemd.ReadSriovSupportedNics()
if err != nil {
glog.Errorf("failed to read list of supported nic ids")
setupLog.Error(err, "failed to read list of supported nic ids")
sriovResult := &systemd.SriovResult{
SyncStatus: "Failed",
LastSyncError: fmt.Sprintf("failed to read list of supported nic ids: %v", err),
}
err = systemd.WriteSriovResult(sriovResult)
if err != nil {
glog.Errorf("sriov-config-service failed to write sriov result file with content %v error: %v", *sriovResult, err)
setupLog.Error(err, "failed to write sriov result file", "content", *sriovResult)
return fmt.Errorf("sriov-config-service failed to write sriov result file with content %v error: %v", *sriovResult, err)
}
return fmt.Errorf("sriov-config-service failed to read list of supported nic ids: %v", err)
Expand All @@ -74,14 +76,14 @@ func runServiceCmd(cmd *cobra.Command, args []string) error {
nodeStateSpec, err := systemd.ReadConfFile()
if err != nil {
if _, err := os.Stat(systemd.SriovSystemdConfigPath); !errors.Is(err, os.ErrNotExist) {
glog.Errorf("failed to read the sriov configuration file in path %s: %v", systemd.SriovSystemdConfigPath, err)
setupLog.Error(err, "failed to read the sriov configuration file", "path", systemd.SriovSystemdConfigPath)
sriovResult := &systemd.SriovResult{
SyncStatus: "Failed",
LastSyncError: fmt.Sprintf("failed to read the sriov configuration file in path %s: %v", systemd.SriovSystemdConfigPath, err),
}
err = systemd.WriteSriovResult(sriovResult)
if err != nil {
glog.Errorf("sriov-config-service failed to write sriov result file with content %v error: %v", *sriovResult, err)
setupLog.Error(err, "failed to write sriov result file", "content", *sriovResult)
return fmt.Errorf("sriov-config-service failed to write sriov result file with content %v error: %v", *sriovResult, err)
}
}
Expand All @@ -93,18 +95,18 @@ func runServiceCmd(cmd *cobra.Command, args []string) error {
}
}

glog.V(2).Infof("sriov-config-service read config: %v", nodeStateSpec)
setupLog.V(2).Info("sriov-config-service", "config", nodeStateSpec)

storeManager, err := utils.NewStoreManager(true)
if err != nil {
glog.Errorf("failed to create store manager: %v", err)
setupLog.Error(err, "failed to create store manager")
return err
}
// Load kernel modules
hostManager := host.NewHostManager(true)
_, err = hostManager.TryEnableRdma()
if err != nil {
glog.Warningf("failed to enable RDMA: %v", err)
setupLog.Error(err, "warning, failed to enable RDMA")
}
hostManager.TryEnableTun()
hostManager.TryEnableVhostNet()
Expand All @@ -115,40 +117,40 @@ func runServiceCmd(cmd *cobra.Command, args []string) error {
// Bare metal support
ifaceStatuses, err = utils.DiscoverSriovDevices(nodeStateSpec.UnsupportedNics, storeManager)
if err != nil {
glog.Errorf("sriov-config-service: failed to discover sriov devices on the host: %v", err)
setupLog.Error(err, "failed to discover sriov devices on the host")
return fmt.Errorf("sriov-config-service: failed to discover sriov devices on the host: %v", err)
}

// Create the generic plugin
configPlugin, err = generic.NewGenericPlugin(true, hostManager, storeManager)
if err != nil {
glog.Errorf("sriov-config-service: failed to create generic plugin %v", err)
setupLog.Error(err, "failed to create generic plugin")
return fmt.Errorf("sriov-config-service failed to create generic plugin %v", err)
}
} else if nodeStateSpec.PlatformType == utils.VirtualOpenStack {
// Openstack support
metaData, networkData, err := utils.GetOpenstackData(false)
if err != nil {
glog.Errorf("sriov-config-service: failed to read OpenStack data: %v", err)
setupLog.Error(err, "failed to read OpenStack data")
return fmt.Errorf("sriov-config-service failed to read OpenStack data: %v", err)
}

openStackDevicesInfo, err := utils.CreateOpenstackDevicesInfo(metaData, networkData)
if err != nil {
glog.Errorf("failed to read OpenStack data: %v", err)
setupLog.Error(err, "failed to read OpenStack data")
return fmt.Errorf("sriov-config-service failed to read OpenStack data: %v", err)
}

ifaceStatuses, err = utils.DiscoverSriovDevicesVirtual(openStackDevicesInfo)
if err != nil {
glog.Errorf("sriov-config-service:failed to read OpenStack data: %v", err)
setupLog.Error(err, "failed to read OpenStack data")
return fmt.Errorf("sriov-config-service: failed to read OpenStack data: %v", err)
}

// Create the virtual plugin
configPlugin, err = virtual.NewVirtualPlugin(true)
if err != nil {
glog.Errorf("sriov-config-service: failed to create virtual plugin %v", err)
setupLog.Error(err, "failed to create virtual plugin")
return fmt.Errorf("sriov-config-service: failed to create virtual plugin %v", err)
}
}
Expand All @@ -160,7 +162,7 @@ func runServiceCmd(cmd *cobra.Command, args []string) error {

_, _, err = configPlugin.OnNodeStateChange(nodeState)
if err != nil {
glog.Errorf("sriov-config-service: failed to run OnNodeStateChange to update the generic plugin status %v", err)
setupLog.Error(err, "failed to run OnNodeStateChange to update the generic plugin status")
return fmt.Errorf("sriov-config-service: failed to run OnNodeStateChange to update the generic plugin status %v", err)
}

Expand All @@ -171,17 +173,17 @@ func runServiceCmd(cmd *cobra.Command, args []string) error {

err = configPlugin.Apply()
if err != nil {
glog.Errorf("sriov-config-service failed to run apply node configuration %v", err)
setupLog.Error(err, "failed to run apply node configuration")
sriovResult.SyncStatus = "Failed"
sriovResult.LastSyncError = err.Error()
}

err = systemd.WriteSriovResult(sriovResult)
if err != nil {
glog.Errorf("sriov-config-service failed to write sriov result file with content %v error: %v", *sriovResult, err)
setupLog.Error(err, "failed to write sriov result file", "content", *sriovResult)
return fmt.Errorf("sriov-config-service failed to write sriov result file with content %v error: %v", *sriovResult, err)
}

glog.V(0).Info("Shutting down sriov-config-service")
setupLog.V(0).Info("shutting down sriov-config-service")
return nil
}
53 changes: 28 additions & 25 deletions cmd/sriov-network-config-daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ package main

import (
"context"
"flag"
"fmt"
"net"
"net/url"
"os"
"strings"
"time"

"github.com/golang/glog"
configv1 "github.com/openshift/api/config/v1"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/spf13/cobra"
Expand All @@ -35,10 +33,12 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/connrotation"
"sigs.k8s.io/controller-runtime/pkg/log"

sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
snclientset "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/client/clientset/versioned"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/daemon"
snolog "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/log"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/version"
)
Expand All @@ -48,7 +48,7 @@ var (
Use: "start",
Short: "Starts SR-IOV Network Config Daemon",
Long: "",
Run: runStartCmd,
RunE: runStartCmd,
}

startOpts struct {
Expand All @@ -65,17 +65,18 @@ func init() {
startCmd.PersistentFlags().BoolVar(&startOpts.systemd, "use-systemd-service", false, "use config daemon in systemd mode")
}

func runStartCmd(cmd *cobra.Command, args []string) {
flag.Set("logtostderr", "true")
flag.Parse()
func runStartCmd(cmd *cobra.Command, args []string) error {
// init logger
snolog.InitLog()
setupLog := log.Log.WithName("sriov-network-config-daemon")

// To help debugging, immediately log version
glog.V(2).Infof("Version: %+v", version.Version)
setupLog.V(2).Info("sriov-network-config-daemon", "version", version.Version)

if startOpts.nodeName == "" {
name, ok := os.LookupEnv("NODE_NAME")
if !ok || name == "" {
glog.Fatalf("node-name is required")
return fmt.Errorf("node-name is required")
}
startOpts.nodeName = name
}
Expand Down Expand Up @@ -104,19 +105,19 @@ func runStartCmd(cmd *cobra.Command, args []string) {
if os.Getenv("CLUSTER_TYPE") == utils.ClusterTypeOpenshift {
kubeconfig, err := clientcmd.LoadFromFile("/host/etc/kubernetes/kubeconfig")
if err != nil {
glog.Errorf("failed to load kubelet kubeconfig: %v", err)
setupLog.Error(err, "failed to load kubelet kubeconfig")
}
clusterName := kubeconfig.Contexts[kubeconfig.CurrentContext].Cluster
apiURL := kubeconfig.Clusters[clusterName].Server

url, err := url.Parse(apiURL)
if err != nil {
glog.Errorf("failed to parse api url from kubelet kubeconfig: %v", err)
setupLog.Error(err, "failed to parse api url from kubelet kubeconfig")
}

// The kubernetes in-cluster functions don't let you override the apiserver
// directly; gotta "pass" it via environment vars.
glog.V(0).Infof("overriding kubernetes api to %s", apiURL)
setupLog.V(0).Info("overriding kubernetes api", "new-url", apiURL)
os.Setenv("KUBERNETES_SERVICE_HOST", url.Hostname())
os.Setenv("KUBERNETES_SERVICE_PORT", url.Port())
}
Expand All @@ -130,12 +131,12 @@ func runStartCmd(cmd *cobra.Command, args []string) {
}

if err != nil {
panic(err.Error())
return err
}

closeAllConns, err := updateDialer(config)
if err != nil {
panic(err.Error())
return err
}

sriovnetworkv1.AddToScheme(scheme.Scheme)
Expand All @@ -146,7 +147,7 @@ func runStartCmd(cmd *cobra.Command, args []string) {
kubeclient := kubernetes.NewForConfigOrDie(config)
openshiftContext, err := utils.NewOpenshiftContext(config, scheme.Scheme)
if err != nil {
panic(err)
return err
}

config.Timeout = 5 * time.Second
Expand All @@ -156,13 +157,13 @@ func runStartCmd(cmd *cobra.Command, args []string) {
devMode := false
if mode == "TRUE" {
devMode = true
glog.V(0).Info("dev mode enabled")
setupLog.V(0).Info("dev mode enabled")
}

eventRecorder := daemon.NewEventRecorder(writerclient, startOpts.nodeName, kubeclient)
defer eventRecorder.Shutdown()

glog.V(0).Info("starting node writer")
setupLog.V(0).Info("starting node writer")
nodeWriter := daemon.NewNodeStateStatusWriter(writerclient, startOpts.nodeName, closeAllConns, eventRecorder, devMode)

destdir := os.Getenv("DEST_DIR")
Expand All @@ -180,27 +181,28 @@ func runStartCmd(cmd *cobra.Command, args []string) {
}
}
} else {
glog.Fatalf("Failed to fetch node state %s, %v!", startOpts.nodeName, err)
setupLog.Error(err, "failed to fetch node state, exiting", "node-name", startOpts.nodeName)
return err
}
glog.V(0).Infof("Running on platform: %s", platformType.String())
setupLog.Info("Running on", "platform", platformType.String())

var namespace = os.Getenv("NAMESPACE")
if err := sriovnetworkv1.InitNicIDMapFromConfigMap(kubeclient, namespace); err != nil {
glog.Errorf("failed to run init NicIdMap: %v", err)
panic(err.Error())
setupLog.Error(err, "failed to run init NicIdMap")
return err
}

eventRecorder.SendEvent("ConfigDaemonStart", "Config Daemon starting")

// block the deamon process until nodeWriter finish first its run
err = nodeWriter.RunOnce(destdir, platformType)
if err != nil {
glog.Errorf("failed to run writer: %v", err)
panic(err.Error())
setupLog.Error(err, "failed to run writer")
return err
}
go nodeWriter.Run(stopCh, refreshCh, syncCh, platformType)

glog.V(0).Info("Starting SriovNetworkConfigDaemon")
setupLog.V(0).Info("Starting SriovNetworkConfigDaemon")
err = daemon.New(
startOpts.nodeName,
snclient,
Expand All @@ -216,9 +218,10 @@ func runStartCmd(cmd *cobra.Command, args []string) {
devMode,
).Run(stopCh, exitCh)
if err != nil {
glog.Errorf("failed to run daemon: %v", err)
setupLog.Error(err, "failed to run daemon")
}
glog.V(0).Info("Shutting down SriovNetworkConfigDaemon")
setupLog.V(0).Info("Shutting down SriovNetworkConfigDaemon")
return err
}

// updateDialer instruments a restconfig with a dial. the returned function allows forcefully closing all active connections.
Expand Down
Loading

0 comments on commit f00830a

Please sign in to comment.