Skip to content

Commit 2248b58

Browse files
committed
Remove unused code
1 parent de7798a commit 2248b58

File tree

2 files changed

+1
-387
lines changed

2 files changed

+1
-387
lines changed

pkg/k8sutil/patch_options.go

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -220,82 +220,3 @@ func cleanSecurityContext(container *corev1.Container) {
220220
// Capabilities are often modified by PSPs
221221
// container.SecurityContext.Capabilities = nil
222222
}
223-
224-
// IgnorePodResourcesIfAnnotated creates a CalculateOption that ignores pod resource
225-
// requests/limits if the pod has specific annotations indicating it's managed by
226-
// an external system (e.g., ScaleOps, VPA)
227-
func IgnorePodResourcesIfAnnotated() patch.CalculateOption {
228-
return func(current, modified []byte) ([]byte, []byte, error) {
229-
currentMap := map[string]interface{}{}
230-
if err := json.Unmarshal(current, &currentMap); err != nil {
231-
return current, modified, nil
232-
}
233-
234-
// Check if this pod should ignore resource diffs (e.g., via annotation)
235-
if shouldIgnoreResources(currentMap) {
236-
// Remove resources from comparison
237-
current = removeResourcesFromPod(current)
238-
modified = removeResourcesFromPod(modified)
239-
}
240-
241-
return current, modified, nil
242-
}
243-
}
244-
245-
func shouldIgnoreResources(podMap map[string]interface{}) bool {
246-
metadata, ok := podMap["metadata"].(map[string]interface{})
247-
if !ok {
248-
return false
249-
}
250-
251-
annotations, ok := metadata["annotations"].(map[string]interface{})
252-
if !ok {
253-
return false
254-
}
255-
256-
// Check for annotations that indicate external resource management
257-
annotationsToCheck := []string{
258-
"scaleops.sh/pod-owner-grouping",
259-
"vpa.k8s.io/updateMode",
260-
"cluster-autoscaler.kubernetes.io/safe-to-evict-local-volumes",
261-
}
262-
263-
for _, ann := range annotationsToCheck {
264-
if _, exists := annotations[ann]; exists {
265-
return true
266-
}
267-
}
268-
269-
return false
270-
}
271-
272-
func removeResourcesFromPod(podBytes []byte) []byte {
273-
podMap := map[string]interface{}{}
274-
if err := json.Unmarshal(podBytes, &podMap); err != nil {
275-
return podBytes
276-
}
277-
278-
if spec, ok := podMap["spec"].(map[string]interface{}); ok {
279-
// Remove resources from all containers
280-
if containers, ok := spec["containers"].([]interface{}); ok {
281-
for _, c := range containers {
282-
if container, ok := c.(map[string]interface{}); ok {
283-
delete(container, "resources")
284-
}
285-
}
286-
}
287-
if initContainers, ok := spec["initContainers"].([]interface{}); ok {
288-
for _, c := range initContainers {
289-
if container, ok := c.(map[string]interface{}); ok {
290-
delete(container, "resources")
291-
}
292-
}
293-
}
294-
}
295-
296-
result, err := json.Marshal(podMap)
297-
if err != nil {
298-
return podBytes
299-
}
300-
return result
301-
}

0 commit comments

Comments
 (0)