Skip to content

Commit cd036c1

Browse files
authored
Merge pull request #380 from oracle/oke-119-pending
Await workrequest for UpdateNSG and UpdateLBShape
2 parents 3125d72 + d3bd020 commit cd036c1

8 files changed

+225
-19
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ cloud-provider specific code out of the Kubernetes codebase.
2727
| \>=v 0.11 | v1.16 | v1.18 |
2828
| \>=v 0.12 | v1.18 | v1.21 |
2929
| \>=v 0.13 | v1.19 | v1.21 |
30+
| v1.19.12 | v1.19 | v1.21 |
3031

3132
Note:
3233
Versions older than v0.13.0 are no longer supported, new features / bug fixes will be available in v0.13.0 and later.

docs/expand-block-volume-using-csi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Create PVC
88

9-
```bash
9+
```yaml
1010
apiVersion: v1
1111
kind: PersistentVolumeClaim
1212
metadata:
@@ -22,7 +22,7 @@ spec:
2222
2323
## Create POD
2424
25-
```bash
25+
```yaml
2626
apiVersion: v1
2727
kind: Pod
2828
metadata:

docs/load-balancer-annotations.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
This file defines a list of [Service][4] `type: LoadBalancer` annotations which are
44
supported by the `oci-cloud-controller-manager`.
55

6-
All annotations are prefixed with `service.beta.kubernetes.io/` or `oci.oraclecloud.com/`. For example:
6+
All annotations are prefixed with `service.beta.kubernetes.io/` or `oci.oraclecloud.com/` or `oci-network-load-balancer.oraclecloud.com/` (for OCI Network Load Balancer specific annotations). For example:
77

88
```yaml
99
kind: Service
1010
apiVersion: v1
1111
metadata:
1212
name: nginx-service
1313
annotations:
14+
oci.oraclecloud.com/load-balancer-type: "lb"
1415
service.beta.kubernetes.io/oci-load-balancer-shape: "400Mbps"
1516
service.beta.kubernetes.io/oci-load-balancer-subnet1: "ocid..."
1617
service.beta.kubernetes.io/oci-load-balancer-subnet2: "ocid..."
@@ -58,6 +59,49 @@ Note:
5859
- If an invalid mode is passed in the annotation, then the default (`"All"`) mode is configured.
5960
- If an annotation is not specified, the mode specified in the cloud provider config file is configured.
6061

62+
## Network Load Balancer
63+
64+
For example:
65+
66+
```yaml
67+
apiVersion: v1
68+
kind: Service
69+
metadata:
70+
name: example-nlb
71+
annotations:
72+
oci-network-load-balancer.oraclecloud.com/security-list-management-mode: "All"
73+
oci.oraclecloud.com/load-balancer-type: nlb
74+
spec:
75+
selector:
76+
app: example-nlb
77+
ports:
78+
- port: 8088
79+
targetPort: 80
80+
type: LoadBalancer
81+
externalTrafficPolicy: Local
82+
```
83+
84+
Note:
85+
- The only security list management mode allowed when backend protocol is UDP is "None"
86+
- `externalTrafficPolicy` should be "Local" for preserving source IP
87+
- We recommend to set the `security-list-management-mode` as "None" and configure NSG / Security rules on your own.
88+
89+
## Network Load Balancer Specific Annotations
90+
91+
| Name | Description | Default
92+
| ----- | ----------- | -------
93+
| `oci-network-load-balancer.oraclecloud.com/internal` | Create an [internal network load balancer][1]. Cannot be modified after load balancer creation. | `false`
94+
| `oci-network-load-balancer.oraclecloud.com/subnet` | The OCID of the required regional or AD specific subnet to attach the network load balancer. | Value set for the cluster
95+
| `oci-network-load-balancer.oraclecloud.com/oci-network-security-groups` | Specifies Network Security Groups' OCIDs to be associated with the network load balancer. | `""`
96+
| `oci-network-load-balancer.oraclecloud.com/initial-freeform-tags-override` | Specifies one or multiple Freeform tags to apply to the OCI Network Load Balancer. | `""`
97+
| `oci-network-load-balancer.oraclecloud.com/initial-defined-tags-override` | Specifies one or multiple Defined tags to apply to the OCI Network Load Balancer. | `""`
98+
| `oci-network-load-balancer.oraclecloud.com/health-check-retries` | The number of retries to attempt before a backend server is considered "unhealthy". | `3`
99+
| `oci-network-load-balancer.oraclecloud.com/health-check-timeout` | The maximum time, in milliseconds, to wait for a reply to a health check. A health check is successful only if a reply returns within this timeout period. | `3000 ms`
100+
| `oci-network-load-balancer.oraclecloud.com/health-check-interval` | The interval between health checks requests, in milliseconds. | `3000 ms`
101+
| `oci-network-load-balancer.oraclecloud.com/backend-policy` | The network load balancer policy for the backend set. Valid values: "TWO_TUPLE", "THREE_TUPLE", or "FIVE_TUPLE" | `"FIVE_TUPLE"`
102+
| `oci-network-load-balancer.oraclecloud.com/security-list-management-mode` | Specifies the security list mode ("All", "Frontend","None") to configure how security lists are managed. | `"None"`
103+
104+
61105
[1]: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer
62106
[2]: https://docs.us-phoenix-1.oraclecloud.com/Content/Network/Tasks/managingVCNs.htm
63107
[3]: https://kubernetes.io/docs/concepts/services-networking/ingress/#tls
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Block Volume Expansion using CSI
2+
3+
## Setup
4+
5+
1. Make sure you have installed [CCM](../README.md) and [CSI](../container-storage-interface.md) version v1.19.12 or later
6+
7+
To create a PVC backed by a block volume with a Lower Cost, Balanced, or Higher Performance performance level, set vpusPerGB in the storage class definition as follows:
8+
9+
* for a Lower Cost performance level, set vpusPerGB: "0"
10+
* for a Balanced performance level, set vpusPerGB: "10"
11+
* for a Higher Performance performance level, set vpusPerGB: "20"
12+
13+
## Create Storage Class for high performance
14+
```yaml
15+
apiVersion: storage.k8s.io/v1
16+
kind: StorageClass
17+
metadata:
18+
name: oci-high
19+
provisioner: blockvolume.csi.oraclecloud.com
20+
parameters:
21+
vpusPerGB: "20"
22+
reclaimPolicy: Delete
23+
volumeBindingMode: WaitForFirstConsumer
24+
allowVolumeExpansion: true
25+
```
26+
27+
The value of vpusPerGB must be "0", "10", or "20". Other values are not supported.
28+
29+
## Create PVC
30+
31+
```yaml
32+
apiVersion: v1
33+
kind: PersistentVolumeClaim
34+
metadata:
35+
name: oci-pvc-high
36+
spec:
37+
storageClassName: oci-high
38+
accessModes:
39+
- ReadWriteOnce
40+
resources:
41+
requests:
42+
storage: 50Gi
43+
```
44+
45+
## Create POD
46+
47+
```yaml
48+
apiVersion: v1
49+
kind: Pod
50+
metadata:
51+
name: app1
52+
spec:
53+
containers:
54+
- name: app1
55+
image: centos
56+
command: ["/bin/sh"]
57+
args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"]
58+
volumeMounts:
59+
- name: persistent-storage
60+
mountPath: /data
61+
volumes:
62+
- name: persistent-storage
63+
persistentVolumeClaim:
64+
claimName: oci-pvc-high
65+
```
66+
67+
For more information refer [CSI BV Performance Doc][1]
68+
69+
Note:
70+
Performance of block volume can be specified at the creation itself. Performance (vpusPerGB) cannot be modified after volume is provisioned.
71+
CSI version 1.19.12 or later which runs on k8s cluster 1.19 or later supports block volume expansion.
72+
Flex volume does not support.
73+
74+
[1]: https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengcreatingpersistentvolumeclaim.htm#contengcreatingpersistentvolumeclaim_topic_Provisioning_PVCs_on_BV_PV_Volume_performance

docs/using-network-load-balancer.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Network load balancer
2+
3+
## Setup
4+
5+
1. Make sure you have installed [CCM](../README.md) version v1.19.12 or later
6+
7+
## Create Service
8+
9+
```yaml
10+
apiVersion: v1
11+
kind: Service
12+
metadata:
13+
name: example-nlb
14+
annotations:
15+
oci-network-load-balancer.oraclecloud.com/security-list-management-mode: "All"
16+
oci.oraclecloud.com/load-balancer-type: nlb
17+
spec:
18+
selector:
19+
app: example-nlb
20+
ports:
21+
- port: 8088
22+
targetPort: 80
23+
type: LoadBalancer
24+
externalTrafficPolicy: Local
25+
```
26+
For more info please refer [OKE NLB DOC][1]
27+
28+
[1]: https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengcreatingloadbalancer.htm#contengcreatingnetworkloadbalancers

pkg/cloudprovider/providers/oci/instances_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,17 +460,35 @@ func (c *MockLoadBalancerClient) DeleteListener(ctx context.Context, lbID, name
460460
return "", nil
461461
}
462462

463+
var awaitLoadbalancerWorkrequestMap = map[string]error{
464+
"failedToGetUpdateNetworkSecurityGroupsWorkRequest": errors.New("internal server error for get workrequest call"),
465+
}
466+
463467
func (c *MockLoadBalancerClient) AwaitWorkRequest(ctx context.Context, id string) (*client.GenericWorkRequest, error) {
468+
if err, ok := awaitLoadbalancerWorkrequestMap[id]; ok {
469+
return nil, err
470+
}
464471
return nil, nil
465472
}
466473

467474
func (c *MockLoadBalancerClient) UpdateLoadBalancerShape(context.Context, string, *client.GenericUpdateLoadBalancerShapeDetails) (string, error) {
468475
return "", nil
469476
}
470477

478+
var updateNetworkSecurityGroupsLBsFailures = map[string]error{
479+
"": errors.New("provided LB ID is empty"),
480+
"failedToCreateRequest": errors.New("internal server error"),
481+
}
482+
var updateNetworkSecurityGroupsLBsWorkRequests = map[string]string{
483+
"failedToGetUpdateNetworkSecurityGroupsWorkRequest": "failedToGetUpdateNetworkSecurityGroupsWorkRequest",
484+
}
485+
471486
func (c *MockLoadBalancerClient) UpdateNetworkSecurityGroups(ctx context.Context, lbId string, nsgIds []string) (string, error) {
472-
if lbId == "" {
473-
return "", errors.New("provided LB ID is empty")
487+
if err, ok := updateNetworkSecurityGroupsLBsFailures[lbId]; ok {
488+
return "", err
489+
}
490+
if wrID, ok := updateNetworkSecurityGroupsLBsWorkRequests[lbId]; ok {
491+
return wrID, nil
474492
}
475493
return "", nil
476494
}

pkg/cloudprovider/providers/oci/load_balancer.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -983,23 +983,35 @@ func (clb *CloudLoadBalancerProvider) updateLoadbalancerShape(ctx context.Contex
983983
MaximumBandwidthInMbps: spec.FlexMax,
984984
}
985985
}
986-
opcRequestID, err := clb.lbClient.UpdateLoadBalancerShape(ctx, *lb.Id, &shapeDetails)
986+
wrID, err := clb.lbClient.UpdateLoadBalancerShape(ctx, *lb.Id, &shapeDetails)
987987
if err != nil {
988-
return errors.Wrap(err, "failed to update loadbalancer shape")
988+
return errors.Wrap(err, "failed to create UpdateLoadBalancerShape request")
989989
}
990-
clb.logger.With("old-shape", *lb.ShapeName, "new-shape", spec.Shape,
990+
logger := clb.logger.With("old-shape", *lb.ShapeName, "new-shape", spec.Shape,
991991
"flexMinimumMbps", spec.FlexMin, "flexMaximumMbps", spec.FlexMax,
992-
"opc-request-id", opcRequestID, "loadBalancerType", getLoadBalancerType(spec.service)).Info("Successfully created an loadbalancer update shape request")
992+
"opc-workrequest-id", wrID, "loadBalancerType", getLoadBalancerType(spec.service))
993+
logger.Info("Awaiting UpdateLoadBalancerShape workrequest")
994+
_, err = clb.lbClient.AwaitWorkRequest(ctx, wrID)
995+
if err != nil {
996+
return err
997+
}
998+
logger.Info("UpdateLoadBalancerShape request completed successfully")
993999
return nil
9941000
}
9951001

9961002
func (clb *CloudLoadBalancerProvider) updateLoadBalancerNetworkSecurityGroups(ctx context.Context, lb *client.GenericLoadBalancer, spec *LBSpec) error {
997-
opcRequestID, err := clb.lbClient.UpdateNetworkSecurityGroups(ctx, *lb.Id, spec.NetworkSecurityGroupIds)
1003+
wrID, err := clb.lbClient.UpdateNetworkSecurityGroups(ctx, *lb.Id, spec.NetworkSecurityGroupIds)
1004+
if err != nil {
1005+
return errors.Wrap(err, "failed to create UpdateNetworkSecurityGroups request")
1006+
}
1007+
logger := clb.logger.With("existingNSGIds", lb.NetworkSecurityGroupIds, "newNSGIds", spec.NetworkSecurityGroupIds,
1008+
"opc-workrequest-id", wrID)
1009+
logger.Info("Awaiting UpdateNetworkSecurityGroups workrequest")
1010+
_, err = clb.lbClient.AwaitWorkRequest(ctx, wrID)
9981011
if err != nil {
999-
return errors.Wrap(err, "failed to update loadbalancer Network Security Group")
1012+
return errors.Wrap(err, "failed to await UpdateNetworkSecurityGroups workrequest")
10001013
}
1001-
clb.logger.With("existingNSGIds", lb.NetworkSecurityGroupIds, "newNSGIds", spec.NetworkSecurityGroupIds,
1002-
"opc-request-id", opcRequestID).Info("successfully updated the network security groups")
1014+
logger.Info("Loadbalancer UpdateNetworkSecurityGroups workrequest completed successfully")
10031015
return nil
10041016
}
10051017

pkg/cloudprovider/providers/oci/load_balancer_test.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424
v1 "k8s.io/api/core/v1"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626

27+
providercfg "github.com/oracle/oci-cloud-controller-manager/pkg/cloudprovider/providers/oci/config"
28+
"github.com/oracle/oci-cloud-controller-manager/pkg/oci/client"
2729
"github.com/oracle/oci-go-sdk/v50/common"
2830
"github.com/oracle/oci-go-sdk/v50/core"
29-
"github.com/oracle/oci-cloud-controller-manager/pkg/oci/client"
30-
providercfg "github.com/oracle/oci-cloud-controller-manager/pkg/cloudprovider/providers/oci/config"
3131
)
3232

3333
func Test_getDefaultLBSubnets(t *testing.T) {
@@ -476,7 +476,7 @@ func TestUpdateLoadBalancerNetworkSecurityGroups(t *testing.T) {
476476
loadbalancer *client.GenericLoadBalancer
477477
wantErr error
478478
}{
479-
"Update NSG when there's an issue with LB": {
479+
"lb id is missing": {
480480
spec: &LBSpec{
481481
Name: "test",
482482
NetworkSecurityGroupIds: []string{"ocid1"},
@@ -485,7 +485,29 @@ func TestUpdateLoadBalancerNetworkSecurityGroups(t *testing.T) {
485485
Id: common.String(""),
486486
DisplayName: common.String("privateLB"),
487487
},
488-
wantErr: errors.New("failed to update loadbalancer Network Security Group: provided LB ID is empty"),
488+
wantErr: errors.New("failed to create UpdateNetworkSecurityGroups request: provided LB ID is empty"),
489+
},
490+
"failed to create workrequest": {
491+
spec: &LBSpec{
492+
Name: "test",
493+
NetworkSecurityGroupIds: []string{"ocid1"},
494+
},
495+
loadbalancer: &client.GenericLoadBalancer{
496+
Id: common.String("failedToCreateRequest"),
497+
DisplayName: common.String("privateLB"),
498+
},
499+
wantErr: errors.New("failed to create UpdateNetworkSecurityGroups request: internal server error"),
500+
},
501+
"failed to get workrequest": {
502+
spec: &LBSpec{
503+
Name: "test",
504+
NetworkSecurityGroupIds: []string{"ocid1"},
505+
},
506+
loadbalancer: &client.GenericLoadBalancer{
507+
Id: common.String("failedToGetUpdateNetworkSecurityGroupsWorkRequest"),
508+
DisplayName: common.String("privateLB"),
509+
},
510+
wantErr: errors.New("failed to await UpdateNetworkSecurityGroups workrequest: internal server error for get workrequest call"),
489511
},
490512
"Update NSG to existing LB": {
491513
spec: &LBSpec{
@@ -507,8 +529,8 @@ func TestUpdateLoadBalancerNetworkSecurityGroups(t *testing.T) {
507529
for name, tt := range tests {
508530
t.Run(name, func(t *testing.T) {
509531
err := cp.updateLoadBalancerNetworkSecurityGroups(context.Background(), tt.loadbalancer, tt.spec)
510-
if err != nil && err.Error() != tt.wantErr.Error() {
511-
t.Errorf("Expected error = %v, but got %v", err, tt.wantErr)
532+
if !assertError(err, tt.wantErr) {
533+
t.Errorf("Expected error = %v, but got %v", tt.wantErr, err)
512534
return
513535
}
514536
})
@@ -626,3 +648,10 @@ func TestCloudProvider_EnsureLoadBalancerDeleted(t *testing.T) {
626648
})
627649
}
628650
}
651+
652+
func assertError(actual, expected error) bool {
653+
if expected == nil || actual == nil {
654+
return expected == actual
655+
}
656+
return actual.Error() == expected.Error()
657+
}

0 commit comments

Comments
 (0)