@@ -13,6 +13,7 @@ import (
1313 batchv1 "k8s.io/api/batch/v1"
1414 corev1 "k8s.io/api/core/v1"
1515 rbacv1 "k8s.io/api/rbac/v1"
16+ "k8s.io/apimachinery/pkg/api/resource"
1617 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1718 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1819 "k8s.io/client-go/tools/record"
@@ -23,6 +24,7 @@ import (
2324 "github.com/crunchydata/postgres-operator/internal/initialize"
2425 "github.com/crunchydata/postgres-operator/internal/naming"
2526 "github.com/crunchydata/postgres-operator/internal/testing/cmp"
27+ "github.com/crunchydata/postgres-operator/internal/testing/events"
2628 "github.com/crunchydata/postgres-operator/internal/testing/require"
2729 "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
2830)
@@ -783,3 +785,76 @@ postgres-operator.crunchydata.com/role: replica
783785 ` ))
784786 })
785787}
788+
789+ func TestPatroniLogSize (t * testing.T ) {
790+ ctx := context .Background ()
791+
792+ oneHundredMeg , err := resource .ParseQuantity ("100M" )
793+ assert .NilError (t , err )
794+
795+ tooSmall , err := resource .ParseQuantity ("1k" )
796+ assert .NilError (t , err )
797+
798+ cluster := v1beta1.PostgresCluster {
799+ ObjectMeta : metav1.ObjectMeta {
800+ Name : "sometest" ,
801+ Namespace : "test-namespace" ,
802+ },
803+ Spec : v1beta1.PostgresClusterSpec {}}
804+
805+ t .Run ("Default" , func (t * testing.T ) {
806+ recorder := events .NewRecorder (t , runtime .Scheme )
807+ reconciler := & Reconciler {Recorder : recorder }
808+
809+ size := reconciler .patroniLogSize (ctx , & cluster )
810+
811+ assert .Equal (t , size , int64 (0 ))
812+ assert .Equal (t , len (recorder .Events ), 0 )
813+ })
814+
815+ t .Run ("NoSize" , func (t * testing.T ) {
816+ recorder := events .NewRecorder (t , runtime .Scheme )
817+ reconciler := & Reconciler {Recorder : recorder }
818+
819+ cluster .Spec .Patroni = & v1beta1.PatroniSpec {
820+ Logging : & v1beta1.PatroniLogConfig {}}
821+
822+ size := reconciler .patroniLogSize (ctx , & cluster )
823+
824+ assert .Equal (t , size , int64 (0 ))
825+ assert .Equal (t , len (recorder .Events ), 0 )
826+ })
827+
828+ t .Run ("ValidSize" , func (t * testing.T ) {
829+ recorder := events .NewRecorder (t , runtime .Scheme )
830+ reconciler := & Reconciler {Recorder : recorder }
831+
832+ cluster .Spec .Patroni = & v1beta1.PatroniSpec {
833+ Logging : & v1beta1.PatroniLogConfig {
834+ StorageLimit : & oneHundredMeg ,
835+ }}
836+
837+ size := reconciler .patroniLogSize (ctx , & cluster )
838+
839+ assert .Equal (t , size , int64 (100000000 ))
840+ assert .Equal (t , len (recorder .Events ), 0 )
841+ })
842+
843+ t .Run ("BadSize" , func (t * testing.T ) {
844+ recorder := events .NewRecorder (t , runtime .Scheme )
845+ reconciler := & Reconciler {Recorder : recorder }
846+
847+ cluster .Spec .Patroni = & v1beta1.PatroniSpec {
848+ Logging : & v1beta1.PatroniLogConfig {
849+ StorageLimit : & tooSmall ,
850+ }}
851+
852+ size := reconciler .patroniLogSize (ctx , & cluster )
853+
854+ assert .Equal (t , size , int64 (25000000 ))
855+ assert .Equal (t , len (recorder .Events ), 1 )
856+ assert .Equal (t , recorder .Events [0 ].Regarding .Name , cluster .Name )
857+ assert .Equal (t , recorder .Events [0 ].Reason , "PatroniLogStorageLimitTooSmall" )
858+ assert .Equal (t , recorder .Events [0 ].Note , "Configured Patroni log storage limit is too small. File size will default to 25M." )
859+ })
860+ }
0 commit comments