Skip to content

Commit

Permalink
fix ingress flag as used (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonahd committed Nov 29, 2023
1 parent 7f0367f commit a459be1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/kor/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
corev1 "k8s.io/api/core/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -35,7 +35,7 @@ func DeleteResourceCmd() map[string]func(clientset kubernetes.Interface, namespa
return clientset.AutoscalingV1().HorizontalPodAutoscalers(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
},
"Ingress": func(clientset kubernetes.Interface, namespace, name string) error {
return clientset.NetworkingV1beta1().Ingresses(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
return clientset.NetworkingV1().Ingresses(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
},
"PDB": func(clientset kubernetes.Interface, namespace, name string) error {
return clientset.PolicyV1beta1().PodDisruptionBudgets(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
Expand Down Expand Up @@ -95,7 +95,7 @@ func updateResource(clientset kubernetes.Interface, namespace, resourceType stri
case "HPA":
return clientset.AutoscalingV1().HorizontalPodAutoscalers(namespace).Update(context.TODO(), resource.(*autoscalingv1.HorizontalPodAutoscaler), metav1.UpdateOptions{})
case "Ingress":
return clientset.NetworkingV1beta1().Ingresses(namespace).Update(context.TODO(), resource.(*networkingv1beta1.Ingress), metav1.UpdateOptions{})
return clientset.NetworkingV1().Ingresses(namespace).Update(context.TODO(), resource.(*networkingv1.Ingress), metav1.UpdateOptions{})
case "PDB":
return clientset.PolicyV1beta1().PodDisruptionBudgets(namespace).Update(context.TODO(), resource.(*policyv1beta1.PodDisruptionBudget), metav1.UpdateOptions{})
case "Roles":
Expand Down Expand Up @@ -125,7 +125,7 @@ func getResource(clientset kubernetes.Interface, namespace, resourceType, resour
case "HPA":
return clientset.AutoscalingV1().HorizontalPodAutoscalers(namespace).Get(context.TODO(), resourceName, metav1.GetOptions{})
case "Ingress":
return clientset.NetworkingV1beta1().Ingresses(namespace).Get(context.TODO(), resourceName, metav1.GetOptions{})
return clientset.NetworkingV1().Ingresses(namespace).Get(context.TODO(), resourceName, metav1.GetOptions{})
case "PDB":
return clientset.PolicyV1beta1().PodDisruptionBudgets(namespace).Get(context.TODO(), resourceName, metav1.GetOptions{})
case "Roles":
Expand Down
7 changes: 3 additions & 4 deletions pkg/kor/ingresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ func retrieveUsedIngress(clientset kubernetes.Interface, namespace string, filte
usedIngresses := []string{}

for _, ingress := range ingresses.Items {
if ingress.Labels["kor/used"] == "true" {
continue
}

// checks if the resource has any labels that match the excluded selector specified in opts.ExcludeLabels.
// If it does, the resource is skipped.
if excluded, _ := HasExcludedLabel(ingress.Labels, filterOpts.ExcludeLabels); excluded {
Expand Down Expand Up @@ -83,6 +79,9 @@ func retrieveIngressNames(clientset kubernetes.Interface, namespace string) ([]s
}
names := make([]string, 0, len(ingresses.Items))
for _, ingress := range ingresses.Items {
if ingress.Labels["kor/used"] == "true" {
continue
}
names = append(names, ingress.Name)
}
return names, nil
Expand Down

0 comments on commit a459be1

Please sign in to comment.