Skip to content

Commit 9ab2000

Browse files
committed
temp
Signed-off-by: Kyori Sakao <[email protected]>
1 parent c9de8c9 commit 9ab2000

File tree

6 files changed

+177
-0
lines changed

6 files changed

+177
-0
lines changed

api/pie/v1alpha1/pieprobe_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ type PieProbeSpec struct {
4242
//+kubebuilder:validation:Optional
4343
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="disableMountProbes is immutable"
4444
DisableMountProbes bool `json:"disableMountProbes"`
45+
46+
//+kubebuilder:validation:Optional
47+
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
4548
}
4649

4750
// PieProbeStatus defines the observed state of PieProbe

api/pie/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/pie/templates/pie.topolvm.io_pieprobes.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,65 @@ spec:
165165
x-kubernetes-validations:
166166
- message: pvcCapacity is immutable
167167
rule: self == oldSelf
168+
resources:
169+
description: ResourceRequirements describes the compute resource requirements.
170+
properties:
171+
claims:
172+
description: |-
173+
Claims lists the names of resources, defined in spec.resourceClaims,
174+
that are used by this container.
175+
176+
This is an alpha field and requires enabling the
177+
DynamicResourceAllocation feature gate.
178+
179+
This field is immutable. It can only be set for containers.
180+
items:
181+
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
182+
properties:
183+
name:
184+
description: |-
185+
Name must match the name of one entry in pod.spec.resourceClaims of
186+
the Pod where this field is used. It makes that resource available
187+
inside a container.
188+
type: string
189+
request:
190+
description: |-
191+
Request is the name chosen for a request in the referenced claim.
192+
If empty, everything from the claim is made available, otherwise
193+
only the result of this request.
194+
type: string
195+
required:
196+
- name
197+
type: object
198+
type: array
199+
x-kubernetes-list-map-keys:
200+
- name
201+
x-kubernetes-list-type: map
202+
limits:
203+
additionalProperties:
204+
anyOf:
205+
- type: integer
206+
- type: string
207+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
208+
x-kubernetes-int-or-string: true
209+
description: |-
210+
Limits describes the maximum amount of compute resources allowed.
211+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
212+
type: object
213+
requests:
214+
additionalProperties:
215+
anyOf:
216+
- type: integer
217+
- type: string
218+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
219+
x-kubernetes-int-or-string: true
220+
description: |-
221+
Requests describes the minimum amount of compute resources required.
222+
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
223+
otherwise to an implementation-defined value. Requests cannot exceed Limits.
224+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
225+
type: object
226+
type: object
168227
required:
169228
- monitoringStorageClass
170229
- nodeSelector

config/crd/bases/pie.topolvm.io_pieprobes.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,65 @@ spec:
165165
x-kubernetes-validations:
166166
- message: pvcCapacity is immutable
167167
rule: self == oldSelf
168+
resources:
169+
description: ResourceRequirements describes the compute resource requirements.
170+
properties:
171+
claims:
172+
description: |-
173+
Claims lists the names of resources, defined in spec.resourceClaims,
174+
that are used by this container.
175+
176+
This is an alpha field and requires enabling the
177+
DynamicResourceAllocation feature gate.
178+
179+
This field is immutable. It can only be set for containers.
180+
items:
181+
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
182+
properties:
183+
name:
184+
description: |-
185+
Name must match the name of one entry in pod.spec.resourceClaims of
186+
the Pod where this field is used. It makes that resource available
187+
inside a container.
188+
type: string
189+
request:
190+
description: |-
191+
Request is the name chosen for a request in the referenced claim.
192+
If empty, everything from the claim is made available, otherwise
193+
only the result of this request.
194+
type: string
195+
required:
196+
- name
197+
type: object
198+
type: array
199+
x-kubernetes-list-map-keys:
200+
- name
201+
x-kubernetes-list-type: map
202+
limits:
203+
additionalProperties:
204+
anyOf:
205+
- type: integer
206+
- type: string
207+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
208+
x-kubernetes-int-or-string: true
209+
description: |-
210+
Limits describes the maximum amount of compute resources allowed.
211+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
212+
type: object
213+
requests:
214+
additionalProperties:
215+
anyOf:
216+
- type: integer
217+
- type: string
218+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
219+
x-kubernetes-int-or-string: true
220+
description: |-
221+
Requests describes the minimum amount of compute resources required.
222+
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
223+
otherwise to an implementation-defined value. Requests cannot exceed Limits.
224+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
225+
type: object
226+
type: object
168227
required:
169228
- monitoringStorageClass
170229
- nodeSelector

internal/controller/pie/pieprobe_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ func (r *PieProbeReconciler) createOrUpdateJob(
392392
container := &cronjob.Spec.JobTemplate.Spec.Template.Spec.Containers[0]
393393
container.Name = constants.ProbeContainerName
394394
container.Image = r.containerImage
395+
container.Resources = pieProbe.Spec.Resources
395396

396397
var userID int64 = 1001
397398
var groupID int64 = 1001

internal/controller/pie/pieprobe_controller_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,60 @@ var _ = Describe("PieProbe controller", func() {
283283
deletePieProbeAndReferencingResources(ctx, pieProbe2)
284284
})
285285

286+
It("should create CronJob with the resource specified in the PieProbe resource", func() {
287+
By("checking the default CronJob's resource dose not exist")
288+
Eventually(func(g Gomega) {
289+
var cronjobList batchv1.CronJobList
290+
err := k8sClient.List(context.Background(), &cronjobList, client.MatchingLabels(map[string]string{
291+
"storage-class": "sc",
292+
}))
293+
g.Expect(err).NotTo(HaveOccurred())
294+
g.Expect(cronjobList.Items).To(HaveLen(3))
295+
296+
cronjob := cronjobList.Items[0]
297+
resources := cronjob.Spec.JobTemplate.Spec.Template.Spec.Resources
298+
g.Expect(resources).To(BeNil())
299+
}).Should(Succeed())
300+
301+
By("creating a new CronJob via PieProbe with .spec.resources")
302+
pieProbe2 := &piev1alpha1.PieProbe{
303+
ObjectMeta: metav1.ObjectMeta{
304+
Namespace: "default",
305+
Name: "pie-probe-sc2",
306+
},
307+
Spec: piev1alpha1.PieProbeSpec{
308+
MonitoringStorageClass: "sc2",
309+
NodeSelector: nodeSelector,
310+
ProbePeriod: 1,
311+
Resources: corev1.ResourceRequirements{
312+
Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m")},
313+
Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("50m")},
314+
},
315+
},
316+
}
317+
_, err := ctrl.CreateOrUpdate(ctx, k8sClient, pieProbe2, func() error { return nil })
318+
Expect(err).NotTo(HaveOccurred())
319+
320+
By("checking the CronJob's resource specified")
321+
Eventually(func(g Gomega) {
322+
var cronjobList batchv1.CronJobList
323+
err := k8sClient.List(context.Background(), &cronjobList, client.MatchingLabels(map[string]string{
324+
"storage-class": "sc2",
325+
}))
326+
g.Expect(err).NotTo(HaveOccurred())
327+
g.Expect(cronjobList.Items).To(HaveLen(3))
328+
329+
cronjob := cronjobList.Items[0]
330+
resources := cronjob.Spec.JobTemplate.Spec.Template.Spec.Resources
331+
332+
g.Expect(resources.Limits).To(Equal(corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m")}))
333+
g.Expect(resources.Requests).To(Equal(corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("50m")}))
334+
}).Should(Succeed())
335+
336+
By("cleaning up PVCs and CronJobs for sc2")
337+
deletePieProbeAndReferencingResources(ctx, pieProbe2)
338+
})
339+
286340
It("should create only mount probes if .spec.disableProvisionProbes is true", func() {
287341
By("creating a new PieProbe with .spec.disableProvisionProbes true")
288342
pieProbe2 := &piev1alpha1.PieProbe{

0 commit comments

Comments
 (0)