Skip to content

Commit a338330

Browse files
committed
Minor formatting fixups
1 parent 99cb84f commit a338330

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

pkg/oci/load_balancer.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ func (cp *CloudProvider) EnsureLoadBalancer(clusterName string, service *api.Ser
215215
return status, nil
216216
}
217217

218-
func (cp *CloudProvider) updateLoadBalancer(lb *baremetal.LoadBalancer, spec LBSpec, sslConfigMap map[int]*baremetal.SSLConfiguration, sourceCIDRs []string) error {
218+
func (cp *CloudProvider) updateLoadBalancer(
219+
lb *baremetal.LoadBalancer,
220+
spec LBSpec,
221+
sslConfigMap map[int]*baremetal.SSLConfiguration,
222+
sourceCIDRs []string) error {
219223
lbOCID := lb.ID
220224

221225
actualBackendSets := lb.BackendSets
@@ -228,8 +232,7 @@ func (cp *CloudProvider) updateLoadBalancer(lb *baremetal.LoadBalancer, spec LBS
228232
listenerActions := getListenerChanges(actualListeners, desiredListeners)
229233

230234
if len(backendSetActions) == 0 && len(listenerActions) == 0 {
231-
// Nothing to do
232-
return nil
235+
return nil // Nothing to do.
233236
}
234237

235238
lbSubnets, err := cp.client.GetSubnets(spec.Subnets)
@@ -253,9 +256,9 @@ func (cp *CloudProvider) updateLoadBalancer(lb *baremetal.LoadBalancer, spec LBS
253256
case *ListenerAction:
254257
backendSet := spec.GetBackendSets()[a.Listener.DefaultBackendSetName]
255258
if a.Type() == Delete {
256-
// If we need to delete the backendset then it'll no longer be present
257-
// in the spec since that's what is desired, so we need to fetch it
258-
// from the load balancer object.
259+
// If we need to delete the backendset then it'll no longer be
260+
// present in the spec since that's what is desired, so we need
261+
// to fetch it from the load balancer object.
259262
backendSet = lb.BackendSets[a.Listener.DefaultBackendSetName]
260263
}
261264

pkg/oci/load_balancer_util.go

+28-21
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,27 @@ const (
4848
Delete = "delete"
4949
)
5050

51-
// Action that should take place on the resource
51+
// Action that should take place on the resource.
5252
type Action interface {
5353
Type() ActionType
5454
Name() string
5555
}
5656

57-
// BackendSetAction denotes the action that should be taken on the given backend set.
57+
// BackendSetAction denotes the action that should be taken on the given
58+
// BackendSet.
5859
type BackendSetAction struct {
5960
Action
6061

6162
actionType ActionType
6263
BackendSet baremetal.BackendSet
6364
}
6465

65-
// Type of the Action
66+
// Type of the Action.
6667
func (b *BackendSetAction) Type() ActionType {
6768
return b.actionType
6869
}
6970

70-
// Name of the action's object
71+
// Name of the action's object.
7172
func (b *BackendSetAction) Name() string {
7273
return b.BackendSet.Name
7374
}
@@ -76,20 +77,20 @@ func (b *BackendSetAction) String() string {
7677
return fmt.Sprintf("BackendSetAction:{Name: %s, Type: %v }", b.Name(), b.actionType)
7778
}
7879

79-
// ListenerAction denotes the action that should be taken on the given listener.
80+
// ListenerAction denotes the action that should be taken on the given Listener.
8081
type ListenerAction struct {
8182
Action
8283

8384
actionType ActionType
8485
Listener baremetal.Listener
8586
}
8687

87-
// Type of the Action
88+
// Type of the Action.
8889
func (l *ListenerAction) Type() ActionType {
8990
return l.actionType
9091
}
9192

92-
// Name of the action's object
93+
// Name of the action's object.
9394
func (l *ListenerAction) Name() string {
9495
return l.Listener.Name
9596
}
@@ -98,7 +99,8 @@ func (l *ListenerAction) String() string {
9899
return fmt.Sprintf("ListenerAction:{Name: %s, Type: %v }", l.Name(), l.actionType)
99100
}
100101

101-
// TODO(horwitz): this doesn't check weight which we may want in the future to evenly distribute Local traffic policy load.
102+
// TODO(horwitz): this doesn't check weight which we may want in the future to
103+
// evenly distribute Local traffic policy load.
102104
func hasBackendSetChanged(actual, desired baremetal.BackendSet) bool {
103105
if !reflect.DeepEqual(actual.HealthChecker, desired.HealthChecker) {
104106
return true
@@ -114,8 +116,8 @@ func hasBackendSetChanged(actual, desired baremetal.BackendSet) bool {
114116

115117
nameFormat := "%s:%d"
116118

117-
// Since the lengths are equal that means the membership must be the same else
118-
// there has been change.
119+
// Since the lengths are equal that means the membership must be the same
120+
// else there has been change.
119121
desiredSet := sets.NewString()
120122
for _, backend := range desired.Backends {
121123
name := fmt.Sprintf(nameFormat, backend.IPAddress, backend.Port)
@@ -138,7 +140,7 @@ func getBackendSetChanges(actual, desired map[string]baremetal.BackendSet) []Act
138140
for name, actualBackendSet := range actual {
139141
desiredBackendSet, ok := desired[name]
140142
if !ok {
141-
// no longer exists
143+
// No longer exists.
142144
backendSetActions = append(backendSetActions, &BackendSetAction{
143145
BackendSet: actualBackendSet,
144146
actionType: Delete,
@@ -157,7 +159,7 @@ func getBackendSetChanges(actual, desired map[string]baremetal.BackendSet) []Act
157159
// Now check if any need to be created.
158160
for name, desiredBackendSet := range desired {
159161
if _, ok := actual[name]; !ok {
160-
// doesn't exist so lets create it
162+
// Doesn't exist so lets create it.
161163
backendSetActions = append(backendSetActions, &BackendSetAction{
162164
BackendSet: desiredBackendSet,
163165
actionType: Create,
@@ -277,30 +279,34 @@ func parseSecretString(secretString string) (string, string) {
277279
return "", secretString
278280
}
279281

282+
// sortAndCombineActions combines two slices of Actions and then sorts them to
283+
// ensure that BackendSets are created prior to their associated Listeners but
284+
// deleted after their associated Listeners.
280285
func sortAndCombineActions(backendSetActions []Action, listenerActions []Action) []Action {
281286
actions := append(backendSetActions, listenerActions...)
282287
sort.Slice(actions, func(i, j int) bool {
283-
// One action will be backendset and one will be the listener
284288
a1 := actions[i]
285289
a2 := actions[j]
290+
291+
// Sort by the name until we get to the point a1 and a2 are Actions upon
292+
// an associated Listener and BackendSet (which share the same name).
286293
if a1.Name() != a2.Name() {
287-
// Since the actions aren't for the same listener/backendset then just
288-
// sort by the name until we get to the point we are
289294
return a1.Name() < a2.Name()
290295
}
291296

292-
// For create and delete (which is what we really care about) the ActionType
293-
// will always be the same so we can get away with just checking the first action.
297+
// For Create and Delete (which is what we really care about) the
298+
// ActionType will always be the same so we can get away with just
299+
// checking the type of the first action.
294300
switch a1.Type() {
295301
case Create:
296-
// Create the BackendSet then Listener
302+
// Create the BackendSet then Listener.
297303
_, ok := a1.(*BackendSetAction)
298304
return ok
299305
case Update:
300-
// Doesn't matter
306+
// Doesn't matter.
301307
return true
302308
case Delete:
303-
// Delete the Listener then BackendSet
309+
// Delete the Listener then BackendSet.
304310
_, ok := a2.(*BackendSetAction)
305311
return ok
306312
default:
@@ -313,6 +319,7 @@ func sortAndCombineActions(backendSetActions []Action, listenerActions []Action)
313319
}
314320

315321
func getBackendPort(backends []baremetal.Backend) uint64 {
316-
// TODO: what happens if this is 0? e.g. we scale the pods to 0 for a deployment
322+
// TODO: what happens if this is 0? e.g. we scale the pods to 0 for a
323+
// deployment.
317324
return uint64(backends[0].Port)
318325
}

0 commit comments

Comments
 (0)