Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #663 from hongchaodeng/le
Browse files Browse the repository at this point in the history
import leader election here and remove k8s dep
  • Loading branch information
hongchaodeng committed Jan 21, 2017
2 parents 1aeefcb + 1137a7f commit eae902d
Show file tree
Hide file tree
Showing 7 changed files with 497 additions and 184 deletions.
46 changes: 8 additions & 38 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"flag"
"fmt"
"net/url"
"os"
"time"

Expand All @@ -28,19 +27,17 @@ import (
"github.com/coreos/etcd-operator/pkg/controller"
"github.com/coreos/etcd-operator/pkg/garbagecollection"
"github.com/coreos/etcd-operator/pkg/util/k8sutil"
"github.com/coreos/etcd-operator/pkg/util/k8sutil/election"
"github.com/coreos/etcd-operator/pkg/util/k8sutil/election/resourcelock"
"github.com/coreos/etcd-operator/version"

"github.com/Sirupsen/logrus"
"golang.org/x/time/rate"
"k8s.io/client-go/1.5/kubernetes"
"k8s.io/client-go/1.5/pkg/api"
"k8s.io/client-go/1.5/pkg/labels"
"k8s.io/client-go/1.5/rest"
k8sapi "k8s.io/kubernetes/pkg/api"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/leaderelection"
"k8s.io/kubernetes/pkg/client/leaderelection/resourcelock"
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/client-go/1.5/tools/record"
)

var (
Expand Down Expand Up @@ -112,11 +109,11 @@ func main() {
// TODO: replace this to client-go once leader election pacakge is imported
// https://github.com/kubernetes/client-go/issues/28
rl := &resourcelock.EndpointsLock{
EndpointsMeta: k8sapi.ObjectMeta{
EndpointsMeta: api.ObjectMeta{
Namespace: namespace,
Name: "etcd-operator",
},
Client: mustCreateLeaderElectionClient(masterHost, tlsInsecure, &restclient.TLSClientConfig{
Client: k8sutil.MustCreateClient(masterHost, tlsInsecure, &rest.TLSClientConfig{
CertFile: certFile,
KeyFile: keyFile,
CAFile: caFile,
Expand All @@ -127,12 +124,12 @@ func main() {
},
}

leaderelection.RunOrDie(leaderelection.LeaderElectionConfig{
election.RunOrDie(election.LeaderElectionConfig{
Lock: rl,
LeaseDuration: leaseDuration,
RenewDeadline: renewDuration,
RetryPeriod: retryPeriod,
Callbacks: leaderelection.LeaderCallbacks{
Callbacks: election.LeaderCallbacks{
OnStartedLeading: run,
OnStoppedLeading: func() {
logrus.Fatalf("leader election lost")
Expand Down Expand Up @@ -235,30 +232,3 @@ func startChaos(ctx context.Context, k8s kubernetes.Interface, ns string, chaosL
default:
}
}

func mustCreateLeaderElectionClient(host string, tlsInsecure bool, tlsConfig *restclient.TLSClientConfig) clientset.Interface {
var cfg *restclient.Config
if len(host) == 0 {
var err error
cfg, err = restclient.InClusterConfig()
if err != nil {
panic(err)
}
} else {
cfg = &restclient.Config{
Host: host,
QPS: 100,
Burst: 100,
}
hostUrl, err := url.Parse(host)
if err != nil {
panic(fmt.Sprintf("failed to parse host url %s : %v", host, err))
}
if hostUrl.Scheme == "https" {
cfg.TLSClientConfig = *tlsConfig
cfg.Insecure = tlsInsecure
}
}

return clientset.NewForConfigOrDie(cfg)
}
164 changes: 20 additions & 144 deletions glide.lock

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

2 changes: 0 additions & 2 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ import:
version: v3.1.0-alpha.1
- package: k8s.io/client-go
version: v1.5.0
- package: k8s.io/kubernetes
version: v1.5.2
20 changes: 20 additions & 0 deletions pkg/util/k8sutil/election/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Date: 01/20/17

This package is imported from Kubernetes 1.5 branch .

client-go doesn’t have leader election package imported at the time of writing.
We are trying our best to communicate with upstream and get that package imported to client-go.

Meanwhile, that process is slow, and even complicated due to a few aspects:

- The importing work seems to be happening on 2.0/master but not 1.5 that we are using.
- We are using client-go 1.5 which is k8s 1.4, and we need to pull packages from k8s 1.5 due to some concern.
This is mixing versions, which gets things more complicated.
- This might introduce new API to client-go 1.5, which might get things more complicated.
- There are still concerns on upstream on “write to endpoints”. This is the most complicated.

The situation is complicated, and we need to expedite our work.
Thus, we fork "pkg/client/leaderelection" from Kubernetes 1.5 branch to our repo.

Nonetheless, we should try our best to push the changes to upstream and communicate with community members to resolve the problem.
After that we should replace it to client-go again.
Loading

0 comments on commit eae902d

Please sign in to comment.