mirror of https://github.com/k3s-io/k3s
Ensure all new API versions of resources default to DeleteDependents
parent
0351853ea1
commit
3b099ddf86
|
@ -44,19 +44,20 @@ type daemonSetStrategy struct {
|
|||
// Strategy is the default logic that applies when creating and updating DaemonSet objects.
|
||||
var Strategy = daemonSetStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
|
||||
|
||||
// DefaultGarbageCollectionPolicy returns OrphanDependents by default. For apps/v1, returns DeleteDependents.
|
||||
// DefaultGarbageCollectionPolicy returns OrphanDependents for extensions/v1beta1 and apps/v1beta2 for backwards compatibility,
|
||||
// and DeleteDependents for all other versions.
|
||||
func (daemonSetStrategy) DefaultGarbageCollectionPolicy(ctx context.Context) rest.GarbageCollectionPolicy {
|
||||
var groupVersion schema.GroupVersion
|
||||
if requestInfo, found := genericapirequest.RequestInfoFrom(ctx); found {
|
||||
groupVersion := schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||
switch groupVersion {
|
||||
case extensionsv1beta1.SchemeGroupVersion, appsv1beta2.SchemeGroupVersion:
|
||||
// for back compatibility
|
||||
return rest.OrphanDependents
|
||||
default:
|
||||
return rest.DeleteDependents
|
||||
}
|
||||
groupVersion = schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||
}
|
||||
switch groupVersion {
|
||||
case extensionsv1beta1.SchemeGroupVersion, appsv1beta2.SchemeGroupVersion:
|
||||
// for back compatibility
|
||||
return rest.OrphanDependents
|
||||
default:
|
||||
return rest.DeleteDependents
|
||||
}
|
||||
return rest.OrphanDependents
|
||||
}
|
||||
|
||||
// NamespaceScoped returns true because all DaemonSets need to be within a namespace.
|
||||
|
|
|
@ -72,7 +72,7 @@ func TestDaemonsetDefaultGarbageCollectionPolicy(t *testing.T) {
|
|||
false,
|
||||
},
|
||||
{
|
||||
expectedGCPolicy: rest.OrphanDependents,
|
||||
expectedGCPolicy: rest.DeleteDependents,
|
||||
isNilRequestInfo: true,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -46,19 +46,20 @@ type deploymentStrategy struct {
|
|||
// objects via the REST API.
|
||||
var Strategy = deploymentStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
|
||||
|
||||
// DefaultGarbageCollectionPolicy returns OrphanDependents by default. For apps/v1, returns DeleteDependents.
|
||||
// DefaultGarbageCollectionPolicy returns OrphanDependents for extensions/v1beta1, apps/v1beta1, and apps/v1beta2 for backwards compatibility,
|
||||
// and DeleteDependents for all other versions.
|
||||
func (deploymentStrategy) DefaultGarbageCollectionPolicy(ctx context.Context) rest.GarbageCollectionPolicy {
|
||||
var groupVersion schema.GroupVersion
|
||||
if requestInfo, found := genericapirequest.RequestInfoFrom(ctx); found {
|
||||
groupVersion := schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||
switch groupVersion {
|
||||
case extensionsv1beta1.SchemeGroupVersion, appsv1beta1.SchemeGroupVersion, appsv1beta2.SchemeGroupVersion:
|
||||
// for back compatibility
|
||||
return rest.OrphanDependents
|
||||
default:
|
||||
return rest.DeleteDependents
|
||||
}
|
||||
groupVersion = schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||
}
|
||||
switch groupVersion {
|
||||
case extensionsv1beta1.SchemeGroupVersion, appsv1beta1.SchemeGroupVersion, appsv1beta2.SchemeGroupVersion:
|
||||
// for back compatibility
|
||||
return rest.OrphanDependents
|
||||
default:
|
||||
return rest.DeleteDependents
|
||||
}
|
||||
return rest.OrphanDependents
|
||||
}
|
||||
|
||||
// NamespaceScoped is true for deployment.
|
||||
|
|
|
@ -231,7 +231,7 @@ func TestDeploymentDefaultGarbageCollectionPolicy(t *testing.T) {
|
|||
false,
|
||||
},
|
||||
{
|
||||
expectedGCPolicy: rest.OrphanDependents,
|
||||
expectedGCPolicy: rest.DeleteDependents,
|
||||
isNilRequestInfo: true,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -52,19 +52,20 @@ type rsStrategy struct {
|
|||
// Strategy is the default logic that applies when creating and updating ReplicaSet objects.
|
||||
var Strategy = rsStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
|
||||
|
||||
// DefaultGarbageCollectionPolicy returns OrphanDependents by default. For apps/v1, returns DeleteDependents.
|
||||
// DefaultGarbageCollectionPolicy returns OrphanDependents for extensions/v1beta1 and apps/v1beta2 for backwards compatibility,
|
||||
// and DeleteDependents for all other versions.
|
||||
func (rsStrategy) DefaultGarbageCollectionPolicy(ctx context.Context) rest.GarbageCollectionPolicy {
|
||||
var groupVersion schema.GroupVersion
|
||||
if requestInfo, found := genericapirequest.RequestInfoFrom(ctx); found {
|
||||
groupVersion := schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||
switch groupVersion {
|
||||
case extensionsv1beta1.SchemeGroupVersion, appsv1beta2.SchemeGroupVersion:
|
||||
// for back compatibility
|
||||
return rest.OrphanDependents
|
||||
default:
|
||||
return rest.DeleteDependents
|
||||
}
|
||||
groupVersion = schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||
}
|
||||
switch groupVersion {
|
||||
case extensionsv1beta1.SchemeGroupVersion, appsv1beta2.SchemeGroupVersion:
|
||||
// for back compatibility
|
||||
return rest.OrphanDependents
|
||||
default:
|
||||
return rest.DeleteDependents
|
||||
}
|
||||
return rest.OrphanDependents
|
||||
}
|
||||
|
||||
// NamespaceScoped returns true because all ReplicaSets need to be within a namespace.
|
||||
|
|
|
@ -266,7 +266,7 @@ func TestReplicasetDefaultGarbageCollectionPolicy(t *testing.T) {
|
|||
false,
|
||||
},
|
||||
{
|
||||
expectedGCPolicy: rest.OrphanDependents,
|
||||
expectedGCPolicy: rest.DeleteDependents,
|
||||
isNilRequestInfo: true,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -43,19 +43,20 @@ type statefulSetStrategy struct {
|
|||
// Strategy is the default logic that applies when creating and updating Replication StatefulSet objects.
|
||||
var Strategy = statefulSetStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
|
||||
|
||||
// DefaultGarbageCollectionPolicy returns OrphanDependents by default. For apps/v1, returns DeleteDependents.
|
||||
// DefaultGarbageCollectionPolicy returns OrphanDependents for apps/v1beta1 and apps/v1beta2 for backwards compatibility,
|
||||
// and DeleteDependents for all other versions.
|
||||
func (statefulSetStrategy) DefaultGarbageCollectionPolicy(ctx context.Context) rest.GarbageCollectionPolicy {
|
||||
var groupVersion schema.GroupVersion
|
||||
if requestInfo, found := genericapirequest.RequestInfoFrom(ctx); found {
|
||||
groupVersion := schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||
switch groupVersion {
|
||||
case appsv1beta1.SchemeGroupVersion, appsv1beta2.SchemeGroupVersion:
|
||||
// for back compatibility
|
||||
return rest.OrphanDependents
|
||||
default:
|
||||
return rest.DeleteDependents
|
||||
}
|
||||
groupVersion = schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||
}
|
||||
switch groupVersion {
|
||||
case appsv1beta1.SchemeGroupVersion, appsv1beta2.SchemeGroupVersion:
|
||||
// for back compatibility
|
||||
return rest.OrphanDependents
|
||||
default:
|
||||
return rest.DeleteDependents
|
||||
}
|
||||
return rest.OrphanDependents
|
||||
}
|
||||
|
||||
// NamespaceScoped returns true because all StatefulSet' need to be within a namespace.
|
||||
|
|
|
@ -130,7 +130,7 @@ func TestStatefulsetDefaultGarbageCollectionPolicy(t *testing.T) {
|
|||
false,
|
||||
},
|
||||
{
|
||||
expectedGCPolicy: rest.OrphanDependents,
|
||||
expectedGCPolicy: rest.DeleteDependents,
|
||||
isNilRequestInfo: true,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -18,8 +18,12 @@ go_library(
|
|||
"//pkg/api/pod:go_default_library",
|
||||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/batch/validation:go_default_library",
|
||||
"//staging/src/k8s.io/api/batch/v1beta1:go_default_library",
|
||||
"//staging/src/k8s.io/api/batch/v2alpha1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/registry/rest:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/storage/names:go_default_library",
|
||||
],
|
||||
|
|
|
@ -19,8 +19,12 @@ package cronjob
|
|||
import (
|
||||
"context"
|
||||
|
||||
batchv1beta1 "k8s.io/api/batch/v1beta1"
|
||||
batchv2alpha1 "k8s.io/api/batch/v2alpha1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
"k8s.io/apiserver/pkg/storage/names"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
|
@ -38,10 +42,20 @@ type cronJobStrategy struct {
|
|||
// Strategy is the default logic that applies when creating and updating CronJob objects.
|
||||
var Strategy = cronJobStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
|
||||
|
||||
// DefaultGarbageCollectionPolicy returns Orphan because that was the default
|
||||
// behavior before the server-side garbage collection was implemented.
|
||||
// DefaultGarbageCollectionPolicy returns OrphanDependents for batch/v1beta1 and batch/v2alpha1 for backwards compatibility,
|
||||
// and DeleteDependents for all other versions.
|
||||
func (cronJobStrategy) DefaultGarbageCollectionPolicy(ctx context.Context) rest.GarbageCollectionPolicy {
|
||||
return rest.OrphanDependents
|
||||
var groupVersion schema.GroupVersion
|
||||
if requestInfo, found := genericapirequest.RequestInfoFrom(ctx); found {
|
||||
groupVersion = schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||
}
|
||||
switch groupVersion {
|
||||
case batchv1beta1.SchemeGroupVersion, batchv2alpha1.SchemeGroupVersion:
|
||||
// for back compatibility
|
||||
return rest.OrphanDependents
|
||||
default:
|
||||
return rest.DeleteDependents
|
||||
}
|
||||
}
|
||||
|
||||
// NamespaceScoped returns true because all scheduled jobs need to be within a namespace.
|
||||
|
|
|
@ -90,7 +90,22 @@ func TestCronJobStrategy(t *testing.T) {
|
|||
// Make sure we correctly implement the interface.
|
||||
// Otherwise a typo could silently change the default.
|
||||
var gcds rest.GarbageCollectionDeleteStrategy = Strategy
|
||||
if got, want := gcds.DefaultGarbageCollectionPolicy(genericapirequest.NewContext()), rest.OrphanDependents; got != want {
|
||||
if got, want := gcds.DefaultGarbageCollectionPolicy(genericapirequest.NewContext()), rest.DeleteDependents; got != want {
|
||||
t.Errorf("DefaultGarbageCollectionPolicy() = %#v, want %#v", got, want)
|
||||
}
|
||||
|
||||
var (
|
||||
v1beta1Ctx = genericapirequest.WithRequestInfo(genericapirequest.NewContext(), &genericapirequest.RequestInfo{APIGroup: "batch", APIVersion: "v1beta1", Resource: "cronjobs"})
|
||||
v2alpha1Ctx = genericapirequest.WithRequestInfo(genericapirequest.NewContext(), &genericapirequest.RequestInfo{APIGroup: "batch", APIVersion: "v2alpha1", Resource: "cronjobs"})
|
||||
otherVersionCtx = genericapirequest.WithRequestInfo(genericapirequest.NewContext(), &genericapirequest.RequestInfo{APIGroup: "batch", APIVersion: "v100", Resource: "cronjobs"})
|
||||
)
|
||||
if got, want := gcds.DefaultGarbageCollectionPolicy(v1beta1Ctx), rest.OrphanDependents; got != want {
|
||||
t.Errorf("DefaultGarbageCollectionPolicy() = %#v, want %#v", got, want)
|
||||
}
|
||||
if got, want := gcds.DefaultGarbageCollectionPolicy(v2alpha1Ctx), rest.OrphanDependents; got != want {
|
||||
t.Errorf("DefaultGarbageCollectionPolicy() = %#v, want %#v", got, want)
|
||||
}
|
||||
if got, want := gcds.DefaultGarbageCollectionPolicy(otherVersionCtx), rest.DeleteDependents; got != want {
|
||||
t.Errorf("DefaultGarbageCollectionPolicy() = %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,14 @@ go_library(
|
|||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/batch/validation:go_default_library",
|
||||
"//pkg/features:go_default_library",
|
||||
"//staging/src/k8s.io/api/batch/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/registry/generic:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/registry/rest:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/storage:go_default_library",
|
||||
|
|
|
@ -21,11 +21,14 @@ import (
|
|||
"fmt"
|
||||
"strconv"
|
||||
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/registry/generic"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
"k8s.io/apiserver/pkg/storage"
|
||||
|
@ -47,10 +50,20 @@ type jobStrategy struct {
|
|||
// Strategy is the default logic that applies when creating and updating Replication Controller objects.
|
||||
var Strategy = jobStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
|
||||
|
||||
// DefaultGarbageCollectionPolicy returns Orphan because that was the default
|
||||
// behavior before the server-side garbage collection was implemented.
|
||||
// DefaultGarbageCollectionPolicy returns OrphanDependents for batch/v1 for backwards compatibility,
|
||||
// and DeleteDependents for all other versions.
|
||||
func (jobStrategy) DefaultGarbageCollectionPolicy(ctx context.Context) rest.GarbageCollectionPolicy {
|
||||
return rest.OrphanDependents
|
||||
var groupVersion schema.GroupVersion
|
||||
if requestInfo, found := genericapirequest.RequestInfoFrom(ctx); found {
|
||||
groupVersion = schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||
}
|
||||
switch groupVersion {
|
||||
case batchv1.SchemeGroupVersion:
|
||||
// for back compatibility
|
||||
return rest.OrphanDependents
|
||||
default:
|
||||
return rest.DeleteDependents
|
||||
}
|
||||
}
|
||||
|
||||
// NamespaceScoped returns true because all jobs need to be within a namespace.
|
||||
|
|
|
@ -124,7 +124,18 @@ func TestJobStrategy(t *testing.T) {
|
|||
// Make sure we correctly implement the interface.
|
||||
// Otherwise a typo could silently change the default.
|
||||
var gcds rest.GarbageCollectionDeleteStrategy = Strategy
|
||||
if got, want := gcds.DefaultGarbageCollectionPolicy(genericapirequest.NewContext()), rest.OrphanDependents; got != want {
|
||||
if got, want := gcds.DefaultGarbageCollectionPolicy(genericapirequest.NewContext()), rest.DeleteDependents; got != want {
|
||||
t.Errorf("DefaultGarbageCollectionPolicy() = %#v, want %#v", got, want)
|
||||
}
|
||||
|
||||
var (
|
||||
v1Ctx = genericapirequest.WithRequestInfo(genericapirequest.NewContext(), &genericapirequest.RequestInfo{APIGroup: "batch", APIVersion: "v1", Resource: "jobs"})
|
||||
otherVersionCtx = genericapirequest.WithRequestInfo(genericapirequest.NewContext(), &genericapirequest.RequestInfo{APIGroup: "batch", APIVersion: "v100", Resource: "jobs"})
|
||||
)
|
||||
if got, want := gcds.DefaultGarbageCollectionPolicy(v1Ctx), rest.OrphanDependents; got != want {
|
||||
t.Errorf("DefaultGarbageCollectionPolicy() = %#v, want %#v", got, want)
|
||||
}
|
||||
if got, want := gcds.DefaultGarbageCollectionPolicy(otherVersionCtx), rest.DeleteDependents; got != want {
|
||||
t.Errorf("DefaultGarbageCollectionPolicy() = %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,14 @@ go_library(
|
|||
"//pkg/apis/core:go_default_library",
|
||||
"//pkg/apis/core/helper:go_default_library",
|
||||
"//pkg/apis/core/validation:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/registry/generic:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/registry/rest:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/storage:go_default_library",
|
||||
|
|
|
@ -24,11 +24,14 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/registry/generic"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
apistorage "k8s.io/apiserver/pkg/storage"
|
||||
|
@ -49,10 +52,20 @@ type rcStrategy struct {
|
|||
// Strategy is the default logic that applies when creating and updating Replication Controller objects.
|
||||
var Strategy = rcStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
|
||||
|
||||
// DefaultGarbageCollectionPolicy returns Orphan because that was the default
|
||||
// behavior before the server-side garbage collection was implemented.
|
||||
// DefaultGarbageCollectionPolicy returns OrphanDependents for v1 for backwards compatibility,
|
||||
// and DeleteDependents for all other versions.
|
||||
func (rcStrategy) DefaultGarbageCollectionPolicy(ctx context.Context) rest.GarbageCollectionPolicy {
|
||||
return rest.OrphanDependents
|
||||
var groupVersion schema.GroupVersion
|
||||
if requestInfo, found := genericapirequest.RequestInfoFrom(ctx); found {
|
||||
groupVersion = schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||
}
|
||||
switch groupVersion {
|
||||
case corev1.SchemeGroupVersion:
|
||||
// for back compatibility
|
||||
return rest.OrphanDependents
|
||||
default:
|
||||
return rest.DeleteDependents
|
||||
}
|
||||
}
|
||||
|
||||
// NamespaceScoped returns true because all Replication Controllers need to be within a namespace.
|
||||
|
|
Loading…
Reference in New Issue