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

WIP: Split the controller into common and sidecar controllers - based on Snapshot Beta APIs #178

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
038d92c
Update VolumeSnapshot CRD version to v1beta
xing-yang Jul 11, 2019
9b86d7c
generate crds, modify api
yuxiangqian Aug 23, 2019
1eac944
final adjustment on types.go based on feedback
yuxiangqian Aug 23, 2019
5e43240
Update VolumeSnapshot CRD version to v1beta
xing-yang Jul 11, 2019
31bf112
generate crds, modify api
yuxiangqian Aug 23, 2019
8efee61
final adjustment on types.go based on feedback
yuxiangqian Aug 23, 2019
6666da6
Update snapshot controller using v1beta1 APIs
xing-yang Aug 28, 2019
2d966de
add local error type VolumeSnapshotError instead of using storage.Vol…
yuxiangqian Aug 28, 2019
fefe96a
pull from xing
yuxiangqian Aug 28, 2019
410d520
Update controller and tests to use the new Error API change
xing-yang Aug 28, 2019
df77c9a
remove CSIVolumeSnapshotSource and VolumeSnapshotSource and flatten t…
yuxiangqian Aug 30, 2019
bc334e7
Merge branch 'beta' of github.com:xing-yang/external-snapshotter into…
yuxiangqian Aug 30, 2019
2d017ee
remove CSIVolumeSnapshotSource and VolumeSnapshotSource and flatten t…
yuxiangqian Aug 30, 2019
123eed3
.
yuxiangqian Sep 10, 2019
4a70bdc
Merge branch 'master' into beta
yuxiangqian Sep 10, 2019
f0189ba
Update VolumeSnapshot CRD version to v1beta
xing-yang Jul 11, 2019
e3e8bfd
Update dependencies
xing-yang Sep 10, 2019
522f9d1
update from beta
yuxiangqian Sep 10, 2019
03c04bd
api changes
yuxiangqian Sep 19, 2019
8974813
api changes, make the repo builds(test will fail and needs to be fixe…
yuxiangqian Sep 20, 2019
8fa756e
api changes and make it compile, testings are still failing
yuxiangqian Oct 4, 2019
19abc09
fix test cases and controller logic with API changes
yuxiangqian Oct 8, 2019
06794ef
status to optional, comments update
yuxiangqian Oct 11, 2019
9f82f7c
Split controller based on snapshot beta APIs
Oct 12, 2019
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
6 changes: 6 additions & 0 deletions Dockerfile_common
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="CSI External Snapshotter Common"

COPY ./bin/csi-snapshotter-common csi-snapshotter-common
ENTRYPOINT ["/csi-snapshotter-common"]
6 changes: 6 additions & 0 deletions Dockerfile_sidecar
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="CSI External Snapshotter Sidecar"

COPY ./bin/csi-snapshotter-sidecar csi-snapshotter-sidecar
ENTRYPOINT ["/csi-snapshotter-sidecar"]
16 changes: 0 additions & 16 deletions Gopkg.lock

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

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ required = [
name = "k8s.io/code-generator"
version = "kubernetes-1.14.0"

[[constraint]]
name = "k8s.io/apiextensions-apiserver"
version = "kubernetes-1.14.0"

[[constraint]]
name = "github.com/kubernetes-csi/csi-lib-utils"
version = ">=v0.6.1"
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

.PHONY: all csi-snapshotter clean test
.PHONY: all csi-snapshotter-common csi-snapshotter-sidecar clean test

CMDS=csi-snapshotter
CMDS=csi-snapshotter-common csi-snapshotter-sidecar
all: build
include release-tools/build.make
19 changes: 19 additions & 0 deletions Makefile_old
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.

.PHONY: all csi-snapshotter clean test

CMDS=csi-snapshotter
all: build
include release-tools/build.make
157 changes: 157 additions & 0 deletions cmd/csi-snapshotter-common/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
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"
"strings"
"time"

"google.golang.org/grpc"

"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/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
csirpc "github.com/kubernetes-csi/csi-lib-utils/rpc"
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.")
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"
prefix = "external-snapshotter-leader"
)

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] resyncPeriod [%+v]", *kubeconfig, *resyncPeriod)

ctrl := controller.NewCSISnapshotCommonController(
snapClient,
kubeClient,
factory.Snapshot().V1beta1().VolumeSnapshots(),
factory.Snapshot().V1beta1().VolumeSnapshotContents(),
factory.Snapshot().V1beta1().VolumeSnapshotClasses(),
coreFactory.Core().V1().PersistentVolumeClaims(),
*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 := fmt.Sprintf("%s-%s", prefix, strings.Replace("common-snapshotter", "/", "-", -1))
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()
}

func supportsControllerCreateSnapshot(ctx context.Context, conn *grpc.ClientConn) (bool, error) {
capabilities, err := csirpc.GetControllerCapabilities(ctx, conn)
if err != nil {
return false, err
}

return capabilities[csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT], nil
}
Loading