From 89a54e464e119866c06dc7bd7197390094741ead Mon Sep 17 00:00:00 2001 From: Hardik Shingala Date: Mon, 1 Jan 2024 13:36:05 +0530 Subject: [PATCH] Drop deprecated module and fix tests --- cmd/aperturectl/cmd/tui/radio-button.go | 4 +-- operator/controllers/agent/config_test.tpl | 6 ++++ operator/controllers/agent/configmaps_test.go | 6 ++-- operator/controllers/agent/daemonset.go | 4 +-- operator/controllers/agent/daemonset_test.go | 30 ++++++++-------- operator/controllers/agent/deployment.go | 6 ++-- operator/controllers/agent/deployment_test.go | 34 +++++++++---------- .../agent/mutating_webhook_configuration.go | 8 ++--- .../mutating_webhook_configuration_test.go | 8 ++--- operator/controllers/agent/secrets_test.go | 10 +++--- .../controllers/agent/serviceaccount_test.go | 14 ++++---- operator/controllers/agent/services_test.go | 10 +++--- .../controllers/controller/configmaps_test.go | 6 ++-- operator/controllers/controller/deployment.go | 4 +-- .../controllers/controller/deployment_test.go | 32 ++++++++--------- .../controllers/controller/secrets_test.go | 10 +++--- .../controller/serviceaccount_test.go | 14 ++++---- .../controllers/controller/services_test.go | 10 +++--- .../validating_webhook_configuration.go | 8 ++--- .../validating_webhook_configuration_test.go | 16 ++++----- operator/controllers/mutate_func_test.go | 8 ++--- .../mutatingwebhook/agent_pod_test.go | 22 ++++++------ .../mutating_webhook_configuration.go | 14 ++++---- .../mutating_webhook_configuration_test.go | 14 ++++---- .../mutatingwebhook/reconciler_test.go | 8 ++--- operator/controllers/utils.go | 24 ++++++------- operator/controllers/utils_test.go | 28 +++++++-------- 27 files changed, 182 insertions(+), 176 deletions(-) diff --git a/cmd/aperturectl/cmd/tui/radio-button.go b/cmd/aperturectl/cmd/tui/radio-button.go index 24543de47d..67b3286134 100644 --- a/cmd/aperturectl/cmd/tui/radio-button.go +++ b/cmd/aperturectl/cmd/tui/radio-button.go @@ -4,7 +4,7 @@ import ( "fmt" tea "github.com/charmbracelet/bubbletea" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) type radioButtonModel struct { @@ -20,7 +20,7 @@ type optionMsg int func InitialRadioButtonModel(options []string, msg string) *radioButtonModel { return &radioButtonModel{ options: options, - Selected: pointer.Int(0), + Selected: ptr.To(0), msg: msg, } } diff --git a/operator/controllers/agent/config_test.tpl b/operator/controllers/agent/config_test.tpl index 86c4f54171..c7cfe22fc9 100644 --- a/operator/controllers/agent/config_test.tpl +++ b/operator/controllers/agent/config_test.tpl @@ -281,3 +281,9 @@ object_storage: bucket: list key_prefix: asdf operations_channel_size: 1000 + retry_policy: + timeout: 10s + backoff: + initial: 0.500s + multiplier: 1.5 + maximum: 2s diff --git a/operator/controllers/agent/configmaps_test.go b/operator/controllers/agent/configmaps_test.go index da72c3c33b..c8389ce707 100644 --- a/operator/controllers/agent/configmaps_test.go +++ b/operator/controllers/agent/configmaps_test.go @@ -29,7 +29,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" agent "github.com/fluxninja/aperture/v2/cmd/aperture-agent/config" agentv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/agent/v1alpha1" @@ -143,8 +143,8 @@ var _ = Describe("ConfigMap for Agent", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Agent", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, diff --git a/operator/controllers/agent/daemonset.go b/operator/controllers/agent/daemonset.go index c5f1731eaa..7247f501ce 100644 --- a/operator/controllers/agent/daemonset.go +++ b/operator/controllers/agent/daemonset.go @@ -28,7 +28,7 @@ import ( corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -92,7 +92,7 @@ func daemonsetForAgent(instance *agentv1alpha1.Agent, log logr.Logger, scheme *r Affinity: spec.Affinity, Tolerations: spec.Tolerations, SecurityContext: controllers.PodSecurityContext(spec.PodSecurityContext), - TerminationGracePeriodSeconds: pointer.Int64(spec.TerminationGracePeriodSeconds), + TerminationGracePeriodSeconds: ptr.To[int64](spec.TerminationGracePeriodSeconds), InitContainers: spec.InitContainers, Containers: []corev1.Container{ { diff --git a/operator/controllers/agent/daemonset_test.go b/operator/controllers/agent/daemonset_test.go index dbfbe67241..df1c28c7a6 100644 --- a/operator/controllers/agent/daemonset_test.go +++ b/operator/controllers/agent/daemonset_test.go @@ -26,7 +26,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" agent "github.com/fluxninja/aperture/v2/cmd/aperture-agent/config" agentv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/agent/v1alpha1" @@ -148,8 +148,8 @@ var _ = Describe("Agent DaemonSet", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Agent", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, Annotations: nil, @@ -174,7 +174,7 @@ var _ = Describe("Agent DaemonSet", func() { NodeSelector: nil, Tolerations: nil, SecurityContext: &corev1.PodSecurityContext{}, - TerminationGracePeriodSeconds: pointer.Int64(0), + TerminationGracePeriodSeconds: ptr.To[int64](0), InitContainers: nil, Containers: []corev1.Container{ { @@ -265,7 +265,7 @@ var _ = Describe("Agent DaemonSet", func() { Name: "aperture-agent-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: AgentServiceName, }, @@ -412,8 +412,8 @@ var _ = Describe("Agent DaemonSet", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Agent", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, Annotations: TestMap, @@ -446,9 +446,9 @@ var _ = Describe("Agent DaemonSet", func() { Affinity: affinity, Tolerations: tolerations, SecurityContext: &corev1.PodSecurityContext{ - FSGroup: pointer.Int64(1001), + FSGroup: ptr.To[int64](1001), }, - TerminationGracePeriodSeconds: pointer.Int64(10), + TerminationGracePeriodSeconds: ptr.To[int64](10), InitContainers: []corev1.Container{ { Name: Test, @@ -460,10 +460,10 @@ var _ = Describe("Agent DaemonSet", func() { Image: "docker.io/fluxninja/aperture-agent:latest", ImagePullPolicy: corev1.PullIfNotPresent, SecurityContext: &corev1.SecurityContext{ - RunAsUser: pointer.Int64(0), - RunAsGroup: pointer.Int64(0), - RunAsNonRoot: pointer.Bool(false), - ReadOnlyRootFilesystem: pointer.Bool(false), + RunAsUser: ptr.To[int64](0), + RunAsGroup: ptr.To[int64](0), + RunAsNonRoot: ptr.To(false), + ReadOnlyRootFilesystem: ptr.To(false), }, Command: TestArray, Args: TestArray, @@ -606,7 +606,7 @@ var _ = Describe("Agent DaemonSet", func() { Name: "aperture-agent-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: AgentServiceName, }, @@ -646,7 +646,7 @@ var _ = Describe("Test DaemonSet Mutate", func() { NodeSelector: map[string]string{}, Tolerations: []corev1.Toleration{}, SecurityContext: &corev1.PodSecurityContext{ - FSGroup: pointer.Int64(1001), + FSGroup: ptr.To[int64](1001), }, InitContainers: []corev1.Container{}, Containers: []corev1.Container{ diff --git a/operator/controllers/agent/deployment.go b/operator/controllers/agent/deployment.go index 6a8e0a1d4a..e28eae1200 100644 --- a/operator/controllers/agent/deployment.go +++ b/operator/controllers/agent/deployment.go @@ -28,7 +28,7 @@ import ( corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -76,7 +76,7 @@ func deploymentForAgent(instance *agentv1alpha1.Agent, log logr.Logger, scheme * Annotations: spec.Annotations, }, Spec: appsv1.DeploymentSpec{ - Replicas: pointer.Int32(spec.DeploymentConfigSpec.Replicas), + Replicas: ptr.To[int32](spec.DeploymentConfigSpec.Replicas), Selector: &v1.LabelSelector{ MatchLabels: controllers.SelectorLabels(instance.GetName(), controllers.AgentServiceName), }, @@ -95,7 +95,7 @@ func deploymentForAgent(instance *agentv1alpha1.Agent, log logr.Logger, scheme * Affinity: spec.Affinity, Tolerations: spec.Tolerations, SecurityContext: controllers.PodSecurityContext(spec.PodSecurityContext), - TerminationGracePeriodSeconds: pointer.Int64(spec.TerminationGracePeriodSeconds), + TerminationGracePeriodSeconds: ptr.To[int64](spec.TerminationGracePeriodSeconds), InitContainers: spec.InitContainers, Containers: []corev1.Container{ { diff --git a/operator/controllers/agent/deployment_test.go b/operator/controllers/agent/deployment_test.go index 5f32bdcc76..316aef0c8f 100644 --- a/operator/controllers/agent/deployment_test.go +++ b/operator/controllers/agent/deployment_test.go @@ -26,7 +26,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" agent "github.com/fluxninja/aperture/v2/cmd/aperture-agent/config" agentv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/agent/v1alpha1" @@ -152,14 +152,14 @@ var _ = Describe("Agent Deployment", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Agent", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, Annotations: nil, }, Spec: appsv1.DeploymentSpec{ - Replicas: pointer.Int32(1), + Replicas: ptr.To[int32](1), Selector: &metav1.LabelSelector{ MatchLabels: selectorLabels, }, @@ -181,7 +181,7 @@ var _ = Describe("Agent Deployment", func() { NodeSelector: nil, Tolerations: nil, SecurityContext: &corev1.PodSecurityContext{}, - TerminationGracePeriodSeconds: pointer.Int64(0), + TerminationGracePeriodSeconds: ptr.To[int64](0), InitContainers: nil, Containers: []corev1.Container{ { @@ -268,7 +268,7 @@ var _ = Describe("Agent Deployment", func() { Name: "aperture-agent-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: AgentServiceName, }, @@ -420,14 +420,14 @@ var _ = Describe("Agent Deployment", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Agent", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, Annotations: TestMap, }, Spec: appsv1.DeploymentSpec{ - Replicas: pointer.Int32(1), + Replicas: ptr.To[int32](1), Selector: &metav1.LabelSelector{ MatchLabels: selectorLabels, }, @@ -457,9 +457,9 @@ var _ = Describe("Agent Deployment", func() { Affinity: affinity, Tolerations: tolerations, SecurityContext: &corev1.PodSecurityContext{ - FSGroup: pointer.Int64(1001), + FSGroup: ptr.To[int64](1001), }, - TerminationGracePeriodSeconds: pointer.Int64(10), + TerminationGracePeriodSeconds: ptr.To[int64](10), InitContainers: []corev1.Container{ { Name: Test, @@ -471,10 +471,10 @@ var _ = Describe("Agent Deployment", func() { Image: "docker.io/fluxninja/aperture-agent:latest", ImagePullPolicy: corev1.PullIfNotPresent, SecurityContext: &corev1.SecurityContext{ - RunAsUser: pointer.Int64(0), - RunAsGroup: pointer.Int64(0), - RunAsNonRoot: pointer.Bool(false), - ReadOnlyRootFilesystem: pointer.Bool(false), + RunAsUser: ptr.To[int64](0), + RunAsGroup: ptr.To[int64](0), + RunAsNonRoot: ptr.To(false), + ReadOnlyRootFilesystem: ptr.To(false), }, Command: TestArray, Args: TestArray, @@ -613,7 +613,7 @@ var _ = Describe("Agent Deployment", func() { Name: "aperture-agent-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: Test, }, @@ -658,7 +658,7 @@ var _ = Describe("Test Deployment Mutate", func() { NodeSelector: map[string]string{}, Tolerations: []corev1.Toleration{}, SecurityContext: &corev1.PodSecurityContext{ - FSGroup: pointer.Int64(1001), + FSGroup: ptr.To[int64](1001), }, InitContainers: []corev1.Container{}, Containers: []corev1.Container{ diff --git a/operator/controllers/agent/mutating_webhook_configuration.go b/operator/controllers/agent/mutating_webhook_configuration.go index 289ce732a7..50aa33f02b 100644 --- a/operator/controllers/agent/mutating_webhook_configuration.go +++ b/operator/controllers/agent/mutating_webhook_configuration.go @@ -24,7 +24,7 @@ import ( admissionregistrationv1 "k8s.io/api/admissionregistration/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" agentv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/agent/v1alpha1" ) @@ -51,8 +51,8 @@ func podMutatingWebhookConfiguration(instance *agentv1alpha1.Agent) (*admissionr Service: &admissionregistrationv1.ServiceReference{ Name: os.Getenv("APERTURE_OPERATOR_SERVICE_NAME"), Namespace: os.Getenv("APERTURE_OPERATOR_NAMESPACE"), - Path: pointer.String(controllers.MutatingWebhookURI), - Port: pointer.Int32(443), + Path: ptr.To(controllers.MutatingWebhookURI), + Port: ptr.To[int32](443), }, }, NamespaceSelector: &v1.LabelSelector{ @@ -78,7 +78,7 @@ func podMutatingWebhookConfiguration(instance *agentv1alpha1.Agent) (*admissionr AdmissionReviewVersions: []string{controllers.V1Version}, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Fail}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassNone}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } diff --git a/operator/controllers/agent/mutating_webhook_configuration_test.go b/operator/controllers/agent/mutating_webhook_configuration_test.go index dc699cc9cc..c5a488e583 100644 --- a/operator/controllers/agent/mutating_webhook_configuration_test.go +++ b/operator/controllers/agent/mutating_webhook_configuration_test.go @@ -27,7 +27,7 @@ import ( . "github.com/onsi/gomega" admissionregistrationv1 "k8s.io/api/admissionregistration/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" agentv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/agent/v1alpha1" "github.com/fluxninja/aperture/v2/operator/api/common" @@ -90,8 +90,8 @@ var _ = Describe("MutatingWebhookConfiguration for Pods", func() { Service: &admissionregistrationv1.ServiceReference{ Name: AppName, Namespace: AppName, - Path: pointer.String(MutatingWebhookURI), - Port: pointer.Int32(443), + Path: ptr.To(MutatingWebhookURI), + Port: ptr.To[int32](443), }, CABundle: serverCertPEM.Bytes(), }, @@ -118,7 +118,7 @@ var _ = Describe("MutatingWebhookConfiguration for Pods", func() { AdmissionReviewVersions: []string{V1Version}, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Fail}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassNone}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } diff --git a/operator/controllers/agent/secrets_test.go b/operator/controllers/agent/secrets_test.go index 8b23517cdc..8bd97826ed 100644 --- a/operator/controllers/agent/secrets_test.go +++ b/operator/controllers/agent/secrets_test.go @@ -25,7 +25,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" agentv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/agent/v1alpha1" "github.com/fluxninja/aperture/v2/operator/api/common" @@ -66,8 +66,8 @@ var _ = Describe("Secret for Agent", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Agent", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, @@ -122,8 +122,8 @@ var _ = Describe("Secret for Agent", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Agent", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, diff --git a/operator/controllers/agent/serviceaccount_test.go b/operator/controllers/agent/serviceaccount_test.go index 70b81a12b1..a7363252b9 100644 --- a/operator/controllers/agent/serviceaccount_test.go +++ b/operator/controllers/agent/serviceaccount_test.go @@ -23,7 +23,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" agentv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/agent/v1alpha1" "github.com/fluxninja/aperture/v2/operator/api/common" @@ -63,12 +63,12 @@ var _ = Describe("ServiceAccount for Agent", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Agent", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, - AutomountServiceAccountToken: pointer.Bool(true), + AutomountServiceAccountToken: ptr.To(true), } result, err := serviceAccountForAgent(instance.DeepCopy(), scheme.Scheme) @@ -118,12 +118,12 @@ var _ = Describe("ServiceAccount for Agent", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Agent", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, - AutomountServiceAccountToken: pointer.Bool(false), + AutomountServiceAccountToken: ptr.To(false), } result, err := serviceAccountForAgent(instance.DeepCopy(), scheme.Scheme) diff --git a/operator/controllers/agent/services_test.go b/operator/controllers/agent/services_test.go index 22f51974e9..cb80f6d32d 100644 --- a/operator/controllers/agent/services_test.go +++ b/operator/controllers/agent/services_test.go @@ -24,7 +24,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" agent "github.com/fluxninja/aperture/v2/cmd/aperture-agent/config" agentv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/agent/v1alpha1" @@ -76,8 +76,8 @@ var _ = Describe("Service for Agent", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Agent", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, @@ -171,8 +171,8 @@ var _ = Describe("Service for Agent", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Agent", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, diff --git a/operator/controllers/controller/configmaps_test.go b/operator/controllers/controller/configmaps_test.go index b3f3912634..7919650267 100644 --- a/operator/controllers/controller/configmaps_test.go +++ b/operator/controllers/controller/configmaps_test.go @@ -29,7 +29,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" controller "github.com/fluxninja/aperture/v2/cmd/aperture-controller/config" "github.com/fluxninja/aperture/v2/operator/api/common" @@ -126,8 +126,8 @@ var _ = Describe("ConfigMap for Controller", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Controller", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, diff --git a/operator/controllers/controller/deployment.go b/operator/controllers/controller/deployment.go index c4dd4445fe..d65135d9b4 100644 --- a/operator/controllers/controller/deployment.go +++ b/operator/controllers/controller/deployment.go @@ -28,7 +28,7 @@ import ( corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -92,7 +92,7 @@ func deploymentForController(instance *controllerv1alpha1.Controller, log logr.L Affinity: spec.Affinity, Tolerations: spec.Tolerations, SecurityContext: controllers.PodSecurityContext(spec.PodSecurityContext), - TerminationGracePeriodSeconds: pointer.Int64(spec.TerminationGracePeriodSeconds), + TerminationGracePeriodSeconds: ptr.To[int64](spec.TerminationGracePeriodSeconds), InitContainers: spec.InitContainers, Containers: []corev1.Container{ { diff --git a/operator/controllers/controller/deployment_test.go b/operator/controllers/controller/deployment_test.go index f81e9bf516..253cbadfd6 100644 --- a/operator/controllers/controller/deployment_test.go +++ b/operator/controllers/controller/deployment_test.go @@ -28,7 +28,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" controller "github.com/fluxninja/aperture/v2/cmd/aperture-controller/config" . "github.com/fluxninja/aperture/v2/operator/controllers" @@ -151,8 +151,8 @@ var _ = Describe("Controller Deployment", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Controller", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, Annotations: nil, @@ -260,7 +260,7 @@ var _ = Describe("Controller Deployment", func() { Name: "aperture-controller-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: ControllerServiceName, }, @@ -271,7 +271,7 @@ var _ = Describe("Controller Deployment", func() { Name: "server-cert", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), SecretName: fmt.Sprintf("%s-controller-cert", instance.GetName()), }, }, @@ -413,8 +413,8 @@ var _ = Describe("Controller Deployment", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Controller", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, Annotations: TestMap, @@ -452,9 +452,9 @@ var _ = Describe("Controller Deployment", func() { Affinity: affinity, Tolerations: tolerations, SecurityContext: &corev1.PodSecurityContext{ - FSGroup: pointer.Int64(1001), + FSGroup: ptr.To[int64](1001), }, - TerminationGracePeriodSeconds: pointer.Int64(10), + TerminationGracePeriodSeconds: ptr.To[int64](10), InitContainers: []corev1.Container{ { Name: Test, @@ -466,10 +466,10 @@ var _ = Describe("Controller Deployment", func() { Image: "docker.io/fluxninja/aperture-controller:latest", ImagePullPolicy: corev1.PullIfNotPresent, SecurityContext: &corev1.SecurityContext{ - RunAsUser: pointer.Int64(0), - RunAsGroup: pointer.Int64(0), - RunAsNonRoot: pointer.Bool(false), - ReadOnlyRootFilesystem: pointer.Bool(false), + RunAsUser: ptr.To[int64](0), + RunAsGroup: ptr.To[int64](0), + RunAsNonRoot: ptr.To(false), + ReadOnlyRootFilesystem: ptr.To(false), }, Command: TestArray, Args: TestArray, @@ -598,7 +598,7 @@ var _ = Describe("Controller Deployment", func() { Name: "aperture-controller-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: ControllerServiceName, }, @@ -609,7 +609,7 @@ var _ = Describe("Controller Deployment", func() { Name: "server-cert", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), SecretName: fmt.Sprintf("%s-controller-cert", instance.GetName()), }, }, @@ -650,7 +650,7 @@ var _ = Describe("Test Deployment Mutate", func() { Tolerations: []corev1.Toleration{}, TopologySpreadConstraints: []corev1.TopologySpreadConstraint{}, SecurityContext: &corev1.PodSecurityContext{ - FSGroup: pointer.Int64(1001), + FSGroup: ptr.To[int64](1001), }, InitContainers: []corev1.Container{}, Containers: []corev1.Container{ diff --git a/operator/controllers/controller/secrets_test.go b/operator/controllers/controller/secrets_test.go index a168945826..426add2354 100644 --- a/operator/controllers/controller/secrets_test.go +++ b/operator/controllers/controller/secrets_test.go @@ -26,7 +26,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/fluxninja/aperture/v2/operator/api/common" controllerv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/controller/v1alpha1" @@ -67,8 +67,8 @@ var _ = Describe("Secret for Controller", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Controller", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, @@ -123,8 +123,8 @@ var _ = Describe("Secret for Controller", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Controller", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, diff --git a/operator/controllers/controller/serviceaccount_test.go b/operator/controllers/controller/serviceaccount_test.go index 27ab47a569..f470c0fd68 100644 --- a/operator/controllers/controller/serviceaccount_test.go +++ b/operator/controllers/controller/serviceaccount_test.go @@ -23,7 +23,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/fluxninja/aperture/v2/operator/api/common" controllerv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/controller/v1alpha1" @@ -62,12 +62,12 @@ var _ = Describe("ServiceAccount for Controller", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Controller", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, - AutomountServiceAccountToken: pointer.Bool(true), + AutomountServiceAccountToken: ptr.To(true), } result, err := serviceAccountForController(instance.DeepCopy(), scheme.Scheme) @@ -117,12 +117,12 @@ var _ = Describe("ServiceAccount for Controller", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Controller", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, - AutomountServiceAccountToken: pointer.Bool(false), + AutomountServiceAccountToken: ptr.To(false), } result, err := serviceAccountForController(instance.DeepCopy(), scheme.Scheme) diff --git a/operator/controllers/controller/services_test.go b/operator/controllers/controller/services_test.go index ad45df9fe3..e4edc4e9e3 100644 --- a/operator/controllers/controller/services_test.go +++ b/operator/controllers/controller/services_test.go @@ -26,7 +26,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/fluxninja/aperture/v2/operator/api/common" controllerv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/controller/v1alpha1" @@ -71,8 +71,8 @@ var _ = Describe("Service for Controller", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Controller", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, @@ -149,8 +149,8 @@ var _ = Describe("Service for Controller", func() { APIVersion: "fluxninja.com/v1alpha1", Name: instance.GetName(), Kind: "Controller", - Controller: pointer.Bool(true), - BlockOwnerDeletion: pointer.Bool(true), + Controller: ptr.To(true), + BlockOwnerDeletion: ptr.To(true), }, }, }, diff --git a/operator/controllers/controller/validating_webhook_configuration.go b/operator/controllers/controller/validating_webhook_configuration.go index 03a50bb58a..0897fb79fe 100644 --- a/operator/controllers/controller/validating_webhook_configuration.go +++ b/operator/controllers/controller/validating_webhook_configuration.go @@ -20,7 +20,7 @@ import ( "github.com/fluxninja/aperture/v2/operator/controllers" admissionregistrationv1 "k8s.io/api/admissionregistration/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" controllerv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/controller/v1alpha1" ) @@ -42,8 +42,8 @@ func validatingWebhookConfiguration(instance *controllerv1alpha1.Controller, cer Service: &admissionregistrationv1.ServiceReference{ Name: controllers.ControllerResourcesName(instance), Namespace: instance.GetNamespace(), - Path: pointer.String(controllers.PolicyValidatingWebhookURI), - Port: pointer.Int32(serverPort), + Path: ptr.To(controllers.PolicyValidatingWebhookURI), + Port: ptr.To[int32](serverPort), }, CABundle: cert, }, @@ -66,7 +66,7 @@ func validatingWebhookConfiguration(instance *controllerv1alpha1.Controller, cer AdmissionReviewVersions: []string{controllers.V1Version}, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Fail}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassNone}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } diff --git a/operator/controllers/controller/validating_webhook_configuration_test.go b/operator/controllers/controller/validating_webhook_configuration_test.go index b10499fc98..c6d18d4e9c 100644 --- a/operator/controllers/controller/validating_webhook_configuration_test.go +++ b/operator/controllers/controller/validating_webhook_configuration_test.go @@ -24,7 +24,7 @@ import ( . "github.com/onsi/gomega" admissionregistrationv1 "k8s.io/api/admissionregistration/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/fluxninja/aperture/v2/operator/api/common" controllerv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/controller/v1alpha1" @@ -77,8 +77,8 @@ var _ = Describe("ValidatingWebhookConfiguration for Controller", func() { Service: &admissionregistrationv1.ServiceReference{ Name: ControllerServiceName, Namespace: instance.GetNamespace(), - Path: pointer.String(PolicyValidatingWebhookURI), - Port: pointer.Int32(8080), + Path: ptr.To(PolicyValidatingWebhookURI), + Port: ptr.To[int32](8080), }, CABundle: []byte(Test), }, @@ -101,7 +101,7 @@ var _ = Describe("ValidatingWebhookConfiguration for Controller", func() { AdmissionReviewVersions: []string{V1Version}, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Fail}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassNone}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } @@ -163,8 +163,8 @@ var _ = Describe("ValidatingWebhookConfiguration for Controller", func() { Service: &admissionregistrationv1.ServiceReference{ Name: ControllerServiceName, Namespace: instance.GetNamespace(), - Path: pointer.String(PolicyValidatingWebhookURI), - Port: pointer.Int32(80), + Path: ptr.To(PolicyValidatingWebhookURI), + Port: ptr.To[int32](80), }, CABundle: []byte(Test), }, @@ -187,7 +187,7 @@ var _ = Describe("ValidatingWebhookConfiguration for Controller", func() { AdmissionReviewVersions: []string{V1Version}, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Fail}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassNone}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } @@ -221,7 +221,7 @@ var _ = Describe("Test ValidatingWebhookConfiguration Mutate", func() { }, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Ignore}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassSome}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } diff --git a/operator/controllers/mutate_func_test.go b/operator/controllers/mutate_func_test.go index 5044e9fd04..9621eda568 100644 --- a/operator/controllers/mutate_func_test.go +++ b/operator/controllers/mutate_func_test.go @@ -25,7 +25,7 @@ import ( corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) var _ = Describe("Test ClusterRole Mutate", func() { @@ -104,7 +104,7 @@ var _ = Describe("Test MutatingWebhookConfiguration Mutate", func() { }, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Ignore}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassSome}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } @@ -144,7 +144,7 @@ var _ = Describe("Test ServiceAccount Mutate", func() { It("Mutate should update required fields only", func() { expected := &corev1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{}, - AutomountServiceAccountToken: pointer.Bool(true), + AutomountServiceAccountToken: ptr.To(true), } sa := &corev1.ServiceAccount{} @@ -201,7 +201,7 @@ var _ = Describe("Test ValidatingWebhookConfiguration Mutate", func() { }, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Ignore}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassSome}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } diff --git a/operator/controllers/mutatingwebhook/agent_pod_test.go b/operator/controllers/mutatingwebhook/agent_pod_test.go index 7837fd9a01..3cfad2a477 100644 --- a/operator/controllers/mutatingwebhook/agent_pod_test.go +++ b/operator/controllers/mutatingwebhook/agent_pod_test.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" agent "github.com/fluxninja/aperture/v2/cmd/aperture-agent/config" agentv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/agent/v1alpha1" @@ -247,8 +247,8 @@ var _ = Describe("Sidecar container for Agent", func() { Image: "auto", ImagePullPolicy: corev1.PullAlways, SecurityContext: &corev1.SecurityContext{ - RunAsUser: pointer.Int64(1000), - RunAsGroup: pointer.Int64(1000), + RunAsUser: ptr.To[int64](1000), + RunAsGroup: ptr.To[int64](1000), }, Command: TestArray, Args: TestArray, @@ -277,8 +277,8 @@ var _ = Describe("Sidecar container for Agent", func() { Image: "docker.io/fluxninja/aperture-agent:latest", ImagePullPolicy: corev1.PullAlways, SecurityContext: &corev1.SecurityContext{ - RunAsUser: pointer.Int64(1000), - RunAsGroup: pointer.Int64(1000), + RunAsUser: ptr.To[int64](1000), + RunAsGroup: ptr.To[int64](1000), }, Command: TestArray, Args: TestArray, @@ -478,10 +478,10 @@ var _ = Describe("Sidecar container for Agent", func() { Image: "docker.io/fluxninja/aperture-agent:latest", ImagePullPolicy: corev1.PullIfNotPresent, SecurityContext: &corev1.SecurityContext{ - RunAsUser: pointer.Int64(0), - RunAsGroup: pointer.Int64(0), - RunAsNonRoot: pointer.Bool(false), - ReadOnlyRootFilesystem: pointer.Bool(false), + RunAsUser: ptr.To[int64](0), + RunAsGroup: ptr.To[int64](0), + RunAsNonRoot: ptr.To(false), + ReadOnlyRootFilesystem: ptr.To(false), }, Command: TestArray, Args: TestArray, @@ -772,7 +772,7 @@ var _ = Describe("Pod modification for Agent", func() { Name: "aperture-agent-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: AgentServiceName, }, @@ -993,7 +993,7 @@ var _ = Describe("Pod modification for Agent", func() { Name: "aperture-agent-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: AgentServiceName, }, diff --git a/operator/controllers/mutatingwebhook/mutating_webhook_configuration.go b/operator/controllers/mutatingwebhook/mutating_webhook_configuration.go index 1cb966dcf6..623eb3f5f6 100644 --- a/operator/controllers/mutatingwebhook/mutating_webhook_configuration.go +++ b/operator/controllers/mutatingwebhook/mutating_webhook_configuration.go @@ -24,7 +24,7 @@ import ( admissionregistrationv1 "k8s.io/api/admissionregistration/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) // agentMutatingWebhookConfiguration prepares the MutatingWebhookConfiguration object for the Operator to mutate Agents, based on the provided parameter. @@ -53,8 +53,8 @@ func agentMutatingWebhookConfiguration() (*admissionregistrationv1.MutatingWebho Service: &admissionregistrationv1.ServiceReference{ Name: os.Getenv("APERTURE_OPERATOR_SERVICE_NAME"), Namespace: os.Getenv("APERTURE_OPERATOR_NAMESPACE"), - Path: pointer.String(fmt.Sprintf("/%s", controllers.AgentMutatingWebhookURI)), - Port: pointer.Int32(443), + Path: ptr.To(fmt.Sprintf("/%s", controllers.AgentMutatingWebhookURI)), + Port: ptr.To[int32](443), }, }, NamespaceSelector: &v1.LabelSelector{}, @@ -72,7 +72,7 @@ func agentMutatingWebhookConfiguration() (*admissionregistrationv1.MutatingWebho AdmissionReviewVersions: []string{controllers.V1Version}, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Fail}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassNone}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } @@ -106,8 +106,8 @@ func controllerMutatingWebhookConfiguration() (*admissionregistrationv1.Mutating Service: &admissionregistrationv1.ServiceReference{ Name: os.Getenv("APERTURE_OPERATOR_SERVICE_NAME"), Namespace: os.Getenv("APERTURE_OPERATOR_NAMESPACE"), - Path: pointer.String(fmt.Sprintf("/%s", controllers.ControllerMutatingWebhookURI)), - Port: pointer.Int32(443), + Path: ptr.To(fmt.Sprintf("/%s", controllers.ControllerMutatingWebhookURI)), + Port: ptr.To[int32](443), }, }, NamespaceSelector: &v1.LabelSelector{}, @@ -125,7 +125,7 @@ func controllerMutatingWebhookConfiguration() (*admissionregistrationv1.Mutating AdmissionReviewVersions: []string{controllers.V1Version}, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Fail}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassNone}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } diff --git a/operator/controllers/mutatingwebhook/mutating_webhook_configuration_test.go b/operator/controllers/mutatingwebhook/mutating_webhook_configuration_test.go index 670afe3ef2..728db7113c 100644 --- a/operator/controllers/mutatingwebhook/mutating_webhook_configuration_test.go +++ b/operator/controllers/mutatingwebhook/mutating_webhook_configuration_test.go @@ -27,7 +27,7 @@ import ( . "github.com/onsi/gomega" admissionregistrationv1 "k8s.io/api/admissionregistration/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) var _ = Describe("MutatingWebhookConfiguration for Agent CR", func() { @@ -63,8 +63,8 @@ var _ = Describe("MutatingWebhookConfiguration for Agent CR", func() { Service: &admissionregistrationv1.ServiceReference{ Name: AppName, Namespace: AppName, - Path: pointer.String("/agent-defaulter"), - Port: pointer.Int32(443), + Path: ptr.To("/agent-defaulter"), + Port: ptr.To[int32](443), }, CABundle: serverCertPEM.Bytes(), }, @@ -83,7 +83,7 @@ var _ = Describe("MutatingWebhookConfiguration for Agent CR", func() { AdmissionReviewVersions: []string{V1Version}, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Fail}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassNone}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } @@ -131,8 +131,8 @@ var _ = Describe("MutatingWebhookConfiguration for Controller CR", func() { Service: &admissionregistrationv1.ServiceReference{ Name: AppName, Namespace: AppName, - Path: pointer.String("/controller-defaulter"), - Port: pointer.Int32(443), + Path: ptr.To("/controller-defaulter"), + Port: ptr.To[int32](443), }, CABundle: serverCertPEM.Bytes(), }, @@ -151,7 +151,7 @@ var _ = Describe("MutatingWebhookConfiguration for Controller CR", func() { AdmissionReviewVersions: []string{V1Version}, FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Fail}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassNone}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } diff --git a/operator/controllers/mutatingwebhook/reconciler_test.go b/operator/controllers/mutatingwebhook/reconciler_test.go index 2d8e30f148..fe97888dc0 100644 --- a/operator/controllers/mutatingwebhook/reconciler_test.go +++ b/operator/controllers/mutatingwebhook/reconciler_test.go @@ -23,7 +23,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" admissionregistrationv1 "k8s.io/api/admissionregistration/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -53,8 +53,8 @@ var _ = Describe("MutatingWebhookConfiguration controller", Ordered, func() { Service: &admissionregistrationv1.ServiceReference{ Name: "agent-defaulter.fluxninja.com", Namespace: Test, - Path: pointer.String("/agent-defaulter"), - Port: pointer.Int32(443), + Path: ptr.To("/agent-defaulter"), + Port: ptr.To[int32](443), }, }, NamespaceSelector: &v1.LabelSelector{}, @@ -73,7 +73,7 @@ var _ = Describe("MutatingWebhookConfiguration controller", Ordered, func() { FailurePolicy: &[]admissionregistrationv1.FailurePolicyType{admissionregistrationv1.Fail}[0], MatchPolicy: &[]admissionregistrationv1.MatchPolicyType{admissionregistrationv1.Equivalent}[0], SideEffects: &[]admissionregistrationv1.SideEffectClass{admissionregistrationv1.SideEffectClassNone}[0], - TimeoutSeconds: pointer.Int32(10), + TimeoutSeconds: ptr.To[int32](10), }, }, } diff --git a/operator/controllers/utils.go b/operator/controllers/utils.go index 64c44be5bc..27f1a726a5 100644 --- a/operator/controllers/utils.go +++ b/operator/controllers/utils.go @@ -42,7 +42,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/rest" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -57,10 +57,10 @@ func ContainerSecurityContext(containerSecurityContext common.ContainerSecurityC var securityContext *corev1.SecurityContext if containerSecurityContext.Enabled { securityContext = &corev1.SecurityContext{ - RunAsUser: pointer.Int64(containerSecurityContext.RunAsUser), - RunAsNonRoot: pointer.Bool(containerSecurityContext.RunAsNonRootUser), - ReadOnlyRootFilesystem: pointer.Bool(containerSecurityContext.ReadOnlyRootFilesystem), - RunAsGroup: pointer.Int64(containerSecurityContext.RunAsGroup), + RunAsUser: ptr.To[int64](containerSecurityContext.RunAsUser), + RunAsNonRoot: ptr.To(containerSecurityContext.RunAsNonRootUser), + ReadOnlyRootFilesystem: ptr.To(containerSecurityContext.ReadOnlyRootFilesystem), + RunAsGroup: ptr.To[int64](containerSecurityContext.RunAsGroup), } } else { securityContext = &corev1.SecurityContext{} @@ -74,7 +74,7 @@ func PodSecurityContext(podSecurityContext common.PodSecurityContext) *corev1.Po var securityContext *corev1.PodSecurityContext if podSecurityContext.Enabled { securityContext = &corev1.PodSecurityContext{ - FSGroup: pointer.Int64(podSecurityContext.FsGroup), + FSGroup: ptr.To[int64](podSecurityContext.FsGroup), } } else { securityContext = &corev1.PodSecurityContext{} @@ -254,7 +254,7 @@ func AgentEnv(instance *agentv1alpha1.Agent, agentGroup string) []corev1.EnvVar Name: SecretName(instance.GetName(), "agent", &instance.Spec.Secrets.FluxNinjaExtension), }, Key: SecretDataKey(&instance.Spec.Secrets.FluxNinjaExtension.SecretKeyRef), - Optional: pointer.Bool(false), + Optional: ptr.To(false), }, }, }) @@ -291,7 +291,7 @@ func AgentVolumes(instance *agentv1alpha1.Agent) []corev1.Volume { Name: "aperture-agent-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: AgentResourceName(instance), }, @@ -305,7 +305,7 @@ func AgentVolumes(instance *agentv1alpha1.Agent) []corev1.Volume { Name: agentSpec.ControllerClientCertConfig.ConfigMapName, VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: agentSpec.ControllerClientCertConfig.ConfigMapName, }, @@ -346,7 +346,7 @@ func ControllerEnv(instance *controllerv1alpha1.Controller) []corev1.EnvVar { Name: SecretName(instance.GetName(), "controller", &instance.Spec.Secrets.FluxNinjaExtension), }, Key: SecretDataKey(&instance.Spec.Secrets.FluxNinjaExtension.SecretKeyRef), - Optional: pointer.Bool(false), + Optional: ptr.To(false), }, }, }) @@ -379,7 +379,7 @@ func ControllerVolumes(instance *controllerv1alpha1.Controller) []corev1.Volume Name: "aperture-controller-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: ControllerResourcesName(instance), }, @@ -390,7 +390,7 @@ func ControllerVolumes(instance *controllerv1alpha1.Controller) []corev1.Volume Name: "server-cert", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), SecretName: fmt.Sprintf("%s-controller-cert", instance.GetName()), }, }, diff --git a/operator/controllers/utils_test.go b/operator/controllers/utils_test.go index d583de80f1..83e8c1d4ee 100644 --- a/operator/controllers/utils_test.go +++ b/operator/controllers/utils_test.go @@ -27,7 +27,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" agentv1alpha1 "github.com/fluxninja/aperture/v2/operator/api/agent/v1alpha1" "github.com/fluxninja/aperture/v2/operator/api/common" @@ -77,10 +77,10 @@ var _ = Describe("Tests for containerSecurityContext", func() { } expected := &corev1.SecurityContext{ - RunAsUser: pointer.Int64(0), - RunAsGroup: pointer.Int64(0), - RunAsNonRoot: pointer.Bool(false), - ReadOnlyRootFilesystem: pointer.Bool(false), + RunAsUser: ptr.To[int64](0), + RunAsGroup: ptr.To[int64](0), + RunAsNonRoot: ptr.To(false), + ReadOnlyRootFilesystem: ptr.To(false), } result := ContainerSecurityContext(instance.Spec.ContainerSecurityContext) @@ -129,7 +129,7 @@ var _ = Describe("Tests for podSecurityContext", func() { } expected := &corev1.PodSecurityContext{ - FSGroup: pointer.Int64(1001), + FSGroup: ptr.To[int64](1001), } result := PodSecurityContext(instance.Spec.PodSecurityContext) @@ -641,7 +641,7 @@ var _ = Describe("Tests for agentEnv", func() { Name: Test, }, Key: Test, - Optional: pointer.Bool(false), + Optional: ptr.To(false), }, }, }, @@ -781,7 +781,7 @@ var _ = Describe("Tests for agentVolumes", func() { Name: "aperture-agent-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: AgentServiceName, }, @@ -827,7 +827,7 @@ var _ = Describe("Tests for agentVolumes", func() { Name: "aperture-agent-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: AgentServiceName, }, @@ -887,7 +887,7 @@ var _ = Describe("Tests for controllerEnv", func() { Name: Test, }, Key: Test, - Optional: pointer.Bool(false), + Optional: ptr.To(false), }, }, }, @@ -1028,7 +1028,7 @@ var _ = Describe("Tests for controllerVolumes", func() { Name: "aperture-controller-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: ControllerServiceName, }, @@ -1039,7 +1039,7 @@ var _ = Describe("Tests for controllerVolumes", func() { Name: "server-cert", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), SecretName: fmt.Sprintf("%s-controller-cert", instance.GetName()), }, }, @@ -1083,7 +1083,7 @@ var _ = Describe("Tests for controllerVolumes", func() { Name: "aperture-controller-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), LocalObjectReference: corev1.LocalObjectReference{ Name: ControllerServiceName, }, @@ -1094,7 +1094,7 @@ var _ = Describe("Tests for controllerVolumes", func() { Name: "server-cert", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - DefaultMode: pointer.Int32(420), + DefaultMode: ptr.To[int32](420), SecretName: fmt.Sprintf("%s-controller-cert", instance.GetName()), }, },