Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controllers: use k8s pointer util #2428

Merged
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
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
7 changes: 3 additions & 4 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 @@ -929,10 +930,8 @@ func copyManifests() {
}

func getUXBackendServerDeployment() appsv1.DeploymentSpec {
replica := int32(1)
ptrToTrue := true
deployment := appsv1.DeploymentSpec{
Replicas: &replica,
Replicas: ptr.To(int32(1)),
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app.kubernetes.io/component": "ux-backend-server",
Expand Down Expand Up @@ -1023,7 +1022,7 @@ func getUXBackendServerDeployment() appsv1.DeploymentSpec {
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "onboarding-private-key",
Optional: &ptrToTrue,
Optional: ptr.To(true),
},
},
},
Expand Down
Loading