@@ -503,6 +503,90 @@ func TestNewLBSpecSuccess(t *testing.T) {
503503 }
504504}
505505
506+ func TestNewLBSpecSingleAD (t * testing.T ) {
507+ testCases := map [string ]struct {
508+ defaultSubnetOne string
509+ defaultSubnetTwo string
510+ nodes []* v1.Node
511+ service * v1.Service
512+ expected * LBSpec
513+ }{
514+ "single subnet for single AD" : {
515+ defaultSubnetOne : "one" ,
516+ service : & v1.Service {
517+ ObjectMeta : metav1.ObjectMeta {
518+ Namespace : "kube-system" ,
519+ Name : "testservice" ,
520+ UID : "test-uid" ,
521+ Annotations : map [string ]string {
522+ ServiceAnnotationLoadBalancerBEProtocol : "" ,
523+ ServiceAnnotationLoadBalancerSubnet1 : "annotation-one" ,
524+ },
525+ },
526+ Spec : v1.ServiceSpec {
527+ SessionAffinity : v1 .ServiceAffinityNone ,
528+ Ports : []v1.ServicePort {
529+ v1.ServicePort {
530+ Protocol : v1 .ProtocolTCP ,
531+ Port : int32 (80 ),
532+ },
533+ },
534+ },
535+ },
536+ expected : & LBSpec {
537+ Name : "test-uid" ,
538+ Shape : "100Mbps" ,
539+ Internal : false ,
540+ Subnets : []string {"annotation-one" },
541+ Listeners : map [string ]loadbalancer.ListenerDetails {
542+ "TCP-80" : loadbalancer.ListenerDetails {
543+ DefaultBackendSetName : common .String ("TCP-80" ),
544+ Port : common .Int (80 ),
545+ Protocol : common .String ("TCP" ),
546+ },
547+ },
548+ BackendSets : map [string ]loadbalancer.BackendSetDetails {
549+ "TCP-80" : loadbalancer.BackendSetDetails {
550+ Backends : []loadbalancer.BackendDetails {},
551+ HealthChecker : & loadbalancer.HealthCheckerDetails {
552+ Protocol : common .String ("HTTP" ),
553+ Port : common .Int (10256 ),
554+ UrlPath : common .String ("/healthz" ),
555+ },
556+ Policy : common .String ("ROUND_ROBIN" ),
557+ },
558+ },
559+ SourceCIDRs : []string {"0.0.0.0/0" },
560+ Ports : map [string ]portSpec {
561+ "TCP-80" : portSpec {
562+ ListenerPort : 80 ,
563+ HealthCheckerPort : 10256 ,
564+ },
565+ },
566+ securityListManager : newSecurityListManagerNOOP (),
567+ },
568+ },
569+ }
570+ for name , tc := range testCases {
571+ t .Run (name , func (t * testing.T ) {
572+ // we expect the service to be unchanged
573+ tc .expected .service = tc .service
574+ subnets := []string {tc .defaultSubnetOne }
575+ slManagerFactory := func (mode string ) securityListManager {
576+ return newSecurityListManagerNOOP ()
577+ }
578+ result , err := NewLBSpec (tc .service , tc .nodes , subnets , nil , slManagerFactory )
579+ if err != nil {
580+ t .Error (err )
581+ }
582+
583+ if ! reflect .DeepEqual (result , tc .expected ) {
584+ t .Errorf ("Expected load balancer spec\n %+v\n but got\n %+v" , tc .expected , result )
585+ }
586+ })
587+ }
588+ }
589+
506590func TestNewLBSpecFailure (t * testing.T ) {
507591 testCases := map [string ]struct {
508592 defaultSubnetOne string
@@ -566,21 +650,6 @@ func TestNewLBSpecFailure(t *testing.T) {
566650 },
567651 expectedErrMsg : "error parsing service annotation: service.beta.kubernetes.io/oci-load-balancer-connection-idle-timeout=whoops" ,
568652 },
569- "missing subnet defaults and annotations" : {
570- service : & v1.Service {
571- ObjectMeta : metav1.ObjectMeta {
572- Namespace : "kube-system" ,
573- Name : "testservice" ,
574- UID : "test-uid" ,
575- Annotations : map [string ]string {},
576- },
577- Spec : v1.ServiceSpec {
578- SessionAffinity : v1 .ServiceAffinityNone ,
579- Ports : []v1.ServicePort {},
580- },
581- },
582- expectedErrMsg : "a configuration for both subnets must be specified" ,
583- },
584653 "internal lb missing subnet1" : {
585654 defaultSubnetTwo : "two" ,
586655 service : & v1.Service {
0 commit comments