Skip to content

Commit

Permalink
fix oauth2 key secret ref hash (#239)
Browse files Browse the repository at this point in the history
* fix oauth2 key secret ref hash

* fix ci
  • Loading branch information
freeznet authored Aug 21, 2024
1 parent 5d62e31 commit 4966635
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ linters:
- exportloopref
# - gci
- gocritic
- gocyclo
# - gocyclo
# - godot
- gofmt
- goimports
Expand Down
10 changes: 10 additions & 0 deletions controllers/pulsarconnection_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,16 @@ func (r *PulsarConnectionReconciler) findSecretsForConnection(secret client.Obje
})
}
}
if auth != nil && auth.OAuth2 != nil && auth.OAuth2.Key != nil && auth.OAuth2.Key.SecretRef != nil {
if auth.OAuth2.Key.SecretRef.Name == secret.GetName() {
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
Name: i.GetName(),
Namespace: i.GetNamespace(),
},
})
}
}
}

return requests
Expand Down
15 changes: 15 additions & 0 deletions pkg/connection/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ func (r *PulsarConnectionReconciler) Reconcile(ctx context.Context) error {
}
r.connection.Status.SecretKeyHash = hash
}
if auth != nil && auth.OAuth2 != nil && auth.OAuth2.Key != nil && auth.OAuth2.Key.SecretRef != nil {
// calculate secret key hash
secret := &corev1.Secret{}
if err := r.client.Get(ctx, types.NamespacedName{
Namespace: r.connection.Namespace,
Name: auth.OAuth2.Key.SecretRef.Name,
}, secret); err != nil {
return err
}
hash, err := utils.CalculateSecretKeyMd5(secret, auth.OAuth2.Key.SecretRef.Key)
if err != nil {
return err
}
r.connection.Status.SecretKeyHash = hash
}
r.connection.Status.ObservedGeneration = r.connection.Generation
meta.SetStatusCondition(&r.connection.Status.Conditions, *NewReadyCondition(r.connection.Generation))
if err := r.client.Status().Update(ctx, r.connection); err != nil {
Expand Down

0 comments on commit 4966635

Please sign in to comment.