Skip to content

Commit

Permalink
Support Pause/Unpause MCP in Openshift
Browse files Browse the repository at this point in the history
Implement MCPManager which pauses/unpauses MCP
in openshift environments.

- Add Openshift detection logic
- Implement MCPManager
- Integrate MCPManager in nodemaintenance controller

Signed-off-by: adrianc <adrianc@nvidia.com>
  • Loading branch information
adrianchiris committed Jan 16, 2025
1 parent d25eb29 commit a6e78a6
Show file tree
Hide file tree
Showing 13 changed files with 944 additions and 88 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,16 @@ clean: ## clean files

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

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

.PHONY: test
test: unit-test lint
test: lint unit-test

.PHONY: unit-test
unit-test: envtest ## Run unit tests.
Expand Down
17 changes: 17 additions & 0 deletions cmd/maintenance-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"

ocpconfigv1 "github.com/openshift/api/config/v1"
mcv1 "github.com/openshift/api/machineconfiguration/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand All @@ -40,6 +42,7 @@ import (
"github.com/Mellanox/maintenance-operator/internal/cordon"
"github.com/Mellanox/maintenance-operator/internal/drain"
operatorlog "github.com/Mellanox/maintenance-operator/internal/log"
"github.com/Mellanox/maintenance-operator/internal/openshift"
"github.com/Mellanox/maintenance-operator/internal/podcompletion"
"github.com/Mellanox/maintenance-operator/internal/scheduler"
"github.com/Mellanox/maintenance-operator/internal/version"
Expand All @@ -54,6 +57,8 @@ var (

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(ocpconfigv1.Install(scheme))
utilruntime.Must(mcv1.Install(scheme))

utilruntime.Must(maintenancev1alpha1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
Expand Down Expand Up @@ -147,12 +152,24 @@ func main() {
ctx := ctrl.SetupSignalHandler()
mgrClient := mgr.GetClient()

ocpUtils, err := openshift.NewOpenshiftUtils(ctx, mgr.GetAPIReader())
if err != nil {
setupLog.Error(err, "unable to create openshift utils")
os.Exit(1)
}

if ocpUtils.IsOpenshift() {
setupLog.Info("openshift cluster detected",
"isOpenshift", ocpUtils.IsOpenshift(), "isHypershift", ocpUtils.IsHypershift())
}

if err = (&controller.NodeMaintenanceReconciler{
Client: mgrClient,
Scheme: mgr.GetScheme(),
CordonHandler: cordon.NewCordonHandler(mgrClient, k8sInterface),
WaitPodCompletionHandler: podcompletion.NewPodCompletionHandler(mgrClient),
DrainManager: drain.NewManager(ctrl.Log.WithName("DrainManager"), ctx, k8sInterface),
MCPManager: openshift.NewMCPManager(ocpUtils, mgrClient),
}).SetupWithManager(ctx, mgr, ctrl.Log.WithName("NodeMaintenanceReconciler")); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "NodeMaintenance")
os.Exit(1)
Expand Down
27 changes: 15 additions & 12 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,35 @@ rules:
- list
- watch
- apiGroups:
- maintenance.nvidia.com
- config.openshift.io
resources:
- maintenanceoperatorconfigs
- infrastructures
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- maintenance.nvidia.com
- machineconfiguration.openshift.io
resources:
- maintenanceoperatorconfigs/finalizers
- machineconfigpools
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- maintenance.nvidia.com
- machineconfiguration.openshift.io
resources:
- maintenanceoperatorconfigs/status
- machineconfigs
verbs:
- get
- patch
- update
- list
- watch
- apiGroups:
- maintenance.nvidia.com
resources:
- maintenanceoperatorconfigs
- nodemaintenances
verbs:
- create
Expand All @@ -93,12 +94,14 @@ rules:
- apiGroups:
- maintenance.nvidia.com
resources:
- maintenanceoperatorconfigs/finalizers
- nodemaintenances/finalizers
verbs:
- update
- apiGroups:
- maintenance.nvidia.com
resources:
- maintenanceoperatorconfigs/status
- nodemaintenances/status
verbs:
- get
Expand Down
59 changes: 23 additions & 36 deletions deployment/maintenance-operator-chart/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "maintenance-operator.fullname" . }}-manager-role
labels:
{{- include "maintenance-operator.labels" . | nindent 4 }}
rules:
- apiGroups:
- authentication.k8s.io
resources:
- tokenreviews
verbs:
- create
- apiGroups:
- authorization.k8s.io
resources:
- subjectaccessreviews
verbs:
- create
- nonResourceURLs:
- /metrics
verbs:
- get
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -62,34 +47,43 @@ rules:
- patch
- update
- apiGroups:
- maintenance.nvidia.com
- apps
resources:
- maintenanceoperatorconfigs
- daemonsets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- maintenance.nvidia.com
- config.openshift.io
resources:
- maintenanceoperatorconfigs/finalizers
- infrastructures
verbs:
- update
- get
- list
- watch
- apiGroups:
- maintenance.nvidia.com
- machineconfiguration.openshift.io
resources:
- maintenanceoperatorconfigs/status
- machineconfigpools
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- machineconfiguration.openshift.io
resources:
- machineconfigs
verbs:
- get
- list
- watch
- apiGroups:
- maintenance.nvidia.com
resources:
- maintenanceoperatorconfigs
- nodemaintenances
verbs:
- create
Expand All @@ -102,26 +96,19 @@ rules:
- apiGroups:
- maintenance.nvidia.com
resources:
- maintenanceoperatorconfigs/finalizers
- nodemaintenances/finalizers
verbs:
- update
- apiGroups:
- maintenance.nvidia.com
resources:
- maintenanceoperatorconfigs/status
- nodemaintenances/status
verbs:
- get
- patch
- update
- apiGroups:
- apps
resources:
- daemonsets
verbs:
- get
- list
- watch

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/go-logr/logr v1.4.2
github.com/onsi/ginkgo/v2 v2.22.2
github.com/onsi/gomega v1.36.2
github.com/openshift/api v0.0.0-20250102185430-d6d8306a24ec
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.10.0
go.uber.org/zap v1.27.0
Expand All @@ -30,7 +31,6 @@ require (
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand Down Expand Up @@ -73,7 +73,7 @@ require (
github.com/prometheus/procfs v0.15.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
Expand Down
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8P3k=
github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ=
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f h1:Wl78ApPPB2Wvf/TIe2xdyJxTlb6obmF18d8QdkxNDu4=
Expand Down Expand Up @@ -112,6 +112,8 @@ github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
github.com/openshift/api v0.0.0-20250102185430-d6d8306a24ec h1:VEDRGJmiYeN0V0xW1aI9wfzEMgaMZOVasy3FzEz27Lo=
github.com/openshift/api v0.0.0-20250102185430-d6d8306a24ec/go.mod h1:Shkl4HanLwDiiBzakv+con/aMGnVE2MAGvoKp5oyYUo=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand All @@ -135,8 +137,9 @@ github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace h1:9PNP1jnUjRhfmGMlkXHjYPishpcw4jpSt/V/xYY3FMA=
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
Loading

0 comments on commit a6e78a6

Please sign in to comment.