Plugins: Support MT app registration (#113348)

This commit is contained in:
Todd Treece
2025-12-02 09:59:46 -05:00
committed by GitHub
parent 77e13f7ef8
commit bdf529c545
22 changed files with 385 additions and 240 deletions
@@ -1,20 +1,29 @@
package client
import (
"context"
"fmt"
"strings"
"time"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
)
var (
defaultPollInterval = 500 * time.Millisecond
defaultAvailabilityTimeout = 30 * time.Second
)
type DiscoveryClient interface {
discovery.DiscoveryInterface
GetResourceForKind(gvk schema.GroupVersionKind) (schema.GroupVersionResource, error)
GetKindForResource(gvr schema.GroupVersionResource) (schema.GroupVersionKind, error)
GetPreferredVesion(gr schema.GroupResource) (schema.GroupVersionResource, schema.GroupVersionKind, error)
GetPreferredVersionForKind(gk schema.GroupKind) (schema.GroupVersionResource, schema.GroupVersionKind, error)
WaitForAvailability(ctx context.Context, gv schema.GroupVersion) error
}
type DiscoveryClientImpl struct {
@@ -134,3 +143,13 @@ func (d *DiscoveryClientImpl) GetPreferredVersionForKind(gk schema.GroupKind) (s
}
return schema.GroupVersionResource{}, schema.GroupVersionKind{}, fmt.Errorf("preferred version not found for kind %s in group %s", gk.Kind, gk.Group)
}
func (d *DiscoveryClientImpl) WaitForAvailability(ctx context.Context, gv schema.GroupVersion) error {
return wait.PollUntilContextTimeout(ctx, defaultPollInterval, defaultAvailabilityTimeout, true, func(ctx context.Context) (bool, error) {
_, err := d.ServerResourcesForGroupVersion(gv.String())
if err != nil {
return false, nil
}
return true, nil
})
}