Skip to content

Commit a6e78a6

Browse files
committed
Support Pause/Unpause MCP in Openshift
Implement MCPManager which pauses/unpauses MCP in openshift environments. - Add Openshift detection logic - Implement MCPManager - Integrate MCPManager in nodemaintenance controller Signed-off-by: adrianc <[email protected]>
1 parent d25eb29 commit a6e78a6

File tree

13 files changed

+944
-88
lines changed

13 files changed

+944
-88
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,16 @@ clean: ## clean files
284284

285285
.PHONY: manifests
286286
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
287-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./api/..." output:crd:artifacts:config=config/crd/bases
287+
$(CONTROLLER_GEN) crd paths="./api/..." output:crd:artifacts:config=config/crd/bases
288+
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./internal/controller/..."
288289
cp -f config/crd/bases/* deployment/maintenance-operator-chart/crds
289290

290291
.PHONY: generate
291292
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
292293
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..."
293294

294295
.PHONY: test
295-
test: unit-test lint
296+
test: lint unit-test
296297

297298
.PHONY: unit-test
298299
unit-test: envtest ## Run unit tests.

cmd/maintenance-manager/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"k8s.io/client-go/kubernetes"
2828
_ "k8s.io/client-go/plugin/pkg/client/auth"
2929

30+
ocpconfigv1 "github.com/openshift/api/config/v1"
31+
mcv1 "github.com/openshift/api/machineconfiguration/v1"
3032
"k8s.io/apimachinery/pkg/runtime"
3133
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3234
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
@@ -40,6 +42,7 @@ import (
4042
"github.com/Mellanox/maintenance-operator/internal/cordon"
4143
"github.com/Mellanox/maintenance-operator/internal/drain"
4244
operatorlog "github.com/Mellanox/maintenance-operator/internal/log"
45+
"github.com/Mellanox/maintenance-operator/internal/openshift"
4346
"github.com/Mellanox/maintenance-operator/internal/podcompletion"
4447
"github.com/Mellanox/maintenance-operator/internal/scheduler"
4548
"github.com/Mellanox/maintenance-operator/internal/version"
@@ -54,6 +57,8 @@ var (
5457

5558
func init() {
5659
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
60+
utilruntime.Must(ocpconfigv1.Install(scheme))
61+
utilruntime.Must(mcv1.Install(scheme))
5762

5863
utilruntime.Must(maintenancev1alpha1.AddToScheme(scheme))
5964
//+kubebuilder:scaffold:scheme
@@ -147,12 +152,24 @@ func main() {
147152
ctx := ctrl.SetupSignalHandler()
148153
mgrClient := mgr.GetClient()
149154

155+
ocpUtils, err := openshift.NewOpenshiftUtils(ctx, mgr.GetAPIReader())
156+
if err != nil {
157+
setupLog.Error(err, "unable to create openshift utils")
158+
os.Exit(1)
159+
}
160+
161+
if ocpUtils.IsOpenshift() {
162+
setupLog.Info("openshift cluster detected",
163+
"isOpenshift", ocpUtils.IsOpenshift(), "isHypershift", ocpUtils.IsHypershift())
164+
}
165+
150166
if err = (&controller.NodeMaintenanceReconciler{
151167
Client: mgrClient,
152168
Scheme: mgr.GetScheme(),
153169
CordonHandler: cordon.NewCordonHandler(mgrClient, k8sInterface),
154170
WaitPodCompletionHandler: podcompletion.NewPodCompletionHandler(mgrClient),
155171
DrainManager: drain.NewManager(ctrl.Log.WithName("DrainManager"), ctx, k8sInterface),
172+
MCPManager: openshift.NewMCPManager(ocpUtils, mgrClient),
156173
}).SetupWithManager(ctx, mgr, ctrl.Log.WithName("NodeMaintenanceReconciler")); err != nil {
157174
setupLog.Error(err, "unable to create controller", "controller", "NodeMaintenance")
158175
os.Exit(1)

config/rbac/role.yaml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,35 @@ rules:
5353
- list
5454
- watch
5555
- apiGroups:
56-
- maintenance.nvidia.com
56+
- config.openshift.io
5757
resources:
58-
- maintenanceoperatorconfigs
58+
- infrastructures
5959
verbs:
60-
- create
61-
- delete
6260
- get
6361
- list
64-
- patch
65-
- update
6662
- watch
6763
- apiGroups:
68-
- maintenance.nvidia.com
64+
- machineconfiguration.openshift.io
6965
resources:
70-
- maintenanceoperatorconfigs/finalizers
66+
- machineconfigpools
7167
verbs:
68+
- get
69+
- list
70+
- patch
7271
- update
72+
- watch
7373
- apiGroups:
74-
- maintenance.nvidia.com
74+
- machineconfiguration.openshift.io
7575
resources:
76-
- maintenanceoperatorconfigs/status
76+
- machineconfigs
7777
verbs:
7878
- get
79-
- patch
80-
- update
79+
- list
80+
- watch
8181
- apiGroups:
8282
- maintenance.nvidia.com
8383
resources:
84+
- maintenanceoperatorconfigs
8485
- nodemaintenances
8586
verbs:
8687
- create
@@ -93,12 +94,14 @@ rules:
9394
- apiGroups:
9495
- maintenance.nvidia.com
9596
resources:
97+
- maintenanceoperatorconfigs/finalizers
9698
- nodemaintenances/finalizers
9799
verbs:
98100
- update
99101
- apiGroups:
100102
- maintenance.nvidia.com
101103
resources:
104+
- maintenanceoperatorconfigs/status
102105
- nodemaintenances/status
103106
verbs:
104107
- get

deployment/maintenance-operator-chart/templates/role.yaml

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
1+
---
12
apiVersion: rbac.authorization.k8s.io/v1
23
kind: ClusterRole
34
metadata:
45
name: {{ include "maintenance-operator.fullname" . }}-manager-role
56
labels:
67
{{- include "maintenance-operator.labels" . | nindent 4 }}
78
rules:
8-
- apiGroups:
9-
- authentication.k8s.io
10-
resources:
11-
- tokenreviews
12-
verbs:
13-
- create
14-
- apiGroups:
15-
- authorization.k8s.io
16-
resources:
17-
- subjectaccessreviews
18-
verbs:
19-
- create
20-
- nonResourceURLs:
21-
- /metrics
22-
verbs:
23-
- get
249
- apiGroups:
2510
- ""
2611
resources:
@@ -62,34 +47,43 @@ rules:
6247
- patch
6348
- update
6449
- apiGroups:
65-
- maintenance.nvidia.com
50+
- apps
6651
resources:
67-
- maintenanceoperatorconfigs
52+
- daemonsets
6853
verbs:
69-
- create
70-
- delete
7154
- get
7255
- list
73-
- patch
74-
- update
7556
- watch
7657
- apiGroups:
77-
- maintenance.nvidia.com
58+
- config.openshift.io
7859
resources:
79-
- maintenanceoperatorconfigs/finalizers
60+
- infrastructures
8061
verbs:
81-
- update
62+
- get
63+
- list
64+
- watch
8265
- apiGroups:
83-
- maintenance.nvidia.com
66+
- machineconfiguration.openshift.io
8467
resources:
85-
- maintenanceoperatorconfigs/status
68+
- machineconfigpools
8669
verbs:
8770
- get
71+
- list
8872
- patch
8973
- update
74+
- watch
75+
- apiGroups:
76+
- machineconfiguration.openshift.io
77+
resources:
78+
- machineconfigs
79+
verbs:
80+
- get
81+
- list
82+
- watch
9083
- apiGroups:
9184
- maintenance.nvidia.com
9285
resources:
86+
- maintenanceoperatorconfigs
9387
- nodemaintenances
9488
verbs:
9589
- create
@@ -102,26 +96,19 @@ rules:
10296
- apiGroups:
10397
- maintenance.nvidia.com
10498
resources:
99+
- maintenanceoperatorconfigs/finalizers
105100
- nodemaintenances/finalizers
106101
verbs:
107102
- update
108103
- apiGroups:
109104
- maintenance.nvidia.com
110105
resources:
106+
- maintenanceoperatorconfigs/status
111107
- nodemaintenances/status
112108
verbs:
113109
- get
114110
- patch
115111
- update
116-
- apiGroups:
117-
- apps
118-
resources:
119-
- daemonsets
120-
verbs:
121-
- get
122-
- list
123-
- watch
124-
125112
---
126113
apiVersion: rbac.authorization.k8s.io/v1
127114
kind: Role

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/go-logr/logr v1.4.2
1010
github.com/onsi/ginkgo/v2 v2.22.2
1111
github.com/onsi/gomega v1.36.2
12+
github.com/openshift/api v0.0.0-20250102185430-d6d8306a24ec
1213
github.com/pkg/errors v0.9.1
1314
github.com/stretchr/testify v1.10.0
1415
go.uber.org/zap v1.27.0
@@ -30,7 +31,6 @@ require (
3031
github.com/chai2010/gettext-go v1.0.2 // indirect
3132
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3233
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
33-
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
3434
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
3535
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
3636
github.com/fsnotify/fsnotify v1.7.0 // indirect
@@ -73,7 +73,7 @@ require (
7373
github.com/prometheus/procfs v0.15.1 // indirect
7474
github.com/russross/blackfriday/v2 v2.1.0 // indirect
7575
github.com/spf13/cobra v1.8.1 // indirect
76-
github.com/spf13/pflag v1.0.5 // indirect
76+
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace // indirect
7777
github.com/stretchr/objx v0.5.2 // indirect
7878
github.com/x448/float16 v0.8.4 // indirect
7979
github.com/xlab/treeprint v1.2.0 // indirect

go.sum

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
2222
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2323
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
2424
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
25-
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
26-
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
25+
github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8P3k=
26+
github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ=
2727
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
2828
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
2929
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f h1:Wl78ApPPB2Wvf/TIe2xdyJxTlb6obmF18d8QdkxNDu4=
@@ -112,6 +112,8 @@ github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU
112112
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
113113
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
114114
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
115+
github.com/openshift/api v0.0.0-20250102185430-d6d8306a24ec h1:VEDRGJmiYeN0V0xW1aI9wfzEMgaMZOVasy3FzEz27Lo=
116+
github.com/openshift/api v0.0.0-20250102185430-d6d8306a24ec/go.mod h1:Shkl4HanLwDiiBzakv+con/aMGnVE2MAGvoKp5oyYUo=
115117
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
116118
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
117119
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -135,8 +137,9 @@ github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
135137
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
136138
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
137139
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
138-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
139140
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
141+
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace h1:9PNP1jnUjRhfmGMlkXHjYPishpcw4jpSt/V/xYY3FMA=
142+
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
140143
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
141144
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
142145
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=

0 commit comments

Comments
 (0)