Skip to content

Commit 0f30456

Browse files
authored
promote definition "workload.codeflare.dev/appwrapper" to api (#282)
1 parent ed82907 commit 0f30456

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

api/v1beta2/appwrapper_types.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ const (
179179
RetryableExitCodesAnnotation = "workload.codeflare.dev.appwrapper/retryableExitCodes"
180180
)
181181

182-
const AppWrapperControllerName = "workload.codeflare.dev/appwrapper-controller"
182+
const (
183+
AppWrapperControllerName = "workload.codeflare.dev/appwrapper-controller"
184+
AppWrapperLabel = "workload.codeflare.dev/appwrapper"
185+
)
183186

184187
//+kubebuilder:object:root=true
185188
//+kubebuilder:subresource:status

internal/controller/appwrapper/appwrapper_controller.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ import (
5050
)
5151

5252
const (
53-
AppWrapperLabel = "workload.codeflare.dev/appwrapper"
5453
AppWrapperFinalizer = "workload.codeflare.dev/finalizer"
55-
childJobQueueName = "workload.codeflare.dev.admitted"
5654
)
5755

5856
// AppWrapperReconciler reconciles an appwrapper
@@ -546,7 +544,7 @@ func (r *AppWrapperReconciler) getPodStatus(ctx context.Context, aw *workloadv1b
546544
pods := &v1.PodList{}
547545
if err := r.List(ctx, pods,
548546
client.InNamespace(aw.Namespace),
549-
client.MatchingLabels{AppWrapperLabel: aw.Name}); err != nil {
547+
client.MatchingLabels{workloadv1beta2.AppWrapperLabel: aw.Name}); err != nil {
550548
return nil, err
551549
}
552550
pc, err := utils.ExpectedPodCount(aw)
@@ -913,7 +911,7 @@ func clearCondition(aw *workloadv1beta2.AppWrapper, condition workloadv1beta2.Ap
913911
// podMapFunc maps pods to appwrappers and generates reconcile.Requests for those whose Status.Phase is PodSucceeded
914912
func (r *AppWrapperReconciler) podMapFunc(ctx context.Context, obj client.Object) []reconcile.Request {
915913
pod := obj.(*v1.Pod)
916-
if name, ok := pod.Labels[AppWrapperLabel]; ok {
914+
if name, ok := pod.Labels[workloadv1beta2.AppWrapperLabel]; ok {
917915
if pod.Status.Phase == v1.PodSucceeded {
918916
return []reconcile.Request{{NamespacedName: types.NamespacedName{Namespace: pod.Namespace, Name: name}}}
919917
}

internal/controller/appwrapper/appwrapper_controller_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ var _ = Describe("AppWrapper Controller", func() {
367367

368368
By("Validate expected markers and Autopilot anti-affinities were injected")
369369
for _, p := range pods {
370-
Expect(p.Labels).Should(HaveKeyWithValue(AppWrapperLabel, awName.Name))
370+
Expect(p.Labels).Should(HaveKeyWithValue(workloadv1beta2.AppWrapperLabel, awName.Name))
371371
validateMarkers(&p)
372372
validateAutopilot(&p)
373373
}
@@ -382,7 +382,7 @@ var _ = Describe("AppWrapper Controller", func() {
382382

383383
By("Validate expected markers and Autopilot anti-affinities were injected")
384384
for _, p := range pods {
385-
Expect(p.Labels).Should(HaveKeyWithValue(AppWrapperLabel, awName.Name))
385+
Expect(p.Labels).Should(HaveKeyWithValue(workloadv1beta2.AppWrapperLabel, awName.Name))
386386
validateMarkers(&p)
387387
validateAutopilot(&p)
388388
}

internal/controller/appwrapper/fixtures_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func getPods(aw *workloadv1beta2.AppWrapper) []v1.Pod {
7575
err := k8sClient.List(ctx, podList, &client.ListOptions{Namespace: aw.Namespace})
7676
Expect(err).NotTo(HaveOccurred())
7777
for _, pod := range podList.Items {
78-
if awn, found := pod.Labels[AppWrapperLabel]; found && awn == aw.Name {
78+
if awn, found := pod.Labels[workloadv1beta2.AppWrapperLabel]; found && awn == aw.Name {
7979
result = append(result, pod)
8080
}
8181
}
@@ -93,7 +93,7 @@ func setPodStatus(aw *workloadv1beta2.AppWrapper, phase v1.PodPhase, numToChange
9393
if numToChange <= 0 {
9494
return nil
9595
}
96-
if awn, found := pod.Labels[AppWrapperLabel]; found && awn == aw.Name {
96+
if awn, found := pod.Labels[workloadv1beta2.AppWrapperLabel]; found && awn == aw.Name {
9797
pod.Status.Phase = phase
9898
err = k8sClient.Status().Update(ctx, &pod)
9999
if err != nil {

internal/controller/appwrapper/resource_management.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
197197
if err != nil {
198198
return err, true
199199
}
200-
awLabels := map[string]string{AppWrapperLabel: aw.Name}
200+
awLabels := map[string]string{workloadv1beta2.AppWrapperLabel: aw.Name}
201201
obj.SetLabels(utilmaps.MergeKeepFirst(obj.GetLabels(), awLabels))
202202

203203
for podSetsIdx, podSet := range componentStatus.PodSets {
@@ -411,7 +411,7 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
411411
if err := r.List(ctx, pods,
412412
client.UnsafeDisableDeepCopy,
413413
client.InNamespace(aw.Namespace),
414-
client.MatchingLabels{AppWrapperLabel: aw.Name}); err != nil {
414+
client.MatchingLabels{workloadv1beta2.AppWrapperLabel: aw.Name}); err != nil {
415415
log.FromContext(ctx).Error(err, "Pod list error")
416416
}
417417

test/e2e/util_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4242

4343
workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
44-
"github.com/project-codeflare/appwrapper/internal/controller/appwrapper"
4544
"github.com/project-codeflare/appwrapper/pkg/utils"
4645
)
4746

@@ -216,7 +215,7 @@ func getNodeForAppwrapper(ctx context.Context, awName types.NamespacedName) (str
216215
return "", err
217216
}
218217
for _, pod := range podList.Items {
219-
if awn, found := pod.Labels[appwrapper.AppWrapperLabel]; found && awn == awName.Name {
218+
if awn, found := pod.Labels[workloadv1beta2.AppWrapperLabel]; found && awn == awName.Name {
220219
return pod.Spec.NodeName, nil
221220
}
222221
}
@@ -249,7 +248,7 @@ func podsInPhase(awNamespace string, awName string, phase []v1.PodPhase, minimum
249248

250249
matchingPodCount := int32(0)
251250
for _, pod := range podList.Items {
252-
if awn, found := pod.Labels[appwrapper.AppWrapperLabel]; found && awn == awName {
251+
if awn, found := pod.Labels[workloadv1beta2.AppWrapperLabel]; found && awn == awName {
253252
for _, p := range phase {
254253
if pod.Status.Phase == p {
255254
matchingPodCount++
@@ -272,7 +271,7 @@ func noPodsExist(awNamespace string, awName string) wait.ConditionWithContextFun
272271
}
273272

274273
for _, podFromPodList := range podList.Items {
275-
if awn, found := podFromPodList.Labels[appwrapper.AppWrapperLabel]; found && awn == awName {
274+
if awn, found := podFromPodList.Labels[workloadv1beta2.AppWrapperLabel]; found && awn == awName {
276275
return false, nil
277276
}
278277
}

0 commit comments

Comments
 (0)