diff --git a/internal/load/build.go b/internal/load/build.go index 7caba154..3d01d246 100644 --- a/internal/load/build.go +++ b/internal/load/build.go @@ -47,12 +47,9 @@ func registerSingleBuild(kubeAccess KubeAccess, namespace string, name string, b return nil, err } - var graceperiod = int64(0) - deleteOptions := metav1.DeleteOptions{GracePeriodSeconds: &graceperiod} - if !buildRunOptions.skipDelete { defer func() { - if err := deleteBuild(kubeAccess, build.Namespace, build.Name, &deleteOptions); err != nil { + if err := deleteBuild(kubeAccess, build.Namespace, build.Name, defaultDeleteOptions); err != nil { warn("failed to delete build %s, %v\n", name, err) } }() diff --git a/internal/load/buildrun.go b/internal/load/buildrun.go index 1227b254..1c556fbd 100644 --- a/internal/load/buildrun.go +++ b/internal/load/buildrun.go @@ -24,14 +24,13 @@ import ( "sync" "time" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/gonvenience/bunt" "github.com/gonvenience/text" + buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) type buildRunOptions struct { @@ -178,12 +177,9 @@ func ExecuteSingleBuildRun(kubeAccess KubeAccess, namespace string, name string, return nil, err } - var graceperiod = int64(0) - deleteOptions := metav1.DeleteOptions{GracePeriodSeconds: &graceperiod} - if !buildRunOptions.skipDelete { defer func() { - if err := deleteBuild(kubeAccess, build.Namespace, build.Name, &deleteOptions); err != nil { + if err := deleteBuild(kubeAccess, build.Namespace, build.Name, defaultDeleteOptions); err != nil { warn("failed to delete build %s, %v\n", name, err) } }() @@ -196,7 +192,7 @@ func ExecuteSingleBuildRun(kubeAccess KubeAccess, namespace string, name string, if !buildRunOptions.skipDelete { defer func() { - if err := deleteBuildRun(kubeAccess, buildRun.Namespace, buildRun.Name, &deleteOptions); err != nil { + if err := deleteBuildRun(kubeAccess, buildRun.Namespace, buildRun.Name, defaultDeleteOptions); err != nil { warn("failed to delete buildrun %s, %v\n", name, err) } }() diff --git a/internal/load/kubeops.go b/internal/load/kubeops.go index 907ed4d9..f81d7a56 100644 --- a/internal/load/kubeops.go +++ b/internal/load/kubeops.go @@ -41,6 +41,9 @@ import ( var ( defaultBuildRunWaitTimeout = time.Duration(5 * time.Minute) + defaultDeleteOptions = &metav1.DeleteOptions{ + GracePeriodSeconds: ptr.Int64(0), + } ) func newBuild(namespace string, name string, buildSpec buildv1alpha1.BuildSpec, annotations map[string]string) buildv1alpha1.Build { @@ -85,7 +88,7 @@ func newBuildRun(name string, build buildv1alpha1.Build, generateServiceAccount } func applyBuild(kubeAccess KubeAccess, build buildv1alpha1.Build) (*buildv1alpha1.Build, error) { - if err := deleteBuild(kubeAccess, build.Namespace, build.Name, &metav1.DeleteOptions{GracePeriodSeconds: ptr.Int64(0)}); err != nil { + if err := deleteBuild(kubeAccess, build.Namespace, build.Name, defaultDeleteOptions); err != nil { return nil, err } @@ -97,7 +100,7 @@ func applyBuild(kubeAccess KubeAccess, build buildv1alpha1.Build) (*buildv1alpha } func applyBuildRun(kubeAccess KubeAccess, buildRun buildv1alpha1.BuildRun) (*buildv1alpha1.BuildRun, error) { - if err := deleteBuildRun(kubeAccess, buildRun.Namespace, buildRun.Name, &metav1.DeleteOptions{GracePeriodSeconds: ptr.Int64(0)}); err != nil { + if err := deleteBuildRun(kubeAccess, buildRun.Namespace, buildRun.Name, defaultDeleteOptions); err != nil { return nil, err }