mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Add IPAddress API to the REST registry
ipaddress registry storage don't generate names for ipaddress
This commit is contained in:
parent
d9cc625538
commit
a2dfbd6117
17
pkg/registry/networking/ipaddress/doc.go
Normal file
17
pkg/registry/networking/ipaddress/doc.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ipaddress // import "k8s.io/kubernetes/pkg/registry/networking/ipaddress"
|
63
pkg/registry/networking/ipaddress/storage/storage.go
Normal file
63
pkg/registry/networking/ipaddress/storage/storage.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apiserver/pkg/registry/generic"
|
||||||
|
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
|
||||||
|
"k8s.io/apiserver/pkg/registry/rest"
|
||||||
|
"k8s.io/kubernetes/pkg/apis/networking"
|
||||||
|
"k8s.io/kubernetes/pkg/printers"
|
||||||
|
printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
|
||||||
|
printerstorage "k8s.io/kubernetes/pkg/printers/storage"
|
||||||
|
"k8s.io/kubernetes/pkg/registry/networking/ipaddress"
|
||||||
|
)
|
||||||
|
|
||||||
|
// REST implements a RESTStorage for IPAddress against etcd
|
||||||
|
type REST struct {
|
||||||
|
*genericregistry.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewREST returns a RESTStorage object that will work against endpoint slices.
|
||||||
|
func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) {
|
||||||
|
store := &genericregistry.Store{
|
||||||
|
NewFunc: func() runtime.Object { return &networking.IPAddress{} },
|
||||||
|
NewListFunc: func() runtime.Object { return &networking.IPAddressList{} },
|
||||||
|
DefaultQualifiedResource: networking.Resource("ipaddresses"),
|
||||||
|
SingularQualifiedResource: networking.Resource("ipaddress"),
|
||||||
|
|
||||||
|
CreateStrategy: ipaddress.Strategy,
|
||||||
|
UpdateStrategy: ipaddress.Strategy,
|
||||||
|
DeleteStrategy: ipaddress.Strategy,
|
||||||
|
|
||||||
|
TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)},
|
||||||
|
}
|
||||||
|
options := &generic.StoreOptions{RESTOptions: optsGetter}
|
||||||
|
if err := store.CompleteWithOptions(options); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &REST{store}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implement ShortNamesProvider.
|
||||||
|
var _ rest.ShortNamesProvider = &REST{}
|
||||||
|
|
||||||
|
// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
|
||||||
|
func (r *REST) ShortNames() []string {
|
||||||
|
return []string{"ip"}
|
||||||
|
}
|
110
pkg/registry/networking/ipaddress/strategy.go
Normal file
110
pkg/registry/networking/ipaddress/strategy.go
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ipaddress
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
|
"k8s.io/apiserver/pkg/registry/rest"
|
||||||
|
"k8s.io/apiserver/pkg/storage/names"
|
||||||
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
|
"k8s.io/kubernetes/pkg/apis/networking"
|
||||||
|
"k8s.io/kubernetes/pkg/apis/networking/validation"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ipAddressStrategy implements verification logic for Replication.
|
||||||
|
type ipAddressStrategy struct {
|
||||||
|
runtime.ObjectTyper
|
||||||
|
names.NameGenerator
|
||||||
|
}
|
||||||
|
|
||||||
|
// noopNameGenerator does not generate names, it just returns the base.
|
||||||
|
type noopNameGenerator struct{}
|
||||||
|
|
||||||
|
func (noopNameGenerator) GenerateName(base string) string {
|
||||||
|
return base
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strategy is the default logic that applies when creating and updating Replication IPAddress objects.
|
||||||
|
var Strategy = ipAddressStrategy{legacyscheme.Scheme, noopNameGenerator{}}
|
||||||
|
|
||||||
|
// Strategy should implement rest.RESTCreateStrategy
|
||||||
|
var _ rest.RESTCreateStrategy = Strategy
|
||||||
|
|
||||||
|
// Strategy should implement rest.RESTUpdateStrategy
|
||||||
|
var _ rest.RESTUpdateStrategy = Strategy
|
||||||
|
|
||||||
|
// NamespaceScoped returns false because all IPAddresses is cluster scoped.
|
||||||
|
func (ipAddressStrategy) NamespaceScoped() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrepareForCreate clears the status of an IPAddress before creation.
|
||||||
|
func (ipAddressStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
|
||||||
|
_ = obj.(*networking.IPAddress)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||||
|
func (ipAddressStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
|
||||||
|
newIPAddress := obj.(*networking.IPAddress)
|
||||||
|
oldIPAddress := old.(*networking.IPAddress)
|
||||||
|
|
||||||
|
_, _ = newIPAddress, oldIPAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate validates a new IPAddress.
|
||||||
|
func (ipAddressStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
|
||||||
|
ipAddress := obj.(*networking.IPAddress)
|
||||||
|
err := validation.ValidateIPAddress(ipAddress)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Canonicalize normalizes the object after validation.
|
||||||
|
func (ipAddressStrategy) Canonicalize(obj runtime.Object) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllowCreateOnUpdate is false for IPAddress; this means POST is needed to create one.
|
||||||
|
func (ipAddressStrategy) AllowCreateOnUpdate() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidateUpdate is the default update validation for an end user.
|
||||||
|
func (ipAddressStrategy) ValidateUpdate(ctx context.Context, new, old runtime.Object) field.ErrorList {
|
||||||
|
newIPAddress := new.(*networking.IPAddress)
|
||||||
|
oldIPAddress := old.(*networking.IPAddress)
|
||||||
|
errList := validation.ValidateIPAddress(newIPAddress)
|
||||||
|
errList = append(errList, validation.ValidateIPAddressUpdate(newIPAddress, oldIPAddress)...)
|
||||||
|
return errList
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllowUnconditionalUpdate is the default update policy for IPAddress objects.
|
||||||
|
func (ipAddressStrategy) AllowUnconditionalUpdate() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
|
func (ipAddressStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WarningsOnUpdate returns warnings for the given update.
|
||||||
|
func (ipAddressStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||||
|
return nil
|
||||||
|
}
|
17
pkg/registry/networking/ipaddress/strategy_test.go
Normal file
17
pkg/registry/networking/ipaddress/strategy_test.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ipaddress
|
Loading…
Reference in New Issue
Block a user