feat: reload execution and observability

This commit is contained in:
TheiLLeniumStudios
2025-12-28 08:47:52 +01:00
parent ce1e7dfafb
commit b5df945fff
8 changed files with 1827 additions and 21 deletions
+21 -1
View File
@@ -74,7 +74,8 @@ func (s *EnvVarStrategy) Name() string {
return string(config.ReloadStrategyEnvVars)
}
// Apply adds or updates an environment variable to trigger a restart.
// Apply adds, updates, or removes an environment variable to trigger a restart.
// When hash is empty (resource deleted), the env var is removed.
func (s *EnvVarStrategy) Apply(input StrategyInput) (bool, error) {
if input.Container == nil {
return false, fmt.Errorf("container is required for env-var strategy")
@@ -82,6 +83,11 @@ func (s *EnvVarStrategy) Apply(input StrategyInput) (bool, error) {
envVarName := s.envVarName(input.ResourceName, input.ResourceType)
// Handle deletion: remove the env var when hash is empty
if input.Hash == "" {
return s.removeEnvVar(input.Container, envVarName), nil
}
// Check if env var already exists
for i := range input.Container.Env {
if input.Container.Env[i].Name == envVarName {
@@ -104,6 +110,20 @@ func (s *EnvVarStrategy) Apply(input StrategyInput) (bool, error) {
return true, nil
}
// removeEnvVar removes an environment variable from a container.
// Returns true if a variable was removed.
func (s *EnvVarStrategy) removeEnvVar(container *corev1.Container, name string) bool {
for i := range container.Env {
if container.Env[i].Name == name {
// Remove by replacing with last element and truncating
container.Env[i] = container.Env[len(container.Env)-1]
container.Env = container.Env[:len(container.Env)-1]
return true
}
}
return false
}
// envVarName generates the environment variable name for a resource.
func (s *EnvVarStrategy) envVarName(resourceName string, resourceType ResourceType) string {
var postfix string