Skip to content

Commit 9458977

Browse files
committed
add application profile annotation support
1 parent cc91a95 commit 9458977

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

Diff for: pkg/ccm/loadbalancer.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ package ccm
1111
import (
1212
"context"
1313
"fmt"
14+
"strconv"
15+
"strings"
16+
1417
"github.com/vmware/cloud-provider-for-cloud-director/pkg/cpisdk"
1518
"github.com/vmware/cloud-provider-for-cloud-director/pkg/util"
1619
"github.com/vmware/cloud-provider-for-cloud-director/pkg/vcdsdk"
@@ -22,13 +25,12 @@ import (
2225
"k8s.io/client-go/kubernetes"
2326
cloudProvider "k8s.io/cloud-provider"
2427
"k8s.io/klog"
25-
"strconv"
26-
"strings"
2728
)
2829

2930
const (
3031
sslPortsAnnotation = `service.beta.kubernetes.io/vcloud-avi-ssl-ports`
3132
sslCertAliasAnnotation = `service.beta.kubernetes.io/vcloud-avi-ssl-cert-alias`
33+
applicationProfileAnnotation = `service.beta.kubernetes.io/vcloud-avi-application-profile`
3234
skipAviSSLTerminationAnnotation = `service.beta.kubernetes.io/vcloud-avi-ssl-no-termination`
3335
// TODO: Update controlPlaneLabel to use default K8s constants if available
3436
controlPlaneLabel = `node-role.kubernetes.io/control-plane`
@@ -504,6 +506,15 @@ func getSSLCertAlias(service *v1.Service) string {
504506
return sslCertAlias
505507
}
506508

509+
func getApplicationProfile(service *v1.Service) string {
510+
applicationProfile, ok := service.Annotations[applicationProfileAnnotation]
511+
if !ok {
512+
return ""
513+
}
514+
515+
return applicationProfile
516+
}
517+
507518
func shouldSkipAviSSLTermination(service *v1.Service) bool {
508519
shouldSkipAviSSLTerminationStr, ok := service.Annotations[skipAviSSLTerminationAnnotation]
509520
if !ok {
@@ -643,6 +654,8 @@ func (lb *LBManager) createLoadBalancer(ctx context.Context, service *v1.Service
643654
certAlias = ""
644655
}
645656

657+
applicationProfile := getApplicationProfile(service)
658+
646659
// golang doesn't have the set data structure
647660
portsMap := make(map[int32]bool)
648661
for _, port := range ports {
@@ -676,7 +689,7 @@ func (lb *LBManager) createLoadBalancer(ctx context.Context, service *v1.Service
676689
// Create using VCD API
677690
resourcesAllocated := &util.AllocatedResourcesMap{}
678691
lbIP, err := gm.CreateLoadBalancer(ctx, virtualServiceNamePrefix, lbPoolNamePrefix, nodeIPs, portDetailsList,
679-
lb.OneArm, lb.EnableVirtualServiceSharedIP, portNameToIPMap, userSpecifiedLBIP, resourcesAllocated)
692+
lb.OneArm, lb.EnableVirtualServiceSharedIP, portNameToIPMap, userSpecifiedLBIP, resourcesAllocated, applicationProfile)
680693
if rdeErr := lb.addLBResourcesToRDE(ctx, resourcesAllocated, lbIP); rdeErr != nil {
681694
return nil, fmt.Errorf("unable to add load balancer pool resources to RDE [%s]: [%v]", lb.clusterID, err)
682695
}

Diff for: pkg/vcdsdk/gateway.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ package vcdsdk
1010
import (
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

2627
type OneArm struct {
@@ -1187,7 +1188,7 @@ func (gatewayManager *GatewayManager) UpdateVirtualService(ctx context.Context,
11871188
func (gatewayManager *GatewayManager) CreateVirtualService(ctx context.Context, virtualServiceName string,
11881189
lbPoolRef *swaggerClient.EntityReference, segRef *swaggerClient.EntityReference,
11891190
freeIP string, vsType string, externalPort int32,
1190-
useSSL bool, certificateAlias string) (*swaggerClient.EntityReference, error) {
1191+
useSSL bool, certificateAlias, applicationProfile string) (*swaggerClient.EntityReference, error) {
11911192

11921193
client := gatewayManager.Client
11931194
if gatewayManager.GatewayRef == nil {
@@ -1259,6 +1260,10 @@ func (gatewayManager *GatewayManager) CreateVirtualService(ctx context.Context,
12591260
return nil, fmt.Errorf("unhandled virtual service type [%s]", vsType)
12601261
}
12611262

1263+
if len(applicationProfile) != 0 {
1264+
virtualServiceConfig.ApplicationProfile.Name = applicationProfile
1265+
}
1266+
12621267
clusterOrg, err := client.VCDClient.GetOrgByName(client.ClusterOrgName)
12631268
if err != nil {
12641269
return nil, fmt.Errorf("unable to get org for org [%s]: [%v]", client.ClusterOrgName, err)
@@ -1502,7 +1507,7 @@ func (gatewayManager *GatewayManager) GetLoadBalancerPoolMemberIPs(ctx context.C
15021507

15031508
func (gm *GatewayManager) CreateLoadBalancer(ctx context.Context, virtualServiceNamePrefix string, lbPoolNamePrefix string,
15041509
ips []string, portDetailsList []PortDetails, oneArm *OneArm, enableVirtualServiceSharedIP bool,
1505-
portNameToIP map[string]string, providedIP string, resourcesAllocated *util.AllocatedResourcesMap) (string, error) {
1510+
portNameToIP map[string]string, providedIP string, resourcesAllocated *util.AllocatedResourcesMap, applicationProfile string) (string, error) {
15061511
if len(portDetailsList) == 0 {
15071512
// nothing to do here
15081513
klog.Infof("There is no port specified. Hence nothing to do.")
@@ -1707,7 +1712,7 @@ func (gm *GatewayManager) CreateLoadBalancer(ctx context.Context, virtualService
17071712

17081713
virtualServiceRef, err := gm.CreateVirtualService(ctx, virtualServiceName, lbPoolRef, segRef,
17091714
virtualServiceIP, portDetails.Protocol, portDetails.ExternalPort,
1710-
portDetails.UseSSL, portDetails.CertAlias)
1715+
portDetails.UseSSL, portDetails.CertAlias, applicationProfile)
17111716
if err != nil {
17121717
// return plain error if vcdsdk.VirtualServicePendingError is returned. Helps the caller recognize that the
17131718
// error is because VirtualService is still in Pending state.

Diff for: pkg/vcdsdk/gateway_system_test.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ package vcdsdk
88
import (
99
"context"
1010
"fmt"
11+
"io/ioutil"
12+
"path/filepath"
13+
"testing"
14+
"time"
15+
1116
"github.com/google/uuid"
1217
"github.com/stretchr/testify/assert"
1318
"github.com/stretchr/testify/require"
1419
"github.com/vmware/cloud-provider-for-cloud-director/pkg/util"
1520
swaggerClient "github.com/vmware/cloud-provider-for-cloud-director/pkg/vcdswaggerclient_36_0"
1621
"gopkg.in/yaml.v2"
17-
"io/ioutil"
18-
"path/filepath"
19-
"testing"
20-
"time"
2122
)
2223

2324
const BusyRetries = 5
@@ -332,7 +333,7 @@ func TestVirtualServiceHttpCRUDE(t *testing.T) {
332333
var vsRef *swaggerClient.EntityReference
333334
for i := 0; i < BusyRetries; i++ {
334335
vsRef, err = gm.CreateVirtualService(ctx, virtualServiceName, lbPoolRef, segRef,
335-
internalIP, "HTTP", 80, false, "")
336+
internalIP, "HTTP", 80, false, "", "")
336337
if err != nil {
337338
if _, ok := err.(*VirtualServicePendingError); !ok {
338339
break
@@ -353,7 +354,7 @@ func TestVirtualServiceHttpCRUDE(t *testing.T) {
353354
// repeated creation should not fail
354355
for i := 0; i < BusyRetries; i++ {
355356
vsRef, err = gm.CreateVirtualService(ctx, virtualServiceName, lbPoolRef, segRef,
356-
internalIP, "HTTP", 80, false, "")
357+
internalIP, "HTTP", 80, false, "", "")
357358
if err != nil {
358359
if _, ok := err.(*VirtualServicePendingError); !ok {
359360
break
@@ -436,7 +437,7 @@ func TestVirtualServiceHttpsCRUDE(t *testing.T) {
436437
var vsRef *swaggerClient.EntityReference
437438
for i := 0; i < BusyRetries; i++ {
438439
vsRef, err = gm.CreateVirtualService(ctx, virtualServiceName, lbPoolRef, segRef,
439-
internalIP, "HTTP", 80, false, "")
440+
internalIP, "HTTP", 80, false, "", "")
440441
if err != nil {
441442
if _, ok := err.(*VirtualServicePendingError); !ok {
442443
break
@@ -455,7 +456,7 @@ func TestVirtualServiceHttpsCRUDE(t *testing.T) {
455456

456457
// repeated creation should not fail
457458
vsRef, err = gm.CreateVirtualService(ctx, virtualServiceName, lbPoolRef, segRef,
458-
internalIP, "HTTPS", 443, true, certName)
459+
internalIP, "HTTPS", 443, true, certName, "")
459460
assert.NoError(t, err, "Unable to create virtual service for the second time")
460461
require.NotNil(t, vsRef, "VirtualServiceRef should not be nil")
461462
assert.Equal(t, virtualServiceName, vsRef.Name, "Virtual Service name should match")
@@ -548,7 +549,7 @@ func TestLoadBalancerCRUDE(t *testing.T) {
548549
EndIP: "192.168.8.100",
549550
}
550551
freeIP, err = gm.CreateLoadBalancer(ctx, virtualServiceNamePrefix,
551-
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, false, nil, "", &util.AllocatedResourcesMap{})
552+
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, false, nil, "", &util.AllocatedResourcesMap{}, "")
552553
assert.NoError(t, err, "Load Balancer should be created")
553554
assert.NotEmpty(t, freeIP, "There should be a non-empty IP returned")
554555

@@ -567,7 +568,7 @@ func TestLoadBalancerCRUDE(t *testing.T) {
567568
assert.Equal(t, freeIP, freeIPObtained, "The IPs should match")
568569

569570
freeIP, err = gm.CreateLoadBalancer(ctx, virtualServiceNamePrefix,
570-
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, false, nil, "", &util.AllocatedResourcesMap{})
571+
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, false, nil, "", &util.AllocatedResourcesMap{}, "")
571572
assert.NoError(t, err, "Load Balancer should be created even on second attempt")
572573
assert.NotEmpty(t, freeIP, "There should be a non-empty IP returned")
573574

@@ -675,7 +676,7 @@ func TestLoadBalancer_ExplicitLBIP_OneArmDisabled_CRUDE(t *testing.T) {
675676

676677
var oneArm *OneArm
677678
freeIP, err = gm.CreateLoadBalancer(ctx, virtualServiceNamePrefix,
678-
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, true, nil, testConfig.FreeLoadBalancerIP, &util.AllocatedResourcesMap{})
679+
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, true, nil, testConfig.FreeLoadBalancerIP, &util.AllocatedResourcesMap{}, "")
679680
assert.NoError(t, err, "Load Balancer should be created")
680681
assert.NotEmpty(t, freeIP, "There should be a non-empty IP returned")
681682
assert.Equal(t, freeIP, testConfig.FreeLoadBalancerIP, "the provided external IP address should be the same as the load balancer IP address.")
@@ -695,7 +696,7 @@ func TestLoadBalancer_ExplicitLBIP_OneArmDisabled_CRUDE(t *testing.T) {
695696
assert.Equal(t, freeIP, freeIPObtained, "The IPs should match")
696697

697698
freeIP, err = gm.CreateLoadBalancer(ctx, virtualServiceNamePrefix,
698-
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, true, nil, testConfig.FreeLoadBalancerIP, &util.AllocatedResourcesMap{})
699+
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, true, nil, testConfig.FreeLoadBalancerIP, &util.AllocatedResourcesMap{}, "")
699700
assert.NoError(t, err, "Load Balancer should be created even on second attempt")
700701
assert.NotEmpty(t, freeIP, "There should be a non-empty IP returned")
701702
assert.Equal(t, freeIP, testConfig.FreeLoadBalancerIP, "the provided external IP address should be the same as the load balancer IP address.")
@@ -816,7 +817,7 @@ func TestLoadBalancer_ExplicitLBIP_OneArmEnabled_CRUDE(t *testing.T) {
816817
}
817818

818819
freeIP, err = gm.CreateLoadBalancer(ctx, virtualServiceNamePrefix,
819-
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, true, nil, testConfig.FreeLoadBalancerIP, &util.AllocatedResourcesMap{})
820+
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, true, nil, testConfig.FreeLoadBalancerIP, &util.AllocatedResourcesMap{}, "")
820821
assert.NoError(t, err, "Load Balancer should be created")
821822
assert.NotEmpty(t, freeIP, "There should be a non-empty IP returned")
822823
assert.Equal(t, freeIP, testConfig.FreeLoadBalancerIP, "the provided external IP address should be the same as the load balancer IP address.")
@@ -836,7 +837,7 @@ func TestLoadBalancer_ExplicitLBIP_OneArmEnabled_CRUDE(t *testing.T) {
836837
assert.Equal(t, freeIP, freeIPObtained, "The IPs should match")
837838

838839
freeIP, err = gm.CreateLoadBalancer(ctx, virtualServiceNamePrefix,
839-
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, true, nil, testConfig.FreeLoadBalancerIP, &util.AllocatedResourcesMap{})
840+
lbPoolNamePrefix, []string{"1.2.3.4", "1.2.3.5"}, portDetailsList, oneArm, true, nil, testConfig.FreeLoadBalancerIP, &util.AllocatedResourcesMap{}, "")
840841
assert.NoError(t, err, "Load Balancer should be created even on second attempt")
841842
assert.NotEmpty(t, freeIP, "There should be a non-empty IP returned")
842843

0 commit comments

Comments
 (0)