Skip to content

Commit

Permalink
Update secretsencrypt pagination
Browse files Browse the repository at this point in the history
Make secretsencrypt page size and iteration  consistent with other paginators

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
  • Loading branch information
brandond committed Jul 16, 2024
1 parent 63abec2 commit a85a3c8
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions pkg/secretsencrypt/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
secretsProgressEvent string = "SecretsProgress"
secretsUpdateCompleteEvent string = "SecretsUpdateComplete"
secretsUpdateErrorEvent string = "SecretsUpdateError"

secretListPageSize = 20
)

type handler struct {
Expand Down Expand Up @@ -116,7 +118,7 @@ func (h *handler) onChangeNode(nodeName string, node *corev1.Node) (*corev1.Node
return node, err
}

if err := h.updateSecrets(node); err != nil {
if err := h.updateSecrets(nodeRef); err != nil {
h.recorder.Event(nodeRef, corev1.EventTypeWarning, secretsUpdateErrorEvent, err.Error())
return node, err
}
Expand Down Expand Up @@ -213,36 +215,27 @@ func (h *handler) validateReencryptStage(node *corev1.Node, annotation string) (
return true, nil
}

func (h *handler) updateSecrets(node *corev1.Node) error {
nodeRef := &corev1.ObjectReference{
Kind: "Node",
Name: node.Name,
UID: types.UID(node.Name),
Namespace: "",
}
secretPager := pager.New(pager.SimplePageFunc(func(opts metav1.ListOptions) (runtime.Object, error) {
return h.secrets.List("", opts)
}))
secretsList, _, err := secretPager.List(h.ctx, metav1.ListOptions{})
if err != nil {
return err
}
func (h *handler) updateSecrets(nodeRef *corev1.ObjectReference) error {
secretPager := pager.New(pager.SimplePageFunc(func(opts metav1.ListOptions) (runtime.Object, error) { return h.secrets.List(meta.NamespaceAll, opts) }))

Check failure on line 219 in pkg/secretsencrypt/controller.go

View workflow job for this annotation

GitHub Actions / Unit Tests

undefined: meta.NamespaceAll
secretPager.PageSize = secretListPageSize

i := 0
err = meta.EachListItem(secretsList, func(obj runtime.Object) error {
if secret, ok := obj.(*corev1.Secret); ok {
if _, err := h.secrets.Update(secret); err != nil && !apierrors.IsConflict(err) {
return fmt.Errorf("failed to update secret: %v", err)
}
if i != 0 && i%10 == 0 {
h.recorder.Eventf(nodeRef, corev1.EventTypeNormal, secretsProgressEvent, "reencrypted %d secrets", i)
}
i++
if err := secretPager.EachListItem(h.ctx, metav1.ListOptions{}, func(obj runtime.Object) error {
secret, ok := obj.(*corev1.Secret)
if !ok {
}
if _, err := h.secrets.Update(secret); err != nil && !apierrors.IsConflict(err) {
return fmt.Errorf("failed to update secret: %v", err)
}
if i != 0 && i%10 == 0 {
h.recorder.Eventf(nodeRef, corev1.EventTypeNormal, secretsProgressEvent, "reencrypted %d secrets", i)
}
i++
return nil
})
if err != nil {
}); err != nil {
return err
}

h.recorder.Eventf(nodeRef, corev1.EventTypeNormal, secretsUpdateCompleteEvent, "completed reencrypt of %d secrets", i)
return nil
}

0 comments on commit a85a3c8

Please sign in to comment.