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

[TEP-0135] Refactor CreatePVCsForWorkspaces #6921

Merged

Conversation

QuanZhang-William
Copy link
Member

@QuanZhang-William QuanZhang-William commented Jul 12, 2023

Changes

Part of #6740 and closes #6915.

Prior to this commit, the createOrUpdateAffinityAssistantsAndPVCs function attempts to create all Affinity Assistant StatefulSets and returns aggregated errors.
This could result in time and resource waste when executing a pipelinerun that will fail. This commit updates it to "fail fast" strategy where the function is returned as soon as the first error is encountered.

This commit also refactors the original CreatePVCsForWorkspacesWithoutAffinityAssistant (renamed to CreatePVCFromVolumeClaimTemplate) function
and its usages to improve readability since the PVC creation logic is now dependent on AffinityAssistantBehavior.

/kind cleanup

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

@tekton-robot
Copy link
Collaborator

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

@tekton-robot tekton-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesnt merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 12, 2023
@QuanZhang-William QuanZhang-William marked this pull request as ready for review July 12, 2023 00:04
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 12, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 97.2% 98.2% 1.0
pkg/reconciler/taskrun/taskrun.go 84.8% 84.5% -0.3
pkg/reconciler/volumeclaim/pvchandler.go 90.0% 89.7% -0.3

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 97.2% 98.2% 1.0
pkg/reconciler/taskrun/taskrun.go 84.8% 84.5% -0.3
pkg/reconciler/volumeclaim/pvchandler.go 90.0% 89.7% -0.3

@QuanZhang-William QuanZhang-William marked this pull request as draft July 12, 2023 00:43
@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 12, 2023
@lbernick lbernick self-assigned this Jul 12, 2023
@QuanZhang-William QuanZhang-William force-pushed the tep-0135-refactor-pvc-creation branch 2 times, most recently from 70fd19d to 1b38911 Compare July 12, 2023 18:56
@QuanZhang-William QuanZhang-William marked this pull request as ready for review July 12, 2023 18:56
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 12, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 97.2% 99.1% 1.9
pkg/reconciler/pipelinerun/pipelinerun.go 91.8% 92.1% 0.3
pkg/reconciler/taskrun/taskrun.go 84.8% 84.5% -0.3
pkg/reconciler/volumeclaim/pvchandler.go 90.0% 89.7% -0.3

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 97.2% 99.1% 1.9
pkg/reconciler/pipelinerun/pipelinerun.go 91.8% 92.1% 0.3
pkg/reconciler/taskrun/taskrun.go 84.8% 84.5% -0.3
pkg/reconciler/volumeclaim/pvchandler.go 90.0% 89.7% -0.3

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 97.2% 99.1% 1.9
pkg/reconciler/pipelinerun/pipelinerun.go 91.8% 92.1% 0.3
pkg/reconciler/taskrun/taskrun.go 84.8% 84.5% -0.3
pkg/reconciler/volumeclaim/pvchandler.go 90.0% 89.7% -0.3

pkg/reconciler/pipelinerun/pipelinerun.go Outdated Show resolved Hide resolved
pkg/reconciler/pipelinerun/affinity_assistant.go Outdated Show resolved Hide resolved
pkg/reconciler/pipelinerun/affinity_assistant.go Outdated Show resolved Hide resolved
Comment on lines 67 to 83
if err != nil && !apierrors.IsAlreadyExists(err) {
return fmt.Errorf("failed to create PVC %s: %w", claim.Name, err)
}

if apierrors.IsAlreadyExists(err) {
c.logger.Infof("Tried to create PersistentVolumeClaim %s in namespace %s, but it already exists",
claim.Name, claim.Namespace)
}

claim := workspaceBinding.VolumeClaimTemplate.DeepCopy()
claim.Name = GetPVCNameWithoutAffinityAssistant(workspaceBinding.VolumeClaimTemplate.Name, workspaceBinding, ownerReference)
claim.Namespace = namespace
claim.OwnerReferences = []metav1.OwnerReference{ownerReference}
claims[workspaceBinding.Name] = claim
if err == nil {
c.logger.Infof("Created PersistentVolumeClaim %s in namespace %s", claim.Name, claim.Namespace)
}
case err != nil:
return fmt.Errorf("failed to retrieve PVC %s: %w", claim.Name, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

can this conditional logic be simplified?

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 refactored this part a bit. It is not really simplified but I found it is easier to read for me

}

claim := workspaceBinding.VolumeClaimTemplate.DeepCopy()
claim.Name = GetPVCNameWithoutAffinityAssistant(workspaceBinding.VolumeClaimTemplate.Name, workspaceBinding, ownerReference)
Copy link
Member

Choose a reason for hiding this comment

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

maybe a better name for this function could be "GeneratePVCNameFromWorkspaceBinding"?

Copy link
Member Author

Choose a reason for hiding this comment

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

SGTM, function name changed

@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 19, 2023
@wlynch wlynch removed their request for review July 19, 2023 13:25
Part of [tektoncd#6740][tektoncd#6740] and closes [tektoncd#6915].

Prior to this commit, the `createOrUpdateAffinityAssistantsAndPVCs` function attempts to create all Affinity Assistant StatefulSets and returns aggregated errors.
This could result in time and resource waste when executing a pipelinerun that will fail. This commit updates it to "fail fast" strategy
where the function is returned as soon as the first error is encountered.

This commit also refactors the original `CreatePVCsForWorkspacesWithoutAffinityAssistant` (renamed to `CreatePVCFromVolumeClaimTemplate`) function
and its usages to improve readability since the PVC creation logic is now dependent on `AffinityAssistantBehavior`.

/kind feature

[tektoncd#6740]: tektoncd#6740
[tektoncd#6915]: tektoncd#6915
@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 24, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 94.4% 96.0% 1.6
pkg/reconciler/pipelinerun/pipelinerun.go 91.8% 91.7% -0.1
pkg/reconciler/taskrun/taskrun.go 84.8% 84.8% 0.0
pkg/reconciler/volumeclaim/pvchandler.go 83.3% 82.6% -0.7

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/affinity_assistant.go 94.4% 96.0% 1.6
pkg/reconciler/pipelinerun/pipelinerun.go 91.8% 91.7% -0.1
pkg/reconciler/taskrun/taskrun.go 84.8% 84.8% 0.0
pkg/reconciler/volumeclaim/pvchandler.go 83.3% 82.6% -0.7

@@ -314,6 +315,76 @@ func TestCreateAndDeleteOfAffinityAssistantPerWorkspaceOrDisabled(t *testing.T)
}
}

func TestCreateOrUpdateAffinityAssistantsAndPVCs_Failure(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test is copied from #6927

"Failed to create StatefulSet for PipelineRun %s/%s correctly: %s",
pr.Namespace, pr.Name, err)
} else {
if err := c.createOrUpdateAffinityAssistantsAndPVCs(ctx, pr, aaBehavior); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

This part is copied from #6927

@QuanZhang-William
Copy link
Member Author

/hold until v0.50 LTS is released

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 24, 2023
@QuanZhang-William
Copy link
Member Author

QuanZhang-William commented Jul 24, 2023

/cc @Yongxuanzhang @JeromeJu , could you please also help review this PR, which is probably the last implementation PR for this feature 😁 ?

There are some overlap between this PR and #6927, both PRs are open to review but I think it is probably better to review and merge this one first (sorry for the overlap but I have addressed it carefully and it shouldn't cause too much conflict).

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lbernick

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 24, 2023
@Yongxuanzhang
Copy link
Member

/assign

@QuanZhang-William
Copy link
Member Author

/hold cancel

v0.50 LTS is released

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 25, 2023
Copy link
Member

@Yongxuanzhang Yongxuanzhang left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 26, 2023
@QuanZhang-William
Copy link
Member Author

/test pull-tekton-pipeline-alpha-integration-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesnt merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor CreatePVCsForWorkspacesWithoutAffinityAssistant
4 participants