@@ -12,12 +12,14 @@ import (
1212 "k8s.io/utils/ptr"
1313 capiv2 "sigs.k8s.io/cluster-api/api/core/v1beta2"
1414
15+ semver "github.com/blang/semver/v4"
1516 . "github.com/onsi/gomega"
1617 "github.com/teutonet/cluster-api-provider-hosted-control-plane/api/v1alpha1"
1718 . "github.com/teutonet/cluster-api-provider-hosted-control-plane/test"
1819 "go.etcd.io/etcd/api/v3/etcdserverpb"
1920 "k8s.io/apimachinery/pkg/api/resource"
2021 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+ corev1ac "k8s.io/client-go/applyconfigurations/core/v1"
2123)
2224
2325func TestEtcdClusterReconciler_getETCDVolumeSize (t * testing.T ) {
@@ -779,3 +781,60 @@ func TestEtcdClusterReconciler_reconcileETCDBackup(t *testing.T) {
779781 g .Expect (hcp .Status .ETCDNextBackupTime ).NotTo (BeZero ())
780782 })
781783}
784+
785+ func TestBuildEtcdArgs_SnapshotCount (t * testing.T ) {
786+ tests := []struct {
787+ name string
788+ etcdVersion semver.Version
789+ expectSnapshotCount bool
790+ }{
791+ {
792+ name : "version < 3.7 sets snapshot-count" ,
793+ etcdVersion : semver .MustParse ("3.6.0" ),
794+ expectSnapshotCount : true ,
795+ },
796+ {
797+ name : "version >= 3.7 omits snapshot-count" ,
798+ etcdVersion : semver .MustParse ("3.7.0" ),
799+ expectSnapshotCount : false ,
800+ },
801+ }
802+
803+ for _ , tt := range tests {
804+ t .Run (tt .name , func (t * testing.T ) {
805+ g := NewWithT (t )
806+
807+ reconciler := & etcdClusterReconciler {}
808+ hcp := & v1alpha1.HostedControlPlane {
809+ ObjectMeta : metav1.ObjectMeta {Namespace : "test-ns" },
810+ Status : v1alpha1.HostedControlPlaneStatus {ETCDVolumeSize : resource .MustParse ("10Gi" )},
811+ }
812+ cluster := & capiv2.Cluster {
813+ ObjectMeta : metav1.ObjectMeta {Name : "test-cluster" , Namespace : "test-ns" },
814+ }
815+ serverPort := corev1ac .ContainerPort ().WithContainerPort (2379 )
816+ peerPort := corev1ac .ContainerPort ().WithContainerPort (2380 )
817+ metricsPort := corev1ac .ContainerPort ().WithContainerPort (2381 )
818+ dataMount := corev1ac .VolumeMount ().WithMountPath ("/var/lib/etcd" )
819+ certMount := corev1ac .VolumeMount ().WithMountPath ("/etc/etcd" )
820+
821+ args := reconciler .buildEtcdArgs (
822+ context .Background (),
823+ hcp ,
824+ cluster ,
825+ tt .etcdVersion ,
826+ dataMount ,
827+ certMount ,
828+ serverPort ,
829+ peerPort ,
830+ metricsPort ,
831+ )
832+
833+ if tt .expectSnapshotCount {
834+ g .Expect (args ).To (ContainElement ("--snapshot-count=10000" ))
835+ } else {
836+ g .Expect (args ).NotTo (ContainElement (ContainSubstring ("snapshot-count" )))
837+ }
838+ })
839+ }
840+ }
0 commit comments