From fcb152b19ad64595d7fbfddacd50cfda9c3ba245 Mon Sep 17 00:00:00 2001 From: shashank-netapp <108022276+shashank-netapp@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:36:40 +0530 Subject: [PATCH] setting the updated logConfig values on node pods during node registration. --- core/orchestrator_core.go | 10 ++++++++++ frontend/csi/controller_api/rest.go | 3 +++ frontend/csi/node_server.go | 11 +++++++++++ frontend/rest/controller_handlers.go | 10 ++++++++++ persistent_store/crd/apis/netapp/v1/node.go | 3 +++ persistent_store/crd/apis/netapp/v1/types.go | 6 ++++++ utils/types.go | 9 +++++++++ 7 files changed, 52 insertions(+) diff --git a/core/orchestrator_core.go b/core/orchestrator_core.go index 4ed2e146c..a6c0cb2ff 100644 --- a/core/orchestrator_core.go +++ b/core/orchestrator_core.go @@ -5150,6 +5150,16 @@ func (o *TridentOrchestrator) AddNode( node.PublicationState = existingNode.PublicationState } + // Setting log level, log workflows and log layers on the node same as to what is set on the controller. + logLevel := GetDefaultLogLevel() + node.LogLevel = logLevel + + logWorkflows := GetSelectedWorkFlows() + node.LogWorkflows = logWorkflows + + logLayers := GetSelectedLogLayers() + node.LogLayers = logLayers + if err = o.storeClient.AddOrUpdateNode(ctx, node); err != nil { return } diff --git a/frontend/csi/controller_api/rest.go b/frontend/csi/controller_api/rest.go index b3c781e69..5819e7d03 100644 --- a/frontend/csi/controller_api/rest.go +++ b/frontend/csi/controller_api/rest.go @@ -119,6 +119,9 @@ func (c *ControllerRestClient) InvokeAPI( type CreateNodeResponse struct { TopologyLabels map[string]string `json:"topologyLabels"` + LogLevel string `json:"logLevel"` + LogWorkflows string `json:"logWorkflows"` + LogLayers string `json:"logLayers"` } // CreateNode registers the node with the CSI controller server diff --git a/frontend/csi/node_server.go b/frontend/csi/node_server.go index ce84a4f2f..316e4185a 100644 --- a/frontend/csi/node_server.go +++ b/frontend/csi/node_server.go @@ -735,6 +735,17 @@ func (p *Plugin) nodeRegisterWithController(ctx context.Context, timeout time.Du if err == nil { topologyLabels = nodeDetails.TopologyLabels node.TopologyLabels = nodeDetails.TopologyLabels + + // Setting log level, log workflows and log layers on the node same as to what is set on the controller. + if err = p.orchestrator.SetLogLevel(ctx, nodeDetails.LogLevel); err != nil { + Logc(ctx).WithError(err).Error("Unable to set log level.") + } + if err = p.orchestrator.SetLoggingWorkflows(ctx, nodeDetails.LogWorkflows); err != nil { + Logc(ctx).WithError(err).Error("Unable to set logging workflows.") + } + if err = p.orchestrator.SetLogLayers(ctx, nodeDetails.LogLayers); err != nil { + Logc(ctx).WithError(err).Error("Unable to set logging layers.") + } } return err } diff --git a/frontend/rest/controller_handlers.go b/frontend/rest/controller_handlers.go index 30950aa16..3a88232b4 100644 --- a/frontend/rest/controller_handlers.go +++ b/frontend/rest/controller_handlers.go @@ -913,6 +913,9 @@ func DeleteStorageClass(w http.ResponseWriter, r *http.Request) { type AddNodeResponse struct { Name string `json:"name"` TopologyLabels map[string]string `json:"topologyLabels,omitempty"` + LogLevel string `json:"logLevel,omitempty"` + LogWorkflows string `json:"logWorkflows,omitempty"` + LogLayers string `json:"logLayers,omitempty"` Error string `json:"error,omitempty"` } @@ -947,6 +950,9 @@ func AddNode(w http.ResponseWriter, r *http.Request) { Name: "", TopologyLabels: make(map[string]string), Error: "", + LogLayers: "", + LogLevel: "", + LogWorkflows: "", } const auditMsg = "AddNode endpoint called." @@ -997,11 +1003,15 @@ func AddNode(w http.ResponseWriter, r *http.Request) { nodeEventCallback := func(eventType, reason, message string) { helper.RecordNodeEvent(ctx, node.Name, eventType, reason, message) } + err = orchestrator.AddNode(ctx, node, nodeEventCallback) if err != nil { response.setError(err) } updateResponse.Name = node.Name + updateResponse.LogLevel = node.LogLevel + updateResponse.LogWorkflows = node.LogWorkflows + updateResponse.LogLayers = node.LogLayers return httpStatusCodeForAdd(err) }, ) diff --git a/persistent_store/crd/apis/netapp/v1/node.go b/persistent_store/crd/apis/netapp/v1/node.go index c62112c09..5228f569e 100644 --- a/persistent_store/crd/apis/netapp/v1/node.go +++ b/persistent_store/crd/apis/netapp/v1/node.go @@ -43,6 +43,9 @@ func (in *TridentNode) Apply(persistent *utils.Node) error { in.IPs = persistent.IPs in.Deleted = persistent.Deleted in.PublicationState = string(persistent.PublicationState) + in.LogLevel = persistent.LogLevel + in.LogWorkflows = persistent.LogWorkflows + in.LogLayers = persistent.LogLayers nodePrep, err := json.Marshal(persistent.NodePrep) if err != nil { diff --git a/persistent_store/crd/apis/netapp/v1/types.go b/persistent_store/crd/apis/netapp/v1/types.go index e814e2d57..125b43efd 100644 --- a/persistent_store/crd/apis/netapp/v1/types.go +++ b/persistent_store/crd/apis/netapp/v1/types.go @@ -376,6 +376,12 @@ type TridentNode struct { Deleted bool `json:"deleted"` // PublicationState indicates whether the node is safe for volume publications PublicationState string `json:"publicationState"` + // LogLevel indicates the log level which is currently set for the node + LogLevel string `json:"logLevel"` + // LogWorkflows indicates the selected workflows which are currently set for the node + LogWorkflows string `json:"logWorkflows"` + // LogLayers indicates the selected log layers which are currently set for the node + LogLayers string `json:"logLayers"` } // TridentNodeList is a list of TridentNode objects. diff --git a/utils/types.go b/utils/types.go index 93fd54813..6c76e317c 100644 --- a/utils/types.go +++ b/utils/types.go @@ -168,6 +168,9 @@ type Node struct { HostInfo *HostSystem `json:"hostInfo,omitempty"` Deleted bool `json:"deleted"` PublicationState NodePublicationState `json:"publicationState"` + LogLevel string `json:"logLevel"` + LogWorkflows string `json:"logWorkflows"` + LogLayers string `json:"logLayers"` } type NodeExternal struct { @@ -180,6 +183,9 @@ type NodeExternal struct { HostInfo *HostSystem `json:"hostInfo,omitempty"` Deleted *bool `json:"deleted,omitempty"` PublicationState NodePublicationState `json:"publicationState,omitempty"` + LogLevel string `json:"logLevel"` + LogWorkflows string `json:"logWorkflows"` + LogLayers string `json:"logLayers"` } func (n *Node) Copy() *Node { @@ -209,6 +215,9 @@ func (n *Node) ConstructExternal() *NodeExternal { HostInfo: node.HostInfo, Deleted: Ptr(node.Deleted), PublicationState: node.PublicationState, + LogLevel: node.LogLevel, + LogWorkflows: node.LogWorkflows, + LogLayers: node.LogLayers, } }