Skip to content
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
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ rules:
- get
- list
- watch
- apiGroups:
- config.openshift.io
resources:
- infrastructures
verbs:
- get
- list
- watch
- apiGroups:
- machineconfiguration.openshift.io
resources:
Expand Down
1 change: 1 addition & 0 deletions controllers/performanceprofile_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func validateUpdateEvent(e *event.UpdateEvent) bool {
// +kubebuilder:rbac:groups=machineconfiguration.openshift.io,resources=machineconfigs;machineconfigpools;kubeletconfigs,verbs=*
// +kubebuilder:rbac:groups=tuned.openshift.io,resources=tuneds;profiles,verbs=*
// +kubebuilder:rbac:groups=node.k8s.io,resources=runtimeclasses,verbs=*
// +kubebuilder:rbac:groups=config.openshift.io,resources=infrastructures,verbs=get;list;watch
// +kubebuilder:rbac:namespace="openshift-performance-addon-operator",groups=core,resources=pods;services;services/finalizers;configmaps,verbs=*
// +kubebuilder:rbac:namespace="openshift-performance-addon-operator",groups=coordination.k8s.io,resources=leases,verbs=create;get;list;update
// +kubebuilder:rbac:namespace="openshift-performance-addon-operator",groups=apps,resourceNames=performance-operator,resources=deployments/finalizers,verbs=update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ spec:
- get
- list
- watch
- apiGroups:
- config.openshift.io
resources:
- infrastructures
verbs:
- get
- list
- watch
- apiGroups:
- machineconfiguration.openshift.io
resources:
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/openshift/api v3.9.1-0.20191111211345-a27ff30ebf09+incompatible
github.com/openshift/cluster-node-tuning-operator v0.0.0-20200914165052-a39511828cf0
github.com/openshift/custom-resource-status v0.0.0-20200602122900-c002fd1547ca
github.com/openshift/library-go v0.0.0-20211220195323-eca2c467c492
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why another lib bump? can we squash in the previous?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely let me squash things up, the bump is to just make sure we're on the latest version that pulls in this PR 1273

github.com/openshift/machine-config-operator v4.2.0-alpha.0.0.20190917115525-033375cbe820+incompatible
github.com/operator-framework/api v0.10.7
github.com/operator-framework/operator-lifecycle-manager v3.11.0+incompatible
Expand Down Expand Up @@ -100,6 +101,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/openshift/client-go v0.0.0-20210916133943-9acee1a0fb83 // indirect
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why yet another lib bump? can we squash in the previous?

github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.28.0 // indirect
Expand Down Expand Up @@ -176,7 +178,7 @@ replace (
github.com/openshift/api => github.com/openshift/api v0.0.0-20210610130314-a6ac319a7eed // release-4.8
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142 // release-4.8
github.com/openshift/cluster-node-tuning-operator => github.com/openshift/cluster-node-tuning-operator v0.0.0-20210303185751-cbeeb4d9f3cc // release-4.9
github.com/openshift/library-go => github.com/openshift/library-go v0.0.0-20210706120254-6f1208ffd780 // release-4.8
github.com/openshift/library-go => github.com/openshift/library-go v0.0.0-20211208213416-9b73bdcf5d00 // release-4.8
github.com/openshift/machine-config-operator => github.com/openshift/machine-config-operator v0.0.1-0.20210701174259-29813c845a4a // release-4.8
github.com/operator-framework/operator-sdk => github.com/operator-framework/operator-sdk v0.18.1
golang.org/x/tools => golang.org/x/tools v0.0.0-20191206213732-070c9d21b343
Expand Down
34 changes: 9 additions & 25 deletions go.sum

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
performancev2 "github.com/openshift-kni/performance-addon-operators/api/v2"
"github.com/openshift-kni/performance-addon-operators/controllers"
"github.com/openshift-kni/performance-addon-operators/pkg/controller/performanceprofile/components"
"github.com/openshift-kni/performance-addon-operators/pkg/utils/leaderelection"
"github.com/openshift-kni/performance-addon-operators/version"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -132,12 +133,18 @@ func runPAO() {
metav1.NamespaceNone,
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
restConfig := ctrl.GetConfigOrDie()
le := leaderelection.GetLeaderElectionConfig(restConfig, enableLeaderElection)

mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
NewCache: cache.MultiNamespacedCacheBuilder(namespaces),
Scheme: scheme,
MetricsBindAddress: metricsAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: leaderElectionID,
LeaseDuration: &le.LeaseDuration.Duration,
RetryPeriod: &le.RetryPeriod.Duration,
RenewDeadline: &le.RenewDeadline.Duration,
})

if err != nil {
Expand Down
36 changes: 36 additions & 0 deletions pkg/utils/leaderelection/leaderelection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package leaderelection
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can probably put in pkg/leaderelection (skip utils) but not a big deal, and we can move later


import (
"context"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/library-go/pkg/config/clusterstatus"
"github.com/openshift/library-go/pkg/config/leaderelection"
"k8s.io/client-go/rest"
"k8s.io/klog"
)

// GetLeaderElectionConfig returns leader election configs defaults based on the cluster topology
func GetLeaderElectionConfig(restcfg *rest.Config, enabled bool) configv1.LeaderElection {
Comment thread
eggfoobar marked this conversation as resolved.

// Defaults follow conventions
// https://github.com/openshift/enhancements/blob/master/CONVENTIONS.md#high-availability
defaultLeaderElection := leaderelection.LeaderElectionDefaulting(
configv1.LeaderElection{
Disable: !enabled,
},
"", "",
)

if enabled {
if infra, err := clusterstatus.GetClusterInfraStatus(context.TODO(), restcfg); err == nil && infra != nil {
if infra.ControlPlaneTopology == configv1.SingleReplicaTopologyMode {
return leaderelection.LeaderElectionSNOConfig(defaultLeaderElection)
}
} else {
klog.Warningf("unable to get cluster infrastructure status, using HA cluster values for leader election: %v", err)
}
}

return defaultLeaderElection
}
191 changes: 191 additions & 0 deletions vendor/github.com/openshift/client-go/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading