8000 Leader election for deployment, replica set and rc by diptadas · Pull Request #206 · stashed/stash · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Leader election for deployment, replica set and rc #206

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 a 8000 ccount

Merged
merged 31 commits into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
69bd229
Add recovery for restic backup
diptadas Oct 16, 2017
4d3f111
Revise recovery api objects
diptadas Oct 17, 2017
6fa790b
Update codes for api changes
diptadas Oct 17, 2017
5afc14d
Add support for local-backend recovery
diptadas Oct 18, 2017
a456cd6
Add test for deamonset recovery
diptadas Oct 18, 2017
38f8957
Update smartPrefix for workload
diptadas Oct 19, 2017
a5c29c9
Fix DaemonSet tests
diptadas Oct 19, 2017
7ba428d
Add tests for replicaset, satefulset and rc
diptadas Oct 23, 2017
4f99e5a
Merge branch 'master' into recovery
diptadas Oct 24, 2017
9de1d43
Remove focus
diptadas Oct 24, 2017
ea48225
Refactor
diptadas Oct 24, 2017
8cda5f0
Update codegen.sh
tamalsaha Oct 25, 2017
4f46688
Fix +genclient tags
tamalsaha Oct 25, 2017
43d8d46
Use LocalTypedReference as workload and NodeName instead of NodeSelector
diptadas Oct 25, 2017
e3ec50b
WIP: events not working for recovery
diptadas Oct 26, 2017
16b6053
Fix recorder initialization
diptadas Oct 26, 2017
efa9369
Check recovery succeeded/running
diptadas Oct 26, 2017
60667d5
Delete recovery job after completed
diptadas Oct 26, 2017
b20493e
Cleanup
diptadas Oct 27, 2017
b485fac
Implement leader election
diptadas Oct 30, 2017
f306870
Revendor
tamalsaha Oct 30, 2017
7237384
Run leader election only for Deploy, RC and RS
diptadas Oct 31, 2017
fe69beb
Set workload as configmap's owner ref
diptadas Oct 31, 2017
0883151
Update test for leader election
diptadas Oct 31, 2017
bd3e0e3
Add tests for ReplicaSet and RC
diptadas Oct 31, 2017
023ade7
Merge branch 'master' into leader-election
tamalsaha Nov 10, 2017
465b460
added-all
tamalsaha Nov 10, 2017
53f6a86
added-all
tamalsaha Nov 10, 2017
da89e00
Create resource lock Configmap from operator
tamalsaha Nov 11, 2017
6a8cf9d
Fix RBAC
tamalsaha Nov 11, 2017
c7f27eb
added-all
tamalsaha Nov 11, 2017
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
4 changes: 4 additions & 0 deletions chart/stable/stash/templates/cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ rules:
- namespaces
- replicationcontrollers
verbs: ["get", "list", "watch", "patch"]
- apiGroups: [""]
resources:
- configmaps
verbs: ["delete"]
- apiGroups: [""]
resources:
- secrets
Expand Down
62 changes: 33 additions & 29 deletions glide.lock

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

23 changes: 16 additions & 7 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import:
- package: github.com/onsi/gomega
version: v1.2.0
- package: github.com/pkg/errors
- package: github.com/prometheus/client_golang
version: v0.8.0
- package: github.com/spf13/cobra
version: master
- package: github.com/spf13/pflag
Expand All @@ -37,13 +35,24 @@ import:
vcs: git
version: v2
- package: k8s.io/api
version: fe29995db37613b9c5b2a647544cf627bfa8d299
- package: k8s.io/apiextensions-apiserver
version: release-1.8
- package: k8s.io/apimachinery
version: 019ae5ada31de202164b118aee88ee2d14075c31
version: release-1.8
- package: k8s.io/client-go
version: v5.0.0
testImport:
version: kubernetes-1.8.3-beta.0
- package: k8s.io/apiextensions-apiserver
version: release-1.8
- package: k8s.io/kubernetes
repo: https://github.com/appscode/kubernetes.git
version: v1.8.3
vcs: git
- package: github.com/prometheus/client_golang
version: v0.8.0
- package: github.com/prometheus/common
version: 3233b24a36715a2fe36d162260457857a56d672d
- package: github.com/sirupsen/logrus
version: v1.0.3
- package: github.com/docker/distribution
version: edc3ab29cdff8694dd6feb85cfeb4b5f1b38ed9c
- package: github.com/onsi/ginkgo
version: v1.4.0
8 changes: 8 additions & 0 deletions hack/deploy/with-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ rules:
- namespaces
- replicationcontrollers
verbs: ["get", "list", "watch", "patch"]
- apiGroups: [""]
resources:
- configmaps
verbs: ["delete"]
- apiGroups: [""]
resources:
- secrets
Expand Down Expand Up @@ -177,6 +181,10 @@ rules:
- replicationcontrollers
- secrets
verbs: ["get"]
- apiGroups: [""]
resources:
- configmaps
verbs: ["create", "update", "get"]
- apiGroups: [""]
resources:
- events
Expand Down
30 changes: 12 additions & 18 deletions pkg/cmds/schedule.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package cmds

import (
"io/ioutil"
"os"
"strings"
"time"

"github.com/appscode/go/log"
"github.com/appscode/kutil"
api "github.com/appscode/stash/apis/stash/v1alpha1"
cs "github.com/appscode/stash/client/typed/stash/v1alpha1"
"github.com/appscode/stash/pkg/scheduler"
"github.com/appscode/stash/pkg/util"
Expand Down Expand Up @@ -58,28 +58,22 @@ func NewCmdSchedule() *cobra.Command {
if opt.SnapshotHostname, opt.SmartPrefix, err = opt.Workload.HostnamePrefix(opt.PodName, opt.NodeName); err != nil {
log.Fatalf(err.Error())
}
if err = util.CheckWorkloadExists(kubeClient, opt.Namespace, opt.Workload); err != nil {
if err = util.WorkloadExists(kubeClient, opt.Namespace, opt.Workload); err != nil {
log.Fatalf(err.Error())
}

opt.ScratchDir = strings.TrimSuffix(opt.ScratchDir, "/")
err = os.MkdirAll(opt.ScratchDir, 0755)
if err != nil {
log.Fatalf("Failed to create scratch dir: %s", err)
}
err = ioutil.WriteFile(opt.ScratchDir+"/.stash", []byte("test"), 644)
if err != nil {
log.Fatalf("No write access in scratch dir: %s", err)
}
opt.ScratchDir = strings.TrimSuffix(opt.ScratchDir, "/") // setup ScratchDir in SetupAndRun

ctrl := scheduler.New(kubeClient, stashClient, opt)
err = ctrl.Setup()
if err != nil {
log.Fatalf("Failed to setup scheduler: %s", err)
stopBackup := make(chan struct{})
defer close(stopBackup)

// split code from here for leader election
switch opt.Workload.Kind {
case api.AppKindDeployment, api.AppKindReplicaSet, api.AppKindReplicationController:
ctrl.ElectLeader(stopBackup)
default:
ctrl.SetupAndRun(stopBackup)
}
stop := make(chan struct{})
defer close(stop)
go ctrl.Run(1, stop)

// Wait forever
select {}
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ func (c *StashController) runDeploymentInjector(key string) error {
if !exists {
// Below we will warm up our cache with a Deployment, so that we will see a delete for one d
fmt.Printf("Deployment %s does not exist anymore\n", key)

ns, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
return err
}
util.DeleteConfigmapLock(c.k8sClient, ns, api.LocalTypedReference{Kind: api.AppKindDeployment, Name: name})
} else {
dp := obj.(*apps.Deployment)
fmt.Printf("Sync/Add/Update for Deployment %s\n", dp.GetName())
Expand Down Expand Up @@ -233,5 +239,9 @@ func (c *StashController) EnsureDeploymentSidecarDeleted(resource *apps.Deployme
return
}
err = util.WaitUntilSidecarRemoved(c.k8sClient, resource.Namespace, resource.Spec.Selector)
if err != nil {
return
}
util.DeleteConfigmapLock(c.k8sClient, resource.Namespace, api.LocalTypedReference{Kind: api.AppKindDeployment, Name: resource.Name})
return err
}
10 changes: 10 additions & 0 deletions pkg/controller/rcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func (c *StashController) runRCInjector(key string) error {
if !exists {
// Below we will warm up our cache with a ReplicationController, so that we will see a delete for one d
fmt.Printf("ReplicationController %s does not exist anymore\n", key)

ns, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
return err
}
util.DeleteConfigmapLock(c.k8sClient, ns, api.LocalTypedReference{Kind: api.AppKindReplicationController, Name: name})
} else {
rc := obj.(*core.ReplicationController)
fmt.Printf("Sync/Add/Update for ReplicationController %s\n", rc.GetName())
Expand Down Expand Up @@ -231,5 +237,9 @@ func (c *StashController) EnsureReplicationControllerSidecarDeleted(resource *co
return
}
err = util.WaitUntilSidecarRemoved(c.k8sClient, resource.Namespace, &metav1.LabelSelector{MatchLabels: resource.Spec.Selector})
if err != nil {
return
}
util.DeleteConfigmapLock(c.k8sClient, resource.Namespace, api.LocalTypedReference{Kind: api.AppKindReplicationController, Name: resource.Name})
return err
}
12 changes: 11 additions & 1 deletion pkg/controller/replicasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ func (c *StashController) runReplicaSetInjector(key string) error {
if !exists {
// Below we will warm up our cache with a ReplicaSet, so that we will see a delete for one d
fmt.Printf("ReplicaSet %s does not exist anymore\n", key)

ns, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
return err
}
util.DeleteConfigmapLock(c.k8sClient, ns, api.LocalTypedReference{Kind: api.AppKindReplicaSet, Name: name})
} else {
rs := obj.(*extensions.ReplicaSet)
fmt.Printf("Sync/Add/Update for ReplicaSet %s\n", rs.GetName())
Expand Down Expand Up @@ -238,5 +244,9 @@ func (c *StashController) EnsureReplicaSetSidecarDeleted(resource *extensions.Re
return
}
err = util.WaitUntilSidecarRemoved(c.k8sClient, resource.Namespace, resource.Spec.Selector)
return err
if err != nil {
return
}
util.DeleteConfigmapLock(c.k8sClient, resource.Namespace, api.LocalTypedReference{Kind: api.AppKindReplicaSet, Name: resource.Name})
return
}
Loading
0