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

Fiixed: persistentvolumeclaims already exists #1130 #1363

Merged
merged 18 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"swagger": "2.0",
"info": {
"title": "Argo",
"version": "v2.3.0-rc3"
"version": "v2.4.0"
},
"paths": {},
"definitions": {
Expand Down
21 changes: 21 additions & 0 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,9 +897,30 @@ func (woc *wfOperationCtx) createPVCs() error {
*metav1.NewControllerRef(woc.wf, wfv1.SchemaGroupVersionKind),
}
pvc, err := pvcClient.Create(&pvcTmpl)
if err != nil && apierr.IsAlreadyExists(err) {
woc.log.Infof("%s pvc has already exists. Workflow is re-using it", pvcTmpl.Name)
pvc, err = pvcClient.Get(pvcTmpl.Name, metav1.GetOptions{})
if err != nil {
return err
}
hasOwnerReference := false
for i := range pvc.OwnerReferences {
ownerRef := pvc.OwnerReferences[i]
if ownerRef.UID != "" && ownerRef.UID == woc.wf.UID {
Copy link
Member

Choose a reason for hiding this comment

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

The check for ownerRef.UID != "" is unnecessary. kubernetes guarantees that all entries in ownerReferences has non-empty UID.

hasOwnerReference = true
break
}
}
if !hasOwnerReference {
return errors.New(errors.CodeForbidden, "%s pvc has already exists with different ownerreference")
}
}

//continue
if err != nil {
return err
}

vol := apiv1.Volume{
Name: refName,
VolumeSource: apiv1.VolumeSource{
Expand Down