@@ -31,40 +31,40 @@ import (
31
31
func (r * PyTorchJobReconciler ) ReconcileHPA (pytorhcjob * pytorchv1.PyTorchJob ) error {
32
32
logger := r .Log .WithValues (pytorchv1 .Singular , pytorhcjob .Name )
33
33
34
- if pytorhcjob .Spec .ElasticPolicy == nil {
35
- logger .V (1 ).Info ("No ElasicPolicy is specified, skipping HPA reconciling process" )
34
+ if pytorhcjob .Spec .ElasticPolicy == nil || pytorhcjob .Spec .ElasticPolicy .Metrics == nil {
35
+ logger .V (1 ).Info (
36
+ "No ElasicPolicy or Metric is specified, skipping HPA reconciling process" )
36
37
return nil
37
38
}
38
39
39
- // Create or update HPA
40
- hpa := & autoscalingv2beta2.HorizontalPodAutoscaler {}
41
- err := r .Get (context .TODO (), types.NamespacedName {Name : pytorhcjob .Name , Namespace : pytorhcjob .Namespace }, hpa )
40
+ current := & autoscalingv2beta2.HorizontalPodAutoscaler {}
41
+
42
+ // Get the exepected HPA.
43
+ expected , err := desiredHPA (pytorhcjob , r .Scheme )
42
44
if err != nil {
45
+ return err
46
+ }
47
+
48
+ if err := r .Get (context .TODO (), types.NamespacedName {
49
+ Name : pytorhcjob .Name ,
50
+ Namespace : pytorhcjob .Namespace ,
51
+ }, current ); err != nil {
43
52
if ! errors .IsNotFound (err ) {
44
53
return err
45
54
}
46
55
47
56
// Create the new HPA.
48
- hpa , err = desiredHPA (pytorhcjob , r .Scheme )
49
- if err != nil {
50
- return err
51
- }
52
- logger .V (1 ).Info ("Creating HPA" , "HPA.Namespace" , hpa .Namespace , "HPA.Name" , hpa .Name )
53
- err = r .Create (context .TODO (), hpa )
57
+ logger .V (1 ).Info ("Creating HPA" , "namespace" , expected .Namespace , "name" , expected .Name )
58
+ err = r .Create (context .TODO (), expected )
54
59
if err != nil {
55
60
return err
56
61
}
57
62
return nil
58
63
}
59
64
60
- // Update HPA
61
- expected , err := desiredHPA (pytorhcjob , r .Scheme )
62
- if err != nil {
63
- return err
64
- }
65
- if ! equality .Semantic .DeepEqual (expected .Spec , hpa .Spec ) {
66
- logger .V (1 ).Info ("Updating HPA" , "HPA.Namespace" , hpa .Namespace , "HPA.Name" , hpa .Name )
67
- expected .ResourceVersion = hpa .ResourceVersion
65
+ if ! equality .Semantic .DeepEqual (expected .Spec , current .Spec ) {
66
+ logger .V (1 ).Info ("Updating HPA" , "namespace" , current .Namespace , "name" , current .Name )
67
+ expected .ResourceVersion = current .ResourceVersion
68
68
err = r .Update (context .TODO (), expected )
69
69
if err != nil {
70
70
return err
0 commit comments