Skip to content

Commit 84e14f7

Browse files
committed
feat(devbox): support extra resource and annotation matcher
1 parent 62bada9 commit 84e14f7

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

controllers/devbox/cmd/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func main() {
8787
// pod matcher flag
8888
var enablePodResourceMatcher bool
8989
var enablePodExtraResourceMatcher bool
90-
var enablePodExpectedAnnotationsMatcher bool
90+
var enablePodAnnotationsMatcher bool
9191
var enablePodEnvMatcher bool
9292
var enablePodPortMatcher bool
9393
var enablePodEphemeralStorageMatcher bool
@@ -122,7 +122,7 @@ func main() {
122122
// pod matcher flag, pod resource matcher, env matcher, port matcher will be enabled by default, ephemeral storage matcher will be disabled by default
123123
flag.BoolVar(&enablePodResourceMatcher, "enable-pod-resource-matcher", true, "If set, pod resource matcher will be enabled")
124124
flag.BoolVar(&enablePodExtraResourceMatcher, "enable-pod-extra-resource-matcher", true, "If set, pod extra resource matcher will be enabled")
125-
flag.BoolVar(&enablePodExpectedAnnotationsMatcher, "enable-pod-expected-annotations-matcher", true, "If set, pod expected annotations matcher will be enabled")
125+
flag.BoolVar(&enablePodAnnotationsMatcher, "enable-pod-expected-annotations-matcher", true, "If set, pod expected annotations matcher will be enabled")
126126
flag.BoolVar(&enablePodEnvMatcher, "enable-pod-env-matcher", true, "If set, pod env matcher will be enabled")
127127
flag.BoolVar(&enablePodPortMatcher, "enable-pod-port-matcher", true, "If set, pod port matcher will be enabled")
128128
flag.BoolVar(&enablePodEphemeralStorageMatcher, "enable-pod-ephemeral-storage-matcher", false, "If set, pod ephemeral storage matcher will be enabled")
@@ -235,8 +235,8 @@ func main() {
235235
if enablePodExtraResourceMatcher {
236236
podMatchers = append(podMatchers, matcher.ExtraResourceMatcher{})
237237
}
238-
if enablePodExpectedAnnotationsMatcher {
239-
podMatchers = append(podMatchers, matcher.ExpectedAnnotationsMatcher{})
238+
if enablePodAnnotationsMatcher {
239+
podMatchers = append(podMatchers, matcher.AnnotationsMatcher{})
240240
}
241241
if enablePodEnvMatcher {
242242
podMatchers = append(podMatchers, matcher.EnvVarMatcher{})

controllers/devbox/internal/controller/devbox_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func (r *DevboxReconciler) syncPod(ctx context.Context, devbox *devboxv1alpha1.D
404404
}
405405
// update devbox status with latestDevbox status
406406
logger.Info("updating devbox status")
407-
logger.Info("merge commit history", "devbox", devbox.Status.CommitHistory, "latestDevbox", latestDevbox.Status.CommitHistory)
407+
// logger.Info("merge commit history", "devbox", devbox.Status.CommitHistory, "latestDevbox", latestDevbox.Status.CommitHistory)
408408
devbox.Status.Phase = helper.GenerateDevboxPhase(devbox, podList)
409409
helper.UpdateDevboxStatus(devbox, latestDevbox)
410410
return r.Status().Update(ctx, latestDevbox)

controllers/devbox/internal/controller/utils/matcher/matcher.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ package matcher
1616

1717
import (
1818
"log/slog"
19+
"os"
1920

2021
corev1 "k8s.io/api/core/v1"
2122
)
2223

24+
func init() {
25+
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})))
26+
}
27+
2328
type PodMatcher interface {
2429
Match(expectPod *corev1.Pod, pod *corev1.Pod) bool
2530
}
@@ -94,7 +99,7 @@ func compareExtraResourceList(expect corev1.ResourceList, actual corev1.Resource
9499
return true
95100
}
96101

97-
func compareExpectedAnnotations(expect map[string]string, actual map[string]string) bool {
102+
func compareAnnotations(expect map[string]string, actual map[string]string) bool {
98103
if len(expect) == 0 {
99104
return true
100105
}
@@ -128,10 +133,10 @@ func (m ExtraResourceMatcher) Match(expectPod *corev1.Pod, pod *corev1.Pod) bool
128133
return checkPodResources(expectPod, pod, extraResourceChecker)
129134
}
130135

131-
type ExpectedAnnotationsMatcher struct{}
136+
type AnnotationsMatcher struct{}
132137

133-
func (m ExpectedAnnotationsMatcher) Match(expectPod *corev1.Pod, pod *corev1.Pod) bool {
134-
return compareExpectedAnnotations(expectPod.Annotations, pod.Annotations)
138+
func (m AnnotationsMatcher) Match(expectPod *corev1.Pod, pod *corev1.Pod) bool {
139+
return compareAnnotations(expectPod.Annotations, pod.Annotations)
135140
}
136141

137142
type EphemeralStorageMatcher struct{}

controllers/devbox/internal/controller/utils/matcher/matcher_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,12 @@ func TestExpectedAnnotationsMatcher(t *testing.T) {
348348
},
349349
}
350350

351-
annotationMatcher := ExpectedAnnotationsMatcher{}
351+
annotationMatcher := AnnotationsMatcher{}
352352
for _, tt := range tests {
353353
t.Run(tt.name, func(t *testing.T) {
354354
result := annotationMatcher.Match(expectPod, tt.pod)
355355
if result != tt.expected {
356-
t.Errorf("ExpectedAnnotationsMatcher.Match() = %v, expected %v", result, tt.expected)
356+
t.Errorf("AnnotationsMatcher.Match() = %v, expected %v", result, tt.expected)
357357
}
358358
})
359359
}

0 commit comments

Comments
 (0)