Skip to content

Commit

Permalink
refact(cvc): move cvc operator to its own deployment
Browse files Browse the repository at this point in the history
Signed-off-by: prateekpandey14 <[email protected]>
  • Loading branch information
prateekpandey14 committed Dec 18, 2019
1 parent e59a8de commit 7ee6dfa
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 18 deletions.
18 changes: 16 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ M_EXPORTER_REPO_NAME?=m-exporter
ADMISSION_SERVER_REPO_NAME?=admission-server
M_UPGRADE_REPO_NAME?=m-upgrade
CSPC_OPERATOR_REPO_NAME?=cspc-operator
CVC_OPERATOR_REPO_NAME?=cvc-operator

ifeq (${IMAGE_TAG}, )
IMAGE_TAG = ci
Expand Down Expand Up @@ -109,7 +110,7 @@ EXPORTER=maya-exporter
CSPC_OPERATOR=cspc-operator
CSPC_OPERATOR_DEBUG=cspc-operator-debug
CSP_OPERATOR_DEBUG=cstor-pool-mgmt-debug

CVC_OPERATOR=cvc-operator

# Specify the date o build
BUILD_DATE = $(shell date +'%Y%m%d%H%M%S')
Expand All @@ -121,7 +122,9 @@ include ./buildscripts/upgrade/Makefile.mk
include ./buildscripts/upgrade-082090/Makefile.mk

.PHONY: all
all: compile-tests apiserver-image exporter-image pool-mgmt-image volume-mgmt-image admission-server-image cspc-operator-image cspc-operator-debug-image cspi-mgmt-image upgrade-image provisioner-localpv-image
all: compile-tests apiserver-image exporter-image pool-mgmt-image volume-mgmt-image \
admission-server-image cspc-operator-image cspc-operator-debug-image \
cvc-operator-image cspi-mgmt-image upgrade-image provisioner-localpv-image

.PHONY: all.arm64
all.arm64: apiserver-image.arm64 provisioner-localpv-image.arm64
Expand Down Expand Up @@ -422,6 +425,17 @@ cspc-operator-debug-image:
@cd buildscripts/${CSPC_OPERATOR_DEBUG} && sudo docker build -t ${HUB_USER}/${CSPC_OPERATOR_REPO_NAME}:inject --build-arg BUILD_DATE=${BUILD_DATE} .
@rm buildscripts/${CSPC_OPERATOR_DEBUG}/${CSPC_OPERATOR}

.PHONY: cvc-operator-image
cvc-operator-image:
@echo "----------------------------"
@echo -n "--> cvc-operator image "
@echo "${HUB_USER}/${CVC_OPERATOR_REPO_NAME}:${IMAGE_TAG}"
@echo "----------------------------"
@PNAME=${CVC_OPERATOR} CTLNAME=${CVC_OPERATOR} sh -c "'$(PWD)/buildscripts/build.sh'"
@cp bin/${CVC_OPERATOR}/${CVC_OPERATOR} buildscripts/cvc-operator/
@cd buildscripts/${CVC_OPERATOR} && sudo docker build -t ${HUB_USER}/${CVC_OPERATOR_REPO_NAME}:${IMAGE_TAG} --build-arg BUILD_DATE=${BUILD_DATE} .
@rm buildscripts/${CVC_OPERATOR}/${CVC_OPERATOR}

# Push images
.PHONY: deploy-images
deploy-images:
Expand Down
23 changes: 23 additions & 0 deletions buildscripts/cvc-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM alpine:3.10

RUN apk add --no-cache \
iproute2 \
bash \
curl \
net-tools \
mii-tool \
procps \
libc6-compat \
ca-certificates

COPY cvc-operator /usr/local/bin/cvc-operator

ARG BUILD_DATE
LABEL org.label-schema.name="cvc-operator"
LABEL org.label-schema.description="Operator for OpenEBS cStor csi volumes"
LABEL org.label-schema.url="http://www.openebs.io/"
LABEL org.label-schema.vcs-url="https://github.com/openebs/maya"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.build-date=$BUILD_DATE

ENTRYPOINT ["/usr/local/bin/cvc-operator"]
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func getOrCreateCStorTargetDeployment(
vol *apis.CStorVolume,
) (*appsv1.Deployment, error) {

deployObj, err := deploy.NewKubeClient(deploy.WithNamespace("openebs")).
deployObj, err := deploy.NewKubeClient(deploy.WithNamespace(getNamespace())).
Get(vol.Name + "-target")

if err != nil && !k8serror.IsNotFound(err) {
Expand Down Expand Up @@ -357,7 +357,7 @@ func getOrCreateCStorTargetDeployment(
return nil, errors.Wrapf(err, "failed to build deployment object")
}

deployObj, err = deploy.NewKubeClient(deploy.WithNamespace("openebs")).Create(deployObj)
deployObj, err = deploy.NewKubeClient(deploy.WithNamespace(getNamespace())).Create(deployObj)

if err != nil {
return nil, errors.Wrapf(err, "failed to create deployment object")
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"flag"
"os"
"os/signal"
"sync"

"github.com/pkg/errors"
"k8s.io/klog"
Expand All @@ -47,12 +46,20 @@ var (

// Command line flags
var (
leaderElection = flag.Bool("leader-election", true, "Enables leader election.")
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.")
)

// Start starts the cstorvolumeclaim controller.
func Start(controllerMtx *sync.RWMutex) error {
func Start() error {

klog.InitFlags(nil)
err := flag.Set("logtostderr", "true")
if err != nil {
return errors.Wrap(err, "failed to set logtostderr flag")
}
flag.Parse()

// Get in cluster config
cfg, err := getClusterConfig(kubeconfig)
if err != nil {
Expand Down Expand Up @@ -85,7 +92,6 @@ func Start(controllerMtx *sync.RWMutex) error {
// 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 := NewCVCControllerBuilder().
withKubeClient(kubeClient).
withOpenEBSClient(openebsClient).
Expand All @@ -100,8 +106,6 @@ func Start(controllerMtx *sync.RWMutex) error {
withEventHandler(cvcInformerFactory).
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")
}
Expand Down
32 changes: 32 additions & 0 deletions cmd/cvc-operator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2019 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 main

import (
"os"

cvc "github.com/openebs/maya/cmd/cvc-operator/controller"
"k8s.io/klog"
)

func main() {
if err := cvc.Start(); err != nil {
klog.Errorf("Failed to start cstorvolumeclaim controller:{%s}", err.Error())
os.Exit(1)
}
os.Exit(0)
}
8 changes: 0 additions & 8 deletions cmd/maya-apiserver/app/command/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"syscall"
"time"

cvc "github.com/openebs/maya/cmd/cstorvolumeclaim"
"github.com/openebs/maya/cmd/maya-apiserver/app/config"
"github.com/openebs/maya/cmd/maya-apiserver/app/server"
"github.com/openebs/maya/cmd/maya-apiserver/cstor-operator/spc"
Expand Down Expand Up @@ -213,13 +212,6 @@ func Run(cmd *cobra.Command, c *CmdStartOptions) error {

}()

go func() {
err := cvc.Start(&ControllerMutex)
if err != nil {
klog.Errorf("Failed to start cstorvolume claim controller: %s", err.Error())
}
}()

if env.Truthy(env.OpenEBSEnableAnalytics) {
usage.New().Build().InstallBuilder(true).Send()
go usage.PingCheck()
Expand Down

0 comments on commit 7ee6dfa

Please sign in to comment.