Skip to content

Commit

Permalink
Merge pull request #98312 from deads2k/finish-export-option-removal
Browse files Browse the repository at this point in the history
finish removal of exportoptions
  • Loading branch information
k8s-ci-robot authored Jan 25, 2021
2 parents a03264b + 3f0f38e commit b7fc3f9
Show file tree
Hide file tree
Showing 49 changed files with 482 additions and 2,626 deletions.
1,490 changes: 185 additions & 1,305 deletions api/openapi-spec/swagger.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/api/testing/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ var nonRoundTrippableTypes = sets.NewString(
"PatchOptions",
)

var commonKinds = []string{"Status", "ListOptions", "DeleteOptions", "ExportOptions", "GetOptions", "CreateOptions", "UpdateOptions", "PatchOptions"}
var commonKinds = []string{"Status", "ListOptions", "DeleteOptions", "GetOptions", "CreateOptions", "UpdateOptions", "PatchOptions"}

// TestCommonKindsRegistered verifies that all group/versions registered with
// the legacyscheme package have the common kinds.
Expand Down
1 change: 0 additions & 1 deletion pkg/controlplane/import_known_versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var typesAllowedTags = map[reflect.Type]bool{
reflect.TypeOf(metav1.OwnerReference{}): true,
reflect.TypeOf(metav1.LabelSelector{}): true,
reflect.TypeOf(metav1.GetOptions{}): true,
reflect.TypeOf(metav1.ExportOptions{}): true,
reflect.TypeOf(metav1.ListOptions{}): true,
reflect.TypeOf(metav1.DeleteOptions{}): true,
reflect.TypeOf(metav1.GroupVersionKind{}): true,
Expand Down
21 changes: 2 additions & 19 deletions pkg/controlplane/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,7 @@ func TestLegacyRestStorageStrategies(t *testing.T) {
t.Errorf("failed to create legacy REST storage: %v", err)
}

// Any new stores with export logic will need to be added here:
exceptions := registrytest.StrategyExceptions{
// Only these stores should have an export strategy defined:
HasExportStrategy: []string{
"secrets",
"limitRanges",
"nodes",
"podTemplates",
},
}

strategyErrors := registrytest.ValidateStorageStrategies(apiGroupInfo.VersionedResourcesStorageMap["v1"], exceptions)
strategyErrors := registrytest.ValidateStorageStrategies(apiGroupInfo.VersionedResourcesStorageMap["v1"])
for _, err := range strategyErrors {
t.Error(err)
}
Expand All @@ -187,14 +176,8 @@ func TestCertificatesRestStorageStrategies(t *testing.T) {
t.Fatalf("unexpected error from REST storage: %v", err)
}

exceptions := registrytest.StrategyExceptions{
HasExportStrategy: []string{
"certificatesigningrequests",
},
}

strategyErrors := registrytest.ValidateStorageStrategies(
apiGroupInfo.VersionedResourcesStorageMap[certificatesapiv1beta1.SchemeGroupVersion.Version], exceptions)
apiGroupInfo.VersionedResourcesStorageMap[certificatesapiv1beta1.SchemeGroupVersion.Version])
for _, err := range strategyErrors {
t.Error(err)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/registry/certificates/certificates/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST, *Approva
CreateStrategy: csrregistry.Strategy,
UpdateStrategy: csrregistry.Strategy,
DeleteStrategy: csrregistry.Strategy,
ExportStrategy: csrregistry.Strategy,

TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)},
}
Expand Down
15 changes: 0 additions & 15 deletions pkg/registry/certificates/certificates/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,6 @@ func (csrStrategy) AllowUnconditionalUpdate() bool {
return true
}

func (s csrStrategy) Export(ctx context.Context, obj runtime.Object, exact bool) error {
csr, ok := obj.(*certificates.CertificateSigningRequest)
if !ok {
// unexpected programmer error
return fmt.Errorf("unexpected object: %v", obj)
}
s.PrepareForCreate(ctx, obj)
if exact {
return nil
}
// CSRs allow direct subresource edits, we clear them without exact so the CSR value can be reused.
csr.Status = certificates.CertificateSigningRequestStatus{}
return nil
}

// Storage strategy for the Status subresource
type csrStatusStrategy struct {
csrStrategy
Expand Down
1 change: 0 additions & 1 deletion pkg/registry/core/limitrange/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) {
CreateStrategy: limitrange.Strategy,
UpdateStrategy: limitrange.Strategy,
DeleteStrategy: limitrange.Strategy,
ExportStrategy: limitrange.Strategy,

// TODO: define table converter that exposes more than name/creation timestamp
TableConvertor: rest.NewDefaultTableConvertor(api.Resource("limitranges")),
Expand Down
7 changes: 0 additions & 7 deletions pkg/registry/core/limitrange/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,3 @@ func (limitrangeStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.O
func (limitrangeStrategy) AllowUnconditionalUpdate() bool {
return true
}

func (limitrangeStrategy) Export(context.Context, runtime.Object, bool) error {
// Copied from OpenShift exporter
// TODO: this needs to be fixed
// limitrange.Strategy.PrepareForCreate(ctx, obj)
return nil
}
4 changes: 0 additions & 4 deletions pkg/registry/core/namespace/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ func (r *REST) Watch(ctx context.Context, options *metainternalversion.ListOptio
return r.store.Watch(ctx, options)
}

func (r *REST) Export(ctx context.Context, name string, opts metav1.ExportOptions) (runtime.Object, error) {
return r.store.Export(ctx, name, opts)
}

// Delete enforces life-cycle rules for namespace termination
func (r *REST) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions) (runtime.Object, bool, error) {
nsObj, err := r.Get(ctx, name, &metav1.GetOptions{})
Expand Down
1 change: 0 additions & 1 deletion pkg/registry/core/node/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func NewStorage(optsGetter generic.RESTOptionsGetter, kubeletClientConfig client
CreateStrategy: node.Strategy,
UpdateStrategy: node.Strategy,
DeleteStrategy: node.Strategy,
ExportStrategy: node.Strategy,

TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)},
}
Expand Down
16 changes: 0 additions & 16 deletions pkg/registry/core/node/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,6 @@ func (nodeStrategy) AllowUnconditionalUpdate() bool {
return true
}

func (ns nodeStrategy) Export(ctx context.Context, obj runtime.Object, exact bool) error {
n, ok := obj.(*api.Node)
if !ok {
// unexpected programmer error
return fmt.Errorf("unexpected object: %v", obj)
}
ns.PrepareForCreate(ctx, obj)
if exact {
return nil
}
// Nodes are the only resources that allow direct status edits, therefore
// we clear that without exact so that the node value can be reused.
n.Status = api.NodeStatus{}
return nil
}

type nodeStatusStrategy struct {
nodeStrategy
}
Expand Down
1 change: 0 additions & 1 deletion pkg/registry/core/podtemplate/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) {
CreateStrategy: podtemplate.Strategy,
UpdateStrategy: podtemplate.Strategy,
DeleteStrategy: podtemplate.Strategy,
ExportStrategy: podtemplate.Strategy,

ReturnDeletedObject: true,

Expand Down
5 changes: 0 additions & 5 deletions pkg/registry/core/podtemplate/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,3 @@ func (podTemplateStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.
func (podTemplateStrategy) AllowUnconditionalUpdate() bool {
return true
}

func (podTemplateStrategy) Export(ctx context.Context, obj runtime.Object, exact bool) error {
// Do nothing
return nil
}
4 changes: 0 additions & 4 deletions pkg/registry/core/secret/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ go_library(
"//pkg/api/legacyscheme:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/core/validation:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors: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",
Expand All @@ -37,9 +36,6 @@ go_test(
"//pkg/api/testing:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/core/install:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
],
)

Expand Down
1 change: 0 additions & 1 deletion pkg/registry/core/secret/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) {
CreateStrategy: secret.Strategy,
UpdateStrategy: secret.Strategy,
DeleteStrategy: secret.Strategy,
ExportStrategy: secret.Strategy,

TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)},
}
Expand Down
21 changes: 0 additions & 21 deletions pkg/registry/core/secret/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -85,26 +84,6 @@ func (strategy) AllowUnconditionalUpdate() bool {
return true
}

func (s strategy) Export(ctx context.Context, obj runtime.Object, exact bool) error {
t, ok := obj.(*api.Secret)
if !ok {
// unexpected programmer error
return fmt.Errorf("unexpected object: %v", obj)
}
s.PrepareForCreate(ctx, obj)
if exact {
return nil
}
// secrets that are tied to the UID of a service account cannot be exported anyway
if t.Type == api.SecretTypeServiceAccountToken || len(t.Annotations[api.ServiceAccountUIDKey]) > 0 {
errs := []*field.Error{
field.Invalid(field.NewPath("type"), t, "can not export service account secrets"),
}
return errors.NewInvalid(api.Kind("Secret"), t.Name, errs)
}
return nil
}

// GetAttrs returns labels and fields of a given object for filtering purposes.
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
secret, ok := obj.(*api.Secret)
Expand Down
78 changes: 0 additions & 78 deletions pkg/registry/core/secret/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,93 +17,15 @@ limitations under the License.
package secret

import (
"reflect"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
apitesting "k8s.io/kubernetes/pkg/api/testing"
api "k8s.io/kubernetes/pkg/apis/core"

// ensure types are installed
_ "k8s.io/kubernetes/pkg/apis/core/install"
)

func TestExportSecret(t *testing.T) {
tests := []struct {
objIn runtime.Object
objOut runtime.Object
exact bool
expectErr bool
}{
{
objIn: &api.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Data: map[string][]byte{
"foo": []byte("bar"),
},
},
objOut: &api.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Data: map[string][]byte{
"foo": []byte("bar"),
},
},
exact: true,
},
{
objIn: &api.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Type: api.SecretTypeServiceAccountToken,
},
expectErr: true,
},
{
objIn: &api.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
Annotations: map[string]string{
api.ServiceAccountUIDKey: "true",
},
},
},
expectErr: true,
},
{
objIn: &api.Pod{},
expectErr: true,
},
}

for _, test := range tests {
err := Strategy.Export(genericapirequest.NewContext(), test.objIn, test.exact)
if err != nil {
if !test.expectErr {
t.Errorf("unexpected error: %v", err)
}
continue
}
if test.expectErr {
t.Error("unexpected non-error")
continue
}
if !reflect.DeepEqual(test.objIn, test.objOut) {
t.Errorf("expected:\n%v\nsaw:\n%v\n", test.objOut, test.objIn)
}
}
}

func TestSelectableFieldLabelConversions(t *testing.T) {
apitesting.TestSelectableFieldLabelConversionsOfKind(t,
"v1",
Expand Down
5 changes: 0 additions & 5 deletions pkg/registry/core/service/storage/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ type ServiceStorage interface {
rest.CreaterUpdater
rest.GracefulDeleter
rest.Watcher
rest.Exporter
rest.StorageVersionProvider
}

Expand Down Expand Up @@ -189,10 +188,6 @@ func (rs *REST) Watch(ctx context.Context, options *metainternalversion.ListOpti
return rs.services.Watch(ctx, options)
}

func (rs *REST) Export(ctx context.Context, name string, opts metav1.ExportOptions) (runtime.Object, error) {
return rs.services.Export(ctx, name, opts)
}

func (rs *REST) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
service := obj.(*api.Service)

Expand Down
4 changes: 0 additions & 4 deletions pkg/registry/core/service/storage/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ func (s *serviceStorage) ConvertToTable(ctx context.Context, object runtime.Obje
panic("not implemented")
}

func (s *serviceStorage) Export(ctx context.Context, name string, opts metav1.ExportOptions) (runtime.Object, error) {
panic("not implemented")
}

func (s *serviceStorage) StorageVersion() runtime.GroupVersioner {
panic("not implemented")
}
Expand Down
1 change: 0 additions & 1 deletion pkg/registry/core/service/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func NewGenericREST(optsGetter generic.RESTOptionsGetter, serviceCIDR net.IPNet,
CreateStrategy: strategy,
UpdateStrategy: strategy,
DeleteStrategy: strategy,
ExportStrategy: strategy,

TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)},
}
Expand Down
Loading

0 comments on commit b7fc3f9

Please sign in to comment.