Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Changed

- All the modules in [`pkg/sdk`](https://github.com/operator-framework/operator-sdk/tree/master/pkg/sdk) have been combined into a single package. `action`, `handler`, `informer` `types` and `query` pkgs have been consolidated into `pkg/sdk`. [#242](https://github.com/operator-framework/operator-sdk/pull/242)
- The SDK exposes the Kubernetes clientset via `k8sclient.GetKubeClient()` #295

### Removed

Expand Down
9 changes: 8 additions & 1 deletion pkg/k8sclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ import (
var (
restMapper *discovery.DeferredDiscoveryRESTMapper
clientPool dynamic.ClientPool
kubeClient kubernetes.Interface
kubeConfig *rest.Config
)

// init initializes the restMapper and clientPool needed to create a resource client dynamically
func init() {
kubeClient, kubeConfig := mustNewKubeClientAndConfig()
kubeClient, kubeConfig = mustNewKubeClientAndConfig()
cachedDiscoveryClient := cached.NewMemCacheClient(kubeClient.Discovery())
restMapper = discovery.NewDeferredDiscoveryRESTMapper(cachedDiscoveryClient, meta.InterfacesForUnstructured)
restMapper.Reset()
Expand Down Expand Up @@ -74,6 +76,11 @@ func GetResourceClient(apiVersion, kind, namespace string) (dynamic.ResourceInte
return resourceClient, pluralName, nil
}

// GetKubeClient returns the kubernetes client used to create the dynamic client
func GetKubeClient() kubernetes.Interface {
return kubeClient
}

// apiResource consults the REST mapper to translate an <apiVersion, kind, namespace> tuple to a metav1.APIResource struct.
func apiResource(gvk schema.GroupVersionKind, restMapper *discovery.DeferredDiscoveryRESTMapper) (*metav1.APIResource, error) {
mapping, err := restMapper.RESTMapping(gvk.GroupKind(), gvk.Version)
Expand Down