Skip to content

operator: remove one-cr-per-kind limitation #1579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ NAME DESIRED READY NODE SELECTOR AGE
gpudeviceplugin-sample 1 1 5s
```

**NOTE:** Intel Device Plugin Operator supports multiple custom resources per Kind (QAT, DSA, etc.). With multiple custom resources and different `nodeSelectors`, it is possible to customize device plugin configuration per node or per group of nodes. See also [known issues](#multiple-custom-resources).

## Upgrade

The upgrade of the deployed plugins can be done by simply installing a new release of the operator.
Expand Down Expand Up @@ -135,6 +137,10 @@ command line argument multiple times.

## Known issues

### Multiple Custom Resources

With multiple custom resources, `nodeSelector` has to be carefully set to avoid device plugin DaemonSet getting deployed multiple times on the same node, as operator does not check or prevent this. Multiple plugins managing same resource on a node can cause invalid behavior and/or duplicate device resources on node.

### Cluster behind a proxy

If your cluster operates behind a corporate proxy make sure that the API
Expand Down
9 changes: 0 additions & 9 deletions pkg/apis/deviceplugin/v1/dlbdeviceplugin_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package v1

import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand All @@ -25,10 +24,6 @@ import (
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/controllers"
)

const (
dlbPluginKind = "DlbDevicePlugin"
)

var (
// dlbdevicepluginlog is for logging in this package.
dlbdevicepluginlog = logf.Log.WithName("dlbdeviceplugin-resource")
Expand Down Expand Up @@ -64,10 +59,6 @@ var _ webhook.Validator = &DlbDevicePlugin{}
func (r *DlbDevicePlugin) ValidateCreate() (admission.Warnings, error) {
dlbdevicepluginlog.Info("validate create", "name", r.Name)

if controllers.GetDevicePluginCount(dlbPluginKind) > 0 {
return nil, errors.Errorf("an instance of %q already exists in the cluster", dlbPluginKind)
}

return nil, r.validatePlugin()
}

Expand Down
8 changes: 0 additions & 8 deletions pkg/apis/deviceplugin/v1/dsadeviceplugin_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import (
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/controllers"
)

const (
dsaPluginKind = "DsaDevicePlugin"
)

var (
// dsadevicepluginlog is for logging in this package.
dsadevicepluginlog = logf.Log.WithName("dsadeviceplugin-resource")
Expand Down Expand Up @@ -64,10 +60,6 @@ var _ webhook.Validator = &DsaDevicePlugin{}
func (r *DsaDevicePlugin) ValidateCreate() (admission.Warnings, error) {
dsadevicepluginlog.Info("validate create", "name", r.Name)

if controllers.GetDevicePluginCount(dsaPluginKind) > 0 {
return nil, errors.Errorf("an instance of %q already exists in the cluster", dsaPluginKind)
}

return nil, r.validatePlugin()
}

Expand Down
9 changes: 0 additions & 9 deletions pkg/apis/deviceplugin/v1/fpgadeviceplugin_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package v1

import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand All @@ -25,10 +24,6 @@ import (
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/controllers"
)

const (
fpgaPluginKind = "FpgaDevicePlugin"
)

var (
// fpgadevicepluginlog is for logging in this package.
fpgadevicepluginlog = logf.Log.WithName("fpgadeviceplugin-resource")
Expand Down Expand Up @@ -68,10 +63,6 @@ var _ webhook.Validator = &FpgaDevicePlugin{}
func (r *FpgaDevicePlugin) ValidateCreate() (admission.Warnings, error) {
fpgadevicepluginlog.Info("validate create", "name", r.Name)

if controllers.GetDevicePluginCount(fpgaPluginKind) > 0 {
return nil, errors.Errorf("an instance of %q already exists in the cluster", fpgaPluginKind)
}

return nil, r.validatePlugin()
}

Expand Down
43 changes: 35 additions & 8 deletions pkg/apis/deviceplugin/v1/gpudeviceplugin_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,32 @@
package v1

import (
"context"

"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/intel/intel-device-plugins-for-kubernetes/pkg/controllers"
)

const (
gpuPluginKind = "GpuDevicePlugin"
)

var (
// gpudevicepluginlog is for logging in this package.
gpudevicepluginlog = logf.Log.WithName("gpudeviceplugin-resource")

gpuMinVersion = controllers.ImageMinVersion
)

var cli client.Client

// SetupWebhookWithManager sets up a webhook for GpuDevicePlugin custom resources.
func (r *GpuDevicePlugin) SetupWebhookWithManager(mgr ctrl.Manager) error {
cli = mgr.GetClient()

return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
Expand All @@ -64,10 +67,6 @@ var _ webhook.Validator = &GpuDevicePlugin{}
func (r *GpuDevicePlugin) ValidateCreate() (admission.Warnings, error) {
gpudevicepluginlog.Info("validate create", "name", r.Name)

if controllers.GetDevicePluginCount(gpuPluginKind) > 0 {
return nil, errors.Errorf("an instance of %q already exists in the cluster", gpuPluginKind)
}

return nil, r.validatePlugin()
}

Expand All @@ -85,6 +84,30 @@ func (r *GpuDevicePlugin) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}

func (r *GpuDevicePlugin) crossCheckResourceManagement() bool {
ctx := context.Background()
gpuCrs := GpuDevicePluginList{}

if err := cli.List(ctx, &gpuCrs); err != nil {
gpudevicepluginlog.Info("unable to list GPU CRs")

return false
}

for _, cr := range gpuCrs.Items {
// Ignore itself.
if cr.Name == r.Name {
continue
}

if cr.Spec.ResourceManager != r.Spec.ResourceManager {
return false
}
}

return true
}

func (r *GpuDevicePlugin) validatePlugin() error {
if r.Spec.SharedDevNum == 1 && r.Spec.PreferredAllocationPolicy != "none" {
return errors.Errorf("PreferredAllocationPolicy is valid only when setting sharedDevNum > 1")
Expand All @@ -94,5 +117,9 @@ func (r *GpuDevicePlugin) validatePlugin() error {
return errors.Errorf("resourceManager is valid only when setting sharedDevNum > 1")
}

if !r.crossCheckResourceManagement() {
return errors.Errorf("All GPU CRs must be with or without resource management")
}

return validatePluginImage(r.Spec.Image, "intel-gpu-plugin", gpuMinVersion)
}
8 changes: 0 additions & 8 deletions pkg/apis/deviceplugin/v1/iaadeviceplugin_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import (
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/controllers"
)

const (
iaaPluginKind = "IaaDevicePlugin"
)

var (
// iaadevicepluginlog is for logging in this package.
iaadevicepluginlog = logf.Log.WithName("iaadeviceplugin-resource")
Expand Down Expand Up @@ -64,10 +60,6 @@ var _ webhook.Validator = &IaaDevicePlugin{}
func (r *IaaDevicePlugin) ValidateCreate() (admission.Warnings, error) {
iaadevicepluginlog.Info("validate create", "name", r.Name)

if controllers.GetDevicePluginCount(iaaPluginKind) > 0 {
return nil, errors.Errorf("an instance of %q already exists in the cluster", iaaPluginKind)
}

return nil, r.validatePlugin()
}

Expand Down
8 changes: 0 additions & 8 deletions pkg/apis/deviceplugin/v1/qatdeviceplugin_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import (
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/controllers"
)

const (
qatPluginKind = "QatDevicePlugin"
)

var (
// qatdevicepluginlog is for logging in this package.
qatdevicepluginlog = logf.Log.WithName("qatdeviceplugin-resource")
Expand Down Expand Up @@ -64,10 +60,6 @@ var _ webhook.Validator = &QatDevicePlugin{}
func (r *QatDevicePlugin) ValidateCreate() (admission.Warnings, error) {
qatdevicepluginlog.Info("validate create", "name", r.Name)

if controllers.GetDevicePluginCount(qatPluginKind) > 0 {
return nil, errors.Errorf("an instance of %q already exists in the cluster", qatPluginKind)
}

return nil, r.validatePlugin()
}

Expand Down
9 changes: 0 additions & 9 deletions pkg/apis/deviceplugin/v1/sgxdeviceplugin_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package v1

import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand All @@ -25,10 +24,6 @@ import (
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/controllers"
)

const (
sgxPluginKind = "SgxDevicePlugin"
)

var (
// sgxdevicepluginlog is for logging in this package.
sgxdevicepluginlog = logf.Log.WithName("sgxdeviceplugin-resource")
Expand Down Expand Up @@ -64,10 +59,6 @@ var _ webhook.Validator = &SgxDevicePlugin{}
func (r *SgxDevicePlugin) ValidateCreate() (admission.Warnings, error) {
sgxdevicepluginlog.Info("validate create", "name", r.Name)

if controllers.GetDevicePluginCount(sgxPluginKind) > 0 {
return nil, errors.Errorf("an instance of %q already exists in the cluster", sgxPluginKind)
}

return nil, r.validatePlugin()
}

Expand Down
11 changes: 2 additions & 9 deletions pkg/controllers/dlb/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,12 @@ func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
}

func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {
var list devicepluginv1.DlbDevicePluginList
if err := clnt.List(ctx, &list); err != nil {
return 0, err
}

return len(list.Items), nil
}

func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
devicePlugin := rawObj.(*devicepluginv1.DlbDevicePlugin)

ds := deployments.DLBPluginDaemonSet()
ds.Name = controllers.SuffixedName(ds.Name, devicePlugin.Name)

if len(devicePlugin.Spec.NodeSelector) > 0 {
ds.Spec.Template.Spec.NodeSelector = devicePlugin.Spec.NodeSelector
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/dlb/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
},
ObjectMeta: metav1.ObjectMeta{
Namespace: c.ns,
Name: appLabel,
Name: appLabel + "-" + devicePlugin.Name,
Labels: map[string]string{
"app": appLabel,
},
Expand Down Expand Up @@ -139,6 +139,7 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
// equal to the expected daemonset.
func TestNewDaemonSetDLB(t *testing.T) {
plugin := &devicepluginv1.DlbDevicePlugin{}
plugin.Name = "testing"
c := &controller{}

expected := c.newDaemonSetExpected(plugin)
Expand Down
11 changes: 2 additions & 9 deletions pkg/controllers/dsa/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
}

func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {
var list devicepluginv1.DsaDevicePluginList
if err := clnt.List(ctx, &list); err != nil {
return 0, err
}

return len(list.Items), nil
}

func removeInitContainer(ds *apps.DaemonSet, dp *devicepluginv1.DsaDevicePlugin) {
newInitContainers := []v1.Container{}

Expand Down Expand Up @@ -199,6 +190,8 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
devicePlugin := rawObj.(*devicepluginv1.DsaDevicePlugin)

daemonSet := deployments.DSAPluginDaemonSet()
daemonSet.Name = controllers.SuffixedName(daemonSet.Name, devicePlugin.Name)

if len(devicePlugin.Spec.NodeSelector) > 0 {
daemonSet.Spec.Template.Spec.NodeSelector = devicePlugin.Spec.NodeSelector
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/dsa/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
},
ObjectMeta: metav1.ObjectMeta{
Namespace: c.ns,
Name: appLabel,
Name: appLabel + "-" + devicePlugin.Name,
Labels: map[string]string{
"app": appLabel,
},
Expand Down Expand Up @@ -160,6 +160,7 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
// equal to the expected daemonset.
func TestNewDaemonSetDSA(t *testing.T) {
plugin := &devicepluginv1.DsaDevicePlugin{}
plugin.Name = "testing"
c := &controller{}

expected := c.newDaemonSetExpected(plugin)
Expand Down
11 changes: 2 additions & 9 deletions pkg/controllers/fpga/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,12 @@ func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
}

func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {
var list devicepluginv1.FpgaDevicePluginList
if err := clnt.List(ctx, &list); err != nil {
return 0, err
}

return len(list.Items), nil
}

func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
devicePlugin := rawObj.(*devicepluginv1.FpgaDevicePlugin)

daemonSet := deployments.FPGAPluginDaemonSet()
daemonSet.Name = controllers.SuffixedName(daemonSet.Name, devicePlugin.Name)

if len(devicePlugin.Spec.NodeSelector) > 0 {
daemonSet.Spec.Template.Spec.NodeSelector = devicePlugin.Spec.NodeSelector
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/fpga/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
},
ObjectMeta: metav1.ObjectMeta{
Namespace: c.ns,
Name: appLabel,
Name: appLabel + "-" + devicePlugin.Name,
Labels: map[string]string{
"app": appLabel,
},
Expand Down Expand Up @@ -184,6 +184,7 @@ func TestNewDaemonSetFPGA(t *testing.T) {
InitImage: "intel/intel-fpga-initcontainer:devel",
},
}
plugin.Name = "testing"

expected := c.newDaemonSetExpected(plugin)
actual := c.NewDaemonSet(plugin)
Expand Down
Loading