@@ -10,17 +10,18 @@ package vcdsdk
1010import (
1111 "context"
1212 "fmt"
13+ "net/http"
14+ "net/url"
15+ "strconv"
16+ "strings"
17+
1318 "github.com/antihax/optional"
1419 "github.com/peterhellberg/link"
1520 "github.com/vmware/cloud-provider-for-cloud-director/pkg/util"
1621 swaggerClient "github.com/vmware/cloud-provider-for-cloud-director/pkg/vcdswaggerclient_36_0"
1722 "github.com/vmware/go-vcloud-director/v2/govcd"
1823 "github.com/vmware/go-vcloud-director/v2/types/v56"
1924 "k8s.io/klog"
20- "net/http"
21- "net/url"
22- "strconv"
23- "strings"
2425)
2526
2627type OneArm struct {
@@ -1104,7 +1105,7 @@ func (gatewayManager *GatewayManager) checkIfGatewayIsReady(ctx context.Context)
11041105}
11051106
11061107func (gatewayManager * GatewayManager ) UpdateVirtualService (ctx context.Context , virtualServiceName string ,
1107- virtualServiceIP string , externalPort int32 , oneArmEnabled bool ) (* swaggerClient.EntityReference , error ) {
1108+ virtualServiceIP string , externalPort int32 , oneArmEnabled bool , applicationProfile string ) (* swaggerClient.EntityReference , error ) {
11081109 client := gatewayManager .Client
11091110 vsSummary , err := gatewayManager .GetVirtualService (ctx , virtualServiceName )
11101111 if err != nil {
@@ -1147,6 +1148,11 @@ func (gatewayManager *GatewayManager) UpdateVirtualService(ctx context.Context,
11471148 // update the virtual IP address of the virtual service when one arm is nil
11481149 vs .VirtualIpAddress = virtualServiceIP
11491150 }
1151+
1152+ if applicationProfile != "" && vs .ApplicationProfile .Name != applicationProfile {
1153+ vs .ApplicationProfile .Name = applicationProfile
1154+ }
1155+
11501156 resp , err := client .APIClient .EdgeGatewayLoadBalancerVirtualServiceApi .UpdateVirtualService (ctx , vs , vsSummary .Id , org .Org .ID )
11511157 if resp != nil && resp .StatusCode != http .StatusAccepted {
11521158 var responseMessageBytes []byte
@@ -1187,7 +1193,7 @@ func (gatewayManager *GatewayManager) UpdateVirtualService(ctx context.Context,
11871193func (gatewayManager * GatewayManager ) CreateVirtualService (ctx context.Context , virtualServiceName string ,
11881194 lbPoolRef * swaggerClient.EntityReference , segRef * swaggerClient.EntityReference ,
11891195 freeIP string , vsType string , externalPort int32 ,
1190- useSSL bool , certificateAlias string ) (* swaggerClient.EntityReference , error ) {
1196+ useSSL bool , certificateAlias , applicationProfile string ) (* swaggerClient.EntityReference , error ) {
11911197
11921198 client := gatewayManager .Client
11931199 if gatewayManager .GatewayRef == nil {
@@ -1231,9 +1237,7 @@ func (gatewayManager *GatewayManager) CreateVirtualService(ctx context.Context,
12311237 SslEnabled : useSSL ,
12321238 },
12331239 },
1234- ApplicationProfile : & swaggerClient.EdgeLoadBalancerApplicationProfile {
1235- SystemDefined : true ,
1236- },
1240+ ApplicationProfile : & swaggerClient.EdgeLoadBalancerApplicationProfile {},
12371241 }
12381242 switch vsType {
12391243 case "TCP" :
@@ -1259,6 +1263,10 @@ func (gatewayManager *GatewayManager) CreateVirtualService(ctx context.Context,
12591263 return nil , fmt .Errorf ("unhandled virtual service type [%s]" , vsType )
12601264 }
12611265
1266+ if applicationProfile != "" {
1267+ virtualServiceConfig .ApplicationProfile .Name = applicationProfile
1268+ }
1269+
12621270 clusterOrg , err := client .VCDClient .GetOrgByName (client .ClusterOrgName )
12631271 if err != nil {
12641272 return nil , fmt .Errorf ("unable to get org for org [%s]: [%v]" , client .ClusterOrgName , err )
@@ -1502,7 +1510,7 @@ func (gatewayManager *GatewayManager) GetLoadBalancerPoolMemberIPs(ctx context.C
15021510
15031511func (gm * GatewayManager ) CreateLoadBalancer (ctx context.Context , virtualServiceNamePrefix string , lbPoolNamePrefix string ,
15041512 ips []string , portDetailsList []PortDetails , oneArm * OneArm , enableVirtualServiceSharedIP bool ,
1505- portNameToIP map [string ]string , providedIP string , resourcesAllocated * util.AllocatedResourcesMap ) (string , error ) {
1513+ portNameToIP map [string ]string , providedIP string , resourcesAllocated * util.AllocatedResourcesMap , applicationProfile string ) (string , error ) {
15061514 if len (portDetailsList ) == 0 {
15071515 // nothing to do here
15081516 klog .Infof ("There is no port specified. Hence nothing to do." )
@@ -1707,7 +1715,7 @@ func (gm *GatewayManager) CreateLoadBalancer(ctx context.Context, virtualService
17071715
17081716 virtualServiceRef , err := gm .CreateVirtualService (ctx , virtualServiceName , lbPoolRef , segRef ,
17091717 virtualServiceIP , portDetails .Protocol , portDetails .ExternalPort ,
1710- portDetails .UseSSL , portDetails .CertAlias )
1718+ portDetails .UseSSL , portDetails .CertAlias , applicationProfile )
17111719 if err != nil {
17121720 // return plain error if vcdsdk.VirtualServicePendingError is returned. Helps the caller recognize that the
17131721 // error is because VirtualService is still in Pending state.
@@ -1833,7 +1841,7 @@ func (gm *GatewayManager) DeleteLoadBalancer(ctx context.Context, virtualService
18331841
18341842func (gm * GatewayManager ) UpdateLoadBalancer (ctx context.Context , lbPoolName string , virtualServiceName string ,
18351843 ips []string , externalIP string , internalPort int32 , externalPort int32 , oneArm * OneArm , enableVirtualServiceSharedIP bool , protocol string ,
1836- resourcesAllocated * util.AllocatedResourcesMap ) (string , error ) {
1844+ resourcesAllocated * util.AllocatedResourcesMap , applicationProfile string ) (string , error ) {
18371845
18381846 if gm == nil {
18391847 return "" , fmt .Errorf ("GatewayManager cannot be nil" )
@@ -1852,7 +1860,7 @@ func (gm *GatewayManager) UpdateLoadBalancer(ctx context.Context, lbPoolName str
18521860 return "" , fmt .Errorf ("unable to update load balancer pool [%s]: [%v]" , lbPoolName , err )
18531861 }
18541862 resourcesAllocated .Insert (VcdResourceLoadBalancerPool , lbPoolRef )
1855- vsRef , err := gm .UpdateVirtualService (ctx , virtualServiceName , externalIP , externalPort , oneArm != nil )
1863+ vsRef , err := gm .UpdateVirtualService (ctx , virtualServiceName , externalIP , externalPort , oneArm != nil , applicationProfile )
18561864 if vsRef != nil {
18571865 resourcesAllocated .Insert (VcdResourceVirtualService , vsRef )
18581866 }
0 commit comments