-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[TEP-0135] Refactor CreatePVCsForWorkspaces #6921
Conversation
Skipping CI for Draft Pull Request. |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
70fd19d
to
1b38911
Compare
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
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) | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM, function name changed
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
1b38911
to
e50a7fb
Compare
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
@@ -314,6 +315,76 @@ func TestCreateAndDeleteOfAffinityAssistantPerWorkspaceOrDisabled(t *testing.T) | |||
} | |||
} | |||
|
|||
func TestCreateOrUpdateAffinityAssistantsAndPVCs_Failure(t *testing.T) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
/hold until v0.50 LTS is released |
/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). |
[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 |
/assign |
/hold cancel v0.50 LTS is released |
e50a7fb
to
f130104
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/test pull-tekton-pipeline-alpha-integration-tests |
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 toCreatePVCFromVolumeClaimTemplate
) functionand 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:
/kind <type>
. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tepRelease Notes