-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VPA] Add subresource status for vpa with e2e fix #5766
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -360,6 +360,23 @@ func InstallVPA(f *framework.Framework, vpa *vpa_types.VerticalPodAutoscaler) { | |
vpaClientSet := getVpaClientSet(f) | ||
_, err := vpaClientSet.AutoscalingV1beta2().VerticalPodAutoscalers(f.Namespace.Name).Create(context.TODO(), vpa, metav1.CreateOptions{}) | ||
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "unexpected error creating VPA") | ||
// apiserver ignore status in vpa create, so need to update status | ||
if !isStatusEmpty(&vpa.Status) { | ||
if vpa.Status.Recommendation != nil { | ||
PatchVpaRecommendation(f, vpa, vpa.Status.Recommendation) | ||
} | ||
} | ||
wu0407 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+363
to
+368
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment is needed in InstallVPA that create vpa with status need individual update status, so isStatusEmpty needs to be preserved, and the code may appear a bit redundant |
||
} | ||
|
||
func isStatusEmpty(status *vpa_types.VerticalPodAutoscalerStatus) bool { | ||
if status == nil { | ||
return true | ||
} | ||
|
||
if len(status.Conditions) == 0 && status.Recommendation == nil { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// InstallRawVPA installs a VPA object passed in as raw json in the test cluster. | ||
|
@@ -384,7 +401,7 @@ func PatchVpaRecommendation(f *framework.Framework, vpa *vpa_types.VerticalPodAu | |
Value: *newStatus, | ||
}}) | ||
gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||
_, err = getVpaClientSet(f).AutoscalingV1beta2().VerticalPodAutoscalers(f.Namespace.Name).Patch(context.TODO(), vpa.Name, types.JSONPatchType, bytes, metav1.PatchOptions{}) | ||
_, err = getVpaClientSet(f).AutoscalingV1beta2().VerticalPodAutoscalers(f.Namespace.Name).Patch(context.TODO(), vpa.Name, types.JSONPatchType, bytes, metav1.PatchOptions{}, "status") | ||
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to patch VPA.") | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -49,14 +49,14 @@ type patchRecord struct { | |||||||||||||||||||
Value interface{} `json:"value"` | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func patchVpa(vpaClient vpa_api.VerticalPodAutoscalerInterface, vpaName string, patches []patchRecord) (result *vpa_types.VerticalPodAutoscaler, err error) { | ||||||||||||||||||||
func patchVpaStatus(vpaClient vpa_api.VerticalPodAutoscalerInterface, vpaName string, patches []patchRecord) (result *vpa_types.VerticalPodAutoscaler, err error) { | ||||||||||||||||||||
bytes, err := json.Marshal(patches) | ||||||||||||||||||||
if err != nil { | ||||||||||||||||||||
klog.Errorf("Cannot marshal VPA status patches %+v. Reason: %+v", patches, err) | ||||||||||||||||||||
return | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
return vpaClient.Patch(context.TODO(), vpaName, types.JSONPatchType, bytes, meta.PatchOptions{}) | ||||||||||||||||||||
return vpaClient.Patch(context.TODO(), vpaName, types.JSONPatchType, bytes, meta.PatchOptions{}, "status") | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a unit test we can add to cover this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is already have test case on autoscaler/vertical-pod-autoscaler/pkg/utils/vpa/api_test.go Lines 93 to 101 in 1384c8b
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, makes sense. |
||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
// UpdateVpaStatusIfNeeded updates the status field of the VPA API object. | ||||||||||||||||||||
|
@@ -69,7 +69,7 @@ func UpdateVpaStatusIfNeeded(vpaClient vpa_api.VerticalPodAutoscalerInterface, v | |||||||||||||||||||
}} | ||||||||||||||||||||
|
||||||||||||||||||||
if !apiequality.Semantic.DeepEqual(*oldStatus, *newStatus) { | ||||||||||||||||||||
return patchVpa(vpaClient, vpaName, patches) | ||||||||||||||||||||
return patchVpaStatus(vpaClient, vpaName, patches) | ||||||||||||||||||||
} | ||||||||||||||||||||
return nil, nil | ||||||||||||||||||||
} | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd write this as one condition: