Skip to content

use leases object when elect the leader #24

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 0 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@ module tkestack.io/csi-operator
go 1.13

require (
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/etcd v3.3.17+incompatible // indirect
github.com/go-logr/zapr v0.1.1 // indirect
github.com/gobuffalo/envy v1.8.1 // indirect
github.com/gobuffalo/flect v0.1.7 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/markbates/inflect v1.0.4 // indirect
github.com/prometheus/client_golang v1.2.1 // indirect
github.com/rogpeppe/go-internal v1.5.0 // indirect
go.uber.org/zap v1.13.0 // indirect
golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
Expand All @@ -25,9 +18,7 @@ require (
k8s.io/apiextensions-apiserver v0.0.0-20191121021419-88daf26ec3b8
k8s.io/apimachinery v0.0.0-20191121015412-41065c7a8c2a
k8s.io/client-go v0.0.0-20191121015835-571c0ef67034
k8s.io/gengo v0.0.0-20191120174120-e74f70b9b27e // indirect
k8s.io/klog v1.0.0
k8s.io/utils v0.0.0-20191114200735-6ca3b61696b6 // indirect
sigs.k8s.io/controller-runtime v0.4.0
sigs.k8s.io/controller-tools v0.2.4 // indirect
)
121 changes: 11 additions & 110 deletions go.sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type Config struct {
Filesystems string
// NeedDefaultSC indicates whether the cluster need to create default storage classes.
NeedDefaultSc bool
// DemonSetMaxUnavailable
DaemonSetMaxUnavailable string
}

// AddFlags add the configurations to global flag.
Expand All @@ -45,6 +47,8 @@ func (config *Config) AddFlags() {
"xfs,ext4", "Supported file systems for well known block volumes")
flag.BoolVar(&config.NeedDefaultSc, "need-default-sc", true,
"NeedDefaultSC indicates whether the cluster need to create default storage classes")
flag.StringVar(&config.DaemonSetMaxUnavailable, "daemonset-max-unavailable", "5%",
"Need default daemonSetMaxUnavailable")
config.CephConfig.AddFlags()
config.TencentCloudConfig.AddFlags()
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/controller/csi/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (r *ReconcileCSI) syncNodeDriver(csiDeploy *csiv1.CSI) (*appsv1.DaemonSet,
func (r *ReconcileCSI) generateNodeDriver(csiDeploy *csiv1.CSI) *appsv1.DaemonSet {
template := csiDeploy.Spec.DriverTemplate.Template.DeepCopy()

r.handleNodeDriverTemplate(template, csiDeploy.Spec.DriverName)

if csiDeploy.Namespace == systemNamespace {
// Make node as system critical.
template.Spec.PriorityClassName = "system-cluster-critical"
Expand Down Expand Up @@ -148,6 +150,7 @@ func (r *ReconcileCSI) generateNodeDriver(csiDeploy *csiv1.CSI) *appsv1.DaemonSe
selectedLabels := map[string]string{nodeDriverLabel: name}
mergeLabels(&template.ObjectMeta, selectedLabels)

klog.V(4).Infof("RollingUpdate:%v", r.config.DaemonSetMaxUnavailable)
// Generate the NodeRegistrar object.
return &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -161,11 +164,26 @@ func (r *ReconcileCSI) generateNodeDriver(csiDeploy *csiv1.CSI) *appsv1.DaemonSe
UpdateStrategy: appsv1.DaemonSetUpdateStrategy{
// TODO: Make this configurable?
Type: appsv1.RollingUpdateDaemonSetStrategyType,
RollingUpdate: &appsv1.RollingUpdateDaemonSet{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.String,
StrVal: r.config.DaemonSetMaxUnavailable,
}},
},
},
}
}

// handleNodeDriverTemplate remove prometheus configuration and disable metrics
func (r *ReconcileCSI) handleNodeDriverTemplate(template *corev1.PodTemplateSpec, driverName string) {
if driverName == csiv1.CSIDriverTencentCBS {
template.Annotations = map[string]string{}
if len(template.Spec.Containers) == 1 {
template.Spec.Containers[0].Args = append(template.Spec.Containers[0].Args, "--enable_metrics_server=false")
}
}
}

// generateNodeDriverVolumes generates the volumes of Node Driver.
func (r *ReconcileCSI) generateNodeDriverVolumes(csiDeploy *csiv1.CSI) []corev1.Volume {
return []corev1.Volume{
Expand Down Expand Up @@ -426,6 +444,7 @@ func (r *ReconcileCSI) generateProvisioner(csiDeploy *csiv1.CSI) corev1.Containe
"--v=5",
"--csi-address=$(ADDRESS)",
"--enable-leader-election=true",
"--leader-election-type=leases",
"--feature-gates=Topology=true",
},
Resources: csiDeploy.Spec.Controller.Provisioner.Resources,
Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/csi/enhancer/enhancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
)

Expand Down Expand Up @@ -182,6 +183,13 @@ func getSecretName(csiDeploy *csiv1.CSI) string {
return strings.ReplaceAll(csiDeploy.Spec.DriverName+"-secret", ".", "-")
}

func getTemplateObjectMeta(csiDeploy *csiv1.CSI) metav1.ObjectMeta {
if csiDeploy.Spec.DriverTemplate != nil && &csiDeploy.Spec.DriverTemplate.Template != nil {
return csiDeploy.Spec.DriverTemplate.Template.ObjectMeta
}
return metav1.ObjectMeta{}
}

// getConfigMapName returns a name for secret.
func getConfigMapName(csiDeploy *csiv1.CSI) string {
return strings.ReplaceAll(csiDeploy.Spec.DriverName+"-conf", ".", "-")
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/csi/enhancer/tencentCloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (e *tencentCloudEnhancer) generateDriverTemplate(
csiDeploy *csiv1.CSI) *csiv1.CSIDriverTemplate {
return &csiv1.CSIDriverTemplate{
Template: corev1.PodTemplateSpec{
ObjectMeta: getTemplateObjectMeta(csiDeploy),
Spec: corev1.PodSpec{
HostNetwork: true,
HostPID: true,
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/csi/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ func snapshotterPolicyRules() []rbacv1.PolicyRule {
Resources: []string{"volumesnapshots"},
Verbs: []string{"get", "list", "watch", "update"},
},
{
APIGroups: []string{"snapshot.storage.k8s.io"},
Resources: []string{"volumesnapshots/status"},
Verbs: []string{"get", "list", "watch", "update"},
},
{
APIGroups: []string{"apiextensions.k8s.io"},
Resources: []string{"customresourcedefinitions"},
Expand Down