-
Notifications
You must be signed in to change notification settings - Fork 179
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
[WIP] Deploy CSI driver as a deployment and support multi master & leader e… #72
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,21 +17,46 @@ limitations under the License. | |
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"os" | ||
|
||
"github.com/kubernetes-csi/csi-lib-utils/leaderelection" | ||
"k8s.io/klog" | ||
k8s "sigs.k8s.io/vsphere-csi-driver/pkg/kubernetes" | ||
|
||
metadatasyncer "sigs.k8s.io/vsphere-csi-driver/pkg/syncer" | ||
) | ||
|
||
var ( | ||
enableLeaderElection = flag.Bool("leader-election", false, "Enable leader election.") | ||
) | ||
|
||
// main is ignored when this package is built as a go plug-in. | ||
func main() { | ||
klog.InitFlags(nil) | ||
flag.Parse() | ||
metadataSyncer := metadatasyncer.NewInformer() | ||
if err := metadataSyncer.Init(); err != nil { | ||
klog.Errorf("Error initializing Metadata Syncer") | ||
os.Exit(1) | ||
run := func(ctx context.Context) { | ||
if err := metadataSyncer.Init(); err != nil { | ||
klog.Errorf("Error initializing Metadata Syncer") | ||
os.Exit(1) | ||
} | ||
} | ||
Comment on lines
+40
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The context that gets passed into your run func will be canceled when this process loses leadership. It looks like you don't pass that into In most core k8s components, we react to loss of leadership with |
||
|
||
if !*enableLeaderElection { | ||
run(context.TODO()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
} else { | ||
k8sClient, err := k8s.NewClient() | ||
if err != nil { | ||
klog.Errorf("Creating Kubernetes client failed. Err: %v", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: you can use |
||
os.Exit(1) | ||
} | ||
lockName := "vsphere-syncer" | ||
le := leaderelection.NewLeaderElection(k8sClient, lockName, run) | ||
|
||
if err := le.Run(); err != nil { | ||
klog.Fatalf("Error initializing leader election: %v", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
kind: StatefulSet | ||
kind: Deployment | ||
apiVersion: apps/v1 | ||
metadata: | ||
name: vsphere-csi-controller | ||
namespace: kube-system | ||
spec: | ||
serviceName: vsphere-csi-controller | ||
replicas: 1 | ||
updateStrategy: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
type: "RollingUpdate" | ||
strategy: | ||
type: RollingUpdate | ||
selector: | ||
matchLabels: | ||
app: vsphere-csi-controller | ||
|
@@ -32,6 +31,8 @@ spec: | |
- "--v=4" | ||
- "--timeout=300s" | ||
- "--csi-address=$(ADDRESS)" | ||
- "--leader-election" | ||
- "--leader-election-type=leases" | ||
env: | ||
- name: ADDRESS | ||
value: /csi/csi.sock | ||
|
@@ -85,7 +86,8 @@ spec: | |
- name: vsphere-syncer | ||
image: vmware/volume-metadata-syncer:v1.0.0 | ||
args: | ||
- "--v=2" | ||
- "--v=5" | ||
- "--leader-election" | ||
imagePullPolicy: "Always" | ||
env: | ||
- name: FULL_SYNC_INTERVAL_MINUTES | ||
|
@@ -104,6 +106,8 @@ spec: | |
- "--csi-address=$(ADDRESS)" | ||
- "--feature-gates=Topology=true" | ||
- "--strict-topology" | ||
- "--enable-leader-election" | ||
- "--leader-election-type=leases" | ||
env: | ||
- name: ADDRESS | ||
value: /csi/csi.sock | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
metadataSyncer.Init()
a blocking call that runs the syncer forever?