Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/17115.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
gateway: Change status condition reason for invalid certificate on a listener from "Accepted" to "ResolvedRefs".
```
36 changes: 34 additions & 2 deletions agent/consul/gateways/controller_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ func (r *apiGatewayReconciler) reconcileGateway(_ context.Context, req controlle
return err
}

// set each listener as having valid certs, then overwrite that status condition
// if there are any certificate errors
meta.eachListener(func(listener *structs.APIGatewayListener, bound *structs.BoundAPIGatewayListener) error {
listenerRef := structs.ResourceReference{
Kind: structs.APIGateway,
Name: meta.BoundGateway.Name,
SectionName: bound.Name,
EnterpriseMeta: meta.BoundGateway.EnterpriseMeta,
}
updater.SetCondition(validCertificate(listenerRef))
return nil
})

for ref, err := range certificateErrors {
updater.SetCondition(invalidCertificate(ref, err))
}
Expand Down Expand Up @@ -741,8 +754,14 @@ func (g *gatewayMeta) checkCertificates(store *state.Store) (map[structs.Resourc
if err != nil {
return err
}
listenerRef := structs.ResourceReference{
Kind: structs.APIGateway,
Name: g.BoundGateway.Name,
SectionName: bound.Name,
EnterpriseMeta: g.BoundGateway.EnterpriseMeta,
}
if certificate == nil {
certificateErrors[ref] = errors.New("certificate not found")
certificateErrors[listenerRef] = fmt.Errorf("certificate %q not found", ref.Name)
} else {
bound.Certificates = append(bound.Certificates, ref)
}
Expand Down Expand Up @@ -840,12 +859,25 @@ func gatewayAccepted() structs.Condition {
)
}

// invalidCertificate returns a condition used when a gateway references a
// certificate that does not exist. It takes a ref used to scope the condition
// to a given APIGateway listener.
func validCertificate(ref structs.ResourceReference) structs.Condition {
return structs.NewGatewayCondition(
api.GatewayConditionResolvedRefs,
api.ConditionStatusTrue,
api.GatewayReasonResolvedRefs,
"resolved refs",
ref,
)
}

// invalidCertificate returns a condition used when a gateway references a
// certificate that does not exist. It takes a ref used to scope the condition
// to a given APIGateway listener.
func invalidCertificate(ref structs.ResourceReference, err error) structs.Condition {
return structs.NewGatewayCondition(
api.GatewayConditionAccepted,
api.GatewayConditionResolvedRefs,
api.ConditionStatusFalse,
api.GatewayListenerReasonInvalidCertificateRef,
err.Error(),
Expand Down
Loading