Skip to content

Commit 89ad053

Browse files
authored
Merge pull request #557 from mythi/PR-2021-009
operator: move deviceplugin/v1 CRDs to cluster scope
2 parents c1f609c + 37618d4 commit 89ad053

26 files changed

+133
-99
lines changed

cmd/operator/main.go

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"flag"
1919
"os"
2020

21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
"k8s.io/apimachinery/pkg/runtime"
2223
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
2324
"k8s.io/klog/v2/klogr"
@@ -51,17 +52,29 @@ func init() {
5152
// +kubebuilder:scaffold:scheme
5253
}
5354

55+
type devicePluginControllerAndWebhook map[string](func(ctrl.Manager, string, bool) error)
56+
5457
func main() {
5558
var metricsAddr string
59+
var devicePluginNamespace string
5660
var enableLeaderElection bool
5761
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
62+
flag.StringVar(&devicePluginNamespace, "deviceplugin-namespace", metav1.NamespaceSystem, "The namespace where deviceplugin daemonsets are created")
5863
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
5964
"Enable leader election for controller manager. "+
6065
"Enabling this will ensure there is only one active controller manager.")
6166
flag.Parse()
6267

6368
ctrl.SetLogger(klogr.New())
6469

70+
setupControllerAndWebhook := devicePluginControllerAndWebhook{
71+
"dsa": dsa.SetupReconciler,
72+
"gpu": gpu.SetupReconciler,
73+
"fpga": fpga.SetupReconciler,
74+
"qat": qat.SetupReconciler,
75+
"sgx": sgx.SetupReconciler,
76+
}
77+
6578
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
6679
Scheme: scheme,
6780
MetricsBindAddress: metricsAddr,
@@ -75,40 +88,19 @@ func main() {
7588
os.Exit(1)
7689
}
7790

78-
if err = dsa.SetupReconciler(mgr); err != nil {
79-
setupLog.Error(err, "unable to create controller", "controller", "DsaDevicePlugin")
80-
os.Exit(1)
81-
}
82-
if err = (&devicepluginv1.DsaDevicePlugin{}).SetupWebhookWithManager(mgr); err != nil {
83-
setupLog.Error(err, "unable to create webhook", "webhook", "DsaDevicePlugin")
84-
os.Exit(1)
91+
ns := os.Getenv("DEVICEPLUGIN_NAMESPACE")
92+
if ns == "" {
93+
ns = devicePluginNamespace
8594
}
8695

87-
if err = gpu.SetupReconciler(mgr); err != nil {
88-
setupLog.Error(err, "unable to create controller", "controller", "GpuDevicePlugin")
89-
os.Exit(1)
90-
}
91-
if err = (&devicepluginv1.GpuDevicePlugin{}).SetupWebhookWithManager(mgr); err != nil {
92-
setupLog.Error(err, "unable to create webhook", "webhook", "GpuDevicePlugin")
93-
os.Exit(1)
94-
}
96+
withWebhook := true
9597

96-
if err = qat.SetupReconciler(mgr); err != nil {
97-
setupLog.Error(err, "unable to create controller", "controller", "QatDevicePlugin")
98-
os.Exit(1)
99-
}
100-
if err = (&devicepluginv1.QatDevicePlugin{}).SetupWebhookWithManager(mgr); err != nil {
101-
setupLog.Error(err, "unable to create webhook", "webhook", "QatDevicePlugin")
102-
os.Exit(1)
103-
}
104-
105-
if err = sgx.SetupReconciler(mgr); err != nil {
106-
setupLog.Error(err, "unable to create controller", "controller", "SgxDevicePlugin")
107-
os.Exit(1)
108-
}
109-
if err = (&devicepluginv1.SgxDevicePlugin{}).SetupWebhookWithManager(mgr); err != nil {
110-
setupLog.Error(err, "unable to create webhook", "webhook", "SgxDevicePlugin")
111-
os.Exit(1)
98+
// TODO(mythi): add a StringVar flag to select which controllers to enable
99+
for _, device := range []string{"dsa", "fpga", "gpu", "qat", "sgx"} {
100+
if err = setupControllerAndWebhook[device](mgr, ns, withWebhook); err != nil {
101+
setupLog.Error(err, "unable to initialize controller", "controller", device)
102+
os.Exit(1)
103+
}
112104
}
113105

114106
pm := patcher.NewPatcherManager(mgr.GetLogger().WithName("webhooks").WithName("Fpga"))
@@ -121,15 +113,6 @@ func main() {
121113
Handler: &sgxwebhook.SgxMutator{Client: mgr.GetClient()},
122114
})
123115

124-
if err = fpga.SetupReconciler(mgr); err != nil {
125-
setupLog.Error(err, "unable to create controller", "controller", "FpgaDevicePlugin")
126-
os.Exit(1)
127-
}
128-
if err = (&devicepluginv1.FpgaDevicePlugin{}).SetupWebhookWithManager(mgr); err != nil {
129-
setupLog.Error(err, "unable to create webhook", "webhook", "FpgaDevicePlugin")
130-
os.Exit(1)
131-
}
132-
133116
if err = (&fpgacontroller.AcceleratorFunctionReconciler{
134117
Client: mgr.GetClient(),
135118
Scheme: mgr.GetScheme(),

deployments/operator/crd/bases/deviceplugin.intel.com_dsadeviceplugins.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
listKind: DsaDevicePluginList
2828
plural: dsadeviceplugins
2929
singular: dsadeviceplugin
30-
scope: Namespaced
30+
scope: Cluster
3131
subresources:
3232
status: {}
3333
validation:

deployments/operator/crd/bases/deviceplugin.intel.com_fpgadeviceplugins.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
listKind: FpgaDevicePluginList
2828
plural: fpgadeviceplugins
2929
singular: fpgadeviceplugin
30-
scope: Namespaced
30+
scope: Cluster
3131
subresources:
3232
status: {}
3333
validation:

deployments/operator/crd/bases/deviceplugin.intel.com_gpudeviceplugins.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
listKind: GpuDevicePluginList
2828
plural: gpudeviceplugins
2929
singular: gpudeviceplugin
30-
scope: Namespaced
30+
scope: Cluster
3131
subresources:
3232
status: {}
3333
validation:

deployments/operator/crd/bases/deviceplugin.intel.com_qatdeviceplugins.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
listKind: QatDevicePluginList
2828
plural: qatdeviceplugins
2929
singular: qatdeviceplugin
30-
scope: Namespaced
30+
scope: Cluster
3131
subresources:
3232
status: {}
3333
validation:

deployments/operator/crd/bases/deviceplugin.intel.com_sgxdeviceplugins.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
listKind: SgxDevicePluginList
2828
plural: sgxdeviceplugins
2929
singular: sgxdeviceplugin
30-
scope: Namespaced
30+
scope: Cluster
3131
subresources:
3232
status: {}
3333
validation:

deployments/operator/manager/manager.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@ spec:
3838
runAsUser: 3210
3939
runAsGroup: 3210
4040
readOnlyRootFilesystem: true
41+
env:
42+
- name: DEVICEPLUGIN_NAMESPACE
43+
valueFrom:
44+
fieldRef:
45+
fieldPath: metadata.namespace
4146
serviceAccountName: default
4247
terminationGracePeriodSeconds: 10

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ require (
2020
k8s.io/klog/v2 v2.4.0
2121
k8s.io/kubelet v0.20.2
2222
k8s.io/kubernetes v1.20.2
23-
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
24-
sigs.k8s.io/controller-runtime v0.7.0
23+
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009
24+
sigs.k8s.io/controller-runtime v0.8.1
2525
)
2626

2727
replace (

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,10 +1001,10 @@ k8s.io/metrics v0.20.2/go.mod h1:yTck5nl5wt/lIeLcU6g0b8/AKJf2girwe0PQiaM4Mwk=
10011001
k8s.io/mount-utils v0.20.3-rc.0/go.mod h1:Jv9NRZ5L2LF87A17GaGlArD+r3JAJdZFvo4XD1cG4Kc=
10021002
k8s.io/sample-apiserver v0.20.2/go.mod h1:Q4VuPfFr3WOSkv6XKmY8FukZESdtH5MWqO0umFDfHcM=
10031003
k8s.io/system-validators v1.2.0/go.mod h1:bPldcLgkIUK22ALflnsXk8pvkTEndYdNuaHH6gRrl0Q=
1004-
k8s.io/utils v0.0.0-20200912215256-4140de9c8800 h1:9ZNvfPvVIEsp/T1ez4GQuzCcCTEQWhovSofhqR73A6g=
1005-
k8s.io/utils v0.0.0-20200912215256-4140de9c8800/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
10061004
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 h1:CbnUZsM497iRC5QMVkHwyl8s2tB3g7yaSHkYPkpgelw=
10071005
k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
1006+
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009 h1:0T5IaWHO3sJTEmCP6mUlBvMukxPKUQWqiI/YuiBNMiQ=
1007+
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
10081008
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
10091009
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
10101010
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
@@ -1016,8 +1016,8 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
10161016
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
10171017
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14 h1:TihvEz9MPj2u0KWds6E2OBUXfwaL4qRJ33c7HGiJpqk=
10181018
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
1019-
sigs.k8s.io/controller-runtime v0.7.0 h1:bU20IBBEPccWz5+zXpLnpVsgBYxqclaHu1pVDl/gEt8=
1020-
sigs.k8s.io/controller-runtime v0.7.0/go.mod h1:pJ3YBrJiAqMAZKi6UVGuE98ZrroV1p+pIhoHsMm9wdU=
1019+
sigs.k8s.io/controller-runtime v0.8.1 h1:O0K2CJ2JavK8/Tf4LfcpAwRxOFBhv8DjyrbmE6Qw59s=
1020+
sigs.k8s.io/controller-runtime v0.8.1/go.mod h1:U/l+DUopBc1ecfRZ5aviA9JDmGFQKvLf5YkZNx2e0sU=
10211021
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
10221022
sigs.k8s.io/structured-merge-diff/v4 v4.0.2 h1:YHQV7Dajm86OuqnIR6zAelnDWBRjo+YhYV9PmGrh1s8=
10231023
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=

pkg/apis/deviceplugin/v1/dsadeviceplugin_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type DsaDevicePluginStatus struct {
6363
}
6464

6565
// +kubebuilder:object:root=true
66+
// +kubebuilder:resource:path=dsadeviceplugins,scope=Cluster
6667
// +kubebuilder:subresource:status
6768
// +kubebuilder:printcolumn:name="Desired",type=integer,JSONPath=`.status.desiredNumberScheduled`
6869
// +kubebuilder:printcolumn:name="Ready",type=integer,JSONPath=`.status.numberReady`

0 commit comments

Comments
 (0)