mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00
fpga webhook: reimplement to use kubebuilder framework
Simplify upgrade procedure to newer versions of kubernetes by relying on the kubebuilder framework rather than using codegen directly. Closes #377
This commit is contained in:
parent
c923b712d9
commit
a62c6f7d5e
14
DEVEL.md
14
DEVEL.md
@ -155,22 +155,10 @@ Just run it inside the repo's root, e.g.
|
|||||||
```
|
```
|
||||||
$ ./k8s_gomod_update.sh 1.18.1
|
$ ./k8s_gomod_update.sh 1.18.1
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run the code generator script which can be found at
|
|
||||||
https://github.com/kubernetes/code-generator/blob/master/generate-groups.sh
|
|
||||||
|
|
||||||
```
|
|
||||||
$ generate-groups.sh all github.com/intel/intel-device-plugins-for-kubernetes/pkg/client \
|
|
||||||
github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis \
|
|
||||||
fpga.intel.com:v2
|
|
||||||
```
|
|
||||||
|
|
||||||
Please note that the script (at least of v0.18.2-beta.0) expects the device plugins
|
|
||||||
repo to be located under $GOPATH/src.
|
|
||||||
|
|
||||||
Finally run
|
Finally run
|
||||||
|
|
||||||
```
|
```
|
||||||
|
$ make generate
|
||||||
$ make test
|
$ make test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
9
Makefile
9
Makefile
@ -60,14 +60,21 @@ lint:
|
|||||||
checks: lint go-mod-tidy
|
checks: lint go-mod-tidy
|
||||||
|
|
||||||
generate:
|
generate:
|
||||||
$(CONTROLLER_GEN) object:headerFile="build/boilerplate/boilerplate.go.txt" paths="./pkg/apis/deviceplugin/..."
|
$(CONTROLLER_GEN) object:headerFile="build/boilerplate/boilerplate.go.txt" paths="./pkg/apis/..."
|
||||||
$(CONTROLLER_GEN) crd:trivialVersions=true \
|
$(CONTROLLER_GEN) crd:trivialVersions=true \
|
||||||
paths="./pkg/apis/deviceplugin/..." \
|
paths="./pkg/apis/deviceplugin/..." \
|
||||||
output:crd:artifacts:config=deployments/operator/crd/bases
|
output:crd:artifacts:config=deployments/operator/crd/bases
|
||||||
|
$(CONTROLLER_GEN) crd:trivialVersions=true \
|
||||||
|
paths="./pkg/apis/fpga.intel.com/..." \
|
||||||
|
output:crd:artifacts:config=deployments/fpga_admissionwebhook/crd/bases
|
||||||
$(CONTROLLER_GEN) webhook \
|
$(CONTROLLER_GEN) webhook \
|
||||||
paths="./pkg/apis/deviceplugin/..." \
|
paths="./pkg/apis/deviceplugin/..." \
|
||||||
output:webhook:artifacts:config=deployments/operator/webhook
|
output:webhook:artifacts:config=deployments/operator/webhook
|
||||||
|
$(CONTROLLER_GEN) webhook \
|
||||||
|
paths="./pkg/fpgacontroller/..." \
|
||||||
|
output:webhook:artifacts:config=deployments/fpga_admissionwebhook/webhook
|
||||||
$(CONTROLLER_GEN) rbac:roleName=manager-role paths="./pkg/controllers/..." output:dir=deployments/operator/rbac
|
$(CONTROLLER_GEN) rbac:roleName=manager-role paths="./pkg/controllers/..." output:dir=deployments/operator/rbac
|
||||||
|
$(CONTROLLER_GEN) rbac:roleName=manager-role paths="./pkg/fpgacontroller/..." output:dir=deployments/fpga_admissionwebhook/rbac
|
||||||
|
|
||||||
$(cmds):
|
$(cmds):
|
||||||
cd cmd/$@; $(GO) build -tags $(BUILDTAGS)
|
cd cmd/$@; $(GO) build -tags $(BUILDTAGS)
|
||||||
|
@ -1,258 +0,0 @@
|
|||||||
// Copyright 2018 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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 main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
|
||||||
"k8s.io/apimachinery/pkg/util/runtime"
|
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
"k8s.io/client-go/rest"
|
|
||||||
"k8s.io/client-go/tools/cache"
|
|
||||||
"k8s.io/client-go/util/workqueue"
|
|
||||||
"k8s.io/klog"
|
|
||||||
|
|
||||||
clientset "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned"
|
|
||||||
informers "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/informers/externalversions"
|
|
||||||
listers "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/listers/fpga.intel.com/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
resyncPeriod = 0 * time.Second
|
|
||||||
)
|
|
||||||
|
|
||||||
type fpgaObjectKey struct {
|
|
||||||
name string
|
|
||||||
kind string
|
|
||||||
}
|
|
||||||
|
|
||||||
type controller struct {
|
|
||||||
patcherManager patcherManager
|
|
||||||
informerFactory informers.SharedInformerFactory
|
|
||||||
afsSynced cache.InformerSynced
|
|
||||||
regionsSynced cache.InformerSynced
|
|
||||||
afLister listers.AcceleratorFunctionLister
|
|
||||||
regionLister listers.FpgaRegionLister
|
|
||||||
queue workqueue.RateLimitingInterface
|
|
||||||
stopCh chan struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newController(patcherManager patcherManager, config *rest.Config) (*controller, error) {
|
|
||||||
clientset, err := clientset.NewForConfig(config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "Failed to create REST clientset")
|
|
||||||
}
|
|
||||||
|
|
||||||
informerFactory := informers.NewSharedInformerFactory(clientset, resyncPeriod)
|
|
||||||
stopCh := make(chan struct{})
|
|
||||||
|
|
||||||
afInformer := informerFactory.Fpga().V2().AcceleratorFunctions()
|
|
||||||
regionInformer := informerFactory.Fpga().V2().FpgaRegions()
|
|
||||||
|
|
||||||
controller := &controller{
|
|
||||||
patcherManager: patcherManager,
|
|
||||||
informerFactory: informerFactory,
|
|
||||||
queue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()),
|
|
||||||
afsSynced: afInformer.Informer().HasSynced,
|
|
||||||
regionsSynced: regionInformer.Informer().HasSynced,
|
|
||||||
afLister: afInformer.Lister(),
|
|
||||||
regionLister: regionInformer.Lister(),
|
|
||||||
stopCh: stopCh,
|
|
||||||
}
|
|
||||||
afInformer.Informer().AddEventHandler(createEventHandler("af", controller.queue))
|
|
||||||
regionInformer.Informer().AddEventHandler(createEventHandler("region", controller.queue))
|
|
||||||
|
|
||||||
return controller, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// run sets up the event handlers for AcceleratorFunction and FpgaRegion types,
|
|
||||||
// as well as syncing informer caches and starts workers. It will block until stopCh
|
|
||||||
// is closed, at which point it will shutdown the workqueue and wait for
|
|
||||||
// workers to finish processing their current work items.
|
|
||||||
func (c *controller) run(threadiness int) error {
|
|
||||||
defer runtime.HandleCrash()
|
|
||||||
defer c.queue.ShutDown()
|
|
||||||
|
|
||||||
klog.V(1).Info("Starting controller")
|
|
||||||
|
|
||||||
go c.informerFactory.Start(c.stopCh)
|
|
||||||
|
|
||||||
if ok := cache.WaitForCacheSync(c.stopCh, c.afsSynced); !ok {
|
|
||||||
return errors.New("failed to wait for AF caches to sync")
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok := cache.WaitForCacheSync(c.stopCh, c.regionsSynced); !ok {
|
|
||||||
return errors.New("failed to wait for Region caches to sync")
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < threadiness; i++ {
|
|
||||||
go wait.Until(func() {
|
|
||||||
for c.processNextWorkItem() {
|
|
||||||
}
|
|
||||||
}, time.Second, c.stopCh)
|
|
||||||
}
|
|
||||||
klog.V(1).Info("Started controller workers")
|
|
||||||
<-c.stopCh
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// processNextWorkItem reads a single work item off the workqueue and
|
|
||||||
// attempts to process it, by calling the sync handlers.
|
|
||||||
func (c *controller) processNextWorkItem() bool {
|
|
||||||
obj, shutdown := c.queue.Get()
|
|
||||||
|
|
||||||
if shutdown {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// We wrap this block in a func so we can defer c.workqueue.Done.
|
|
||||||
err := func(obj interface{}) error {
|
|
||||||
var key fpgaObjectKey
|
|
||||||
var ok bool
|
|
||||||
|
|
||||||
// We call Done here so the workqueue knows we have finished
|
|
||||||
// processing this item.
|
|
||||||
defer c.queue.Done(obj)
|
|
||||||
|
|
||||||
if key, ok = obj.(fpgaObjectKey); !ok {
|
|
||||||
c.queue.Forget(obj)
|
|
||||||
return errors.Errorf("expected fpgaObjectKey in workqueue but got %#v", obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch key.kind {
|
|
||||||
case "af":
|
|
||||||
if err := c.syncAfHandler(key.name); err != nil {
|
|
||||||
return errors.Wrapf(err, "error syncing '%s'", key.name)
|
|
||||||
}
|
|
||||||
case "region":
|
|
||||||
if err := c.syncRegionHandler(key.name); err != nil {
|
|
||||||
return errors.Wrapf(err, "error syncing '%s'", key.name)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
c.queue.Forget(obj)
|
|
||||||
return errors.Errorf("Unknown kind of object key: %s", key.kind)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, if no error occurs we Forget this item so it does not
|
|
||||||
// get queued again until another change happens.
|
|
||||||
c.queue.Forget(obj)
|
|
||||||
klog.V(4).Infof("Successfully synced '%s'", key)
|
|
||||||
return nil
|
|
||||||
}(obj)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
runtime.HandleError(err)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *controller) syncAfHandler(key string) error {
|
|
||||||
// Convert the namespace/name string into a distinct namespace and name
|
|
||||||
namespace, name, err := cache.SplitMetaNamespaceKey(key)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HandleError(errors.Errorf("invalid resource key: %s", key))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
patcher := c.patcherManager.getPatcher(namespace)
|
|
||||||
|
|
||||||
// Get the AcceleratorFunction resource with this namespace/name
|
|
||||||
af, err := c.afLister.AcceleratorFunctions(namespace).Get(name)
|
|
||||||
if err != nil {
|
|
||||||
// The AcceleratorFunction resource may no longer exist, in which case we stop
|
|
||||||
// processing.
|
|
||||||
if k8serrors.IsNotFound(err) {
|
|
||||||
runtime.HandleError(errors.Errorf("accelerated function '%s' in work queue no longer exists", key))
|
|
||||||
klog.V(4).Infof("AF '%s' no longer exists", key)
|
|
||||||
patcher.removeAf(name)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
klog.V(4).Info("Received", af)
|
|
||||||
return patcher.addAf(af)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *controller) syncRegionHandler(key string) error {
|
|
||||||
// Convert the namespace/name string into a distinct namespace and name
|
|
||||||
namespace, name, err := cache.SplitMetaNamespaceKey(key)
|
|
||||||
if err != nil {
|
|
||||||
runtime.HandleError(errors.Errorf("invalid resource key: %s", key))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
patcher := c.patcherManager.getPatcher(namespace)
|
|
||||||
|
|
||||||
// Get the FpgaRegion resource with this namespace/name
|
|
||||||
region, err := c.regionLister.FpgaRegions(namespace).Get(name)
|
|
||||||
if err != nil {
|
|
||||||
// The FpgaRegion resource may no longer exist, in which case we stop
|
|
||||||
// processing.
|
|
||||||
if k8serrors.IsNotFound(err) {
|
|
||||||
runtime.HandleError(errors.Errorf("FPGA region '%s' in work queue no longer exists", key))
|
|
||||||
klog.V(4).Infof("Region '%s' no longer exists", key)
|
|
||||||
patcher.removeRegion(name)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
klog.V(4).Info("Received", region)
|
|
||||||
patcher.addRegion(region)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func createEventHandler(kind string, queue workqueue.RateLimitingInterface) cache.ResourceEventHandlerFuncs {
|
|
||||||
return cache.ResourceEventHandlerFuncs{
|
|
||||||
AddFunc: func(obj interface{}) {
|
|
||||||
key, err := cache.MetaNamespaceKeyFunc(obj)
|
|
||||||
if err == nil {
|
|
||||||
queue.Add(fpgaObjectKey{
|
|
||||||
name: key,
|
|
||||||
kind: kind,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
UpdateFunc: func(old, new interface{}) {
|
|
||||||
key, err := cache.MetaNamespaceKeyFunc(new)
|
|
||||||
if err == nil {
|
|
||||||
queue.Add(fpgaObjectKey{
|
|
||||||
name: key,
|
|
||||||
kind: kind,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
DeleteFunc: func(obj interface{}) {
|
|
||||||
// IndexerInformer uses a delta queue, therefore for deletes we have to use this
|
|
||||||
// key function.
|
|
||||||
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
|
|
||||||
if err == nil {
|
|
||||||
queue.Add(fpgaObjectKey{
|
|
||||||
name: key,
|
|
||||||
kind: kind,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,395 +0,0 @@
|
|||||||
// Copyright 2018 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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 main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
|
||||||
"k8s.io/client-go/rest"
|
|
||||||
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
listers "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/listers/fpga.intel.com/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type fakeAfNamespaceLister struct {
|
|
||||||
af *v2.AcceleratorFunction
|
|
||||||
err error
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
flag.Set("v", "4") ///Enable debug output
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nl *fakeAfNamespaceLister) Get(name string) (*v2.AcceleratorFunction, error) {
|
|
||||||
return nl.af, nl.err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nl *fakeAfNamespaceLister) List(selector labels.Selector) (ret []*v2.AcceleratorFunction, err error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type fakeAfLister struct {
|
|
||||||
af *v2.AcceleratorFunction
|
|
||||||
err error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *fakeAfLister) AcceleratorFunctions(namespace string) listers.AcceleratorFunctionNamespaceLister {
|
|
||||||
return &fakeAfNamespaceLister{
|
|
||||||
af: l.af,
|
|
||||||
err: l.err,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *fakeAfLister) List(selector labels.Selector) (ret []*v2.AcceleratorFunction, err error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSyncAfHandler(t *testing.T) {
|
|
||||||
tcases := []struct {
|
|
||||||
name string
|
|
||||||
key string
|
|
||||||
afLister *fakeAfLister
|
|
||||||
expectedErr bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "Wrong key format",
|
|
||||||
key: "wrong/key/format/of/object",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Known key",
|
|
||||||
key: "default/arria10-nlb0",
|
|
||||||
afLister: &fakeAfLister{
|
|
||||||
af: &v2.AcceleratorFunction{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "arria10-nlb0",
|
|
||||||
},
|
|
||||||
Spec: v2.AcceleratorFunctionSpec{
|
|
||||||
AfuID: "d8424dc4a4a3c413f89e433683f9040b",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Unknown key",
|
|
||||||
key: "default/unknown",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Unhandled error",
|
|
||||||
key: "default/unknown",
|
|
||||||
afLister: &fakeAfLister{
|
|
||||||
err: fmt.Errorf("Some fake error"),
|
|
||||||
},
|
|
||||||
expectedErr: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tcases {
|
|
||||||
pm := newPatcherManager()
|
|
||||||
c, err := newController(pm, &rest.Config{})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Test case '%s': %+v", tt.name, err)
|
|
||||||
}
|
|
||||||
if tt.afLister != nil {
|
|
||||||
c.afLister = tt.afLister
|
|
||||||
}
|
|
||||||
err = c.syncAfHandler(tt.key)
|
|
||||||
if err != nil && !tt.expectedErr {
|
|
||||||
t.Errorf("Test case '%s': unexpected error: %+v", tt.name, err)
|
|
||||||
}
|
|
||||||
if err == nil && tt.expectedErr {
|
|
||||||
t.Errorf("Test case '%s': expected error, but got success", tt.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type fakeRegionNamespaceLister struct {
|
|
||||||
region *v2.FpgaRegion
|
|
||||||
err error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nl *fakeRegionNamespaceLister) Get(name string) (*v2.FpgaRegion, error) {
|
|
||||||
return nl.region, nl.err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nl *fakeRegionNamespaceLister) List(selector labels.Selector) (ret []*v2.FpgaRegion, err error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type fakeRegionLister struct {
|
|
||||||
region *v2.FpgaRegion
|
|
||||||
err error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *fakeRegionLister) FpgaRegions(namespace string) listers.FpgaRegionNamespaceLister {
|
|
||||||
return &fakeRegionNamespaceLister{
|
|
||||||
region: l.region,
|
|
||||||
err: l.err,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *fakeRegionLister) List(selector labels.Selector) (ret []*v2.FpgaRegion, err error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSyncRegionHandler(t *testing.T) {
|
|
||||||
tcases := []struct {
|
|
||||||
name string
|
|
||||||
key string
|
|
||||||
regionLister *fakeRegionLister
|
|
||||||
expectedErr bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "Wrong key format",
|
|
||||||
key: "wrong/key/format/of/object",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Known key",
|
|
||||||
key: "default/arria10",
|
|
||||||
regionLister: &fakeRegionLister{
|
|
||||||
region: &v2.FpgaRegion{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "arria10",
|
|
||||||
},
|
|
||||||
Spec: v2.FpgaRegionSpec{
|
|
||||||
InterfaceID: "ce48969398f05f33946d560708be108a",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Unknown key",
|
|
||||||
key: "default/unknown",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Unhandled error",
|
|
||||||
key: "default/unknown",
|
|
||||||
regionLister: &fakeRegionLister{
|
|
||||||
err: fmt.Errorf("Some fake error"),
|
|
||||||
},
|
|
||||||
expectedErr: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tcases {
|
|
||||||
pm := newPatcherManager()
|
|
||||||
c, err := newController(pm, &rest.Config{})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Test case '%s': %+v", tt.name, err)
|
|
||||||
}
|
|
||||||
if tt.regionLister != nil {
|
|
||||||
c.regionLister = tt.regionLister
|
|
||||||
}
|
|
||||||
err = c.syncRegionHandler(tt.key)
|
|
||||||
if err != nil && !tt.expectedErr {
|
|
||||||
t.Errorf("Test case '%s': unexpected error: %+v", tt.name, err)
|
|
||||||
}
|
|
||||||
if err == nil && tt.expectedErr {
|
|
||||||
t.Errorf("Test case '%s': expected error, but got success", tt.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type fakeQueue struct {
|
|
||||||
obj *fpgaObjectKey
|
|
||||||
shutdown bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *fakeQueue) Add(item interface{}) {}
|
|
||||||
|
|
||||||
func (q *fakeQueue) AddAfter(item interface{}, duration time.Duration) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *fakeQueue) AddRateLimited(item interface{}) {}
|
|
||||||
|
|
||||||
func (q *fakeQueue) Done(item interface{}) {}
|
|
||||||
|
|
||||||
func (q *fakeQueue) Forget(item interface{}) {}
|
|
||||||
|
|
||||||
func (q *fakeQueue) Get() (item interface{}, shutdown bool) {
|
|
||||||
if q.obj == nil {
|
|
||||||
return nil, q.shutdown
|
|
||||||
}
|
|
||||||
|
|
||||||
return *q.obj, q.shutdown
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *fakeQueue) Len() int {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *fakeQueue) NumRequeues(item interface{}) int {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *fakeQueue) ShutDown() {}
|
|
||||||
|
|
||||||
func (q *fakeQueue) ShuttingDown() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestProcessNextWorkItem(t *testing.T) {
|
|
||||||
tcases := []struct {
|
|
||||||
name string
|
|
||||||
obj *fpgaObjectKey
|
|
||||||
afLister *fakeAfLister
|
|
||||||
regionLister *fakeRegionLister
|
|
||||||
expectedContinue bool
|
|
||||||
shutdown bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "Receive invalid object",
|
|
||||||
expectedContinue: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Shutdown queue",
|
|
||||||
shutdown: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Receive unknown kind of object",
|
|
||||||
obj: &fpgaObjectKey{
|
|
||||||
kind: "unknown",
|
|
||||||
},
|
|
||||||
expectedContinue: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Receive object with AF key",
|
|
||||||
obj: &fpgaObjectKey{
|
|
||||||
kind: "af",
|
|
||||||
},
|
|
||||||
expectedContinue: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Receive object with Region key",
|
|
||||||
obj: &fpgaObjectKey{
|
|
||||||
kind: "region",
|
|
||||||
},
|
|
||||||
expectedContinue: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Receive broken object with AF key",
|
|
||||||
obj: &fpgaObjectKey{
|
|
||||||
kind: "af",
|
|
||||||
},
|
|
||||||
afLister: &fakeAfLister{
|
|
||||||
err: fmt.Errorf("some fake error"),
|
|
||||||
},
|
|
||||||
expectedContinue: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Receive broken object with Region key",
|
|
||||||
obj: &fpgaObjectKey{
|
|
||||||
kind: "region",
|
|
||||||
},
|
|
||||||
regionLister: &fakeRegionLister{
|
|
||||||
err: fmt.Errorf("some fake error"),
|
|
||||||
},
|
|
||||||
expectedContinue: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tcases {
|
|
||||||
pm := newPatcherManager()
|
|
||||||
c, err := newController(pm, &rest.Config{})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Test case '%s': %+v", tt.name, err)
|
|
||||||
}
|
|
||||||
c.queue = &fakeQueue{
|
|
||||||
shutdown: tt.shutdown,
|
|
||||||
obj: tt.obj,
|
|
||||||
}
|
|
||||||
if tt.afLister != nil {
|
|
||||||
c.afLister = tt.afLister
|
|
||||||
}
|
|
||||||
if tt.regionLister != nil {
|
|
||||||
c.regionLister = tt.regionLister
|
|
||||||
}
|
|
||||||
toContinue := c.processNextWorkItem()
|
|
||||||
if toContinue != tt.expectedContinue {
|
|
||||||
t.Errorf("Test case '%s': expected toContinue flag %v, but got %v", tt.name, tt.expectedContinue, toContinue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreateEventhandler(t *testing.T) {
|
|
||||||
funcs := createEventHandler("testkind", &fakeQueue{})
|
|
||||||
funcs.AddFunc(&v2.FpgaRegion{})
|
|
||||||
funcs.UpdateFunc(nil, &v2.FpgaRegion{})
|
|
||||||
funcs.DeleteFunc(&v2.FpgaRegion{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRun(t *testing.T) {
|
|
||||||
tcases := []struct {
|
|
||||||
name string
|
|
||||||
expectedErr bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "Fail to wait for AF caches to sync",
|
|
||||||
expectedErr: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tcases {
|
|
||||||
pm := newPatcherManager()
|
|
||||||
c, err := newController(pm, &rest.Config{})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Test case '%s': %+v", tt.name, err)
|
|
||||||
}
|
|
||||||
close(c.stopCh)
|
|
||||||
err = c.run(0)
|
|
||||||
if err != nil && !tt.expectedErr {
|
|
||||||
t.Errorf("Test case '%s': unexpected error: %+v", tt.name, err)
|
|
||||||
}
|
|
||||||
if err == nil && tt.expectedErr {
|
|
||||||
t.Errorf("Test case '%s': expected error, but got success", tt.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewController(t *testing.T) {
|
|
||||||
tcases := []struct {
|
|
||||||
name string
|
|
||||||
configHost string
|
|
||||||
expectedErr bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "wrong config",
|
|
||||||
configHost: "hostname/somepath",
|
|
||||||
expectedErr: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "successful creation",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tcases {
|
|
||||||
config := &rest.Config{
|
|
||||||
Host: tt.configHost,
|
|
||||||
}
|
|
||||||
pm := newPatcherManager()
|
|
||||||
c, err := newController(pm, config)
|
|
||||||
if err != nil && !tt.expectedErr {
|
|
||||||
t.Errorf("Test case '%s': unexpected error: %+v", tt.name, err)
|
|
||||||
}
|
|
||||||
if err == nil && tt.expectedErr {
|
|
||||||
t.Errorf("Test case '%s': expected error, but got success", tt.name)
|
|
||||||
}
|
|
||||||
if err == nil && c == nil {
|
|
||||||
t.Errorf("Test case '%s': no controller created", tt.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,260 +0,0 @@
|
|||||||
// Copyright 2018 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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 main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
"k8s.io/api/admission/v1beta1"
|
|
||||||
admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
|
||||||
"k8s.io/apimachinery/pkg/types"
|
|
||||||
"k8s.io/client-go/rest"
|
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
|
||||||
"k8s.io/klog"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
controllerThreadNum = 1
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
scheme = runtime.NewScheme()
|
|
||||||
codecs = serializer.NewCodecFactory(scheme)
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
klog.InitFlags(nil)
|
|
||||||
addToScheme(scheme)
|
|
||||||
}
|
|
||||||
|
|
||||||
func addToScheme(scheme *runtime.Scheme) {
|
|
||||||
corev1.AddToScheme(scheme)
|
|
||||||
admissionregistrationv1beta1.AddToScheme(scheme)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getTLSConfig(certFile string, keyFile string) *tls.Config {
|
|
||||||
sCert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
|
||||||
if err != nil {
|
|
||||||
klog.Fatal(err)
|
|
||||||
}
|
|
||||||
return &tls.Config{
|
|
||||||
Certificates: []tls.Certificate{sCert},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func mutatePods(ar v1beta1.AdmissionReview, pm patcherManager) *v1beta1.AdmissionResponse {
|
|
||||||
var ops []string
|
|
||||||
|
|
||||||
klog.V(4).Info("mutating pods")
|
|
||||||
|
|
||||||
podResource := metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
|
|
||||||
if ar.Request.Resource != podResource {
|
|
||||||
klog.Warningf("Unexpected resource type %s", ar.Request.Resource)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
raw := ar.Request.Object.Raw
|
|
||||||
pod := corev1.Pod{}
|
|
||||||
deserializer := codecs.UniversalDeserializer()
|
|
||||||
if _, _, err := deserializer.Decode(raw, nil, &pod); err != nil {
|
|
||||||
klog.Warningf("%+v", err)
|
|
||||||
return toAdmissionResponse(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace := pod.Namespace
|
|
||||||
if namespace == "" && ar.Request.Namespace != "" {
|
|
||||||
namespace = ar.Request.Namespace
|
|
||||||
}
|
|
||||||
name := pod.Name
|
|
||||||
if name == "" && pod.ObjectMeta.GenerateName != "" {
|
|
||||||
name = pod.ObjectMeta.GenerateName
|
|
||||||
}
|
|
||||||
klog.V(4).Infof("Received pod '%s' in name space '%s'", name, namespace)
|
|
||||||
patcher := pm.getPatcher(namespace)
|
|
||||||
|
|
||||||
reviewResponse := v1beta1.AdmissionResponse{}
|
|
||||||
reviewResponse.Allowed = true
|
|
||||||
|
|
||||||
for containerIdx, container := range pod.Spec.Containers {
|
|
||||||
patchOps, err := patcher.getPatchOps(containerIdx, container)
|
|
||||||
if err != nil {
|
|
||||||
return toAdmissionResponse(err)
|
|
||||||
}
|
|
||||||
ops = append(ops, patchOps...)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ops) > 0 {
|
|
||||||
reviewResponse.Patch = []byte("[ " + strings.Join(ops, ",") + " ]")
|
|
||||||
pt := v1beta1.PatchTypeJSONPatch
|
|
||||||
reviewResponse.PatchType = &pt
|
|
||||||
}
|
|
||||||
|
|
||||||
return &reviewResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
type admitFunc func(v1beta1.AdmissionReview) *v1beta1.AdmissionResponse
|
|
||||||
|
|
||||||
func toAdmissionResponse(err error) *v1beta1.AdmissionResponse {
|
|
||||||
return &v1beta1.AdmissionResponse{
|
|
||||||
Result: &metav1.Status{
|
|
||||||
Message: err.Error(),
|
|
||||||
},
|
|
||||||
Allowed: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func serve(w http.ResponseWriter, r *http.Request, admit admitFunc) {
|
|
||||||
var body []byte
|
|
||||||
var reviewResponse *v1beta1.AdmissionResponse
|
|
||||||
var reqUID types.UID
|
|
||||||
|
|
||||||
if r.Body != nil {
|
|
||||||
if data, err := ioutil.ReadAll(r.Body); err == nil {
|
|
||||||
body = data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(body) == 0 {
|
|
||||||
klog.V(4).Info("No body in request")
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify the content type is accurate
|
|
||||||
contentType := r.Header.Get("Content-Type")
|
|
||||||
if contentType != "application/json" {
|
|
||||||
klog.V(4).Infof("contentType=%s, expect application/json", contentType)
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
klog.V(4).Infof("handling request: %s", string(body))
|
|
||||||
ar := v1beta1.AdmissionReview{}
|
|
||||||
deserializer := codecs.UniversalDeserializer()
|
|
||||||
if _, _, err := deserializer.Decode(body, nil, &ar); err != nil {
|
|
||||||
klog.Warningf("%+v", err)
|
|
||||||
reviewResponse = toAdmissionResponse(err)
|
|
||||||
} else {
|
|
||||||
if ar.Request == nil {
|
|
||||||
err = errors.New("Request is empty")
|
|
||||||
reviewResponse = toAdmissionResponse(err)
|
|
||||||
} else {
|
|
||||||
reqUID = ar.Request.UID
|
|
||||||
reviewResponse = admit(ar)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
klog.V(4).Info("sending response", string(reviewResponse.Patch))
|
|
||||||
|
|
||||||
response := v1beta1.AdmissionReview{}
|
|
||||||
if reviewResponse != nil {
|
|
||||||
response.Response = reviewResponse
|
|
||||||
response.Response.UID = reqUID
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset the Object and OldObject, they are not needed in a response.
|
|
||||||
if ar.Request != nil {
|
|
||||||
ar.Request.Object = runtime.RawExtension{}
|
|
||||||
ar.Request.OldObject = runtime.RawExtension{}
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := json.Marshal(response)
|
|
||||||
if err != nil {
|
|
||||||
klog.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _, err := w.Write(resp); err != nil {
|
|
||||||
klog.Warningf("%+v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func makePodsHandler(pm patcherManager) func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
serve(w, r, func(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
|
|
||||||
return mutatePods(ar, pm)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
var kubeconfig string
|
|
||||||
var master string
|
|
||||||
var certFile string
|
|
||||||
var keyFile string
|
|
||||||
var config *rest.Config
|
|
||||||
var err error
|
|
||||||
|
|
||||||
flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
|
|
||||||
flag.StringVar(&master, "master", "", "master url")
|
|
||||||
flag.StringVar(&certFile, "tls-cert-file", certFile,
|
|
||||||
"File containing the x509 Certificate for HTTPS. (CA cert, if any, concatenated after server cert).")
|
|
||||||
flag.StringVar(&keyFile, "tls-private-key-file", keyFile, "File containing the x509 private key matching --tls-cert-file.")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if certFile == "" {
|
|
||||||
klog.Fatal("TLS certificate file is not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
if keyFile == "" {
|
|
||||||
klog.Fatal("TLS private key is not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err = os.Stat(certFile); err != nil {
|
|
||||||
klog.Fatal("TLS certificate not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err = os.Stat(keyFile); err != nil {
|
|
||||||
klog.Fatal("TLS private key not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
if kubeconfig == "" {
|
|
||||||
config, err = rest.InClusterConfig()
|
|
||||||
} else {
|
|
||||||
config, err = clientcmd.BuildConfigFromFlags(master, kubeconfig)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
klog.Fatal("Failed to get cluster config ", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pm := newPatcherManager()
|
|
||||||
|
|
||||||
controller, err := newController(pm, config)
|
|
||||||
if err != nil {
|
|
||||||
klog.Fatalf("%+v", err)
|
|
||||||
}
|
|
||||||
go controller.run(controllerThreadNum)
|
|
||||||
|
|
||||||
http.HandleFunc("/pods", makePodsHandler(pm))
|
|
||||||
|
|
||||||
klog.V(4).Info("Webhook started")
|
|
||||||
|
|
||||||
server := &http.Server{
|
|
||||||
Addr: ":8443",
|
|
||||||
TLSConfig: getTLSConfig(certFile, keyFile),
|
|
||||||
}
|
|
||||||
|
|
||||||
klog.Fatal(server.ListenAndServeTLS("", ""))
|
|
||||||
}
|
|
@ -1,299 +0,0 @@
|
|||||||
// Copyright 2018 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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 main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
"k8s.io/api/admission/v1beta1"
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
flag.Set("v", "4")
|
|
||||||
}
|
|
||||||
|
|
||||||
func fakeMutatePods(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
|
|
||||||
reviewResponse := v1beta1.AdmissionResponse{}
|
|
||||||
return &reviewResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestServe(t *testing.T) {
|
|
||||||
ar1, err := json.Marshal(&v1beta1.AdmissionReview{})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
ar2, err := json.Marshal(&v1beta1.AdmissionReview{
|
|
||||||
Request: &v1beta1.AdmissionRequest{},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tcases := []struct {
|
|
||||||
header http.Header
|
|
||||||
body io.Reader
|
|
||||||
expectedStatus int
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
expectedStatus: http.StatusBadRequest,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
body: strings.NewReader("hello world"),
|
|
||||||
expectedStatus: http.StatusBadRequest,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: http.Header{
|
|
||||||
"Content-Type": []string{"application/json"},
|
|
||||||
},
|
|
||||||
expectedStatus: http.StatusBadRequest,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
body: strings.NewReader("hello world"),
|
|
||||||
header: http.Header{
|
|
||||||
"Content-Type": []string{"application/json"},
|
|
||||||
},
|
|
||||||
expectedStatus: http.StatusOK,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
body: bytes.NewReader(ar1),
|
|
||||||
header: http.Header{
|
|
||||||
"Content-Type": []string{"application/json"},
|
|
||||||
},
|
|
||||||
expectedStatus: http.StatusOK,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
body: bytes.NewReader(ar2),
|
|
||||||
header: http.Header{
|
|
||||||
"Content-Type": []string{"application/json"},
|
|
||||||
},
|
|
||||||
expectedStatus: http.StatusOK,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tcase := range tcases {
|
|
||||||
req, err := http.NewRequest("POST", "/pods", tcase.body)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
req.Header = tcase.header
|
|
||||||
|
|
||||||
rr := httptest.NewRecorder()
|
|
||||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { serve(w, r, fakeMutatePods) })
|
|
||||||
|
|
||||||
handler.ServeHTTP(rr, req)
|
|
||||||
|
|
||||||
if status := rr.Code; status != tcase.expectedStatus {
|
|
||||||
t.Errorf("handler returned wrong status code: got %v want %v",
|
|
||||||
status, tcase.expectedStatus)
|
|
||||||
}
|
|
||||||
|
|
||||||
if tcase.expectedStatus == http.StatusOK {
|
|
||||||
var ar v1beta1.AdmissionReview
|
|
||||||
err = json.Unmarshal(rr.Body.Bytes(), &ar)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMutatePods(t *testing.T) {
|
|
||||||
pod := corev1.Pod{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Namespace: "default",
|
|
||||||
},
|
|
||||||
Spec: corev1.PodSpec{
|
|
||||||
Containers: []corev1.Container{
|
|
||||||
{
|
|
||||||
Name: "test-container",
|
|
||||||
Image: "test-image",
|
|
||||||
Resources: corev1.ResourceRequirements{
|
|
||||||
Limits: corev1.ResourceList{
|
|
||||||
"cpu": resource.MustParse("1"),
|
|
||||||
"fpga.intel.com/arria10": resource.MustParse("1"),
|
|
||||||
},
|
|
||||||
Requests: corev1.ResourceList{
|
|
||||||
"cpu": resource.MustParse("1"),
|
|
||||||
"fpga.intel.com/arria10": resource.MustParse("1"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
brokenPod := corev1.Pod{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Namespace: "default",
|
|
||||||
},
|
|
||||||
Spec: corev1.PodSpec{
|
|
||||||
Containers: []corev1.Container{
|
|
||||||
{
|
|
||||||
Name: "test-container",
|
|
||||||
Image: "test-image",
|
|
||||||
Resources: corev1.ResourceRequirements{
|
|
||||||
Limits: corev1.ResourceList{
|
|
||||||
"cpu": resource.MustParse("1"),
|
|
||||||
"fpga.intel.com/arria10": resource.MustParse("1"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
podRaw, err := json.Marshal(pod)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
brokenPodRaw, err := json.Marshal(brokenPod)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tcases := []struct {
|
|
||||||
name string
|
|
||||||
ar v1beta1.AdmissionReview
|
|
||||||
expectedResponse bool
|
|
||||||
expectedAllowed bool
|
|
||||||
expectedPatchOps int
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "empty admission request",
|
|
||||||
ar: v1beta1.AdmissionReview{
|
|
||||||
Request: &v1beta1.AdmissionRequest{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "admission request without object",
|
|
||||||
ar: v1beta1.AdmissionReview{
|
|
||||||
Request: &v1beta1.AdmissionRequest{
|
|
||||||
Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expectedResponse: true,
|
|
||||||
expectedAllowed: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "admission request with corrupted object",
|
|
||||||
ar: v1beta1.AdmissionReview{
|
|
||||||
Request: &v1beta1.AdmissionRequest{
|
|
||||||
Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
|
|
||||||
Object: runtime.RawExtension{
|
|
||||||
Raw: []byte(`{"corrupted json":}`),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expectedResponse: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "successful non-empty admission request",
|
|
||||||
ar: v1beta1.AdmissionReview{
|
|
||||||
Request: &v1beta1.AdmissionRequest{
|
|
||||||
Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
|
|
||||||
Object: runtime.RawExtension{
|
|
||||||
Raw: podRaw,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expectedResponse: true,
|
|
||||||
expectedPatchOps: 4,
|
|
||||||
expectedAllowed: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "handle error after wrong getPatchOps()",
|
|
||||||
ar: v1beta1.AdmissionReview{
|
|
||||||
Request: &v1beta1.AdmissionRequest{
|
|
||||||
Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
|
|
||||||
Object: runtime.RawExtension{
|
|
||||||
Raw: brokenPodRaw,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expectedResponse: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tcase := range tcases {
|
|
||||||
t.Run(tcase.name, func(t *testing.T) {
|
|
||||||
p := newPatcher()
|
|
||||||
p.addRegion(&fpgav2.FpgaRegion{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "arria10",
|
|
||||||
},
|
|
||||||
Spec: fpgav2.FpgaRegionSpec{
|
|
||||||
InterfaceID: "ce48969398f05f33946d560708be108a",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
pm := newPatcherManager()
|
|
||||||
pm["default"] = p
|
|
||||||
resp := mutatePods(tcase.ar, pm)
|
|
||||||
|
|
||||||
actualPatchOps := 0
|
|
||||||
if !tcase.expectedResponse && resp != nil {
|
|
||||||
t.Errorf("Test case '%s': got unexpected response", tcase.name)
|
|
||||||
} else if tcase.expectedResponse && resp == nil {
|
|
||||||
t.Errorf("Test case '%s': got no response", tcase.name)
|
|
||||||
} else if tcase.expectedResponse {
|
|
||||||
if tcase.expectedAllowed != resp.Allowed {
|
|
||||||
t.Errorf("Allowed expected to be %t but got %t", tcase.expectedAllowed, resp.Allowed)
|
|
||||||
} else if resp.Allowed && resp.Patch != nil {
|
|
||||||
var ops interface{}
|
|
||||||
|
|
||||||
err := json.Unmarshal(resp.Patch, &ops)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Test case '%s': got unparsable patch '%s'", tcase.name, resp.Patch)
|
|
||||||
} else {
|
|
||||||
actualPatchOps = len(ops.([]interface{}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if actualPatchOps != tcase.expectedPatchOps {
|
|
||||||
t.Errorf("Test case '%s': got wrong number of operations in the patch. Expected %d, but got %d\n%s",
|
|
||||||
tcase.name, tcase.expectedPatchOps, actualPatchOps, string(resp.Patch))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type fakeResponseWriter struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*fakeResponseWriter) Header() http.Header {
|
|
||||||
return http.Header{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*fakeResponseWriter) Write([]byte) (int, error) {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*fakeResponseWriter) WriteHeader(int) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMakePodsHandler(t *testing.T) {
|
|
||||||
serveFunc := makePodsHandler(newPatcherManager())
|
|
||||||
serveFunc(&fakeResponseWriter{}, &http.Request{})
|
|
||||||
}
|
|
99
cmd/fpga_admissionwebhook/main.go
Normal file
99
cmd/fpga_admissionwebhook/main.go
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// 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 main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
||||||
|
"k8s.io/klog"
|
||||||
|
"k8s.io/klog/klogr"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
||||||
|
|
||||||
|
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
||||||
|
controllers "github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpgacontroller"
|
||||||
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpgacontroller/patcher"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
scheme = runtime.NewScheme()
|
||||||
|
setupLog = ctrl.Log.WithName("setup")
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
klog.InitFlags(nil)
|
||||||
|
|
||||||
|
_ = fpgav2.AddToScheme(scheme)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var metricsAddr string
|
||||||
|
var enableLeaderElection bool
|
||||||
|
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
|
||||||
|
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
|
||||||
|
"Enable leader election for controller manager. "+
|
||||||
|
"Enabling this will ensure there is only one active controller manager.")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
ctrl.SetLogger(klogr.New())
|
||||||
|
|
||||||
|
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
|
||||||
|
Scheme: scheme,
|
||||||
|
MetricsBindAddress: metricsAddr,
|
||||||
|
Port: 8443,
|
||||||
|
LeaderElection: enableLeaderElection,
|
||||||
|
LeaderElectionID: "f2c6a4df.intel.com",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
setupLog.Error(err, "unable to start manager")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
pm := patcher.NewPatcherManager(ctrl.Log.WithName("webhooks").WithName("Fpga"))
|
||||||
|
|
||||||
|
mgr.GetWebhookServer().Register("/pods", &webhook.Admission{
|
||||||
|
Handler: admission.HandlerFunc(pm.GetPodMutator()),
|
||||||
|
})
|
||||||
|
|
||||||
|
if err = (&controllers.AcceleratorFunctionReconciler{
|
||||||
|
Client: mgr.GetClient(),
|
||||||
|
Log: ctrl.Log.WithName("controllers").WithName("AcceleratorFunction"),
|
||||||
|
Scheme: mgr.GetScheme(),
|
||||||
|
PatcherManager: pm,
|
||||||
|
}).SetupWithManager(mgr); err != nil {
|
||||||
|
setupLog.Error(err, "unable to create controller", "controller", "AcceleratorFunction")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = (&controllers.FpgaRegionReconciler{
|
||||||
|
Client: mgr.GetClient(),
|
||||||
|
Log: ctrl.Log.WithName("controllers").WithName("FpgaRegion"),
|
||||||
|
Scheme: mgr.GetScheme(),
|
||||||
|
PatcherManager: pm,
|
||||||
|
}).SetupWithManager(mgr); err != nil {
|
||||||
|
setupLog.Error(err, "unable to create controller", "controller", "FpgaRegion")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
setupLog.Info("starting manager")
|
||||||
|
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
|
||||||
|
setupLog.Error(err, "problem running manager")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
@ -9,8 +9,6 @@ spec:
|
|||||||
containers:
|
containers:
|
||||||
- name: manager
|
- name: manager
|
||||||
args:
|
args:
|
||||||
- -tls-cert-file=/tmp/k8s-webhook-server/serving-certs/tls.crt
|
|
||||||
- -tls-private-key-file=/tmp/k8s-webhook-server/serving-certs/tls.key
|
|
||||||
- -v=1
|
- -v=1
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8443
|
- containerPort: 8443
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: apiextensions.k8s.io/v1beta1
|
||||||
|
kind: CustomResourceDefinition
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
controller-gen.kubebuilder.io/version: v0.3.0
|
||||||
|
creationTimestamp: null
|
||||||
|
name: acceleratorfunctions.fpga.intel.com
|
||||||
|
spec:
|
||||||
|
group: fpga.intel.com
|
||||||
|
names:
|
||||||
|
kind: AcceleratorFunction
|
||||||
|
listKind: AcceleratorFunctionList
|
||||||
|
plural: acceleratorfunctions
|
||||||
|
shortNames:
|
||||||
|
- af
|
||||||
|
singular: acceleratorfunction
|
||||||
|
scope: Namespaced
|
||||||
|
validation:
|
||||||
|
openAPIV3Schema:
|
||||||
|
description: AcceleratorFunction is a specification for an AcceleratorFunction
|
||||||
|
resource.
|
||||||
|
properties:
|
||||||
|
apiVersion:
|
||||||
|
description: 'APIVersion defines the versioned schema of this representation
|
||||||
|
of an object. Servers should convert recognized schemas to the latest
|
||||||
|
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
|
||||||
|
type: string
|
||||||
|
kind:
|
||||||
|
description: 'Kind is a string value representing the REST resource this
|
||||||
|
object represents. Servers may infer this from the endpoint the client
|
||||||
|
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
|
||||||
|
type: string
|
||||||
|
metadata:
|
||||||
|
type: object
|
||||||
|
spec:
|
||||||
|
description: AcceleratorFunctionSpec contains actual specs for AcceleratorFunction.
|
||||||
|
properties:
|
||||||
|
afuId:
|
||||||
|
pattern: ^[0-9a-f]{8,40}$
|
||||||
|
type: string
|
||||||
|
interfaceId:
|
||||||
|
pattern: ^[0-9a-f]{8,32}$
|
||||||
|
type: string
|
||||||
|
mode:
|
||||||
|
pattern: ^af|region$
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- afuId
|
||||||
|
- interfaceId
|
||||||
|
- mode
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- spec
|
||||||
|
type: object
|
||||||
|
version: v2
|
||||||
|
versions:
|
||||||
|
- name: v2
|
||||||
|
served: true
|
||||||
|
storage: true
|
||||||
|
status:
|
||||||
|
acceptedNames:
|
||||||
|
kind: ""
|
||||||
|
plural: ""
|
||||||
|
conditions: []
|
||||||
|
storedVersions: []
|
@ -1,32 +0,0 @@
|
|||||||
apiVersion: apiextensions.k8s.io/v1beta1
|
|
||||||
kind: CustomResourceDefinition
|
|
||||||
metadata:
|
|
||||||
name: acceleratorfunctions.fpga.intel.com
|
|
||||||
spec:
|
|
||||||
group: fpga.intel.com
|
|
||||||
version: v2
|
|
||||||
versions:
|
|
||||||
- name: v2
|
|
||||||
served: true
|
|
||||||
storage: true
|
|
||||||
names:
|
|
||||||
plural: acceleratorfunctions
|
|
||||||
singular: acceleratorfunction
|
|
||||||
kind: AcceleratorFunction
|
|
||||||
shortNames:
|
|
||||||
- af
|
|
||||||
scope: Namespaced
|
|
||||||
validation:
|
|
||||||
openAPIV3Schema:
|
|
||||||
properties:
|
|
||||||
spec:
|
|
||||||
properties:
|
|
||||||
afuId:
|
|
||||||
type: string
|
|
||||||
pattern: '^[0-9a-f]{8,40}$'
|
|
||||||
interfaceId:
|
|
||||||
type: string
|
|
||||||
pattern: '^[0-9a-f]{8,32}$'
|
|
||||||
mode:
|
|
||||||
type: string
|
|
||||||
pattern: '^af|region$'
|
|
@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: apiextensions.k8s.io/v1beta1
|
||||||
|
kind: CustomResourceDefinition
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
controller-gen.kubebuilder.io/version: v0.3.0
|
||||||
|
creationTimestamp: null
|
||||||
|
name: fpgaregions.fpga.intel.com
|
||||||
|
spec:
|
||||||
|
group: fpga.intel.com
|
||||||
|
names:
|
||||||
|
kind: FpgaRegion
|
||||||
|
listKind: FpgaRegionList
|
||||||
|
plural: fpgaregions
|
||||||
|
shortNames:
|
||||||
|
- fpga
|
||||||
|
singular: fpgaregion
|
||||||
|
scope: Namespaced
|
||||||
|
validation:
|
||||||
|
openAPIV3Schema:
|
||||||
|
description: FpgaRegion is a specification for a FpgaRegion resource.
|
||||||
|
properties:
|
||||||
|
apiVersion:
|
||||||
|
description: 'APIVersion defines the versioned schema of this representation
|
||||||
|
of an object. Servers should convert recognized schemas to the latest
|
||||||
|
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
|
||||||
|
type: string
|
||||||
|
kind:
|
||||||
|
description: 'Kind is a string value representing the REST resource this
|
||||||
|
object represents. Servers may infer this from the endpoint the client
|
||||||
|
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
|
||||||
|
type: string
|
||||||
|
metadata:
|
||||||
|
type: object
|
||||||
|
spec:
|
||||||
|
description: FpgaRegionSpec contains actual specs for FpgaRegion.
|
||||||
|
properties:
|
||||||
|
interfaceId:
|
||||||
|
pattern: ^[0-9a-f]{8,32}$
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- interfaceId
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- spec
|
||||||
|
type: object
|
||||||
|
version: v2
|
||||||
|
versions:
|
||||||
|
- name: v2
|
||||||
|
served: true
|
||||||
|
storage: true
|
||||||
|
status:
|
||||||
|
acceptedNames:
|
||||||
|
kind: ""
|
||||||
|
plural: ""
|
||||||
|
conditions: []
|
||||||
|
storedVersions: []
|
@ -1,26 +0,0 @@
|
|||||||
apiVersion: apiextensions.k8s.io/v1beta1
|
|
||||||
kind: CustomResourceDefinition
|
|
||||||
metadata:
|
|
||||||
name: fpgaregions.fpga.intel.com
|
|
||||||
spec:
|
|
||||||
group: fpga.intel.com
|
|
||||||
version: v2
|
|
||||||
versions:
|
|
||||||
- name: v2
|
|
||||||
served: true
|
|
||||||
storage: true
|
|
||||||
names:
|
|
||||||
plural: fpgaregions
|
|
||||||
singular: fpgaregion
|
|
||||||
kind: FpgaRegion
|
|
||||||
shortNames:
|
|
||||||
- fpga
|
|
||||||
scope: Namespaced
|
|
||||||
validation:
|
|
||||||
openAPIV3Schema:
|
|
||||||
properties:
|
|
||||||
spec:
|
|
||||||
properties:
|
|
||||||
interfaceId:
|
|
||||||
type: string
|
|
||||||
pattern: '^[0-9a-f]{8,32}$'
|
|
@ -2,5 +2,5 @@
|
|||||||
# since it depends on service name and namespace that are out of this kustomize package.
|
# since it depends on service name and namespace that are out of this kustomize package.
|
||||||
# It should be run by deployment/fpga_admissionwebhook/default
|
# It should be run by deployment/fpga_admissionwebhook/default
|
||||||
resources:
|
resources:
|
||||||
- bases/fpga.intel.com_af.yaml
|
- bases/fpga.intel.com_acceleratorfunctions.yaml
|
||||||
- bases/fpga.intel.com_region.yaml
|
- bases/fpga.intel.com_fpgaregions.yaml
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
|
||||||
|
---
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
metadata:
|
metadata:
|
||||||
@ -5,7 +7,7 @@ metadata:
|
|||||||
name: manager-role
|
name: manager-role
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- "fpga.intel.com"
|
- fpga.intel.com
|
||||||
resources:
|
resources:
|
||||||
- acceleratorfunctions
|
- acceleratorfunctions
|
||||||
- fpgaregions
|
- fpgaregions
|
||||||
|
@ -12,6 +12,7 @@ webhooks:
|
|||||||
name: webhook-service
|
name: webhook-service
|
||||||
namespace: system
|
namespace: system
|
||||||
path: /pods
|
path: /pods
|
||||||
|
failurePolicy: Ignore
|
||||||
name: fpga.mutator.webhooks.intel.com
|
name: fpga.mutator.webhooks.intel.com
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
|
1
go.sum
1
go.sum
@ -1,6 +1,7 @@
|
|||||||
bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690/go.mod h1:Ulb78X89vxKYgdL24HMTiXYHlyHEvruOj1ZPlqeNEZM=
|
bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690/go.mod h1:Ulb78X89vxKYgdL24HMTiXYHlyHEvruOj1ZPlqeNEZM=
|
||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo=
|
||||||
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||||
github.com/Azure/azure-sdk-for-go v35.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
|
github.com/Azure/azure-sdk-for-go v35.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
|
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
package fpgaintel
|
|
||||||
|
|
||||||
// API parameters.
|
|
||||||
const (
|
|
||||||
GroupName = "fpga.intel.com"
|
|
||||||
)
|
|
56
pkg/apis/fpga.intel.com/v2/acceleratorfunction_types.go
Normal file
56
pkg/apis/fpga.intel.com/v2/acceleratorfunction_types.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// 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 v2
|
||||||
|
|
||||||
|
import (
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AcceleratorFunctionSpec contains actual specs for AcceleratorFunction.
|
||||||
|
type AcceleratorFunctionSpec struct {
|
||||||
|
// +kubebuilder:validation:Pattern=`^[0-9a-f]{8,40}$`
|
||||||
|
AfuID string `json:"afuId"`
|
||||||
|
|
||||||
|
// +kubebuilder:validation:Pattern=`^[0-9a-f]{8,32}$`
|
||||||
|
InterfaceID string `json:"interfaceId"`
|
||||||
|
|
||||||
|
// +kubebuilder:validation:Pattern=`^af|region$`
|
||||||
|
Mode string `json:"mode"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:object:root=true
|
||||||
|
// +kubebuilder:resource:shortName=af
|
||||||
|
|
||||||
|
// AcceleratorFunction is a specification for an AcceleratorFunction resource.
|
||||||
|
type AcceleratorFunction struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||||
|
|
||||||
|
Spec AcceleratorFunctionSpec `json:"spec"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:object:root=true
|
||||||
|
|
||||||
|
// AcceleratorFunctionList is a list of AcceleratorFunction resources.
|
||||||
|
type AcceleratorFunctionList struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ListMeta `json:"metadata,omitempty"`
|
||||||
|
|
||||||
|
Items []AcceleratorFunction `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
SchemeBuilder.Register(&AcceleratorFunction{}, &AcceleratorFunctionList{})
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
// +k8s:deepcopy-gen=package,register
|
|
||||||
|
|
||||||
// +groupName=fpga.intel.com
|
|
||||||
|
|
||||||
package v2
|
|
50
pkg/apis/fpga.intel.com/v2/fpgaregion_types.go
Normal file
50
pkg/apis/fpga.intel.com/v2/fpgaregion_types.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// 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 v2
|
||||||
|
|
||||||
|
import (
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FpgaRegionSpec contains actual specs for FpgaRegion.
|
||||||
|
type FpgaRegionSpec struct {
|
||||||
|
// +kubebuilder:validation:Pattern=`^[0-9a-f]{8,32}$`
|
||||||
|
InterfaceID string `json:"interfaceId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:object:root=true
|
||||||
|
// +kubebuilder:resource:shortName=fpga
|
||||||
|
|
||||||
|
// FpgaRegion is a specification for a FpgaRegion resource.
|
||||||
|
type FpgaRegion struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||||
|
|
||||||
|
Spec FpgaRegionSpec `json:"spec"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:object:root=true
|
||||||
|
|
||||||
|
// FpgaRegionList is a list of FpgaRegion resources.
|
||||||
|
type FpgaRegionList struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ListMeta `json:"metadata,omitempty"`
|
||||||
|
|
||||||
|
Items []FpgaRegion `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
SchemeBuilder.Register(&FpgaRegion{}, &FpgaRegionList{})
|
||||||
|
}
|
34
pkg/apis/fpga.intel.com/v2/groupversion_info.go
Normal file
34
pkg/apis/fpga.intel.com/v2/groupversion_info.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// 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 v2 contains API Schema definitions for the fpga.intel.com v2 API group
|
||||||
|
// +kubebuilder:object:generate=true
|
||||||
|
// +groupName=fpga.intel.com
|
||||||
|
package v2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/scheme"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// GroupVersion is group version used to register these objects
|
||||||
|
GroupVersion = schema.GroupVersion{Group: "fpga.intel.com", Version: "v2"}
|
||||||
|
|
||||||
|
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
|
||||||
|
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
|
||||||
|
|
||||||
|
// AddToScheme adds the types in this group-version to the given scheme.
|
||||||
|
AddToScheme = SchemeBuilder.AddToScheme
|
||||||
|
)
|
@ -1,41 +0,0 @@
|
|||||||
package v2
|
|
||||||
|
|
||||||
import (
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
|
|
||||||
fpgaintel "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SchemeGroupVersion is group version used to register these objects.
|
|
||||||
var SchemeGroupVersion = schema.GroupVersion{Group: fpgaintel.GroupName, Version: "v2"}
|
|
||||||
|
|
||||||
// Kind takes an unqualified kind and returns back a Group qualified GroupKind.
|
|
||||||
func Kind(kind string) schema.GroupKind {
|
|
||||||
return SchemeGroupVersion.WithKind(kind).GroupKind()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resource takes an unqualified resource and returns a Group qualified GroupResource.
|
|
||||||
func Resource(resource string) schema.GroupResource {
|
|
||||||
return SchemeGroupVersion.WithResource(resource).GroupResource()
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
// SchemeBuilder builds scheme.
|
|
||||||
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
|
|
||||||
// AddToScheme adds known types to scheme.
|
|
||||||
AddToScheme = SchemeBuilder.AddToScheme
|
|
||||||
)
|
|
||||||
|
|
||||||
// Adds the list of known types to Scheme.
|
|
||||||
func addKnownTypes(scheme *runtime.Scheme) error {
|
|
||||||
scheme.AddKnownTypes(SchemeGroupVersion,
|
|
||||||
&AcceleratorFunction{},
|
|
||||||
&AcceleratorFunctionList{},
|
|
||||||
&FpgaRegion{},
|
|
||||||
&FpgaRegionList{},
|
|
||||||
)
|
|
||||||
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
package v2
|
|
||||||
|
|
||||||
import (
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
// +genclient
|
|
||||||
// +genclient:noStatus
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
|
||||||
|
|
||||||
// AcceleratorFunction is a specification for an AcceleratorFunction resource.
|
|
||||||
type AcceleratorFunction struct {
|
|
||||||
metav1.TypeMeta `json:"inline"`
|
|
||||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
|
||||||
|
|
||||||
Spec AcceleratorFunctionSpec `json:"spec"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// AcceleratorFunctionSpec contains actual specs for AcceleratorFunction.
|
|
||||||
type AcceleratorFunctionSpec struct {
|
|
||||||
AfuID string `json:"afuId"`
|
|
||||||
InterfaceID string `json:"interfaceId"`
|
|
||||||
Mode string `json:"mode"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
|
||||||
|
|
||||||
// AcceleratorFunctionList is a list of AcceleratorFunction resources.
|
|
||||||
type AcceleratorFunctionList struct {
|
|
||||||
metav1.TypeMeta `json:",inline"`
|
|
||||||
metav1.ListMeta `json:"metadata"`
|
|
||||||
|
|
||||||
Items []AcceleratorFunction `json:"items"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// +genclient
|
|
||||||
// +genclient:noStatus
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
|
||||||
|
|
||||||
// FpgaRegion is a specification for a FpgaRegion resource.
|
|
||||||
type FpgaRegion struct {
|
|
||||||
metav1.TypeMeta `json:"inline"`
|
|
||||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
|
||||||
|
|
||||||
Spec FpgaRegionSpec `json:"spec"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// FpgaRegionSpec contains actual specs for FpgaRegion.
|
|
||||||
type FpgaRegionSpec struct {
|
|
||||||
InterfaceID string `json:"interfaceId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
|
||||||
|
|
||||||
// FpgaRegionList is a list of FpgaRegion resources.
|
|
||||||
type FpgaRegionList struct {
|
|
||||||
metav1.TypeMeta `json:",inline"`
|
|
||||||
metav1.ListMeta `json:"metadata"`
|
|
||||||
|
|
||||||
Items []FpgaRegion `json:"items"`
|
|
||||||
}
|
|
@ -14,7 +14,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// Code generated by deepcopy-gen. DO NOT EDIT.
|
// Code generated by controller-gen. DO NOT EDIT.
|
||||||
|
|
||||||
package v2
|
package v2
|
||||||
|
|
||||||
@ -28,7 +28,6 @@ func (in *AcceleratorFunction) DeepCopyInto(out *AcceleratorFunction) {
|
|||||||
out.TypeMeta = in.TypeMeta
|
out.TypeMeta = in.TypeMeta
|
||||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||||
out.Spec = in.Spec
|
out.Spec = in.Spec
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AcceleratorFunction.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AcceleratorFunction.
|
||||||
@ -61,7 +60,6 @@ func (in *AcceleratorFunctionList) DeepCopyInto(out *AcceleratorFunctionList) {
|
|||||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AcceleratorFunctionList.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AcceleratorFunctionList.
|
||||||
@ -85,7 +83,6 @@ func (in *AcceleratorFunctionList) DeepCopyObject() runtime.Object {
|
|||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *AcceleratorFunctionSpec) DeepCopyInto(out *AcceleratorFunctionSpec) {
|
func (in *AcceleratorFunctionSpec) DeepCopyInto(out *AcceleratorFunctionSpec) {
|
||||||
*out = *in
|
*out = *in
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AcceleratorFunctionSpec.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AcceleratorFunctionSpec.
|
||||||
@ -104,7 +101,6 @@ func (in *FpgaRegion) DeepCopyInto(out *FpgaRegion) {
|
|||||||
out.TypeMeta = in.TypeMeta
|
out.TypeMeta = in.TypeMeta
|
||||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||||
out.Spec = in.Spec
|
out.Spec = in.Spec
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FpgaRegion.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FpgaRegion.
|
||||||
@ -137,7 +133,6 @@ func (in *FpgaRegionList) DeepCopyInto(out *FpgaRegionList) {
|
|||||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FpgaRegionList.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FpgaRegionList.
|
||||||
@ -161,7 +156,6 @@ func (in *FpgaRegionList) DeepCopyObject() runtime.Object {
|
|||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *FpgaRegionSpec) DeepCopyInto(out *FpgaRegionSpec) {
|
func (in *FpgaRegionSpec) DeepCopyInto(out *FpgaRegionSpec) {
|
||||||
*out = *in
|
*out = *in
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FpgaRegionSpec.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FpgaRegionSpec.
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package versioned
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned/typed/fpga.intel.com/v2"
|
|
||||||
discovery "k8s.io/client-go/discovery"
|
|
||||||
rest "k8s.io/client-go/rest"
|
|
||||||
flowcontrol "k8s.io/client-go/util/flowcontrol"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Interface interface {
|
|
||||||
Discovery() discovery.DiscoveryInterface
|
|
||||||
FpgaV2() fpgav2.FpgaV2Interface
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clientset contains the clients for groups. Each group has exactly one
|
|
||||||
// version included in a Clientset.
|
|
||||||
type Clientset struct {
|
|
||||||
*discovery.DiscoveryClient
|
|
||||||
fpgaV2 *fpgav2.FpgaV2Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// FpgaV2 retrieves the FpgaV2Client
|
|
||||||
func (c *Clientset) FpgaV2() fpgav2.FpgaV2Interface {
|
|
||||||
return c.fpgaV2
|
|
||||||
}
|
|
||||||
|
|
||||||
// Discovery retrieves the DiscoveryClient
|
|
||||||
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
|
|
||||||
if c == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return c.DiscoveryClient
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewForConfig creates a new Clientset for the given config.
|
|
||||||
// If config's RateLimiter is not set and QPS and Burst are acceptable,
|
|
||||||
// NewForConfig will generate a rate-limiter in configShallowCopy.
|
|
||||||
func NewForConfig(c *rest.Config) (*Clientset, error) {
|
|
||||||
configShallowCopy := *c
|
|
||||||
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
|
|
||||||
if configShallowCopy.Burst <= 0 {
|
|
||||||
return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0")
|
|
||||||
}
|
|
||||||
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
|
|
||||||
}
|
|
||||||
var cs Clientset
|
|
||||||
var err error
|
|
||||||
cs.fpgaV2, err = fpgav2.NewForConfig(&configShallowCopy)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &cs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewForConfigOrDie creates a new Clientset for the given config and
|
|
||||||
// panics if there is an error in the config.
|
|
||||||
func NewForConfigOrDie(c *rest.Config) *Clientset {
|
|
||||||
var cs Clientset
|
|
||||||
cs.fpgaV2 = fpgav2.NewForConfigOrDie(c)
|
|
||||||
|
|
||||||
cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c)
|
|
||||||
return &cs
|
|
||||||
}
|
|
||||||
|
|
||||||
// New creates a new Clientset for the given RESTClient.
|
|
||||||
func New(c rest.Interface) *Clientset {
|
|
||||||
var cs Clientset
|
|
||||||
cs.fpgaV2 = fpgav2.New(c)
|
|
||||||
|
|
||||||
cs.DiscoveryClient = discovery.NewDiscoveryClient(c)
|
|
||||||
return &cs
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
// This package has the automatically generated clientset.
|
|
||||||
package versioned
|
|
@ -1,80 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package fake
|
|
||||||
|
|
||||||
import (
|
|
||||||
clientset "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned"
|
|
||||||
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned/typed/fpga.intel.com/v2"
|
|
||||||
fakefpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
|
||||||
"k8s.io/client-go/discovery"
|
|
||||||
fakediscovery "k8s.io/client-go/discovery/fake"
|
|
||||||
"k8s.io/client-go/testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewSimpleClientset returns a clientset that will respond with the provided objects.
|
|
||||||
// It's backed by a very simple object tracker that processes creates, updates and deletions as-is,
|
|
||||||
// without applying any validations and/or defaults. It shouldn't be considered a replacement
|
|
||||||
// for a real clientset and is mostly useful in simple unit tests.
|
|
||||||
func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
|
||||||
o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
|
|
||||||
for _, obj := range objects {
|
|
||||||
if err := o.Add(obj); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cs := &Clientset{tracker: o}
|
|
||||||
cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
|
|
||||||
cs.AddReactor("*", "*", testing.ObjectReaction(o))
|
|
||||||
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
|
|
||||||
gvr := action.GetResource()
|
|
||||||
ns := action.GetNamespace()
|
|
||||||
watch, err := o.Watch(gvr, ns)
|
|
||||||
if err != nil {
|
|
||||||
return false, nil, err
|
|
||||||
}
|
|
||||||
return true, watch, nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return cs
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clientset implements clientset.Interface. Meant to be embedded into a
|
|
||||||
// struct to get a default implementation. This makes faking out just the method
|
|
||||||
// you want to test easier.
|
|
||||||
type Clientset struct {
|
|
||||||
testing.Fake
|
|
||||||
discovery *fakediscovery.FakeDiscovery
|
|
||||||
tracker testing.ObjectTracker
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
|
|
||||||
return c.discovery
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Clientset) Tracker() testing.ObjectTracker {
|
|
||||||
return c.tracker
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ clientset.Interface = &Clientset{}
|
|
||||||
|
|
||||||
// FpgaV2 retrieves the FpgaV2Client
|
|
||||||
func (c *Clientset) FpgaV2() fpgav2.FpgaV2Interface {
|
|
||||||
return &fakefpgav2.FakeFpgaV2{Fake: &c.Fake}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
// This package has the automatically generated fake clientset.
|
|
||||||
package fake
|
|
@ -1,54 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package fake
|
|
||||||
|
|
||||||
import (
|
|
||||||
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
var scheme = runtime.NewScheme()
|
|
||||||
var codecs = serializer.NewCodecFactory(scheme)
|
|
||||||
var parameterCodec = runtime.NewParameterCodec(scheme)
|
|
||||||
var localSchemeBuilder = runtime.SchemeBuilder{
|
|
||||||
fpgav2.AddToScheme,
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
|
|
||||||
// of clientsets, like in:
|
|
||||||
//
|
|
||||||
// import (
|
|
||||||
// "k8s.io/client-go/kubernetes"
|
|
||||||
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
|
|
||||||
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
|
|
||||||
// )
|
|
||||||
//
|
|
||||||
// kclientset, _ := kubernetes.NewForConfig(c)
|
|
||||||
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
|
|
||||||
//
|
|
||||||
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
|
|
||||||
// correctly.
|
|
||||||
var AddToScheme = localSchemeBuilder.AddToScheme
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"})
|
|
||||||
utilruntime.Must(AddToScheme(scheme))
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
// This package contains the scheme of the automatically generated clientset.
|
|
||||||
package scheme
|
|
@ -1,54 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package scheme
|
|
||||||
|
|
||||||
import (
|
|
||||||
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Scheme = runtime.NewScheme()
|
|
||||||
var Codecs = serializer.NewCodecFactory(Scheme)
|
|
||||||
var ParameterCodec = runtime.NewParameterCodec(Scheme)
|
|
||||||
var localSchemeBuilder = runtime.SchemeBuilder{
|
|
||||||
fpgav2.AddToScheme,
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
|
|
||||||
// of clientsets, like in:
|
|
||||||
//
|
|
||||||
// import (
|
|
||||||
// "k8s.io/client-go/kubernetes"
|
|
||||||
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
|
|
||||||
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
|
|
||||||
// )
|
|
||||||
//
|
|
||||||
// kclientset, _ := kubernetes.NewForConfig(c)
|
|
||||||
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
|
|
||||||
//
|
|
||||||
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
|
|
||||||
// correctly.
|
|
||||||
var AddToScheme = localSchemeBuilder.AddToScheme
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
|
|
||||||
utilruntime.Must(AddToScheme(Scheme))
|
|
||||||
}
|
|
@ -1,176 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
scheme "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned/scheme"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
types "k8s.io/apimachinery/pkg/types"
|
|
||||||
watch "k8s.io/apimachinery/pkg/watch"
|
|
||||||
rest "k8s.io/client-go/rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AcceleratorFunctionsGetter has a method to return a AcceleratorFunctionInterface.
|
|
||||||
// A group's client should implement this interface.
|
|
||||||
type AcceleratorFunctionsGetter interface {
|
|
||||||
AcceleratorFunctions(namespace string) AcceleratorFunctionInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
// AcceleratorFunctionInterface has methods to work with AcceleratorFunction resources.
|
|
||||||
type AcceleratorFunctionInterface interface {
|
|
||||||
Create(ctx context.Context, acceleratorFunction *v2.AcceleratorFunction, opts v1.CreateOptions) (*v2.AcceleratorFunction, error)
|
|
||||||
Update(ctx context.Context, acceleratorFunction *v2.AcceleratorFunction, opts v1.UpdateOptions) (*v2.AcceleratorFunction, error)
|
|
||||||
Delete(ctx context.Context, name string, opts v1.DeleteOptions) error
|
|
||||||
DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error
|
|
||||||
Get(ctx context.Context, name string, opts v1.GetOptions) (*v2.AcceleratorFunction, error)
|
|
||||||
List(ctx context.Context, opts v1.ListOptions) (*v2.AcceleratorFunctionList, error)
|
|
||||||
Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
|
|
||||||
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.AcceleratorFunction, err error)
|
|
||||||
AcceleratorFunctionExpansion
|
|
||||||
}
|
|
||||||
|
|
||||||
// acceleratorFunctions implements AcceleratorFunctionInterface
|
|
||||||
type acceleratorFunctions struct {
|
|
||||||
client rest.Interface
|
|
||||||
ns string
|
|
||||||
}
|
|
||||||
|
|
||||||
// newAcceleratorFunctions returns a AcceleratorFunctions
|
|
||||||
func newAcceleratorFunctions(c *FpgaV2Client, namespace string) *acceleratorFunctions {
|
|
||||||
return &acceleratorFunctions{
|
|
||||||
client: c.RESTClient(),
|
|
||||||
ns: namespace,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get takes name of the acceleratorFunction, and returns the corresponding acceleratorFunction object, and an error if there is any.
|
|
||||||
func (c *acceleratorFunctions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v2.AcceleratorFunction, err error) {
|
|
||||||
result = &v2.AcceleratorFunction{}
|
|
||||||
err = c.client.Get().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("acceleratorfunctions").
|
|
||||||
Name(name).
|
|
||||||
VersionedParams(&options, scheme.ParameterCodec).
|
|
||||||
Do(ctx).
|
|
||||||
Into(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// List takes label and field selectors, and returns the list of AcceleratorFunctions that match those selectors.
|
|
||||||
func (c *acceleratorFunctions) List(ctx context.Context, opts v1.ListOptions) (result *v2.AcceleratorFunctionList, err error) {
|
|
||||||
var timeout time.Duration
|
|
||||||
if opts.TimeoutSeconds != nil {
|
|
||||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
|
||||||
}
|
|
||||||
result = &v2.AcceleratorFunctionList{}
|
|
||||||
err = c.client.Get().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("acceleratorfunctions").
|
|
||||||
VersionedParams(&opts, scheme.ParameterCodec).
|
|
||||||
Timeout(timeout).
|
|
||||||
Do(ctx).
|
|
||||||
Into(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Watch returns a watch.Interface that watches the requested acceleratorFunctions.
|
|
||||||
func (c *acceleratorFunctions) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
|
||||||
var timeout time.Duration
|
|
||||||
if opts.TimeoutSeconds != nil {
|
|
||||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
|
||||||
}
|
|
||||||
opts.Watch = true
|
|
||||||
return c.client.Get().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("acceleratorfunctions").
|
|
||||||
VersionedParams(&opts, scheme.ParameterCodec).
|
|
||||||
Timeout(timeout).
|
|
||||||
Watch(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create takes the representation of a acceleratorFunction and creates it. Returns the server's representation of the acceleratorFunction, and an error, if there is any.
|
|
||||||
func (c *acceleratorFunctions) Create(ctx context.Context, acceleratorFunction *v2.AcceleratorFunction, opts v1.CreateOptions) (result *v2.AcceleratorFunction, err error) {
|
|
||||||
result = &v2.AcceleratorFunction{}
|
|
||||||
err = c.client.Post().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("acceleratorfunctions").
|
|
||||||
VersionedParams(&opts, scheme.ParameterCodec).
|
|
||||||
Body(acceleratorFunction).
|
|
||||||
Do(ctx).
|
|
||||||
Into(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update takes the representation of a acceleratorFunction and updates it. Returns the server's representation of the acceleratorFunction, and an error, if there is any.
|
|
||||||
func (c *acceleratorFunctions) Update(ctx context.Context, acceleratorFunction *v2.AcceleratorFunction, opts v1.UpdateOptions) (result *v2.AcceleratorFunction, err error) {
|
|
||||||
result = &v2.AcceleratorFunction{}
|
|
||||||
err = c.client.Put().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("acceleratorfunctions").
|
|
||||||
Name(acceleratorFunction.Name).
|
|
||||||
VersionedParams(&opts, scheme.ParameterCodec).
|
|
||||||
Body(acceleratorFunction).
|
|
||||||
Do(ctx).
|
|
||||||
Into(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete takes name of the acceleratorFunction and deletes it. Returns an error if one occurs.
|
|
||||||
func (c *acceleratorFunctions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
|
|
||||||
return c.client.Delete().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("acceleratorfunctions").
|
|
||||||
Name(name).
|
|
||||||
Body(&opts).
|
|
||||||
Do(ctx).
|
|
||||||
Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteCollection deletes a collection of objects.
|
|
||||||
func (c *acceleratorFunctions) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
|
|
||||||
var timeout time.Duration
|
|
||||||
if listOpts.TimeoutSeconds != nil {
|
|
||||||
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
|
|
||||||
}
|
|
||||||
return c.client.Delete().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("acceleratorfunctions").
|
|
||||||
VersionedParams(&listOpts, scheme.ParameterCodec).
|
|
||||||
Timeout(timeout).
|
|
||||||
Body(&opts).
|
|
||||||
Do(ctx).
|
|
||||||
Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Patch applies the patch and returns the patched acceleratorFunction.
|
|
||||||
func (c *acceleratorFunctions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.AcceleratorFunction, err error) {
|
|
||||||
result = &v2.AcceleratorFunction{}
|
|
||||||
err = c.client.Patch(pt).
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("acceleratorfunctions").
|
|
||||||
Name(name).
|
|
||||||
SubResource(subresources...).
|
|
||||||
VersionedParams(&opts, scheme.ParameterCodec).
|
|
||||||
Body(data).
|
|
||||||
Do(ctx).
|
|
||||||
Into(result)
|
|
||||||
return
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
// This package has the automatically generated typed clients.
|
|
||||||
package v2
|
|
@ -1,18 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
// Package fake has the automatically generated clients.
|
|
||||||
package fake
|
|
@ -1,128 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package fake
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
labels "k8s.io/apimachinery/pkg/labels"
|
|
||||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
types "k8s.io/apimachinery/pkg/types"
|
|
||||||
watch "k8s.io/apimachinery/pkg/watch"
|
|
||||||
testing "k8s.io/client-go/testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FakeAcceleratorFunctions implements AcceleratorFunctionInterface
|
|
||||||
type FakeAcceleratorFunctions struct {
|
|
||||||
Fake *FakeFpgaV2
|
|
||||||
ns string
|
|
||||||
}
|
|
||||||
|
|
||||||
var acceleratorfunctionsResource = schema.GroupVersionResource{Group: "fpga.intel.com", Version: "v2", Resource: "acceleratorfunctions"}
|
|
||||||
|
|
||||||
var acceleratorfunctionsKind = schema.GroupVersionKind{Group: "fpga.intel.com", Version: "v2", Kind: "AcceleratorFunction"}
|
|
||||||
|
|
||||||
// Get takes name of the acceleratorFunction, and returns the corresponding acceleratorFunction object, and an error if there is any.
|
|
||||||
func (c *FakeAcceleratorFunctions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v2.AcceleratorFunction, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewGetAction(acceleratorfunctionsResource, c.ns, name), &v2.AcceleratorFunction{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*v2.AcceleratorFunction), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// List takes label and field selectors, and returns the list of AcceleratorFunctions that match those selectors.
|
|
||||||
func (c *FakeAcceleratorFunctions) List(ctx context.Context, opts v1.ListOptions) (result *v2.AcceleratorFunctionList, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewListAction(acceleratorfunctionsResource, acceleratorfunctionsKind, c.ns, opts), &v2.AcceleratorFunctionList{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
label, _, _ := testing.ExtractFromListOptions(opts)
|
|
||||||
if label == nil {
|
|
||||||
label = labels.Everything()
|
|
||||||
}
|
|
||||||
list := &v2.AcceleratorFunctionList{ListMeta: obj.(*v2.AcceleratorFunctionList).ListMeta}
|
|
||||||
for _, item := range obj.(*v2.AcceleratorFunctionList).Items {
|
|
||||||
if label.Matches(labels.Set(item.Labels)) {
|
|
||||||
list.Items = append(list.Items, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Watch returns a watch.Interface that watches the requested acceleratorFunctions.
|
|
||||||
func (c *FakeAcceleratorFunctions) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
|
||||||
return c.Fake.
|
|
||||||
InvokesWatch(testing.NewWatchAction(acceleratorfunctionsResource, c.ns, opts))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create takes the representation of a acceleratorFunction and creates it. Returns the server's representation of the acceleratorFunction, and an error, if there is any.
|
|
||||||
func (c *FakeAcceleratorFunctions) Create(ctx context.Context, acceleratorFunction *v2.AcceleratorFunction, opts v1.CreateOptions) (result *v2.AcceleratorFunction, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewCreateAction(acceleratorfunctionsResource, c.ns, acceleratorFunction), &v2.AcceleratorFunction{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*v2.AcceleratorFunction), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update takes the representation of a acceleratorFunction and updates it. Returns the server's representation of the acceleratorFunction, and an error, if there is any.
|
|
||||||
func (c *FakeAcceleratorFunctions) Update(ctx context.Context, acceleratorFunction *v2.AcceleratorFunction, opts v1.UpdateOptions) (result *v2.AcceleratorFunction, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewUpdateAction(acceleratorfunctionsResource, c.ns, acceleratorFunction), &v2.AcceleratorFunction{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*v2.AcceleratorFunction), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete takes name of the acceleratorFunction and deletes it. Returns an error if one occurs.
|
|
||||||
func (c *FakeAcceleratorFunctions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
|
|
||||||
_, err := c.Fake.
|
|
||||||
Invokes(testing.NewDeleteAction(acceleratorfunctionsResource, c.ns, name), &v2.AcceleratorFunction{})
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteCollection deletes a collection of objects.
|
|
||||||
func (c *FakeAcceleratorFunctions) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
|
|
||||||
action := testing.NewDeleteCollectionAction(acceleratorfunctionsResource, c.ns, listOpts)
|
|
||||||
|
|
||||||
_, err := c.Fake.Invokes(action, &v2.AcceleratorFunctionList{})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Patch applies the patch and returns the patched acceleratorFunction.
|
|
||||||
func (c *FakeAcceleratorFunctions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.AcceleratorFunction, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewPatchSubresourceAction(acceleratorfunctionsResource, c.ns, name, pt, data, subresources...), &v2.AcceleratorFunction{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*v2.AcceleratorFunction), err
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package fake
|
|
||||||
|
|
||||||
import (
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned/typed/fpga.intel.com/v2"
|
|
||||||
rest "k8s.io/client-go/rest"
|
|
||||||
testing "k8s.io/client-go/testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FakeFpgaV2 struct {
|
|
||||||
*testing.Fake
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FakeFpgaV2) AcceleratorFunctions(namespace string) v2.AcceleratorFunctionInterface {
|
|
||||||
return &FakeAcceleratorFunctions{c, namespace}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FakeFpgaV2) FpgaRegions(namespace string) v2.FpgaRegionInterface {
|
|
||||||
return &FakeFpgaRegions{c, namespace}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RESTClient returns a RESTClient that is used to communicate
|
|
||||||
// with API server by this client implementation.
|
|
||||||
func (c *FakeFpgaV2) RESTClient() rest.Interface {
|
|
||||||
var ret *rest.RESTClient
|
|
||||||
return ret
|
|
||||||
}
|
|
@ -1,128 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package fake
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
labels "k8s.io/apimachinery/pkg/labels"
|
|
||||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
types "k8s.io/apimachinery/pkg/types"
|
|
||||||
watch "k8s.io/apimachinery/pkg/watch"
|
|
||||||
testing "k8s.io/client-go/testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FakeFpgaRegions implements FpgaRegionInterface
|
|
||||||
type FakeFpgaRegions struct {
|
|
||||||
Fake *FakeFpgaV2
|
|
||||||
ns string
|
|
||||||
}
|
|
||||||
|
|
||||||
var fpgaregionsResource = schema.GroupVersionResource{Group: "fpga.intel.com", Version: "v2", Resource: "fpgaregions"}
|
|
||||||
|
|
||||||
var fpgaregionsKind = schema.GroupVersionKind{Group: "fpga.intel.com", Version: "v2", Kind: "FpgaRegion"}
|
|
||||||
|
|
||||||
// Get takes name of the fpgaRegion, and returns the corresponding fpgaRegion object, and an error if there is any.
|
|
||||||
func (c *FakeFpgaRegions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v2.FpgaRegion, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewGetAction(fpgaregionsResource, c.ns, name), &v2.FpgaRegion{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*v2.FpgaRegion), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// List takes label and field selectors, and returns the list of FpgaRegions that match those selectors.
|
|
||||||
func (c *FakeFpgaRegions) List(ctx context.Context, opts v1.ListOptions) (result *v2.FpgaRegionList, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewListAction(fpgaregionsResource, fpgaregionsKind, c.ns, opts), &v2.FpgaRegionList{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
label, _, _ := testing.ExtractFromListOptions(opts)
|
|
||||||
if label == nil {
|
|
||||||
label = labels.Everything()
|
|
||||||
}
|
|
||||||
list := &v2.FpgaRegionList{ListMeta: obj.(*v2.FpgaRegionList).ListMeta}
|
|
||||||
for _, item := range obj.(*v2.FpgaRegionList).Items {
|
|
||||||
if label.Matches(labels.Set(item.Labels)) {
|
|
||||||
list.Items = append(list.Items, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Watch returns a watch.Interface that watches the requested fpgaRegions.
|
|
||||||
func (c *FakeFpgaRegions) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
|
||||||
return c.Fake.
|
|
||||||
InvokesWatch(testing.NewWatchAction(fpgaregionsResource, c.ns, opts))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create takes the representation of a fpgaRegion and creates it. Returns the server's representation of the fpgaRegion, and an error, if there is any.
|
|
||||||
func (c *FakeFpgaRegions) Create(ctx context.Context, fpgaRegion *v2.FpgaRegion, opts v1.CreateOptions) (result *v2.FpgaRegion, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewCreateAction(fpgaregionsResource, c.ns, fpgaRegion), &v2.FpgaRegion{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*v2.FpgaRegion), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update takes the representation of a fpgaRegion and updates it. Returns the server's representation of the fpgaRegion, and an error, if there is any.
|
|
||||||
func (c *FakeFpgaRegions) Update(ctx context.Context, fpgaRegion *v2.FpgaRegion, opts v1.UpdateOptions) (result *v2.FpgaRegion, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewUpdateAction(fpgaregionsResource, c.ns, fpgaRegion), &v2.FpgaRegion{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*v2.FpgaRegion), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete takes name of the fpgaRegion and deletes it. Returns an error if one occurs.
|
|
||||||
func (c *FakeFpgaRegions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
|
|
||||||
_, err := c.Fake.
|
|
||||||
Invokes(testing.NewDeleteAction(fpgaregionsResource, c.ns, name), &v2.FpgaRegion{})
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteCollection deletes a collection of objects.
|
|
||||||
func (c *FakeFpgaRegions) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
|
|
||||||
action := testing.NewDeleteCollectionAction(fpgaregionsResource, c.ns, listOpts)
|
|
||||||
|
|
||||||
_, err := c.Fake.Invokes(action, &v2.FpgaRegionList{})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Patch applies the patch and returns the patched fpgaRegion.
|
|
||||||
func (c *FakeFpgaRegions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.FpgaRegion, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewPatchSubresourceAction(fpgaregionsResource, c.ns, name, pt, data, subresources...), &v2.FpgaRegion{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*v2.FpgaRegion), err
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v2
|
|
||||||
|
|
||||||
import (
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned/scheme"
|
|
||||||
rest "k8s.io/client-go/rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FpgaV2Interface interface {
|
|
||||||
RESTClient() rest.Interface
|
|
||||||
AcceleratorFunctionsGetter
|
|
||||||
FpgaRegionsGetter
|
|
||||||
}
|
|
||||||
|
|
||||||
// FpgaV2Client is used to interact with features provided by the fpga.intel.com group.
|
|
||||||
type FpgaV2Client struct {
|
|
||||||
restClient rest.Interface
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FpgaV2Client) AcceleratorFunctions(namespace string) AcceleratorFunctionInterface {
|
|
||||||
return newAcceleratorFunctions(c, namespace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FpgaV2Client) FpgaRegions(namespace string) FpgaRegionInterface {
|
|
||||||
return newFpgaRegions(c, namespace)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewForConfig creates a new FpgaV2Client for the given config.
|
|
||||||
func NewForConfig(c *rest.Config) (*FpgaV2Client, error) {
|
|
||||||
config := *c
|
|
||||||
if err := setConfigDefaults(&config); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
client, err := rest.RESTClientFor(&config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &FpgaV2Client{client}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewForConfigOrDie creates a new FpgaV2Client for the given config and
|
|
||||||
// panics if there is an error in the config.
|
|
||||||
func NewForConfigOrDie(c *rest.Config) *FpgaV2Client {
|
|
||||||
client, err := NewForConfig(c)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return client
|
|
||||||
}
|
|
||||||
|
|
||||||
// New creates a new FpgaV2Client for the given RESTClient.
|
|
||||||
func New(c rest.Interface) *FpgaV2Client {
|
|
||||||
return &FpgaV2Client{c}
|
|
||||||
}
|
|
||||||
|
|
||||||
func setConfigDefaults(config *rest.Config) error {
|
|
||||||
gv := v2.SchemeGroupVersion
|
|
||||||
config.GroupVersion = &gv
|
|
||||||
config.APIPath = "/apis"
|
|
||||||
config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
|
|
||||||
|
|
||||||
if config.UserAgent == "" {
|
|
||||||
config.UserAgent = rest.DefaultKubernetesUserAgent()
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RESTClient returns a RESTClient that is used to communicate
|
|
||||||
// with API server by this client implementation.
|
|
||||||
func (c *FpgaV2Client) RESTClient() rest.Interface {
|
|
||||||
if c == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return c.restClient
|
|
||||||
}
|
|
@ -1,176 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
scheme "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned/scheme"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
types "k8s.io/apimachinery/pkg/types"
|
|
||||||
watch "k8s.io/apimachinery/pkg/watch"
|
|
||||||
rest "k8s.io/client-go/rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FpgaRegionsGetter has a method to return a FpgaRegionInterface.
|
|
||||||
// A group's client should implement this interface.
|
|
||||||
type FpgaRegionsGetter interface {
|
|
||||||
FpgaRegions(namespace string) FpgaRegionInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
// FpgaRegionInterface has methods to work with FpgaRegion resources.
|
|
||||||
type FpgaRegionInterface interface {
|
|
||||||
Create(ctx context.Context, fpgaRegion *v2.FpgaRegion, opts v1.CreateOptions) (*v2.FpgaRegion, error)
|
|
||||||
Update(ctx context.Context, fpgaRegion *v2.FpgaRegion, opts v1.UpdateOptions) (*v2.FpgaRegion, error)
|
|
||||||
Delete(ctx context.Context, name string, opts v1.DeleteOptions) error
|
|
||||||
DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error
|
|
||||||
Get(ctx context.Context, name string, opts v1.GetOptions) (*v2.FpgaRegion, error)
|
|
||||||
List(ctx context.Context, opts v1.ListOptions) (*v2.FpgaRegionList, error)
|
|
||||||
Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
|
|
||||||
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.FpgaRegion, err error)
|
|
||||||
FpgaRegionExpansion
|
|
||||||
}
|
|
||||||
|
|
||||||
// fpgaRegions implements FpgaRegionInterface
|
|
||||||
type fpgaRegions struct {
|
|
||||||
client rest.Interface
|
|
||||||
ns string
|
|
||||||
}
|
|
||||||
|
|
||||||
// newFpgaRegions returns a FpgaRegions
|
|
||||||
func newFpgaRegions(c *FpgaV2Client, namespace string) *fpgaRegions {
|
|
||||||
return &fpgaRegions{
|
|
||||||
client: c.RESTClient(),
|
|
||||||
ns: namespace,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get takes name of the fpgaRegion, and returns the corresponding fpgaRegion object, and an error if there is any.
|
|
||||||
func (c *fpgaRegions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v2.FpgaRegion, err error) {
|
|
||||||
result = &v2.FpgaRegion{}
|
|
||||||
err = c.client.Get().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("fpgaregions").
|
|
||||||
Name(name).
|
|
||||||
VersionedParams(&options, scheme.ParameterCodec).
|
|
||||||
Do(ctx).
|
|
||||||
Into(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// List takes label and field selectors, and returns the list of FpgaRegions that match those selectors.
|
|
||||||
func (c *fpgaRegions) List(ctx context.Context, opts v1.ListOptions) (result *v2.FpgaRegionList, err error) {
|
|
||||||
var timeout time.Duration
|
|
||||||
if opts.TimeoutSeconds != nil {
|
|
||||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
|
||||||
}
|
|
||||||
result = &v2.FpgaRegionList{}
|
|
||||||
err = c.client.Get().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("fpgaregions").
|
|
||||||
VersionedParams(&opts, scheme.ParameterCodec).
|
|
||||||
Timeout(timeout).
|
|
||||||
Do(ctx).
|
|
||||||
Into(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Watch returns a watch.Interface that watches the requested fpgaRegions.
|
|
||||||
func (c *fpgaRegions) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
|
||||||
var timeout time.Duration
|
|
||||||
if opts.TimeoutSeconds != nil {
|
|
||||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
|
||||||
}
|
|
||||||
opts.Watch = true
|
|
||||||
return c.client.Get().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("fpgaregions").
|
|
||||||
VersionedParams(&opts, scheme.ParameterCodec).
|
|
||||||
Timeout(timeout).
|
|
||||||
Watch(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create takes the representation of a fpgaRegion and creates it. Returns the server's representation of the fpgaRegion, and an error, if there is any.
|
|
||||||
func (c *fpgaRegions) Create(ctx context.Context, fpgaRegion *v2.FpgaRegion, opts v1.CreateOptions) (result *v2.FpgaRegion, err error) {
|
|
||||||
result = &v2.FpgaRegion{}
|
|
||||||
err = c.client.Post().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("fpgaregions").
|
|
||||||
VersionedParams(&opts, scheme.ParameterCodec).
|
|
||||||
Body(fpgaRegion).
|
|
||||||
Do(ctx).
|
|
||||||
Into(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update takes the representation of a fpgaRegion and updates it. Returns the server's representation of the fpgaRegion, and an error, if there is any.
|
|
||||||
func (c *fpgaRegions) Update(ctx context.Context, fpgaRegion *v2.FpgaRegion, opts v1.UpdateOptions) (result *v2.FpgaRegion, err error) {
|
|
||||||
result = &v2.FpgaRegion{}
|
|
||||||
err = c.client.Put().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("fpgaregions").
|
|
||||||
Name(fpgaRegion.Name).
|
|
||||||
VersionedParams(&opts, scheme.ParameterCodec).
|
|
||||||
Body(fpgaRegion).
|
|
||||||
Do(ctx).
|
|
||||||
Into(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete takes name of the fpgaRegion and deletes it. Returns an error if one occurs.
|
|
||||||
func (c *fpgaRegions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
|
|
||||||
return c.client.Delete().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("fpgaregions").
|
|
||||||
Name(name).
|
|
||||||
Body(&opts).
|
|
||||||
Do(ctx).
|
|
||||||
Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteCollection deletes a collection of objects.
|
|
||||||
func (c *fpgaRegions) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
|
|
||||||
var timeout time.Duration
|
|
||||||
if listOpts.TimeoutSeconds != nil {
|
|
||||||
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
|
|
||||||
}
|
|
||||||
return c.client.Delete().
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("fpgaregions").
|
|
||||||
VersionedParams(&listOpts, scheme.ParameterCodec).
|
|
||||||
Timeout(timeout).
|
|
||||||
Body(&opts).
|
|
||||||
Do(ctx).
|
|
||||||
Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Patch applies the patch and returns the patched fpgaRegion.
|
|
||||||
func (c *fpgaRegions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.FpgaRegion, err error) {
|
|
||||||
result = &v2.FpgaRegion{}
|
|
||||||
err = c.client.Patch(pt).
|
|
||||||
Namespace(c.ns).
|
|
||||||
Resource("fpgaregions").
|
|
||||||
Name(name).
|
|
||||||
SubResource(subresources...).
|
|
||||||
VersionedParams(&opts, scheme.ParameterCodec).
|
|
||||||
Body(data).
|
|
||||||
Do(ctx).
|
|
||||||
Into(result)
|
|
||||||
return
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v2
|
|
||||||
|
|
||||||
type AcceleratorFunctionExpansion interface{}
|
|
||||||
|
|
||||||
type FpgaRegionExpansion interface{}
|
|
@ -1,178 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by informer-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package externalversions
|
|
||||||
|
|
||||||
import (
|
|
||||||
reflect "reflect"
|
|
||||||
sync "sync"
|
|
||||||
time "time"
|
|
||||||
|
|
||||||
versioned "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned"
|
|
||||||
fpgaintelcom "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/informers/externalversions/fpga.intel.com"
|
|
||||||
internalinterfaces "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/informers/externalversions/internalinterfaces"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
cache "k8s.io/client-go/tools/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SharedInformerOption defines the functional option type for SharedInformerFactory.
|
|
||||||
type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory
|
|
||||||
|
|
||||||
type sharedInformerFactory struct {
|
|
||||||
client versioned.Interface
|
|
||||||
namespace string
|
|
||||||
tweakListOptions internalinterfaces.TweakListOptionsFunc
|
|
||||||
lock sync.Mutex
|
|
||||||
defaultResync time.Duration
|
|
||||||
customResync map[reflect.Type]time.Duration
|
|
||||||
|
|
||||||
informers map[reflect.Type]cache.SharedIndexInformer
|
|
||||||
// startedInformers is used for tracking which informers have been started.
|
|
||||||
// This allows Start() to be called multiple times safely.
|
|
||||||
startedInformers map[reflect.Type]bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithCustomResyncConfig sets a custom resync period for the specified informer types.
|
|
||||||
func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption {
|
|
||||||
return func(factory *sharedInformerFactory) *sharedInformerFactory {
|
|
||||||
for k, v := range resyncConfig {
|
|
||||||
factory.customResync[reflect.TypeOf(k)] = v
|
|
||||||
}
|
|
||||||
return factory
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory.
|
|
||||||
func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption {
|
|
||||||
return func(factory *sharedInformerFactory) *sharedInformerFactory {
|
|
||||||
factory.tweakListOptions = tweakListOptions
|
|
||||||
return factory
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithNamespace limits the SharedInformerFactory to the specified namespace.
|
|
||||||
func WithNamespace(namespace string) SharedInformerOption {
|
|
||||||
return func(factory *sharedInformerFactory) *sharedInformerFactory {
|
|
||||||
factory.namespace = namespace
|
|
||||||
return factory
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
|
|
||||||
func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory {
|
|
||||||
return NewSharedInformerFactoryWithOptions(client, defaultResync)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory.
|
|
||||||
// Listers obtained via this SharedInformerFactory will be subject to the same filters
|
|
||||||
// as specified here.
|
|
||||||
// Deprecated: Please use NewSharedInformerFactoryWithOptions instead
|
|
||||||
func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory {
|
|
||||||
return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions))
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options.
|
|
||||||
func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory {
|
|
||||||
factory := &sharedInformerFactory{
|
|
||||||
client: client,
|
|
||||||
namespace: v1.NamespaceAll,
|
|
||||||
defaultResync: defaultResync,
|
|
||||||
informers: make(map[reflect.Type]cache.SharedIndexInformer),
|
|
||||||
startedInformers: make(map[reflect.Type]bool),
|
|
||||||
customResync: make(map[reflect.Type]time.Duration),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply all options
|
|
||||||
for _, opt := range options {
|
|
||||||
factory = opt(factory)
|
|
||||||
}
|
|
||||||
|
|
||||||
return factory
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start initializes all requested informers.
|
|
||||||
func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
|
|
||||||
for informerType, informer := range f.informers {
|
|
||||||
if !f.startedInformers[informerType] {
|
|
||||||
go informer.Run(stopCh)
|
|
||||||
f.startedInformers[informerType] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WaitForCacheSync waits for all started informers' cache were synced.
|
|
||||||
func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool {
|
|
||||||
informers := func() map[reflect.Type]cache.SharedIndexInformer {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
|
|
||||||
informers := map[reflect.Type]cache.SharedIndexInformer{}
|
|
||||||
for informerType, informer := range f.informers {
|
|
||||||
if f.startedInformers[informerType] {
|
|
||||||
informers[informerType] = informer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return informers
|
|
||||||
}()
|
|
||||||
|
|
||||||
res := map[reflect.Type]bool{}
|
|
||||||
for informType, informer := range informers {
|
|
||||||
res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// InternalInformerFor returns the SharedIndexInformer for obj using an internal
|
|
||||||
// client.
|
|
||||||
func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
|
|
||||||
informerType := reflect.TypeOf(obj)
|
|
||||||
informer, exists := f.informers[informerType]
|
|
||||||
if exists {
|
|
||||||
return informer
|
|
||||||
}
|
|
||||||
|
|
||||||
resyncPeriod, exists := f.customResync[informerType]
|
|
||||||
if !exists {
|
|
||||||
resyncPeriod = f.defaultResync
|
|
||||||
}
|
|
||||||
|
|
||||||
informer = newFunc(f.client, resyncPeriod)
|
|
||||||
f.informers[informerType] = informer
|
|
||||||
|
|
||||||
return informer
|
|
||||||
}
|
|
||||||
|
|
||||||
// SharedInformerFactory provides shared informers for resources in all known
|
|
||||||
// API group versions.
|
|
||||||
type SharedInformerFactory interface {
|
|
||||||
internalinterfaces.SharedInformerFactory
|
|
||||||
ForResource(resource schema.GroupVersionResource) (GenericInformer, error)
|
|
||||||
WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool
|
|
||||||
|
|
||||||
Fpga() fpgaintelcom.Interface
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sharedInformerFactory) Fpga() fpgaintelcom.Interface {
|
|
||||||
return fpgaintelcom.New(f, f.namespace, f.tweakListOptions)
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by informer-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package fpga
|
|
||||||
|
|
||||||
import (
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/informers/externalversions/fpga.intel.com/v2"
|
|
||||||
internalinterfaces "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/informers/externalversions/internalinterfaces"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Interface provides access to each of this group's versions.
|
|
||||||
type Interface interface {
|
|
||||||
// V2 provides access to shared informers for resources in V2.
|
|
||||||
V2() v2.Interface
|
|
||||||
}
|
|
||||||
|
|
||||||
type group struct {
|
|
||||||
factory internalinterfaces.SharedInformerFactory
|
|
||||||
namespace string
|
|
||||||
tweakListOptions internalinterfaces.TweakListOptionsFunc
|
|
||||||
}
|
|
||||||
|
|
||||||
// New returns a new Interface.
|
|
||||||
func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface {
|
|
||||||
return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions}
|
|
||||||
}
|
|
||||||
|
|
||||||
// V2 returns a new v2.Interface.
|
|
||||||
func (g *group) V2() v2.Interface {
|
|
||||||
return v2.New(g.factory, g.namespace, g.tweakListOptions)
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by informer-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
time "time"
|
|
||||||
|
|
||||||
fpgaintelcomv2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
versioned "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned"
|
|
||||||
internalinterfaces "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/informers/externalversions/internalinterfaces"
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/listers/fpga.intel.com/v2"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
watch "k8s.io/apimachinery/pkg/watch"
|
|
||||||
cache "k8s.io/client-go/tools/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AcceleratorFunctionInformer provides access to a shared informer and lister for
|
|
||||||
// AcceleratorFunctions.
|
|
||||||
type AcceleratorFunctionInformer interface {
|
|
||||||
Informer() cache.SharedIndexInformer
|
|
||||||
Lister() v2.AcceleratorFunctionLister
|
|
||||||
}
|
|
||||||
|
|
||||||
type acceleratorFunctionInformer struct {
|
|
||||||
factory internalinterfaces.SharedInformerFactory
|
|
||||||
tweakListOptions internalinterfaces.TweakListOptionsFunc
|
|
||||||
namespace string
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewAcceleratorFunctionInformer constructs a new informer for AcceleratorFunction type.
|
|
||||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
|
||||||
// one. This reduces memory footprint and number of connections to the server.
|
|
||||||
func NewAcceleratorFunctionInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
|
|
||||||
return NewFilteredAcceleratorFunctionInformer(client, namespace, resyncPeriod, indexers, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFilteredAcceleratorFunctionInformer constructs a new informer for AcceleratorFunction type.
|
|
||||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
|
||||||
// one. This reduces memory footprint and number of connections to the server.
|
|
||||||
func NewFilteredAcceleratorFunctionInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
|
|
||||||
return cache.NewSharedIndexInformer(
|
|
||||||
&cache.ListWatch{
|
|
||||||
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
|
|
||||||
if tweakListOptions != nil {
|
|
||||||
tweakListOptions(&options)
|
|
||||||
}
|
|
||||||
return client.FpgaV2().AcceleratorFunctions(namespace).List(context.TODO(), options)
|
|
||||||
},
|
|
||||||
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
|
|
||||||
if tweakListOptions != nil {
|
|
||||||
tweakListOptions(&options)
|
|
||||||
}
|
|
||||||
return client.FpgaV2().AcceleratorFunctions(namespace).Watch(context.TODO(), options)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
&fpgaintelcomv2.AcceleratorFunction{},
|
|
||||||
resyncPeriod,
|
|
||||||
indexers,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *acceleratorFunctionInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
|
|
||||||
return NewFilteredAcceleratorFunctionInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *acceleratorFunctionInformer) Informer() cache.SharedIndexInformer {
|
|
||||||
return f.factory.InformerFor(&fpgaintelcomv2.AcceleratorFunction{}, f.defaultInformer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *acceleratorFunctionInformer) Lister() v2.AcceleratorFunctionLister {
|
|
||||||
return v2.NewAcceleratorFunctionLister(f.Informer().GetIndexer())
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by informer-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
time "time"
|
|
||||||
|
|
||||||
fpgaintelcomv2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
versioned "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned"
|
|
||||||
internalinterfaces "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/informers/externalversions/internalinterfaces"
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/listers/fpga.intel.com/v2"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
watch "k8s.io/apimachinery/pkg/watch"
|
|
||||||
cache "k8s.io/client-go/tools/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FpgaRegionInformer provides access to a shared informer and lister for
|
|
||||||
// FpgaRegions.
|
|
||||||
type FpgaRegionInformer interface {
|
|
||||||
Informer() cache.SharedIndexInformer
|
|
||||||
Lister() v2.FpgaRegionLister
|
|
||||||
}
|
|
||||||
|
|
||||||
type fpgaRegionInformer struct {
|
|
||||||
factory internalinterfaces.SharedInformerFactory
|
|
||||||
tweakListOptions internalinterfaces.TweakListOptionsFunc
|
|
||||||
namespace string
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFpgaRegionInformer constructs a new informer for FpgaRegion type.
|
|
||||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
|
||||||
// one. This reduces memory footprint and number of connections to the server.
|
|
||||||
func NewFpgaRegionInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
|
|
||||||
return NewFilteredFpgaRegionInformer(client, namespace, resyncPeriod, indexers, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFilteredFpgaRegionInformer constructs a new informer for FpgaRegion type.
|
|
||||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
|
||||||
// one. This reduces memory footprint and number of connections to the server.
|
|
||||||
func NewFilteredFpgaRegionInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
|
|
||||||
return cache.NewSharedIndexInformer(
|
|
||||||
&cache.ListWatch{
|
|
||||||
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
|
|
||||||
if tweakListOptions != nil {
|
|
||||||
tweakListOptions(&options)
|
|
||||||
}
|
|
||||||
return client.FpgaV2().FpgaRegions(namespace).List(context.TODO(), options)
|
|
||||||
},
|
|
||||||
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
|
|
||||||
if tweakListOptions != nil {
|
|
||||||
tweakListOptions(&options)
|
|
||||||
}
|
|
||||||
return client.FpgaV2().FpgaRegions(namespace).Watch(context.TODO(), options)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
&fpgaintelcomv2.FpgaRegion{},
|
|
||||||
resyncPeriod,
|
|
||||||
indexers,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *fpgaRegionInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
|
|
||||||
return NewFilteredFpgaRegionInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *fpgaRegionInformer) Informer() cache.SharedIndexInformer {
|
|
||||||
return f.factory.InformerFor(&fpgaintelcomv2.FpgaRegion{}, f.defaultInformer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *fpgaRegionInformer) Lister() v2.FpgaRegionLister {
|
|
||||||
return v2.NewFpgaRegionLister(f.Informer().GetIndexer())
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by informer-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v2
|
|
||||||
|
|
||||||
import (
|
|
||||||
internalinterfaces "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/informers/externalversions/internalinterfaces"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Interface provides access to all the informers in this group version.
|
|
||||||
type Interface interface {
|
|
||||||
// AcceleratorFunctions returns a AcceleratorFunctionInformer.
|
|
||||||
AcceleratorFunctions() AcceleratorFunctionInformer
|
|
||||||
// FpgaRegions returns a FpgaRegionInformer.
|
|
||||||
FpgaRegions() FpgaRegionInformer
|
|
||||||
}
|
|
||||||
|
|
||||||
type version struct {
|
|
||||||
factory internalinterfaces.SharedInformerFactory
|
|
||||||
namespace string
|
|
||||||
tweakListOptions internalinterfaces.TweakListOptionsFunc
|
|
||||||
}
|
|
||||||
|
|
||||||
// New returns a new Interface.
|
|
||||||
func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface {
|
|
||||||
return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AcceleratorFunctions returns a AcceleratorFunctionInformer.
|
|
||||||
func (v *version) AcceleratorFunctions() AcceleratorFunctionInformer {
|
|
||||||
return &acceleratorFunctionInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FpgaRegions returns a FpgaRegionInformer.
|
|
||||||
func (v *version) FpgaRegions() FpgaRegionInformer {
|
|
||||||
return &fpgaRegionInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by informer-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package externalversions
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
cache "k8s.io/client-go/tools/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GenericInformer is type of SharedIndexInformer which will locate and delegate to other
|
|
||||||
// sharedInformers based on type
|
|
||||||
type GenericInformer interface {
|
|
||||||
Informer() cache.SharedIndexInformer
|
|
||||||
Lister() cache.GenericLister
|
|
||||||
}
|
|
||||||
|
|
||||||
type genericInformer struct {
|
|
||||||
informer cache.SharedIndexInformer
|
|
||||||
resource schema.GroupResource
|
|
||||||
}
|
|
||||||
|
|
||||||
// Informer returns the SharedIndexInformer.
|
|
||||||
func (f *genericInformer) Informer() cache.SharedIndexInformer {
|
|
||||||
return f.informer
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lister returns the GenericLister.
|
|
||||||
func (f *genericInformer) Lister() cache.GenericLister {
|
|
||||||
return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ForResource gives generic access to a shared informer of the matching type
|
|
||||||
// TODO extend this to unknown resources with a client pool
|
|
||||||
func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
|
|
||||||
switch resource {
|
|
||||||
// Group=fpga.intel.com, Version=v2
|
|
||||||
case v2.SchemeGroupVersion.WithResource("acceleratorfunctions"):
|
|
||||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Fpga().V2().AcceleratorFunctions().Informer()}, nil
|
|
||||||
case v2.SchemeGroupVersion.WithResource("fpgaregions"):
|
|
||||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Fpga().V2().FpgaRegions().Informer()}, nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("no informer found for %v", resource)
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by informer-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package internalinterfaces
|
|
||||||
|
|
||||||
import (
|
|
||||||
time "time"
|
|
||||||
|
|
||||||
versioned "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
cache "k8s.io/client-go/tools/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer.
|
|
||||||
type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer
|
|
||||||
|
|
||||||
// SharedInformerFactory a small interface to allow for adding an informer without an import cycle
|
|
||||||
type SharedInformerFactory interface {
|
|
||||||
Start(stopCh <-chan struct{})
|
|
||||||
InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer
|
|
||||||
}
|
|
||||||
|
|
||||||
// TweakListOptionsFunc is a function that transforms a v1.ListOptions.
|
|
||||||
type TweakListOptionsFunc func(*v1.ListOptions)
|
|
@ -1,92 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by lister-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v2
|
|
||||||
|
|
||||||
import (
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
|
||||||
"k8s.io/client-go/tools/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AcceleratorFunctionLister helps list AcceleratorFunctions.
|
|
||||||
type AcceleratorFunctionLister interface {
|
|
||||||
// List lists all AcceleratorFunctions in the indexer.
|
|
||||||
List(selector labels.Selector) (ret []*v2.AcceleratorFunction, err error)
|
|
||||||
// AcceleratorFunctions returns an object that can list and get AcceleratorFunctions.
|
|
||||||
AcceleratorFunctions(namespace string) AcceleratorFunctionNamespaceLister
|
|
||||||
AcceleratorFunctionListerExpansion
|
|
||||||
}
|
|
||||||
|
|
||||||
// acceleratorFunctionLister implements the AcceleratorFunctionLister interface.
|
|
||||||
type acceleratorFunctionLister struct {
|
|
||||||
indexer cache.Indexer
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewAcceleratorFunctionLister returns a new AcceleratorFunctionLister.
|
|
||||||
func NewAcceleratorFunctionLister(indexer cache.Indexer) AcceleratorFunctionLister {
|
|
||||||
return &acceleratorFunctionLister{indexer: indexer}
|
|
||||||
}
|
|
||||||
|
|
||||||
// List lists all AcceleratorFunctions in the indexer.
|
|
||||||
func (s *acceleratorFunctionLister) List(selector labels.Selector) (ret []*v2.AcceleratorFunction, err error) {
|
|
||||||
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
|
|
||||||
ret = append(ret, m.(*v2.AcceleratorFunction))
|
|
||||||
})
|
|
||||||
return ret, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// AcceleratorFunctions returns an object that can list and get AcceleratorFunctions.
|
|
||||||
func (s *acceleratorFunctionLister) AcceleratorFunctions(namespace string) AcceleratorFunctionNamespaceLister {
|
|
||||||
return acceleratorFunctionNamespaceLister{indexer: s.indexer, namespace: namespace}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AcceleratorFunctionNamespaceLister helps list and get AcceleratorFunctions.
|
|
||||||
type AcceleratorFunctionNamespaceLister interface {
|
|
||||||
// List lists all AcceleratorFunctions in the indexer for a given namespace.
|
|
||||||
List(selector labels.Selector) (ret []*v2.AcceleratorFunction, err error)
|
|
||||||
// Get retrieves the AcceleratorFunction from the indexer for a given namespace and name.
|
|
||||||
Get(name string) (*v2.AcceleratorFunction, error)
|
|
||||||
AcceleratorFunctionNamespaceListerExpansion
|
|
||||||
}
|
|
||||||
|
|
||||||
// acceleratorFunctionNamespaceLister implements the AcceleratorFunctionNamespaceLister
|
|
||||||
// interface.
|
|
||||||
type acceleratorFunctionNamespaceLister struct {
|
|
||||||
indexer cache.Indexer
|
|
||||||
namespace string
|
|
||||||
}
|
|
||||||
|
|
||||||
// List lists all AcceleratorFunctions in the indexer for a given namespace.
|
|
||||||
func (s acceleratorFunctionNamespaceLister) List(selector labels.Selector) (ret []*v2.AcceleratorFunction, err error) {
|
|
||||||
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
|
|
||||||
ret = append(ret, m.(*v2.AcceleratorFunction))
|
|
||||||
})
|
|
||||||
return ret, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get retrieves the AcceleratorFunction from the indexer for a given namespace and name.
|
|
||||||
func (s acceleratorFunctionNamespaceLister) Get(name string) (*v2.AcceleratorFunction, error) {
|
|
||||||
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if !exists {
|
|
||||||
return nil, errors.NewNotFound(v2.Resource("acceleratorfunction"), name)
|
|
||||||
}
|
|
||||||
return obj.(*v2.AcceleratorFunction), nil
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by lister-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v2
|
|
||||||
|
|
||||||
// AcceleratorFunctionListerExpansion allows custom methods to be added to
|
|
||||||
// AcceleratorFunctionLister.
|
|
||||||
type AcceleratorFunctionListerExpansion interface{}
|
|
||||||
|
|
||||||
// AcceleratorFunctionNamespaceListerExpansion allows custom methods to be added to
|
|
||||||
// AcceleratorFunctionNamespaceLister.
|
|
||||||
type AcceleratorFunctionNamespaceListerExpansion interface{}
|
|
||||||
|
|
||||||
// FpgaRegionListerExpansion allows custom methods to be added to
|
|
||||||
// FpgaRegionLister.
|
|
||||||
type FpgaRegionListerExpansion interface{}
|
|
||||||
|
|
||||||
// FpgaRegionNamespaceListerExpansion allows custom methods to be added to
|
|
||||||
// FpgaRegionNamespaceLister.
|
|
||||||
type FpgaRegionNamespaceListerExpansion interface{}
|
|
@ -1,92 +0,0 @@
|
|||||||
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Code generated by lister-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v2
|
|
||||||
|
|
||||||
import (
|
|
||||||
v2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
|
||||||
"k8s.io/client-go/tools/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FpgaRegionLister helps list FpgaRegions.
|
|
||||||
type FpgaRegionLister interface {
|
|
||||||
// List lists all FpgaRegions in the indexer.
|
|
||||||
List(selector labels.Selector) (ret []*v2.FpgaRegion, err error)
|
|
||||||
// FpgaRegions returns an object that can list and get FpgaRegions.
|
|
||||||
FpgaRegions(namespace string) FpgaRegionNamespaceLister
|
|
||||||
FpgaRegionListerExpansion
|
|
||||||
}
|
|
||||||
|
|
||||||
// fpgaRegionLister implements the FpgaRegionLister interface.
|
|
||||||
type fpgaRegionLister struct {
|
|
||||||
indexer cache.Indexer
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFpgaRegionLister returns a new FpgaRegionLister.
|
|
||||||
func NewFpgaRegionLister(indexer cache.Indexer) FpgaRegionLister {
|
|
||||||
return &fpgaRegionLister{indexer: indexer}
|
|
||||||
}
|
|
||||||
|
|
||||||
// List lists all FpgaRegions in the indexer.
|
|
||||||
func (s *fpgaRegionLister) List(selector labels.Selector) (ret []*v2.FpgaRegion, err error) {
|
|
||||||
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
|
|
||||||
ret = append(ret, m.(*v2.FpgaRegion))
|
|
||||||
})
|
|
||||||
return ret, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// FpgaRegions returns an object that can list and get FpgaRegions.
|
|
||||||
func (s *fpgaRegionLister) FpgaRegions(namespace string) FpgaRegionNamespaceLister {
|
|
||||||
return fpgaRegionNamespaceLister{indexer: s.indexer, namespace: namespace}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FpgaRegionNamespaceLister helps list and get FpgaRegions.
|
|
||||||
type FpgaRegionNamespaceLister interface {
|
|
||||||
// List lists all FpgaRegions in the indexer for a given namespace.
|
|
||||||
List(selector labels.Selector) (ret []*v2.FpgaRegion, err error)
|
|
||||||
// Get retrieves the FpgaRegion from the indexer for a given namespace and name.
|
|
||||||
Get(name string) (*v2.FpgaRegion, error)
|
|
||||||
FpgaRegionNamespaceListerExpansion
|
|
||||||
}
|
|
||||||
|
|
||||||
// fpgaRegionNamespaceLister implements the FpgaRegionNamespaceLister
|
|
||||||
// interface.
|
|
||||||
type fpgaRegionNamespaceLister struct {
|
|
||||||
indexer cache.Indexer
|
|
||||||
namespace string
|
|
||||||
}
|
|
||||||
|
|
||||||
// List lists all FpgaRegions in the indexer for a given namespace.
|
|
||||||
func (s fpgaRegionNamespaceLister) List(selector labels.Selector) (ret []*v2.FpgaRegion, err error) {
|
|
||||||
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
|
|
||||||
ret = append(ret, m.(*v2.FpgaRegion))
|
|
||||||
})
|
|
||||||
return ret, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get retrieves the FpgaRegion from the indexer for a given namespace and name.
|
|
||||||
func (s fpgaRegionNamespaceLister) Get(name string) (*v2.FpgaRegion, error) {
|
|
||||||
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if !exists {
|
|
||||||
return nil, errors.NewNotFound(v2.Resource("fpgaregion"), name)
|
|
||||||
}
|
|
||||||
return obj.(*v2.FpgaRegion), nil
|
|
||||||
}
|
|
108
pkg/fpgacontroller/fpgacontroller.go
Normal file
108
pkg/fpgacontroller/fpgacontroller.go
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// 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 fpgacontroller implements reconiciling controller for
|
||||||
|
// AcceleratorFunction and FpgaRegion objects used in the FPGA admission
|
||||||
|
// webhook.
|
||||||
|
package fpgacontroller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/go-logr/logr"
|
||||||
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
|
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
||||||
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpgacontroller/patcher"
|
||||||
|
)
|
||||||
|
|
||||||
|
// +kubebuilder:rbac:groups=fpga.intel.com,resources=acceleratorfunctions;fpgaregions,verbs=get;list;watch
|
||||||
|
|
||||||
|
// AcceleratorFunctionReconciler reconciles AcceleratorFunction objects.
|
||||||
|
type AcceleratorFunctionReconciler struct {
|
||||||
|
client.Client
|
||||||
|
Log logr.Logger
|
||||||
|
Scheme *runtime.Scheme
|
||||||
|
PatcherManager *patcher.PatcherManager
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reconcile reconciles updates for AcceleratorFunction objects.
|
||||||
|
func (r *AcceleratorFunctionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||||
|
ctx := context.Background()
|
||||||
|
log := r.Log.WithValues("af", req.NamespacedName)
|
||||||
|
|
||||||
|
p := r.PatcherManager.GetPatcher(req.NamespacedName.Namespace)
|
||||||
|
var af fpgav2.AcceleratorFunction
|
||||||
|
if err := r.Get(ctx, req.NamespacedName, &af); err != nil {
|
||||||
|
if apierrors.IsNotFound(err) {
|
||||||
|
p.RemoveAf(req.NamespacedName.Name)
|
||||||
|
log.V(4).Info("removed from patcher")
|
||||||
|
return ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Error(err, "unable to fetch AcceleratorFunction object")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(4).Info("received", "AcceleratorFunction", af)
|
||||||
|
return ctrl.Result{}, p.AddAf(&af)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupWithManager sets up the controller.
|
||||||
|
func (r *AcceleratorFunctionReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
|
For(&fpgav2.AcceleratorFunction{}).
|
||||||
|
Complete(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FpgaRegionReconciler reconciles AcceleratorFunction objects.
|
||||||
|
type FpgaRegionReconciler struct {
|
||||||
|
client.Client
|
||||||
|
Log logr.Logger
|
||||||
|
Scheme *runtime.Scheme
|
||||||
|
PatcherManager *patcher.PatcherManager
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reconcile reconciles updates for FpgaRegion objects.
|
||||||
|
func (r *FpgaRegionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||||
|
ctx := context.Background()
|
||||||
|
log := r.Log.WithValues("af", req.NamespacedName)
|
||||||
|
|
||||||
|
p := r.PatcherManager.GetPatcher(req.NamespacedName.Namespace)
|
||||||
|
var region fpgav2.FpgaRegion
|
||||||
|
if err := r.Get(ctx, req.NamespacedName, ®ion); err != nil {
|
||||||
|
if apierrors.IsNotFound(err) {
|
||||||
|
p.RemoveRegion(req.NamespacedName.Name)
|
||||||
|
log.V(4).Info("removed from patcher")
|
||||||
|
return ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Error(err, "unable to fetch FpgaRegion object")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(4).Info("received", "FpgaRegion", region)
|
||||||
|
p.AddRegion(®ion)
|
||||||
|
return ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupWithManager sets up the controller.
|
||||||
|
func (r *FpgaRegionReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
|
For(&fpgav2.FpgaRegion{}).
|
||||||
|
Complete(r)
|
||||||
|
}
|
135
pkg/fpgacontroller/fpgacontroller_test.go
Normal file
135
pkg/fpgacontroller/fpgacontroller_test.go
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// 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 fpgacontroller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
"k8s.io/klog/klogr"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
|
||||||
|
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
||||||
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpgacontroller/patcher"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
log = ctrl.Log.WithName("test")
|
||||||
|
scheme = runtime.NewScheme()
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ctrl.SetLogger(klogr.New())
|
||||||
|
_ = fpgav2.AddToScheme(scheme)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAcceleratorFunctionReconcile(t *testing.T) {
|
||||||
|
tcases := []struct {
|
||||||
|
name string
|
||||||
|
expectedErr bool
|
||||||
|
getError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty af",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "client error",
|
||||||
|
getError: errors.New("client error"),
|
||||||
|
expectedErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "af not found",
|
||||||
|
getError: apierrors.NewNotFound(schema.GroupResource{}, "fake"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tcases {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
reconciler := &AcceleratorFunctionReconciler{
|
||||||
|
Client: &mockClient{
|
||||||
|
getError: tt.getError,
|
||||||
|
},
|
||||||
|
Log: log,
|
||||||
|
PatcherManager: patcher.NewPatcherManager(log),
|
||||||
|
}
|
||||||
|
_, err := reconciler.Reconcile(ctrl.Request{})
|
||||||
|
if err != nil && !tt.expectedErr {
|
||||||
|
t.Errorf("unexpected error: %+v", err)
|
||||||
|
}
|
||||||
|
if err == nil && tt.expectedErr {
|
||||||
|
t.Error("expected error but got success")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAcceleratorFunctionSetupWithManager(t *testing.T) {
|
||||||
|
r := &AcceleratorFunctionReconciler{}
|
||||||
|
err := r.SetupWithManager(&mockManager{scheme: scheme})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected error: %+v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFpgaRegionReconcile(t *testing.T) {
|
||||||
|
tcases := []struct {
|
||||||
|
name string
|
||||||
|
expectedErr bool
|
||||||
|
getError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty region",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "client error",
|
||||||
|
getError: errors.New("client error"),
|
||||||
|
expectedErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "region not found",
|
||||||
|
getError: apierrors.NewNotFound(schema.GroupResource{}, "fake"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tcases {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
reconciler := &FpgaRegionReconciler{
|
||||||
|
Client: &mockClient{
|
||||||
|
getError: tt.getError,
|
||||||
|
},
|
||||||
|
Log: log,
|
||||||
|
PatcherManager: patcher.NewPatcherManager(log),
|
||||||
|
}
|
||||||
|
_, err := reconciler.Reconcile(ctrl.Request{})
|
||||||
|
if err != nil && !tt.expectedErr {
|
||||||
|
t.Errorf("unexpected error: %+v", err)
|
||||||
|
}
|
||||||
|
if err == nil && tt.expectedErr {
|
||||||
|
t.Error("expected error but got success")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFpgaRegionSetupWithManager(t *testing.T) {
|
||||||
|
r := &FpgaRegionReconciler{}
|
||||||
|
err := r.SetupWithManager(&mockManager{scheme: scheme})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected error: %+v", err)
|
||||||
|
}
|
||||||
|
}
|
135
pkg/fpgacontroller/mocks_test.go
Normal file
135
pkg/fpgacontroller/mocks_test.go
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// 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 fpgacontroller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/client-go/rest"
|
||||||
|
"k8s.io/client-go/tools/record"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/cache"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/healthz"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/manager"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||||
|
)
|
||||||
|
|
||||||
|
type mockClient struct {
|
||||||
|
getError error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mockClient) Create(context.Context, runtime.Object, ...client.CreateOption) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mockClient) Delete(context.Context, runtime.Object, ...client.DeleteOption) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mockClient) DeleteAllOf(context.Context, runtime.Object, ...client.DeleteAllOfOption) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mockClient) Get(context.Context, types.NamespacedName, runtime.Object) error {
|
||||||
|
return c.getError
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mockClient) List(context.Context, runtime.Object, ...client.ListOption) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mockClient) Patch(context.Context, runtime.Object, client.Patch, ...client.PatchOption) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mockClient) Status() client.StatusWriter {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mockClient) Update(context.Context, runtime.Object, ...client.UpdateOption) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type mockManager struct {
|
||||||
|
scheme *runtime.Scheme
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) Add(manager.Runnable) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) AddHealthzCheck(string, healthz.Checker) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) AddMetricsExtraHandler(string, http.Handler) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) AddReadyzCheck(string, healthz.Checker) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) Elected() <-chan struct{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) GetAPIReader() client.Reader {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) GetCache() cache.Cache {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) GetClient() client.Client {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) GetConfig() *rest.Config {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) GetEventRecorderFor(string) record.EventRecorder {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) GetFieldIndexer() client.FieldIndexer {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) GetRESTMapper() meta.RESTMapper {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) GetScheme() *runtime.Scheme {
|
||||||
|
return m.scheme
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) GetWebhookServer() *webhook.Server {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) SetFields(interface{}) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockManager) Start(<-chan struct{}) error {
|
||||||
|
return nil
|
||||||
|
}
|
@ -12,7 +12,8 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package main
|
// Package patcher provides functionality required to patch pods by the FPGA admission webhook.
|
||||||
|
package patcher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -21,10 +22,10 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/go-logr/logr"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/klog"
|
|
||||||
|
|
||||||
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
||||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga"
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga"
|
||||||
@ -71,20 +72,23 @@ var (
|
|||||||
type patcher struct {
|
type patcher struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
|
log logr.Logger
|
||||||
|
|
||||||
afMap map[string]*fpgav2.AcceleratorFunction
|
afMap map[string]*fpgav2.AcceleratorFunction
|
||||||
resourceMap map[string]string
|
resourceMap map[string]string
|
||||||
resourceModeMap map[string]string
|
resourceModeMap map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPatcher() *patcher {
|
func newPatcher(log logr.Logger) *patcher {
|
||||||
return &patcher{
|
return &patcher{
|
||||||
|
log: log,
|
||||||
afMap: make(map[string]*fpgav2.AcceleratorFunction),
|
afMap: make(map[string]*fpgav2.AcceleratorFunction),
|
||||||
resourceMap: make(map[string]string),
|
resourceMap: make(map[string]string),
|
||||||
resourceModeMap: make(map[string]string),
|
resourceModeMap: make(map[string]string),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *patcher) addAf(accfunc *fpgav2.AcceleratorFunction) error {
|
func (p *patcher) AddAf(accfunc *fpgav2.AcceleratorFunction) error {
|
||||||
defer p.Unlock()
|
defer p.Unlock()
|
||||||
p.Lock()
|
p.Lock()
|
||||||
|
|
||||||
@ -104,7 +108,7 @@ func (p *patcher) addAf(accfunc *fpgav2.AcceleratorFunction) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *patcher) addRegion(region *fpgav2.FpgaRegion) {
|
func (p *patcher) AddRegion(region *fpgav2.FpgaRegion) {
|
||||||
defer p.Unlock()
|
defer p.Unlock()
|
||||||
p.Lock()
|
p.Lock()
|
||||||
|
|
||||||
@ -112,7 +116,7 @@ func (p *patcher) addRegion(region *fpgav2.FpgaRegion) {
|
|||||||
p.resourceMap[namespace+"/"+region.Name] = rfc6901Escaper.Replace(namespace + "/region-" + region.Spec.InterfaceID)
|
p.resourceMap[namespace+"/"+region.Name] = rfc6901Escaper.Replace(namespace + "/region-" + region.Spec.InterfaceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *patcher) removeAf(name string) {
|
func (p *patcher) RemoveAf(name string) {
|
||||||
defer p.Unlock()
|
defer p.Unlock()
|
||||||
p.Lock()
|
p.Lock()
|
||||||
|
|
||||||
@ -121,7 +125,7 @@ func (p *patcher) removeAf(name string) {
|
|||||||
delete(p.resourceModeMap, namespace+"/"+name)
|
delete(p.resourceModeMap, namespace+"/"+name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *patcher) removeRegion(name string) {
|
func (p *patcher) RemoveRegion(name string) {
|
||||||
defer p.Unlock()
|
defer p.Unlock()
|
||||||
p.Lock()
|
p.Lock()
|
||||||
|
|
||||||
@ -217,11 +221,11 @@ func (p *patcher) getPatchOps(containerIdx int, container corev1.Container) ([]s
|
|||||||
envVars[fmt.Sprintf("FPGA_AFU_%d", counter)] = p.afMap[rname].Spec.AfuID
|
envVars[fmt.Sprintf("FPGA_AFU_%d", counter)] = p.afMap[rname].Spec.AfuID
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
msg := fmt.Sprintf("%q is registered with unknown mode %q instead of %q or %q",
|
|
||||||
rname, p.resourceModeMap[rname], af, region)
|
|
||||||
// Let admin know about broken af CRD.
|
// Let admin know about broken af CRD.
|
||||||
klog.Error(msg)
|
err := errors.Errorf("%q is registered with unknown mode %q instead of %q or %q",
|
||||||
return nil, errors.New(msg)
|
rname, p.resourceModeMap[rname], af, region)
|
||||||
|
p.log.Error(err, "unable to construct patching operations")
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if fpgaPluginMode == "" {
|
if fpgaPluginMode == "" {
|
||||||
@ -260,28 +264,11 @@ func (p *patcher) getPatchOps(containerIdx int, container corev1.Container) ([]s
|
|||||||
}
|
}
|
||||||
t := template.Must(template.New("add_operation").Parse(envAddOpTpl))
|
t := template.Must(template.New("add_operation").Parse(envAddOpTpl))
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
t.Execute(buf, data)
|
if err := t.Execute(buf, data); err != nil {
|
||||||
|
return nil, errors.Wrap(err, "unable to execute template")
|
||||||
|
}
|
||||||
ops = append(ops, buf.String())
|
ops = append(ops, buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return ops, nil
|
return ops, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// patcherManager keeps track of patchers registered for different Kubernetes namespaces.
|
|
||||||
type patcherManager map[string]*patcher
|
|
||||||
|
|
||||||
func newPatcherManager() patcherManager {
|
|
||||||
return make(map[string]*patcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pm patcherManager) getPatcher(namespace string) *patcher {
|
|
||||||
if p, ok := pm[namespace]; ok {
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
p := newPatcher()
|
|
||||||
pm[namespace] = p
|
|
||||||
klog.V(4).Info("created new patcher for namespace", namespace)
|
|
||||||
|
|
||||||
return p
|
|
||||||
}
|
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package main
|
package patcher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
@ -21,16 +21,17 @@ import (
|
|||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
|
||||||
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.Set("v", "4")
|
_ = flag.Set("v", "4")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPatcherStorageFunctions(t *testing.T) {
|
func TestPatcherStorageFunctions(t *testing.T) {
|
||||||
af := &fpgav2.AcceleratorFunction{
|
goodAf := &fpgav2.AcceleratorFunction{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "arria10-nlb0",
|
Name: "arria10-nlb0",
|
||||||
},
|
},
|
||||||
@ -38,6 +39,16 @@ func TestPatcherStorageFunctions(t *testing.T) {
|
|||||||
AfuID: "d8424dc4a4a3c413f89e433683f9040b",
|
AfuID: "d8424dc4a4a3c413f89e433683f9040b",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
brokenAf := &fpgav2.AcceleratorFunction{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "arria10-nlb0",
|
||||||
|
},
|
||||||
|
Spec: fpgav2.AcceleratorFunctionSpec{
|
||||||
|
AfuID: "wrong string",
|
||||||
|
InterfaceID: "wrong string",
|
||||||
|
Mode: af,
|
||||||
|
},
|
||||||
|
}
|
||||||
region := &fpgav2.FpgaRegion{
|
region := &fpgav2.FpgaRegion{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "arria10",
|
Name: "arria10",
|
||||||
@ -47,24 +58,29 @@ func TestPatcherStorageFunctions(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
p := newPatcher()
|
p := newPatcher(ctrl.Log.WithName("test"))
|
||||||
|
|
||||||
p.addAf(af)
|
if err := p.AddAf(goodAf); err != nil {
|
||||||
|
t.Error("unexpected error")
|
||||||
|
}
|
||||||
if len(p.resourceModeMap) != 1 || len(p.afMap) != 1 || len(p.resourceMap) != 1 {
|
if len(p.resourceModeMap) != 1 || len(p.afMap) != 1 || len(p.resourceMap) != 1 {
|
||||||
t.Error("Failed to add AF to patcher")
|
t.Error("Failed to add AF to patcher")
|
||||||
}
|
}
|
||||||
|
if err := p.AddAf(brokenAf); err == nil {
|
||||||
|
t.Error("AddAf() must fail")
|
||||||
|
}
|
||||||
|
|
||||||
p.removeAf(af.Name)
|
p.RemoveAf(goodAf.Name)
|
||||||
if len(p.resourceModeMap) != 0 || len(p.afMap) != 0 || len(p.resourceMap) != 0 {
|
if len(p.resourceModeMap) != 0 || len(p.afMap) != 0 || len(p.resourceMap) != 0 {
|
||||||
t.Error("Failed to remove AF from patcher")
|
t.Error("Failed to remove AF from patcher")
|
||||||
}
|
}
|
||||||
|
|
||||||
p.addRegion(region)
|
p.AddRegion(region)
|
||||||
if len(p.resourceModeMap) != 1 || len(p.resourceMap) != 1 {
|
if len(p.resourceModeMap) != 1 || len(p.resourceMap) != 1 {
|
||||||
t.Error("Failed to add fpga region to patcher")
|
t.Error("Failed to add fpga region to patcher")
|
||||||
}
|
}
|
||||||
|
|
||||||
p.removeRegion(region.Name)
|
p.RemoveRegion(region.Name)
|
||||||
if len(p.resourceModeMap) != 0 || len(p.resourceMap) != 0 {
|
if len(p.resourceModeMap) != 0 || len(p.resourceMap) != 0 {
|
||||||
t.Error("Failed to remove fpga region from patcher")
|
t.Error("Failed to remove fpga region from patcher")
|
||||||
}
|
}
|
||||||
@ -314,12 +330,12 @@ func TestGetPatchOps(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tcases {
|
for _, tt := range tcases {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
p := newPatcher()
|
p := newPatcher(ctrl.Log.WithName("test"))
|
||||||
for _, af := range tt.afs {
|
for _, af := range tt.afs {
|
||||||
p.addAf(af)
|
_ = p.AddAf(af)
|
||||||
}
|
}
|
||||||
for _, region := range tt.regions {
|
for _, region := range tt.regions {
|
||||||
p.addRegion(region)
|
p.AddRegion(region)
|
||||||
}
|
}
|
||||||
ops, err := p.getPatchOps(0, tt.container)
|
ops, err := p.getPatchOps(0, tt.container)
|
||||||
if tt.expectedErr && err == nil {
|
if tt.expectedErr && err == nil {
|
||||||
@ -334,28 +350,3 @@ func TestGetPatchOps(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetPatcher(t *testing.T) {
|
|
||||||
namespace := "test"
|
|
||||||
tcases := []struct {
|
|
||||||
name string
|
|
||||||
pm patcherManager
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "Create new patcher",
|
|
||||||
pm: newPatcherManager(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Return existing patcher",
|
|
||||||
pm: map[string]*patcher{namespace: newPatcher()},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tcases {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
p := tt.pm.getPatcher(namespace)
|
|
||||||
if p != tt.pm[namespace] {
|
|
||||||
t.Error("stored and received patchers are not equal")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
135
pkg/fpgacontroller/patcher/patchermanager.go
Normal file
135
pkg/fpgacontroller/patcher/patchermanager.go
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// 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 patcher
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-logr/logr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
admissionv1beta1 "k8s.io/api/admission/v1beta1"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
scheme = runtime.NewScheme()
|
||||||
|
codecs = serializer.NewCodecFactory(scheme)
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
_ = corev1.AddToScheme(scheme)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PatcherManager keeps track of patchers registered for different Kubernetes namespaces.
|
||||||
|
type PatcherManager struct {
|
||||||
|
log logr.Logger
|
||||||
|
patchers map[string]*patcher
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPatcherManager creates a new PatcherManager.
|
||||||
|
func NewPatcherManager(log logr.Logger) *PatcherManager {
|
||||||
|
return &PatcherManager{
|
||||||
|
log: log,
|
||||||
|
patchers: make(map[string]*patcher),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPatcher returns a patcher specific to given namespace.
|
||||||
|
func (pm *PatcherManager) GetPatcher(namespace string) *patcher {
|
||||||
|
if p, ok := pm.patchers[namespace]; ok {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
p := newPatcher(pm.log.WithValues("namespace", namespace))
|
||||||
|
pm.patchers[namespace] = p
|
||||||
|
pm.log.V(1).Info("created new patcher", "namespace", namespace)
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPodMutator returns a handler function replacing FPGA resource names with
|
||||||
|
// real FPGA resources in pods.
|
||||||
|
func (pm *PatcherManager) GetPodMutator() func(ctx context.Context, req webhook.AdmissionRequest) webhook.AdmissionResponse {
|
||||||
|
return pm.mutate
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:webhook:verbs=create;update,path=/pods,mutating=true,failurePolicy=Ignore,groups="",resources=pods,versions=v1,name=fpga.mutator.webhooks.intel.com
|
||||||
|
|
||||||
|
func (pm *PatcherManager) mutate(ctx context.Context, req webhook.AdmissionRequest) webhook.AdmissionResponse {
|
||||||
|
podResource := metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
|
||||||
|
if req.Resource != podResource {
|
||||||
|
err := errors.Errorf("unexpected resource type %q", req.Resource)
|
||||||
|
pm.log.Error(err, "unable to mutate")
|
||||||
|
return toAdmissionResponse(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
raw := req.Object.Raw
|
||||||
|
pod := corev1.Pod{}
|
||||||
|
deserializer := codecs.UniversalDeserializer()
|
||||||
|
if _, _, err := deserializer.Decode(raw, nil, &pod); err != nil {
|
||||||
|
pm.log.Error(err, "unable to decode")
|
||||||
|
return toAdmissionResponse(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace := pod.Namespace
|
||||||
|
if namespace == "" && req.Namespace != "" {
|
||||||
|
namespace = req.Namespace
|
||||||
|
}
|
||||||
|
name := pod.Name
|
||||||
|
if name == "" && pod.ObjectMeta.GenerateName != "" {
|
||||||
|
name = pod.ObjectMeta.GenerateName
|
||||||
|
}
|
||||||
|
pm.log.V(1).Info("Received pod", "Pod", name, "Namespace", namespace)
|
||||||
|
patcher := pm.GetPatcher(namespace)
|
||||||
|
|
||||||
|
reviewResponse := admissionv1beta1.AdmissionResponse{
|
||||||
|
Allowed: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
var ops []string
|
||||||
|
for containerIdx, container := range pod.Spec.Containers {
|
||||||
|
patchOps, err := patcher.getPatchOps(containerIdx, container)
|
||||||
|
if err != nil {
|
||||||
|
return toAdmissionResponse(err)
|
||||||
|
}
|
||||||
|
ops = append(ops, patchOps...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ops) > 0 {
|
||||||
|
reviewResponse.Patch = []byte("[ " + strings.Join(ops, ",") + " ]")
|
||||||
|
pt := admissionv1beta1.PatchTypeJSONPatch
|
||||||
|
reviewResponse.PatchType = &pt
|
||||||
|
}
|
||||||
|
return webhook.AdmissionResponse{
|
||||||
|
AdmissionResponse: reviewResponse,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func toAdmissionResponse(err error) webhook.AdmissionResponse {
|
||||||
|
return webhook.AdmissionResponse{
|
||||||
|
AdmissionResponse: admissionv1beta1.AdmissionResponse{
|
||||||
|
Result: &metav1.Status{
|
||||||
|
Message: err.Error(),
|
||||||
|
},
|
||||||
|
Allowed: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
199
pkg/fpgacontroller/patcher/patchermanager_test.go
Normal file
199
pkg/fpgacontroller/patcher/patchermanager_test.go
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
// Copyright 2020 Intel Corporation. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// 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 patcher
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/api/admission/v1beta1"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/klog/klogr"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||||
|
|
||||||
|
fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ctrl.SetLogger(klogr.New())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetPatcher(t *testing.T) {
|
||||||
|
log := ctrl.Log.WithName("test")
|
||||||
|
namespace := "test"
|
||||||
|
tcases := []struct {
|
||||||
|
name string
|
||||||
|
pm *PatcherManager
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Create new patcher",
|
||||||
|
pm: NewPatcherManager(log),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Return existing patcher",
|
||||||
|
pm: &PatcherManager{patchers: map[string]*patcher{namespace: newPatcher(log)}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tcases {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
p := tt.pm.GetPatcher(namespace)
|
||||||
|
if p != tt.pm.patchers[namespace] {
|
||||||
|
t.Error("stored and received patchers are not equal")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMutate(t *testing.T) {
|
||||||
|
pod := corev1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "default",
|
||||||
|
GenerateName: "goodpod",
|
||||||
|
},
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
Containers: []corev1.Container{
|
||||||
|
{
|
||||||
|
Name: "test-container",
|
||||||
|
Image: "test-image",
|
||||||
|
Resources: corev1.ResourceRequirements{
|
||||||
|
Limits: corev1.ResourceList{
|
||||||
|
"cpu": resource.MustParse("1"),
|
||||||
|
"fpga.intel.com/arria10": resource.MustParse("1"),
|
||||||
|
},
|
||||||
|
Requests: corev1.ResourceList{
|
||||||
|
"cpu": resource.MustParse("1"),
|
||||||
|
"fpga.intel.com/arria10": resource.MustParse("1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
brokenPod := corev1.Pod{
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
Containers: []corev1.Container{
|
||||||
|
{
|
||||||
|
Name: "test-container",
|
||||||
|
Image: "test-image",
|
||||||
|
Resources: corev1.ResourceRequirements{
|
||||||
|
Limits: corev1.ResourceList{
|
||||||
|
"cpu": resource.MustParse("1"),
|
||||||
|
"fpga.intel.com/arria10": resource.MustParse("1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
podRaw, err := json.Marshal(pod)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
brokenPodRaw, err := json.Marshal(brokenPod)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tcases := []struct {
|
||||||
|
name string
|
||||||
|
ar v1beta1.AdmissionRequest
|
||||||
|
expectedAllowed bool
|
||||||
|
expectedPatchOps int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty admission request",
|
||||||
|
ar: v1beta1.AdmissionRequest{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "admission request without object",
|
||||||
|
ar: v1beta1.AdmissionRequest{
|
||||||
|
Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
|
||||||
|
},
|
||||||
|
expectedAllowed: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "admission request with corrupted object",
|
||||||
|
ar: v1beta1.AdmissionRequest{
|
||||||
|
Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
|
||||||
|
Object: runtime.RawExtension{
|
||||||
|
Raw: []byte(`{"corrupted json":}`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "successful non-empty admission request",
|
||||||
|
ar: v1beta1.AdmissionRequest{
|
||||||
|
Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
|
||||||
|
Object: runtime.RawExtension{
|
||||||
|
Raw: podRaw,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedPatchOps: 4,
|
||||||
|
expectedAllowed: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "handle error after wrong getPatchOps()",
|
||||||
|
ar: v1beta1.AdmissionRequest{
|
||||||
|
Namespace: "test",
|
||||||
|
Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
|
||||||
|
Object: runtime.RawExtension{
|
||||||
|
Raw: brokenPodRaw,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tcase := range tcases {
|
||||||
|
t.Run(tcase.name, func(t *testing.T) {
|
||||||
|
log := ctrl.Log.WithName("test")
|
||||||
|
p := newPatcher(log)
|
||||||
|
p.AddRegion(&fpgav2.FpgaRegion{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "arria10",
|
||||||
|
},
|
||||||
|
Spec: fpgav2.FpgaRegionSpec{
|
||||||
|
InterfaceID: "ce48969398f05f33946d560708be108a",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
pm := NewPatcherManager(log)
|
||||||
|
pm.patchers["default"] = p
|
||||||
|
resp := pm.GetPodMutator()(context.TODO(), webhook.AdmissionRequest{AdmissionRequest: tcase.ar})
|
||||||
|
|
||||||
|
actualPatchOps := 0
|
||||||
|
if tcase.expectedAllowed != resp.Allowed {
|
||||||
|
t.Errorf("Allowed expected to be %t but got %t", tcase.expectedAllowed, resp.Allowed)
|
||||||
|
} else if resp.Allowed && resp.Patch != nil {
|
||||||
|
var ops interface{}
|
||||||
|
|
||||||
|
err := json.Unmarshal(resp.Patch, &ops)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Test case '%s': got unparsable patch '%s'", tcase.name, resp.Patch)
|
||||||
|
} else {
|
||||||
|
actualPatchOps = len(ops.([]interface{}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if actualPatchOps != tcase.expectedPatchOps {
|
||||||
|
t.Errorf("Test case '%s': got wrong number of operations in the patch. Expected %d, but got %d\n%s",
|
||||||
|
tcase.name, tcase.expectedPatchOps, actualPatchOps, string(resp.Patch))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -1,33 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Copyright 2018 Intel Corporation. All Rights Reserved.
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
|
|
||||||
CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
|
|
||||||
PKG_PATH="github.com/intel/intel-device-plugins-for-kubernetes/pkg"
|
|
||||||
|
|
||||||
# generate the code with:
|
|
||||||
# --output-base because this script should also be able to run inside the vendor dir of
|
|
||||||
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
|
|
||||||
# instead of the $GOPATH directly. For normal projects this can be dropped.
|
|
||||||
${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
|
|
||||||
${PKG_PATH}/client ${PKG_PATH}/apis \
|
|
||||||
fpga.intel.com:v2 \
|
|
||||||
--output-base "$(dirname ${BASH_SOURCE})/../../../.." \
|
|
||||||
--go-header-file ${SCRIPT_ROOT}/build/boilerplate/boilerplate.go.txt
|
|
@ -41,22 +41,31 @@ func describe() {
|
|||||||
f := framework.NewDefaultFramework("webhook")
|
f := framework.NewDefaultFramework("webhook")
|
||||||
|
|
||||||
ginkgo.It("mutates created pods to reference resolved AFs", func() {
|
ginkgo.It("mutates created pods to reference resolved AFs", func() {
|
||||||
checkPodMutation(f, "fpga.intel.com/d5005-nlb3-preprogrammed",
|
checkPodMutation(f, f.Namespace.Name, "fpga.intel.com/d5005-nlb3-preprogrammed",
|
||||||
"fpga.intel.com/af-bfa.f7d.v6xNhR7oVv6MlYZc4buqLfffQFy9es9yIvFEsLk6zRg")
|
"fpga.intel.com/af-bfa.f7d.v6xNhR7oVv6MlYZc4buqLfffQFy9es9yIvFEsLk6zRg")
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It("mutates created pods to reference resolved Regions", func() {
|
ginkgo.It("mutates created pods to reference resolved Regions", func() {
|
||||||
checkPodMutation(f, "fpga.intel.com/arria10.dcp1.0-nlb0-orchestrated",
|
checkPodMutation(f, f.Namespace.Name, "fpga.intel.com/arria10.dcp1.0-nlb0-orchestrated",
|
||||||
"fpga.intel.com/region-ce48969398f05f33946d560708be108a")
|
"fpga.intel.com/region-ce48969398f05f33946d560708be108a")
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It("mutates created pods to reference resolved Regions in regiondevel mode", func() {
|
ginkgo.It("mutates created pods to reference resolved Regions in regiondevel mode", func() {
|
||||||
checkPodMutation(f, "fpga.intel.com/arria10.dcp1.0",
|
checkPodMutation(f, f.Namespace.Name, "fpga.intel.com/arria10.dcp1.0",
|
||||||
"fpga.intel.com/region-ce48969398f05f33946d560708be108a")
|
"fpga.intel.com/region-ce48969398f05f33946d560708be108a")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ginkgo.It("doesn't mutate a pod if it's created in a namespace different from mappings'", func() {
|
||||||
|
ginkgo.By("create another namespace for mappings")
|
||||||
|
ns, err := f.CreateNamespace("mappings", nil)
|
||||||
|
framework.ExpectNoError(err, "unable to create a namespace")
|
||||||
|
|
||||||
|
checkPodMutation(f, ns.Name, "fpga.intel.com/arria10.dcp1.0-nlb0-orchestrated",
|
||||||
|
"fpga.intel.com/arria10.dcp1.0-nlb0-orchestrated")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkPodMutation(f *framework.Framework, source, expectedMutation v1.ResourceName) {
|
func checkPodMutation(f *framework.Framework, mappingsNamespace string, source, expectedMutation v1.ResourceName) {
|
||||||
kustomizationPath, err := utils.LocateRepoFile(kustomizationYaml)
|
kustomizationPath, err := utils.LocateRepoFile(kustomizationYaml)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
framework.Failf("unable to locate %q: %v", kustomizationYaml, err)
|
framework.Failf("unable to locate %q: %v", kustomizationYaml, err)
|
||||||
@ -66,7 +75,7 @@ func checkPodMutation(f *framework.Framework, source, expectedMutation v1.Resour
|
|||||||
utils.DeployFpgaWebhook(f, kustomizationPath)
|
utils.DeployFpgaWebhook(f, kustomizationPath)
|
||||||
|
|
||||||
ginkgo.By("deploying mappings")
|
ginkgo.By("deploying mappings")
|
||||||
framework.RunKubectlOrDie(f.Namespace.Name, "apply", "-n", f.Namespace.Name, "-f", filepath.Dir(kustomizationPath)+"/../mappings-collection.yaml")
|
framework.RunKubectlOrDie(f.Namespace.Name, "apply", "-n", mappingsNamespace, "-f", filepath.Dir(kustomizationPath)+"/../mappings-collection.yaml")
|
||||||
|
|
||||||
ginkgo.By("submitting a pod for admission")
|
ginkgo.By("submitting a pod for admission")
|
||||||
podSpec := f.NewTestPod("webhook-tester",
|
podSpec := f.NewTestPod("webhook-tester",
|
||||||
@ -74,6 +83,12 @@ func checkPodMutation(f *framework.Framework, source, expectedMutation v1.Resour
|
|||||||
v1.ResourceList{source: resource.MustParse("1")})
|
v1.ResourceList{source: resource.MustParse("1")})
|
||||||
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(),
|
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(),
|
||||||
podSpec, metav1.CreateOptions{})
|
podSpec, metav1.CreateOptions{})
|
||||||
|
|
||||||
|
if source.String() == expectedMutation.String() {
|
||||||
|
framework.ExpectError(err, "pod mistakenly got accepted")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
framework.ExpectNoError(err, "pod Create API error")
|
framework.ExpectNoError(err, "pod Create API error")
|
||||||
|
|
||||||
ginkgo.By("checking the pod has been mutated")
|
ginkgo.By("checking the pod has been mutated")
|
||||||
|
Loading…
Reference in New Issue
Block a user