Skip to content

Commit 2217b6b

Browse files
committed
ToSquash: Add integration test for NewAlertGetter
1 parent 69c8baf commit 2217b6b

5 files changed

Lines changed: 128 additions & 7 deletions

File tree

pkg/alert/alerts.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"k8s.io/client-go/rest"
1111

1212
routev1 "github.com/openshift/api/route/v1"
13+
routeclientset "github.com/openshift/client-go/route/clientset/versioned"
1314
routev1client "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
1415
)
1516

@@ -51,14 +52,13 @@ type Getter interface {
5152
Get(ctx context.Context) (*DataAndStatus, error)
5253
}
5354

54-
func NewAlertGetterOrDie(c *rest.Config) Getter {
55-
client := routev1client.NewForConfigOrDie(c)
56-
return &ocAlertGetter{config: c, routeClient: client}
55+
func NewAlertGetter(c *rest.Config, routeClient routeclientset.Interface) Getter {
56+
return &ocAlertGetter{config: c, routesGetter: routeClient.RouteV1()}
5757
}
5858

5959
type ocAlertGetter struct {
60-
config *rest.Config
61-
routeClient *routev1client.RouteV1Client
60+
config *rest.Config
61+
routesGetter routev1client.RoutesGetter
6262
}
6363

6464
func (o *ocAlertGetter) Get(ctx context.Context) (*DataAndStatus, error) {
@@ -68,7 +68,7 @@ func (o *ocAlertGetter) Get(ctx context.Context) (*DataAndStatus, error) {
6868
}
6969

7070
routeGetter := func(ctx context.Context, namespace string, name string, opts metav1.GetOptions) (*routev1.Route, error) {
71-
return o.routeClient.Routes(namespace).Get(ctx, name, opts)
71+
return o.routesGetter.Routes(namespace).Get(ctx, name, opts)
7272
}
7373
alertsBytes, err := GetAlerts(ctx, roundTripper, routeGetter)
7474
if err != nil {

pkg/start/start.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
configinformers "github.com/openshift/client-go/config/informers/externalversions"
3838
operatorclientset "github.com/openshift/client-go/operator/clientset/versioned"
3939
operatorinformers "github.com/openshift/client-go/operator/informers/externalversions"
40+
routeclientset "github.com/openshift/client-go/route/clientset/versioned"
4041
"github.com/openshift/library-go/pkg/config/clusterstatus"
4142
libgoleaderelection "github.com/openshift/library-go/pkg/config/leaderelection"
4243

@@ -506,6 +507,10 @@ func (cb *ClientBuilder) OperatorClientOrDie(name string, configFns ...func(*res
506507
return operatorclientset.NewForConfigOrDie(rest.AddUserAgent(cb.RestConfig(configFns...), name))
507508
}
508509

510+
func (cb *ClientBuilder) RouteClientOrDie(name string, configFns ...func(*rest.Config)) routeclientset.Interface {
511+
return routeclientset.NewForConfigOrDie(rest.AddUserAgent(cb.RestConfig(configFns...), name))
512+
}
513+
509514
func newClientBuilder(kubeconfig string) (*ClientBuilder, error) {
510515
clientCfg := clientcmd.NewDefaultClientConfigLoadingRules()
511516
clientCfg.ExplicitPath = kubeconfig
@@ -603,6 +608,8 @@ func (o *Options) NewControllerContext(
603608
cvoKubeClient := cb.KubeClientOrDie(o.Namespace, useProtobuf)
604609
o.PromQLTarget.KubeClient = cvoKubeClient
605610

611+
routeClient := cb.RouteClientOrDie("route-client")
612+
606613
cvo, err := cvo.New(
607614
o.NodeName,
608615
o.Namespace, o.Name,
@@ -629,7 +636,7 @@ func (o *Options) NewControllerContext(
629636
startingFeatureSet,
630637
startingCvoGates,
631638
startingEnabledManifestFeatureGates,
632-
alert.NewAlertGetterOrDie(cb.config),
639+
alert.NewAlertGetter(cb.RestConfig(), routeClient),
633640
)
634641
if err != nil {
635642
return nil, err

pkg/start/start_integration_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
clientset "github.com/openshift/client-go/config/clientset/versioned"
3333

3434
"github.com/openshift/cluster-version-operator/lib/resourcemerge"
35+
"github.com/openshift/cluster-version-operator/pkg/alert"
3536
"github.com/openshift/cluster-version-operator/pkg/cvo"
3637
"github.com/openshift/cluster-version-operator/pkg/internal"
3738
"github.com/openshift/cluster-version-operator/pkg/payload"
@@ -122,6 +123,14 @@ func TestIntegrationCVO_initializeAndUpgrade(t *testing.T) {
122123
kc := cb.KubeClientOrDie("integration-test")
123124
client := cb.ClientOrDie("integration-test")
124125

126+
routeClient := cb.RouteClientOrDie("integration-test")
127+
alertGetter := alert.NewAlertGetter(cb.RestConfig(), routeClient)
128+
data, err := alertGetter.Get(ctx)
129+
if err != nil {
130+
t.Fatal(err)
131+
}
132+
t.Logf("alertGetter got data: %v", data)
133+
125134
ns := fmt.Sprintf("e2e-cvo-%s", randutil.String(4))
126135

127136
if _, err := kc.CoreV1().Namespaces().Create(

vendor/github.com/openshift/client-go/route/clientset/versioned/clientset.go

Lines changed: 104 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ github.com/openshift/client-go/operator/listers/operator/v1
235235
github.com/openshift/client-go/operator/listers/operator/v1alpha1
236236
github.com/openshift/client-go/route/applyconfigurations/internal
237237
github.com/openshift/client-go/route/applyconfigurations/route/v1
238+
github.com/openshift/client-go/route/clientset/versioned
238239
github.com/openshift/client-go/route/clientset/versioned/scheme
239240
github.com/openshift/client-go/route/clientset/versioned/typed/route/v1
240241
github.com/openshift/client-go/security/applyconfigurations

0 commit comments

Comments
 (0)