-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor dynamic client creation and add testing ones
- Loading branch information
Showing
3 changed files
with
50 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
pkg/operator/genericoperatorclient/test_operator_client.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package genericoperatorclient | ||
|
||
import ( | ||
"github.com/openshift/library-go/pkg/operator/v1helpers" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/dynamic" | ||
"k8s.io/client-go/dynamic/dynamicinformer" | ||
"k8s.io/client-go/rest" | ||
"net/http" | ||
) | ||
|
||
func NewOperatorClientWithClient(httpClient *http.Client, gvr schema.GroupVersionResource, gvk schema.GroupVersionKind, extractApplySpec OperatorSpecExtractorFunc, extractApplyStatus OperatorStatusExtractorFunc) (v1helpers.OperatorClientWithFinalizers, dynamicinformer.DynamicSharedInformerFactory, error) { | ||
return NewOperatorClientWithConfigNameWithClient(httpClient, gvr, gvk, defaultConfigName, extractApplySpec, extractApplyStatus) | ||
|
||
} | ||
|
||
func NewOperatorClientWithConfigNameWithClient(httpClient *http.Client, gvr schema.GroupVersionResource, gvk schema.GroupVersionKind, configName string, extractApplySpec OperatorSpecExtractorFunc, extractApplyStatus OperatorStatusExtractorFunc) (v1helpers.OperatorClientWithFinalizers, dynamicinformer.DynamicSharedInformerFactory, error) { | ||
dynamicClient, err := dynamic.NewForConfigAndClient(&rest.Config{}, httpClient) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return newClusterScopedOperatorClient(dynamicClient, gvr, gvk, configName, | ||
convertOperatorSpecToStaticPodOperatorSpec(extractApplySpec), convertOperatorStatusToStaticPodOperatorStatus(extractApplyStatus)) | ||
} | ||
|
||
func NewStaticPodOperatorClientWithConfigNameWithClient(httpClient *http.Client, gvr schema.GroupVersionResource, gvk schema.GroupVersionKind, configName string, extractApplySpec OperatorSpecExtractorFunc, extractApplyStatus OperatorStatusExtractorFunc) (v1helpers.StaticPodOperatorClient, dynamicinformer.DynamicSharedInformerFactory, error) { | ||
dynamicClient, err := dynamic.NewForConfigAndClient(&rest.Config{}, httpClient) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return newClusterScopedOperatorClient(dynamicClient, gvr, gvk, configName, | ||
convertOperatorSpecToStaticPodOperatorSpec(extractApplySpec), convertOperatorStatusToStaticPodOperatorStatus(extractApplyStatus)) | ||
} |