Skip to content

Commit 940dd31

Browse files
committed
cleanup: workloadv1beta2 ==> awv1beta2
1 parent 92e7a2b commit 940dd31

15 files changed

+428
-428
lines changed

cmd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import (
4949

5050
kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1"
5151

52-
workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
52+
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
5353
"github.com/project-codeflare/appwrapper/internal/metrics"
5454
"github.com/project-codeflare/appwrapper/pkg/config"
5555
"github.com/project-codeflare/appwrapper/pkg/controller"
@@ -67,7 +67,7 @@ var (
6767
func init() {
6868
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
6969
utilruntime.Must(kueue.AddToScheme(scheme))
70-
utilruntime.Must(workloadv1beta2.AddToScheme(scheme))
70+
utilruntime.Must(awv1beta2.AddToScheme(scheme))
7171
//+kubebuilder:scaffold:scheme
7272
}
7373

internal/controller/appwrapper/appwrapper_controller.go

Lines changed: 118 additions & 118 deletions
Large diffs are not rendered by default.

internal/controller/appwrapper/appwrapper_controller_test.go

Lines changed: 74 additions & 74 deletions
Large diffs are not rendered by default.

internal/controller/appwrapper/fixtures_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1"
3434
"sigs.k8s.io/yaml"
3535

36-
workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
36+
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
3737
)
3838

3939
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
@@ -47,16 +47,16 @@ func randName(baseName string) string {
4747
return fmt.Sprintf("%s-%s", baseName, string(b))
4848
}
4949

50-
func toAppWrapper(components ...workloadv1beta2.AppWrapperComponent) *workloadv1beta2.AppWrapper {
51-
return &workloadv1beta2.AppWrapper{
52-
TypeMeta: metav1.TypeMeta{APIVersion: workloadv1beta2.GroupVersion.String(), Kind: "AppWrapper"},
50+
func toAppWrapper(components ...awv1beta2.AppWrapperComponent) *awv1beta2.AppWrapper {
51+
return &awv1beta2.AppWrapper{
52+
TypeMeta: metav1.TypeMeta{APIVersion: awv1beta2.GroupVersion.String(), Kind: "AppWrapper"},
5353
ObjectMeta: metav1.ObjectMeta{Name: randName("aw"), Namespace: "default"},
54-
Spec: workloadv1beta2.AppWrapperSpec{Components: components},
54+
Spec: awv1beta2.AppWrapperSpec{Components: components},
5555
}
5656
}
5757

58-
func getAppWrapper(typeNamespacedName types.NamespacedName) *workloadv1beta2.AppWrapper {
59-
aw := &workloadv1beta2.AppWrapper{}
58+
func getAppWrapper(typeNamespacedName types.NamespacedName) *awv1beta2.AppWrapper {
59+
aw := &awv1beta2.AppWrapper{}
6060
err := k8sClient.Get(ctx, typeNamespacedName, aw)
6161
Expect(err).NotTo(HaveOccurred())
6262
return aw
@@ -69,21 +69,21 @@ func getNode(name string) *v1.Node {
6969
return node
7070
}
7171

72-
func getPods(aw *workloadv1beta2.AppWrapper) []v1.Pod {
72+
func getPods(aw *awv1beta2.AppWrapper) []v1.Pod {
7373
result := []v1.Pod{}
7474
podList := &v1.PodList{}
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[workloadv1beta2.AppWrapperLabel]; found && awn == aw.Name {
78+
if awn, found := pod.Labels[awv1beta2.AppWrapperLabel]; found && awn == aw.Name {
7979
result = append(result, pod)
8080
}
8181
}
8282
return result
8383
}
8484

8585
// envTest doesn't have a Pod controller; so simulate it
86-
func setPodStatus(aw *workloadv1beta2.AppWrapper, phase v1.PodPhase, numToChange int32) error {
86+
func setPodStatus(aw *awv1beta2.AppWrapper, phase v1.PodPhase, numToChange int32) error {
8787
podList := &v1.PodList{}
8888
err := k8sClient.List(ctx, podList, &client.ListOptions{Namespace: aw.Namespace})
8989
if err != nil {
@@ -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[workloadv1beta2.AppWrapperLabel]; found && awn == aw.Name {
96+
if awn, found := pod.Labels[awv1beta2.AppWrapperLabel]; found && awn == aw.Name {
9797
pod.Status.Phase = phase
9898
err = k8sClient.Status().Update(ctx, &pod)
9999
if err != nil {
@@ -123,7 +123,7 @@ spec:
123123
limits:
124124
nvidia.com/gpu: %v`
125125

126-
func pod(milliCPU int64, numGPU int64, declarePodSets bool) workloadv1beta2.AppWrapperComponent {
126+
func pod(milliCPU int64, numGPU int64, declarePodSets bool) awv1beta2.AppWrapperComponent {
127127
yamlString := fmt.Sprintf(podYAML,
128128
randName("pod"),
129129
resource.NewMilliQuantity(milliCPU, resource.DecimalSI),
@@ -132,11 +132,11 @@ func pod(milliCPU int64, numGPU int64, declarePodSets bool) workloadv1beta2.AppW
132132

133133
jsonBytes, err := yaml.YAMLToJSON([]byte(yamlString))
134134
Expect(err).NotTo(HaveOccurred())
135-
awc := &workloadv1beta2.AppWrapperComponent{
135+
awc := &awv1beta2.AppWrapperComponent{
136136
Template: runtime.RawExtension{Raw: jsonBytes},
137137
}
138138
if declarePodSets {
139-
awc.DeclaredPodSets = []workloadv1beta2.AppWrapperPodSet{{Replicas: ptr.To(int32(1)), Path: "template"}}
139+
awc.DeclaredPodSets = []awv1beta2.AppWrapperPodSet{{Replicas: ptr.To(int32(1)), Path: "template"}}
140140
}
141141
return *awc
142142
}
@@ -181,11 +181,11 @@ spec:
181181
limits:
182182
nvidia.com/gpu: 1`
183183

184-
func complexPodYaml() workloadv1beta2.AppWrapperComponent {
184+
func complexPodYaml() awv1beta2.AppWrapperComponent {
185185
yamlString := fmt.Sprintf(complexPodYAML, randName("pod"))
186186
jsonBytes, err := yaml.YAMLToJSON([]byte(yamlString))
187187
Expect(err).NotTo(HaveOccurred())
188-
awc := &workloadv1beta2.AppWrapperComponent{
188+
awc := &awv1beta2.AppWrapperComponent{
189189
Template: runtime.RawExtension{Raw: jsonBytes},
190190
}
191191
return *awc
@@ -205,15 +205,15 @@ spec:
205205
requests:
206206
cpu: %v`
207207

208-
func malformedPod(milliCPU int64) workloadv1beta2.AppWrapperComponent {
208+
func malformedPod(milliCPU int64) awv1beta2.AppWrapperComponent {
209209
yamlString := fmt.Sprintf(malformedPodYAML,
210210
randName("pod"),
211211
resource.NewMilliQuantity(milliCPU, resource.DecimalSI))
212212

213213
jsonBytes, err := yaml.YAMLToJSON([]byte(yamlString))
214214
Expect(err).NotTo(HaveOccurred())
215-
return workloadv1beta2.AppWrapperComponent{
216-
DeclaredPodSets: []workloadv1beta2.AppWrapperPodSet{{Replicas: ptr.To(int32(1)), Path: "template"}},
215+
return awv1beta2.AppWrapperComponent{
216+
DeclaredPodSets: []awv1beta2.AppWrapperPodSet{{Replicas: ptr.To(int32(1)), Path: "template"}},
217217
Template: runtime.RawExtension{Raw: jsonBytes},
218218
}
219219
}

internal/controller/appwrapper/resource_management.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"fmt"
2323
"time"
2424

25-
workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
25+
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
2626
"github.com/project-codeflare/appwrapper/pkg/utils"
2727
v1 "k8s.io/api/core/v1"
2828
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -188,7 +188,7 @@ func addNodeSelectorsToAffinity(spec map[string]interface{}, exprsToAdd []v1.Nod
188188
}
189189

190190
//gocyclo:ignore
191-
func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workloadv1beta2.AppWrapper, componentIdx int) (error, bool) {
191+
func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *awv1beta2.AppWrapper, componentIdx int) (error, bool) {
192192
component := aw.Spec.Components[componentIdx]
193193
componentStatus := aw.Status.ComponentStatus[componentIdx]
194194
toMap := func(x interface{}) map[string]string {
@@ -218,11 +218,11 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
218218
if err != nil {
219219
return err, true
220220
}
221-
awLabels := map[string]string{workloadv1beta2.AppWrapperLabel: aw.Name}
221+
awLabels := map[string]string{awv1beta2.AppWrapperLabel: aw.Name}
222222
obj.SetLabels(utilmaps.MergeKeepFirst(obj.GetLabels(), awLabels))
223223

224224
for podSetsIdx, podSet := range componentStatus.PodSets {
225-
toInject := &workloadv1beta2.AppWrapperPodSetInfo{}
225+
toInject := &awv1beta2.AppWrapperPodSetInfo{}
226226
if r.Config.EnableKueueIntegrations {
227227
if podSetsIdx < len(component.PodSetInfos) {
228228
toInject = &component.PodSetInfos[podSetsIdx]
@@ -354,12 +354,12 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
354354
log.FromContext(ctx).Info("After injection", "obj", obj)
355355

356356
orig := copyForStatusPatch(aw)
357-
if meta.FindStatusCondition(aw.Status.ComponentStatus[componentIdx].Conditions, string(workloadv1beta2.ResourcesDeployed)) == nil {
357+
if meta.FindStatusCondition(aw.Status.ComponentStatus[componentIdx].Conditions, string(awv1beta2.ResourcesDeployed)) == nil {
358358
aw.Status.ComponentStatus[componentIdx].Name = obj.GetName()
359359
aw.Status.ComponentStatus[componentIdx].Kind = obj.GetKind()
360360
aw.Status.ComponentStatus[componentIdx].APIVersion = obj.GetAPIVersion()
361361
meta.SetStatusCondition(&aw.Status.ComponentStatus[componentIdx].Conditions, metav1.Condition{
362-
Type: string(workloadv1beta2.ResourcesDeployed),
362+
Type: string(awv1beta2.ResourcesDeployed),
363363
Status: metav1.ConditionUnknown,
364364
Reason: "ComponentCreationInitiated",
365365
})
@@ -383,7 +383,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
383383
// resource not actually created; patch status to reflect that
384384
orig := copyForStatusPatch(aw)
385385
meta.SetStatusCondition(&aw.Status.ComponentStatus[componentIdx].Conditions, metav1.Condition{
386-
Type: string(workloadv1beta2.ResourcesDeployed),
386+
Type: string(awv1beta2.ResourcesDeployed),
387387
Status: metav1.ConditionFalse,
388388
Reason: "ComponentCreationErrored",
389389
})
@@ -399,7 +399,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
399399
orig = copyForStatusPatch(aw)
400400
aw.Status.ComponentStatus[componentIdx].Name = obj.GetName() // Update name to support usage of GenerateName
401401
meta.SetStatusCondition(&aw.Status.ComponentStatus[componentIdx].Conditions, metav1.Condition{
402-
Type: string(workloadv1beta2.ResourcesDeployed),
402+
Type: string(awv1beta2.ResourcesDeployed),
403403
Status: metav1.ConditionTrue,
404404
Reason: "ComponentCreatedSuccessfully",
405405
})
@@ -411,9 +411,9 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
411411
}
412412

413413
// createComponents incrementally patches aw.Status -- MUST NOT CARRY STATUS PATCHES ACROSS INVOCATIONS
414-
func (r *AppWrapperReconciler) createComponents(ctx context.Context, aw *workloadv1beta2.AppWrapper) (error, bool) {
414+
func (r *AppWrapperReconciler) createComponents(ctx context.Context, aw *awv1beta2.AppWrapper) (error, bool) {
415415
for componentIdx := range aw.Spec.Components {
416-
if !meta.IsStatusConditionTrue(aw.Status.ComponentStatus[componentIdx].Conditions, string(workloadv1beta2.ResourcesDeployed)) {
416+
if !meta.IsStatusConditionTrue(aw.Status.ComponentStatus[componentIdx].Conditions, string(awv1beta2.ResourcesDeployed)) {
417417
if err, fatal := r.createComponent(ctx, aw, componentIdx); err != nil {
418418
return err, fatal
419419
}
@@ -422,10 +422,10 @@ func (r *AppWrapperReconciler) createComponents(ctx context.Context, aw *workloa
422422
return nil, false
423423
}
424424

425-
func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloadv1beta2.AppWrapper) bool {
425+
func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *awv1beta2.AppWrapper) bool {
426426
deleteIfPresent := func(idx int, opts ...client.DeleteOption) bool {
427427
cs := &aw.Status.ComponentStatus[idx]
428-
rd := meta.FindStatusCondition(cs.Conditions, string(workloadv1beta2.ResourcesDeployed))
428+
rd := meta.FindStatusCondition(cs.Conditions, string(awv1beta2.ResourcesDeployed))
429429
if rd == nil || rd.Status == metav1.ConditionFalse || (rd.Status == metav1.ConditionUnknown && cs.Name == "") {
430430
return false // not present
431431
}
@@ -437,7 +437,7 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
437437
if apierrors.IsNotFound(err) {
438438
// Has already been undeployed; update componentStatus and return not present
439439
meta.SetStatusCondition(&cs.Conditions, metav1.Condition{
440-
Type: string(workloadv1beta2.ResourcesDeployed),
440+
Type: string(awv1beta2.ResourcesDeployed),
441441
Status: metav1.ConditionFalse,
442442
Reason: "CompononetDeleted",
443443
})
@@ -451,7 +451,7 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
451451
}
452452

453453
meta.SetStatusCondition(&aw.Status.Conditions, metav1.Condition{
454-
Type: string(workloadv1beta2.DeletingResources),
454+
Type: string(awv1beta2.DeletingResources),
455455
Status: metav1.ConditionTrue,
456456
Reason: "DeletionInitiated",
457457
})
@@ -462,7 +462,7 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
462462
}
463463

464464
deletionGracePeriod := r.forcefulDeletionGraceDuration(ctx, aw)
465-
whenInitiated := meta.FindStatusCondition(aw.Status.Conditions, string(workloadv1beta2.DeletingResources)).LastTransitionTime
465+
whenInitiated := meta.FindStatusCondition(aw.Status.Conditions, string(awv1beta2.DeletingResources)).LastTransitionTime
466466
gracePeriodExpired := time.Now().After(whenInitiated.Time.Add(deletionGracePeriod))
467467

468468
if componentsRemaining && !gracePeriodExpired {
@@ -474,13 +474,13 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
474474
if err := r.List(ctx, pods,
475475
client.UnsafeDisableDeepCopy,
476476
client.InNamespace(aw.Namespace),
477-
client.MatchingLabels{workloadv1beta2.AppWrapperLabel: aw.Name}); err != nil {
477+
client.MatchingLabels{awv1beta2.AppWrapperLabel: aw.Name}); err != nil {
478478
log.FromContext(ctx).Error(err, "Pod list error")
479479
}
480480

481481
if !componentsRemaining && len(pods.Items) == 0 {
482482
// no resources or pods left; deletion is complete
483-
clearCondition(aw, workloadv1beta2.DeletingResources, "DeletionComplete", "")
483+
clearCondition(aw, awv1beta2.DeletingResources, "DeletionComplete", "")
484484
return true
485485
}
486486

internal/controller/appwrapper/suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
logf "sigs.k8s.io/controller-runtime/pkg/log"
3939
"sigs.k8s.io/controller-runtime/pkg/log/zap"
4040

41-
workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
41+
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
4242
kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1"
4343
)
4444

@@ -85,7 +85,7 @@ var _ = BeforeSuite(func() {
8585
Expect(cfg).NotTo(BeNil())
8686

8787
scheme := apimachineryruntime.NewScheme()
88-
err = workloadv1beta2.AddToScheme(scheme)
88+
err = awv1beta2.AddToScheme(scheme)
8989
Expect(err).NotTo(HaveOccurred())
9090

9191
err = admissionv1.AddToScheme(scheme)

internal/controller/workload/workload_controller.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"sigs.k8s.io/kueue/pkg/controller/jobframework"
2828
"sigs.k8s.io/kueue/pkg/podset"
2929

30-
workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
30+
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
3131
"github.com/project-codeflare/appwrapper/pkg/utils"
3232
)
3333

@@ -39,10 +39,10 @@ import (
3939
// +kubebuilder:rbac:groups=kueue.x-k8s.io,resources=resourceflavors,verbs=get;list;watch
4040
// +kubebuilder:rbac:groups=kueue.x-k8s.io,resources=workloadpriorityclasses,verbs=get;list;watch
4141

42-
type AppWrapper workloadv1beta2.AppWrapper
42+
type AppWrapper awv1beta2.AppWrapper
4343

4444
var (
45-
GVK = workloadv1beta2.GroupVersion.WithKind("AppWrapper")
45+
GVK = awv1beta2.GroupVersion.WithKind("AppWrapper")
4646
WorkloadReconciler = jobframework.NewGenericReconcilerFactory(
4747
func() jobframework.GenericJob { return &AppWrapper{} },
4848
func(b *builder.Builder, c client.Client) *builder.Builder {
@@ -52,15 +52,15 @@ var (
5252
)
5353

5454
func (aw *AppWrapper) Object() client.Object {
55-
return (*workloadv1beta2.AppWrapper)(aw)
55+
return (*awv1beta2.AppWrapper)(aw)
5656
}
5757

5858
func (aw *AppWrapper) IsSuspended() bool {
5959
return aw.Spec.Suspend
6060
}
6161

6262
func (aw *AppWrapper) IsActive() bool {
63-
return meta.IsStatusConditionTrue(aw.Status.Conditions, string(workloadv1beta2.QuotaReserved))
63+
return meta.IsStatusConditionTrue(aw.Status.Conditions, string(awv1beta2.QuotaReserved))
6464
}
6565

6666
func (aw *AppWrapper) Suspend() {
@@ -72,7 +72,7 @@ func (aw *AppWrapper) GVK() schema.GroupVersionKind {
7272
}
7373

7474
func (aw *AppWrapper) PodSets() []kueue.PodSet {
75-
podSets, err := utils.GetPodSets((*workloadv1beta2.AppWrapper)(aw))
75+
podSets, err := utils.GetPodSets((*awv1beta2.AppWrapper)(aw))
7676
if err != nil {
7777
// Kueue will raise an error on zero length PodSet; the Kueue GenericJob API prevents propagating the actual error.
7878
return []kueue.PodSet{}
@@ -85,24 +85,24 @@ func (aw *AppWrapper) PodSets() []kueue.PodSet {
8585
}
8686

8787
func (aw *AppWrapper) RunWithPodSetsInfo(podSetsInfo []podset.PodSetInfo) error {
88-
if err := utils.SetPodSetInfos((*workloadv1beta2.AppWrapper)(aw), podSetsInfo); err != nil {
88+
if err := utils.SetPodSetInfos((*awv1beta2.AppWrapper)(aw), podSetsInfo); err != nil {
8989
return err
9090
}
9191
aw.Spec.Suspend = false
9292
return nil
9393
}
9494

9595
func (aw *AppWrapper) RestorePodSetsInfo(podSetsInfo []podset.PodSetInfo) bool {
96-
return utils.ClearPodSetInfos((*workloadv1beta2.AppWrapper)(aw))
96+
return utils.ClearPodSetInfos((*awv1beta2.AppWrapper)(aw))
9797
}
9898

9999
func (aw *AppWrapper) Finished() (message string, success, finished bool) {
100100
switch aw.Status.Phase {
101-
case workloadv1beta2.AppWrapperSucceeded:
101+
case awv1beta2.AppWrapperSucceeded:
102102
return "AppWrapper finished successfully", true, true
103103

104-
case workloadv1beta2.AppWrapperFailed:
105-
if meta.IsStatusConditionTrue(aw.Status.Conditions, string(workloadv1beta2.ResourcesDeployed)) {
104+
case awv1beta2.AppWrapperFailed:
105+
if meta.IsStatusConditionTrue(aw.Status.Conditions, string(awv1beta2.ResourcesDeployed)) {
106106
return "Still deleting resources for failed AppWrapper", false, false
107107
} else {
108108
return "AppWrapper failed", false, true
@@ -112,5 +112,5 @@ func (aw *AppWrapper) Finished() (message string, success, finished bool) {
112112
}
113113

114114
func (aw *AppWrapper) PodsReady() bool {
115-
return meta.IsStatusConditionTrue(aw.Status.Conditions, string(workloadv1beta2.PodsReady))
115+
return meta.IsStatusConditionTrue(aw.Status.Conditions, string(awv1beta2.PodsReady))
116116
}

0 commit comments

Comments
 (0)