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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.16 AS builder
FROM golang:1.17 AS builder
WORKDIR /go/src/github.com/openshift/ptp-operator
COPY . .
ENV GO111MODULE=off
Expand Down
8 changes: 8 additions & 0 deletions bundle/manifests/ptp-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ spec:
- rolebindings
verbs:
- '*'
- apiGroups:
- config.openshift.io
resources:
- infrastructures
verbs:
- get
- list
- watch
- apiGroups:
- ptp.openshift.io
resources:
Expand Down
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- config.openshift.io
resources:
- infrastructures
verbs:
- get
- list
- watch
- apiGroups:
- ptp.openshift.io
resources:
Expand Down
1 change: 1 addition & 0 deletions controllers/ptpconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type PtpConfigReconciler struct {
//+kubebuilder:rbac:groups=ptp.openshift.io,resources=ptpconfigs,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=ptp.openshift.io,resources=ptpconfigs/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=ptp.openshift.io,resources=ptpconfigs/finalizers,verbs=update
//+kubebuilder:rbac:groups=config.openshift.io,resources=infrastructures,verbs=get;list;watch

func (r *PtpConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (reconcile.Result, error) {
reqLogger := r.Log.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)
Expand Down
1 change: 1 addition & 0 deletions controllers/ptpoperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
//+kubebuilder:rbac:groups=ptp.openshift.io,resources=ptpoperatorconfigs,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=ptp.openshift.io,resources=ptpoperatorconfigs/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=ptp.openshift.io,resources=ptpoperatorconfigs/finalizers,verbs=update
//+kubebuilder:rbac:groups=config.openshift.io,resources=infrastructures,verbs=get;list;watch

func (r *PtpOperatorConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (reconcile.Result, error) {
reqLogger := r.Log.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)
Expand Down
31 changes: 17 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/go-logr/logr v0.4.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/go-logr/logr v1.2.0
github.com/golang/glog v1.0.0
github.com/huandu/xstrings v1.3.2 // indirect
github.com/mitchellh/copystructure v1.1.1 // indirect
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.13.0
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.17.0
github.com/openshift/api v0.0.0-20211209135129-c58d9f695577
github.com/openshift/library-go v0.0.0-20211220195323-eca2c467c492
github.com/pkg/errors v0.9.1
k8s.io/api v0.22.2
k8s.io/apiextensions-apiserver v0.22.2
k8s.io/apimachinery v0.22.2
k8s.io/api v0.23.0
k8s.io/apiextensions-apiserver v0.23.0
k8s.io/apimachinery v0.23.0
k8s.io/client-go v1.5.2
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a
sigs.k8s.io/controller-runtime v0.9.2
k8s.io/klog v1.0.0
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b
sigs.k8s.io/controller-runtime v0.11.0
)

// Manually pinned to kubernetes-1.22.2
// Manually pinned to kubernetes-1.23.0
replace (
k8s.io/api => k8s.io/api v0.22.2
k8s.io/apimachinery => k8s.io/apimachinery v0.22.2
k8s.io/client-go => k8s.io/client-go v0.22.2
k8s.io/api => k8s.io/api v0.23.0
k8s.io/apimachinery => k8s.io/apimachinery v0.23.0
k8s.io/client-go => k8s.io/client-go v0.23.0
)
518 changes: 435 additions & 83 deletions go.sum

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (

ptpv1 "github.com/openshift/ptp-operator/api/v1"
"github.com/openshift/ptp-operator/controllers"
"github.com/openshift/ptp-operator/pkg/leaderelection"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the leaderelection implementation specific to ptp-operator? Why aren't you just importing https://github.com/openshift/library-go/blob/master/pkg/config/leaderelection/leaderelection.go here?

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.

Hey @josephdrichard You're right this isn't specific to ptp-operator. When the PR was opened there was a breaking dependency change between the k8s-23 libs and controller-runtime. It was causing some problems and I figured a bit of code was the better approach for now since library-go wasn't being used else where in the code. Luckily, controller-runtime was updated a few hours so we can import it now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are you still looking to update this?

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.

Apologies, forgot to mention in the reply. This PR has been updated with the latest library-go code and I'm using those methods to drive the leaderelection configs

"github.com/openshift/ptp-operator/pkg/names"
//+kubebuilder:scaffold:imports
)
Expand All @@ -61,14 +62,19 @@ func main() {
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.Parse()

restConfig := ctrl.GetConfigOrDie()
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
le := leaderelection.GetLeaderElectionConfig(restConfig, enableLeaderElection)

namespace := os.Getenv("WATCH_NAMESPACE")
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaseDuration: &le.LeaseDuration.Duration,
RenewDeadline: &le.RenewDeadline.Duration,
RetryPeriod: &le.RetryPeriod.Duration,
LeaderElectionID: "ptp.openshift.io",
Namespace: namespace,
})
Expand Down
8 changes: 8 additions & 0 deletions manifests/stable/ptp-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ spec:
- rolebindings
verbs:
- '*'
- apiGroups:
- config.openshift.io
resources:
- infrastructures
verbs:
- get
- list
- watch
- apiGroups:
- ptp.openshift.io
resources:
Expand Down
39 changes: 39 additions & 0 deletions pkg/leaderelection/leaderelection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package leaderelection

import (
"context"
"time"

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(restConfig *rest.Config, enabled bool) configv1.LeaderElection {

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

if enabled {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()
if infra, err := clusterstatus.GetClusterInfraStatus(ctx, restConfig); 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
}
3 changes: 2 additions & 1 deletion vendor/cloud.google.com/go/compute/metadata/metadata.go

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.

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

This file was deleted.

16 changes: 13 additions & 3 deletions vendor/github.com/fsnotify/fsnotify/AUTHORS

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

Loading