Skip to content

Commit 5467b7d

Browse files
committed
review feedback
1 parent bdcf042 commit 5467b7d

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

cmd/all_in_one.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func (s *allCmdParam) applyBootstrapIngress(
338338
// Fetch the bootstrap ingress as a one-off.
339339
ns, n, ok := strings.Cut(name, "/")
340340
if !ok {
341-
return fmt.Errorf("expected ingress name in namespace/name formt")
341+
return fmt.Errorf("expected ingress name in namespace/name format, got %q", name)
342342
}
343343
nn := types.NamespacedName{Namespace: ns, Name: n}
344344
scheme, err := getScheme()
@@ -362,14 +362,16 @@ func (s *allCmdParam) applyBootstrapIngress(
362362
return fmt.Errorf("fetch bootstrap ingress data: %w", err)
363363
}
364364

365-
// Force the route 'From' URL to use the service proxy URL (so we don't need
365+
// Force the route 'To' URL to use the service proxy URL (so we don't need
366366
// to watch for changes to the service endpoints).
367367
ic.Ingress = ic.Ingress.DeepCopy()
368-
ic.Ingress.Annotations[annotationPrefix+"/"+model.UseServiceProxy] = "true"
368+
util.SetAnnotation(ic.Ingress, annotationPrefix+"/"+model.UseServiceProxy, "true")
369369

370370
routes, err := pomerium.IngressToRoutes(ctx, ic)
371371
if err != nil {
372372
return fmt.Errorf("convert bootstrap ingress to routes: %w", err)
373+
} else if len(routes) == 0 {
374+
return fmt.Errorf("bootstrap ingress %q has no rules", name)
373375
}
374376
s.cfg.Options.Policies = append(s.cfg.Options.Policies, routes...)
375377

pomerium/sync_api.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func (r *APIReconciler) upsertOneIngress(
260260
return changed, err
261261
}
262262
if ic.Annotations[k] != *route.Id {
263-
setAnnotation(ic, k, *route.Id)
263+
util.SetAnnotation(ic, k, *route.Id)
264264
}
265265
changed = changed || changedRoute
266266
}
@@ -332,7 +332,7 @@ func (r *APIReconciler) syncOneSecret(
332332
if err != nil {
333333
return false, err
334334
} else if changed {
335-
setAnnotation(secret, apiKeyPairIDAnnotation, keyPair.GetId())
335+
util.SetAnnotation(secret, apiKeyPairIDAnnotation, keyPair.GetId())
336336
controllerutil.AddFinalizer(secret, apiFinalizer)
337337
err = r.k8sClient.Patch(ctx, secret, client.MergeFrom(originalSecret))
338338
}
@@ -502,7 +502,7 @@ func (r *APIReconciler) SetGatewayConfig(
502502
}
503503
changes = changes || routeChanged
504504
if gr.Annotations[k] != *route.Id {
505-
setAnnotation(gr, k, *route.Id)
505+
util.SetAnnotation(gr, k, *route.Id)
506506
}
507507
}
508508
controllerutil.AddFinalizer(gr, apiFinalizer)
@@ -570,7 +570,7 @@ func (r *APIReconciler) syncGatewayPolicies(
570570
return changes, nil, err
571571
} else if changedPolicy {
572572
changes = true
573-
setAnnotation(obj, apiPolicyIDAnnotation, policy.GetId())
573+
util.SetAnnotation(obj, apiPolicyIDAnnotation, policy.GetId())
574574
controllerutil.AddFinalizer(obj, apiFinalizer)
575575
}
576576

@@ -770,7 +770,7 @@ func (r *APIReconciler) syncIngressPolicy(
770770
return false, "", fmt.Errorf("couldn't update ingress policy: %w", err)
771771
}
772772
updatedPolicyID = apiPolicy.GetId()
773-
setAnnotation(ingress, apiPolicyIDAnnotation, updatedPolicyID)
773+
util.SetAnnotation(ingress, apiPolicyIDAnnotation, updatedPolicyID)
774774
return changed, updatedPolicyID, nil
775775
}
776776

@@ -1040,15 +1040,6 @@ func convertProto[Dst, Src proto.Message](msg Src) (Dst, error) {
10401040
return newMsg, err
10411041
}
10421042

1043-
func setAnnotation(object client.Object, key, value string) {
1044-
m := object.GetAnnotations()
1045-
if m == nil {
1046-
m = make(map[string]string)
1047-
}
1048-
m[key] = value
1049-
object.SetAnnotations(m)
1050-
}
1051-
10521043
func falseToNil(x *bool) *bool {
10531044
if x != nil && !*x {
10541045
return nil

util/object.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package util
2+
3+
import "sigs.k8s.io/controller-runtime/pkg/client"
4+
5+
// SetAnnotation sets the given annotation key/value, making a new Annotations
6+
// map if one does not already exist.
7+
func SetAnnotation(object client.Object, key, value string) {
8+
m := object.GetAnnotations()
9+
if m == nil {
10+
m = make(map[string]string)
11+
}
12+
m[key] = value
13+
object.SetAnnotations(m)
14+
}

0 commit comments

Comments
 (0)