From 6c2eacfae54b02e142c30d6321028a4cc9a7f2d3 Mon Sep 17 00:00:00 2001 From: Dmitry Rozhkov Date: Thu, 2 Apr 2020 12:23:57 +0300 Subject: [PATCH 1/4] webhook: remove mode of operation fpga: make AFU resource name 63 char long webhook: drop mode from README webhook: extend mappings description webhook: tighten CRD definitions webhook: drop mapping to non-existing afuId explicitly state mappings names can be in any format use consistent terminology across fpga webhook and plugin --- cmd/fpga_admissionwebhook/README.md | 55 +-- cmd/fpga_admissionwebhook/controller.go | 16 +- cmd/fpga_admissionwebhook/controller_test.go | 50 +-- .../fpga_admissionwebhook.go | 24 +- .../fpga_admissionwebhook_test.go | 116 +++--- cmd/fpga_admissionwebhook/patcher.go | 306 ++++++-------- cmd/fpga_admissionwebhook/patcher_test.go | 374 ++++++++---------- cmd/fpga_plugin/README.md | 42 +- cmd/fpga_plugin/dfl_test.go | 14 +- cmd/fpga_plugin/fpga_plugin.go | 7 +- cmd/fpga_plugin/opae_test.go | 6 +- .../{FPGA-preprogrammed.png => FPGA-af.png} | Bin ...{FPGA-orchestrated.png => FPGA-region.png} | Bin deployments/fpga_admissionwebhook/af-crd.yaml | 8 +- .../base/acceleratorfunctions.yaml | 7 - .../fpga_admissionwebhook/deployment-tpl.yaml | 1 - .../mappings-collection.yaml | 32 +- .../fpga_admissionwebhook/region-crd.yaml | 2 +- pkg/apis/fpga.intel.com/v1/types.go | 4 +- scripts/webhook-deploy.sh | 13 +- .../fpgaadmissionwebhook.go | 32 +- 21 files changed, 494 insertions(+), 615 deletions(-) rename cmd/fpga_plugin/pictures/{FPGA-preprogrammed.png => FPGA-af.png} (100%) rename cmd/fpga_plugin/pictures/{FPGA-orchestrated.png => FPGA-region.png} (100%) diff --git a/cmd/fpga_admissionwebhook/README.md b/cmd/fpga_admissionwebhook/README.md index b5edafe33..d234a0746 100644 --- a/cmd/fpga_admissionwebhook/README.md +++ b/cmd/fpga_admissionwebhook/README.md @@ -30,16 +30,6 @@ The admission controller also keeps the user from bypassing namespaced mapping r by denying admission of any pods that are trying to use internal knowledge of InterfaceID or Bitstream ID environment variables used by the prestart hook. -The admission controller can operate in two separate modes - preprogrammed or orchestration programmed. -The mode must be chosen to match that of the [FPGA plugin](../fpga_plugin/README.md) configuraton, as -shown in the following table: - -| FPGA plugin mode | matching admission controller mode | -|:---------------- |:---------------------------------- | -| region | orchestrated | -| af | preprogrammed | - - # Dependencies This component is one of a set of components that work together. You may also want to @@ -118,14 +108,6 @@ Register webhook mutatingwebhookconfiguration.admissionregistration.k8s.io/fpga-mutator-webhook-cfg created ``` -By default, the script deploys the webhook in a preprogrammed mode. - -Use the option `--mode` script option to deploy the webhook in orchestrated mode: - -```bash -$ ./scripts/webhook-deploy.sh --mode orchestrated -``` - The script needs the CA bundle used for signing certificate requests in your cluster. By default, the script fetches the bundle stored in the configmap `extension-apiserver-authentication`. However, your cluster may use a different signing @@ -138,13 +120,38 @@ $ ./scripts/webhook-deploy.sh --ca-bundle-path /var/run/kubernetes/server-ca.crt # Mappings -Requested FPGA resources are translated to AF resources. For example, -`fpga.intel.com/arria10.dcp1.1-nlb0` is translated to `fpga.intel.com/af-d8424dc4a4a3c413f89e433683f9040b`. +Mappings is a an essential part of the setup that gives a flexible instrument to a cluster +administrator to manage FPGA bitstreams and to control access to them. Being a set of +custom resource definitions they are used to configure the way FPGA resource requests get +translated into actual resources provided by the cluster. + +For the following mapping + +```yaml +apiVersion: fpga.intel.com/v1 +kind: AcceleratorFunction +metadata: + name: arria10.dcp1.1-nlb0 +spec: + afuId: d8424dc4a4a3c413f89e433683f9040b + interfaceId: 9926ab6d6c925a68aabca7d84c545738 + mode: af +``` -In orchestrated mode, `fpga.intel.com/arria10.dcp1.1-nlb0` gets translated to -`fpga.intel.com/region-9926ab6d6c925a68aabca7d84c545738`, and, the corresponding AF IDs are set in -environment variables for the container. The [FPGA CRI-O hook](../fpga_crihook/README.md) -then loads the requested bitstream to a region before the container is started. +requested FPGA resources are translated to AF resources. For example, +`fpga.intel.com/arria10.dcp1.1-nlb0` is translated to +`fpga.intel.com/9926ab6d6c925a68aabca7d84c54573d8424dc4a4a3c413f89e433683f9040b`. +The first 31 characters of the resource name part (`9926ab6d6c925a68aabca7d84c54573`) +is the first 31 characters of the region interface ID for Arria10 with DCP1.1 +firmware. The next 32 characters (`d8424dc4a4a3c413f89e433683f9040b`) is an accelerator function ID. +The format of resource names (e.g. `arria10.dcp1.1-nlb0`) can be any and is up +to a cluster administrator. + +The same mapping, but with its mode field set to `region`, translates +`fpga.intel.com/arria10.dcp1.1-nlb0` to `fpga.intel.com/region-9926ab6d6c925a68aabca7d84c545738`, +and the corresponding AF IDs are set in environment variables for the container. +The [FPGA CRI-O hook](../fpga_crihook/README.md) then loads the requested bitstream to a region +before the container is started. Mappings of resource names are configured with objects of `AcceleratorFunction` and `FpgaRegion` custom resource definitions found respectively in diff --git a/cmd/fpga_admissionwebhook/controller.go b/cmd/fpga_admissionwebhook/controller.go index bd17f81c5..0592e3164 100644 --- a/cmd/fpga_admissionwebhook/controller.go +++ b/cmd/fpga_admissionwebhook/controller.go @@ -42,7 +42,7 @@ type fpgaObjectKey struct { } type controller struct { - patcherManager *patcherManager + patcherManager patcherManager informerFactory informers.SharedInformerFactory afsSynced cache.InformerSynced regionsSynced cache.InformerSynced @@ -52,7 +52,7 @@ type controller struct { stopCh chan struct{} } -func newController(patcherManager *patcherManager, config *rest.Config) (*controller, error) { +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") @@ -172,11 +172,7 @@ func (c *controller) syncAfHandler(key string) error { return nil } - patcher, err := c.patcherManager.getPatcher(namespace) - if err != nil { - runtime.HandleError(errors.Wrapf(err, "can't get patcher for namespace %s", namespace)) - return nil - } + patcher := c.patcherManager.getPatcher(namespace) // Get the AcceleratorFunction resource with this namespace/name af, err := c.afLister.AcceleratorFunctions(namespace).Get(name) @@ -206,11 +202,7 @@ func (c *controller) syncRegionHandler(key string) error { return nil } - patcher, err := c.patcherManager.getPatcher(namespace) - if err != nil { - runtime.HandleError(errors.Wrapf(err, "can't get patcher for namespace %s", namespace)) - return nil - } + patcher := c.patcherManager.getPatcher(namespace) // Get the FpgaRegion resource with this namespace/name region, err := c.regionLister.FpgaRegions(namespace).Get(name) diff --git a/cmd/fpga_admissionwebhook/controller_test.go b/cmd/fpga_admissionwebhook/controller_test.go index ef2184b26..0c44afd58 100644 --- a/cmd/fpga_admissionwebhook/controller_test.go +++ b/cmd/fpga_admissionwebhook/controller_test.go @@ -63,11 +63,10 @@ func (l *fakeAfLister) List(selector labels.Selector) (ret []*v1.AcceleratorFunc func TestSyncAfHandler(t *testing.T) { tcases := []struct { - name string - key string - afLister *fakeAfLister - patcherManagerIsBroken bool - expectedErr bool + name string + key string + afLister *fakeAfLister + expectedErr bool }{ { name: "Wrong key format", @@ -87,11 +86,6 @@ func TestSyncAfHandler(t *testing.T) { }, }, }, - { - name: "Broken patcher manager", - key: "default/arria10-nlb0", - patcherManagerIsBroken: true, - }, { name: "Unknown key", key: "default/unknown", @@ -107,13 +101,7 @@ func TestSyncAfHandler(t *testing.T) { } for _, tt := range tcases { - pm, err := newPatcherManager(preprogrammed) - if err != nil { - t.Fatalf("Test case '%s': %+v", tt.name, err) - } - if tt.patcherManagerIsBroken { - pm.defaultMode = "broken" - } + pm := newPatcherManager() c, err := newController(pm, &rest.Config{}) if err != nil { t.Fatalf("Test case '%s': %+v", tt.name, err) @@ -162,11 +150,10 @@ func (l *fakeRegionLister) List(selector labels.Selector) (ret []*v1.FpgaRegion, func TestSyncRegionHandler(t *testing.T) { tcases := []struct { - name string - key string - patcherManagerIsBroken bool - regionLister *fakeRegionLister - expectedErr bool + name string + key string + regionLister *fakeRegionLister + expectedErr bool }{ { name: "Wrong key format", @@ -186,11 +173,6 @@ func TestSyncRegionHandler(t *testing.T) { }, }, }, - { - name: "Broken patcher manager", - key: "default/arria10", - patcherManagerIsBroken: true, - }, { name: "Unknown key", key: "default/unknown", @@ -206,13 +188,7 @@ func TestSyncRegionHandler(t *testing.T) { } for _, tt := range tcases { - pm, err := newPatcherManager(preprogrammed) - if err != nil { - t.Fatalf("Test case '%s': %+v", tt.name, err) - } - if tt.patcherManagerIsBroken { - pm.defaultMode = "broken" - } + pm := newPatcherManager() c, err := newController(pm, &rest.Config{}) if err != nil { t.Fatalf("Test case '%s': %+v", tt.name, err) @@ -328,7 +304,7 @@ func TestProcessNextWorkItem(t *testing.T) { }, } for _, tt := range tcases { - pm, _ := newPatcherManager(preprogrammed) + pm := newPatcherManager() c, err := newController(pm, &rest.Config{}) if err != nil { t.Fatalf("Test case '%s': %+v", tt.name, err) @@ -369,7 +345,7 @@ func TestRun(t *testing.T) { } for _, tt := range tcases { - pm := &patcherManager{} + pm := newPatcherManager() c, err := newController(pm, &rest.Config{}) if err != nil { t.Fatalf("Test case '%s': %+v", tt.name, err) @@ -404,7 +380,7 @@ func TestNewController(t *testing.T) { config := &rest.Config{ Host: tt.configHost, } - pm := &patcherManager{} + pm := newPatcherManager() c, err := newController(pm, config) if err != nil && !tt.expectedErr { t.Errorf("Test case '%s': unexpected error: %+v", tt.name, err) diff --git a/cmd/fpga_admissionwebhook/fpga_admissionwebhook.go b/cmd/fpga_admissionwebhook/fpga_admissionwebhook.go index 295e5ec2a..3c7f22ac3 100644 --- a/cmd/fpga_admissionwebhook/fpga_admissionwebhook.go +++ b/cmd/fpga_admissionwebhook/fpga_admissionwebhook.go @@ -18,7 +18,6 @@ import ( "crypto/tls" "encoding/json" "flag" - "fmt" "io/ioutil" "net/http" "os" @@ -39,8 +38,6 @@ import ( ) const ( - preprogrammed = "preprogrammed" - orchestrated = "orchestrated" controllerThreadNum = 1 ) @@ -69,7 +66,7 @@ func getTLSConfig(certFile string, keyFile string) *tls.Config { } } -func mutatePods(ar v1beta1.AdmissionReview, pm *patcherManager) *v1beta1.AdmissionResponse { +func mutatePods(ar v1beta1.AdmissionReview, pm patcherManager) *v1beta1.AdmissionResponse { var ops []string klog.V(4).Info("mutating pods") @@ -97,11 +94,7 @@ func mutatePods(ar v1beta1.AdmissionReview, pm *patcherManager) *v1beta1.Admissi name = pod.ObjectMeta.GenerateName } klog.V(4).Infof("Received pod '%s' in name space '%s'", name, namespace) - patcher, err := pm.getPatcher(namespace) - if err != nil { - klog.Warningf("%+v", err) - return toAdmissionResponse(err) - } + patcher := pm.getPatcher(namespace) reviewResponse := v1beta1.AdmissionResponse{} reviewResponse.Allowed = true @@ -198,7 +191,7 @@ func serve(w http.ResponseWriter, r *http.Request, admit admitFunc) { } } -func makePodsHandler(pm *patcherManager) func(w http.ResponseWriter, r *http.Request) { +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) @@ -211,7 +204,6 @@ func main() { var master string var certFile string var keyFile string - var mode string var config *rest.Config var err error @@ -220,7 +212,6 @@ func main() { 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.StringVar(&mode, "mode", preprogrammed, fmt.Sprintf("webhook mode: '%s' (default) or '%s'", preprogrammed, orchestrated)) flag.Parse() if certFile == "" { @@ -248,18 +239,15 @@ func main() { klog.Fatal("Failed to get cluster config ", err) } - patcherManager, err := newPatcherManager(mode) - if err != nil { - klog.Fatalf("%+v", err) - } + pm := newPatcherManager() - controller, err := newController(patcherManager, config) + controller, err := newController(pm, config) if err != nil { klog.Fatalf("%+v", err) } go controller.run(controllerThreadNum) - http.HandleFunc("/pods", makePodsHandler(patcherManager)) + http.HandleFunc("/pods", makePodsHandler(pm)) klog.V(4).Info("Webhook started") diff --git a/cmd/fpga_admissionwebhook/fpga_admissionwebhook_test.go b/cmd/fpga_admissionwebhook/fpga_admissionwebhook_test.go index f7d030519..5a4b3d301 100644 --- a/cmd/fpga_admissionwebhook/fpga_admissionwebhook_test.go +++ b/cmd/fpga_admissionwebhook/fpga_admissionwebhook_test.go @@ -24,6 +24,7 @@ import ( "strings" "testing" + fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" "k8s.io/api/admission/v1beta1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -144,16 +145,39 @@ func TestMutatePods(t *testing.T) { }, }, } + 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 - mode string ar v1beta1.AdmissionReview expectedResponse bool + expectedAllowed bool expectedPatchOps int }{ { @@ -161,7 +185,6 @@ func TestMutatePods(t *testing.T) { ar: v1beta1.AdmissionReview{ Request: &v1beta1.AdmissionRequest{}, }, - mode: preprogrammed, }, { name: "admission request without object", @@ -170,8 +193,8 @@ func TestMutatePods(t *testing.T) { Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}, }, }, - mode: preprogrammed, expectedResponse: true, + expectedAllowed: true, }, { name: "admission request with corrupted object", @@ -183,11 +206,10 @@ func TestMutatePods(t *testing.T) { }, }, }, - mode: preprogrammed, expectedResponse: true, }, { - name: "non-empty admission request in preprogrammed mode", + name: "successful non-empty admission request", ar: v1beta1.AdmissionReview{ Request: &v1beta1.AdmissionRequest{ Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}, @@ -196,23 +218,9 @@ func TestMutatePods(t *testing.T) { }, }, }, - mode: preprogrammed, expectedResponse: true, expectedPatchOps: 4, - }, - { - name: "non-empty admission request in orchestrated mode", - ar: v1beta1.AdmissionReview{ - Request: &v1beta1.AdmissionRequest{ - Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}, - Object: runtime.RawExtension{ - Raw: podRaw, - }, - }, - }, - mode: orchestrated, - expectedResponse: true, - expectedPatchOps: 5, + expectedAllowed: true, }, { name: "handle error after wrong getPatchOps()", @@ -220,48 +228,54 @@ func TestMutatePods(t *testing.T) { Request: &v1beta1.AdmissionRequest{ Resource: metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}, Object: runtime.RawExtension{ - Raw: podRaw, + Raw: brokenPodRaw, }, }, }, - mode: "unknown mode", expectedResponse: true, }, } for _, tcase := range tcases { - p := &patcher{ - mode: tcase.mode, - regionMap: map[string]string{ - "arria10": "ce48969398f05f33946d560708be108a", - }, - resourceMap: map[string]string{ - "fpga.intel.com/arria10": "ce48969398f05f33946d560708be108a", - }, - } - pm := &patcherManager{ - defaultMode: tcase.mode, - patchers: map[string]*patcher{ - "default": p, - }, - } - resp := mutatePods(tcase.ar, pm) + t.Run(tcase.name, func(t *testing.T) { + p := newPatcher() + p.addRegion(&fpgav1.FpgaRegion{ + ObjectMeta: metav1.ObjectMeta{ + Name: "arria10", + }, + Spec: fpgav1.FpgaRegionSpec{ + InterfaceID: "ce48969398f05f33946d560708be108a", + }, + }) + pm := newPatcherManager() + pm["default"] = p + resp := mutatePods(tcase.ar, pm) - 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 && tcase.expectedPatchOps > 0 { - var ops interface{} + 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 if len(ops.([]interface{})) != tcase.expectedPatchOps { + 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, len(ops.([]interface{})), string(resp.Patch)) + tcase.name, tcase.expectedPatchOps, actualPatchOps, string(resp.Patch)) } - } + }) } } @@ -280,6 +294,6 @@ func (*fakeResponseWriter) WriteHeader(int) { } func TestMakePodsHandler(t *testing.T) { - serveFunc := makePodsHandler(&patcherManager{}) + serveFunc := makePodsHandler(newPatcherManager()) serveFunc(&fakeResponseWriter{}, &http.Request{}) } diff --git a/cmd/fpga_admissionwebhook/patcher.go b/cmd/fpga_admissionwebhook/patcher.go index c2ddcae5d..582601898 100644 --- a/cmd/fpga_admissionwebhook/patcher.go +++ b/cmd/fpga_admissionwebhook/patcher.go @@ -17,7 +17,6 @@ package main import ( "bytes" "fmt" - "regexp" "strings" "sync" "text/template" @@ -33,14 +32,12 @@ import ( const ( namespace = "fpga.intel.com" - resourceReplaceOp = `{ - "op": "remove", - "path": "/spec/containers/%d/resources/%s/%s" - }, { - "op": "add", - "path": "/spec/containers/%d/resources/%s/%s", - "value": %s - }` + af = "af" + region = "region" + // "regiondevel" corresponds to the FPGA plugin's regiondevel mode. It requires + // FpgaRegion CRDs to be added to the cluster. + regiondevel = "regiondevel" + resourceRemoveOp = `{ "op": "remove", "path": "/spec/containers/%d/resources/%s/%s" @@ -64,48 +61,52 @@ const ( {{- end -}} ] }` + + // Names of extended resources cannot be longer than 63 characters. + // Therefore for AF resources we have to cut the interface ID prefix + // to 31 characters only. + interfaceIDPrefixLength = 31 ) var ( rfc6901Escaper = strings.NewReplacer("~", "~0", "/", "~1") - resourceRe = regexp.MustCompile(namespace + `/(?P[[:alnum:].]+)(-(?P[[:alnum:]]+))?`) ) type patcher struct { sync.Mutex - mode string - regionMap map[string]string - afMap map[string]string - resourceMap map[string]string + afMap map[string]*fpgav1.AcceleratorFunction + resourceMap map[string]string + resourceModeMap map[string]string } -func newPatcher(mode string) (*patcher, error) { - if mode != preprogrammed && mode != orchestrated { - return nil, errors.Errorf("Unknown mode: %s", mode) - } - +func newPatcher() *patcher { return &patcher{ - mode: mode, - regionMap: make(map[string]string), - afMap: make(map[string]string), - resourceMap: make(map[string]string), - }, nil + afMap: make(map[string]*fpgav1.AcceleratorFunction), + resourceMap: make(map[string]string), + resourceModeMap: make(map[string]string), + } } -func (p *patcher) addAf(af *fpgav1.AcceleratorFunction) { +func (p *patcher) addAf(accfunc *fpgav1.AcceleratorFunction) { defer p.Unlock() p.Lock() - p.afMap[af.Name] = af.Spec.AfuID - p.resourceMap[namespace+"/"+af.Name] = rfc6901Escaper.Replace(namespace + "/af-" + af.Spec.AfuID) + p.afMap[namespace+"/"+accfunc.Name] = accfunc + if accfunc.Spec.Mode == af { + p.resourceMap[namespace+"/"+accfunc.Name] = rfc6901Escaper.Replace(namespace + "/" + + accfunc.Spec.InterfaceID[:interfaceIDPrefixLength] + accfunc.Spec.AfuID) + } else { + p.resourceMap[namespace+"/"+accfunc.Name] = rfc6901Escaper.Replace(namespace + "/region-" + accfunc.Spec.InterfaceID) + } + p.resourceModeMap[namespace+"/"+accfunc.Name] = accfunc.Spec.Mode } func (p *patcher) addRegion(region *fpgav1.FpgaRegion) { defer p.Unlock() p.Lock() - p.regionMap[region.Name] = region.Spec.InterfaceID + p.resourceModeMap[namespace+"/"+region.Name] = regiondevel p.resourceMap[namespace+"/"+region.Name] = rfc6901Escaper.Replace(namespace + "/region-" + region.Spec.InterfaceID) } @@ -113,149 +114,138 @@ func (p *patcher) removeAf(name string) { defer p.Unlock() p.Lock() - delete(p.afMap, name) + delete(p.afMap, namespace+"/"+name) delete(p.resourceMap, namespace+"/"+name) + delete(p.resourceModeMap, namespace+"/"+name) } func (p *patcher) removeRegion(name string) { defer p.Unlock() p.Lock() - delete(p.regionMap, name) delete(p.resourceMap, namespace+"/"+name) + delete(p.resourceModeMap, namespace+"/"+name) } -func (p *patcher) getPatchOps(containerIdx int, container corev1.Container) ([]string, error) { - switch p.mode { - case preprogrammed: - return p.getPatchOpsPreprogrammed(containerIdx, container) - case orchestrated: - return p.getPatchOpsOrchestrated(containerIdx, container) - } - - return nil, errors.Errorf("Uknown mode: %s", p.mode) -} - -func (p *patcher) getPatchOpsPreprogrammed(containerIdx int, container corev1.Container) ([]string, error) { - var ops []string - - for resourceName, resourceQuantity := range container.Resources.Limits { - newName, err := p.translateFpgaResourceName(resourceName) - if err != nil { - return nil, err - } - if len(newName) > 0 { - op := fmt.Sprintf(resourceReplaceOp, containerIdx, - "limits", rfc6901Escaper.Replace(string(resourceName)), - containerIdx, "limits", newName, resourceQuantity.String()) - ops = append(ops, op) +// getRequestedResources validates the container's requirements first, then returns them as a map. +func getRequestedResources(container corev1.Container) (map[string]int64, error) { + for _, v := range container.Env { + if strings.HasPrefix(v.Name, "FPGA_REGION") || strings.HasPrefix(v.Name, "FPGA_AFU") { + return nil, errors.Errorf("environment variable '%s' is not allowed", v.Name) } } + + // Container may happen to have Requests, but not Limits. Check Requests first, + // then in the next loop iterate over Limits. for resourceName, resourceQuantity := range container.Resources.Requests { - newName, err := p.translateFpgaResourceName(resourceName) - if err != nil { - return nil, err - } - if len(newName) > 0 { - op := fmt.Sprintf(resourceReplaceOp, containerIdx, - "requests", rfc6901Escaper.Replace(string(resourceName)), - containerIdx, "requests", newName, resourceQuantity.String()) - ops = append(ops, op) + rname := strings.ToLower(string(resourceName)) + if !strings.HasPrefix(rname, namespace) { + // Skip non-FPGA resources in Requests. + continue } - } - - return ops, nil -} - -func (p *patcher) translateFpgaResourceName(oldname corev1.ResourceName) (string, error) { - rname := strings.ToLower(string(oldname)) - if !strings.HasPrefix(rname, namespace) { - return "", nil - } - - defer p.Unlock() - p.Lock() - if newname, ok := p.resourceMap[rname]; ok { - return newname, nil + if container.Resources.Limits[resourceName] != resourceQuantity { + return nil, errors.Errorf( + "'limits' and 'requests' for %q must be equal as extended resources cannot be overcommitted", + rname) + } } - return "", errors.Errorf("Unknown FPGA resource: %s", rname) -} - -func (p *patcher) checkResourceRequests(container corev1.Container) error { - for resourceName, resourceQuantity := range container.Resources.Requests { - interfaceID, _, err := p.parseResourceName(string(resourceName)) - if err != nil { - return err + resources := make(map[string]int64) + for resourceName, resourceQuantity := range container.Resources.Limits { + rname := strings.ToLower(string(resourceName)) + if !strings.HasPrefix(rname, namespace) { + // Skip non-FPGA resources in Limits. + continue } - if interfaceID == "" { - // Skip non-FPGA resources - continue + if container.Resources.Requests[resourceName] != resourceQuantity { + return nil, errors.Errorf( + "'limits' and 'requests' for %q must be equal as extended resources cannot be overcommitted", + rname) } - if container.Resources.Limits[resourceName] != resourceQuantity { - return errors.Errorf("'limits' and 'requests' for %s must be equal", string(resourceName)) + + quantity, ok := resourceQuantity.AsInt64() + if !ok { + return nil, errors.Errorf("resource quantity isn't of integral type for %q", rname) } + + resources[rname] = quantity } - return nil + return resources, nil } -func (p *patcher) getPatchOpsOrchestrated(containerIdx int, container corev1.Container) ([]string, error) { +func (p *patcher) getPatchOps(containerIdx int, container corev1.Container) ([]string, error) { var ops []string - for _, v := range container.Env { - if strings.HasPrefix(v.Name, "FPGA_REGION") || strings.HasPrefix(v.Name, "FPGA_AFU") { - return nil, errors.Errorf("The environment variable '%s' is not allowed", v.Name) - } - } - - if err := p.checkResourceRequests(container); err != nil { + requestedResources, err := getRequestedResources(container) + if err != nil { return nil, err } - regions := make(map[string]int64) + defer p.Unlock() + p.Lock() + + fpgaPluginMode := "" + resources := make(map[string]int64) envVars := make(map[string]string) counter := 0 - for resourceName, resourceQuantity := range container.Resources.Limits { - interfaceID, afuID, err := p.parseResourceName(string(resourceName)) - if err != nil { - return nil, err - } + for rname, quantity := range requestedResources { - if interfaceID == "" && afuID == "" { - // Skip non-FPGA resources - continue + mode, found := p.resourceModeMap[rname] + if !found { + return nil, errors.Errorf("no such resource: %q", rname) } - if container.Resources.Requests[resourceName] != resourceQuantity { - return nil, errors.Errorf("'limits' and 'requests' for %s must be equal", string(resourceName)) + switch mode { + case regiondevel: + // Do nothing. + // The requested resources are exposed by FPGA plugins working in "regiondevel" mode. + // In this mode the workload is supposed to program FPGA regions. + // A cluster admin has to add FpgaRegion CRDs to allow this. + case af: + // Do nothing. + // The requested resources are exposed by FPGA plugins working in "af" mode. + case region: + // Let fpga_crihook know how to program the regions by setting ENV variables. + // The requested resources are exposed by FPGA plugins working in "region" mode. + for i := int64(0); i < quantity; i++ { + counter++ + envVars[fmt.Sprintf("FPGA_REGION_%d", counter)] = p.afMap[rname].Spec.InterfaceID + envVars[fmt.Sprintf("FPGA_AFU_%d", counter)] = p.afMap[rname].Spec.AfuID + } + 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. + klog.Error(msg) + return nil, errors.New(msg) } - quantity, ok := resourceQuantity.AsInt64() - if !ok { - return nil, errors.New("Resource quantity isn't of integral type") + if fpgaPluginMode == "" { + fpgaPluginMode = mode + } else if fpgaPluginMode != mode { + return nil, errors.New("container cannot be scheduled as it requires resources operated in different modes") } - regions[interfaceID] = regions[interfaceID] + quantity - for i := int64(0); i < quantity; i++ { - counter++ - envVars[fmt.Sprintf("FPGA_REGION_%d", counter)] = interfaceID - envVars[fmt.Sprintf("FPGA_AFU_%d", counter)] = afuID - } + mappedName := p.resourceMap[rname] + resources[mappedName] = resources[mappedName] + quantity - ops = append(ops, fmt.Sprintf(resourceRemoveOp, containerIdx, "limits", rfc6901Escaper.Replace(string(resourceName)))) - ops = append(ops, fmt.Sprintf(resourceRemoveOp, containerIdx, "requests", rfc6901Escaper.Replace(string(resourceName)))) + // Add operations to remove unresolved resources from the pod. + ops = append(ops, fmt.Sprintf(resourceRemoveOp, containerIdx, "limits", rfc6901Escaper.Replace(rname))) + ops = append(ops, fmt.Sprintf(resourceRemoveOp, containerIdx, "requests", rfc6901Escaper.Replace(rname))) } - for interfaceID, quantity := range regions { - op := fmt.Sprintf(resourceAddOp, containerIdx, "limits", rfc6901Escaper.Replace(namespace+"/region-"+interfaceID), quantity) + // Add operations to add resolved resources to the pod. + for resource, quantity := range resources { + op := fmt.Sprintf(resourceAddOp, containerIdx, "limits", resource, quantity) ops = append(ops, op) - op = fmt.Sprintf(resourceAddOp, containerIdx, "requests", rfc6901Escaper.Replace(namespace+"/region-"+interfaceID), quantity) + op = fmt.Sprintf(resourceAddOp, containerIdx, "requests", resource, quantity) ops = append(ops, op) } + // Add the ENV variables to the pod if needed. if len(envVars) > 0 { for _, envvar := range container.Env { envVars[envvar.Name] = envvar.Value @@ -276,69 +266,21 @@ func (p *patcher) getPatchOpsOrchestrated(containerIdx int, container corev1.Con return ops, nil } -func (p *patcher) parseResourceName(input string) (string, string, error) { - var interfaceID, afuID string - var regionName, afName string - var ok bool - - result := resourceRe.FindStringSubmatch(input) - if result == nil { - return "", "", nil - } - - defer p.Unlock() - p.Lock() - - for num, group := range resourceRe.SubexpNames() { - switch group { - case "Region": - regionName = result[num] - if interfaceID, ok = p.regionMap[result[num]]; !ok { - return "", "", errors.Errorf("Unknown region name: %s", result[num]) - } - case "Af": - afName = result[num] - } - } - - if afName != "" { - if afuID, ok = p.afMap[regionName+"-"+afName]; !ok { - return "", "", errors.Errorf("Unknown AF name: %s", regionName+"-"+afName) - } - } - - return interfaceID, afuID, nil -} - // patcherManager keeps track of patchers registered for different Kubernetes namespaces. -type patcherManager struct { - defaultMode string - patchers map[string]*patcher -} +type patcherManager map[string]*patcher -func newPatcherManager(defaultMode string) (*patcherManager, error) { - if defaultMode != preprogrammed && defaultMode != orchestrated { - return nil, errors.Errorf("Unknown mode: %s", defaultMode) - } - - return &patcherManager{ - defaultMode: defaultMode, - patchers: make(map[string]*patcher), - }, nil +func newPatcherManager() patcherManager { + return make(map[string]*patcher) } -func (pm *patcherManager) getPatcher(namespace string) (*patcher, error) { - if p, ok := pm.patchers[namespace]; ok { - return p, nil - } - - p, err := newPatcher(pm.defaultMode) - if err != nil { - return nil, err +func (pm patcherManager) getPatcher(namespace string) *patcher { + if p, ok := pm[namespace]; ok { + return p } - pm.patchers[namespace] = p + p := newPatcher() + pm[namespace] = p klog.V(4).Info("created new patcher for namespace", namespace) - return p, nil + return p } diff --git a/cmd/fpga_admissionwebhook/patcher_test.go b/cmd/fpga_admissionwebhook/patcher_test.go index ceb1f1c77..401aa003f 100644 --- a/cmd/fpga_admissionwebhook/patcher_test.go +++ b/cmd/fpga_admissionwebhook/patcher_test.go @@ -21,7 +21,6 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/klog" fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" ) @@ -48,202 +47,133 @@ func TestPatcherStorageFunctions(t *testing.T) { }, } - p, err := newPatcher(preprogrammed) - if err != nil { - t.Fatal(err) - } + p := newPatcher() p.addAf(af) - if 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") } p.removeAf(af.Name) - if 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") } p.addRegion(region) - if len(p.regionMap) != 1 || len(p.resourceMap) != 1 { + if len(p.resourceModeMap) != 1 || len(p.resourceMap) != 1 { t.Error("Failed to add fpga region to patcher") } p.removeRegion(region.Name) - if len(p.regionMap) != 0 || len(p.resourceMap) != 0 { + if len(p.resourceModeMap) != 0 || len(p.resourceMap) != 0 { t.Error("Failed to remove fpga region from patcher") } } -func TestGetPatchOpsPreprogrammed(t *testing.T) { +func TestGetPatchOps(t *testing.T) { tcases := []struct { name string - resourceMap map[string]string container corev1.Container + afs []*fpgav1.AcceleratorFunction + regions []*fpgav1.FpgaRegion expectedErr bool expectedOps int }{ { - name: "Empty container", - }, - { - name: "Unknown resource in limits", + name: "Successful handling for region mode", container: corev1.Container{ Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ - "fpga.intel.com/arria10-unknown": resource.MustParse("1"), - "cpu": resource.MustParse("1"), + "fpga.intel.com/arria10-nlb0": resource.MustParse("1"), + "fpga.intel.com/arria10-nlb0-alias": resource.MustParse("2"), + "cpu": resource.MustParse("1"), + }, + Requests: corev1.ResourceList{ + "fpga.intel.com/arria10-nlb0": resource.MustParse("1"), + "fpga.intel.com/arria10-nlb0-alias": resource.MustParse("2"), + "cpu": resource.MustParse("3"), + }, + }, + Env: []corev1.EnvVar{ + { + Name: "SOME_VAR", + Value: "fake value", }, }, }, - expectedErr: true, - }, - { - name: "Unknown resource in requests", - container: corev1.Container{ - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - "fpga.intel.com/arria10-unknown": resource.MustParse("1"), - "cpu": resource.MustParse("1"), + afs: []*fpgav1.AcceleratorFunction{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "arria10-nlb0", + }, + Spec: fpgav1.AcceleratorFunctionSpec{ + AfuID: "d8424dc4a4a3c413f89e433683f9040b", + InterfaceID: "ce48969398f05f33946d560708be108a", + Mode: region, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "arria10-nlb0-alias", + }, + Spec: fpgav1.AcceleratorFunctionSpec{ + AfuID: "d8424dc4a4a3c413f89e433683f9040b", + InterfaceID: "ce48969398f05f33946d560708be108a", + Mode: region, }, }, }, - expectedErr: true, + expectedOps: 7, }, { - name: "Successful case", + name: "Successful handling for af mode", container: corev1.Container{ Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ "fpga.intel.com/arria10-nlb0": resource.MustParse("1"), - "cpu": resource.MustParse("1"), }, Requests: corev1.ResourceList{ "fpga.intel.com/arria10-nlb0": resource.MustParse("1"), - "cpu": resource.MustParse("1"), }, }, }, - resourceMap: map[string]string{ - "fpga.intel.com/arria10-nlb0": rfc6901Escaper.Replace("fpga.intel.com/af-d8424dc4a4a3c413f89e433683f9040b"), - }, - expectedOps: 2, - }, - } - for _, tt := range tcases { - p := &patcher{ - resourceMap: tt.resourceMap, - } - ops, err := p.getPatchOpsPreprogrammed(0, tt.container) - if tt.expectedErr && err == nil { - t.Errorf("Test case '%s': no error returned", tt.name) - } - if !tt.expectedErr && err != nil { - t.Errorf("Test case '%s': unexpected error %v", tt.name, err) - } - if len(ops) != tt.expectedOps { - t.Errorf("test case '%s': expected %d ops, but got %d\n%v", tt.name, tt.expectedOps, len(ops), ops) - } - } -} - -func TestParseResourceName(t *testing.T) { - tcases := []struct { - input string - interfaceID string - afuID string - afMap map[string]string - regionMap map[string]string - expectedErr bool - }{ - { - input: "fpga.intel.com/arria10", - regionMap: map[string]string{ - "arria10": "ce48969398f05f33946d560708be108a", - }, - interfaceID: "ce48969398f05f33946d560708be108a", - }, - { - input: "fpga.intel.com/arria10-unknown", - regionMap: map[string]string{ - "arria10": "ce48969398f05f33946d560708be108a", - }, - expectedErr: true, - }, - { - input: "fpga.intel.com/unknown", - expectedErr: true, - }, - { - input: "fpga.example.com/something", - }, - { - input: "fpga.intel.com/arria10-nlb0", - regionMap: map[string]string{ - "arria10": "ce48969398f05f33946d560708be108a", - }, - afMap: map[string]string{ - "arria10-nlb0": "d8424dc4a4a3c413f89e433683f9040b", + afs: []*fpgav1.AcceleratorFunction{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "arria10-nlb0", + }, + Spec: fpgav1.AcceleratorFunctionSpec{ + AfuID: "d8424dc4a4a3c413f89e433683f9040b", + InterfaceID: "ce48969398f05f33946d560708be108a", + Mode: af, + }, + }, }, - interfaceID: "ce48969398f05f33946d560708be108a", - afuID: "d8424dc4a4a3c413f89e433683f9040b", + expectedOps: 4, }, - } - - for num, tt := range tcases { - p := &patcher{ - afMap: tt.afMap, - regionMap: tt.regionMap, - } - interfaceID, afuID, err := p.parseResourceName(tt.input) - if tt.expectedErr { - if err != nil { - continue - } else { - t.Errorf("In case %d we didn't get error", num) - } - } - if tt.interfaceID != interfaceID || tt.afuID != afuID { - t.Errorf("In case %d expected (%s, %s), but got (%s, %s)", num, tt.interfaceID, tt.afuID, interfaceID, afuID) - } - } -} - -func TestGetPatchOpsOrchestrated(t *testing.T) { - tcases := []struct { - name string - container corev1.Container - afMap map[string]string - regionMap map[string]string - expectedErr bool - expectedOps int - }{ { - name: "Successful handling", + name: "Successful handling for regiondevel mode", container: corev1.Container{ Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ - "fpga.intel.com/arria10-nlb0": resource.MustParse("1"), - "cpu": resource.MustParse("1"), + "fpga.intel.com/arria10": resource.MustParse("1"), }, Requests: corev1.ResourceList{ - "fpga.intel.com/arria10-nlb0": resource.MustParse("1"), - "cpu": resource.MustParse("1"), + "fpga.intel.com/arria10": resource.MustParse("1"), }, }, - Env: []corev1.EnvVar{ - { - Name: "SOME_VAR", - Value: "fake value", + }, + regions: []*fpgav1.FpgaRegion{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "arria10", + }, + Spec: fpgav1.FpgaRegionSpec{ + InterfaceID: "ce48969398f05f33946d560708be108a", }, }, }, - regionMap: map[string]string{ - "arria10": "ce48969398f05f33946d560708be108a", - }, - afMap: map[string]string{ - "arria10-nlb0": "d8424dc4a4a3c413f89e433683f9040b", - }, - expectedOps: 5, + expectedOps: 4, }, { name: "Unequal FPGA resources in Limits and Requests 1", @@ -255,13 +185,6 @@ func TestGetPatchOpsOrchestrated(t *testing.T) { }, }, }, - regionMap: map[string]string{ - "arria10": "ce48969398f05f33946d560708be108a", - }, - afMap: map[string]string{ - "arria10-nlb0": "d8424dc4a4a3c413f89e433683f9040b", - "arria10-nlb3": "f7df405cbd7acf7222f144b0b93acd18", - }, expectedErr: true, }, { @@ -270,151 +193,168 @@ func TestGetPatchOpsOrchestrated(t *testing.T) { Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ "fpga.intel.com/arria10-nlb0": resource.MustParse("1"), - "fpga.intel.com/arria10-nlb3": resource.MustParse("1"), + "fpga.intel.com/arria10-nlb3": resource.MustParse("2"), }, }, }, - regionMap: map[string]string{ - "arria10": "ce48969398f05f33946d560708be108a", - }, - afMap: map[string]string{ - "arria10-nlb0": "d8424dc4a4a3c413f89e433683f9040b", - "arria10-nlb3": "f7df405cbd7acf7222f144b0b93acd18", - }, expectedErr: true, }, { - name: "Unknown FPGA model in Requests", + name: "Unknown FPGA resources in container requirements", container: corev1.Container{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ "fpga.intel.com/unknown-nlb0": resource.MustParse("1"), }, - }, - }, - expectedErr: true, - }, - { - name: "Unknown AFU in Requests", - container: corev1.Container{ - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - "fpga.intel.com/arria10-unknown": resource.MustParse("1"), + Limits: corev1.ResourceList{ + "fpga.intel.com/unknown-nlb0": resource.MustParse("1"), }, }, }, expectedErr: true, }, { - name: "Unknown FPGA model in Limits", + name: "Wrong ENV", container: corev1.Container{ Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ - "fpga.intel.com/unknown-nlb0": resource.MustParse("1"), + "cpu": resource.MustParse("1"), + }, + }, + Env: []corev1.EnvVar{ + { + Name: "FPGA_REGION", + Value: "fake value", }, }, }, expectedErr: true, }, { - name: "Unknown AFU in Limits", + name: "Wrong type of quantity", container: corev1.Container{ Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ - "fpga.intel.com/arria10-unknown": resource.MustParse("1"), + "fpga.intel.com/arria10-nlb0": resource.MustParse("1.1"), + }, + Requests: corev1.ResourceList{ + "fpga.intel.com/arria10-nlb0": resource.MustParse("1.1"), }, }, }, expectedErr: true, }, { - name: "Wrong ENV", + name: "Require resources operated in af and region modes", container: corev1.Container{ Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ "fpga.intel.com/arria10-nlb0": resource.MustParse("1"), + "fpga.intel.com/arria10-nlb3": resource.MustParse("2"), + "cpu": resource.MustParse("1"), }, - }, - Env: []corev1.EnvVar{ - { - Name: "FPGA_REGION", - Value: "fake value", + Requests: corev1.ResourceList{ + "fpga.intel.com/arria10-nlb0": resource.MustParse("1"), + "fpga.intel.com/arria10-nlb3": resource.MustParse("2"), + "cpu": resource.MustParse("3"), }, }, }, - regionMap: map[string]string{ - "arria10": "ce48969398f05f33946d560708be108a", - }, - afMap: map[string]string{ - "arria10-nlb0": "d8424dc4a4a3c413f89e433683f9040b", + afs: []*fpgav1.AcceleratorFunction{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "arria10-nlb0", + }, + Spec: fpgav1.AcceleratorFunctionSpec{ + AfuID: "d8424dc4a4a3c413f89e433683f9040b", + InterfaceID: "ce48969398f05f33946d560708be108a", + Mode: region, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "arria10-nlb3", + }, + Spec: fpgav1.AcceleratorFunctionSpec{ + AfuID: "d8424dc4a4a3c413f89e433683f9040b", + InterfaceID: "f7df405cbd7acf7222f144b0b93acd18", + Mode: af, + }, + }, }, expectedErr: true, }, { - name: "Wrong type of quantity", + name: "Unknown mode", container: corev1.Container{ Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ - "fpga.intel.com/arria10-nlb0": resource.MustParse("1.1"), + "fpga.intel.com/arria10-nlb0": resource.MustParse("1"), }, Requests: corev1.ResourceList{ - "fpga.intel.com/arria10-nlb0": resource.MustParse("1.1"), + "fpga.intel.com/arria10-nlb0": resource.MustParse("1"), }, }, }, - regionMap: map[string]string{ - "arria10": "ce48969398f05f33946d560708be108a", - }, - afMap: map[string]string{ - "arria10-nlb0": "d8424dc4a4a3c413f89e433683f9040b", + afs: []*fpgav1.AcceleratorFunction{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "arria10-nlb0", + }, + Spec: fpgav1.AcceleratorFunctionSpec{ + AfuID: "d8424dc4a4a3c413f89e433683f9040b", + InterfaceID: "ce48969398f05f33946d560708be108a", + Mode: "unknown", + }, + }, }, expectedErr: true, }, } for _, tt := range tcases { - p := &patcher{ - afMap: tt.afMap, - regionMap: tt.regionMap, - } - klog.V(4).Info(tt.name) - ops, err := p.getPatchOpsOrchestrated(0, tt.container) - if tt.expectedErr && err == nil { - t.Errorf("Test case '%s': no error returned", tt.name) - } - if !tt.expectedErr && err != nil { - t.Errorf("Test case '%s': unexpected error %+v", tt.name, err) - } - if len(ops) != tt.expectedOps { - t.Errorf("test case '%s': expected %d ops, but got %d\n%v", tt.name, tt.expectedOps, len(ops), ops) - } + t.Run(tt.name, func(t *testing.T) { + p := newPatcher() + for _, af := range tt.afs { + p.addAf(af) + } + for _, region := range tt.regions { + p.addRegion(region) + } + ops, err := p.getPatchOps(0, tt.container) + if tt.expectedErr && err == nil { + t.Errorf("Test case '%s': no error returned", tt.name) + } + if !tt.expectedErr && err != nil { + t.Errorf("Test case '%s': unexpected error: %+v", tt.name, err) + } + if len(ops) != tt.expectedOps { + t.Errorf("test case '%s': expected %d ops, but got %d\n%v", tt.name, tt.expectedOps, len(ops), ops) + } + }) } } -func TestNewPatcherManager(t *testing.T) { +func TestGetPatcher(t *testing.T) { + namespace := "test" tcases := []struct { - name string - defaultMode string - expectedErr bool + name string + pm patcherManager }{ { - name: "Everything is OK", - defaultMode: preprogrammed, + name: "Create new patcher", + pm: newPatcherManager(), }, { - name: "Unknown default mode", - defaultMode: "unknownMode", - expectedErr: true, + name: "Return existing patcher", + pm: map[string]*patcher{namespace: newPatcher()}, }, } for _, tt := range tcases { t.Run(tt.name, func(t *testing.T) { - _, err := newPatcherManager(tt.defaultMode) - if tt.expectedErr && err == nil { - t.Errorf("Test case '%s': no error returned", tt.name) - } - if !tt.expectedErr && err != nil { - t.Errorf("Test case '%s': unexpected error %+v", tt.name, err) + p := tt.pm.getPatcher(namespace) + if p != tt.pm[namespace] { + t.Error("stored and received patchers are not equal") } }) } diff --git a/cmd/fpga_plugin/README.md b/cmd/fpga_plugin/README.md index 484f705df..7474c7704 100644 --- a/cmd/fpga_plugin/README.md +++ b/cmd/fpga_plugin/README.md @@ -12,7 +12,7 @@ * [Verify node kubelet config](#verify-node-kubelet-config) * [Deploying as a DaemonSet](#deploying-as-a-daemonset) * [Create a service account](#create-a-service-account) - * [Deploying `orchestrated` mode](#deploying-orchestrated-mode) + * [Deploying `region` mode](#deploying-region-mode) * [Deploying `af` mode](#deploying-af-mode) * [Deploy the DaemonSet](#deploy-the-daemonset) * [Verify plugin registration](#verify-plugin-registration) @@ -75,26 +75,26 @@ development, initial deployment and debugging. The FPGA plugin set can run in one of two modes: -- `region`/`orchestrated` mode, where the plugins locate and advertise +- `region` mode, where the plugins locate and advertise regions of the FPGA, and facilitate programing of those regions with the requested bistreams. -- `af`/`preprogrammed` mode, where the FPGA bitstreams are already loaded +- `af` mode, where the FPGA bitstreams are already loaded onto the FPGA, and the plugins discover and advertises the existing Accelerator Functions (AF). The example YAML deployments described in this document only currently support -`af`/`preprogrammed` mode. To utilise `region`/`orchestrated` mode, either modify -the existing YAML appropriately, or deploy 'by hand'. +`af` mode. To utilise `region` mode, either modify the existing YAML appropriately, +or deploy 'by hand'. -Overview diagrams of `preprogrammed` and `orchestrated` modes are below: +Overview diagrams of `af` and `region` modes are below: -Orchestrated/region mode: +region mode: -![Overview of `orchestrated` mode](pictures/FPGA-orchestrated.png) +![Overview of `region` mode](pictures/FPGA-region.png) -Preprogrammed/af mode: +af mode: -![Overview of `preprogrammed` mode](pictures/FPGA-preprogrammed.png) +![Overview of `af` mode](pictures/FPGA-af.png) # Installation @@ -136,12 +136,11 @@ major components: - [FPGA admission controller webhook](../fpga_admissionwebhook/README.md) - [FPGA prestart CRI-O hook](../fpga_crihook/README.md) -The CRI-O hook is only *required* if `orchestrated` FPGA bitstream programming mode is -being used, but is installed by default by the +The CRI-O hook is only *required* if `region` mode is being used, but is installed by default by the [FPGA plugin DaemonSet YAML](../../deployments/fpga_plugin/fpga_plugin.yaml), and is benign -in `preprogrammed` mode. +in `af` mode. -If using the `preprogrammed` mode, and therefore *not* using the +If using the `af` mode, and therefore *not* using the CRI-O prestart hook, runtimes other than CRI-O can be used (that is, the CRI-O hook presently *only* works with the CRI-O runtime). @@ -192,8 +191,8 @@ YAML deployment files to reference your required image. ### For beta testing: new deployment model The FPGA plugin deployment is currently being rewritten to enable -straight-forward deployment of both `af/preprogrammed` and -`region/orchestrated` modes. The deployment has two steps: +straight-forward deployment of both `af` and +`region` modes. The deployment has two steps: 1. Run `scripts/fpga-plugin-prepare-for-kustomization.sh`. This will create the necessary secrets: a key and a signed certificate for @@ -226,19 +225,16 @@ clusterrole.rbac.authorization.k8s.io/node-getter created clusterrolebinding.rbac.authorization.k8s.io/get-nodes created ``` -### Deploying `orchestrated` mode +### Deploying `region` mode -To deploy the FPGA plugin DaemonSet in `orchestrated` (`region`) mode, you need to set the plugin +To deploy the FPGA plugin DaemonSet in `region` mode, you need to set the plugin mode annotation on all of your nodes, otherwise the FPGA plugin will run in its default -`af` (`preprogrammed`) mode. +`af` mode. ```bash $ kubectl annotate node --all 'fpga.intel.com/device-plugin-mode=region' ``` -Mixing of the two modes (`orchestrated` and `af`) across nodes in the same cluster is -*not currently supported*. - ### Deploying `af` mode To deploy the FPGA plugin DaemonSet in `af` mode, you do not need to set the mode annotation on @@ -260,7 +256,7 @@ daemonset.apps/intel-fpga-plugin created ### Verify plugin registration Verify the FPGA plugin has been deployed on the nodes. The below shows the output -you can expect in `region` mode, but similar output should be expected for `preprogrammed` +you can expect in `region` mode, but similar output should be expected for `af` mode: ```bash diff --git a/cmd/fpga_plugin/dfl_test.go b/cmd/fpga_plugin/dfl_test.go index f4b799910..25260b687 100644 --- a/cmd/fpga_plugin/dfl_test.go +++ b/cmd/fpga_plugin/dfl_test.go @@ -116,7 +116,7 @@ func getDevicesDFL() []device { }, { id: "dfl-port.4", - afuID: "d8424dc4a4a3c413f89e433683f9040b", + afuID: unhealthyAfuID, devNode: "/dev/dfl-port.4", }, }, @@ -240,7 +240,7 @@ func TestGetAfuTreeDFL(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice(afMode+"-d8424dc4a4a3c413f89e433683f9040b", "dfl-port.0", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) + expected.AddDevice("ce48969398f05f33946d560708be108d8424dc4a4a3c413f89e433683f9040b", "dfl-port.0", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -250,7 +250,7 @@ func TestGetAfuTreeDFL(t *testing.T) { }, } - expected.AddDevice(afMode+"-d8424dc4a4a3c413f89e433683f9040b", "dfl-port.1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) + expected.AddDevice("ce48969398f05f33946d560708be108d8424dc4a4a3c413f89e433683f9040b", "dfl-port.1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -259,7 +259,7 @@ func TestGetAfuTreeDFL(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice(afMode+"-d8424dc4a4a3c413f89e433683f9040b", "dfl-port.2", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) + expected.AddDevice("ce48969398f05f33946d560708be108d8424dc4a4a3c413f89e433683f9040b", "dfl-port.2", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -268,7 +268,7 @@ func TestGetAfuTreeDFL(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice(afMode+"-"+unhealthyAfuID, "dfl-port.3", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil)) + expected.AddDevice(unhealthyInterfaceID[:interfaceIDPrefixLength]+unhealthyAfuID, "dfl-port.3", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -277,11 +277,11 @@ func TestGetAfuTreeDFL(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice(afMode+"-d8424dc4a4a3c413f89e433683f9040b", "dfl-port.4", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) + expected.AddDevice(unhealthyInterfaceID[:interfaceIDPrefixLength]+unhealthyAfuID, "dfl-port.4", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil)) result := getAfuTree(getDevicesDFL()) if !reflect.DeepEqual(result, expected) { - t.Errorf("Got unexpected result: %v, expected: %v", result, expected) + t.Errorf("Got unexpected result:\n%v\nexpected:\n%v", result, expected) } } diff --git a/cmd/fpga_plugin/fpga_plugin.go b/cmd/fpga_plugin/fpga_plugin.go index 6fd2405c2..cb214e505 100644 --- a/cmd/fpga_plugin/fpga_plugin.go +++ b/cmd/fpga_plugin/fpga_plugin.go @@ -51,6 +51,11 @@ const ( // Frequency of device scans scanFrequency = 5 * time.Second + + // Names of extended resources cannot be longer than 63 characters. + // Therefore for AF resources we have to cut the interface ID prefix + // to 31 characters only. + interfaceIDPrefixLength = 31 ) type getDevTreeFunc func(devices []device) dpapi.DeviceTree @@ -125,7 +130,7 @@ func getAfuTree(devices []device) dpapi.DeviceTree { if afu.afuID == unhealthyAfuID { health = pluginapi.Unhealthy } - devType := fmt.Sprintf("%s-%s", afMode, afu.afuID) + devType := region.interfaceID[:interfaceIDPrefixLength] + afu.afuID devNodes := []pluginapi.DeviceSpec{ { HostPath: afu.devNode, diff --git a/cmd/fpga_plugin/opae_test.go b/cmd/fpga_plugin/opae_test.go index fd398be9d..84181c621 100644 --- a/cmd/fpga_plugin/opae_test.go +++ b/cmd/fpga_plugin/opae_test.go @@ -210,7 +210,7 @@ func TestGetAfuTreeOPAE(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice(afMode+"-d8424dc4a4a3c413f89e433683f9040b", "intel-fpga-port.0", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) + expected.AddDevice("ce48969398f05f33946d560708be108d8424dc4a4a3c413f89e433683f9040b", "intel-fpga-port.0", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -219,7 +219,7 @@ func TestGetAfuTreeOPAE(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice(afMode+"-d8424dc4a4a3c413f89e433683f9040b", "intel-fpga-port.1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) + expected.AddDevice("ce48969398f05f33946d560708be108d8424dc4a4a3c413f89e433683f9040b", "intel-fpga-port.1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -228,7 +228,7 @@ func TestGetAfuTreeOPAE(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice(afMode+"-"+unhealthyAfuID, "intel-fpga-port.2", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil)) + expected.AddDevice(unhealthyInterfaceID[:interfaceIDPrefixLength]+unhealthyAfuID, "intel-fpga-port.2", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil)) result := getAfuTree(getDevicesOPAE()) if !reflect.DeepEqual(result, expected) { diff --git a/cmd/fpga_plugin/pictures/FPGA-preprogrammed.png b/cmd/fpga_plugin/pictures/FPGA-af.png similarity index 100% rename from cmd/fpga_plugin/pictures/FPGA-preprogrammed.png rename to cmd/fpga_plugin/pictures/FPGA-af.png diff --git a/cmd/fpga_plugin/pictures/FPGA-orchestrated.png b/cmd/fpga_plugin/pictures/FPGA-region.png similarity index 100% rename from cmd/fpga_plugin/pictures/FPGA-orchestrated.png rename to cmd/fpga_plugin/pictures/FPGA-region.png diff --git a/deployments/fpga_admissionwebhook/af-crd.yaml b/deployments/fpga_admissionwebhook/af-crd.yaml index e2a5cfc7c..cdfc50724 100644 --- a/deployments/fpga_admissionwebhook/af-crd.yaml +++ b/deployments/fpga_admissionwebhook/af-crd.yaml @@ -19,4 +19,10 @@ spec: properties: afuId: type: string - pattern: '^[0-9a-f]{8,128}$' + pattern: '^[0-9a-f]{8,32}$' + interfaceId: + type: string + pattern: '^[0-9a-f]{8,32}$' + mode: + type: string + pattern: '^af|region$' diff --git a/deployments/fpga_admissionwebhook/base/acceleratorfunctions.yaml b/deployments/fpga_admissionwebhook/base/acceleratorfunctions.yaml index 803f1dc85..39abaeb6a 100644 --- a/deployments/fpga_admissionwebhook/base/acceleratorfunctions.yaml +++ b/deployments/fpga_admissionwebhook/base/acceleratorfunctions.yaml @@ -1,13 +1,6 @@ # DCP 1.0 apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction -metadata: - name: arria10.dcp1.0-compress -spec: - afuId: 946c21d1e49704a5e5daa0805bc6b0785e1765bf ---- -apiVersion: fpga.intel.com/v1 -kind: AcceleratorFunction metadata: name: arria10.dcp1.0-nlb0 spec: diff --git a/deployments/fpga_admissionwebhook/deployment-tpl.yaml b/deployments/fpga_admissionwebhook/deployment-tpl.yaml index dfface684..a0dbb5694 100644 --- a/deployments/fpga_admissionwebhook/deployment-tpl.yaml +++ b/deployments/fpga_admissionwebhook/deployment-tpl.yaml @@ -29,7 +29,6 @@ spec: args: - -tls-cert-file=/etc/webhook/certs/cert.pem - -tls-private-key-file=/etc/webhook/certs/key.pem - - -mode={MODE} - -v=1 volumeMounts: - name: webhook-certs diff --git a/deployments/fpga_admissionwebhook/mappings-collection.yaml b/deployments/fpga_admissionwebhook/mappings-collection.yaml index bd15c2027..09d666300 100644 --- a/deployments/fpga_admissionwebhook/mappings-collection.yaml +++ b/deployments/fpga_admissionwebhook/mappings-collection.yaml @@ -8,17 +8,12 @@ spec: --- apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction -metadata: - name: arria10.dcp1.0-compress -spec: - afuId: 946c21d1e49704a5e5daa0805bc6b0785e1765bf ---- -apiVersion: fpga.intel.com/v1 -kind: AcceleratorFunction metadata: name: arria10.dcp1.0-nlb0 spec: afuId: d8424dc4a4a3c413f89e433683f9040b + interfaceId: ce48969398f05f33946d560708be108a + mode: region --- apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction @@ -26,6 +21,8 @@ metadata: name: arria10.dcp1.0-nlb3 spec: afuId: f7df405cbd7acf7222f144b0b93acd18 + interfaceId: ce48969398f05f33946d560708be108a + mode: region --- # DCP 1.1 apiVersion: fpga.intel.com/v1 @@ -41,6 +38,8 @@ metadata: name: arria10.dcp1.1-nlb0 spec: afuId: d8424dc4a4a3c413f89e433683f9040b + interfaceId: 9926ab6d6c925a68aabca7d84c545738 + mode: region --- apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction @@ -48,6 +47,8 @@ metadata: name: arria10.dcp1.1-nlb3 spec: afuId: f7df405cbd7acf7222f144b0b93acd18 + interfaceId: 9926ab6d6c925a68aabca7d84c545738 + mode: region --- # DCP 1.2 apiVersion: fpga.intel.com/v1 @@ -63,6 +64,8 @@ metadata: name: arria10.dcp1.2-nlb0 spec: afuId: d8424dc4a4a3c413f89e433683f9040b + interfaceId: 69528db6eb31577a8c3668f9faa081f6 + mode: region --- apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction @@ -70,6 +73,8 @@ metadata: name: arria10.dcp1.2-nlb3 spec: afuId: f7df405cbd7acf7222f144b0b93acd18 + interfaceId: 69528db6eb31577a8c3668f9faa081f6 + mode: region --- # D5005 apiVersion: fpga.intel.com/v1 @@ -85,6 +90,8 @@ metadata: name: d5005-nlb0 spec: afuId: d8424dc4a4a3c413f89e433683f9040b + interfaceId: bfac4d851ee856fe8c95865ce1bbaa2d + mode: region --- apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction @@ -92,3 +99,14 @@ metadata: name: d5005-nlb3 spec: afuId: f7df405cbd7acf7222f144b0b93acd18 + interfaceId: bfac4d851ee856fe8c95865ce1bbaa2d + mode: region +--- +apiVersion: fpga.intel.com/v1 +kind: AcceleratorFunction +metadata: + name: d5005-nlb3-preprogrammed +spec: + afuId: f7df405cbd7acf7222f144b0b93acd18 + interfaceId: bfac4d851ee856fe8c95865ce1bbaa2d + mode: af diff --git a/deployments/fpga_admissionwebhook/region-crd.yaml b/deployments/fpga_admissionwebhook/region-crd.yaml index 3500854b3..d8a7ab29e 100644 --- a/deployments/fpga_admissionwebhook/region-crd.yaml +++ b/deployments/fpga_admissionwebhook/region-crd.yaml @@ -19,4 +19,4 @@ spec: properties: interfaceId: type: string - pattern: '^[0-9a-f]{8,128}$' + pattern: '^[0-9a-f]{8,32}$' diff --git a/pkg/apis/fpga.intel.com/v1/types.go b/pkg/apis/fpga.intel.com/v1/types.go index 65796a1d7..fbe000c94 100644 --- a/pkg/apis/fpga.intel.com/v1/types.go +++ b/pkg/apis/fpga.intel.com/v1/types.go @@ -18,7 +18,9 @@ type AcceleratorFunction struct { // AcceleratorFunctionSpec contains actual specs for AcceleratorFunction type AcceleratorFunctionSpec struct { - AfuID string `json:"afuId"` + AfuID string `json:"afuId"` + InterfaceID string `json:"interfaceId"` + Mode string `json:"mode"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/scripts/webhook-deploy.sh b/scripts/webhook-deploy.sh index 6bc6ae3cd..9e631de23 100755 --- a/scripts/webhook-deploy.sh +++ b/scripts/webhook-deploy.sh @@ -15,7 +15,6 @@ function help { echo '' echo ' Options:' echo ' --kubectl - path to the kubectl utility' - echo ' --mode - "preprogrammed" (default) or "orchestrated" mode of operation' echo ' --ca-bundle-path - path to CA bundle used for signing cerificates in the cluster' echo ' --namespace - namespace to deploy the webhook in' } @@ -30,10 +29,6 @@ while [[ $# -gt 0 ]]; do cabundlepath="$2" shift ;; - --mode) - mode="$2" - shift - ;; --namespace) namespace="$2" shift @@ -54,7 +49,6 @@ while [[ $# -gt 0 ]]; do done [ -z ${kubectl} ] && kubectl="kubectl" -[ -z ${mode} ] && mode="preprogrammed" [ -z ${namespace} ] && namespace="default" which ${kubectl} > /dev/null 2>&1 || { echo "ERROR: ${kubectl} not found"; exit 1; } @@ -75,11 +69,6 @@ if [ "x${command}" = "xcleanup" ]; then exit 0 fi -if [ "x${mode}" != "xpreprogrammed" -a "x${mode}" != "xorchestrated" ]; then - echo "ERROR: supported modes are 'preprogrammed' and 'orchestrated'" - exit 1 -fi - if [ -z ${cabundlepath} ]; then CA_BUNDLE=$(${kubectl} get configmap -n kube-system extension-apiserver-authentication -o=jsonpath='{.data.client-ca-file}' | base64 -w 0) else @@ -98,7 +87,7 @@ cat ${srcroot}/deployments/fpga_admissionwebhook/rbac-config-tpl.yaml | \ ${kubectl} create -f - echo "Create webhook deployment" -cat ${srcroot}/deployments/fpga_admissionwebhook/deployment-tpl.yaml | sed -e "s/{MODE}/${mode}/g" -e "s/{uid}/${uid}/g" -e "s/{gid}/${gid}/g" | ${kubectl} --namespace ${namespace} create -f - +cat ${srcroot}/deployments/fpga_admissionwebhook/deployment-tpl.yaml | sed -e "s/{uid}/${uid}/g" -e "s/{gid}/${gid}/g" | ${kubectl} --namespace ${namespace} create -f - echo "Create webhook service" ${kubectl} --namespace ${namespace} create -f ${srcroot}/deployments/fpga_admissionwebhook/service.yaml diff --git a/test/e2e/fpgaadmissionwebhook/fpgaadmissionwebhook.go b/test/e2e/fpgaadmissionwebhook/fpgaadmissionwebhook.go index b589d8ba3..019e35fa7 100644 --- a/test/e2e/fpgaadmissionwebhook/fpgaadmissionwebhook.go +++ b/test/e2e/fpgaadmissionwebhook/fpgaadmissionwebhook.go @@ -51,25 +51,37 @@ func describe() { return append(os.Environ(), "KUBECONFIG="+framework.TestContext.KubeConfig) } - ginkgo.It("mutates created pods to reference resolved AFs in preprogrammed mode", func() { - ginkgo.By("deploying webhook in preprogrammed mode") + ginkgo.It("mutates created pods to reference resolved AFs", func() { + ginkgo.By("deploying webhook") _, _, err := framework.RunCmdEnv(getEnv(), webhookDeployPath, "--kubectl", framework.TestContext.KubectlPath, "--namespace", f.Namespace.Name) framework.ExpectNoError(err) - checkPodMutation(f, "fpga.intel.com/af-d8424dc4a4a3c413f89e433683f9040b") + checkPodMutation(f, "fpga.intel.com/d5005-nlb3-preprogrammed", + "fpga.intel.com/bfac4d851ee856fe8c95865ce1bbaa2f7df405cbd7acf7222f144b0b93acd18") }) - ginkgo.It("mutates created pods to reference resolved Regions in orchestrated mode", func() { - ginkgo.By("deploying webhook in orchestrated mode") - _, _, err := framework.RunCmdEnv(getEnv(), webhookDeployPath, "--kubectl", framework.TestContext.KubectlPath, "--namespace", f.Namespace.Name, "--mode", "orchestrated") + ginkgo.It("mutates created pods to reference resolved Regions", func() { + ginkgo.By("deploying webhook") + _, _, err := framework.RunCmdEnv(getEnv(), webhookDeployPath, "--kubectl", framework.TestContext.KubectlPath, "--namespace", f.Namespace.Name) + framework.ExpectNoError(err) + + checkPodMutation(f, "fpga.intel.com/arria10.dcp1.0-nlb0", + "fpga.intel.com/region-ce48969398f05f33946d560708be108a") + + }) + + ginkgo.It("mutates created pods to reference resolved Regions in regiondevel mode", func() { + ginkgo.By("deploying webhook") + _, _, err := framework.RunCmdEnv(getEnv(), webhookDeployPath, "--kubectl", framework.TestContext.KubectlPath, "--namespace", f.Namespace.Name) framework.ExpectNoError(err) - checkPodMutation(f, "fpga.intel.com/region-ce48969398f05f33946d560708be108a") + checkPodMutation(f, "fpga.intel.com/arria10.dcp1.0", + "fpga.intel.com/region-ce48969398f05f33946d560708be108a") }) } -func checkPodMutation(f *framework.Framework, expectedMutation v1.ResourceName) { +func checkPodMutation(f *framework.Framework, source, expectedMutation v1.ResourceName) { ginkgo.By("waiting for webhook's availability") if _, err := e2epod.WaitForPodsWithLabelRunningReady(f.ClientSet, f.Namespace.Name, labels.Set{"app": "intel-fpga-webhook"}.AsSelector(), 1 /* one replica */, 10*time.Second); err != nil { @@ -80,8 +92,8 @@ func checkPodMutation(f *framework.Framework, expectedMutation v1.ResourceName) ginkgo.By("submitting a pod for addmission") podSpec := f.NewTestPod("webhook-tester", - v1.ResourceList{"fpga.intel.com/arria10.dcp1.0-nlb0": resource.MustParse("1")}, - v1.ResourceList{"fpga.intel.com/arria10.dcp1.0-nlb0": resource.MustParse("1")}) + v1.ResourceList{source: resource.MustParse("1")}, + v1.ResourceList{source: resource.MustParse("1")}) pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), podSpec, metav1.CreateOptions{}) framework.ExpectNoError(err, "pod Create API error") From 99fcb69d33152c6979eccd4808bab5d4e8805834 Mon Sep 17 00:00:00 2001 From: Dmitry Rozhkov Date: Fri, 24 Apr 2020 12:09:31 +0300 Subject: [PATCH 2/4] fpga: compress fpga AF resource names --- cmd/fpga_admissionwebhook/README.md | 27 ++++---- cmd/fpga_admissionwebhook/controller.go | 3 +- cmd/fpga_admissionwebhook/patcher.go | 18 ++--- cmd/fpga_plugin/dfl_test.go | 10 +-- cmd/fpga_plugin/fpga_plugin.go | 12 ++-- cmd/fpga_plugin/opae_test.go | 6 +- .../mappings-collection.yaml | 25 ++++--- pkg/fpga/devtypes.go | 36 ++++++++++ pkg/fpga/devtypes_test.go | 66 +++++++++++++++++++ .../fpgaadmissionwebhook.go | 4 +- 10 files changed, 161 insertions(+), 46 deletions(-) create mode 100644 pkg/fpga/devtypes.go create mode 100644 pkg/fpga/devtypes_test.go diff --git a/cmd/fpga_admissionwebhook/README.md b/cmd/fpga_admissionwebhook/README.md index d234a0746..a253620f6 100644 --- a/cmd/fpga_admissionwebhook/README.md +++ b/cmd/fpga_admissionwebhook/README.md @@ -131,27 +131,30 @@ For the following mapping apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction metadata: - name: arria10.dcp1.1-nlb0 + name: arria10.dcp1.2-nlb0-preprogrammed spec: afuId: d8424dc4a4a3c413f89e433683f9040b - interfaceId: 9926ab6d6c925a68aabca7d84c545738 + interfaceId: 69528db6eb31577a8c3668f9faa081f6 mode: af ``` requested FPGA resources are translated to AF resources. For example, -`fpga.intel.com/arria10.dcp1.1-nlb0` is translated to -`fpga.intel.com/9926ab6d6c925a68aabca7d84c54573d8424dc4a4a3c413f89e433683f9040b`. -The first 31 characters of the resource name part (`9926ab6d6c925a68aabca7d84c54573`) -is the first 31 characters of the region interface ID for Arria10 with DCP1.1 -firmware. The next 32 characters (`d8424dc4a4a3c413f89e433683f9040b`) is an accelerator function ID. -The format of resource names (e.g. `arria10.dcp1.1-nlb0`) can be any and is up +`fpga.intel.com/arria10.dcp1.2-nlb0-preprogrammed` is translated to +`fpga.intel.com/af-695.d84.aVKNtusxV3qMNmj5-qCB9thCTcSko8QT-J5DNoP5BAs` where the `af-` +prefix indicates the plugin's mode (`af`), `695` is the first three characters of +the region interface ID, `d84` is the first three characters of the accelerator function ID +and the last part `aVKNtusxV3qMNmj5-qCB9thCTcSko8QT-J5DNoP5BAs` is a base64-encoded concatenation +of the full region interface ID and accelerator function ID. +The format of resource names (e.g. `arria10.dcp1.2-nlb0-preprogrammed`) can be any and is up to a cluster administrator. -The same mapping, but with its mode field set to `region`, translates -`fpga.intel.com/arria10.dcp1.1-nlb0` to `fpga.intel.com/region-9926ab6d6c925a68aabca7d84c545738`, +The same mapping, but with its mode field set to `region`, would translate +`fpga.intel.com/arria10.dcp1.2-nlb0-preprogrammed` to `fpga.intel.com/region-69528db6eb31577a8c3668f9faa081f6`, and the corresponding AF IDs are set in environment variables for the container. -The [FPGA CRI-O hook](../fpga_crihook/README.md) then loads the requested bitstream to a region -before the container is started. +Though in this case the cluster administrator would probably want to rename +the mapping `arria10.dcp1.2-nlb0-preprogrammed` to something like `arria10.dcp1.2-nlb0-orchestrated` +to reflect its mode. The [FPGA CRI-O hook](../fpga_crihook/README.md) then loads the requested +bitstream to a region before the container is started. Mappings of resource names are configured with objects of `AcceleratorFunction` and `FpgaRegion` custom resource definitions found respectively in diff --git a/cmd/fpga_admissionwebhook/controller.go b/cmd/fpga_admissionwebhook/controller.go index 0592e3164..543c468dc 100644 --- a/cmd/fpga_admissionwebhook/controller.go +++ b/cmd/fpga_admissionwebhook/controller.go @@ -190,8 +190,7 @@ func (c *controller) syncAfHandler(key string) error { } klog.V(4).Info("Received", af) - patcher.addAf(af) - return nil + return patcher.addAf(af) } func (c *controller) syncRegionHandler(key string) error { diff --git a/cmd/fpga_admissionwebhook/patcher.go b/cmd/fpga_admissionwebhook/patcher.go index 582601898..5dd3a47cb 100644 --- a/cmd/fpga_admissionwebhook/patcher.go +++ b/cmd/fpga_admissionwebhook/patcher.go @@ -27,6 +27,7 @@ import ( "k8s.io/klog" fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + "github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga" ) const ( @@ -61,11 +62,6 @@ const ( {{- end -}} ] }` - - // Names of extended resources cannot be longer than 63 characters. - // Therefore for AF resources we have to cut the interface ID prefix - // to 31 characters only. - interfaceIDPrefixLength = 31 ) var ( @@ -88,18 +84,24 @@ func newPatcher() *patcher { } } -func (p *patcher) addAf(accfunc *fpgav1.AcceleratorFunction) { +func (p *patcher) addAf(accfunc *fpgav1.AcceleratorFunction) error { defer p.Unlock() p.Lock() p.afMap[namespace+"/"+accfunc.Name] = accfunc if accfunc.Spec.Mode == af { - p.resourceMap[namespace+"/"+accfunc.Name] = rfc6901Escaper.Replace(namespace + "/" + - accfunc.Spec.InterfaceID[:interfaceIDPrefixLength] + accfunc.Spec.AfuID) + devtype, err := fpga.GetAfuDevType(accfunc.Spec.InterfaceID, accfunc.Spec.AfuID) + if err != nil { + return err + } + + p.resourceMap[namespace+"/"+accfunc.Name] = rfc6901Escaper.Replace(namespace + "/" + devtype) } else { p.resourceMap[namespace+"/"+accfunc.Name] = rfc6901Escaper.Replace(namespace + "/region-" + accfunc.Spec.InterfaceID) } p.resourceModeMap[namespace+"/"+accfunc.Name] = accfunc.Spec.Mode + + return nil } func (p *patcher) addRegion(region *fpgav1.FpgaRegion) { diff --git a/cmd/fpga_plugin/dfl_test.go b/cmd/fpga_plugin/dfl_test.go index 25260b687..ba2728be6 100644 --- a/cmd/fpga_plugin/dfl_test.go +++ b/cmd/fpga_plugin/dfl_test.go @@ -240,7 +240,7 @@ func TestGetAfuTreeDFL(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice("ce48969398f05f33946d560708be108d8424dc4a4a3c413f89e433683f9040b", "dfl-port.0", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) + expected.AddDevice("af-ce4.d84.zkiWk5jwXzOUbVYHCL4QithCTcSko8QT-J5DNoP5BAs", "dfl-port.0", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -250,7 +250,7 @@ func TestGetAfuTreeDFL(t *testing.T) { }, } - expected.AddDevice("ce48969398f05f33946d560708be108d8424dc4a4a3c413f89e433683f9040b", "dfl-port.1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) + expected.AddDevice("af-ce4.d84.zkiWk5jwXzOUbVYHCL4QithCTcSko8QT-J5DNoP5BAs", "dfl-port.1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -259,7 +259,7 @@ func TestGetAfuTreeDFL(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice("ce48969398f05f33946d560708be108d8424dc4a4a3c413f89e433683f9040b", "dfl-port.2", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) + expected.AddDevice("af-ce4.d84.zkiWk5jwXzOUbVYHCL4QithCTcSko8QT-J5DNoP5BAs", "dfl-port.2", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -268,7 +268,7 @@ func TestGetAfuTreeDFL(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice(unhealthyInterfaceID[:interfaceIDPrefixLength]+unhealthyAfuID, "dfl-port.3", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil)) + expected.AddDevice("af-fff.fff.__________________________________________8", "dfl-port.3", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -277,7 +277,7 @@ func TestGetAfuTreeDFL(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice(unhealthyInterfaceID[:interfaceIDPrefixLength]+unhealthyAfuID, "dfl-port.4", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil)) + expected.AddDevice("af-fff.fff.__________________________________________8", "dfl-port.4", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil)) result := getAfuTree(getDevicesDFL()) if !reflect.DeepEqual(result, expected) { diff --git a/cmd/fpga_plugin/fpga_plugin.go b/cmd/fpga_plugin/fpga_plugin.go index cb214e505..eb58ec5dc 100644 --- a/cmd/fpga_plugin/fpga_plugin.go +++ b/cmd/fpga_plugin/fpga_plugin.go @@ -28,6 +28,7 @@ import ( pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1" dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin" + "github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga" "github.com/pkg/errors" ) @@ -51,11 +52,6 @@ const ( // Frequency of device scans scanFrequency = 5 * time.Second - - // Names of extended resources cannot be longer than 63 characters. - // Therefore for AF resources we have to cut the interface ID prefix - // to 31 characters only. - interfaceIDPrefixLength = 31 ) type getDevTreeFunc func(devices []device) dpapi.DeviceTree @@ -130,7 +126,11 @@ func getAfuTree(devices []device) dpapi.DeviceTree { if afu.afuID == unhealthyAfuID { health = pluginapi.Unhealthy } - devType := region.interfaceID[:interfaceIDPrefixLength] + afu.afuID + devType, err := fpga.GetAfuDevType(region.interfaceID, afu.afuID) + if err != nil { + klog.Warningf("failed to get devtype: %+v", err) + continue + } devNodes := []pluginapi.DeviceSpec{ { HostPath: afu.devNode, diff --git a/cmd/fpga_plugin/opae_test.go b/cmd/fpga_plugin/opae_test.go index 84181c621..d97e2ff1d 100644 --- a/cmd/fpga_plugin/opae_test.go +++ b/cmd/fpga_plugin/opae_test.go @@ -210,7 +210,7 @@ func TestGetAfuTreeOPAE(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice("ce48969398f05f33946d560708be108d8424dc4a4a3c413f89e433683f9040b", "intel-fpga-port.0", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) + expected.AddDevice("af-ce4.d84.zkiWk5jwXzOUbVYHCL4QithCTcSko8QT-J5DNoP5BAs", "intel-fpga-port.0", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -219,7 +219,7 @@ func TestGetAfuTreeOPAE(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice("ce48969398f05f33946d560708be108d8424dc4a4a3c413f89e433683f9040b", "intel-fpga-port.1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) + expected.AddDevice("af-ce4.d84.zkiWk5jwXzOUbVYHCL4QithCTcSko8QT-J5DNoP5BAs", "intel-fpga-port.1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil)) nodes = []pluginapi.DeviceSpec{ { @@ -228,7 +228,7 @@ func TestGetAfuTreeOPAE(t *testing.T) { Permissions: "rw", }, } - expected.AddDevice(unhealthyInterfaceID[:interfaceIDPrefixLength]+unhealthyAfuID, "intel-fpga-port.2", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil)) + expected.AddDevice("af-fff.fff.__________________________________________8", "intel-fpga-port.2", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil)) result := getAfuTree(getDevicesOPAE()) if !reflect.DeepEqual(result, expected) { diff --git a/deployments/fpga_admissionwebhook/mappings-collection.yaml b/deployments/fpga_admissionwebhook/mappings-collection.yaml index 09d666300..6498f3e58 100644 --- a/deployments/fpga_admissionwebhook/mappings-collection.yaml +++ b/deployments/fpga_admissionwebhook/mappings-collection.yaml @@ -9,7 +9,7 @@ spec: apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction metadata: - name: arria10.dcp1.0-nlb0 + name: arria10.dcp1.0-nlb0-orchestrated spec: afuId: d8424dc4a4a3c413f89e433683f9040b interfaceId: ce48969398f05f33946d560708be108a @@ -18,7 +18,7 @@ spec: apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction metadata: - name: arria10.dcp1.0-nlb3 + name: arria10.dcp1.0-nlb3-orchestrated spec: afuId: f7df405cbd7acf7222f144b0b93acd18 interfaceId: ce48969398f05f33946d560708be108a @@ -35,7 +35,7 @@ spec: apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction metadata: - name: arria10.dcp1.1-nlb0 + name: arria10.dcp1.1-nlb0-orchestrated spec: afuId: d8424dc4a4a3c413f89e433683f9040b interfaceId: 9926ab6d6c925a68aabca7d84c545738 @@ -44,7 +44,7 @@ spec: apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction metadata: - name: arria10.dcp1.1-nlb3 + name: arria10.dcp1.1-nlb3-orchestrated spec: afuId: f7df405cbd7acf7222f144b0b93acd18 interfaceId: 9926ab6d6c925a68aabca7d84c545738 @@ -61,7 +61,7 @@ spec: apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction metadata: - name: arria10.dcp1.2-nlb0 + name: arria10.dcp1.2-nlb0-orchestrated spec: afuId: d8424dc4a4a3c413f89e433683f9040b interfaceId: 69528db6eb31577a8c3668f9faa081f6 @@ -70,7 +70,16 @@ spec: apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction metadata: - name: arria10.dcp1.2-nlb3 + name: arria10.dcp1.2-nlb0-preprogrammed +spec: + afuId: d8424dc4a4a3c413f89e433683f9040b + interfaceId: 69528db6eb31577a8c3668f9faa081f6 + mode: af +--- +apiVersion: fpga.intel.com/v1 +kind: AcceleratorFunction +metadata: + name: arria10.dcp1.2-nlb3-orchestrated spec: afuId: f7df405cbd7acf7222f144b0b93acd18 interfaceId: 69528db6eb31577a8c3668f9faa081f6 @@ -87,7 +96,7 @@ spec: apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction metadata: - name: d5005-nlb0 + name: d5005-nlb0-orchestrated spec: afuId: d8424dc4a4a3c413f89e433683f9040b interfaceId: bfac4d851ee856fe8c95865ce1bbaa2d @@ -96,7 +105,7 @@ spec: apiVersion: fpga.intel.com/v1 kind: AcceleratorFunction metadata: - name: d5005-nlb3 + name: d5005-nlb3-orchestrated spec: afuId: f7df405cbd7acf7222f144b0b93acd18 interfaceId: bfac4d851ee856fe8c95865ce1bbaa2d diff --git a/pkg/fpga/devtypes.go b/pkg/fpga/devtypes.go new file mode 100644 index 000000000..5fc2b8f8d --- /dev/null +++ b/pkg/fpga/devtypes.go @@ -0,0 +1,36 @@ +// 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 fpga + +import ( + "encoding/base64" + "encoding/hex" + "fmt" + + "github.com/pkg/errors" +) + +// GetAfuDevType returns extended resource name for AFU without namespace. +// Since in Linux unix socket addresses can't be longer than 108 chars we need +// to compress devtype a bit, because it's used as a part of the socket's address. +// Also names of extended resources (without namespace) cannot be longer than 63 characters. +func GetAfuDevType(interfaceID, afuID string) (string, error) { + bin, err := hex.DecodeString(interfaceID + afuID) + if err != nil { + return "", errors.Wrapf(err, "failed to decode %q and %q", interfaceID, afuID) + } + + return fmt.Sprintf("af-%s.%s.%s", interfaceID[:3], afuID[:3], base64.RawURLEncoding.EncodeToString(bin)), nil +} diff --git a/pkg/fpga/devtypes_test.go b/pkg/fpga/devtypes_test.go new file mode 100644 index 000000000..996f558d7 --- /dev/null +++ b/pkg/fpga/devtypes_test.go @@ -0,0 +1,66 @@ +// 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 fpga + +import ( + "flag" + "testing" +) + +func init() { + flag.Set("v", "4") +} + +func TestGetAfuDevType(t *testing.T) { + tcases := []struct { + name string + interfaceID string + afuID string + expectedDevType string + expectedErr bool + }{ + { + name: "Everything is correct 1", + interfaceID: "ce48969398f05f33946d560708be108a", + afuID: "d8424dc4a4a3c413f89e433683f9040b", + expectedDevType: "af-ce4.d84.zkiWk5jwXzOUbVYHCL4QithCTcSko8QT-J5DNoP5BAs", + }, + { + name: "Everything is correct 2", + interfaceID: "bfac4d851ee856fe8c95865ce1bbaa2d", + afuID: "f7df405cbd7acf7222f144b0b93acd18", + expectedDevType: "af-bfa.f7d.v6xNhR7oVv6MlYZc4buqLfffQFy9es9yIvFEsLk6zRg", + }, + { + name: "unparsable interfaceID", + interfaceID: "unparsable", + expectedErr: true, + }, + } + for _, tt := range tcases { + t.Run(tt.name, func(t *testing.T) { + devtype, err := GetAfuDevType(tt.interfaceID, tt.afuID) + if tt.expectedErr && err == nil { + t.Errorf("no error returned") + } + if !tt.expectedErr && err != nil { + t.Errorf("unexpected error: %+v", err) + } + if tt.expectedDevType != devtype { + t.Errorf("expected %q, but got %q", tt.expectedDevType, devtype) + } + }) + } +} diff --git a/test/e2e/fpgaadmissionwebhook/fpgaadmissionwebhook.go b/test/e2e/fpgaadmissionwebhook/fpgaadmissionwebhook.go index 019e35fa7..ceb77f95d 100644 --- a/test/e2e/fpgaadmissionwebhook/fpgaadmissionwebhook.go +++ b/test/e2e/fpgaadmissionwebhook/fpgaadmissionwebhook.go @@ -57,7 +57,7 @@ func describe() { framework.ExpectNoError(err) checkPodMutation(f, "fpga.intel.com/d5005-nlb3-preprogrammed", - "fpga.intel.com/bfac4d851ee856fe8c95865ce1bbaa2f7df405cbd7acf7222f144b0b93acd18") + "fpga.intel.com/af-bfa.f7d.v6xNhR7oVv6MlYZc4buqLfffQFy9es9yIvFEsLk6zRg") }) ginkgo.It("mutates created pods to reference resolved Regions", func() { @@ -65,7 +65,7 @@ func describe() { _, _, err := framework.RunCmdEnv(getEnv(), webhookDeployPath, "--kubectl", framework.TestContext.KubectlPath, "--namespace", f.Namespace.Name) framework.ExpectNoError(err) - checkPodMutation(f, "fpga.intel.com/arria10.dcp1.0-nlb0", + checkPodMutation(f, "fpga.intel.com/arria10.dcp1.0-nlb0-orchestrated", "fpga.intel.com/region-ce48969398f05f33946d560708be108a") }) From 8d6afae23da30d9d1f076cacd68154e743150482 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Mon, 27 Apr 2020 19:25:21 +0300 Subject: [PATCH 3/4] fpga: update e2e tests to work with mode-less webhook Signed-off-by: Ed Bartosh --- test/e2e/fpga/fpga.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/test/e2e/fpga/fpga.go b/test/e2e/fpga/fpga.go index f6998af3c..5c05b5a9a 100644 --- a/test/e2e/fpga/fpga.go +++ b/test/e2e/fpga/fpga.go @@ -33,9 +33,10 @@ import ( const ( pluginDeployScript = "scripts/deploy-fpgaplugin.sh" webhookDeployScript = "scripts/webhook-deploy.sh" - nlb0NodeResource = "fpga.intel.com/af-d8424dc4a4a3c413f89e433683f9040b" - nlb0PodResource = "fpga.intel.com/arria10.dcp1.2-nlb0" - nlb3PodResource = "fpga.intel.com/arria10.dcp1.2-nlb3" + nlb0NodeResource = "fpga.intel.com/af-695.d84.aVKNtusxV3qMNmj5-qCB9thCTcSko8QT-J5DNoP5BAs" + nlb0PodResource = "fpga.intel.com/arria10.dcp1.2-nlb0-orchestrated" + nlb3PodResource = "fpga.intel.com/arria10.dcp1.2-nlb3-orchestrated" + nlb0PodResourceAF = "fpga.intel.com/arria10.dcp1.2-nlb0-preprogrammed" arria10NodeResource = "fpga.intel.com/region-69528db6eb31577a8c3668f9faa081f6" ) @@ -57,23 +58,23 @@ func describe() { fmw := framework.NewDefaultFramework("fpgaplugin-e2e") ginkgo.It("Run FPGA plugin tests", func() { + // Deploy webhook + ginkgo.By(fmt.Sprintf("namespace %s: deploying webhook", fmw.Namespace.Name)) + _, _, err := framework.RunCmd(webhookDeployScriptPath, "--namespace", fmw.Namespace.Name) + framework.ExpectNoError(err) + waitForPod(fmw, "intel-fpga-webhook") + // Run region test case twice to ensure that device is reprogrammed at least once - runTestCase(fmw, webhookDeployScriptPath, pluginDeployScriptPath, "region", "orchestrated", arria10NodeResource, nlb3PodResource, "nlb3", "nlb0") - runTestCase(fmw, webhookDeployScriptPath, pluginDeployScriptPath, "region", "orchestrated", arria10NodeResource, nlb0PodResource, "nlb0", "nlb3") + runTestCase(fmw, pluginDeployScriptPath, "region", arria10NodeResource, nlb3PodResource, "nlb3", "nlb0") + runTestCase(fmw, pluginDeployScriptPath, "region", arria10NodeResource, nlb0PodResource, "nlb0", "nlb3") // Run af test case - runTestCase(fmw, webhookDeployScriptPath, pluginDeployScriptPath, "af", "preprogrammed", nlb0NodeResource, nlb0PodResource, "nlb0", "nlb3") + runTestCase(fmw, pluginDeployScriptPath, "af", nlb0NodeResource, nlb0PodResourceAF, "nlb0", "nlb3") }) } -func runTestCase(fmw *framework.Framework, webhookDeployScriptPath, pluginDeployScriptPath, pluginMode, webhookMode, nodeResource, podResource, cmd1, cmd2 string) { - ginkgo.By(fmt.Sprintf("deploying webhook in %s mode", webhookMode)) - _, _, err := framework.RunCmd(webhookDeployScriptPath, "--mode", webhookMode, "--namespace", fmw.Namespace.Name) - framework.ExpectNoError(err) - - waitForPod(fmw, "intel-fpga-webhook") - - ginkgo.By(fmt.Sprintf("deploying FPGA plugin in %s mode", pluginMode)) - _, _, err = framework.RunCmd(pluginDeployScriptPath, "--mode", pluginMode, "--namespace", fmw.Namespace.Name) +func runTestCase(fmw *framework.Framework, pluginDeployScriptPath, pluginMode, nodeResource, podResource, cmd1, cmd2 string) { + ginkgo.By(fmt.Sprintf("namespace %s: deploying FPGA plugin in %s mode", fmw.Namespace.Name, pluginMode)) + _, _, err := framework.RunCmd(pluginDeployScriptPath, "--mode", pluginMode, "--namespace", fmw.Namespace.Name) framework.ExpectNoError(err) waitForPod(fmw, "intel-fpga-plugin") @@ -88,18 +89,17 @@ func runTestCase(fmw *framework.Framework, webhookDeployScriptPath, pluginDeploy image := "intel/opae-nlb-demo:devel" ginkgo.By("submitting a pod requesting correct FPGA resources") - pod := createPod(fmw, fmt.Sprintf("fpgaplugin-nlb-%s-%s-%s-correct", pluginMode, cmd1, cmd2), resource, image, []string{cmd1}) + pod := createPod(fmw, fmt.Sprintf("fpgaplugin-%s-%s-%s-correct", pluginMode, cmd1, cmd2), resource, image, []string{cmd1, "-S0"}) ginkgo.By("waiting the pod to finish successfully") fmw.PodClient().WaitForSuccess(pod.ObjectMeta.Name, 60*time.Second) // If WaitForSuccess fails, ginkgo doesn't show the logs of the failed container. // Replacing WaitForSuccess with WaitForFinish + 'kubelet logs' would show the logs - // fmw.PodClient().WaitForFinish(pod.ObjectMeta.Name, 60*time.Second) - // framework.RunKubectlOrDie(fmw.Namespace.Name, "--namespace", fmw.Namespace.Name, "logs", pod.ObjectMeta.Name) - // return + //fmw.PodClient().WaitForFinish(pod.ObjectMeta.Name, 60*time.Second) + //framework.RunKubectlOrDie(fmw.Namespace.Name, "--namespace", fmw.Namespace.Name, "logs", pod.ObjectMeta.Name) ginkgo.By("submitting a pod requesting incorrect FPGA resources") - pod = createPod(fmw, fmt.Sprintf("fpgaplugin-nlb-%s-%s-%s-incorrect", pluginMode, cmd1, cmd2), resource, image, []string{cmd2}) + pod = createPod(fmw, fmt.Sprintf("fpgaplugin-%s-%s-%s-incorrect", pluginMode, cmd1, cmd2), resource, image, []string{cmd2, "-S0"}) ginkgo.By("waiting the pod failure") utils.WaitForPodFailure(fmw, pod.ObjectMeta.Name, 60*time.Second) From c63dbf61b8b2c41b71a70d1bb375de9d8fa84985 Mon Sep 17 00:00:00 2001 From: Dmitry Rozhkov Date: Mon, 4 May 2020 15:03:52 +0300 Subject: [PATCH 4/4] fpgawebhook: move to v2 API of fpga.intel.com group --- DEVEL.md | 2 +- cmd/fpga_admissionwebhook/README.md | 2 +- cmd/fpga_admissionwebhook/controller.go | 6 +-- cmd/fpga_admissionwebhook/controller_test.go | 38 +++++++------- .../fpga_admissionwebhook_test.go | 6 +-- cmd/fpga_admissionwebhook/patcher.go | 10 ++-- cmd/fpga_admissionwebhook/patcher_test.go | 38 +++++++------- deployments/fpga_admissionwebhook/af-crd.yaml | 2 +- .../base/acceleratorfunctions.yaml | 16 +++--- .../fpga_admissionwebhook/base/regions.yaml | 8 +-- .../mappings-collection.yaml | 28 +++++------ .../fpga_admissionwebhook/region-crd.yaml | 2 +- pkg/apis/fpga.intel.com/{v1 => v2}/doc.go | 2 +- .../fpga.intel.com/{v1 => v2}/register.go | 4 +- pkg/apis/fpga.intel.com/{v1 => v2}/types.go | 2 +- .../{v1 => v2}/zz_generated.deepcopy.go | 2 +- pkg/client/clientset/versioned/clientset.go | 18 +++---- .../versioned/fake/clientset_generated.go | 10 ++-- .../clientset/versioned/fake/register.go | 4 +- .../clientset/versioned/scheme/register.go | 4 +- .../{v1 => v2}/acceleratorfunction.go | 50 +++++++++---------- .../typed/fpga.intel.com/{v1 => v2}/doc.go | 2 +- .../fpga.intel.com/{v1 => v2}/fake/doc.go | 0 .../fake/fake_acceleratorfunction.go | 44 ++++++++-------- .../fake/fake_fpga.intel.com_client.go | 10 ++-- .../{v1 => v2}/fake/fake_fpgaregion.go | 44 ++++++++-------- .../{v1 => v2}/fpga.intel.com_client.go | 34 ++++++------- .../fpga.intel.com/{v1 => v2}/fpgaregion.go | 50 +++++++++---------- .../{v1 => v2}/generated_expansion.go | 2 +- .../fpga.intel.com/interface.go | 12 ++--- .../{v1 => v2}/acceleratorfunction.go | 26 +++++----- .../fpga.intel.com/{v1 => v2}/fpgaregion.go | 26 +++++----- .../fpga.intel.com/{v1 => v2}/interface.go | 2 +- .../informers/externalversions/generic.go | 12 ++--- .../{v1 => v2}/acceleratorfunction.go | 24 ++++----- .../{v1 => v2}/expansion_generated.go | 2 +- .../fpga.intel.com/{v1 => v2}/fpgaregion.go | 24 ++++----- scripts/update-generated-code.sh | 2 +- 38 files changed, 285 insertions(+), 285 deletions(-) rename pkg/apis/fpga.intel.com/{v1 => v2}/doc.go (86%) rename pkg/apis/fpga.intel.com/{v1 => v2}/register.go (97%) rename pkg/apis/fpga.intel.com/{v1 => v2}/types.go (99%) rename pkg/apis/fpga.intel.com/{v1 => v2}/zz_generated.deepcopy.go (99%) rename pkg/client/clientset/versioned/typed/fpga.intel.com/{v1 => v2}/acceleratorfunction.go (71%) rename pkg/client/clientset/versioned/typed/fpga.intel.com/{v1 => v2}/doc.go (98%) rename pkg/client/clientset/versioned/typed/fpga.intel.com/{v1 => v2}/fake/doc.go (100%) rename pkg/client/clientset/versioned/typed/fpga.intel.com/{v1 => v2}/fake/fake_acceleratorfunction.go (70%) rename pkg/client/clientset/versioned/typed/fpga.intel.com/{v1 => v2}/fake/fake_fpga.intel.com_client.go (76%) rename pkg/client/clientset/versioned/typed/fpga.intel.com/{v1 => v2}/fake/fake_fpgaregion.go (74%) rename pkg/client/clientset/versioned/typed/fpga.intel.com/{v1 => v2}/fpga.intel.com_client.go (68%) rename pkg/client/clientset/versioned/typed/fpga.intel.com/{v1 => v2}/fpgaregion.go (70%) rename pkg/client/clientset/versioned/typed/fpga.intel.com/{v1 => v2}/generated_expansion.go (98%) rename pkg/client/informers/externalversions/fpga.intel.com/{v1 => v2}/acceleratorfunction.go (80%) rename pkg/client/informers/externalversions/fpga.intel.com/{v1 => v2}/fpgaregion.go (79%) rename pkg/client/informers/externalversions/fpga.intel.com/{v1 => v2}/interface.go (99%) rename pkg/client/listers/fpga.intel.com/{v1 => v2}/acceleratorfunction.go (83%) rename pkg/client/listers/fpga.intel.com/{v1 => v2}/expansion_generated.go (99%) rename pkg/client/listers/fpga.intel.com/{v1 => v2}/fpgaregion.go (82%) diff --git a/DEVEL.md b/DEVEL.md index 49bd41813..df3e43b42 100644 --- a/DEVEL.md +++ b/DEVEL.md @@ -162,7 +162,7 @@ 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:v1 + fpga.intel.com:v2 ``` Please note that the script (at least of v0.18.2-beta.0) expects the device plugins diff --git a/cmd/fpga_admissionwebhook/README.md b/cmd/fpga_admissionwebhook/README.md index a253620f6..aec4a6128 100644 --- a/cmd/fpga_admissionwebhook/README.md +++ b/cmd/fpga_admissionwebhook/README.md @@ -128,7 +128,7 @@ translated into actual resources provided by the cluster. For the following mapping ```yaml -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.2-nlb0-preprogrammed diff --git a/cmd/fpga_admissionwebhook/controller.go b/cmd/fpga_admissionwebhook/controller.go index 543c468dc..30b6b71cc 100644 --- a/cmd/fpga_admissionwebhook/controller.go +++ b/cmd/fpga_admissionwebhook/controller.go @@ -29,7 +29,7 @@ import ( 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/v1" + listers "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/listers/fpga.intel.com/v2" ) const ( @@ -61,8 +61,8 @@ func newController(patcherManager patcherManager, config *rest.Config) (*control informerFactory := informers.NewSharedInformerFactory(clientset, resyncPeriod) stopCh := make(chan struct{}) - afInformer := informerFactory.Fpga().V1().AcceleratorFunctions() - regionInformer := informerFactory.Fpga().V1().FpgaRegions() + afInformer := informerFactory.Fpga().V2().AcceleratorFunctions() + regionInformer := informerFactory.Fpga().V2().FpgaRegions() controller := &controller{ patcherManager: patcherManager, diff --git a/cmd/fpga_admissionwebhook/controller_test.go b/cmd/fpga_admissionwebhook/controller_test.go index 0c44afd58..59a0dc1bb 100644 --- a/cmd/fpga_admissionwebhook/controller_test.go +++ b/cmd/fpga_admissionwebhook/controller_test.go @@ -24,12 +24,12 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/rest" - v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" - listers "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/listers/fpga.intel.com/v1" + 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 *v1.AcceleratorFunction + af *v2.AcceleratorFunction err error } @@ -37,16 +37,16 @@ func init() { flag.Set("v", "4") ///Enable debug output } -func (nl *fakeAfNamespaceLister) Get(name string) (*v1.AcceleratorFunction, error) { +func (nl *fakeAfNamespaceLister) Get(name string) (*v2.AcceleratorFunction, error) { return nl.af, nl.err } -func (nl *fakeAfNamespaceLister) List(selector labels.Selector) (ret []*v1.AcceleratorFunction, err error) { +func (nl *fakeAfNamespaceLister) List(selector labels.Selector) (ret []*v2.AcceleratorFunction, err error) { return nil, nil } type fakeAfLister struct { - af *v1.AcceleratorFunction + af *v2.AcceleratorFunction err error } @@ -57,7 +57,7 @@ func (l *fakeAfLister) AcceleratorFunctions(namespace string) listers.Accelerato } } -func (l *fakeAfLister) List(selector labels.Selector) (ret []*v1.AcceleratorFunction, err error) { +func (l *fakeAfLister) List(selector labels.Selector) (ret []*v2.AcceleratorFunction, err error) { return nil, nil } @@ -76,11 +76,11 @@ func TestSyncAfHandler(t *testing.T) { name: "Known key", key: "default/arria10-nlb0", afLister: &fakeAfLister{ - af: &v1.AcceleratorFunction{ + af: &v2.AcceleratorFunction{ ObjectMeta: metav1.ObjectMeta{ Name: "arria10-nlb0", }, - Spec: v1.AcceleratorFunctionSpec{ + Spec: v2.AcceleratorFunctionSpec{ AfuID: "d8424dc4a4a3c413f89e433683f9040b", }, }, @@ -120,20 +120,20 @@ func TestSyncAfHandler(t *testing.T) { } type fakeRegionNamespaceLister struct { - region *v1.FpgaRegion + region *v2.FpgaRegion err error } -func (nl *fakeRegionNamespaceLister) Get(name string) (*v1.FpgaRegion, error) { +func (nl *fakeRegionNamespaceLister) Get(name string) (*v2.FpgaRegion, error) { return nl.region, nl.err } -func (nl *fakeRegionNamespaceLister) List(selector labels.Selector) (ret []*v1.FpgaRegion, err error) { +func (nl *fakeRegionNamespaceLister) List(selector labels.Selector) (ret []*v2.FpgaRegion, err error) { return nil, nil } type fakeRegionLister struct { - region *v1.FpgaRegion + region *v2.FpgaRegion err error } @@ -144,7 +144,7 @@ func (l *fakeRegionLister) FpgaRegions(namespace string) listers.FpgaRegionNames } } -func (l *fakeRegionLister) List(selector labels.Selector) (ret []*v1.FpgaRegion, err error) { +func (l *fakeRegionLister) List(selector labels.Selector) (ret []*v2.FpgaRegion, err error) { return nil, nil } @@ -163,11 +163,11 @@ func TestSyncRegionHandler(t *testing.T) { name: "Known key", key: "default/arria10", regionLister: &fakeRegionLister{ - region: &v1.FpgaRegion{ + region: &v2.FpgaRegion{ ObjectMeta: metav1.ObjectMeta{ Name: "arria10", }, - Spec: v1.FpgaRegionSpec{ + Spec: v2.FpgaRegionSpec{ InterfaceID: "ce48969398f05f33946d560708be108a", }, }, @@ -328,9 +328,9 @@ func TestProcessNextWorkItem(t *testing.T) { func TestCreateEventhandler(t *testing.T) { funcs := createEventHandler("testkind", &fakeQueue{}) - funcs.AddFunc(&v1.FpgaRegion{}) - funcs.UpdateFunc(nil, &v1.FpgaRegion{}) - funcs.DeleteFunc(&v1.FpgaRegion{}) + funcs.AddFunc(&v2.FpgaRegion{}) + funcs.UpdateFunc(nil, &v2.FpgaRegion{}) + funcs.DeleteFunc(&v2.FpgaRegion{}) } func TestRun(t *testing.T) { diff --git a/cmd/fpga_admissionwebhook/fpga_admissionwebhook_test.go b/cmd/fpga_admissionwebhook/fpga_admissionwebhook_test.go index 5a4b3d301..910207c52 100644 --- a/cmd/fpga_admissionwebhook/fpga_admissionwebhook_test.go +++ b/cmd/fpga_admissionwebhook/fpga_admissionwebhook_test.go @@ -24,7 +24,7 @@ import ( "strings" "testing" - fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" @@ -239,11 +239,11 @@ func TestMutatePods(t *testing.T) { for _, tcase := range tcases { t.Run(tcase.name, func(t *testing.T) { p := newPatcher() - p.addRegion(&fpgav1.FpgaRegion{ + p.addRegion(&fpgav2.FpgaRegion{ ObjectMeta: metav1.ObjectMeta{ Name: "arria10", }, - Spec: fpgav1.FpgaRegionSpec{ + Spec: fpgav2.FpgaRegionSpec{ InterfaceID: "ce48969398f05f33946d560708be108a", }, }) diff --git a/cmd/fpga_admissionwebhook/patcher.go b/cmd/fpga_admissionwebhook/patcher.go index 5dd3a47cb..9b34ca95a 100644 --- a/cmd/fpga_admissionwebhook/patcher.go +++ b/cmd/fpga_admissionwebhook/patcher.go @@ -26,7 +26,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/klog" - fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" ) @@ -71,20 +71,20 @@ var ( type patcher struct { sync.Mutex - afMap map[string]*fpgav1.AcceleratorFunction + afMap map[string]*fpgav2.AcceleratorFunction resourceMap map[string]string resourceModeMap map[string]string } func newPatcher() *patcher { return &patcher{ - afMap: make(map[string]*fpgav1.AcceleratorFunction), + afMap: make(map[string]*fpgav2.AcceleratorFunction), resourceMap: make(map[string]string), resourceModeMap: make(map[string]string), } } -func (p *patcher) addAf(accfunc *fpgav1.AcceleratorFunction) error { +func (p *patcher) addAf(accfunc *fpgav2.AcceleratorFunction) error { defer p.Unlock() p.Lock() @@ -104,7 +104,7 @@ func (p *patcher) addAf(accfunc *fpgav1.AcceleratorFunction) error { return nil } -func (p *patcher) addRegion(region *fpgav1.FpgaRegion) { +func (p *patcher) addRegion(region *fpgav2.FpgaRegion) { defer p.Unlock() p.Lock() diff --git a/cmd/fpga_admissionwebhook/patcher_test.go b/cmd/fpga_admissionwebhook/patcher_test.go index 401aa003f..6be68b540 100644 --- a/cmd/fpga_admissionwebhook/patcher_test.go +++ b/cmd/fpga_admissionwebhook/patcher_test.go @@ -22,7 +22,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + fpgav2 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v2" ) func init() { @@ -30,19 +30,19 @@ func init() { } func TestPatcherStorageFunctions(t *testing.T) { - af := &fpgav1.AcceleratorFunction{ + af := &fpgav2.AcceleratorFunction{ ObjectMeta: metav1.ObjectMeta{ Name: "arria10-nlb0", }, - Spec: fpgav1.AcceleratorFunctionSpec{ + Spec: fpgav2.AcceleratorFunctionSpec{ AfuID: "d8424dc4a4a3c413f89e433683f9040b", }, } - region := &fpgav1.FpgaRegion{ + region := &fpgav2.FpgaRegion{ ObjectMeta: metav1.ObjectMeta{ Name: "arria10", }, - Spec: fpgav1.FpgaRegionSpec{ + Spec: fpgav2.FpgaRegionSpec{ InterfaceID: "ce48969398f05f33946d560708be108a", }, } @@ -74,8 +74,8 @@ func TestGetPatchOps(t *testing.T) { tcases := []struct { name string container corev1.Container - afs []*fpgav1.AcceleratorFunction - regions []*fpgav1.FpgaRegion + afs []*fpgav2.AcceleratorFunction + regions []*fpgav2.FpgaRegion expectedErr bool expectedOps int }{ @@ -101,12 +101,12 @@ func TestGetPatchOps(t *testing.T) { }, }, }, - afs: []*fpgav1.AcceleratorFunction{ + afs: []*fpgav2.AcceleratorFunction{ { ObjectMeta: metav1.ObjectMeta{ Name: "arria10-nlb0", }, - Spec: fpgav1.AcceleratorFunctionSpec{ + Spec: fpgav2.AcceleratorFunctionSpec{ AfuID: "d8424dc4a4a3c413f89e433683f9040b", InterfaceID: "ce48969398f05f33946d560708be108a", Mode: region, @@ -116,7 +116,7 @@ func TestGetPatchOps(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "arria10-nlb0-alias", }, - Spec: fpgav1.AcceleratorFunctionSpec{ + Spec: fpgav2.AcceleratorFunctionSpec{ AfuID: "d8424dc4a4a3c413f89e433683f9040b", InterfaceID: "ce48969398f05f33946d560708be108a", Mode: region, @@ -137,12 +137,12 @@ func TestGetPatchOps(t *testing.T) { }, }, }, - afs: []*fpgav1.AcceleratorFunction{ + afs: []*fpgav2.AcceleratorFunction{ { ObjectMeta: metav1.ObjectMeta{ Name: "arria10-nlb0", }, - Spec: fpgav1.AcceleratorFunctionSpec{ + Spec: fpgav2.AcceleratorFunctionSpec{ AfuID: "d8424dc4a4a3c413f89e433683f9040b", InterfaceID: "ce48969398f05f33946d560708be108a", Mode: af, @@ -163,12 +163,12 @@ func TestGetPatchOps(t *testing.T) { }, }, }, - regions: []*fpgav1.FpgaRegion{ + regions: []*fpgav2.FpgaRegion{ { ObjectMeta: metav1.ObjectMeta{ Name: "arria10", }, - Spec: fpgav1.FpgaRegionSpec{ + Spec: fpgav2.FpgaRegionSpec{ InterfaceID: "ce48969398f05f33946d560708be108a", }, }, @@ -260,12 +260,12 @@ func TestGetPatchOps(t *testing.T) { }, }, }, - afs: []*fpgav1.AcceleratorFunction{ + afs: []*fpgav2.AcceleratorFunction{ { ObjectMeta: metav1.ObjectMeta{ Name: "arria10-nlb0", }, - Spec: fpgav1.AcceleratorFunctionSpec{ + Spec: fpgav2.AcceleratorFunctionSpec{ AfuID: "d8424dc4a4a3c413f89e433683f9040b", InterfaceID: "ce48969398f05f33946d560708be108a", Mode: region, @@ -275,7 +275,7 @@ func TestGetPatchOps(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "arria10-nlb3", }, - Spec: fpgav1.AcceleratorFunctionSpec{ + Spec: fpgav2.AcceleratorFunctionSpec{ AfuID: "d8424dc4a4a3c413f89e433683f9040b", InterfaceID: "f7df405cbd7acf7222f144b0b93acd18", Mode: af, @@ -296,12 +296,12 @@ func TestGetPatchOps(t *testing.T) { }, }, }, - afs: []*fpgav1.AcceleratorFunction{ + afs: []*fpgav2.AcceleratorFunction{ { ObjectMeta: metav1.ObjectMeta{ Name: "arria10-nlb0", }, - Spec: fpgav1.AcceleratorFunctionSpec{ + Spec: fpgav2.AcceleratorFunctionSpec{ AfuID: "d8424dc4a4a3c413f89e433683f9040b", InterfaceID: "ce48969398f05f33946d560708be108a", Mode: "unknown", diff --git a/deployments/fpga_admissionwebhook/af-crd.yaml b/deployments/fpga_admissionwebhook/af-crd.yaml index cdfc50724..2f6452bd4 100644 --- a/deployments/fpga_admissionwebhook/af-crd.yaml +++ b/deployments/fpga_admissionwebhook/af-crd.yaml @@ -4,7 +4,7 @@ metadata: name: acceleratorfunctions.fpga.intel.com spec: group: fpga.intel.com - version: v1 + version: v2 scope: Namespaced names: plural: acceleratorfunctions diff --git a/deployments/fpga_admissionwebhook/base/acceleratorfunctions.yaml b/deployments/fpga_admissionwebhook/base/acceleratorfunctions.yaml index 39abaeb6a..8eeb8b4fd 100644 --- a/deployments/fpga_admissionwebhook/base/acceleratorfunctions.yaml +++ b/deployments/fpga_admissionwebhook/base/acceleratorfunctions.yaml @@ -1,12 +1,12 @@ # DCP 1.0 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.0-nlb0 spec: afuId: d8424dc4a4a3c413f89e433683f9040b --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.0-nlb3 @@ -14,14 +14,14 @@ spec: afuId: f7df405cbd7acf7222f144b0b93acd18 --- # DCP 1.1 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.1-nlb0 spec: afuId: d8424dc4a4a3c413f89e433683f9040b --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.1-nlb3 @@ -29,14 +29,14 @@ spec: afuId: f7df405cbd7acf7222f144b0b93acd18 --- # DCP 1.2 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.2-nlb0 spec: afuId: d8424dc4a4a3c413f89e433683f9040b --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.2-nlb3 @@ -44,14 +44,14 @@ spec: afuId: f7df405cbd7acf7222f144b0b93acd18 --- # D5005 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: d5005-nlb0 spec: afuId: d8424dc4a4a3c413f89e433683f9040b --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: d5005-nlb3 diff --git a/deployments/fpga_admissionwebhook/base/regions.yaml b/deployments/fpga_admissionwebhook/base/regions.yaml index 5fabf413a..a9f84e521 100644 --- a/deployments/fpga_admissionwebhook/base/regions.yaml +++ b/deployments/fpga_admissionwebhook/base/regions.yaml @@ -1,5 +1,5 @@ # DCP 1.0 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: FpgaRegion metadata: name: arria10.dcp1.0 @@ -7,7 +7,7 @@ spec: interfaceId: ce48969398f05f33946d560708be108a --- # DCP 1.1 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: FpgaRegion metadata: name: arria10.dcp1.1 @@ -15,7 +15,7 @@ spec: interfaceId: 9926ab6d6c925a68aabca7d84c545738 --- # DCP 1.2 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: FpgaRegion metadata: name: arria10.dcp1.2 @@ -23,7 +23,7 @@ spec: interfaceId: 69528db6eb31577a8c3668f9faa081f6 --- # D5005 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: FpgaRegion metadata: name: d5005 diff --git a/deployments/fpga_admissionwebhook/mappings-collection.yaml b/deployments/fpga_admissionwebhook/mappings-collection.yaml index 6498f3e58..68054cf9a 100644 --- a/deployments/fpga_admissionwebhook/mappings-collection.yaml +++ b/deployments/fpga_admissionwebhook/mappings-collection.yaml @@ -1,12 +1,12 @@ # DCP 1.0 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: FpgaRegion metadata: name: arria10.dcp1.0 spec: interfaceId: ce48969398f05f33946d560708be108a --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.0-nlb0-orchestrated @@ -15,7 +15,7 @@ spec: interfaceId: ce48969398f05f33946d560708be108a mode: region --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.0-nlb3-orchestrated @@ -25,14 +25,14 @@ spec: mode: region --- # DCP 1.1 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: FpgaRegion metadata: name: arria10.dcp1.1 spec: interfaceId: 9926ab6d6c925a68aabca7d84c545738 --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.1-nlb0-orchestrated @@ -41,7 +41,7 @@ spec: interfaceId: 9926ab6d6c925a68aabca7d84c545738 mode: region --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.1-nlb3-orchestrated @@ -51,14 +51,14 @@ spec: mode: region --- # DCP 1.2 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: FpgaRegion metadata: name: arria10.dcp1.2 spec: interfaceId: 69528db6eb31577a8c3668f9faa081f6 --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.2-nlb0-orchestrated @@ -67,7 +67,7 @@ spec: interfaceId: 69528db6eb31577a8c3668f9faa081f6 mode: region --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.2-nlb0-preprogrammed @@ -76,7 +76,7 @@ spec: interfaceId: 69528db6eb31577a8c3668f9faa081f6 mode: af --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: arria10.dcp1.2-nlb3-orchestrated @@ -86,14 +86,14 @@ spec: mode: region --- # D5005 -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: FpgaRegion metadata: name: d5005 spec: interfaceId: bfac4d851ee856fe8c95865ce1bbaa2d --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: d5005-nlb0-orchestrated @@ -102,7 +102,7 @@ spec: interfaceId: bfac4d851ee856fe8c95865ce1bbaa2d mode: region --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: d5005-nlb3-orchestrated @@ -111,7 +111,7 @@ spec: interfaceId: bfac4d851ee856fe8c95865ce1bbaa2d mode: region --- -apiVersion: fpga.intel.com/v1 +apiVersion: fpga.intel.com/v2 kind: AcceleratorFunction metadata: name: d5005-nlb3-preprogrammed diff --git a/deployments/fpga_admissionwebhook/region-crd.yaml b/deployments/fpga_admissionwebhook/region-crd.yaml index d8a7ab29e..d5dcc8c5f 100644 --- a/deployments/fpga_admissionwebhook/region-crd.yaml +++ b/deployments/fpga_admissionwebhook/region-crd.yaml @@ -4,7 +4,7 @@ metadata: name: fpgaregions.fpga.intel.com spec: group: fpga.intel.com - version: v1 + version: v2 scope: Namespaced names: plural: fpgaregions diff --git a/pkg/apis/fpga.intel.com/v1/doc.go b/pkg/apis/fpga.intel.com/v2/doc.go similarity index 86% rename from pkg/apis/fpga.intel.com/v1/doc.go rename to pkg/apis/fpga.intel.com/v2/doc.go index 4f445318e..dabb34300 100644 --- a/pkg/apis/fpga.intel.com/v1/doc.go +++ b/pkg/apis/fpga.intel.com/v2/doc.go @@ -2,4 +2,4 @@ // +groupName=fpga.intel.com -package v1 +package v2 diff --git a/pkg/apis/fpga.intel.com/v1/register.go b/pkg/apis/fpga.intel.com/v2/register.go similarity index 97% rename from pkg/apis/fpga.intel.com/v1/register.go rename to pkg/apis/fpga.intel.com/v2/register.go index d6bcf793c..1c4645883 100644 --- a/pkg/apis/fpga.intel.com/v1/register.go +++ b/pkg/apis/fpga.intel.com/v2/register.go @@ -1,4 +1,4 @@ -package v1 +package v2 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -9,7 +9,7 @@ import ( ) // SchemeGroupVersion is group version used to register these objects -var SchemeGroupVersion = schema.GroupVersion{Group: fpgaintel.GroupName, Version: "v1"} +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 { diff --git a/pkg/apis/fpga.intel.com/v1/types.go b/pkg/apis/fpga.intel.com/v2/types.go similarity index 99% rename from pkg/apis/fpga.intel.com/v1/types.go rename to pkg/apis/fpga.intel.com/v2/types.go index fbe000c94..218168432 100644 --- a/pkg/apis/fpga.intel.com/v1/types.go +++ b/pkg/apis/fpga.intel.com/v2/types.go @@ -1,4 +1,4 @@ -package v1 +package v2 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/apis/fpga.intel.com/v1/zz_generated.deepcopy.go b/pkg/apis/fpga.intel.com/v2/zz_generated.deepcopy.go similarity index 99% rename from pkg/apis/fpga.intel.com/v1/zz_generated.deepcopy.go rename to pkg/apis/fpga.intel.com/v2/zz_generated.deepcopy.go index 2cc346923..50f7652d8 100644 --- a/pkg/apis/fpga.intel.com/v1/zz_generated.deepcopy.go +++ b/pkg/apis/fpga.intel.com/v2/zz_generated.deepcopy.go @@ -16,7 +16,7 @@ // Code generated by deepcopy-gen. DO NOT EDIT. -package v1 +package v2 import ( runtime "k8s.io/apimachinery/pkg/runtime" diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index 23b58ff16..4eb25ce3b 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -19,7 +19,7 @@ package versioned import ( "fmt" - fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned/typed/fpga.intel.com/v1" + 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" @@ -27,19 +27,19 @@ import ( type Interface interface { Discovery() discovery.DiscoveryInterface - FpgaV1() fpgav1.FpgaV1Interface + FpgaV2() fpgav2.FpgaV2Interface } // Clientset contains the clients for groups. Each group has exactly one // version included in a Clientset. type Clientset struct { *discovery.DiscoveryClient - fpgaV1 *fpgav1.FpgaV1Client + fpgaV2 *fpgav2.FpgaV2Client } -// FpgaV1 retrieves the FpgaV1Client -func (c *Clientset) FpgaV1() fpgav1.FpgaV1Interface { - return c.fpgaV1 +// FpgaV2 retrieves the FpgaV2Client +func (c *Clientset) FpgaV2() fpgav2.FpgaV2Interface { + return c.fpgaV2 } // Discovery retrieves the DiscoveryClient @@ -63,7 +63,7 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { } var cs Clientset var err error - cs.fpgaV1, err = fpgav1.NewForConfig(&configShallowCopy) + cs.fpgaV2, err = fpgav2.NewForConfig(&configShallowCopy) if err != nil { return nil, err } @@ -79,7 +79,7 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { // panics if there is an error in the config. func NewForConfigOrDie(c *rest.Config) *Clientset { var cs Clientset - cs.fpgaV1 = fpgav1.NewForConfigOrDie(c) + cs.fpgaV2 = fpgav2.NewForConfigOrDie(c) cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) return &cs @@ -88,7 +88,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { // New creates a new Clientset for the given RESTClient. func New(c rest.Interface) *Clientset { var cs Clientset - cs.fpgaV1 = fpgav1.New(c) + cs.fpgaV2 = fpgav2.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) return &cs diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index e62f2934f..8646d1ada 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -18,8 +18,8 @@ package fake import ( clientset "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned" - fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned/typed/fpga.intel.com/v1" - fakefpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake" + 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" @@ -74,7 +74,7 @@ func (c *Clientset) Tracker() testing.ObjectTracker { var _ clientset.Interface = &Clientset{} -// FpgaV1 retrieves the FpgaV1Client -func (c *Clientset) FpgaV1() fpgav1.FpgaV1Interface { - return &fakefpgav1.FakeFpgaV1{Fake: &c.Fake} +// FpgaV2 retrieves the FpgaV2Client +func (c *Clientset) FpgaV2() fpgav2.FpgaV2Interface { + return &fakefpgav2.FakeFpgaV2{Fake: &c.Fake} } diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 45ad3e0e3..ba0255af5 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -17,7 +17,7 @@ package fake import ( - fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" @@ -29,7 +29,7 @@ var scheme = runtime.NewScheme() var codecs = serializer.NewCodecFactory(scheme) var parameterCodec = runtime.NewParameterCodec(scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - fpgav1.AddToScheme, + fpgav2.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index 2d4af4225..f3523ba30 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -17,7 +17,7 @@ package scheme import ( - fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" @@ -29,7 +29,7 @@ var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - fpgav1.AddToScheme, + fpgav2.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/acceleratorfunction.go b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/acceleratorfunction.go similarity index 71% rename from pkg/client/clientset/versioned/typed/fpga.intel.com/v1/acceleratorfunction.go rename to pkg/client/clientset/versioned/typed/fpga.intel.com/v2/acceleratorfunction.go index fd00ce8bf..c0faf558a 100644 --- a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/acceleratorfunction.go +++ b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/acceleratorfunction.go @@ -14,15 +14,15 @@ // Code generated by client-gen. DO NOT EDIT. -package v1 +package v2 import ( "context" "time" - v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + 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" @@ -36,14 +36,14 @@ type AcceleratorFunctionsGetter interface { // AcceleratorFunctionInterface has methods to work with AcceleratorFunction resources. type AcceleratorFunctionInterface interface { - Create(ctx context.Context, acceleratorFunction *v1.AcceleratorFunction, opts metav1.CreateOptions) (*v1.AcceleratorFunction, error) - Update(ctx context.Context, acceleratorFunction *v1.AcceleratorFunction, opts metav1.UpdateOptions) (*v1.AcceleratorFunction, error) - Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.AcceleratorFunction, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.AcceleratorFunctionList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.AcceleratorFunction, err error) + 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 } @@ -54,7 +54,7 @@ type acceleratorFunctions struct { } // newAcceleratorFunctions returns a AcceleratorFunctions -func newAcceleratorFunctions(c *FpgaV1Client, namespace string) *acceleratorFunctions { +func newAcceleratorFunctions(c *FpgaV2Client, namespace string) *acceleratorFunctions { return &acceleratorFunctions{ client: c.RESTClient(), ns: namespace, @@ -62,8 +62,8 @@ func newAcceleratorFunctions(c *FpgaV1Client, namespace string) *acceleratorFunc } // 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 metav1.GetOptions) (result *v1.AcceleratorFunction, err error) { - result = &v1.AcceleratorFunction{} +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"). @@ -75,12 +75,12 @@ func (c *acceleratorFunctions) Get(ctx context.Context, name string, options met } // List takes label and field selectors, and returns the list of AcceleratorFunctions that match those selectors. -func (c *acceleratorFunctions) List(ctx context.Context, opts metav1.ListOptions) (result *v1.AcceleratorFunctionList, err error) { +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 = &v1.AcceleratorFunctionList{} + result = &v2.AcceleratorFunctionList{} err = c.client.Get(). Namespace(c.ns). Resource("acceleratorfunctions"). @@ -92,7 +92,7 @@ func (c *acceleratorFunctions) List(ctx context.Context, opts metav1.ListOptions } // Watch returns a watch.Interface that watches the requested acceleratorFunctions. -func (c *acceleratorFunctions) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { +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 @@ -107,8 +107,8 @@ func (c *acceleratorFunctions) Watch(ctx context.Context, opts metav1.ListOption } // 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 *v1.AcceleratorFunction, opts metav1.CreateOptions) (result *v1.AcceleratorFunction, err error) { - result = &v1.AcceleratorFunction{} +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"). @@ -120,8 +120,8 @@ func (c *acceleratorFunctions) Create(ctx context.Context, acceleratorFunction * } // 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 *v1.AcceleratorFunction, opts metav1.UpdateOptions) (result *v1.AcceleratorFunction, err error) { - result = &v1.AcceleratorFunction{} +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"). @@ -134,7 +134,7 @@ func (c *acceleratorFunctions) Update(ctx context.Context, acceleratorFunction * } // 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 metav1.DeleteOptions) error { +func (c *acceleratorFunctions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { return c.client.Delete(). Namespace(c.ns). Resource("acceleratorfunctions"). @@ -145,7 +145,7 @@ func (c *acceleratorFunctions) Delete(ctx context.Context, name string, opts met } // DeleteCollection deletes a collection of objects. -func (c *acceleratorFunctions) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { +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 @@ -161,8 +161,8 @@ func (c *acceleratorFunctions) DeleteCollection(ctx context.Context, opts metav1 } // Patch applies the patch and returns the patched acceleratorFunction. -func (c *acceleratorFunctions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.AcceleratorFunction, err error) { - result = &v1.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"). diff --git a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/doc.go b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/doc.go similarity index 98% rename from pkg/client/clientset/versioned/typed/fpga.intel.com/v1/doc.go rename to pkg/client/clientset/versioned/typed/fpga.intel.com/v2/doc.go index 6bb5f79ee..871f6f2e7 100644 --- a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/doc.go +++ b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/doc.go @@ -15,4 +15,4 @@ // Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated typed clients. -package v1 +package v2 diff --git a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake/doc.go b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake/doc.go similarity index 100% rename from pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake/doc.go rename to pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake/doc.go diff --git a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake/fake_acceleratorfunction.go b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake/fake_acceleratorfunction.go similarity index 70% rename from pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake/fake_acceleratorfunction.go rename to pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake/fake_acceleratorfunction.go index 3988156af..3fb37b20c 100644 --- a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake/fake_acceleratorfunction.go +++ b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake/fake_acceleratorfunction.go @@ -19,7 +19,7 @@ package fake import ( "context" - fpgaintelcomv1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" @@ -30,29 +30,29 @@ import ( // FakeAcceleratorFunctions implements AcceleratorFunctionInterface type FakeAcceleratorFunctions struct { - Fake *FakeFpgaV1 + Fake *FakeFpgaV2 ns string } -var acceleratorfunctionsResource = schema.GroupVersionResource{Group: "fpga.intel.com", Version: "v1", Resource: "acceleratorfunctions"} +var acceleratorfunctionsResource = schema.GroupVersionResource{Group: "fpga.intel.com", Version: "v2", Resource: "acceleratorfunctions"} -var acceleratorfunctionsKind = schema.GroupVersionKind{Group: "fpga.intel.com", Version: "v1", Kind: "AcceleratorFunction"} +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 *fpgaintelcomv1.AcceleratorFunction, err error) { +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), &fpgaintelcomv1.AcceleratorFunction{}) + Invokes(testing.NewGetAction(acceleratorfunctionsResource, c.ns, name), &v2.AcceleratorFunction{}) if obj == nil { return nil, err } - return obj.(*fpgaintelcomv1.AcceleratorFunction), 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 *fpgaintelcomv1.AcceleratorFunctionList, err error) { +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), &fpgaintelcomv1.AcceleratorFunctionList{}) + Invokes(testing.NewListAction(acceleratorfunctionsResource, acceleratorfunctionsKind, c.ns, opts), &v2.AcceleratorFunctionList{}) if obj == nil { return nil, err @@ -62,8 +62,8 @@ func (c *FakeAcceleratorFunctions) List(ctx context.Context, opts v1.ListOptions if label == nil { label = labels.Everything() } - list := &fpgaintelcomv1.AcceleratorFunctionList{ListMeta: obj.(*fpgaintelcomv1.AcceleratorFunctionList).ListMeta} - for _, item := range obj.(*fpgaintelcomv1.AcceleratorFunctionList).Items { + 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) } @@ -79,31 +79,31 @@ func (c *FakeAcceleratorFunctions) Watch(ctx context.Context, opts v1.ListOption } // 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 *fpgaintelcomv1.AcceleratorFunction, opts v1.CreateOptions) (result *fpgaintelcomv1.AcceleratorFunction, err error) { +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), &fpgaintelcomv1.AcceleratorFunction{}) + Invokes(testing.NewCreateAction(acceleratorfunctionsResource, c.ns, acceleratorFunction), &v2.AcceleratorFunction{}) if obj == nil { return nil, err } - return obj.(*fpgaintelcomv1.AcceleratorFunction), 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 *fpgaintelcomv1.AcceleratorFunction, opts v1.UpdateOptions) (result *fpgaintelcomv1.AcceleratorFunction, err error) { +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), &fpgaintelcomv1.AcceleratorFunction{}) + Invokes(testing.NewUpdateAction(acceleratorfunctionsResource, c.ns, acceleratorFunction), &v2.AcceleratorFunction{}) if obj == nil { return nil, err } - return obj.(*fpgaintelcomv1.AcceleratorFunction), 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), &fpgaintelcomv1.AcceleratorFunction{}) + Invokes(testing.NewDeleteAction(acceleratorfunctionsResource, c.ns, name), &v2.AcceleratorFunction{}) return err } @@ -112,17 +112,17 @@ func (c *FakeAcceleratorFunctions) Delete(ctx context.Context, name string, opts 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, &fpgaintelcomv1.AcceleratorFunctionList{}) + _, 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 *fpgaintelcomv1.AcceleratorFunction, err error) { +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...), &fpgaintelcomv1.AcceleratorFunction{}) + Invokes(testing.NewPatchSubresourceAction(acceleratorfunctionsResource, c.ns, name, pt, data, subresources...), &v2.AcceleratorFunction{}) if obj == nil { return nil, err } - return obj.(*fpgaintelcomv1.AcceleratorFunction), err + return obj.(*v2.AcceleratorFunction), err } diff --git a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake/fake_fpga.intel.com_client.go b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake/fake_fpga.intel.com_client.go similarity index 76% rename from pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake/fake_fpga.intel.com_client.go rename to pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake/fake_fpga.intel.com_client.go index 09fcc5c5c..4bb3fbc5c 100644 --- a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake/fake_fpga.intel.com_client.go +++ b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake/fake_fpga.intel.com_client.go @@ -17,26 +17,26 @@ package fake import ( - v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned/typed/fpga.intel.com/v1" + 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 FakeFpgaV1 struct { +type FakeFpgaV2 struct { *testing.Fake } -func (c *FakeFpgaV1) AcceleratorFunctions(namespace string) v1.AcceleratorFunctionInterface { +func (c *FakeFpgaV2) AcceleratorFunctions(namespace string) v2.AcceleratorFunctionInterface { return &FakeAcceleratorFunctions{c, namespace} } -func (c *FakeFpgaV1) FpgaRegions(namespace string) v1.FpgaRegionInterface { +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 *FakeFpgaV1) RESTClient() rest.Interface { +func (c *FakeFpgaV2) RESTClient() rest.Interface { var ret *rest.RESTClient return ret } diff --git a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake/fake_fpgaregion.go b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake/fake_fpgaregion.go similarity index 74% rename from pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake/fake_fpgaregion.go rename to pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake/fake_fpgaregion.go index 4ed70dd41..d11896fd7 100644 --- a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fake/fake_fpgaregion.go +++ b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fake/fake_fpgaregion.go @@ -19,7 +19,7 @@ package fake import ( "context" - fpgaintelcomv1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" @@ -30,29 +30,29 @@ import ( // FakeFpgaRegions implements FpgaRegionInterface type FakeFpgaRegions struct { - Fake *FakeFpgaV1 + Fake *FakeFpgaV2 ns string } -var fpgaregionsResource = schema.GroupVersionResource{Group: "fpga.intel.com", Version: "v1", Resource: "fpgaregions"} +var fpgaregionsResource = schema.GroupVersionResource{Group: "fpga.intel.com", Version: "v2", Resource: "fpgaregions"} -var fpgaregionsKind = schema.GroupVersionKind{Group: "fpga.intel.com", Version: "v1", Kind: "FpgaRegion"} +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 *fpgaintelcomv1.FpgaRegion, err error) { +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), &fpgaintelcomv1.FpgaRegion{}) + Invokes(testing.NewGetAction(fpgaregionsResource, c.ns, name), &v2.FpgaRegion{}) if obj == nil { return nil, err } - return obj.(*fpgaintelcomv1.FpgaRegion), 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 *fpgaintelcomv1.FpgaRegionList, err error) { +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), &fpgaintelcomv1.FpgaRegionList{}) + Invokes(testing.NewListAction(fpgaregionsResource, fpgaregionsKind, c.ns, opts), &v2.FpgaRegionList{}) if obj == nil { return nil, err @@ -62,8 +62,8 @@ func (c *FakeFpgaRegions) List(ctx context.Context, opts v1.ListOptions) (result if label == nil { label = labels.Everything() } - list := &fpgaintelcomv1.FpgaRegionList{ListMeta: obj.(*fpgaintelcomv1.FpgaRegionList).ListMeta} - for _, item := range obj.(*fpgaintelcomv1.FpgaRegionList).Items { + 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) } @@ -79,31 +79,31 @@ func (c *FakeFpgaRegions) Watch(ctx context.Context, opts v1.ListOptions) (watch } // 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 *fpgaintelcomv1.FpgaRegion, opts v1.CreateOptions) (result *fpgaintelcomv1.FpgaRegion, err error) { +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), &fpgaintelcomv1.FpgaRegion{}) + Invokes(testing.NewCreateAction(fpgaregionsResource, c.ns, fpgaRegion), &v2.FpgaRegion{}) if obj == nil { return nil, err } - return obj.(*fpgaintelcomv1.FpgaRegion), 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 *fpgaintelcomv1.FpgaRegion, opts v1.UpdateOptions) (result *fpgaintelcomv1.FpgaRegion, err error) { +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), &fpgaintelcomv1.FpgaRegion{}) + Invokes(testing.NewUpdateAction(fpgaregionsResource, c.ns, fpgaRegion), &v2.FpgaRegion{}) if obj == nil { return nil, err } - return obj.(*fpgaintelcomv1.FpgaRegion), 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), &fpgaintelcomv1.FpgaRegion{}) + Invokes(testing.NewDeleteAction(fpgaregionsResource, c.ns, name), &v2.FpgaRegion{}) return err } @@ -112,17 +112,17 @@ func (c *FakeFpgaRegions) Delete(ctx context.Context, name string, opts v1.Delet 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, &fpgaintelcomv1.FpgaRegionList{}) + _, 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 *fpgaintelcomv1.FpgaRegion, err error) { +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...), &fpgaintelcomv1.FpgaRegion{}) + Invokes(testing.NewPatchSubresourceAction(fpgaregionsResource, c.ns, name, pt, data, subresources...), &v2.FpgaRegion{}) if obj == nil { return nil, err } - return obj.(*fpgaintelcomv1.FpgaRegion), err + return obj.(*v2.FpgaRegion), err } diff --git a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fpga.intel.com_client.go b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fpga.intel.com_client.go similarity index 68% rename from pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fpga.intel.com_client.go rename to pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fpga.intel.com_client.go index 26db422ee..7340b470f 100644 --- a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fpga.intel.com_client.go +++ b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fpga.intel.com_client.go @@ -14,35 +14,35 @@ // Code generated by client-gen. DO NOT EDIT. -package v1 +package v2 import ( - v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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 FpgaV1Interface interface { +type FpgaV2Interface interface { RESTClient() rest.Interface AcceleratorFunctionsGetter FpgaRegionsGetter } -// FpgaV1Client is used to interact with features provided by the fpga.intel.com group. -type FpgaV1Client struct { +// FpgaV2Client is used to interact with features provided by the fpga.intel.com group. +type FpgaV2Client struct { restClient rest.Interface } -func (c *FpgaV1Client) AcceleratorFunctions(namespace string) AcceleratorFunctionInterface { +func (c *FpgaV2Client) AcceleratorFunctions(namespace string) AcceleratorFunctionInterface { return newAcceleratorFunctions(c, namespace) } -func (c *FpgaV1Client) FpgaRegions(namespace string) FpgaRegionInterface { +func (c *FpgaV2Client) FpgaRegions(namespace string) FpgaRegionInterface { return newFpgaRegions(c, namespace) } -// NewForConfig creates a new FpgaV1Client for the given config. -func NewForConfig(c *rest.Config) (*FpgaV1Client, error) { +// 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 @@ -51,12 +51,12 @@ func NewForConfig(c *rest.Config) (*FpgaV1Client, error) { if err != nil { return nil, err } - return &FpgaV1Client{client}, nil + return &FpgaV2Client{client}, nil } -// NewForConfigOrDie creates a new FpgaV1Client for the given config and +// NewForConfigOrDie creates a new FpgaV2Client for the given config and // panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *FpgaV1Client { +func NewForConfigOrDie(c *rest.Config) *FpgaV2Client { client, err := NewForConfig(c) if err != nil { panic(err) @@ -64,13 +64,13 @@ func NewForConfigOrDie(c *rest.Config) *FpgaV1Client { return client } -// New creates a new FpgaV1Client for the given RESTClient. -func New(c rest.Interface) *FpgaV1Client { - return &FpgaV1Client{c} +// 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 := v1.SchemeGroupVersion + gv := v2.SchemeGroupVersion config.GroupVersion = &gv config.APIPath = "/apis" config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() @@ -84,7 +84,7 @@ func setConfigDefaults(config *rest.Config) error { // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. -func (c *FpgaV1Client) RESTClient() rest.Interface { +func (c *FpgaV2Client) RESTClient() rest.Interface { if c == nil { return nil } diff --git a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fpgaregion.go b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fpgaregion.go similarity index 70% rename from pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fpgaregion.go rename to pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fpgaregion.go index 99afa502c..e068cff35 100644 --- a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/fpgaregion.go +++ b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/fpgaregion.go @@ -14,15 +14,15 @@ // Code generated by client-gen. DO NOT EDIT. -package v1 +package v2 import ( "context" "time" - v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + 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" @@ -36,14 +36,14 @@ type FpgaRegionsGetter interface { // FpgaRegionInterface has methods to work with FpgaRegion resources. type FpgaRegionInterface interface { - Create(ctx context.Context, fpgaRegion *v1.FpgaRegion, opts metav1.CreateOptions) (*v1.FpgaRegion, error) - Update(ctx context.Context, fpgaRegion *v1.FpgaRegion, opts metav1.UpdateOptions) (*v1.FpgaRegion, error) - Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.FpgaRegion, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.FpgaRegionList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.FpgaRegion, err error) + 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 } @@ -54,7 +54,7 @@ type fpgaRegions struct { } // newFpgaRegions returns a FpgaRegions -func newFpgaRegions(c *FpgaV1Client, namespace string) *fpgaRegions { +func newFpgaRegions(c *FpgaV2Client, namespace string) *fpgaRegions { return &fpgaRegions{ client: c.RESTClient(), ns: namespace, @@ -62,8 +62,8 @@ func newFpgaRegions(c *FpgaV1Client, namespace string) *fpgaRegions { } // 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 metav1.GetOptions) (result *v1.FpgaRegion, err error) { - result = &v1.FpgaRegion{} +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"). @@ -75,12 +75,12 @@ func (c *fpgaRegions) Get(ctx context.Context, name string, options metav1.GetOp } // List takes label and field selectors, and returns the list of FpgaRegions that match those selectors. -func (c *fpgaRegions) List(ctx context.Context, opts metav1.ListOptions) (result *v1.FpgaRegionList, err error) { +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 = &v1.FpgaRegionList{} + result = &v2.FpgaRegionList{} err = c.client.Get(). Namespace(c.ns). Resource("fpgaregions"). @@ -92,7 +92,7 @@ func (c *fpgaRegions) List(ctx context.Context, opts metav1.ListOptions) (result } // Watch returns a watch.Interface that watches the requested fpgaRegions. -func (c *fpgaRegions) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { +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 @@ -107,8 +107,8 @@ func (c *fpgaRegions) Watch(ctx context.Context, opts metav1.ListOptions) (watch } // 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 *v1.FpgaRegion, opts metav1.CreateOptions) (result *v1.FpgaRegion, err error) { - result = &v1.FpgaRegion{} +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"). @@ -120,8 +120,8 @@ func (c *fpgaRegions) Create(ctx context.Context, fpgaRegion *v1.FpgaRegion, opt } // 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 *v1.FpgaRegion, opts metav1.UpdateOptions) (result *v1.FpgaRegion, err error) { - result = &v1.FpgaRegion{} +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"). @@ -134,7 +134,7 @@ func (c *fpgaRegions) Update(ctx context.Context, fpgaRegion *v1.FpgaRegion, opt } // 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 metav1.DeleteOptions) error { +func (c *fpgaRegions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { return c.client.Delete(). Namespace(c.ns). Resource("fpgaregions"). @@ -145,7 +145,7 @@ func (c *fpgaRegions) Delete(ctx context.Context, name string, opts metav1.Delet } // DeleteCollection deletes a collection of objects. -func (c *fpgaRegions) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { +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 @@ -161,8 +161,8 @@ func (c *fpgaRegions) DeleteCollection(ctx context.Context, opts metav1.DeleteOp } // Patch applies the patch and returns the patched fpgaRegion. -func (c *fpgaRegions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.FpgaRegion, err error) { - result = &v1.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"). diff --git a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/generated_expansion.go b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/generated_expansion.go similarity index 98% rename from pkg/client/clientset/versioned/typed/fpga.intel.com/v1/generated_expansion.go rename to pkg/client/clientset/versioned/typed/fpga.intel.com/v2/generated_expansion.go index 6820720c3..6c60e4b1b 100644 --- a/pkg/client/clientset/versioned/typed/fpga.intel.com/v1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/fpga.intel.com/v2/generated_expansion.go @@ -14,7 +14,7 @@ // Code generated by client-gen. DO NOT EDIT. -package v1 +package v2 type AcceleratorFunctionExpansion interface{} diff --git a/pkg/client/informers/externalversions/fpga.intel.com/interface.go b/pkg/client/informers/externalversions/fpga.intel.com/interface.go index c6740f0fc..7a02e7f2f 100644 --- a/pkg/client/informers/externalversions/fpga.intel.com/interface.go +++ b/pkg/client/informers/externalversions/fpga.intel.com/interface.go @@ -17,14 +17,14 @@ package fpga import ( - v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/informers/externalversions/fpga.intel.com/v1" + 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 { - // V1 provides access to shared informers for resources in V1. - V1() v1.Interface + // V2 provides access to shared informers for resources in V2. + V2() v2.Interface } type group struct { @@ -38,7 +38,7 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// V1 returns a new v1.Interface. -func (g *group) V1() v1.Interface { - return v1.New(g.factory, g.namespace, g.tweakListOptions) +// V2 returns a new v2.Interface. +func (g *group) V2() v2.Interface { + return v2.New(g.factory, g.namespace, g.tweakListOptions) } diff --git a/pkg/client/informers/externalversions/fpga.intel.com/v1/acceleratorfunction.go b/pkg/client/informers/externalversions/fpga.intel.com/v2/acceleratorfunction.go similarity index 80% rename from pkg/client/informers/externalversions/fpga.intel.com/v1/acceleratorfunction.go rename to pkg/client/informers/externalversions/fpga.intel.com/v2/acceleratorfunction.go index 962660b7f..0e15292e1 100644 --- a/pkg/client/informers/externalversions/fpga.intel.com/v1/acceleratorfunction.go +++ b/pkg/client/informers/externalversions/fpga.intel.com/v2/acceleratorfunction.go @@ -14,17 +14,17 @@ // Code generated by informer-gen. DO NOT EDIT. -package v1 +package v2 import ( "context" time "time" - fpgaintelcomv1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" - v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/listers/fpga.intel.com/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + 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" @@ -34,7 +34,7 @@ import ( // AcceleratorFunctions. type AcceleratorFunctionInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.AcceleratorFunctionLister + Lister() v2.AcceleratorFunctionLister } type acceleratorFunctionInformer struct { @@ -56,20 +56,20 @@ func NewAcceleratorFunctionInformer(client versioned.Interface, namespace string 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 metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.FpgaV1().AcceleratorFunctions(namespace).List(context.TODO(), options) + return client.FpgaV2().AcceleratorFunctions(namespace).List(context.TODO(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.FpgaV1().AcceleratorFunctions(namespace).Watch(context.TODO(), options) + return client.FpgaV2().AcceleratorFunctions(namespace).Watch(context.TODO(), options) }, }, - &fpgaintelcomv1.AcceleratorFunction{}, + &fpgaintelcomv2.AcceleratorFunction{}, resyncPeriod, indexers, ) @@ -80,9 +80,9 @@ func (f *acceleratorFunctionInformer) defaultInformer(client versioned.Interface } func (f *acceleratorFunctionInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&fpgaintelcomv1.AcceleratorFunction{}, f.defaultInformer) + return f.factory.InformerFor(&fpgaintelcomv2.AcceleratorFunction{}, f.defaultInformer) } -func (f *acceleratorFunctionInformer) Lister() v1.AcceleratorFunctionLister { - return v1.NewAcceleratorFunctionLister(f.Informer().GetIndexer()) +func (f *acceleratorFunctionInformer) Lister() v2.AcceleratorFunctionLister { + return v2.NewAcceleratorFunctionLister(f.Informer().GetIndexer()) } diff --git a/pkg/client/informers/externalversions/fpga.intel.com/v1/fpgaregion.go b/pkg/client/informers/externalversions/fpga.intel.com/v2/fpgaregion.go similarity index 79% rename from pkg/client/informers/externalversions/fpga.intel.com/v1/fpgaregion.go rename to pkg/client/informers/externalversions/fpga.intel.com/v2/fpgaregion.go index 0c161eb8d..73746dcb4 100644 --- a/pkg/client/informers/externalversions/fpga.intel.com/v1/fpgaregion.go +++ b/pkg/client/informers/externalversions/fpga.intel.com/v2/fpgaregion.go @@ -14,17 +14,17 @@ // Code generated by informer-gen. DO NOT EDIT. -package v1 +package v2 import ( "context" time "time" - fpgaintelcomv1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" - v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/listers/fpga.intel.com/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + 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" @@ -34,7 +34,7 @@ import ( // FpgaRegions. type FpgaRegionInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.FpgaRegionLister + Lister() v2.FpgaRegionLister } type fpgaRegionInformer struct { @@ -56,20 +56,20 @@ func NewFpgaRegionInformer(client versioned.Interface, namespace string, resyncP 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 metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.FpgaV1().FpgaRegions(namespace).List(context.TODO(), options) + return client.FpgaV2().FpgaRegions(namespace).List(context.TODO(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.FpgaV1().FpgaRegions(namespace).Watch(context.TODO(), options) + return client.FpgaV2().FpgaRegions(namespace).Watch(context.TODO(), options) }, }, - &fpgaintelcomv1.FpgaRegion{}, + &fpgaintelcomv2.FpgaRegion{}, resyncPeriod, indexers, ) @@ -80,9 +80,9 @@ func (f *fpgaRegionInformer) defaultInformer(client versioned.Interface, resyncP } func (f *fpgaRegionInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&fpgaintelcomv1.FpgaRegion{}, f.defaultInformer) + return f.factory.InformerFor(&fpgaintelcomv2.FpgaRegion{}, f.defaultInformer) } -func (f *fpgaRegionInformer) Lister() v1.FpgaRegionLister { - return v1.NewFpgaRegionLister(f.Informer().GetIndexer()) +func (f *fpgaRegionInformer) Lister() v2.FpgaRegionLister { + return v2.NewFpgaRegionLister(f.Informer().GetIndexer()) } diff --git a/pkg/client/informers/externalversions/fpga.intel.com/v1/interface.go b/pkg/client/informers/externalversions/fpga.intel.com/v2/interface.go similarity index 99% rename from pkg/client/informers/externalversions/fpga.intel.com/v1/interface.go rename to pkg/client/informers/externalversions/fpga.intel.com/v2/interface.go index 08c89b9d9..e895e357b 100644 --- a/pkg/client/informers/externalversions/fpga.intel.com/v1/interface.go +++ b/pkg/client/informers/externalversions/fpga.intel.com/v2/interface.go @@ -14,7 +14,7 @@ // Code generated by informer-gen. DO NOT EDIT. -package v1 +package v2 import ( internalinterfaces "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/informers/externalversions/internalinterfaces" diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 07a05f239..f040412cb 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -19,7 +19,7 @@ package externalversions import ( "fmt" - v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" ) @@ -50,11 +50,11 @@ func (f *genericInformer) Lister() cache.GenericLister { // 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=v1 - case v1.SchemeGroupVersion.WithResource("acceleratorfunctions"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Fpga().V1().AcceleratorFunctions().Informer()}, nil - case v1.SchemeGroupVersion.WithResource("fpgaregions"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Fpga().V1().FpgaRegions().Informer()}, nil + // 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 } diff --git a/pkg/client/listers/fpga.intel.com/v1/acceleratorfunction.go b/pkg/client/listers/fpga.intel.com/v2/acceleratorfunction.go similarity index 83% rename from pkg/client/listers/fpga.intel.com/v1/acceleratorfunction.go rename to pkg/client/listers/fpga.intel.com/v2/acceleratorfunction.go index 2c09ff46e..8f8b8be32 100644 --- a/pkg/client/listers/fpga.intel.com/v1/acceleratorfunction.go +++ b/pkg/client/listers/fpga.intel.com/v2/acceleratorfunction.go @@ -14,10 +14,10 @@ // Code generated by lister-gen. DO NOT EDIT. -package v1 +package v2 import ( - v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" @@ -26,7 +26,7 @@ import ( // AcceleratorFunctionLister helps list AcceleratorFunctions. type AcceleratorFunctionLister interface { // List lists all AcceleratorFunctions in the indexer. - List(selector labels.Selector) (ret []*v1.AcceleratorFunction, err error) + List(selector labels.Selector) (ret []*v2.AcceleratorFunction, err error) // AcceleratorFunctions returns an object that can list and get AcceleratorFunctions. AcceleratorFunctions(namespace string) AcceleratorFunctionNamespaceLister AcceleratorFunctionListerExpansion @@ -43,9 +43,9 @@ func NewAcceleratorFunctionLister(indexer cache.Indexer) AcceleratorFunctionList } // List lists all AcceleratorFunctions in the indexer. -func (s *acceleratorFunctionLister) List(selector labels.Selector) (ret []*v1.AcceleratorFunction, err error) { +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.(*v1.AcceleratorFunction)) + ret = append(ret, m.(*v2.AcceleratorFunction)) }) return ret, err } @@ -58,9 +58,9 @@ func (s *acceleratorFunctionLister) AcceleratorFunctions(namespace string) Accel // 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 []*v1.AcceleratorFunction, err error) + 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) (*v1.AcceleratorFunction, error) + Get(name string) (*v2.AcceleratorFunction, error) AcceleratorFunctionNamespaceListerExpansion } @@ -72,21 +72,21 @@ type acceleratorFunctionNamespaceLister struct { } // List lists all AcceleratorFunctions in the indexer for a given namespace. -func (s acceleratorFunctionNamespaceLister) List(selector labels.Selector) (ret []*v1.AcceleratorFunction, err error) { +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.(*v1.AcceleratorFunction)) + 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) (*v1.AcceleratorFunction, error) { +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(v1.Resource("acceleratorfunction"), name) + return nil, errors.NewNotFound(v2.Resource("acceleratorfunction"), name) } - return obj.(*v1.AcceleratorFunction), nil + return obj.(*v2.AcceleratorFunction), nil } diff --git a/pkg/client/listers/fpga.intel.com/v1/expansion_generated.go b/pkg/client/listers/fpga.intel.com/v2/expansion_generated.go similarity index 99% rename from pkg/client/listers/fpga.intel.com/v1/expansion_generated.go rename to pkg/client/listers/fpga.intel.com/v2/expansion_generated.go index 993fb3dcd..79f3628d4 100644 --- a/pkg/client/listers/fpga.intel.com/v1/expansion_generated.go +++ b/pkg/client/listers/fpga.intel.com/v2/expansion_generated.go @@ -14,7 +14,7 @@ // Code generated by lister-gen. DO NOT EDIT. -package v1 +package v2 // AcceleratorFunctionListerExpansion allows custom methods to be added to // AcceleratorFunctionLister. diff --git a/pkg/client/listers/fpga.intel.com/v1/fpgaregion.go b/pkg/client/listers/fpga.intel.com/v2/fpgaregion.go similarity index 82% rename from pkg/client/listers/fpga.intel.com/v1/fpgaregion.go rename to pkg/client/listers/fpga.intel.com/v2/fpgaregion.go index 89805dc48..1dfc15342 100644 --- a/pkg/client/listers/fpga.intel.com/v1/fpgaregion.go +++ b/pkg/client/listers/fpga.intel.com/v2/fpgaregion.go @@ -14,10 +14,10 @@ // Code generated by lister-gen. DO NOT EDIT. -package v1 +package v2 import ( - v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1" + 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" @@ -26,7 +26,7 @@ import ( // FpgaRegionLister helps list FpgaRegions. type FpgaRegionLister interface { // List lists all FpgaRegions in the indexer. - List(selector labels.Selector) (ret []*v1.FpgaRegion, err error) + List(selector labels.Selector) (ret []*v2.FpgaRegion, err error) // FpgaRegions returns an object that can list and get FpgaRegions. FpgaRegions(namespace string) FpgaRegionNamespaceLister FpgaRegionListerExpansion @@ -43,9 +43,9 @@ func NewFpgaRegionLister(indexer cache.Indexer) FpgaRegionLister { } // List lists all FpgaRegions in the indexer. -func (s *fpgaRegionLister) List(selector labels.Selector) (ret []*v1.FpgaRegion, err error) { +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.(*v1.FpgaRegion)) + ret = append(ret, m.(*v2.FpgaRegion)) }) return ret, err } @@ -58,9 +58,9 @@ func (s *fpgaRegionLister) FpgaRegions(namespace string) FpgaRegionNamespaceList // 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 []*v1.FpgaRegion, err error) + 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) (*v1.FpgaRegion, error) + Get(name string) (*v2.FpgaRegion, error) FpgaRegionNamespaceListerExpansion } @@ -72,21 +72,21 @@ type fpgaRegionNamespaceLister struct { } // List lists all FpgaRegions in the indexer for a given namespace. -func (s fpgaRegionNamespaceLister) List(selector labels.Selector) (ret []*v1.FpgaRegion, err error) { +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.(*v1.FpgaRegion)) + 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) (*v1.FpgaRegion, error) { +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(v1.Resource("fpgaregion"), name) + return nil, errors.NewNotFound(v2.Resource("fpgaregion"), name) } - return obj.(*v1.FpgaRegion), nil + return obj.(*v2.FpgaRegion), nil } diff --git a/scripts/update-generated-code.sh b/scripts/update-generated-code.sh index e6d112566..ddcaf8fe8 100755 --- a/scripts/update-generated-code.sh +++ b/scripts/update-generated-code.sh @@ -28,6 +28,6 @@ PKG_PATH="github.com/intel/intel-device-plugins-for-kubernetes/pkg" # 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:v1 \ + fpga.intel.com:v2 \ --output-base "$(dirname ${BASH_SOURCE})/../../../.." \ --go-header-file ${SCRIPT_ROOT}/build/boilerplate/boilerplate.go.txt