Skip to content

Enqueued requests for source event from watcher are not sorted in the dependency order #1254

@matheuscscp

Description

@matheuscscp

While working on fluxcd/pkg#976 I noticed that helm-controller is not sorting the enqueued requests for a source event in the dependency order like kustomize-controller.

kustomize-controller:
https://github.com/fluxcd/kustomize-controller/blob/52170876d58b21b3735ce26cd3eadcc123a4706e/internal/controller/kustomization_indexers.go#L67-L77

helm-controller HelmChart:

var list v2.HelmReleaseList
if err := r.List(ctx, &list, client.MatchingFields{
v2.SourceIndexKey: client.ObjectKeyFromObject(hc).String(),
}); err != nil {
ctrl.LoggerFrom(ctx).Error(err, "failed to list HelmReleases for HelmChart change")
return nil
}
var reqs []reconcile.Request
for i, hr := range list.Items {
// If the HelmRelease is ready and the revision of the artifact equals to the
// last attempted revision, we should not make a request for this HelmRelease
if conditions.IsReady(&list.Items[i]) && hc.GetArtifact().HasRevision(hr.Status.GetLastAttemptedRevision()) {
continue
}
reqs = append(reqs, reconcile.Request{NamespacedName: client.ObjectKeyFromObject(&list.Items[i])})
}
return reqs

helm-controller OCIRepository:

var list v2.HelmReleaseList
if err := r.List(ctx, &list, client.MatchingFields{
v2.SourceIndexKey: client.ObjectKeyFromObject(or).String(),
}); err != nil {
ctrl.LoggerFrom(ctx).Error(err, "failed to list HelmReleases for OCIRepository change")
return nil
}
var reqs []reconcile.Request
for i, hr := range list.Items {
// If the HelmRelease is ready and the digest of the artifact equals to the
// last attempted revision digest, we should not make a request for this HelmRelease,
// likewise if we cannot retrieve the artifact digest.
digest := extractDigest(or.GetArtifact().Revision)
if digest == "" {
ctrl.LoggerFrom(ctx).Error(fmt.Errorf("wrong digest for %T", or), "failed to get requests for OCIRepository change")
continue
}
if digest == hr.Status.LastAttemptedRevisionDigest {
continue
}
reqs = append(reqs, reconcile.Request{NamespacedName: client.ObjectKeyFromObject(&list.Items[i])})
}
return reqs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions