diff --git a/Makefile b/Makefile index dc7b64448..d29af690b 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ local: env bash -c 'source local.env; go run ./cmd/api' debug: - env bash -c 'source local.env; dlv debug --headless --listen=:2345 --api-version=2 ./cmd/api + env bash -c 'source local.env; dlv debug --headless --listen=:2345 --api-version=2 ./cmd/api' test: go test -cover --race ./... diff --git a/internal/k8s/fake/fake.go b/internal/k8s/fake/fake.go index a49afecea..a5966ae31 100644 --- a/internal/k8s/fake/fake.go +++ b/internal/k8s/fake/fake.go @@ -170,7 +170,6 @@ func parseResources(scheme *runtime.Scheme, dir fs.FS, path string) clusterResou // This is a hack around how k8s unsafeGuesses resource plurals func depluralized(s string) string { - fmt.Println(s) switch s { case "unleashs": return "unleashes" diff --git a/internal/unleash/unleash.go b/internal/unleash/unleash.go index da24ca74a..bf9795c84 100644 --- a/internal/unleash/unleash.go +++ b/internal/unleash/unleash.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" "time" "github.com/nais/api/internal/k8s" @@ -14,7 +13,6 @@ import ( "github.com/sirupsen/logrus" "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/discovery" "k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic/dynamicinformer" "k8s.io/client-go/informers" @@ -183,19 +181,17 @@ func createClient(apiServer, clusterName string, resources []schema.GroupVersion return &k8sClient{ clientSet: clientSet, dynamicClient: dynamicClient, - informers: createInformers(clientSet, dynamicClient, resources), + informers: createInformers(dynamicClient, resources), }, nil } // @TODO: use namespace from config -func createInformers(clientSet kubernetes.Interface, dynamicClient dynamic.Interface, resources []schema.GroupVersionResource) []informers.GenericInformer { +func createInformers(dynamicClient dynamic.Interface, resources []schema.GroupVersionResource) []informers.GenericInformer { dinf := dynamicinformer.NewFilteredDynamicSharedInformerFactory(dynamicClient, 4*time.Hour, "bifrost-unleash", nil) infs := make([]informers.GenericInformer, 0) for _, resources := range resources { - if supportsResource(clientSet, resources) { - infs = append(infs, dinf.ForResource(resources)) - } + infs = append(infs, dinf.ForResource(resources)) } return infs } @@ -213,22 +209,3 @@ func hasSynced(ctx context.Context, cluster string, informer informers.GenericIn } return nil } - -func supportsResource(clientSet kubernetes.Interface, resource schema.GroupVersionResource) bool { - if clientSet, ok := clientSet.(*kubernetes.Clientset); ok { - resources, err := discovery.NewDiscoveryClient(clientSet.RESTClient()).ServerResourcesForGroupVersion(resource.GroupVersion().String()) - if err != nil && !strings.Contains(err.Error(), "the server could not find the requested resource") { - logrus.Warnf("get server resources for group version: %v", err) - return false - } - if err == nil { - for _, r := range resources.APIResources { - if r.Name == resource.Resource { - return true - } - } - } - } - logrus.Warnf("resource %s not supported", resource.String()) - return false -}