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

Bug 1982046: lib/resourcedelete: Always check delete progress #629

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions lib/resourcedelete/apiext.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ import (
)

// DeleteCustomResourceDefinitionv1 checks the given resource for a valid delete annotation. If found
// and in UpdatingMode it will issue a delete request or provide status of a previousily issued delete request.
// If not in UpdatingMode it simply returns an indication that the delete annotation was found. An error is
// returned if an invalid annotation is found or an error occurs during delete processing.
// it checks the status of a previousily issued delete request. If delete has not been
// requested and in UpdatingMode it will issue a delete request.
func DeleteCustomResourceDefinitionv1(ctx context.Context, client apiextclientv1.CustomResourceDefinitionsGetter,
required *apiextv1.CustomResourceDefinition, updateMode bool) (bool, error) {

if delAnnoFound, err := ValidDeleteAnnotation(required.Annotations); !delAnnoFound || err != nil {
return delAnnoFound, err
} else if !updateMode {
return true, nil
}
existing, err := client.CustomResourceDefinitions().Get(ctx, required.Name, metav1.GetOptions{})
Copy link
Member

Choose a reason for hiding this comment

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

There's no real reason to move this higher, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not required but I did it so this matches resourcedelete delete methods. Also, a minor thing, but now resource is declared closer to where it's used.

resource := Resource{
Kind: "customresourcedefinition",
Namespace: "",
Name: required.Name,
}
existing, err := client.CustomResourceDefinitions().Get(ctx, required.Name, metav1.GetOptions{})
if deleteRequested, err := GetDeleteProgress(resource, err); err == nil {
if !deleteRequested {
// Only request deletion when in update mode.
if !deleteRequested && updateMode {
if err := client.CustomResourceDefinitions().Delete(ctx, required.Name, metav1.DeleteOptions{}); err != nil {
return true, fmt.Errorf("Delete request for %s failed, err=%v", resource, err)
}
Expand Down
12 changes: 5 additions & 7 deletions lib/resourcedelete/apireg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ import (
)

// DeleteAPIServicev1 checks the given resource for a valid delete annotation. If found
// and in UpdatingMode it will issue a delete request or provide status of a previousily issued delete request.
// If not in UpdatingMode it simply returns an indication that the delete annotation was found. An error is
// returned if an invalid annotation is found or an error occurs during delete processing.
// it checks the status of a previousily issued delete request. If delete has not been
// requested and in UpdatingMode it will issue a delete request.
func DeleteAPIServicev1(ctx context.Context, client apiregclientv1.APIServicesGetter, required *apiregv1.APIService,
updateMode bool) (bool, error) {

if delAnnoFound, err := ValidDeleteAnnotation(required.Annotations); !delAnnoFound || err != nil {
return delAnnoFound, err
} else if !updateMode {
return true, nil
}
existing, err := client.APIServices().Get(ctx, required.Name, metav1.GetOptions{})
resource := Resource{
Kind: "apiservice",
Namespace: "",
Name: required.Name,
}
existing, err := client.APIServices().Get(ctx, required.Name, metav1.GetOptions{})
if deleteRequested, err := GetDeleteProgress(resource, err); err == nil {
if !deleteRequested {
// Only request deletion when in update mode.
if !deleteRequested && updateMode {
if err := client.APIServices().Delete(ctx, required.Name, metav1.DeleteOptions{}); err != nil {
return true, fmt.Errorf("Delete request for %s failed, err=%v", resource, err)
}
Expand Down
24 changes: 10 additions & 14 deletions lib/resourcedelete/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ import (
)

// DeleteDeploymentv1 checks the given resource for a valid delete annotation. If found
// and in UpdatingMode it will issue a delete request or provide status of a previousily issued delete request.
// If not in UpdatingMode it simply returns an indication that the delete annotation was found. An error is
// returned if an invalid annotation is found or an error occurs during delete processing.
// it checks the status of a previousily issued delete request. If delete has not been
// requested and in UpdatingMode it will issue a delete request.
func DeleteDeploymentv1(ctx context.Context, client appsclientv1.DeploymentsGetter, required *appsv1.Deployment,
updateMode bool) (bool, error) {

if delAnnoFound, err := ValidDeleteAnnotation(required.Annotations); !delAnnoFound || err != nil {
return delAnnoFound, err
} else if !updateMode {
return true, nil
}
existing, err := client.Deployments(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
resource := Resource{
Kind: "deployment",
Namespace: required.Namespace,
Name: required.Name,
}
existing, err := client.Deployments(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
if deleteRequested, err := GetDeleteProgress(resource, err); err == nil {
if !deleteRequested {
// Only request deletion when in update mode.
if !deleteRequested && updateMode {
if err := client.Deployments(required.Namespace).Delete(ctx, required.Name, metav1.DeleteOptions{}); err != nil {
return true, fmt.Errorf("Delete request for %s failed, err=%v", resource, err)
}
Expand All @@ -41,25 +39,23 @@ func DeleteDeploymentv1(ctx context.Context, client appsclientv1.DeploymentsGett
}

// DeleteDaemonSetv1 checks the given resource for a valid delete annotation. If found
// and in UpdatingMode it will issue a delete request or provide status of a previousily issued delete request.
// If not in UpdatingMode it simply returns an indication that the delete annotation was found. An error is
// returned if an invalid annotation is found or an error occurs during delete processing.
// it checks the status of a previousily issued delete request. If delete has not been
// requested and in UpdatingMode it will issue a delete request.
func DeleteDaemonSetv1(ctx context.Context, client appsclientv1.DaemonSetsGetter, required *appsv1.DaemonSet,
updateMode bool) (bool, error) {

if delAnnoFound, err := ValidDeleteAnnotation(required.Annotations); !delAnnoFound || err != nil {
return delAnnoFound, err
} else if !updateMode {
return true, nil
}
existing, err := client.DaemonSets(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
resource := Resource{
Kind: "daemonset",
Namespace: required.Namespace,
Name: required.Name,
}
existing, err := client.DaemonSets(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
if deleteRequested, err := GetDeleteProgress(resource, err); err == nil {
if !deleteRequested {
// Only request deletion when in update mode.
if !deleteRequested && updateMode {
if err := client.DaemonSets(required.Namespace).Delete(ctx, required.Name, metav1.DeleteOptions{}); err != nil {
return true, fmt.Errorf("Delete request for %s failed, err=%v", resource, err)
}
Expand Down
12 changes: 5 additions & 7 deletions lib/resourcedelete/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ import (
)

// DeleteJobv1 checks the given resource for a valid delete annotation. If found
// and in UpdatingMode it will issue a delete request or provide status of a previousily issued delete request.
// If not in UpdatingMode it simply returns an indication that the delete annotation was found. An error is
// returned if an invalid annotation is found or an error occurs during delete processing.
// it checks the status of a previousily issued delete request. If delete has not been
// requested and in UpdatingMode it will issue a delete request.
func DeleteJobv1(ctx context.Context, client batchclientv1.JobsGetter, required *batchv1.Job,
updateMode bool) (bool, error) {

if delAnnoFound, err := ValidDeleteAnnotation(required.Annotations); !delAnnoFound || err != nil {
return delAnnoFound, err
} else if !updateMode {
return true, nil
}
existing, err := client.Jobs(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
resource := Resource{
Kind: "job",
Namespace: required.Namespace,
Name: required.Name,
}
existing, err := client.Jobs(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
if deleteRequested, err := GetDeleteProgress(resource, err); err == nil {
if !deleteRequested {
// Only request deletion when in update mode.
if !deleteRequested && updateMode {
if err := client.Jobs(required.Namespace).Delete(ctx, required.Name, metav1.DeleteOptions{}); err != nil {
return true, fmt.Errorf("Delete request for %s failed, err=%v", resource, err)
}
Expand Down
48 changes: 20 additions & 28 deletions lib/resourcedelete/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ import (
)

// DeleteNamespacev1 checks the given resource for a valid delete annotation. If found
// and in UpdatingMode it will issue a delete request or provide status of a previousily issued delete request.
// If not in UpdatingMode it simply returns an indication that the delete annotation was found. An error is
// returned if an invalid annotation is found or an error occurs during delete processing.
// it checks the status of a previousily issued delete request. If delete has not been
// requested and in UpdatingMode it will issue a delete request.
func DeleteNamespacev1(ctx context.Context, client coreclientv1.NamespacesGetter, required *corev1.Namespace,
updateMode bool) (bool, error) {

if delAnnoFound, err := ValidDeleteAnnotation(required.Annotations); !delAnnoFound || err != nil {
return delAnnoFound, err
} else if !updateMode {
return true, nil
}
existing, err := client.Namespaces().Get(ctx, required.Name, metav1.GetOptions{})
resource := Resource{
Kind: "namespace",
Namespace: "",
Name: required.Name,
}
existing, err := client.Namespaces().Get(ctx, required.Name, metav1.GetOptions{})
if deleteRequested, err := GetDeleteProgress(resource, err); err == nil {
if !deleteRequested {
// Only request deletion when in update mode.
if !deleteRequested && updateMode {
if err := client.Namespaces().Delete(ctx, required.Name, metav1.DeleteOptions{}); err != nil {
return true, fmt.Errorf("Delete request for %s failed, err=%v", resource, err)
}
Expand All @@ -41,25 +39,23 @@ func DeleteNamespacev1(ctx context.Context, client coreclientv1.NamespacesGetter
}

// DeleteServicev1 checks the given resource for a valid delete annotation. If found
// and in UpdatingMode it will issue a delete request or provide status of a previousily issued delete request.
// If not in UpdatingMode it simply returns an indication that the delete annotation was found. An error is
// returned if an invalid annotation is found or an error occurs during delete processing.
// it checks the status of a previousily issued delete request. If delete has not been
// requested and in UpdatingMode it will issue a delete request.
func DeleteServicev1(ctx context.Context, client coreclientv1.ServicesGetter, required *corev1.Service,
updateMode bool) (bool, error) {

if delAnnoFound, err := ValidDeleteAnnotation(required.Annotations); !delAnnoFound || err != nil {
return delAnnoFound, err
} else if !updateMode {
return true, nil
}
existing, err := client.Services(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
resource := Resource{
Kind: "service",
Namespace: required.Namespace,
Name: required.Name,
}
existing, err := client.Services(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
if deleteRequested, err := GetDeleteProgress(resource, err); err == nil {
if !deleteRequested {
// Only request deletion when in update mode.
if !deleteRequested && updateMode {
if err := client.Services(required.Namespace).Delete(ctx, required.Name, metav1.DeleteOptions{}); err != nil {
return true, fmt.Errorf("Delete request for %s failed, err=%v", resource, err)
}
Expand All @@ -72,25 +68,23 @@ func DeleteServicev1(ctx context.Context, client coreclientv1.ServicesGetter, re
}

// DeleteServiceAccountv1 checks the given resource for a valid delete annotation. If found
// and in UpdatingMode it will issue a delete request or provide status of a previousily issued delete request.
// If not in UpdatingMode it simply returns an indication that the delete annotation was found. An error is
// returned if an invalid annotation is found or an error occurs during delete processing.
// it checks the status of a previousily issued delete request. If delete has not been
// requested and in UpdatingMode it will issue a delete request.
func DeleteServiceAccountv1(ctx context.Context, client coreclientv1.ServiceAccountsGetter, required *corev1.ServiceAccount,
updateMode bool) (bool, error) {

if delAnnoFound, err := ValidDeleteAnnotation(required.Annotations); !delAnnoFound || err != nil {
return delAnnoFound, err
} else if !updateMode {
return true, nil
}
existing, err := client.ServiceAccounts(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
resource := Resource{
Kind: "serviceaccount",
Namespace: required.Namespace,
Name: required.Name,
}
existing, err := client.ServiceAccounts(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
if deleteRequested, err := GetDeleteProgress(resource, err); err == nil {
if !deleteRequested {
// Only request deletion when in update mode.
if !deleteRequested && updateMode {
if err := client.ServiceAccounts(required.Namespace).Delete(ctx, required.Name, metav1.DeleteOptions{}); err != nil {
return true, fmt.Errorf("Delete request for %s failed, err=%v", resource, err)
}
Expand All @@ -103,25 +97,23 @@ func DeleteServiceAccountv1(ctx context.Context, client coreclientv1.ServiceAcco
}

// DeleteConfigMapv1 checks the given resource for a valid delete annotation. If found
// and in UpdatingMode it will issue a delete request or provide status of a previousily issued delete request.
// If not in UpdatingMode it simply returns an indication that the delete annotation was found. An error is
// returned if an invalid annotation is found or an error occurs during delete processing.
// it checks the status of a previousily issued delete request. If delete has not been
// requested and in UpdatingMode it will issue a delete request.
func DeleteConfigMapv1(ctx context.Context, client coreclientv1.ConfigMapsGetter, required *corev1.ConfigMap,
updateMode bool) (bool, error) {

if delAnnoFound, err := ValidDeleteAnnotation(required.Annotations); !delAnnoFound || err != nil {
return delAnnoFound, err
} else if !updateMode {
return true, nil
}
existing, err := client.ConfigMaps(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
resource := Resource{
Kind: "configmap",
Namespace: required.Namespace,
Name: required.Name,
}
existing, err := client.ConfigMaps(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
if deleteRequested, err := GetDeleteProgress(resource, err); err == nil {
if !deleteRequested {
// Only request deletion when in update mode.
if !deleteRequested && updateMode {
if err := client.ConfigMaps(required.Namespace).Delete(ctx, required.Name, metav1.DeleteOptions{}); err != nil {
return true, fmt.Errorf("Delete request for %s failed, err=%v", resource, err)
}
Expand Down
12 changes: 5 additions & 7 deletions lib/resourcedelete/imagestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ import (
)

// DeleteImageStreamv1 checks the given resource for a valid delete annotation. If found
// and in UpdatingMode it will issue a delete request or provide status of a previousily issued delete request.
// If not in UpdatingMode it simply returns an indication that the delete annotation was found. An error is
// returned if an invalid annotation is found or an error occurs during delete processing.
// it checks the status of a previousily issued delete request. If delete has not been
// requested and in UpdatingMode it will issue a delete request.
func DeleteImageStreamv1(ctx context.Context, client imageclientv1.ImageStreamsGetter, required *imagev1.ImageStream,
updateMode bool) (bool, error) {

if delAnnoFound, err := ValidDeleteAnnotation(required.Annotations); !delAnnoFound || err != nil {
return delAnnoFound, err
} else if !updateMode {
return true, nil
}
existing, err := client.ImageStreams(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
resource := Resource{
Kind: "imagestream",
Namespace: required.Namespace,
Name: required.Name,
}
existing, err := client.ImageStreams(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
if deleteRequested, err := GetDeleteProgress(resource, err); err == nil {
if !deleteRequested {
// Only request deletion when in update mode.
if !deleteRequested && updateMode {
if err := client.ImageStreams(required.Namespace).Delete(ctx, required.Name, metav1.DeleteOptions{}); err != nil {
return true, fmt.Errorf("Delete request for %s failed, err=%v", resource, err)
}
Expand Down