Skip to content
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

feat: Collect ResourceQuotas and LimitRanges #215

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions internal/services/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,26 @@ func getConditionalInformers(clientset kubernetes.Interface, cfg *config.Control
return f.Rbac().V1().ClusterRoleBindings().Informer()
},
},
{
groupVersion: corev1.SchemeGroupVersion,
resource: "limitranges",
kind: "LimitRange",
apiType: reflect.TypeOf(&corev1.LimitRange{}),
permissionVerbs: []string{"get", "list", "watch"},
informerFactory: func() cache.SharedIndexInformer {
return f.Core().V1().LimitRanges().Informer()
},
},
{
groupVersion: corev1.SchemeGroupVersion,
resource: "resourcequotas",
kind: "ResourceQuota",
apiType: reflect.TypeOf(&corev1.ResourceQuota{}),
permissionVerbs: []string{"get", "list", "watch"},
informerFactory: func() cache.SharedIndexInformer {
return f.Core().V1().ResourceQuotas().Informer()
},
},
}

for _, cmNamespace := range cfg.ConfigMapNamespaces {
Expand Down
57 changes: 54 additions & 3 deletions internal/services/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"go.uber.org/goleak"
authorizationv1 "k8s.io/api/authorization/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
policyv1 "k8s.io/api/policy/v1"
Expand Down Expand Up @@ -79,18 +80,18 @@ func TestController_ShouldReceiveDeltasBasedOnAvailableResources(t *testing.T) {
apiResourceError error
}{
"All supported objects are found and received in delta": {
expectedReceivedObjectsCount: 25,
expectedReceivedObjectsCount: 27,
},
"when fetching api resources produces multiple errors should exclude those resources": {
apiResourceError: fmt.Errorf("unable to retrieve the complete list of server APIs: %v:"+
"stale GroupVersion discovery: some error,%v: another error",
policyv1.SchemeGroupVersion.String(), storagev1.SchemeGroupVersion.String()),
expectedReceivedObjectsCount: 23,
expectedReceivedObjectsCount: 25,
},
"when fetching api resources produces single error should exclude that resource": {
apiResourceError: fmt.Errorf("unable to retrieve the complete list of server APIs: %v:"+
"stale GroupVersion discovery: some error", storagev1.SchemeGroupVersion.String()),
expectedReceivedObjectsCount: 24,
expectedReceivedObjectsCount: 26,
},
}

Expand Down Expand Up @@ -769,6 +770,30 @@ func loadInitialHappyPathData(t *testing.T, scheme *runtime.Scheme) ([]sampleObj
}
clusterRoleBindingData := asJson(t, clusterRoleBinding)

resourceQuota := &corev1.ResourceQuota{
TypeMeta: metav1.TypeMeta{
Kind: "ResourceQuota",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: v1.NamespaceDefault,
Name: "resourcequota",
},
}
resourceQuotasData := asJson(t, resourceQuota)

limitRange := &corev1.ResourceQuota{
TypeMeta: metav1.TypeMeta{
Kind: "LimitRange",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: v1.NamespaceDefault,
Name: "limitrange",
},
}
limitRangeData := asJson(t, limitRange)

clientset := fake.NewSimpleClientset(
node,
pod,
Expand All @@ -782,6 +807,8 @@ func loadInitialHappyPathData(t *testing.T, scheme *runtime.Scheme) ([]sampleObj
roleBinding,
clusterRole,
clusterRoleBinding,
resourceQuota,
limitRange,
)
runtimeObjects := []runtime.Object{
unstructuredFromJson(t, provisionersData),
Expand Down Expand Up @@ -836,6 +863,18 @@ func loadInitialHappyPathData(t *testing.T, scheme *runtime.Scheme) ([]sampleObj
Kind: "ConfigMap",
Verbs: []string{"get", "list", "watch"},
},
{
Group: "v1",
Name: "limitranges",
Kind: "LimitRange",
Verbs: []string{"get", "list", "watch"},
},
{
Group: "v1",
Name: "resourcequotas",
Kind: "ResourceQuota",
Verbs: []string{"get", "list", "watch"},
},
},
},
{
Expand Down Expand Up @@ -1169,6 +1208,18 @@ func loadInitialHappyPathData(t *testing.T, scheme *runtime.Scheme) ([]sampleObj
Resource: "clusterrolebindings",
Data: clusterRoleBindingData,
},
{
GV: corev1.SchemeGroupVersion,
Kind: "ResourceQuota",
Resource: "resourcequotas",
Data: resourceQuotasData,
},
{
GV: corev1.SchemeGroupVersion,
Kind: "LimitRange",
Resource: "limitranges",
Data: limitRangeData,
},
}
// There are a lot of manually entered samples. Running some sanity checks to ensure they don't contain basic errors.
verifySampleObjectsAreValid(t, objects)
Expand Down
Loading