From dd47a0a1921f5eb1074411aab6b3cc2929e00538 Mon Sep 17 00:00:00 2001 From: Meghan Bailey Date: Thu, 16 Jan 2025 08:47:16 -0800 Subject: [PATCH 1/3] added nil checks --- pkg/core/util/hive/kernelcr.go | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/pkg/core/util/hive/kernelcr.go b/pkg/core/util/hive/kernelcr.go index ffb5e0424..4b887b264 100644 --- a/pkg/core/util/hive/kernelcr.go +++ b/pkg/core/util/hive/kernelcr.go @@ -136,11 +136,16 @@ func (pH *PluginHandler) DynamicReloader(driverConfig *config.DriverConfig) { } if valid { for service, servPh := range *pH.Services { - *servPh.ConfigContext.CmdSenderChan <- core.KernelCmd{ - PluginName: servPh.Name, - Command: core.PLUGIN_EVENT_STOP, + if servPh.ConfigContext != nil && *servPh.ConfigContext.CmdSenderChan != nil { + *servPh.ConfigContext.CmdSenderChan <- core.KernelCmd{ + PluginName: servPh.Name, + Command: core.PLUGIN_EVENT_STOP, + } + driverConfig.CoreConfig.Log.Printf("Shutting down service: %s\n", service) + } else { + driverConfig.CoreConfig.Log.Printf("Service not properly initialized to shut down for cert reloading: %s\n", service) + goto sleep } - driverConfig.CoreConfig.Log.Printf("Shutting down service: %s\n", service) } //TODO: Get rid of os.Exit // 0. Reload certificates @@ -169,15 +174,24 @@ func (pH *PluginHandler) DynamicReloader(driverConfig *config.DriverConfig) { if new_sha, ok := certifyMap["trcsha256"]; ok && new_sha.(string) != servPh.Signature { driverConfig.CoreConfig.Log.Printf("Kernel shutdown, installing new service: %s\n", service) - for service, servPh := range *pH.Services { - *servPh.ConfigContext.CmdSenderChan <- core.KernelCmd{ - PluginName: servPh.Name, - Command: core.PLUGIN_EVENT_STOP, + for s, sPh := range *pH.Services { + if sPh.ConfigContext != nil && *sPh.ConfigContext.CmdSenderChan != nil { + *sPh.ConfigContext.CmdSenderChan <- core.KernelCmd{ + PluginName: sPh.Name, + Command: core.PLUGIN_EVENT_STOP, + } + driverConfig.CoreConfig.Log.Printf("Shutting down service: %s\n", s) + } else { + driverConfig.CoreConfig.Log.Printf("Service not properly initialized to shut down: %s\n", s) + goto sleep } - driverConfig.CoreConfig.Log.Printf("Shutting down service: %s\n", service) } if t, ok := certifyMap["trctype"]; ok && t.(string) == "trcshkubeservice" { + if servPh.ConfigContext == nil || *servPh.ConfigContext.CmdSenderChan == nil { + driverConfig.CoreConfig.Log.Printf("Kube service not properly initialized to shut down: %s\n", service) + goto sleep + } driverConfig.CoreConfig.Log.Printf("Shutting down service: %s\n", service) *servPh.ConfigContext.CmdSenderChan <- core.KernelCmd{ PluginName: servPh.Name, @@ -204,6 +218,7 @@ func (pH *PluginHandler) DynamicReloader(driverConfig *config.DriverConfig) { } } } + sleep: time.Sleep(time.Minute) } } From 968e9ca56b77a2b82c9ba09db0da697a3eb1f82c Mon Sep 17 00:00:00 2001 From: Meghan Bailey Date: Thu, 16 Jan 2025 08:53:23 -0800 Subject: [PATCH 2/3] rename variables --- pkg/core/util/hive/kernelcr.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/core/util/hive/kernelcr.go b/pkg/core/util/hive/kernelcr.go index 4b887b264..28bcd7080 100644 --- a/pkg/core/util/hive/kernelcr.go +++ b/pkg/core/util/hive/kernelcr.go @@ -135,16 +135,16 @@ func (pH *PluginHandler) DynamicReloader(driverConfig *config.DriverConfig) { valid = true } if valid { - for service, servPh := range *pH.Services { - if servPh.ConfigContext != nil && *servPh.ConfigContext.CmdSenderChan != nil { - *servPh.ConfigContext.CmdSenderChan <- core.KernelCmd{ - PluginName: servPh.Name, + for serv, phServ := range *pH.Services { + if phServ.ConfigContext != nil && *phServ.ConfigContext.CmdSenderChan != nil { + *phServ.ConfigContext.CmdSenderChan <- core.KernelCmd{ + PluginName: phServ.Name, Command: core.PLUGIN_EVENT_STOP, } - driverConfig.CoreConfig.Log.Printf("Shutting down service: %s\n", service) + driverConfig.CoreConfig.Log.Printf("Shutting down service: %s\n", serv) } else { - driverConfig.CoreConfig.Log.Printf("Service not properly initialized to shut down for cert reloading: %s\n", service) - goto sleep + driverConfig.CoreConfig.Log.Printf("Service not properly initialized to shut down for cert reloading: %s\n", serv) + goto waitToReload } } //TODO: Get rid of os.Exit @@ -183,14 +183,14 @@ func (pH *PluginHandler) DynamicReloader(driverConfig *config.DriverConfig) { driverConfig.CoreConfig.Log.Printf("Shutting down service: %s\n", s) } else { driverConfig.CoreConfig.Log.Printf("Service not properly initialized to shut down: %s\n", s) - goto sleep + goto waitToReload } } if t, ok := certifyMap["trctype"]; ok && t.(string) == "trcshkubeservice" { if servPh.ConfigContext == nil || *servPh.ConfigContext.CmdSenderChan == nil { driverConfig.CoreConfig.Log.Printf("Kube service not properly initialized to shut down: %s\n", service) - goto sleep + goto waitToReload } driverConfig.CoreConfig.Log.Printf("Shutting down service: %s\n", service) *servPh.ConfigContext.CmdSenderChan <- core.KernelCmd{ @@ -218,7 +218,7 @@ func (pH *PluginHandler) DynamicReloader(driverConfig *config.DriverConfig) { } } } - sleep: + waitToReload: time.Sleep(time.Minute) } } From 132990efe9f22d89f7c6cbfa72d271e4425b01ea Mon Sep 17 00:00:00 2001 From: Meghan Bailey Date: Thu, 16 Jan 2025 08:57:07 -0800 Subject: [PATCH 3/3] fix variable naming --- pkg/core/util/hive/kernelcr.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/core/util/hive/kernelcr.go b/pkg/core/util/hive/kernelcr.go index 28bcd7080..ba2263fce 100644 --- a/pkg/core/util/hive/kernelcr.go +++ b/pkg/core/util/hive/kernelcr.go @@ -135,15 +135,15 @@ func (pH *PluginHandler) DynamicReloader(driverConfig *config.DriverConfig) { valid = true } if valid { - for serv, phServ := range *pH.Services { - if phServ.ConfigContext != nil && *phServ.ConfigContext.CmdSenderChan != nil { - *phServ.ConfigContext.CmdSenderChan <- core.KernelCmd{ - PluginName: phServ.Name, + for s, sPh := range *pH.Services { + if sPh.ConfigContext != nil && *sPh.ConfigContext.CmdSenderChan != nil { + *sPh.ConfigContext.CmdSenderChan <- core.KernelCmd{ + PluginName: sPh.Name, Command: core.PLUGIN_EVENT_STOP, } - driverConfig.CoreConfig.Log.Printf("Shutting down service: %s\n", serv) + driverConfig.CoreConfig.Log.Printf("Shutting down service: %s\n", s) } else { - driverConfig.CoreConfig.Log.Printf("Service not properly initialized to shut down for cert reloading: %s\n", serv) + driverConfig.CoreConfig.Log.Printf("Service not properly initialized to shut down for cert reloading: %s\n", s) goto waitToReload } }