Skip to content

Commit

Permalink
fix: trigger reconcile for Secret updates referenced by a BackendTLSP… (
Browse files Browse the repository at this point in the history
#4581)

fix: trigger reconcile for Secret updates referenced by a BackendTLSPolicy

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg authored Oct 31, 2024
1 parent efe625d commit db68027
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
24 changes: 23 additions & 1 deletion internal/provider/kubernetes/indexers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
backendSecurityPolicyIndex = "backendSecurityPolicyIndex"
configMapCtpIndex = "configMapCtpIndex"
secretCtpIndex = "secretCtpIndex"
secretBtlsIndex = "secretBtlsIndex"
configMapBtlsIndex = "configMapBtlsIndex"
backendEnvoyExtensionPolicyIndex = "backendEnvoyExtensionPolicyIndex"
backendEnvoyProxyTelemetryIndex = "backendEnvoyProxyTelemetryIndex"
Expand Down Expand Up @@ -702,14 +703,17 @@ func configMapRouteFilterIndexFunc(rawObj client.Object) []string {
return configMapReferences
}

// addBtlsIndexers adds indexing on BackendTLSPolicy, for ConfigMap objects that are
// addBtlsIndexers adds indexing on BackendTLSPolicy, for ConfigMap and Secret objects that are
// referenced in BackendTLSPolicy objects. This helps in querying for BackendTLSPolicies that are
// affected by a particular ConfigMap CRUD.
func addBtlsIndexers(ctx context.Context, mgr manager.Manager) error {
if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1a3.BackendTLSPolicy{}, configMapBtlsIndex, configMapBtlsIndexFunc); err != nil {
return err
}

if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1a3.BackendTLSPolicy{}, secretBtlsIndex, secretBtlsIndexFunc); err != nil {
return err
}
return nil
}

Expand All @@ -731,6 +735,24 @@ func configMapBtlsIndexFunc(rawObj client.Object) []string {
return configMapReferences
}

func secretBtlsIndexFunc(rawObj client.Object) []string {
btls := rawObj.(*gwapiv1a3.BackendTLSPolicy)
var secretReferences []string
if btls.Spec.Validation.CACertificateRefs != nil {
for _, caCertRef := range btls.Spec.Validation.CACertificateRefs {
if string(caCertRef.Kind) == resource.KindSecret {
secretReferences = append(secretReferences,
types.NamespacedName{
Namespace: btls.Namespace,
Name: string(caCertRef.Name),
}.String(),
)
}
}
}
return secretReferences
}

// addEnvoyExtensionPolicyIndexers adds indexing on EnvoyExtensionPolicy.
// - For Service objects that are referenced in EnvoyExtensionPolicy objects via
// `.spec.extProc.[*].service.backendObjectReference`. This helps in querying for
Expand Down
22 changes: 22 additions & 0 deletions internal/provider/kubernetes/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ func (r *gatewayAPIReconciler) validateSecretForReconcile(obj client.Object) boo
}
}

if r.bTLSPolicyCRDExists {
if r.isBackendTLSPolicyReferencingSecret(&nsName) {
return true
}
}

return false
}

func (r *gatewayAPIReconciler) isBackendTLSPolicyReferencingSecret(nsName *types.NamespacedName) bool {
btlsList := &gwapiv1a3.BackendTLSPolicyList{}
if err := r.client.List(context.Background(), btlsList, &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(secretBtlsIndex, nsName.String()),
}); err != nil {
r.log.Error(err, "unable to find associated BackendTLSPolicy")
return false
}

if len(btlsList.Items) > 0 {
return true
}

return false
}

Expand Down

0 comments on commit db68027

Please sign in to comment.