Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NonAdminDownloadRequests implementation #233

Open
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

kaovilai
Copy link
Member

@kaovilai kaovilai commented Feb 25, 2025

  • kubebuilder create api --group oadp --version v1alpha1 --kind NonAdminDownloadRequest
  • api init
  • Scaffolds objectReconciler
❯ kubebuilder version
Version: main.version{KubeBuilderVersion:"4.5.1", KubernetesVendor:"1.32.1", GitCommit:"0ace7a8753c52b35014e43edc2a0b0454b78e769", BuildDate:"2025-02-21T20:16:18Z", GoOs:"darwin", GoArch:"arm64"}

Why the changes were made

Fixes #213

OADP PR openshift/oadp-operator#1643

How to test the changes made

See: openshift/oadp-operator#1643

Copy link

openshift-ci bot commented Feb 25, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link

openshift-ci bot commented Feb 25, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kaovilai

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kaovilai kaovilai force-pushed the NADR branch 3 times, most recently from 85deef7 to b61ea75 Compare February 25, 2025 23:57
@weshayutin

This comment was marked as outdated.

@kaovilai

This comment was marked as outdated.

@kaovilai kaovilai force-pushed the NADR branch 2 times, most recently from eb873cc to 0df85a8 Compare February 27, 2025 00:37
@kaovilai kaovilai force-pushed the NADR branch 5 times, most recently from 54212e1 to 7bc176b Compare February 28, 2025 01:20
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
func (r *NonAdminDownloadRequestReconciler) deleteExpiredDownloadRequest(ctx context.Context, veleroDR *velerov1.DownloadRequest, req *nacv1alpha1.NonAdminDownloadRequest) error {
logger := log.FromContext(ctx)
logger.V(1).Info("Deleting expired NonAdminDownloadRequest associated velero download request", req.VeleroDownloadRequestName(), req.Namespace)
if err := r.Delete(ctx, veleroDR); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not this Velero responsibility?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Velero does not garbage collect.

I think they pile up.

vmware-tanzu/velero#5329

Velero might implement gc eventually until then our logic here is fine imo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok maybe ive just seen some cu clusters clogged with them..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can let velero delete, and on velero delete event we can delete nadr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do we want to do with things without expiration? ie. velero server too busy to handle and process.. no url therefore no expiration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shubham said GC on NADR without a corresponding velero DR.. I assume we want to only do this if NADR.status.url is populated which is already processed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

velero once a minute reconcile and check for expiration. we can defer to velero for a successful case.
we need to handle case without expiration due to errors possibly but future enhancement/discussion.

return err
}
}
logger.V(1).Info("Deleting expired NonAdminDownloadRequest", req.Name, req.Namespace)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to keep similar behavior for backup/restore, should we just add message in status that associated velero DownloadRequest was deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DownloadRequest life is very short lived.. so I don't think knowing velero is deleted is useful information to patch into the object. we already logged velero object is being deleted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could patch in.. but the object is being deleted right after.. I don't think you'd want this object lingering past expiration IMO.

}
}
}
return nadr.Spec.Target.Kind != constant.EmptyString &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this does not make sense. Are not these fields required? it would always return true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I add +kubebuilder:validation:Required then I can replace this with a comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no no, I think this is already done in velero side

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want this check replaced with comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just change return true, no need for comment

func (r *NonAdminDownloadRequestReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&nacv1alpha1.NonAdminDownloadRequest{}, builder.WithPredicates(ctrlpredicate.Funcs{
CreateFunc: func(tce event.TypedCreateEvent[client.Object]) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should always return true for create events

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only if CRD validation blocks all invalids.. do we want that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is the controller for this CRD, should it not process all objects creation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there would be anything to process otherwise.. so no.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always return true if all creations have target/kind which it seems we do via velero crd validaiton markers. We can consider simplyfy to returing true here.

expectedDownloadName = nadr.VeleroDownloadRequestName()

// Create a fake client with the NonAdminDownloadRequest object
fakeClient = fake.NewClientBuilder().WithScheme(scheme.Scheme).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not use fake client within controller tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on controller folder, we have access to envtest and k8sClient from suite_test.go

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kubernetes-sigs/controller-runtime#880

envtest is not always the best choice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

			gomega.Expect(createTestNamespaces(ctx, nonAdminNamespace, oadpNamespace)).To(gomega.Succeed())

How did you get these to work?

I see there is deleteNS code in your controller_tests

I just never got delete NS to work.

  [FAILED] in [BeforeEach] - /Users/tiger/git/oadp-non-admin/internal/controller/nonadmindownloadrequest_controller_test.go:108 @ 03/03/25 12:11:43.251
  [FAILED] in [AfterEach] - /Users/tiger/git/oadp-non-admin/internal/controller/nonadmindownloadrequest_controller_test.go:142 @ 03/03/25 12:11:48.254
  << Timeline

  [FAILED] Expected success, but got an error:
      <*errors.StatusError | 0x14000cb61e0>: 
      object is being deleted: namespaces "test-namespace" already exists
      {
          ErrStatus: {
              TypeMeta: {Kind: "", APIVersion: ""},
              ListMeta: {
                  SelfLink: "",
                  ResourceVersion: "",
                  Continue: "",
                  RemainingItemCount: nil,
              },
              Status: "Failure",
              Message: "object is being deleted: namespaces \"test-namespace\" already exists",
              Reason: "AlreadyExists",
              Details: {
                  Name: "test-namespace",
                  Group: "",
                  Kind: "namespaces",
                  UID: "",
                  Causes: nil,
                  RetryAfterSeconds: 0,
              },
              Code: 409,
          },
      }
  In [BeforeEach] at: /Users/tiger/git/oadp-non-admin/internal/controller/nonadmindownloadrequest_controller_test.go:108 @ 03/03/25 12:11:43.251

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we "simulate" deletion by calling delete on these namespaces, and not using them again

each test uses a different set of namespaces (usually 2: nonAdmin and OADP namespace)

Copy link
Contributor

@mateusoliveira43 mateusoliveira43 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested on private browser, worked

return ctrl.Result{}, nil
}
logger := log.FromContext(ctx)
logger.Info("Reconciling NonAdminDownloadRequest", "name", req.Name, "namespace", req.Namespace)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not add info already present in log

example log without adding anything

{"controller": "nonadmindownloadrequest", "controllerGroup": "oadp.openshift.io", "controllerKind": "NonAdminDownloadRequest", "NonAdminDownloadRequest": {"name":"non-admin-download-request-object-1","namespace":"test-non-admin-download-request-reconcile-full-1"}, "namespace": "test-non-admin-download-request-reconcile-full-1", "name": "non-admin-download-request-object-1", "reconcileID": "5f3f2745-13b3-46c8-a340-5166350c9997"}

logger.V(1).Info("Deleting expired NonAdminDownloadRequest associated velero download request", req.VeleroDownloadRequestName(), req.Namespace)
if err := r.Delete(ctx, veleroDR); err != nil {
if !apierrors.IsNotFound(err) {
logger.V(1).Info("Failed to delete expired NonAdminDownloadRequest associated velero download request", req.VeleroDownloadRequestName(), err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when returning error, should not the log level be error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will log as error. should not matter too much as reconcile err should already log the err.

kaovilai added 4 commits March 3, 2025 10:31
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Signed-off-by: Tiger Kaovilai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NonAdminDownloadRequest to make backup logs/resourceLists available to nonAdmins.
6 participants