Skip to content
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

add implement for CSI plugin #7

Merged
merged 2 commits into from
Feb 27, 2019
Merged
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
96 changes: 86 additions & 10 deletions Gopkg.lock

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

17 changes: 11 additions & 6 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,30 @@
# go-tests = true
# unused-packages = true

# TODO: Change to a concrete v1.14 tag after klog is included.
[[constraint]]
branch = "master"
name = "k8s.io/api"
version = "kubernetes-1.14.0-alpha.1"

# TODO: Change to a concrete v1.14 tag after klog is included.
[[constraint]]
branch = "master"
name = "k8s.io/apimachinery"
version = "kubernetes-1.14.0-alpha.1"

# TODO: Change to a concrete v1.14 tag after klog is included.
[[constraint]]
branch = "master"
name = "k8s.io/client-go"
version = "kubernetes-1.14.0-alpha.1"

[[constraint]]
name = "k8s.io/klog"
version = "0.1.0"

[[constraint]]
branch = "master"
name = "github.com/container-storage-interface/spec"

[[constraint]]
name = "github.com/kubernetes-csi/csi-lib-utils"
version = "0.2.0"

[prune]
non-go = true
go-tests = true
Expand Down
20 changes: 17 additions & 3 deletions cmd/csi-resizer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/kubernetes-csi/external-resizer/pkg/resizer"
"github.com/kubernetes-csi/external-resizer/pkg/util"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/informers"
"k8s.io/klog"
)

Expand All @@ -33,6 +35,9 @@ var (
resyncPeriod = flag.Duration("resync-period", time.Minute*10, "Resync period for cache")
workers = flag.Int("workers", 10, "Concurrency to process multiple resize requests")

csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
csiTimeout = flag.Duration("csiTimeout", 15*time.Second, "Timeout for waiting for CSI driver socket.")

enableLeaderElection = flag.Bool("leader-election", false, "Enable leader election.")
leaderElectionIdentity = flag.String("leader-election-identity", "", "Unique identity of this resizer. Typically name of the pod where the resizer runs.")
leaderElectionNamespace = flag.String("leader-election-namespace", "kube-system", "Namespace where this resizer runs.")
Expand All @@ -58,13 +63,20 @@ func main() {
flag.Set("logtostderr", "true")
flag.Parse()

resizerName := "csi/example-resizer"

kubeClient, err := util.NewK8sClient(*master, *kubeConfig)
if err != nil {
klog.Fatal(err.Error())
}

informerFactory := informers.NewSharedInformerFactory(kubeClient, *resyncPeriod)

csiResizer, err := resizer.NewCSIResizer(*csiAddress, *csiTimeout, kubeClient, informerFactory)
if err != nil {
klog.Fatal(err.Error())
}

resizerName := csiResizer.Name()

var leaderElectionConfig *util.LeaderElectionConfig
if *enableLeaderElection {
if leaderElectionIdentity == nil || *leaderElectionIdentity == "" {
Expand All @@ -80,6 +92,8 @@ func main() {
}
}

rc := controller.NewResizeController(resizerName, resizer.New(), kubeClient, *resyncPeriod)
rc := controller.NewResizeController(resizerName, csiResizer, kubeClient, *resyncPeriod, informerFactory)

informerFactory.Start(wait.NeverStop)
rc.Run(*workers, leaderElectionConfig)
}
43 changes: 20 additions & 23 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,24 @@ type ResizeController interface {
}

type resizeController struct {
name string
resizer resizer.Resizer
kubeClient kubernetes.Interface
claimQueue workqueue.RateLimitingInterface
eventRecorder record.EventRecorder
pvLister corelisters.PersistentVolumeLister
pvSynced cache.InformerSynced
pvcLister corelisters.PersistentVolumeClaimLister
pvcSynced cache.InformerSynced
informerFactory informers.SharedInformerFactory
name string
resizer resizer.Resizer
kubeClient kubernetes.Interface
claimQueue workqueue.RateLimitingInterface
eventRecorder record.EventRecorder
pvLister corelisters.PersistentVolumeLister
pvSynced cache.InformerSynced
pvcLister corelisters.PersistentVolumeClaimLister
pvcSynced cache.InformerSynced
}

// NewResizeController returns a ResizeController.
func NewResizeController(
name string,
resizer resizer.Resizer,
kubeClient kubernetes.Interface,
resyncPeriod time.Duration) ResizeController {
informerFactory := informers.NewSharedInformerFactory(kubeClient, resyncPeriod)
resyncPeriod time.Duration,
informerFactory informers.SharedInformerFactory) ResizeController {
pvInformer := informerFactory.Core().V1().PersistentVolumes()
pvcInformer := informerFactory.Core().V1().PersistentVolumeClaims()

Expand All @@ -80,16 +79,15 @@ func NewResizeController(
workqueue.DefaultControllerRateLimiter(), fmt.Sprintf("%s-pvc", name))

ctrl := &resizeController{
name: name,
resizer: resizer,
kubeClient: kubeClient,
pvLister: pvInformer.Lister(),
pvSynced: pvInformer.Informer().HasSynced,
pvcLister: pvcInformer.Lister(),
pvcSynced: pvcInformer.Informer().HasSynced,
claimQueue: claimQueue,
eventRecorder: eventRecorder,
informerFactory: informerFactory,
name: name,
resizer: resizer,
kubeClient: kubeClient,
pvLister: pvInformer.Lister(),
pvSynced: pvInformer.Informer().HasSynced,
pvcLister: pvcInformer.Lister(),
pvcSynced: pvcInformer.Informer().HasSynced,
claimQueue: claimQueue,
eventRecorder: eventRecorder,
}

// Add a resync period as the PVC's request size can be resized again when we handling
Expand Down Expand Up @@ -166,7 +164,6 @@ func (ctrl *resizeController) Run(

stopCh := ctx.Done()

ctrl.informerFactory.Start(stopCh)
if !cache.WaitForCacheSync(stopCh, ctrl.pvSynced, ctrl.pvcSynced) {
klog.Errorf("Cannot sync pv/pvc caches")
return
Expand Down
Loading