refactor(workload): centralize workload listing with registry-based listers and add Argo Rollouts support

This commit is contained in:
TheiLLeniumStudios
2025-12-28 08:47:56 +01:00
parent c19058a66e
commit 3cf0119748
10 changed files with 808 additions and 123 deletions
+3 -22
View File
@@ -2,6 +2,7 @@
package config
import (
"strings"
"time"
"k8s.io/apimachinery/pkg/labels"
@@ -157,7 +158,7 @@ func DefaultAnnotations() AnnotationConfig {
// IsResourceIgnored checks if a resource name should be ignored (case-insensitive).
func (c *Config) IsResourceIgnored(name string) bool {
for _, ignored := range c.IgnoredResources {
if equalFold(ignored, name) {
if strings.EqualFold(ignored, name) {
return true
}
}
@@ -167,7 +168,7 @@ func (c *Config) IsResourceIgnored(name string) bool {
// IsWorkloadIgnored checks if a workload type should be ignored (case-insensitive).
func (c *Config) IsWorkloadIgnored(workloadType string) bool {
for _, ignored := range c.IgnoredWorkloads {
if equalFold(ignored, workloadType) {
if strings.EqualFold(ignored, workloadType) {
return true
}
}
@@ -184,23 +185,3 @@ func (c *Config) IsNamespaceIgnored(namespace string) bool {
return false
}
func equalFold(s, t string) bool {
if len(s) != len(t) {
return false
}
for i := 0; i < len(s); i++ {
c1, c2 := s[i], t[i]
if c1 != c2 {
if 'A' <= c1 && c1 <= 'Z' {
c1 += 'a' - 'A'
}
if 'A' <= c2 && c2 <= 'Z' {
c2 += 'a' - 'A'
}
if c1 != c2 {
return false
}
}
}
return true
}
-26
View File
@@ -201,29 +201,3 @@ func TestConfig_IsNamespaceIgnored(t *testing.T) {
}
}
func TestEqualFold(t *testing.T) {
tests := []struct {
s, t string
want bool
}{
{"abc", "abc", true},
{"ABC", "abc", true},
{"abc", "ABC", true},
{"aBc", "AbC", true},
{"abc", "abcd", false},
{"", "", true},
{"a", "", false},
{"", "a", false},
}
for _, tt := range tests {
t.Run(
tt.s+"_"+tt.t, func(t *testing.T) {
got := equalFold(tt.s, tt.t)
if got != tt.want {
t.Errorf("equalFold(%q, %q) = %v, want %v", tt.s, tt.t, got, tt.want)
}
},
)
}
}
+10 -1
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"github.com/stakater/Reloader/internal/pkg/workload"
"k8s.io/apimachinery/pkg/labels"
)
@@ -102,8 +103,16 @@ func (c *Config) Validate() error {
// Normalize IgnoredResources to lowercase for consistent comparison
c.IgnoredResources = normalizeToLower(c.IgnoredResources)
// Normalize IgnoredWorkloads to lowercase
// Validate and normalize IgnoredWorkloads
c.IgnoredWorkloads = normalizeToLower(c.IgnoredWorkloads)
for _, w := range c.IgnoredWorkloads {
if _, err := workload.KindFromString(w); err != nil {
errs = append(errs, ValidationError{
Field: "IgnoredWorkloads",
Message: fmt.Sprintf("unknown workload type %q", w),
})
}
}
if len(errs) > 0 {
return errs
+14
View File
@@ -178,6 +178,20 @@ func TestConfig_Validate_NormalizesIgnoredWorkloads(t *testing.T) {
}
}
func TestConfig_Validate_InvalidIgnoredWorkload(t *testing.T) {
cfg := NewDefault()
cfg.IgnoredWorkloads = []string{"deployment", "invalidtype"}
err := cfg.Validate()
if err == nil {
t.Fatal("Validate() should return error for invalid workload type")
}
if !strings.Contains(err.Error(), "invalidtype") {
t.Errorf("Error should mention invalid workload type, got: %v", err)
}
}
func TestConfig_Validate_MultipleErrors(t *testing.T) {
cfg := NewDefault()
cfg.ReloadStrategy = "invalid"