Skip to content

Commit 939f5af

Browse files
committed
cleanups
1 parent 1b4d712 commit 939f5af

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

pkg/cluster/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ func (m *manager) initializeKubernetesClients(ctx context.Context) error {
546546
// initializeKubernetesClients initializes clients which are used
547547
// once the cluster is up later on in the install process.
548548
func (m *manager) initializeOperatorDeployer(ctx context.Context) (err error) {
549-
m.aroOperatorDeployer, err = deploy.New(m.log, m.env, m.doc.OpenShiftCluster, m.arocli, m.ch.Client(), m.extensionscli, m.kubernetescli, m.operatorcli)
549+
m.aroOperatorDeployer, err = deploy.New(m.log, m.env, m.doc.OpenShiftCluster, m.arocli, m.ch, m.extensionscli, m.kubernetescli, m.operatorcli)
550550
return
551551
}
552552

pkg/operator/deploy/deploy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1"
3030
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
3131
"k8s.io/client-go/util/retry"
32-
"sigs.k8s.io/controller-runtime/pkg/client"
3332
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3433

3534
"github.com/Azure/ARO-RP/pkg/api"
@@ -39,6 +38,7 @@ import (
3938
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
4039
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
4140
"github.com/Azure/ARO-RP/pkg/operator/controllers/genevalogging"
41+
"github.com/Azure/ARO-RP/pkg/util/clienthelper"
4242
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
4343
utilkubernetes "github.com/Azure/ARO-RP/pkg/util/kubernetes"
4444
utilpem "github.com/Azure/ARO-RP/pkg/util/pem"
@@ -68,14 +68,14 @@ type operator struct {
6868
oc *api.OpenShiftCluster
6969

7070
arocli aroclient.Interface
71-
client client.Client
71+
client clienthelper.Interface
7272
extensionscli extensionsclient.Interface
7373
kubernetescli kubernetes.Interface
7474
operatorcli operatorclient.Interface
7575
dh dynamichelper.Interface
7676
}
7777

78-
func New(log *logrus.Entry, env env.Interface, oc *api.OpenShiftCluster, arocli aroclient.Interface, client client.Client, extensionscli extensionsclient.Interface, kubernetescli kubernetes.Interface, operatorcli operatorclient.Interface) (Operator, error) {
78+
func New(log *logrus.Entry, env env.Interface, oc *api.OpenShiftCluster, arocli aroclient.Interface, client clienthelper.Interface, extensionscli extensionsclient.Interface, kubernetescli kubernetes.Interface, operatorcli operatorclient.Interface) (Operator, error) {
7979
restConfig, err := restconfig.RestConfig(env, oc)
8080
if err != nil {
8181
return nil, err

pkg/operator/deploy/deploy_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212
configv1 "github.com/openshift/api/config/v1"
1313
operatorv1 "github.com/openshift/api/operator/v1"
1414
operatorfake "github.com/openshift/client-go/operator/clientset/versioned/fake"
15+
"github.com/sirupsen/logrus"
1516
appsv1 "k8s.io/api/apps/v1"
1617
corev1 "k8s.io/api/core/v1"
1718
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1819
"k8s.io/client-go/kubernetes/fake"
1920
ctrlfake "sigs.k8s.io/controller-runtime/pkg/client/fake"
2021

2122
"github.com/Azure/ARO-RP/pkg/api"
23+
"github.com/Azure/ARO-RP/pkg/util/clienthelper"
2224
"github.com/Azure/ARO-RP/pkg/util/cmp"
2325
mock_env "github.com/Azure/ARO-RP/pkg/util/mocks/env"
2426
utilerror "github.com/Azure/ARO-RP/test/util/error"
@@ -232,7 +234,7 @@ func TestCreateDeploymentData(t *testing.T) {
232234
o := operator{
233235
oc: oc,
234236
env: env,
235-
client: ctrlfake.NewClientBuilder().WithObjects(cv).Build(),
237+
client: clienthelper.NewWithClient(logrus.NewEntry(logrus.StandardLogger()), ctrlfake.NewClientBuilder().WithObjects(cv).Build()),
236238
}
237239

238240
deploymentData, err := o.createDeploymentData(ctx)
@@ -305,7 +307,7 @@ func TestOperatorVersion(t *testing.T) {
305307
o := &operator{
306308
oc: &api.OpenShiftCluster{Properties: *oc},
307309
env: _env,
308-
client: ctrlfake.NewClientBuilder().WithObjects(cv).Build(),
310+
client: clienthelper.NewWithClient(logrus.NewEntry(logrus.StandardLogger()), ctrlfake.NewClientBuilder().WithObjects(cv).Build()),
309311
}
310312

311313
staticResources, err := o.createObjects(ctx)

pkg/operator/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func GatewayEnabled(cluster *arov1alpha1.Cluster) bool {
2323
// ShouldUsePodSecurityStandard is an admissions controller
2424
// for pods which replaces pod security policies, enabled on
2525
// OpenShift 4.11 and up
26-
func ShouldUsePodSecurityStandard(ctx context.Context, client client.Client) (bool, error) {
26+
func ShouldUsePodSecurityStandard(ctx context.Context, client client.Reader) (bool, error) {
2727
cv := &configv1.ClusterVersion{}
2828

2929
err := client.Get(ctx, types.NamespacedName{Name: "version"}, cv)

pkg/util/clienthelper/clienthelper.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ import (
3535
)
3636

3737
type Interface interface {
38+
client.Reader
39+
client.Writer
3840
EnsureDeleted(ctx context.Context, gvk schema.GroupVersionKind, key types.NamespacedName) error
3941
Ensure(ctx context.Context, objs ...kruntime.Object) error
4042
GetOne(ctx context.Context, key types.NamespacedName, obj kruntime.Object) error
41-
Client() client.Client
4243
}
4344

4445
type clientHelper struct {
45-
log *logrus.Entry
46+
client.Client
4647

47-
client client.Client
48+
log *logrus.Entry
4849
}
4950

5051
func New(log *logrus.Entry, restconfig *rest.Config) (Interface, error) {
@@ -63,14 +64,10 @@ func New(log *logrus.Entry, restconfig *rest.Config) (Interface, error) {
6364
func NewWithClient(log *logrus.Entry, client client.Client) Interface {
6465
return &clientHelper{
6566
log: log,
66-
client: client,
67+
Client: client,
6768
}
6869
}
6970

70-
func (ch *clientHelper) Client() client.Client {
71-
return ch.client
72-
}
73-
7471
func (ch *clientHelper) EnsureDeleted(ctx context.Context, gvk schema.GroupVersionKind, key types.NamespacedName) error {
7572
a := meta.AsPartialObjectMetadata(&metav1.ObjectMeta{
7673
Name: key.Name,
@@ -79,7 +76,7 @@ func (ch *clientHelper) EnsureDeleted(ctx context.Context, gvk schema.GroupVersi
7976
a.SetGroupVersionKind(gvk)
8077

8178
ch.log.Infof("Delete kind %s ns %s name %s", gvk.Kind, key.Namespace, key.Name)
82-
err := ch.client.Delete(ctx, a)
79+
err := ch.Delete(ctx, a)
8380
if kerrors.IsNotFound(err) {
8481
return nil
8582
}
@@ -92,7 +89,7 @@ func (ch *clientHelper) GetOne(ctx context.Context, key types.NamespacedName, ob
9289
return errors.New("can't convert object")
9390
}
9491

95-
return ch.client.Get(ctx, key, newObj)
92+
return ch.Get(ctx, key, newObj)
9693
}
9794

9895
// Ensure that one or more objects match their desired state. Only update
@@ -130,10 +127,10 @@ func (ch *clientHelper) ensureOne(ctx context.Context, new kruntime.Object) erro
130127
return fmt.Errorf("object of kind %s can't be made a client.Object", gvk.String())
131128
}
132129

133-
err = ch.client.Get(ctx, client.ObjectKey{Namespace: newObj.GetNamespace(), Name: newObj.GetName()}, oldObj)
130+
err = ch.Get(ctx, client.ObjectKey{Namespace: newObj.GetNamespace(), Name: newObj.GetName()}, oldObj)
134131
if kerrors.IsNotFound(err) {
135132
ch.log.Infof("Create %s", keyFunc(gvk.GroupKind(), newObj.GetNamespace(), newObj.GetName()))
136-
return ch.client.Create(ctx, newObj)
133+
return ch.Create(ctx, newObj)
137134
}
138135
if err != nil {
139136
return err
@@ -143,7 +140,7 @@ func (ch *clientHelper) ensureOne(ctx context.Context, new kruntime.Object) erro
143140
return err
144141
}
145142
ch.log.Infof("Update %s: %s", keyFunc(gvk.GroupKind(), candidate.GetNamespace(), candidate.GetName()), diff)
146-
return ch.client.Update(ctx, candidate)
143+
return ch.Update(ctx, candidate)
147144
})
148145
}
149146

pkg/util/clienthelper/clienthelper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ func TestMergeApply(t *testing.T) {
13661366
})
13671367

13681368
ch := &clientHelper{
1369-
client: clientFake,
1369+
Client: clientFake,
13701370
log: logrus.NewEntry(logrus.StandardLogger()),
13711371
}
13721372

0 commit comments

Comments
 (0)