Skip to content

Commit

Permalink
feat(api): add remaining k8s resource endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-mccoy committed Jul 21, 2024
1 parent ef14348 commit 7fa24ee
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
35 changes: 35 additions & 0 deletions pkg/api/resources/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
autoscalingV2 "k8s.io/api/autoscaling/v2"
batchV1 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
networkingV1 "k8s.io/api/networking/v1"
storageV1 "k8s.io/api/storage/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -57,6 +59,17 @@ type Cache struct {
ValidatingWebhooks *ResourceList[*admissionRegV1.ValidatingWebhookConfiguration]
HPAs *ResourceList[*autoscalingV2.HorizontalPodAutoscaler]

// Network resources
Services *ResourceList[*v1.Service]
NetworkPolicies *ResourceList[*networkingV1.NetworkPolicy]
Endpoints *ResourceList[*v1.Endpoints]
VirtualServices *ResourceList[*unstructured.Unstructured]

// Storage resources
PersistentVolumes *ResourceList[*v1.PersistentVolume]
PersistentVolumeClaims *ResourceList[*v1.PersistentVolumeClaim]
StorageClasses *ResourceList[*storageV1.StorageClass]

// Metrics
PodMetrics *PodMetrics
MetricsChanges chan struct{}
Expand Down Expand Up @@ -87,6 +100,8 @@ func NewCache(ctx context.Context) (*Cache, error) {
c.bindUDSResources()
c.bindConfigResources()
c.bindClusterOpsResources()
c.bindNetworkResources()
c.bindStorageResources()

// start the informer
go c.factory.Start(c.stopper)
Expand Down Expand Up @@ -132,6 +147,26 @@ func (c *Cache) bindConfigResources() {
func (c *Cache) bindClusterOpsResources() {
c.MutatingWebhooks = NewResourceList[*admissionRegV1.MutatingWebhookConfiguration](c.factory.Admissionregistration().V1().MutatingWebhookConfigurations().Informer())
c.ValidatingWebhooks = NewResourceList[*admissionRegV1.ValidatingWebhookConfiguration](c.factory.Admissionregistration().V1().ValidatingWebhookConfigurations().Informer())
c.HPAs = NewResourceList[*autoscalingV2.HorizontalPodAutoscaler](c.factory.Autoscaling().V2().HorizontalPodAutoscalers().Informer())
}

func (c *Cache) bindNetworkResources() {
c.Services = NewResourceList[*v1.Service](c.factory.Core().V1().Services().Informer())
c.NetworkPolicies = NewResourceList[*networkingV1.NetworkPolicy](c.factory.Networking().V1().NetworkPolicies().Informer())
c.Endpoints = NewResourceList[*v1.Endpoints](c.factory.Core().V1().Endpoints().Informer())

// VirtualServices are not part of the core informer factory
c.VirtualServices = NewResourceList[*unstructured.Unstructured](c.dynamicFactory.ForResource(schema.GroupVersionResource{
Group: "networking.istio.io",
Version: "v1",
Resource: "virtualservices",
}).Informer())
}

func (c *Cache) bindStorageResources() {
c.PersistentVolumes = NewResourceList[*v1.PersistentVolume](c.factory.Core().V1().PersistentVolumes().Informer())
c.PersistentVolumeClaims = NewResourceList[*v1.PersistentVolumeClaim](c.factory.Core().V1().PersistentVolumeClaims().Informer())
c.StorageClasses = NewResourceList[*storageV1.StorageClass](c.factory.Storage().V1().StorageClasses().Informer())
}

func (c *Cache) bindUDSResources() {
Expand Down
15 changes: 12 additions & 3 deletions pkg/api/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,30 @@ func Start(assets embed.FS) error {
r.Route("/config", func(r chi.Router) {
r.Get("/uds-packages", sse.Bind(cache.UDSPackages))
r.Get("/uds-exemptions", sse.Bind(cache.UDSExemptions))
r.Get("/configmaps", sse.Bind(cache.Configmaps))
r.Get("/secrets", sse.Bind(cache.Secrets))
})

// Cluster ops resources
r.Route("/cluster-ops", func(r chi.Router) {

r.Get("/mutatingwebhooks", sse.Bind(cache.MutatingWebhooks))
r.Get("/validatingwebhooks", sse.Bind(cache.ValidatingWebhooks))
r.Get("/hpas", sse.Bind(cache.HPAs))
})

// Network resources
r.Route("/network", func(r chi.Router) {

r.Get("/services", sse.Bind(cache.Services))
r.Get("/networkpolicies", sse.Bind(cache.NetworkPolicies))
r.Get("/endpoints", sse.Bind(cache.Endpoints))
r.Get("/virtualservices", sse.Bind(cache.VirtualServices))
})

// Storage resources
r.Route("/storage", func(r chi.Router) {

r.Get("/persistentvolumes", sse.Bind(cache.PersistentVolumes))
r.Get("/persistentvolumeclaims", sse.Bind(cache.PersistentVolumeClaims))
r.Get("/storageclasses", sse.Bind(cache.StorageClasses))
})
})
})
Expand Down

0 comments on commit 7fa24ee

Please sign in to comment.