Skip to content

Commit

Permalink
controllers: use k8s pointer util
Browse files Browse the repository at this point in the history
Signed-off-by: Jose A. Rivera <[email protected]>
  • Loading branch information
jarrpa committed Feb 2, 2024
1 parent 35ac7ee commit 48b855b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
13 changes: 4 additions & 9 deletions controllers/storagecluster/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
controllerutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

Expand Down Expand Up @@ -276,12 +277,6 @@ func createMetricsExporterServiceMonitor(ctx context.Context, r *StorageClusterR
}

func deployMetricsExporter(ctx context.Context, r *StorageClusterReconciler, instance *ocsv1.StorageCluster) error {
var (
falsePtr = new(bool) // defaults to 'false'
truePtr = new(bool)
)
*truePtr = true

currentDep := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: metricsExporterName,
Expand All @@ -301,8 +296,8 @@ func deployMetricsExporter(ctx context.Context, r *StorageClusterReconciler, ins
Namespace: instance.Namespace,
OwnerReferences: []metav1.OwnerReference{{
APIVersion: instance.APIVersion,
BlockOwnerDeletion: falsePtr,
Controller: falsePtr,
BlockOwnerDeletion: ptr.To(false),
Controller: ptr.To(false),
Kind: instance.Kind,
Name: instance.Name,
UID: instance.UID,
Expand Down Expand Up @@ -337,7 +332,7 @@ func deployMetricsExporter(ctx context.Context, r *StorageClusterReconciler, ins
{ContainerPort: 8081},
},
SecurityContext: &corev1.SecurityContext{
RunAsNonRoot: truePtr,
RunAsNonRoot: ptr.To(true),
},
VolumeMounts: []corev1.VolumeMount{{
Name: "ceph-config",
Expand Down
10 changes: 5 additions & 5 deletions controllers/util/predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)

var one = int64(1)
var now = metav1.NewTime(time.Now())

func TestComposePredicatesUpdate(t *testing.T) {
Expand Down Expand Up @@ -50,10 +50,10 @@ func TestComposePredicatesUpdate(t *testing.T) {
Namespace: "foo",
SelfLink: "foo",
UID: types.UID("foo"),
Generation: one,
Generation: 1,
CreationTimestamp: now,
DeletionTimestamp: &now,
DeletionGracePeriodSeconds: &one,
DeletionGracePeriodSeconds: ptr.To(int64(1)),
OwnerReferences: []metav1.OwnerReference{{}},
ManagedFields: []metav1.ManagedFieldsEntry{{}},
},
Expand Down Expand Up @@ -127,10 +127,10 @@ func TestMetadataChangedPredicateUpdate(t *testing.T) {
SelfLink: "foo",
UID: types.UID("foo"),
ResourceVersion: "foo",
Generation: one,
Generation: 1,
CreationTimestamp: now,
DeletionTimestamp: &now,
DeletionGracePeriodSeconds: &one,
DeletionGracePeriodSeconds: ptr.To(int64(1)),
OwnerReferences: []metav1.OwnerReference{{}},
ManagedFields: []metav1.ManagedFieldsEntry{{}},
},
Expand Down
4 changes: 2 additions & 2 deletions tools/csv-merger/csv-merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/utils/ptr"
)

var (
Expand Down Expand Up @@ -930,7 +931,6 @@ func copyManifests() {

func getUXBackendServerDeployment() appsv1.DeploymentSpec {
replica := int32(1)
ptrToTrue := true
deployment := appsv1.DeploymentSpec{
Replicas: &replica,
Selector: &metav1.LabelSelector{
Expand Down Expand Up @@ -1023,7 +1023,7 @@ func getUXBackendServerDeployment() appsv1.DeploymentSpec {
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "onboarding-private-key",
Optional: &ptrToTrue,
Optional: ptr.To(true),
},
},
},
Expand Down

0 comments on commit 48b855b

Please sign in to comment.