Skip to content

Commit ee76c2f

Browse files
mprahlopenshift-merge-bot[bot]
authored andcommitted
Delete unused code
Signed-off-by: mprahl <[email protected]>
1 parent 0a0193e commit ee76c2f

File tree

2 files changed

+0
-408
lines changed

2 files changed

+0
-408
lines changed

pkg/common/namespace_selection.go

-64
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1717
"k8s.io/apimachinery/pkg/labels"
1818
"k8s.io/apimachinery/pkg/types"
19-
"k8s.io/client-go/kubernetes"
2019
ctrl "sigs.k8s.io/controller-runtime"
2120
"sigs.k8s.io/controller-runtime/pkg/builder"
2221
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -29,8 +28,6 @@ import (
2928
policyv1 "open-cluster-management.io/config-policy-controller/api/v1"
3029
)
3130

32-
var log = ctrl.Log
33-
3431
// Parse *Target.MatchLabels and *Target.MatchExpressions into metav1.LabelSelector for the k8s API
3532
func parseToLabelSelector(selector policyv1.Target) metav1.LabelSelector {
3633
// Build LabelSelector from provided MatchLabels and MatchExpressions
@@ -58,67 +55,6 @@ func parseToLabelSelector(selector policyv1.Target) metav1.LabelSelector {
5855
return labelSelector
5956
}
6057

61-
// GetSelectedNamespaces returns the list of filtered namespaces according to the policy namespace selector.
62-
func GetSelectedNamespaces(client kubernetes.Interface, selector policyv1.Target) ([]string, error) {
63-
// Build LabelSelector from provided MatchLabels and MatchExpressions
64-
labelSelector := parseToLabelSelector(selector)
65-
66-
// get all namespaces matching selector
67-
allNamespaces, err := GetAllNamespaces(client, labelSelector)
68-
if err != nil {
69-
log.Error(err, "error retrieving namespaces")
70-
71-
return []string{}, err
72-
}
73-
74-
// filter the list based on the included/excluded list of patterns
75-
included := selector.Include
76-
excluded := selector.Exclude
77-
log.V(2).Info("Filtering namespace list using include/exclude lists", "include", included, "exclude", excluded)
78-
79-
finalList, err := Matches(allNamespaces, included, excluded)
80-
if err != nil {
81-
return []string{}, err
82-
}
83-
84-
if len(finalList) == 0 {
85-
log.V(2).Info("Filtered namespace list is empty.")
86-
}
87-
88-
log.V(2).Info("Returning final filtered namespace list", "namespaces", finalList)
89-
90-
return finalList, err
91-
}
92-
93-
// GetAllNamespaces gets the list of all namespaces from k8s that matches the input label selector.
94-
func GetAllNamespaces(client kubernetes.Interface, labelSelector metav1.LabelSelector) ([]string, error) {
95-
parsedSelector, err := metav1.LabelSelectorAsSelector(&labelSelector)
96-
if err != nil {
97-
return nil, fmt.Errorf("error parsing namespace LabelSelector: %w", err)
98-
}
99-
100-
listOpt := metav1.ListOptions{
101-
LabelSelector: parsedSelector.String(),
102-
}
103-
104-
log.V(2).Info("Retrieving namespaces with LabelSelector", "LabelSelector", parsedSelector.String())
105-
106-
nsList, err := client.CoreV1().Namespaces().List(context.TODO(), listOpt)
107-
if err != nil {
108-
log.Error(err, "could not list namespaces from the API server")
109-
110-
return nil, err
111-
}
112-
113-
var namespacesNames []string
114-
115-
for _, n := range nsList.Items {
116-
namespacesNames = append(namespacesNames, n.Name)
117-
}
118-
119-
return namespacesNames, nil
120-
}
121-
12258
// SelectorReconciler keeps a cache of NamespaceSelector results, which it should update when
12359
// namespaces are created, deleted, or re-labeled.
12460
type SelectorReconciler interface {

0 commit comments

Comments
 (0)