-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ashutosh Kumar <[email protected]>
- Loading branch information
Ashutosh Kumar
committed
Feb 19, 2020
1 parent
24a58f1
commit eba4742
Showing
26 changed files
with
3,069 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
Copyright 2020 The OpenEBS 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 app | ||
|
||
import ( | ||
"flag" | ||
clientset "github.com/openebs/api/pkg/client/clientset/versioned" | ||
informers "github.com/openebs/api/pkg/client/informers/externalversions" | ||
cspccontroller "github.com/openebs/cstor-operators/pkg/controllers/cspc-controller" | ||
"github.com/openebs/cstor-operators/pkg/signals" | ||
"github.com/pkg/errors" | ||
kubeinformers "k8s.io/client-go/informers" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/klog" | ||
"os" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
var ( | ||
kubeconfig = flag.String("kubeconfig", "", "Path for kube config") | ||
) | ||
|
||
const ( | ||
// ResyncInterval is sync interval of the watcher | ||
ResyncInterval = 30 * time.Second | ||
) | ||
|
||
// Start starts the cstor-operator. | ||
func Start() error { | ||
// set up signals so we handle the first shutdown signal gracefully | ||
stopCh := signals.SetupSignalHandler() | ||
klog.InitFlags(nil) | ||
err := flag.Set("logtostderr", "true") | ||
if err != nil { | ||
return errors.Wrap(err, "failed to set logtostderr flag") | ||
} | ||
flag.Parse() | ||
|
||
cfg, err := getClusterConfig(*kubeconfig) | ||
if err != nil { | ||
return errors.Wrap(err, "error building kubeconfig") | ||
} | ||
|
||
// Building Kubernetes Clientset | ||
kubeClient, err := kubernetes.NewForConfig(cfg) | ||
if err != nil { | ||
return errors.Wrap(err, "error building kubernetes clientset") | ||
} | ||
|
||
// Building OpenEBS Clientset | ||
openebsClient, err := clientset.NewForConfig(cfg) | ||
if err != nil { | ||
return errors.Wrap(err, "error building openebs clientset") | ||
} | ||
|
||
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, getSyncInterval()) | ||
spcInformerFactory := informers.NewSharedInformerFactory(openebsClient, getSyncInterval()) | ||
// Build() fn of all controllers calls AddToScheme to adds all types of this | ||
// clientset into the given scheme. | ||
// If multiple controllers happen to call this AddToScheme same time, | ||
// it causes panic with error saying concurrent map access. | ||
// This lock is used to serialize the AddToScheme call of all controllers. | ||
//controllerMtx.Lock() | ||
|
||
controller, err := cspccontroller.NewControllerBuilder(). | ||
WithKubeClient(kubeClient). | ||
WithOpenEBSClient(openebsClient). | ||
WithCSPCSynced(spcInformerFactory). | ||
WithCSPCLister(spcInformerFactory). | ||
WithRecorder(kubeClient). | ||
WithEventHandler(spcInformerFactory). | ||
WithWorkqueueRateLimiting().Build() | ||
|
||
// blocking call, can't use defer to release the lock | ||
//controllerMtx.Unlock() | ||
|
||
if err != nil { | ||
return errors.Wrapf(err, "error building controller instance") | ||
} | ||
|
||
go kubeInformerFactory.Start(stopCh) | ||
go spcInformerFactory.Start(stopCh) | ||
|
||
// Threadiness defines the number of workers to be launched in Run function | ||
return controller.Run(2, stopCh) | ||
|
||
return nil | ||
} | ||
|
||
// GetClusterConfig return the config for k8s. | ||
func getClusterConfig(kubeconfig string) (*rest.Config, error) { | ||
if kubeconfig != "" { | ||
return clientcmd.BuildConfigFromFlags("", kubeconfig) | ||
} | ||
klog.V(2).Info("Kubeconfig flag is empty") | ||
return rest.InClusterConfig() | ||
} | ||
|
||
// getSyncInterval gets the resync interval from environment variable. | ||
// If missing or zero then default to 30 seconds | ||
// otherwise return the obtained value | ||
func getSyncInterval() time.Duration { | ||
resyncInterval, err := strconv.Atoi(os.Getenv("RESYNC_INTERVAL")) | ||
if err != nil || resyncInterval == 0 { | ||
klog.Warningf("Incorrect resync interval %q obtained from env, defaulting to %q seconds", resyncInterval, ResyncInterval) | ||
return ResyncInterval | ||
} | ||
return time.Duration(resyncInterval) * time.Second | ||
} | ||
|
||
func main() { | ||
err:=Start() | ||
if err!=nil{ | ||
klog.Error("Could not start cspc controller: {%s}",err.Error()) | ||
os.Exit(1) | ||
} | ||
} |
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,24 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
# name must match the spec fields below, and be in the form: <plural>.<group> | ||
name: cstorpoolclusters.cstor.openebs.io | ||
spec: | ||
# group name to use for REST API: /apis/<group>/<version> | ||
group: cstor.openebs.io | ||
# version name to use for REST API: /apis/<group>/<version> | ||
version: v1 | ||
# either Namespaced or Cluster | ||
scope: Namespaced | ||
names: | ||
# plural name to be used in the URL: /apis/<group>/<version>/<plural> | ||
plural: cstorpoolclusters | ||
# singular name to be used as an alias on the CLI and for display | ||
singular: cstorpoolcluster | ||
# kind is normally the CamelCased singular type. Your resource manifests use this. | ||
kind: CStorPoolCluster | ||
# shortNames allow shorter string to match your resource on the CLI | ||
shortNames: | ||
- cspc | ||
--- |
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,24 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
# name must match the spec fields below, and be in the form: <plural>.<group> | ||
name: cstorpoolinstances.cstor.openebs.io | ||
spec: | ||
# group name to use for REST API: /apis/<group>/<version> | ||
group: cstor.openebs.io | ||
# version name to use for REST API: /apis/<group>/<version> | ||
version: v1 | ||
# either Namespaced or Cluster | ||
scope: Namespaced | ||
names: | ||
# plural name to be used in the URL: /apis/<group>/<version>/<plural> | ||
plural: cstorpoolinstances | ||
# singular name to be used as an alias on the CLI and for display | ||
singular: cstorpoolinstance | ||
# kind is normally the CamelCased singular type. Your resource manifests use this. | ||
kind: CStorPoolInstance | ||
# shortNames allow shorter string to match your resource on the CLI | ||
shortNames: | ||
- cspi | ||
--- |
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,14 @@ | ||
apiVersion: cstor.openebs.io/v1 | ||
kind: CStorPoolCluster | ||
metadata: | ||
name: cspc-stripe | ||
namespace: openebs | ||
spec: | ||
pools: | ||
- nodeSelector: | ||
kubernetes.io/hostname: "gke-cstor-demo-default-pool-3385ab41-5swq" | ||
dataRaidGroups: | ||
- blockDevices: | ||
- blockDeviceName: "sparse-1e3a8da94af49e16d937d867777699b0" | ||
poolConfig: | ||
defaultRaidGroupType: "stripe" |
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,30 @@ | ||
apiVersion: cstor.openebs.io/v1 | ||
kind: CStorPoolCluster | ||
metadata: | ||
name: cspc-stripe | ||
namespace: openebs | ||
spec: | ||
pools: | ||
- nodeSelector: | ||
kubernetes.io/hostname: "gke-cstor-demo-default-pool-3385ab41-5swq" | ||
dataRaidGroups: | ||
- blockDevices: | ||
- blockDeviceName: "sparse-1e3a8da94af49e16d937d867777699b0" | ||
poolConfig: | ||
defaultRaidGroupType: "stripe" | ||
|
||
- nodeSelector: | ||
kubernetes.io/hostname: "gke-cstor-demo-default-pool-3385ab41-j90d" | ||
dataRaidGroups: | ||
- blockDevices: | ||
- blockDeviceName: "sparse-8935fde3557f1d04dd8c01a635f3c51f" | ||
poolConfig: | ||
defaultRaidGroupType: "stripe" | ||
|
||
- nodeSelector: | ||
kubernetes.io/hostname: "gke-cstor-demo-default-pool-3385ab41-sr33" | ||
dataRaidGroups: | ||
- blockDevices: | ||
- blockDeviceName: "sparse-a0f9a34f5d9133078b4a6b7f341133ea" | ||
poolConfig: | ||
defaultRaidGroupType: "stripe" |
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,30 @@ | ||
apiVersion: cstor.openebs.io/v1 | ||
kind: CStorPoolInstance | ||
metadata: | ||
name: cspi-stripe | ||
namespace: openebs | ||
spec: | ||
pools: | ||
- nodeSelector: | ||
kubernetes.io/hostname: "gke-cstor-demo-default-pool-3385ab41-5swq" | ||
dataRaidGroups: | ||
- blockDevices: | ||
- blockDeviceName: "sparse-1e3a8da94af49e16d937d867777699b0" | ||
poolConfig: | ||
defaultRaidGroupType: "stripe" | ||
|
||
- nodeSelector: | ||
kubernetes.io/hostname: "gke-cstor-demo-default-pool-3385ab41-j90d" | ||
dataRaidGroups: | ||
- blockDevices: | ||
- blockDeviceName: "sparse-8935fde3557f1d04dd8c01a635f3c51f" | ||
poolConfig: | ||
defaultRaidGroupType: "stripe" | ||
|
||
- nodeSelector: | ||
kubernetes.io/hostname: "gke-cstor-demo-default-pool-3385ab41-sr33" | ||
dataRaidGroups: | ||
- blockDevices: | ||
- blockDeviceName: "sparse-a0f9a34f5d9133078b4a6b7f341133ea" | ||
poolConfig: | ||
defaultRaidGroupType: "stripe" |
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,30 @@ | ||
apiVersion: cstor.openebs.io/v1 | ||
kind: CStorPoolInstance | ||
metadata: | ||
name: cspi-stripe-1 | ||
namespace: openebs | ||
spec: | ||
pools: | ||
- nodeSelector: | ||
kubernetes.io/hostname: "gke-cstor-demo-default-pool-3385ab41-5swq" | ||
dataRaidGroups: | ||
- blockDevices: | ||
- blockDeviceName: "sparse-1e3a8da94af49e16d937d867777699b0" | ||
poolConfig: | ||
defaultRaidGroupType: "stripe" | ||
|
||
- nodeSelector: | ||
kubernetes.io/hostname: "gke-cstor-demo-default-pool-3385ab41-j90d" | ||
dataRaidGroups: | ||
- blockDevices: | ||
- blockDeviceName: "sparse-8935fde3557f1d04dd8c01a635f3c51f" | ||
poolConfig: | ||
defaultRaidGroupType: "stripe" | ||
|
||
- nodeSelector: | ||
kubernetes.io/hostname: "gke-cstor-demo-default-pool-3385ab41-sr33" | ||
dataRaidGroups: | ||
- blockDevices: | ||
- blockDeviceName: "sparse-a0f9a34f5d9133078b4a6b7f341133ea" | ||
poolConfig: | ||
defaultRaidGroupType: "stripe" |
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 @@ | ||
// ToDo : Docs |
Binary file not shown.
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,18 @@ | ||
module github.com/openebs/cstor-operators | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/Masterminds/goutils v1.1.0 // indirect | ||
github.com/Masterminds/semver v1.5.0 // indirect | ||
github.com/Masterminds/sprig v2.22.0+incompatible // indirect | ||
github.com/huandu/xstrings v1.3.0 // indirect | ||
github.com/mitchellh/copystructure v1.0.0 // indirect | ||
github.com/openebs/api v0.0.0-20200219105320-af0efa3eab11 | ||
github.com/openebs/maya v0.0.0-20200211084127-dd6152021192 | ||
github.com/pkg/errors v0.9.1 | ||
k8s.io/api v0.17.2 | ||
k8s.io/apimachinery v0.17.2 | ||
k8s.io/client-go v0.17.2 | ||
k8s.io/klog v1.0.0 | ||
) |
Oops, something went wrong.