Skip to content

Commit

Permalink
applied code formating,
Browse files Browse the repository at this point in the history
updated docs with new api version,
changed bundle script,
added VMServiceScrape for VMCluster objects with port filter
  • Loading branch information
f41gh7 committed Jul 25, 2020
1 parent 85a07e5 commit e6010a5
Show file tree
Hide file tree
Showing 56 changed files with 189 additions and 20,509 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Temporary Build Files
.idea
bin/
build/_output
bundle_crd.zip
operator.zip
bundle.Dockerfile
coverage.txt
doc-print
build/_test
# Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
### Emacs ###
Expand Down
7 changes: 3 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

for developing you need:
- golang 1.13+
- operator-sdk 1.18.1
- operator-sdk 1.19.0
- docker
- minikube or kind for e2e tests
- golangci-lint
- operator-courier



Expand All @@ -18,10 +17,10 @@ Use `make build` - it will generate new crds and build binary

for running locally you need minikube and run two commands:
```bash
kubectl apply -f deploy/crds
make install
make run
```
or you can run it from IDE with ```cmd/manager/main.go```
or you can run it from IDE with ```main.go```

## publish changes

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ e2e-local: generate fmt vet manifests fix118

lint:
golangci-lint run --exclude '(SA1019):' -E typecheck -E gosimple --timeout 5m --skip-dirs 'pkg/client'
golint ./pkg/
golint ./controllers/

.PHONY:clean
clean:
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ make test
# you need minikube for e2e, do not run it on live cluster
#e2e tests with local binary
make e2e-local
# e2e tests with docker image (must be pushed to repository first)
make e2e
```
14 changes: 7 additions & 7 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ namePrefix: vm-operator-
#commonLabels:
# someName: someValue

bases:
- ../crd
- ../rbac
- ../manager
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
#- ../webhook
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
- ../prometheus

patchesStrategicMerge:
# Protect the /metrics endpoint by putting it behind auth.
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, please comment the following line.
Expand All @@ -40,7 +34,6 @@ patchesStrategicMerge:
#- webhookcainjection_patch.yaml

# the following config is for teaching kustomize how to do var substitution
vars:
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
# objref:
Expand Down Expand Up @@ -68,3 +61,10 @@ vars:
# kind: Service
# version: v1
# name: webhook-service
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../crd
- ../rbac
- ../manager
- ../prometheus
30 changes: 0 additions & 30 deletions config/examples/alertmanager-sts.yaml

This file was deleted.

12 changes: 12 additions & 0 deletions config/examples/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## This file is auto-generated, do not modify ##
resources:
- vmagent_rbac.yaml
- vmagent.yaml
- vmalert.yaml
- vmalertmanager.yaml
- vmpodscrape.yaml
- vmrule.yaml
- vmservicescrape.yaml
- vmsingle.yaml
- vmsingle_with_pvc.yaml
- vmcluster.yaml
File renamed without changes.
4 changes: 4 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
resources:
- manager.yaml
images:
- name: manager
newName: victoriametrics/operator
newTag: latest
8 changes: 1 addition & 7 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
apiVersion: v1
kind: Namespace
metadata:
labels:
control-plane: vm-operator
name: default
---
apiVersion: apps/v1
kind: Deployment
Expand All @@ -26,7 +20,7 @@ spec:
- name: manager
command:
- manager
image: victoriametrics/operator:latest
image: manager
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
Expand Down
2 changes: 1 addition & 1 deletion config/manifests/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
resources:
- ../default
- ../samples
- ../examples
13 changes: 12 additions & 1 deletion controllers/factory/servicemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,20 @@ func gzipConfig(buf *bytes.Buffer, conf []byte) error {
return nil
}

func CreateVMServiceScrapeFromService(ctx context.Context, rclient client.Client, service *v1.Service) error {
func CreateVMServiceScrapeFromService(ctx context.Context, rclient client.Client, service *v1.Service, filterPortNames ...string) error {
endPoints := []victoriametricsv1beta1.Endpoint{}
for _, servicePort := range service.Spec.Ports {
var nameMatched bool
for _, filter := range filterPortNames {
if servicePort.Name == filter {
nameMatched = true
break
}
}
if len(filterPortNames) > 0 && !nameMatched {
continue
}

endPoints = append(endPoints, victoriametricsv1beta1.Endpoint{
Port: servicePort.Name,
})
Expand Down
25 changes: 22 additions & 3 deletions controllers/factory/vmcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,17 @@ func CreateOrUpdateVMCluster(ctx context.Context, cr *v1beta1.VMCluster, rclient
return status, err
}

_, err = CreateOrUpdateVMStorageService(ctx, cr, rclient, c)
storageSvc, err := CreateOrUpdateVMStorageService(ctx, cr, rclient, c)
if err != nil {
reason = "failed to create vmStorage service"
return status, err
}
if !c.DisableSelfServiceMonitorCreation {
err := CreateVMServiceScrapeFromService(ctx, rclient, storageSvc, "http")
if err != nil {
log.Error(err, "cannot create VMServiceScrape for vmStorage")
}
}
//wait for expand
expanding, err = waitForExpanding(ctx, rclient, cr.Namespace, cr.VMStorageSelectorLabels(), *cr.Spec.VMStorage.ReplicaCount)
if err != nil {
Expand All @@ -98,11 +104,18 @@ func CreateOrUpdateVMCluster(ctx context.Context, cr *v1beta1.VMCluster, rclient
return status, err
}
//create vmselect service
_, err = CreateOrUpdateVMSelectService(ctx, cr, rclient, c)
selectSvc, err := CreateOrUpdateVMSelectService(ctx, cr, rclient, c)
if err != nil {
reason = "failed to create vmSelect service"
return status, err
}
if !c.DisableSelfServiceMonitorCreation {
err := CreateVMServiceScrapeFromService(ctx, rclient, selectSvc, "http")
if err != nil {
log.Error(err, "cannot create VMServiceScrape for vmSelect")
}
}

err = performRollingUpdateOnSts(ctx, rclient, vmSelectsts.Name, cr.Namespace, cr.VMSelectSelectorLabels(), c)
if err != nil {
reason = v1beta1.SelectRollingUpdateFailed
Expand All @@ -129,11 +142,17 @@ func CreateOrUpdateVMCluster(ctx context.Context, cr *v1beta1.VMCluster, rclient
reason = v1beta1.InsertCreationFailed
return status, err
}
_, err = CreateOrUpdateVMInsertService(ctx, cr, rclient, c)
insertSvc, err := CreateOrUpdateVMInsertService(ctx, cr, rclient, c)
if err != nil {
reason = "failed to create vmInsert service"
return status, err
}
if !c.DisableSelfServiceMonitorCreation {
err := CreateVMServiceScrapeFromService(ctx, rclient, insertSvc)
if err != nil {
log.Error(err, "cannot create VMServiceScrape for vmInsert")
}
}
expanding, err = waitForExpanding(ctx, rclient, cr.Namespace, cr.VMInsertSelectorLabels(), *cr.Spec.VMInsert.ReplicaCount)
if err != nil {
reason = "failed to wait for vmInsert expanding"
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmagent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type VMAgentReconciler struct {
BaseConf *conf.BaseOperatorConf
}

// Reconcile general reconcile method
// +kubebuilder:rbac:groups=operator.victoriametrics.com,resources=vmagents,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=operator.victoriametrics.com,resources=vmagents/status,verbs=get;update;patch
// +kubebuilder:rbac:groups="",resources=pods,verbs=*
Expand All @@ -48,7 +49,6 @@ type VMAgentReconciler struct {
// +kubebuilder:rbac:groups="",resources=services/finalizers,verbs=*
// +kubebuilder:rbac:groups=monitoring.coreos.com,resources=*,verbs=*
// +kubebuilder:rbac:groups="",resources=namespaces,verbs=get;watch;list

func (r *VMAgentReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
reqLogger := r.Log.WithValues("vmagent", req.NamespacedName)
reqLogger.Info("Reconciling")
Expand Down Expand Up @@ -95,6 +95,7 @@ func (r *VMAgentReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
return ctrl.Result{}, nil
}

// SetupWithManager general setup method
func (r *VMAgentReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&victoriametricsv1beta1.VMAgent{}).
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmalert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ type VMAlertReconciler struct {
BaseConf *conf.BaseOperatorConf
}

// Reconcile general reconile method for controller
// +kubebuilder:rbac:groups=operator.victoriametrics.com,resources=vmalerts,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=operator.victoriametrics.com,resources=vmalerts/status,verbs=get;update;patch

func (r *VMAlertReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
reqLogger := r.Log.WithValues("vmalert", req.NamespacedName)
reqLogger.Info("Reconciling")
Expand Down Expand Up @@ -88,6 +88,7 @@ func (r *VMAlertReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
return ctrl.Result{}, nil
}

// SetupWithManager general setup method
func (r *VMAlertReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&victoriametricsv1beta1.VMAlert{}).
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmalertmanager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ type VMAlertmanagerReconciler struct {
BaseConf *conf.BaseOperatorConf
}

// Reconcile general reconcile method for controller
// +kubebuilder:rbac:groups=operator.victoriametrics.com,resources=vmalertmanagers,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=operator.victoriametrics.com,resources=vmalertmanagers/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=*
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=*
// +kubebuilder:rbac:groups="",resources=secrets,verbs=*

func (r *VMAlertmanagerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
reqLogger := r.Log.WithValues("vmalertmanager", req.NamespacedName)
reqLogger.Info("Reconciling")
Expand Down Expand Up @@ -75,6 +75,7 @@ func (r *VMAlertmanagerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
return ctrl.Result{}, nil
}

// SetupWithManager general setup method
func (r *VMAlertmanagerReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&victoriametricsv1beta1.VMAlertmanager{}).
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type VMClusterReconciler struct {
BaseConf *conf.BaseOperatorConf
}

// Reconcile general reconcile method for controller
// +kubebuilder:rbac:groups=operator.victoriametrics.com,resources=vmclusters,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=operator.victoriametrics.com,resources=vmclusters/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=*

func (r *VMClusterReconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) {
reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
reqLogger.Info("Reconciling VMCluster")
Expand Down Expand Up @@ -65,6 +65,7 @@ func (r *VMClusterReconciler) Reconcile(request ctrl.Request) (ctrl.Result, erro
return reconcile.Result{}, nil
}

// SetupWithManager general setup method
func (r *VMClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&victoriametricsv1beta1.VMCluster{}).
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmpodscrape_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ type VMPodScrapeReconciler struct {
BaseConf *conf.BaseOperatorConf
}

// Reconcile general reconcile method for controller
// +kubebuilder:rbac:groups=operator.victoriametrics.com,resources=vmpodscrapes,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=operator.victoriametrics.com,resources=vmpodscrapes/status,verbs=get;update;patch

func (r *VMPodScrapeReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
reqLogger := r.Log.WithValues("vmpodscrape", req.NamespacedName)
reqLogger.Info("Reconciling VMPodScrape")
Expand Down Expand Up @@ -79,6 +79,7 @@ func (r *VMPodScrapeReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
return ctrl.Result{}, nil
}

// SetupWithManager general setup method
func (r *VMPodScrapeReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&victoriametricsv1beta1.VMPodScrape{}).
Expand Down
Loading

0 comments on commit e6010a5

Please sign in to comment.