Skip to content

Bug 1939294: Avoid setting metadata.GracePeriodSeconds to zero seconds #2047

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/api/wrappers/deployment_install_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wrappers

import (
"context"

"github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -102,7 +103,8 @@ func (c *InstallStrategyDeploymentClientForNamespace) CreateDeployment(deploymen

func (c *InstallStrategyDeploymentClientForNamespace) DeleteDeployment(name string) error {
foregroundDelete := metav1.DeletePropagationForeground // cascading delete
immediate := int64(0)
// Note(tflannag): See https://bugzilla.redhat.com/show_bug.cgi?id=1939294.
immediate := int64(1)
immediateForegroundDelete := &metav1.DeleteOptions{GracePeriodSeconds: &immediate, PropagationPolicy: &foregroundDelete}
return c.opClient.DeleteDeployment(c.Namespace, name, immediateForegroundDelete)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/operators/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var (
ctx context.Context

scheme = runtime.NewScheme()
gracePeriod int64 = 0
gracePeriod int64 = 1
propagation = metav1.DeletePropagationForeground
deleteOpts = &client.DeleteOptions{
GracePeriodSeconds: &gracePeriod,
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/registry/reconciler/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (c *ConfigMapRegistryReconciler) ensurePod(source configMapCatalogSourceDec
return nil
}
for _, p := range currentPods {
if err := c.OpClient.KubernetesInterface().CoreV1().Pods(pod.GetNamespace()).Delete(context.TODO(), p.GetName(), *metav1.NewDeleteOptions(0)); err != nil {
if err := c.OpClient.KubernetesInterface().CoreV1().Pods(pod.GetNamespace()).Delete(context.TODO(), p.GetName(), *metav1.NewDeleteOptions(1)); err != nil {
return errors.Wrapf(err, "error deleting old pod: %s", p.GetName())
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/registry/reconciler/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (c *GrpcRegistryReconciler) ensurePod(source grpcCatalogSourceDecorator, sa
return nil
}
for _, p := range currentLivePods {
if err := c.OpClient.KubernetesInterface().CoreV1().Pods(source.GetNamespace()).Delete(context.TODO(), p.GetName(), *metav1.NewDeleteOptions(0)); err != nil {
if err := c.OpClient.KubernetesInterface().CoreV1().Pods(source.GetNamespace()).Delete(context.TODO(), p.GetName(), *metav1.NewDeleteOptions(1)); 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.

Probably easiest if I also add a package constant set to 1 and just reference that variable in NewDeleteOptions(...) instead of hardcoding the value of 1. I need to double-check what the default grace period seconds are, and whether we can just pass an empty metav1.DeleteOptions object instead of explicitly setting the grace period every time.

Copy link
Member

Choose a reason for hiding this comment

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

I'm partial to a package scoped constant that is also the zero value for metav1.DeleteOptions: metav1.DeleteOptions{}.

According to the type docs, as long as the GracePeriodSeconds field is nil:

... the default grace period for the specified type will be used.

return errors.Wrapf(err, "error deleting old pod: %s", p.GetName())
}
}
Expand Down Expand Up @@ -307,6 +307,7 @@ func (c *GrpcRegistryReconciler) ensureService(source grpcCatalogSourceDecorator
if !overwrite && ServiceHashMatch(svc, service) {
return nil
}
// TODO(tflannag): Do we care about force deleting services?
if err := c.OpClient.DeleteService(service.GetNamespace(), service.GetName(), metav1.NewDeleteOptions(0)); err != nil {
return err
}
Expand Down Expand Up @@ -402,7 +403,7 @@ func imageID(pod *corev1.Pod) string {

func (c *GrpcRegistryReconciler) removePods(pods []*corev1.Pod, namespace string) error {
for _, p := range pods {
err := c.OpClient.KubernetesInterface().CoreV1().Pods(namespace).Delete(context.TODO(), p.GetName(), *metav1.NewDeleteOptions(0))
err := c.OpClient.KubernetesInterface().CoreV1().Pods(namespace).Delete(context.TODO(), p.GetName(), *metav1.NewDeleteOptions(1))
if err != nil {
return errors.Wrapf(err, "error deleting pod: %s", p.GetName())
}
Expand Down
4 changes: 2 additions & 2 deletions test/rh-operators/operator_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/operator-framework/api/pkg/operators/v1"
v1 "github.com/operator-framework/api/pkg/operators/v1"
"github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
Expand All @@ -26,7 +26,7 @@ var (
pollDuration = 20 * time.Minute
terminationDuration = 5 * time.Minute

immediate = int64(0)
immediate = int64(1)
immediateDeleteOption = &metav1.DeleteOptions{GracePeriodSeconds: &immediate}
)

Expand Down