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
  •  
  •  
  •  
26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ require (
github.com/google/go-cmp v0.5.5
github.com/google/uuid v1.1.2
github.com/imdario/mergo v0.3.8 // indirect
github.com/openshift/api v0.0.0-20210923172539-00988ef88ee0
github.com/openshift/client-go v0.0.0-20200827190008-3062137373b5
github.com/openshift/library-go v0.0.0-20201013192036-5bd7c282e3e7
github.com/openshift/api v0.0.0-20211209135129-c58d9f695577
github.com/openshift/client-go v0.0.0-20211209144617-7385dd6338e3
github.com/openshift/library-go v0.0.0-20211209153216-ed9bc958bd8a
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.26.0
github.com/spf13/cobra v1.1.3
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023
github.com/prometheus/common v0.28.0
github.com/spf13/cobra v1.2.1
golang.org/x/net v0.0.0-20210825183410-e898025ed96a
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
k8s.io/api v0.22.1
k8s.io/apiextensions-apiserver v0.22.1
k8s.io/apimachinery v0.22.1
k8s.io/client-go v0.22.1
k8s.io/klog/v2 v2.9.0
k8s.io/kube-aggregator v0.22.1
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
k8s.io/api v0.23.0
k8s.io/apiextensions-apiserver v0.23.0
k8s.io/apimachinery v0.23.0
k8s.io/client-go v0.23.0
k8s.io/klog/v2 v2.30.0
k8s.io/kube-aggregator v0.23.0
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b
)
328 changes: 231 additions & 97 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/resourcemerge/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,18 @@ func ensureProbe(modified *bool, existing *corev1.Probe, required corev1.Probe)
setInt32(modified, &existing.SuccessThreshold, required.SuccessThreshold)
setInt32(modified, &existing.FailureThreshold, required.FailureThreshold)

ensureProbeHandler(modified, &existing.Handler, required.Handler)
ensureProbeHandler(modified, &existing.ProbeHandler, required.ProbeHandler)
}

func ensureProbeHandler(modified *bool, existing *corev1.Handler, required corev1.Handler) {
func ensureProbeHandler(modified *bool, existing *corev1.ProbeHandler, required corev1.ProbeHandler) {
ensureProbeHandlerDefaults(&required)
if !equality.Semantic.DeepEqual(required, *existing) {
*modified = true
*existing = required
}
}

func ensureProbeHandlerDefaults(handler *corev1.Handler) {
func ensureProbeHandlerDefaults(handler *corev1.ProbeHandler) {
if handler.HTTPGet != nil && handler.HTTPGet.Scheme == "" {
handler.HTTPGet.Scheme = corev1.URISchemeHTTP
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/payload/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"

configv1 "github.com/openshift/api/config/v1"
imagev1 "github.com/openshift/api/image/v1"
Expand Down Expand Up @@ -117,8 +118,11 @@ func Test_loadUpdatePayload(t *testing.T) {
t.Errorf("loadUpdatePayload() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("loadUpdatePayload() = %s", diff.ObjectReflectDiff(tt.want, got))
// Manifest holds an unexported type of 'resourceID' with a field name of 'id'
// DeepEqual fails, so here we use cmp.Diff to ignore just that field to avoid false positives
stringDiff := cmp.Diff(tt.want, got, cmpopts.IgnoreFields(manifest.Manifest{}, "id"))
if !reflect.DeepEqual(got, tt.want) && stringDiff != "" {
t.Errorf("loadUpdatePayload() = %s", stringDiff)
}
})
}
Expand Down
37 changes: 29 additions & 8 deletions pkg/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
"github.com/openshift/cluster-version-operator/pkg/featurechangestopper"
"github.com/openshift/cluster-version-operator/pkg/internal"
"github.com/openshift/cluster-version-operator/pkg/payload"
"github.com/openshift/library-go/pkg/config/clusterstatus"
libgoleaderelection "github.com/openshift/library-go/pkg/config/leaderelection"
"github.com/openshift/library-go/pkg/crypto"
)

Expand All @@ -46,10 +48,6 @@ const (
defaultComponentNamespace = "openshift-cluster-version"

minResyncPeriod = 2 * time.Minute

leaseDuration = 137 * time.Second
renewDeadline = 107 * time.Second
retryPeriod = 26 * time.Second
)

// Options are the valid inputs to starting the CVO.
Expand Down Expand Up @@ -77,6 +75,8 @@ type Options struct {
Namespace string
PayloadOverride string
ResyncInterval time.Duration

leaderElection configv1.LeaderElection
}

type asyncResult struct {
Expand Down Expand Up @@ -157,7 +157,7 @@ func (o *Options) Run(ctx context.Context) error {
if err := controllerCtx.CVO.InitializeFromPayload(cb.RestConfig(defaultQPS), cb.RestConfig(highQPS)); err != nil {
return err
}

o.leaderElection = getLeaderElectionConfig(ctx, cb.RestConfig(defaultQPS))
o.run(ctx, controllerCtx, lock)
return nil
}
Expand Down Expand Up @@ -234,9 +234,9 @@ func (o *Options) run(ctx context.Context, controllerCtx *Context, lock *resourc
leaderelection.RunOrDie(postMainContext, leaderelection.LeaderElectionConfig{
Lock: lock,
ReleaseOnCancel: true,
LeaseDuration: leaseDuration,
RenewDeadline: renewDeadline,
RetryPeriod: retryPeriod,
LeaseDuration: o.leaderElection.LeaseDuration.Duration,
RenewDeadline: o.leaderElection.RenewDeadline.Duration,
RetryPeriod: o.leaderElection.RetryPeriod.Duration,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: func(_ context.Context) { // no need for this passed-through postMainContext, because goroutines we launch inside will use runContext
launchedMain = true
Expand Down Expand Up @@ -417,6 +417,27 @@ func useProtobuf(config *rest.Config) {
config.ContentType = "application/vnd.kubernetes.protobuf"
}

func getLeaderElectionConfig(ctx context.Context, restcfg *rest.Config) configv1.LeaderElection {

// Defaults follow conventions
// https://github.com/openshift/enhancements/pull/832/files#diff-2e28754e69aa417e5b6d89e99e42f05bfb6330800fa823753383db1d170fbc2fR183
// see rhbz#1986477 for more detail
defaultLeaderElection := libgoleaderelection.LeaderElectionDefaulting(
configv1.LeaderElection{},
"", "",
)

if infra, err := clusterstatus.GetClusterInfraStatus(ctx, restcfg); err == nil && infra != nil {
if infra.ControlPlaneTopology == configv1.SingleReplicaTopologyMode {
return libgoleaderelection.LeaderElectionSNOConfig(defaultLeaderElection)
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.

We're not all that particular about our lease settings, and we do have reasonably solid graceful shutdown logic where we release the leases when termination gives us enough time to do that. So I'm personally fine simplifying all of this and just using libgoleaderelection.LeaderElectionSNOConfig all the time, regardless of the Infrastructure configuration. Thoughts?

}
} else {
klog.Warningf("unable to get cluster infrastructure status, using HA cluster values for leader election: %v", err)
}

return defaultLeaderElection
}

// Context holds the controllers for this operator and exposes a unified start command.
type Context struct {
CVO *cvo.Operator
Expand Down
4 changes: 4 additions & 0 deletions pkg/start/start_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func TestIntegrationCVO_initializeAndUpgrade(t *testing.T) {
options.NodeName = "test-node"
options.ReleaseImage = payloadImage1
options.PayloadOverride = filepath.Join(dir, "ignored")
options.leaderElection = getLeaderElectionConfig(ctx, cfg)
includeTechPreview := false
controllers := options.NewControllerContext(cb, includeTechPreview)

Expand Down Expand Up @@ -447,6 +448,7 @@ func TestIntegrationCVO_initializeAndHandleError(t *testing.T) {
options.ReleaseImage = payloadImage1
options.PayloadOverride = filepath.Join(dir, "ignored")
options.ResyncInterval = 3 * time.Second
options.leaderElection = getLeaderElectionConfig(ctx, cfg)
includeTechPreview := false
controllers := options.NewControllerContext(cb, includeTechPreview)

Expand Down Expand Up @@ -563,6 +565,7 @@ func TestIntegrationCVO_gracefulStepDown(t *testing.T) {
options.Name = ns
options.ListenAddr = ""
options.NodeName = "test-node"
options.leaderElection = getLeaderElectionConfig(ctx, cfg)
includeTechPreview := false
controllers := options.NewControllerContext(cb, includeTechPreview)

Expand Down Expand Up @@ -752,6 +755,7 @@ metadata:
options.NodeName = "test-node"
options.ReleaseImage = payloadImage1
options.PayloadOverride = payloadDir
options.leaderElection = getLeaderElectionConfig(ctx, cfg)
includeTechPreview := false
controllers := options.NewControllerContext(cb, includeTechPreview)
if err := controllers.CVO.InitializeFromPayload(cb.RestConfig(defaultQPS), cb.RestConfig(highQPS)); err != nil {
Expand Down

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.

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

Loading