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

Enable wait for RepositoryServer CR to get ready functionality for actionsets #2228

Merged
merged 6 commits into from
Jul 28, 2023

Conversation

r4rajat
Copy link
Contributor

@r4rajat r4rajat commented Jul 26, 2023

Change Overview

Enable wait for resources to get ready functionality for actionsets

Add --wait-for-repository-server flag while Actionset creation, if provided waits for RepositoryServer to get in Ready state before creating Actionsets

Pull request type

Please check the type of change your PR introduces:

  • 🚧 Work in Progress
  • 🌈 Refactoring (no functional changes, no api changes)
  • 🐹 Trivial/Minor
  • 🐛 Bugfix
  • 🌻 Feature
  • 🗺️ Documentation
  • 🤖 Test

Issues

  • fixes #issue-number

Test Plan

  • 💪 Manual
  • ⚡ Unit test
  • 💚 E2E

Manual Testing Steps

1) Build kando command line tool

$ go build -o kanctl ./cmd/kanctl/main.go

2) Create Actionset

./kanctl create actionset --action backup --namespace kanister --blueprint mysql-blueprint --statefulset mysql-test/mysql-release --secrets mysql=mysql-test/mysql-release --repository-server=kanister/kopia-repo-server-2 --wait-for-repository-server

<waits for repository server to get ready>
actionset backup-9b74s created

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>
@github-actions
Copy link
Contributor

Thanks for submitting this pull request 🎉. The team will review it soon and get back to you.

If you haven't already, please take a moment to review our project contributing guideline and Code of Conduct document.

@infraq infraq added this to In Progress in Kanister Jul 26, 2023
@@ -105,6 +107,7 @@ func newActionSetCmd() *cobra.Command {
cmd.Flags().String(selectorNamespaceFlag, "", "namespace to apply selector on. Used along with the selector specified using --selector/-l")
cmd.Flags().StringSliceP(namespaceTargetsFlagName, "T", []string{}, "namespaces for the action set, comma separated list of namespaces (eg: --namespacetargets namespace1,namespace2)")
cmd.Flags().StringSliceP(objectsFlagName, "O", []string{}, "objects for the action set, comma separated list of object references (eg: --objects group/version/resource/namespace1/name1,group/version/resource/namespace2/name2)")
cmd.Flags().BoolP(waitForReadyFlagName, "w", false, "wait for resources to get in ready state")
Copy link
Contributor

Choose a reason for hiding this comment

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

The wait flag seems a bit ambiguous. Is it for waiting for actionset to complete, or repo server to be ready or resources to be ready? We can have something --wait-for-reposerver?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done !

@@ -121,7 +124,7 @@ func initializeAndPerform(cmd *cobra.Command, args []string) error {
ctx := context.Background()
valFlag, _ := cmd.Flags().GetBool(skipValidationFlag)
if !valFlag {
err = verifyParams(ctx, params, cli, crCli, osCli)
err = verifyParams(cmd, ctx, params, cli, crCli, osCli)
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of passing whole cmd object just to get value to wait flag can we parse it here and just pass the boolean parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done !

Comment on lines 771 to 781
if wait {
err = waitForKopiaRepositoryServerReady(ctx, crCli, rs)
if err != nil {
return err
}
} else {
if rs.Status.Progress != crv1alpha1.Ready {
err = errors.New("Repository Server Not Ready")
return errors.Wrapf(err, "Please make sure that Repository Server CR '%s' is in Ready State", repoServer.Name)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if wait {
err = waitForKopiaRepositoryServerReady(ctx, crCli, rs)
if err != nil {
return err
}
} else {
if rs.Status.Progress != crv1alpha1.Ready {
err = errors.New("Repository Server Not Ready")
return errors.Wrapf(err, "Please make sure that Repository Server CR '%s' is in Ready State", repoServer.Name)
}
}
if wait {
return waitForKopiaRepositoryServerReady(ctx, crCli, rs)
}
if rs.Status.Progress != crv1alpha1.Ready {
err = errors.New("Repository Server Not Ready")
return errors.Wrapf(err, "Please make sure that Repository Server CR '%s' is in Ready State", repoServer.Name)
}

We can get rid of else block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done !

Comment on lines 791 to 794
if repositoryServer.Status.Progress == crv1alpha1.Ready && err == nil {
return true, nil
}
return false, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if repositoryServer.Status.Progress == crv1alpha1.Ready && err == nil {
return true, nil
}
return false, err
return repositoryServer.Status.Progress == crv1alpha1.Ready, err

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done !

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>
Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>
@r4rajat r4rajat requested a review from PrasadG193 July 26, 2023 13:49
timeoutCtx, waitCancel := context.WithTimeout(ctx, contextWaitTimeout)
defer waitCancel()
pollErr := poll.Wait(timeoutCtx, func(ctx context.Context) (bool, error) {
repositoryServer, err := crCli.CrV1alpha1().RepositoryServers(rs.GetNamespace()).Get(ctx, rs.GetName(), metav1.GetOptions{})
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 continue checking if the supplied repo server doesn't exist right? Something like

		if apierrors.IsNotFound(errors.Cause(err)) {
			return false, nil
		}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pavannd1 we're calling this function i.e waitForKopiaRepositoryServerReady in verifyRepositoryServerParams function and there we're checking if the Repository Server is present or not.

So before polling, we're making sure that RepositoryServer CR exists

pkg/kanctl/actionset.go Outdated Show resolved Hide resolved
@@ -755,7 +759,7 @@ func generateActionSetName(p *PerformParams) (string, error) {
return "", errMissingFieldActionName
}

func verifyRepositoryServerParams(repoServer *crv1alpha1.ObjectReference, crCli versioned.Interface, ctx context.Context) error {
func verifyRepositoryServerParams(waitForRepoServerReady bool, repoServer *crv1alpha1.ObjectReference, crCli versioned.Interface, ctx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not in this PR but we should change the order of arguments here. The convention is

context, clis..., other args...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done !

r4rajat and others added 2 commits July 27, 2023 12:33
Co-authored-by: Pavan Navarathna <6504783+pavannd1@users.noreply.github.com>
Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>
@r4rajat r4rajat requested a review from pavannd1 July 27, 2023 07:11
@r4rajat r4rajat changed the title Enable wait for resources to get ready functionality for actionsets Enable wait for RepositoryServer CR to get ready functionality for actionsets Jul 28, 2023
Copy link
Contributor

@PrasadG193 PrasadG193 left a comment

Choose a reason for hiding this comment

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

LGTM

Kanister automation moved this from In Progress to Reviewer approved Jul 28, 2023
@r4rajat r4rajat added the kueue label Jul 28, 2023
@mergify mergify bot merged commit 7df4275 into master Jul 28, 2023
14 checks passed
Kanister automation moved this from Reviewer approved to Done Jul 28, 2023
@mergify mergify bot deleted the enable_wait_in_actionset branch July 28, 2023 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants