@@ -12,13 +12,15 @@ 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 clientv3 "go.etcd.io/etcd/client/v3"
2021 "k8s.io/apimachinery/pkg/api/resource"
2122 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+ corev1ac "k8s.io/client-go/applyconfigurations/core/v1"
2224)
2325
2426func TestEtcdClusterReconciler_getETCDVolumeSize (t * testing.T ) {
@@ -883,3 +885,60 @@ func TestEtcdClusterReconciler_reconcileETCDBackup(t *testing.T) {
883885 g .Expect (hcp .Status .ETCDNextBackupTime ).NotTo (BeZero ())
884886 })
885887}
888+
889+ func TestBuildEtcdArgs_SnapshotCount (t * testing.T ) {
890+ tests := []struct {
891+ name string
892+ etcdVersion semver.Version
893+ expectSnapshotCount bool
894+ }{
895+ {
896+ name : "version < 3.7 sets snapshot-count" ,
897+ etcdVersion : semver .MustParse ("3.6.0" ),
898+ expectSnapshotCount : true ,
899+ },
900+ {
901+ name : "version >= 3.7 omits snapshot-count" ,
902+ etcdVersion : semver .MustParse ("3.7.0" ),
903+ expectSnapshotCount : false ,
904+ },
905+ }
906+
907+ for _ , tt := range tests {
908+ t .Run (tt .name , func (t * testing.T ) {
909+ g := NewWithT (t )
910+
911+ reconciler := & etcdClusterReconciler {}
912+ hcp := & v1alpha1.HostedControlPlane {
913+ ObjectMeta : metav1.ObjectMeta {Namespace : "test-ns" },
914+ Status : v1alpha1.HostedControlPlaneStatus {ETCDVolumeSize : resource .MustParse ("10Gi" )},
915+ }
916+ cluster := & capiv2.Cluster {
917+ ObjectMeta : metav1.ObjectMeta {Name : "test-cluster" , Namespace : "test-ns" },
918+ }
919+ serverPort := corev1ac .ContainerPort ().WithContainerPort (2379 )
920+ peerPort := corev1ac .ContainerPort ().WithContainerPort (2380 )
921+ metricsPort := corev1ac .ContainerPort ().WithContainerPort (2381 )
922+ dataMount := corev1ac .VolumeMount ().WithMountPath ("/var/lib/etcd" )
923+ certMount := corev1ac .VolumeMount ().WithMountPath ("/etc/etcd" )
924+
925+ args := reconciler .buildEtcdArgs (
926+ context .Background (),
927+ hcp ,
928+ cluster ,
929+ tt .etcdVersion ,
930+ dataMount ,
931+ certMount ,
932+ serverPort ,
933+ peerPort ,
934+ metricsPort ,
935+ )
936+
937+ if tt .expectSnapshotCount {
938+ g .Expect (args ).To (ContainElement ("--snapshot-count=10000" ))
939+ } else {
940+ g .Expect (args ).NotTo (ContainElement (ContainSubstring ("snapshot-count" )))
941+ }
942+ })
943+ }
944+ }
0 commit comments