Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oper leader elect #115

Closed
wants to merge 8 commits into from
Closed
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: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ EMBEDDED_YAMLS := pkg/embeddedyamls/yamls.go
$(EMBEDDED_YAMLS): pkg/embeddedyamls/generators/yamls2go.go deploy/crds/submariner.io_servicediscoveries.yaml deploy/crds/submariner.io_brokers.yaml deploy/crds/submariner.io_submariners.yaml deploy/submariner/crds/submariner.io_clusterglobalegressips.yaml deploy/submariner/crds/submariner.io_clusters.yaml deploy/submariner/crds/submariner.io_endpoints.yaml deploy/submariner/crds/submariner.io_gatewayroutes.yaml deploy/submariner/crds/submariner.io_gateways.yaml deploy/submariner/crds/submariner.io_globalegressips.yaml deploy/submariner/crds/submariner.io_globalingressips.yaml deploy/submariner/crds/submariner.io_nongatewayroutes.yaml deploy/submariner/crds/submariner.io_routeagents.yaml $(shell find deploy/ -name "*.yaml") $(shell find config/rbac/ -name "*.yaml") $(CONTROLLER_DEEPCOPY)
$(GO) generate pkg/embeddedyamls/generate.go

bin/%/submariner-operator: main.go $(EMBEDDED_YAMLS)
bin/%/submariner-operator: cmd/main.go $(EMBEDDED_YAMLS)
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) \
LDFLAGS="-X=main.version=$(VERSION)" \
${SCRIPTS_DIR}/compile.sh $@ .
${SCRIPTS_DIR}/compile.sh $@ ./cmd

ci: $(EMBEDDED_YAMLS) golangci-lint markdownlint unit build images

Expand Down Expand Up @@ -185,7 +185,7 @@ is-semantic-version:
# Download kustomize locally if not already downloaded.
# We clear GITHUB_TOKEN to ensure that the installation script won't try to use it (and fail)
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
KUSTOMIZE_VERSION := $(shell cd tools && $(GO) list -m -f {{.Version}} sigs.k8s.io/kustomize/kustomize/v3)
KUSTOMIZE_VERSION := $(shell cd tools && $(GO) list -m -f {{.Version}} sigs.k8s.io/kustomize/kustomize/v5)
$(KUSTOMIZE):
mkdir -p $(@D)
{ curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | GITHUB_TOKEN= bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(@D); }
Expand All @@ -208,7 +208,7 @@ bundle: $(KUSTOMIZE) $(OPERATOR_SDK) kustomization
(set -o pipefail; $(KUSTOMIZE) build $(KUSTOMIZE_BASE_PATH) \
| $(OPERATOR_SDK) generate bundle -q --overwrite --version $(BUNDLE_VERSION) $(BUNDLE_METADATA_OPTS))
(cd config/bundle && $(KUSTOMIZE) edit add resource ../../bundle/manifests/submariner.clusterserviceversion.yaml)
$(KUSTOMIZE) build config/bundle/ --load_restrictor=LoadRestrictionsNone --output bundle/manifests/submariner.clusterserviceversion.yaml
$(KUSTOMIZE) build config/bundle/ --load-restrictor=LoadRestrictionsNone --output bundle/manifests/submariner.clusterserviceversion.yaml
sed -i -e 's/$$(SHORT_VERSION)/$(SHORT_VERSION)/g' bundle/manifests/submariner.clusterserviceversion.yaml
sed -i -e 's/$$(VERSION)/$(VERSION)/g' bundle/manifests/submariner.clusterserviceversion.yaml
$(OPERATOR_SDK) bundle validate --select-optional suite=operatorframework ./bundle
Expand Down
2 changes: 1 addition & 1 deletion PROJECT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
domain: submariner.io
layout:
- go.kubebuilder.io/v3
- go.kubebuilder.io/v4
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
Expand Down
29 changes: 9 additions & 20 deletions main.go → cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,19 @@ limitations under the License.
package main

import (
"context"
"flag"
"fmt"
"os"
"runtime"

configv1 "github.com/openshift/api/config/v1"
"github.com/operator-framework/operator-lib/leader"
"github.com/submariner-io/admiral/pkg/log/kzerolog"
"github.com/submariner-io/admiral/pkg/names"
admversion "github.com/submariner-io/admiral/pkg/version"
"github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/metrics"
"github.com/submariner-io/submariner-operator/controllers/servicediscovery"
"github.com/submariner-io/submariner-operator/controllers/submariner"
"github.com/submariner-io/submariner-operator/internal/controllers/metrics"
"github.com/submariner-io/submariner-operator/internal/controllers/servicediscovery"
"github.com/submariner-io/submariner-operator/internal/controllers/submariner"
"github.com/submariner-io/submariner-operator/pkg/crd"
"github.com/submariner-io/submariner-operator/pkg/gateway"
"github.com/submariner-io/submariner-operator/pkg/lighthouse"
Expand All @@ -48,10 +46,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
)

Expand Down Expand Up @@ -87,8 +83,7 @@ func main() {
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&pprofAddr, "pprof-bind-address", ":8082", "The address the profiling endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
"Enable leader election for the controller manager to ensure there is only one active instance.")

kzerolog.AddFlags(nil)
flag.Parse()
Expand Down Expand Up @@ -116,19 +111,13 @@ func main() {
}

// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
cfg, err := ctrl.GetConfig()
if err != nil {
log.Error(err, "")
log.Error(err, "unable to get kubeconfig")
os.Exit(1)
}

ctx := context.TODO()
// Become the leader before proceeding
err = leader.Become(ctx, "submariner-operator-lock")
if err != nil {
log.Error(err, "")
os.Exit(1)
}
ctx := ctrl.SetupSignalHandler()

// Set up the CRDs we need
crdUpdater, err := crd.UpdaterFromRestConfig(cfg)
Expand Down Expand Up @@ -163,7 +152,7 @@ func main() {
// +kubebuilder:scaffold:scheme

// Create a new Cmd to provide shared dependencies and start components
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Metrics: server.Options{
BindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
Expand Down Expand Up @@ -258,7 +247,7 @@ func main() {
// Start the Cmd
log.Info("Starting the Cmd.")

if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
if err := mgr.Start(ctx); err != nil {
log.Error(err, "Manager exited non-zero")
os.Exit(1)
}
Expand Down
25 changes: 15 additions & 10 deletions config/crd/bases/submariner.io_brokers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.1
controller-gen.kubebuilder.io/version: v0.16.5
name: brokers.submariner.io
spec:
group: submariner.io
Expand All @@ -20,14 +20,19 @@ spec:
description: Broker is the Schema for the brokers API.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
Expand All @@ -38,6 +43,9 @@ spec:
description: ClustersetIP supernet range for allocating ClustersetIPCIDRs
to each cluster.
type: string
clustersetIPEnabled:
description: Enable ClustersetIP default for connecting clusters.
type: boolean
components:
description: List of the components to be installed - any of [service-discovery,
connectivity].
Expand All @@ -60,9 +68,6 @@ spec:
globalnetEnabled:
description: Enable support for Overlapping CIDRs in connecting clusters.
type: boolean
clustersetIPEnabled:
description: Enable ClustersetIP default for connecting clusters.
type: boolean
type: object
status:
description: BrokerStatus defines the observed state of Broker.
Expand Down
68 changes: 36 additions & 32 deletions config/crd/bases/submariner.io_servicediscoveries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.1
controller-gen.kubebuilder.io/version: v0.16.5
name: servicediscoveries.submariner.io
spec:
group: submariner.io
Expand All @@ -20,14 +20,19 @@ spec:
description: ServiceDiscovery is the Schema for the servicediscoveries API.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
Expand All @@ -50,6 +55,8 @@ spec:
type: string
clustersetIPCIDR:
type: string
clustersetIPEnabled:
type: boolean
coreDNSCustomConfig:
properties:
configMapName:
Expand All @@ -70,8 +77,6 @@ spec:
type: boolean
haltOnCertificateError:
type: boolean
clustersetIPEnabled:
type: boolean
imageOverrides:
additionalProperties:
type: string
Expand All @@ -86,40 +91,39 @@ spec:
type: string
tolerations:
items:
description: The pod this Toleration is attached to tolerates any
taint that matches the triple <key,value,effect> using the matching
operator <operator>.
description: |-
The pod this Toleration is attached to tolerates any taint that matches
the triple <key,value,effect> using the matching operator <operator>.
properties:
effect:
description: Effect indicates the taint effect to match. Empty
means match all taint effects. When specified, allowed values
are NoSchedule, PreferNoSchedule and NoExecute.
description: |-
Effect indicates the taint effect to match. Empty means match all taint effects.
When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute.
type: string
key:
description: Key is the taint key that the toleration applies
to. Empty means match all taint keys. If the key is empty,
operator must be Exists; this combination means to match all
values and all keys.
description: |-
Key is the taint key that the toleration applies to. Empty means match all taint keys.
If the key is empty, operator must be Exists; this combination means to match all values and all keys.
type: string
operator:
description: Operator represents a key's relationship to the
value. Valid operators are Exists and Equal. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod
can tolerate all taints of a particular category.
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
type: string
tolerationSeconds:
description: TolerationSeconds represents the period of time
the toleration (which must be of effect NoExecute, otherwise
this field is ignored) tolerates the taint. By default, it
is not set, which means tolerate the taint forever (do not
evict). Zero and negative values will be treated as 0 (evict
immediately) by the system.
description: |-
TolerationSeconds represents the period of time the toleration (which must be
of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default,
it is not set, which means tolerate the taint forever (do not evict). Zero and
negative values will be treated as 0 (evict immediately) by the system.
format: int64
type: integer
value:
description: Value is the taint value the toleration matches
to. If the operator is Exists, the value should be empty,
otherwise just a regular string.
description: |-
Value is the taint value the toleration matches to.
If the operator is Exists, the value should be empty, otherwise just a regular string.
type: string
type: object
type: array
Expand Down
Loading
Loading