-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from xing-yang/new_beta_split_controller
Split snapshot controller using beta APIs
- Loading branch information
Showing
31 changed files
with
2,857 additions
and
1,866 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
FROM gcr.io/distroless/static:latest | ||
LABEL maintainers="Kubernetes Authors" | ||
LABEL description="CSI External Snapshotter" | ||
LABEL description="CSI External Snapshotter Sidecar" | ||
|
||
COPY ./bin/csi-snapshotter csi-snapshotter | ||
ENTRYPOINT ["/csi-snapshotter"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM gcr.io/distroless/static:latest | ||
LABEL maintainers="Kubernetes Authors" | ||
LABEL description="Snapshot Controller" | ||
|
||
COPY ./bin/snapshot-controller snapshot-controller | ||
ENTRYPOINT ["/snapshot-controller"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"time" | ||
|
||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/klog" | ||
|
||
"github.com/kubernetes-csi/csi-lib-utils/leaderelection" | ||
controller "github.com/kubernetes-csi/external-snapshotter/pkg/common-controller" | ||
|
||
clientset "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned" | ||
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/scheme" | ||
informers "github.com/kubernetes-csi/external-snapshotter/pkg/client/informers/externalversions" | ||
coreinformers "k8s.io/client-go/informers" | ||
) | ||
|
||
const ( | ||
// Number of worker threads | ||
threads = 10 | ||
) | ||
|
||
// Command line flags | ||
var ( | ||
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.") | ||
createSnapshotContentRetryCount = flag.Int("create-snapshotcontent-retrycount", 5, "Number of retries when we create a snapshot content object for a snapshot.") | ||
createSnapshotContentInterval = flag.Duration("create-snapshotcontent-interval", 10*time.Second, "Interval between retries when we create a snapshot content object for a snapshot.") | ||
resyncPeriod = flag.Duration("resync-period", 60*time.Second, "Resync interval of the controller.") | ||
showVersion = flag.Bool("version", false, "Show version.") | ||
|
||
leaderElection = flag.Bool("leader-election", false, "Enables leader election.") | ||
leaderElectionNamespace = flag.String("leader-election-namespace", "", "The namespace where the leader election resource exists. Defaults to the pod namespace if not set.") | ||
) | ||
|
||
var ( | ||
version = "unknown" | ||
) | ||
|
||
func main() { | ||
klog.InitFlags(nil) | ||
flag.Set("logtostderr", "true") | ||
flag.Parse() | ||
|
||
if *showVersion { | ||
fmt.Println(os.Args[0], version) | ||
os.Exit(0) | ||
} | ||
klog.Infof("Version: %s", version) | ||
|
||
// Create the client config. Use kubeconfig if given, otherwise assume in-cluster. | ||
config, err := buildConfig(*kubeconfig) | ||
if err != nil { | ||
klog.Error(err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
kubeClient, err := kubernetes.NewForConfig(config) | ||
if err != nil { | ||
klog.Error(err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
snapClient, err := clientset.NewForConfig(config) | ||
if err != nil { | ||
klog.Errorf("Error building snapshot clientset: %s", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
factory := informers.NewSharedInformerFactory(snapClient, *resyncPeriod) | ||
coreFactory := coreinformers.NewSharedInformerFactory(kubeClient, *resyncPeriod) | ||
|
||
// Add Snapshot types to the defualt Kubernetes so events can be logged for them | ||
snapshotscheme.AddToScheme(scheme.Scheme) | ||
|
||
klog.V(2).Infof("Start NewCSISnapshotController with kubeconfig [%s] createSnapshotContentRetryCount [%d] createSnapshotContentInterval [%d] resyncPeriod [%+v]", *kubeconfig, *createSnapshotContentRetryCount, *createSnapshotContentInterval, *resyncPeriod) | ||
|
||
ctrl := controller.NewCSISnapshotCommonController( | ||
snapClient, | ||
kubeClient, | ||
factory.Snapshot().V1beta1().VolumeSnapshots(), | ||
factory.Snapshot().V1beta1().VolumeSnapshotContents(), | ||
factory.Snapshot().V1beta1().VolumeSnapshotClasses(), | ||
coreFactory.Core().V1().PersistentVolumeClaims(), | ||
*createSnapshotContentRetryCount, | ||
*createSnapshotContentInterval, | ||
*resyncPeriod, | ||
) | ||
|
||
run := func(context.Context) { | ||
// run... | ||
stopCh := make(chan struct{}) | ||
factory.Start(stopCh) | ||
coreFactory.Start(stopCh) | ||
go ctrl.Run(threads, stopCh) | ||
|
||
// ...until SIGINT | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt) | ||
<-c | ||
close(stopCh) | ||
} | ||
|
||
if !*leaderElection { | ||
run(context.TODO()) | ||
} else { | ||
lockName := "snapshot-controller-leader" | ||
le := leaderelection.NewLeaderElection(kubeClient, lockName, run) | ||
if *leaderElectionNamespace != "" { | ||
le.WithNamespace(*leaderElectionNamespace) | ||
} | ||
if err := le.Run(); err != nil { | ||
klog.Fatalf("failed to initialize leader election: %v", err) | ||
} | ||
} | ||
} | ||
|
||
func buildConfig(kubeconfig string) (*rest.Config, error) { | ||
if kubeconfig != "" { | ||
return clientcmd.BuildConfigFromFlags("", kubeconfig) | ||
} | ||
return rest.InClusterConfig() | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.