Skip to content

Commit c47080e

Browse files
authored
Eliminate replicaPath from CRD (#109)
1 parent 2d09664 commit c47080e

File tree

11 files changed

+19
-82
lines changed

11 files changed

+19
-82
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
8383
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
8484

8585
.PHONY: generate-apiref
86-
generate-apiref: genref
86+
generate-apiref: genref ## Generate API Reference for project website.
8787
cd site/genref && $(GENREF) -o ../_pages
8888

8989
.PHONY: fmt

api/v1beta2/appwrapper_types.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ type AppWrapperPodSet struct {
5959
//+optional
6060
Replicas *int32 `json:"replicas,omitempty"`
6161

62-
// ReplicaPath is the path within Component.Template to the replica count for this PodSet
63-
//+optional
64-
ReplicaPath string `json:"replicaPath,omitempty"`
65-
6662
// PodPath is the path Component.Template to the PodTemplateSpec for this PodSet
6763
PodPath string `json:"podPath"`
6864
}

config/crd/bases/workload.codeflare.dev_appwrappers.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ spec:
138138
description: PodPath is the path Component.Template to
139139
the PodTemplateSpec for this PodSet
140140
type: string
141-
replicaPath:
142-
description: ReplicaPath is the path within Component.Template
143-
to the replica count for this PodSet
144-
type: string
145141
replicas:
146142
description: Replicas is the number of pods in this PodSet
147143
format: int32

internal/webhook/appwrapper_fixtures_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func deployment(replicaCount int, milliCPU int64) workloadv1beta2.AppWrapperComp
174174
jsonBytes, err := yaml.YAMLToJSON([]byte(yamlString))
175175
Expect(err).NotTo(HaveOccurred())
176176
return workloadv1beta2.AppWrapperComponent{
177-
PodSets: []workloadv1beta2.AppWrapperPodSet{{ReplicaPath: "template.spec.replicas", PodPath: "template.spec.template"}},
177+
PodSets: []workloadv1beta2.AppWrapperPodSet{{Replicas: ptr.To(int32(replicaCount)), PodPath: "template.spec.template"}},
178178
Template: runtime.RawExtension{Raw: jsonBytes},
179179
}
180180
}
@@ -365,7 +365,7 @@ func rayCluster(workerCount int, milliCPU int64) workloadv1beta2.AppWrapperCompo
365365
return workloadv1beta2.AppWrapperComponent{
366366
PodSets: []workloadv1beta2.AppWrapperPodSet{
367367
{Replicas: ptr.To(int32(1)), PodPath: "template.spec.headGroupSpec.template"},
368-
{ReplicaPath: "template.spec.workerGroupSpecs[0].maxReplicas", PodPath: "template.spec.workerGroupSpecs[0].template"},
368+
{Replicas: ptr.To(int32(workerCount)), PodPath: "template.spec.workerGroupSpecs[0].template"},
369369
},
370370
Template: runtime.RawExtension{Raw: jsonBytes},
371371
}
@@ -421,7 +421,7 @@ func jobSet(replicasWorker int, milliCPUWorker int64) workloadv1beta2.AppWrapper
421421
return workloadv1beta2.AppWrapperComponent{
422422
PodSets: []workloadv1beta2.AppWrapperPodSet{
423423
{PodPath: "template.spec.replicatedJobs[0].template.spec.template"},
424-
{ReplicaPath: "template.spec.replicatedJobs[1].template.spec.parallelism", PodPath: "template.spec.replicatedJobs[1].template.spec.template"},
424+
{Replicas: ptr.To(int32(replicasWorker)), PodPath: "template.spec.replicatedJobs[1].template.spec.template"},
425425
},
426426
Template: runtime.RawExtension{Raw: jsonBytes},
427427
}

internal/webhook/appwrapper_webhook.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ func (w *AppWrapperWebhook) Default(ctx context.Context, obj runtime.Object) err
6262
if w.Config.EnableKueueIntegrations {
6363
jobframework.ApplyDefaultForSuspend((*wlc.AppWrapper)(aw), w.Config.ManageJobsWithoutQueueName)
6464
}
65-
if err := expandPodSets(ctx, aw); err != nil {
66-
log.FromContext(ctx).Info("Error raised during podSet expansion", "job", aw)
67-
return err
68-
}
6965
return nil
7066
}
7167

@@ -102,44 +98,6 @@ func (w *AppWrapperWebhook) ValidateDelete(context.Context, runtime.Object) (adm
10298
return nil, nil
10399
}
104100

105-
// expandPodSets expands and simplifies the AppWrapper's PodSets
106-
func expandPodSets(_ context.Context, aw *workloadv1beta2.AppWrapper) error {
107-
components := aw.Spec.Components
108-
componentsPath := field.NewPath("spec").Child("components")
109-
for idx, component := range components {
110-
compPath := componentsPath.Index(idx)
111-
podSetsPath := compPath.Child("podSets")
112-
113-
// TODO: Here is where we would automatically create elided PodSets for known GVKs
114-
// See https://github.com/project-codeflare/appwrapper/issues/65
115-
116-
// Evaluate any ReplicaPaths and expand them to Replicas to simplify later processing
117-
for psIdx, ps := range component.PodSets {
118-
podSetPath := podSetsPath.Index(psIdx)
119-
if ps.ReplicaPath != "" {
120-
unstruct := &unstructured.Unstructured{}
121-
_, _, err := unstructured.UnstructuredJSONScheme.Decode(component.Template.Raw, nil, unstruct)
122-
if err != nil {
123-
return field.Invalid(compPath.Child("template"), component.Template, "failed to decode as JSON")
124-
}
125-
126-
if rc, err := utils.GetReplicas(unstruct, ps.ReplicaPath); err != nil {
127-
return field.Invalid(podSetPath.Child("replicaPath"), ps.ReplicaPath,
128-
fmt.Sprintf("replicaPath does not refer to an int: %v", err))
129-
} else {
130-
if ps.Replicas != nil && *ps.Replicas != rc {
131-
return field.Invalid(podSetPath.Child("replicas"), ps.Replicas,
132-
fmt.Sprintf("does not match value %v at path %v", rc, ps.ReplicaPath))
133-
}
134-
component.PodSets[psIdx].Replicas = &rc
135-
}
136-
}
137-
}
138-
139-
}
140-
return nil
141-
}
142-
143101
// rbacs required to enable SubjectAccessReview
144102
//+kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create
145103
//+kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=list
@@ -262,9 +220,6 @@ func (w *AppWrapperWebhook) validateAppWrapperUpdate(old *workloadv1beta2.AppWra
262220
if oldComponent.PodSets[psIdx].PodPath != newComponent.PodSets[psIdx].PodPath {
263221
allErrors = append(allErrors, field.Forbidden(compPath.Child("podsets").Index(psIdx).Child("podPath"), msg))
264222
}
265-
if oldComponent.PodSets[psIdx].ReplicaPath != newComponent.PodSets[psIdx].ReplicaPath {
266-
allErrors = append(allErrors, field.Forbidden(compPath.Child("podsets").Index(psIdx).Child("replciaPath"), msg))
267-
}
268223
}
269224
}
270225
}

samples/wrapped-deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ metadata:
77
spec:
88
components:
99
- podSets:
10-
- podPath: template.spec.template
11-
replicaPath: template.spec.replicas
10+
- replicas: 1
11+
podPath: template.spec.template
1212
template:
1313
apiVersion: apps/v1
1414
kind: Deployment

samples/wrapped-pytorch-job.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ metadata:
77
spec:
88
components:
99
- podSets:
10-
- podPath: template.spec.pytorchReplicaSpecs.Master.template
11-
replicaPath: template.spec.pytorchReplicaSpecs.Master.replicas
12-
- podPath: template.spec.pytorchReplicaSpecs.Worker.template
13-
replicaPath: template.spec.pytorchReplicaSpecs.Worker.replicas
10+
- replicas: 1
11+
podPath: template.spec.pytorchReplicaSpecs.Master.template
12+
- replicas: 1
13+
podPath: template.spec.pytorchReplicaSpecs.Worker.template
1414
template:
1515
apiVersion: "kubeflow.org/v1"
1616
kind: PyTorchJob

site/_pages/appwrapper.v1beta2.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,6 @@ arbitrary metadata about the Component to customize its treatment by the AppWrap
126126
<p>Replicas is the number of pods in this PodSet</p>
127127
</td>
128128
</tr>
129-
<tr><td><code>replicaPath</code><br/>
130-
<code>string</code>
131-
</td>
132-
<td>
133-
<p>ReplicaPath is the path within Component.Template to the replica count for this PodSet</p>
134-
</td>
135-
</tr>
136129
<tr><td><code>podPath</code> <B>[Required]</B><br/>
137130
<code>string</code>
138131
</td>

site/_pages/sample-pytorch.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ metadata:
1515
spec:
1616
components:
1717
- podSets:
18-
- podPath: template.spec.pytorchReplicaSpecs.Master.template
19-
replicaPath: template.spec.pytorchReplicaSpecs.Master.replicas
20-
- podPath: template.spec.pytorchReplicaSpecs.Worker.template
21-
replicaPath: template.spec.pytorchReplicaSpecs.Worker.replicas
18+
- replicas: 1
19+
podPath: template.spec.pytorchReplicaSpecs.Master.template
20+
- replicas: 1
21+
podPath: template.spec.pytorchReplicaSpecs.Worker.template
2222
template:
2323
apiVersion: "kubeflow.org/v1"
2424
kind: PyTorchJob

test/e2e/appwrapper_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ var _ = Describe("AppWrapper E2E Test", func() {
196196
Expect(updateAppWrapper(ctx, awName, func(aw *workloadv1beta2.AppWrapper) {
197197
aw.Spec.Components[0].PodSets[0].Replicas = ptr.To(int32(12))
198198
})).ShouldNot(Succeed())
199-
200-
Expect(updateAppWrapper(ctx, awName, func(aw *workloadv1beta2.AppWrapper) {
201-
aw.Spec.Components[0].PodSets[0].ReplicaPath = "bad"
202-
})).ShouldNot(Succeed())
203199
})
204200
})
205201

test/e2e/fixtures_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"k8s.io/apimachinery/pkg/api/resource"
2727
"k8s.io/apimachinery/pkg/runtime"
28+
"k8s.io/utils/ptr"
2829
"sigs.k8s.io/yaml"
2930

3031
workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
@@ -158,7 +159,7 @@ func deployment(replicaCount int, milliCPU int64) workloadv1beta2.AppWrapperComp
158159
jsonBytes, err := yaml.YAMLToJSON([]byte(yamlString))
159160
Expect(err).NotTo(HaveOccurred())
160161
return workloadv1beta2.AppWrapperComponent{
161-
PodSets: []workloadv1beta2.AppWrapperPodSet{{ReplicaPath: "template.spec.replicas", PodPath: "template.spec.template"}},
162+
PodSets: []workloadv1beta2.AppWrapperPodSet{{Replicas: ptr.To(int32(replicaCount)), PodPath: "template.spec.template"}},
162163
Template: runtime.RawExtension{Raw: jsonBytes},
163164
}
164165
}
@@ -198,7 +199,7 @@ func statefulset(replicaCount int, milliCPU int64) workloadv1beta2.AppWrapperCom
198199
jsonBytes, err := yaml.YAMLToJSON([]byte(yamlString))
199200
Expect(err).NotTo(HaveOccurred())
200201
return workloadv1beta2.AppWrapperComponent{
201-
PodSets: []workloadv1beta2.AppWrapperPodSet{{ReplicaPath: "template.spec.replicas", PodPath: "template.spec.template"}},
202+
PodSets: []workloadv1beta2.AppWrapperPodSet{{Replicas: ptr.To(int32(replicaCount)), PodPath: "template.spec.template"}},
202203
Template: runtime.RawExtension{Raw: jsonBytes},
203204
}
204205
}
@@ -334,7 +335,7 @@ func pytorchjob(replicasWorker int, milliCPUWorker int64) workloadv1beta2.AppWra
334335
Expect(err).NotTo(HaveOccurred())
335336
return workloadv1beta2.AppWrapperComponent{
336337
PodSets: []workloadv1beta2.AppWrapperPodSet{
337-
{ReplicaPath: "template.spec.pytorchReplicaSpecs.Worker.replicas", PodPath: "template.spec.pytorchReplicaSpecs.Worker.template"},
338+
{Replicas: ptr.To(int32(replicasWorker)), PodPath: "template.spec.pytorchReplicaSpecs.Worker.template"},
338339
},
339340
Template: runtime.RawExtension{Raw: jsonBytes},
340341
}
@@ -390,7 +391,7 @@ func jobSet(replicasWorker int, milliCPUWorker int64) workloadv1beta2.AppWrapper
390391
return workloadv1beta2.AppWrapperComponent{
391392
PodSets: []workloadv1beta2.AppWrapperPodSet{
392393
{PodPath: "template.spec.replicatedJobs[0].template.spec.template"},
393-
{ReplicaPath: "template.spec.replicatedJobs[1].template.spec.parallelism", PodPath: "template.spec.replicatedJobs[1].template.spec.template"},
394+
{Replicas: ptr.To(int32(replicasWorker)), PodPath: "template.spec.replicatedJobs[1].template.spec.template"},
394395
},
395396
Template: runtime.RawExtension{Raw: jsonBytes},
396397
}

0 commit comments

Comments
 (0)