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

feat(REST, CVC): add a support for rest service in CVC Operator #83

Merged
merged 11 commits into from
Jun 9, 2020
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
5 changes: 4 additions & 1 deletion build/cvc-operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ RUN apk add --no-cache \
ca-certificates

COPY cvc-operator /usr/local/bin/cvc-operator
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh

ARG ARCH
ARG DBUILD_DATE
Expand All @@ -24,4 +26,5 @@ LABEL org.label-schema.build-date=$DBUILD_DATE
LABEL org.label-schema.vcs-url=$DBUILD_REPO_URL
LABEL org.label-schema.url=$DBUILD_SITE_URL

ENTRYPOINT ["/usr/local/bin/cvc-operator"]
ENTRYPOINT entrypoint.sh
EXPOSE 5757
5 changes: 4 additions & 1 deletion build/cvc-operator/Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ RUN apk add --no-cache \
ca-certificates

COPY cvc-operator /usr/local/bin/cvc-operator
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh

ARG ARCH
ARG DBUILD_DATE
Expand All @@ -27,4 +29,5 @@ LABEL org.label-schema.build-date=$DBUILD_DATE
LABEL org.label-schema.vcs-url=$DBUILD_REPO_URL
LABEL org.label-schema.url=$DBUILD_SITE_URL

ENTRYPOINT ["/usr/local/bin/cvc-operator"]
ENTRYPOINT entrypoint.sh
EXPOSE 5757
9 changes: 9 additions & 0 deletions build/cvc-operator/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -ex

CVC_API_SERVER_NETWORK="eth0"

CONTAINER_IP_ADDR=$(ip -4 addr show scope global dev "${CVC_API_SERVER_NETWORK}" | grep inet | awk '{print $2}' | cut -d / -f 1)

exec /usr/local/bin/cvc-operator --bind="${CONTAINER_IP_ADDR}" 1>&2
92 changes: 92 additions & 0 deletions deploy/crds/backup-restore-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: cstorbackups.openebs.io
spec:
group: openebs.io
version: v1alpha1
scope: Namespaced
names:
plural: cstorbackups
singular: cstorbackup
kind: CStorBackup
shortNames:
- cbkp
- cbkps
- cbackups
- cbackup
additionalPrinterColumns:
- JSONPath: .spec.volumeName
name: volume
description: volume on which backup performed
type: string
- JSONPath: .spec.backupName
name: backup/schedule
description: Backup/schedule name
type: string
- JSONPath: .status
name: Status
description: Backup status
type: string

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: cstorcompletedbackups.openebs.io
spec:
group: openebs.io
version: v1alpha1
scope: Namespaced
names:
plural: cstorcompletedbackups
singular: cstorcompletedbackup
kind: CStorCompletedBackup
shortNames:
- cbkpc
- cbackupcompleted
additionalPrinterColumns:
- JSONPath: .spec.volumeName
name: volume
description: volume on which backup performed
type: string
- JSONPath: .spec.backupName
name: backup/schedule
description: Backup/schedule name
type: string
- JSONPath: .spec.prevSnapName
name: lastSnap
description: Last successful backup snapshot
type: string
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: cstorrestores.openebs.io
spec:
group: openebs.io
version: v1alpha1
scope: Namespaced
names:
plural: cstorrestores
singular: cstorrestore
kind: CStorRestore
shortNames:
- crst
- crsts
- crestores
- crestore
additionalPrinterColumns:
- JSONPath: .spec.restoreName
name: backup
description: backup name which is restored
type: string
- JSONPath: .spec.volumeName
name: volume
description: volume on which restore performed
type: string
- JSONPath: .status
name: Status
description: Restore status
type: string
---
17 changes: 17 additions & 0 deletions deploy/cstor-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ spec:
- name: OPENEBS_IO_VOLUME_MONITOR_IMAGE
value: "openebs/m-exporter:ci"
---
apiVersion: v1
kind: Service
metadata:
name: cvc-operator-service
namespace: openebs
labels:
openebs.io/component-name: cvc-operator-svc
mittachaitu marked this conversation as resolved.
Show resolved Hide resolved
spec:
ports:
- name: api
port: 5757
protocol: TCP
targetPort: 5757
selector:
name: cvc-operator
sessionAffinity: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ go 1.13
require (
github.com/davecgh/go-spew v1.1.1
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
github.com/ghodss/yaml v1.0.0
github.com/imdario/mergo v0.3.8 // indirect
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect
github.com/openebs/api v1.10.0-RC1.0.20200602151240-2b7d2bdbe1ef
github.com/openebs/api v1.10.0-RC1.0.20200608150240-08b494f77b77
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.4.0
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8
go.uber.org/zap v1.13.0
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ github.com/openebs/api v1.10.0-RC1.0.20200528063752-522f45d17d59 h1:9fZ9KGtlStVx
github.com/openebs/api v1.10.0-RC1.0.20200528063752-522f45d17d59/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w=
github.com/openebs/api v1.10.0-RC1.0.20200602151240-2b7d2bdbe1ef h1:p66ZTG26pNr7TIxOMLmXvJcKjmIxIa+xsQ5Xw0hhJA4=
github.com/openebs/api v1.10.0-RC1.0.20200602151240-2b7d2bdbe1ef/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w=
github.com/openebs/api v1.10.0-RC1.0.20200608150240-08b494f77b77 h1:Daq7JniS96LQOSOgneBwEIYOZDh4iuxZBOy6jbw5LHo=
github.com/openebs/api v1.10.0-RC1.0.20200608150240-08b494f77b77/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.1.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down Expand Up @@ -472,6 +474,7 @@ github.com/thecodeteam/goscaleio v0.1.0/go.mod h1:68sdkZAsK8bvEwBlbQnlLS+xU+hvLY
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/timakin/bodyclose v0.0.0-20190721030226-87058b9bfcec/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 h1:3SVOIvH7Ae1KRYyQWRjXWJEA9sS/c/pjvH++55Gr648=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ultraware/funlen v0.0.1/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
github.com/ultraware/funlen v0.0.2/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
Expand Down
57 changes: 52 additions & 5 deletions pkg/controllers/cstorvolumeconfig/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (
clientset "github.com/openebs/api/pkg/client/clientset/versioned"
informers "github.com/openebs/api/pkg/client/informers/externalversions"
leader "github.com/openebs/api/pkg/kubernetes/leaderelection"
server "github.com/openebs/cstor-operators/pkg/server"
cvcserver "github.com/openebs/cstor-operators/pkg/server/cstorvolumeconfig"
"github.com/openebs/cstor-operators/pkg/snapshot"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand All @@ -39,6 +42,8 @@ import (
var (
// lease lock resource name for lease API resource
leaderElectionLockName = "cvc-controller-leader"
// port on which CVC server serve the REST request
port = 5757
)

// Command line flags
Expand All @@ -47,8 +52,17 @@ var (
resyncPeriod = flag.Duration("resync-period", 60*time.Second, "Resync interval of the controller.")
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.")
bindAddr = flag.String("bind", "", "IP Address to bind for CVC-Operator Server")
)

// ServerOptions holds information to start the CVC server
type ServerOptions struct {
// Address on which CVC server will serve the requests
bindAddress string
// httpServer holds the CVC Server configurations
httpServer *cvcserver.HTTPServer
}

// Start starts the cstorvolumeclaim controller.
func Start() error {

Expand Down Expand Up @@ -77,11 +91,12 @@ func Start() error {
return errors.Wrap(err, "error building openebs clientset")
}

// Building NDM Clientset
// ndmClient, err := ndmclientset.NewForConfig(cfg)
//if err != nil {
//return errors.Wrap(err, "error building ndm clientset")
//}
// setupCVCServer instantiate the HTTP server to serve the CVC request
srvOptions, err := setupCVCServer(kubeClient, openebsClient)
if err != nil {
return errors.Wrapf(err, "failed to setupCVCServer")
}
defer srvOptions.httpServer.Shutdown()

// openebsNamespace will hold where the OpenEBS is installed
openebsNamespace = getNamespace()
Expand Down Expand Up @@ -152,3 +167,35 @@ func getClusterConfig(kubeconfig string) (*rest.Config, error) {
}
return rest.InClusterConfig()
}

// setupCVCServer will load the required server configuration and start the CVC server
func setupCVCServer(k8sclientset kubernetes.Interface, openebsClientset clientset.Interface) (*ServerOptions, error) {
options := &ServerOptions{}
// Load default server config
config := server.DefaultServerConfig()

// Update BindAddress if address is provided as a option
if bindAddr != nil && *bindAddr != "" {
config.BindAddr = *bindAddr
}
config.Port = &port
err := config.NormalizeAddrs()
if err != nil {
return nil, errors.Wrapf(err, "failed to setup CVC Server")
}

cvcServer := cvcserver.NewCVCServer(config, os.Stdout).
WithOpenebsClientSet(openebsClientset).
WithKubernetesClientSet(k8sclientset).
WithSnapshotter(&snapshot.SnapClient{})

// Setup the HTTP server
http, err := cvcserver.NewHTTPServer(cvcServer)
if err != nil {
cvcServer.Shutdown()
klog.Errorf("failed to start http server: %+v", err)
return nil, err
}
options.httpServer = http
return options, nil
}
5 changes: 5 additions & 0 deletions pkg/controllers/cstorvolumeconfig/volume_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ func (c *CVCController) createCVR(
annotations[string(apis.SnapshotNameKey)] = snapName
labels[string(apis.CloneEnableKEY)] = isClone
}
// Set isRestoreVol annotation on CVR if CVC has
// "openebs.io/created-through: restore" annotation
if value := claim.GetAnnotations()["openebs.io/created-through"]; value == "restore" {
annotations["isRestoreVol"] = "true"
}
prateekpandey14 marked this conversation as resolved.
Show resolved Hide resolved
cvrObj, err := c.clientset.CstorV1().CStorVolumeReplicas(openebsNamespace).
Get(volume.Name+"-"+string(pool.Name), metav1.GetOptions{})

Expand Down
Loading