Skip to content

Commit d953295

Browse files
pranavsriram8l-technicore
authored andcommitted
fixing annotation string to match documentation and update respective unit tests
1 parent 94adc61 commit d953295

File tree

2 files changed

+100
-14
lines changed

2 files changed

+100
-14
lines changed

pkg/cloudprovider/providers/oci/load_balancer_spec.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,23 @@ const (
178178
// specifying the security list management mode ("All", "Frontend", "None") that configures how security lists are managed by the CCM
179179
ServiceAnnotationNetworkLoadBalancerSecurityListManagementMode = "oci-network-load-balancer.oraclecloud.com/security-list-management-mode"
180180

181+
// ServiceAnnotationNetworkLoadBalancerDefinedTags is a service annotation for specifying
182+
// defined tags on the nlb
183+
// DEPRECATED
184+
ServiceAnnotationNetworkLoadBalancerDefinedTags = "oci-network-load-balancer.oraclecloud.com/defined-tags"
185+
186+
// ServiceAnnotationNetworkLoadBalancerFreeformTags is a service annotation for specifying
187+
// freeform tags on the nlb
188+
// DEPRECATED
189+
ServiceAnnotationNetworkLoadBalancerFreeformTags = "oci-network-load-balancer.oraclecloud.com/freeform-tags"
190+
181191
// ServiceAnnotationNetworkLoadBalancerInitialDefinedTagsOverride is a service annotation for specifying
182192
// defined tags on the nlb
183-
ServiceAnnotationNetworkLoadBalancerInitialDefinedTagsOverride = "oci-network-load-balancer.oraclecloud.com/defined-tags"
193+
ServiceAnnotationNetworkLoadBalancerInitialDefinedTagsOverride = "oci-network-load-balancer.oraclecloud.com/initial-defined-tags-override"
184194

185195
// ServiceAnnotationNetworkLoadBalancerInitialFreeformTagsOverride is a service annotation for specifying
186196
// freeform tags on the nlb
187-
ServiceAnnotationNetworkLoadBalancerInitialFreeformTagsOverride = "oci-network-load-balancer.oraclecloud.com/freeform-tags"
197+
ServiceAnnotationNetworkLoadBalancerInitialFreeformTagsOverride = "oci-network-load-balancer.oraclecloud.com/initial-freeform-tags-override"
188198

189199
// ServiceAnnotationNetworkLoadBalancerNodeFilter is a service annotation to select specific nodes as your backend in the NLB
190200
// based on label selector.
@@ -1041,6 +1051,14 @@ func getLoadBalancerTags(svc *v1.Service, initialTags *config.InitialTags) (*con
10411051
{
10421052
freeformTagsAnnotation, freeformTagsAnnotationExists = svc.Annotations[ServiceAnnotationNetworkLoadBalancerInitialFreeformTagsOverride]
10431053
definedTagsAnnotation, definedTagsAnnotationExists = svc.Annotations[ServiceAnnotationNetworkLoadBalancerInitialDefinedTagsOverride]
1054+
1055+
if !freeformTagsAnnotationExists {
1056+
freeformTagsAnnotation, freeformTagsAnnotationExists = svc.Annotations[ServiceAnnotationNetworkLoadBalancerFreeformTags]
1057+
}
1058+
1059+
if !definedTagsAnnotationExists {
1060+
definedTagsAnnotation, definedTagsAnnotationExists = svc.Annotations[ServiceAnnotationNetworkLoadBalancerDefinedTags]
1061+
}
10441062
}
10451063
default:
10461064
{

pkg/cloudprovider/providers/oci/load_balancer_spec_test.go

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3489,6 +3489,74 @@ func Test_getLoadBalancerTags(t *testing.T) {
34893489
},
34903490
err: nil,
34913491
},
3492+
"reverse compatibility tags test for nlb 1": {
3493+
service: &v1.Service{
3494+
ObjectMeta: metav1.ObjectMeta{
3495+
Annotations: map[string]string{
3496+
ServiceAnnotationLoadBalancerType: "nlb",
3497+
ServiceAnnotationNetworkLoadBalancerFreeformTags: `{"cluster":"resource1", "unique":"tag1"}`,
3498+
ServiceAnnotationNetworkLoadBalancerDefinedTags: `{"namespace":{"key":"value1", "owner":"team1"}}`,
3499+
ServiceAnnotationNetworkLoadBalancerInitialFreeformTagsOverride: `{"cluster":"resource", "unique":"tag"}`,
3500+
ServiceAnnotationNetworkLoadBalancerInitialDefinedTagsOverride: `{"namespace":{"key":"value", "owner":"team"}}`,
3501+
},
3502+
},
3503+
},
3504+
desiredLBTags: &providercfg.TagConfig{
3505+
FreeformTags: map[string]string{"cluster": "resource", "unique": "tag"},
3506+
DefinedTags: map[string]map[string]interface{}{"namespace": {"owner": "team", "key": "value"}},
3507+
},
3508+
err: nil,
3509+
},
3510+
"reverse compatibility tags test for nlb 2": {
3511+
service: &v1.Service{
3512+
ObjectMeta: metav1.ObjectMeta{
3513+
Annotations: map[string]string{
3514+
ServiceAnnotationLoadBalancerType: "nlb",
3515+
ServiceAnnotationNetworkLoadBalancerFreeformTags: `{"cluster":"resource1", "unique":"tag1"}`,
3516+
ServiceAnnotationNetworkLoadBalancerDefinedTags: `{"namespace":{"key":"value1", "owner":"team1"}}`,
3517+
},
3518+
},
3519+
},
3520+
desiredLBTags: &providercfg.TagConfig{
3521+
FreeformTags: map[string]string{"cluster": "resource1", "unique": "tag1"},
3522+
DefinedTags: map[string]map[string]interface{}{"namespace": {"owner": "team1", "key": "value1"}},
3523+
},
3524+
err: nil,
3525+
},
3526+
"reverse compatibility tags test for nlb 3": {
3527+
service: &v1.Service{
3528+
ObjectMeta: metav1.ObjectMeta{
3529+
Annotations: map[string]string{
3530+
ServiceAnnotationLoadBalancerType: "nlb",
3531+
ServiceAnnotationNetworkLoadBalancerFreeformTags: `{"cluster":"resource1", "unique":"tag1"}`,
3532+
ServiceAnnotationNetworkLoadBalancerDefinedTags: `{"namespace":{"key":"value1", "owner":"team1"}}`,
3533+
ServiceAnnotationNetworkLoadBalancerInitialDefinedTagsOverride: `{"namespace":{"key":"value", "owner":"team"}}`,
3534+
},
3535+
},
3536+
},
3537+
desiredLBTags: &providercfg.TagConfig{
3538+
FreeformTags: map[string]string{"cluster": "resource1", "unique": "tag1"},
3539+
DefinedTags: map[string]map[string]interface{}{"namespace": {"owner": "team", "key": "value"}},
3540+
},
3541+
err: nil,
3542+
},
3543+
"reverse compatibility tags test for nlb 4": {
3544+
service: &v1.Service{
3545+
ObjectMeta: metav1.ObjectMeta{
3546+
Annotations: map[string]string{
3547+
ServiceAnnotationLoadBalancerType: "nlb",
3548+
ServiceAnnotationNetworkLoadBalancerFreeformTags: `{"cluster":"resource1", "unique":"tag1"}`,
3549+
ServiceAnnotationNetworkLoadBalancerDefinedTags: `{"namespace":{"key":"value1", "owner":"team1"}}`,
3550+
ServiceAnnotationNetworkLoadBalancerInitialFreeformTagsOverride: `{"cluster":"resource", "unique":"tag"}`,
3551+
},
3552+
},
3553+
},
3554+
desiredLBTags: &providercfg.TagConfig{
3555+
FreeformTags: map[string]string{"cluster": "resource", "unique": "tag"},
3556+
DefinedTags: map[string]map[string]interface{}{"namespace": {"owner": "team1", "key": "value1"}},
3557+
},
3558+
err: nil,
3559+
},
34923560
}
34933561

34943562
for name, tc := range testCases {
@@ -3599,7 +3667,7 @@ func Test_getHealthChecker(t *testing.T) {
35993667
},
36003668
},
36013669
expected: nil,
3602-
err: fmt.Errorf("invalid value for health check interval, should be between %v and %v", LBHealthCheckIntervalMin, LBHealthCheckIntervalMax),
3670+
err: fmt.Errorf("invalid value for health check interval, should be between %v and %v", LBHealthCheckIntervalMin, LBHealthCheckIntervalMax),
36033671
},
36043672
"lb wrong interval value - greater than max": {
36053673
service: &v1.Service{
@@ -3610,31 +3678,31 @@ func Test_getHealthChecker(t *testing.T) {
36103678
},
36113679
},
36123680
expected: nil,
3613-
err: fmt.Errorf("invalid value for health check interval, should be between %v and %v", LBHealthCheckIntervalMin, LBHealthCheckIntervalMax),
3681+
err: fmt.Errorf("invalid value for health check interval, should be between %v and %v", LBHealthCheckIntervalMin, LBHealthCheckIntervalMax),
36143682
},
36153683
"nlb wrong interval value - lesser than min": {
36163684
service: &v1.Service{
36173685
ObjectMeta: metav1.ObjectMeta{
36183686
Annotations: map[string]string{
3619-
ServiceAnnotationLoadBalancerType: "nlb",
3687+
ServiceAnnotationLoadBalancerType: "nlb",
36203688
ServiceAnnotationNetworkLoadBalancerHealthCheckInterval: "3000",
36213689
},
36223690
},
36233691
},
36243692
expected: nil,
3625-
err: fmt.Errorf("invalid value for health check interval, should be between %v and %v", NLBHealthCheckIntervalMin, NLBHealthCheckIntervalMax),
3693+
err: fmt.Errorf("invalid value for health check interval, should be between %v and %v", NLBHealthCheckIntervalMin, NLBHealthCheckIntervalMax),
36263694
},
36273695
"nlb wrong interval value - greater than max": {
36283696
service: &v1.Service{
36293697
ObjectMeta: metav1.ObjectMeta{
36303698
Annotations: map[string]string{
3631-
ServiceAnnotationLoadBalancerType: "nlb",
3699+
ServiceAnnotationLoadBalancerType: "nlb",
36323700
ServiceAnnotationNetworkLoadBalancerHealthCheckInterval: "3000000",
36333701
},
36343702
},
36353703
},
36363704
expected: nil,
3637-
err: fmt.Errorf("invalid value for health check interval, should be between %v and %v", NLBHealthCheckIntervalMin, NLBHealthCheckIntervalMax),
3705+
err: fmt.Errorf("invalid value for health check interval, should be between %v and %v", NLBHealthCheckIntervalMin, NLBHealthCheckIntervalMax),
36383706
},
36393707
}
36403708

@@ -3825,10 +3893,10 @@ func Test_getSecurityListManagementMode(t *testing.T) {
38253893
}
38263894
}
38273895

3828-
func Test_validateService(t *testing.T){
3896+
func Test_validateService(t *testing.T) {
38293897
testCases := map[string]struct {
3830-
service *v1.Service
3831-
err error
3898+
service *v1.Service
3899+
err error
38323900
}{
38333901
"defaults": {
38343902
service: &v1.Service{
@@ -3848,7 +3916,7 @@ func Test_validateService(t *testing.T){
38483916
},
38493917
ObjectMeta: metav1.ObjectMeta{
38503918
Annotations: map[string]string{
3851-
ServiceAnnotationLoadBalancerType: "nlb",
3919+
ServiceAnnotationLoadBalancerType: "nlb",
38523920
ServiceAnnotationNetworkLoadBalancerSecurityListManagementMode: "Neither",
38533921
},
38543922
},
@@ -3885,7 +3953,7 @@ func Test_validateService(t *testing.T){
38853953
},
38863954
ObjectMeta: metav1.ObjectMeta{
38873955
Annotations: map[string]string{
3888-
ServiceAnnotationLoadBalancerType: "nlb",
3956+
ServiceAnnotationLoadBalancerType: "nlb",
38893957
ServiceAnnotationNetworkLoadBalancerSecurityListManagementMode: "All",
38903958
},
38913959
},
@@ -3905,7 +3973,7 @@ func Test_validateService(t *testing.T){
39053973
},
39063974
ObjectMeta: metav1.ObjectMeta{
39073975
Annotations: map[string]string{
3908-
ServiceAnnotationLoadBalancerType: "nlb",
3976+
ServiceAnnotationLoadBalancerType: "nlb",
39093977
ServiceAnnotationNetworkLoadBalancerSecurityListManagementMode: "None",
39103978
},
39113979
},

0 commit comments

Comments
 (0)