Skip to content

Commit

Permalink
docs: add comments describing newly added functions
Browse files Browse the repository at this point in the history
Signed-off-by: vadasambar <surajrbanakar@gmail.com>
  • Loading branch information
vadasambar committed Jul 12, 2023
1 parent e24784d commit c22d0f1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cluster-autoscaler/utils/test/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func basePod(name string) *apiv1.Pod {
return pod
}

// WithCPU adds requests.cpu (unit: number of CPUs) to all containers in the pod
func WithCPU(cpu int64) func(*apiv1.Pod) {
return func(pod *apiv1.Pod) {

Expand All @@ -68,6 +69,7 @@ func WithCPU(cpu int64) func(*apiv1.Pod) {
}
}

// WithMilliCPU adds requests.cpu (unit: number of milli CPUs) to all containers in the pod
func WithMilliCPU(cpu int64) func(*apiv1.Pod) {
return func(pod *apiv1.Pod) {

Expand All @@ -77,6 +79,7 @@ func WithMilliCPU(cpu int64) func(*apiv1.Pod) {
}
}

// WithMemory adds requests.memory to all the containers in the pod
func WithMemory(mem int64) func(*apiv1.Pod) {

return func(pod *apiv1.Pod) {
Expand All @@ -87,6 +90,8 @@ func WithMemory(mem int64) func(*apiv1.Pod) {
}
}

// WithGPU adds requests.nvidia.com/gpu and limits.nvidia.com/gpu
// to all the containers in the pod
func WithGPU(gpusCount int64) func(*apiv1.Pod) {

return func(pod *apiv1.Pod) {
Expand All @@ -98,13 +103,16 @@ func WithGPU(gpusCount int64) func(*apiv1.Pod) {
}
}

// WithGPUToleration adds nvidia.com/gpu:Exists toleration to the pod
func WithGPUToleration() func(*apiv1.Pod) {

return func(pod *apiv1.Pod) {
pod.Spec.Tolerations = append(pod.Spec.Tolerations, apiv1.Toleration{Key: resourceNvidiaGPU, Operator: apiv1.TolerationOpExists})
}
}

// WithAnnotations adds annotations to the pods
// note: if a key already exists, it will be overwritten
func WithAnnotations(anns map[string]string) func(*apiv1.Pod) {

return func(pod *apiv1.Pod) {
Expand All @@ -115,13 +123,15 @@ func WithAnnotations(anns map[string]string) func(*apiv1.Pod) {
}
}

// WithOwnerRef adds owner ref to pod
func WithOwnerRef(ownerRefs []metav1.OwnerReference) func(*apiv1.Pod) {

return func(pod *apiv1.Pod) {
pod.OwnerReferences = append(pod.OwnerReferences, ownerRefs...)
}
}

// WithEphemeralStorage adds requests.ephemeral-storage to all the containers in the pod
func WithEphemeralStorage(ephemeralStorage int64) func(*apiv1.Pod) {

return func(pod *apiv1.Pod) {
Expand All @@ -131,41 +141,47 @@ func WithEphemeralStorage(ephemeralStorage int64) func(*apiv1.Pod) {
}
}

// ScheduledOnNode sets pod's spec.nodeName
func ScheduledOnNode(nodeName string) func(*apiv1.Pod) {

return func(pod *apiv1.Pod) {
pod.Spec.NodeName = nodeName
}
}

// WithStaticPodAnnotation adds 'kubernetes.io/config.source: file' annotation to the pod
func WithStaticPodAnnotation() func(*apiv1.Pod) {

return func(pod *apiv1.Pod) {
pod.Annotations[kube_types.ConfigSourceAnnotationKey] = kube_types.FileSource
}
}

// AsDaemonSetPod adds daemonset owner ref to the pod
func AsDaemonSetPod(uid string) func(*apiv1.Pod) {

return func(pod *apiv1.Pod) {
pod.OwnerReferences = GenerateOwnerReferences("ds", "DaemonSet", "apps/v1", types.UID(uid))
}
}

// AsReplicaSetPod adds replicaset owner ref to the pod
func AsReplicaSetPod(uid string, rsName string) func(*apiv1.Pod) {

return func(pod *apiv1.Pod) {
pod.OwnerReferences = GenerateOwnerReferences(rsName, "ReplicaSet", "extensions/v1beta1", types.UID(uid))
}
}

// WithMirrorPodAnnotation adds 'kubernetes.io/config.mirror: mirror' annotation to the pod
func WithMirrorPodAnnotation(uid string) func(*apiv1.Pod) {

return func(pod *apiv1.Pod) {
pod.ObjectMeta.Annotations[kube_types.ConfigMirrorAnnotationKey] = "mirror"
}
}

// NewTestPod creates pod with options passed as functions
func NewTestPod(name string, options ...func(*apiv1.Pod)) *apiv1.Pod {
pod := basePod(name)

Expand Down

0 comments on commit c22d0f1

Please sign in to comment.