Skip to content

Commit

Permalink
Merge pull request #267 from Altinity/0.9.1
Browse files Browse the repository at this point in the history
0.9.1
  • Loading branch information
alex-zaitsev authored Feb 24, 2020
2 parents 8c600b8 + a4ecf45 commit aaee541
Show file tree
Hide file tree
Showing 55 changed files with 531 additions and 372 deletions.
27 changes: 17 additions & 10 deletions cmd/metrics_exporter/app/metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ var (
// chopConfigFile defines path to clickhouse-operator config file to be used
chopConfigFile string

// kubeConfigFile defines path to kube config file to be used
kubeConfigFile string

// masterURL defines URL of kubernetes master to be used
masterURL string

// metricsEP defines metrics end-point IP address
metricsEP string

Expand All @@ -55,6 +61,8 @@ var (
func init() {
flag.BoolVar(&versionRequest, "version", false, "Display clickhouse-operator version and exit")
flag.StringVar(&chopConfigFile, "config", "", "Path to clickhouse-operator config file.")
flag.StringVar(&kubeConfigFile, "kubeconfig", "", "Path to custom kubernetes config file. Makes sense if runs outside of the cluster only.")
flag.StringVar(&masterURL, "master", "", "The address of custom Kubernetes API server. Makes sense if runs outside of the cluster and not being specified in kube config file only.")
flag.StringVar(&metricsEP, "metrics-endpoint", defaultMetricsEndpoint, "The Prometheus exporter endpoint.")
flag.StringVar(&chiListEP, "chi-list-endpoint", defaultChiListEP, "The CHI list endpoint.")
flag.Parse()
Expand All @@ -78,18 +86,15 @@ func Run() {
os.Exit(1)
}()

//
// Create operator instance
//
chop := chop.NewCHOp(version.Version, nil, chopConfigFile)
if err := chop.Init(); err != nil {
glog.Fatalf("Unable to init CHOp instance %v\n", err)
os.Exit(1)
}
glog.V(1).Infof("Starting metrics exporter. Version:%s GitSHA:%s\n", version.Version, version.GitSHA)

// Initialize k8s API clients
_, chopClient := chop.GetClientset(kubeConfigFile, masterURL)

glog.V(1).Info("Starting metrics exporter\n")
// Create operator instance
chop := chop.GetCHOp(chopClient, chopConfigFile)

metrics.StartMetricsREST(
exporter := metrics.StartMetricsREST(
metrics.NewCHAccessInfo(
chop.Config().CHUsername,
chop.Config().CHPassword,
Expand All @@ -103,5 +108,7 @@ func Run() {
chiListPath,
)

exporter.DiscoveryWatchedCHIs(chop, chopClient)

<-ctx.Done()
}
82 changes: 5 additions & 77 deletions cmd/operator/app/clickhouse_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"fmt"
"os"
"os/signal"
"os/user"
"path/filepath"
"sync"
"syscall"
"time"
Expand All @@ -30,15 +28,10 @@ import (
"github.com/altinity/clickhouse-operator/pkg/controller/chi"
"github.com/altinity/clickhouse-operator/pkg/version"

chopclientset "github.com/altinity/clickhouse-operator/pkg/client/clientset/versioned"
chopinformers "github.com/altinity/clickhouse-operator/pkg/client/informers/externalversions"

kubeinformers "k8s.io/client-go/informers"
kube "k8s.io/client-go/kubernetes"
kuberest "k8s.io/client-go/rest"
kubeclientcmd "k8s.io/client-go/tools/clientcmd"

"github.com/golang/glog"
kubeinformers "k8s.io/client-go/informers"
)

// Prometheus exporter defaults
Expand Down Expand Up @@ -89,60 +82,12 @@ func init() {
flag.BoolVar(&versionRequest, "version", false, "Display clickhouse-operator version and exit")
flag.BoolVar(&debugRequest, "debug", false, "Debug run")
flag.StringVar(&chopConfigFile, "config", "", "Path to clickhouse-operator config file.")
flag.StringVar(&kubeConfigFile, "kubeconfig", "", "Path to kubernetes config file. Only required if called outside of the cluster.")
flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Only required if called outside of the cluster and not being specified in kube config file.")
flag.StringVar(&kubeConfigFile, "kubeconfig", "", "Path to custom kubernetes config file. Makes sense if runs outside of the cluster only.")
flag.StringVar(&masterURL, "master", "", "The address of custom Kubernetes API server. Makes sense if runs outside of the cluster and not being specified in kube config file only.")
flag.StringVar(&metricsEP, "metrics-endpoint", defaultMetricsEndpoint, "The Prometheus exporter endpoint.")
flag.Parse()
}

// getKubeConfig creates kuberest.Config object based on current environment
func getKubeConfig(kubeConfigFile, masterURL string) (*kuberest.Config, error) {
if len(kubeConfigFile) > 0 {
// kube config file specified as CLI flag
return kubeclientcmd.BuildConfigFromFlags(masterURL, kubeConfigFile)
}

if len(os.Getenv("KUBECONFIG")) > 0 {
// kube config file specified as ENV var
return kubeclientcmd.BuildConfigFromFlags(masterURL, os.Getenv("KUBECONFIG"))
}

if conf, err := kuberest.InClusterConfig(); err == nil {
// in-cluster configuration found
return conf, nil
}

usr, err := user.Current()
if err != nil {
return nil, fmt.Errorf("user not found")
}

// OS user found. Parse ~/.kube/config file
conf, err := kubeclientcmd.BuildConfigFromFlags("", filepath.Join(usr.HomeDir, ".kube", "config"))
if err != nil {
return nil, fmt.Errorf("~/.kube/config not found")
}

// ~/.kube/config found
return conf, nil
}

// createClientsets creates Clientset objects
func createClientsets(config *kuberest.Config) (*kube.Clientset, *chopclientset.Clientset) {

kubeClientset, err := kube.NewForConfig(config)
if err != nil {
glog.Fatalf("Unable to initialize kubernetes API clientset: %s", err.Error())
}

chopClientset, err := chopclientset.NewForConfig(config)
if err != nil {
glog.Fatalf("Unable to initialize clickhouse-operator API clientset: %s", err.Error())
}

return kubeClientset, chopClientset
}

// Run is an entry point of the application
func Run() {
if versionRequest {
Expand All @@ -157,28 +102,13 @@ func Run() {

glog.V(1).Infof("Starting clickhouse-operator. Version:%s GitSHA:%s\n", version.Version, version.GitSHA)

//
// Initialize k8s API clients
//
kubeConfig, err := getKubeConfig(kubeConfigFile, masterURL)
if err != nil {
glog.Fatalf("Unable to build kubeconf: %s", err.Error())
os.Exit(1)
}
kubeClient, chopClient := createClientsets(kubeConfig)
kubeClient, chopClient := chop.GetClientset(kubeConfigFile, masterURL)

//
// Create operator instance
//
chop := chop.NewCHOp(version.Version, chopClient, chopConfigFile)
if err := chop.Init(); err != nil {
glog.Fatalf("Unable to init CHOP instance %v\n", err)
os.Exit(1)
}
chop := chop.GetCHOp(chopClient, chopConfigFile)

//
// Create Informers
//
kubeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(
kubeClient,
kubeInformerFactoryResyncPeriod,
Expand All @@ -190,9 +120,7 @@ func Run() {
chopinformers.WithNamespace(chop.Config().GetInformerNamespace()),
)

//
// Create Controller
//
chiController := chi.NewController(
chop,
chopClient,
Expand Down
2 changes: 1 addition & 1 deletion config/config-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ChConfigNetworksHostRegexpTemplate: "chi-{chi}-[^.]+\\d+-\\d+\\.{namespace}.svc.
# 1. Metrics requests
# 2. Schema maintenance
# 3. DROP DNS CACHE
# User with such credentials credentials can be specified in additional ClickHouse .xml config files,
# User with such credentials can be specified in additional ClickHouse .xml config files,
# located in `chUsersConfigsPath` folder
chUsername: clickhouse_operator
chPassword: clickhouse_operator_password
Expand Down
5 changes: 3 additions & 2 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

# List of namespaces where clickhouse-operator watches for events.
# Concurrently running operators should watch on different namespaces
# watchNamespaces:
#watchNamespaces:
# - dev
# - test
# - info
# - onemore

Expand Down Expand Up @@ -89,7 +90,7 @@ ChConfigNetworksHostRegexpTemplate: "chi-{chi}-[^.]+\\d+-\\d+\\.{namespace}.svc.
# 1. Metrics requests
# 2. Schema maintenance
# 3. DROP DNS CACHE
# User with such credentials credentials can be specified in additional ClickHouse .xml config files,
# User with such credentials can be specified in additional ClickHouse .xml config files,
# located in `chUsersConfigsPath` folder
chUsername: clickhouse_operator
chPassword: clickhouse_operator_password
Expand Down
30 changes: 12 additions & 18 deletions deploy/dev/clickhouse-operator-install-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# Possible Template Parameters:
#
# dev
# altinity/clickhouse-operator:0.9.0
#
# Setup CustomResourceDefinition(s)
# CustomResourceDefinition is namespace-less and must have unique name
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand Down Expand Up @@ -1288,7 +1281,7 @@ subjects:
# Possible Template Parameters:
#
# dev
# altinity/clickhouse-operator:0.9.0
# altinity/clickhouse-operator:0.9.1
# etc-clickhouse-operator-files
#
apiVersion: v1
Expand All @@ -1308,8 +1301,9 @@ data:
# List of namespaces where clickhouse-operator watches for events.
# Concurrently running operators should watch on different namespaces
# watchNamespaces:
#watchNamespaces:
# - dev
# - test
# - info
# - onemore
Expand Down Expand Up @@ -1391,7 +1385,7 @@ data:
# 1. Metrics requests
# 2. Schema maintenance
# 3. DROP DNS CACHE
# User with such credentials credentials can be specified in additional ClickHouse .xml config files,
# User with such credentials can be specified in additional ClickHouse .xml config files,
# located in `chUsersConfigsPath` folder
chUsername: clickhouse_operator
chPassword: clickhouse_operator_password
Expand All @@ -1401,7 +1395,7 @@ data:
# Possible Template Parameters:
#
# dev
# altinity/clickhouse-operator:0.9.0
# altinity/clickhouse-operator:0.9.1
# etc-clickhouse-operator-confd-files
#
apiVersion: v1
Expand All @@ -1416,7 +1410,7 @@ data:
# Possible Template Parameters:
#
# dev
# altinity/clickhouse-operator:0.9.0
# altinity/clickhouse-operator:0.9.1
# etc-clickhouse-operator-configd-files
#
apiVersion: v1
Expand Down Expand Up @@ -1462,7 +1456,7 @@ data:
# Possible Template Parameters:
#
# dev
# altinity/clickhouse-operator:0.9.0
# altinity/clickhouse-operator:0.9.1
# etc-clickhouse-operator-templatesd-files
#
apiVersion: v1
Expand Down Expand Up @@ -1561,7 +1555,7 @@ data:
# Possible Template Parameters:
#
# dev
# altinity/clickhouse-operator:0.9.0
# altinity/clickhouse-operator:0.9.1
# etc-clickhouse-operator-usersd-files
#
apiVersion: v1
Expand Down Expand Up @@ -1610,8 +1604,8 @@ data:
# Possible Template Parameters:
#
# dev
# altinity/clickhouse-operator:0.9.0
# altinity/metrics-exporter:0.9.0
# altinity/clickhouse-operator:0.9.1
# altinity/metrics-exporter:0.9.1
#
# Setup Deployment for clickhouse-operator
# Deployment would be created in kubectl-specified namespace
Expand Down Expand Up @@ -1651,7 +1645,7 @@ spec:
name: etc-clickhouse-operator-usersd-files
containers:
- name: clickhouse-operator
image: altinity/clickhouse-operator:0.9.0
image: altinity/clickhouse-operator:0.9.1
imagePullPolicy: Always
volumeMounts:
- name: etc-clickhouse-operator-folder
Expand Down Expand Up @@ -1716,7 +1710,7 @@ spec:
resource: limits.memory

- name: metrics-exporter
image: altinity/metrics-exporter:0.9.0
image: altinity/metrics-exporter:0.9.1
imagePullPolicy: Always
volumeMounts:
- name: etc-clickhouse-operator-folder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# Possible Template Parameters:
#
# ${OPERATOR_NAMESPACE}
# ${OPERATOR_IMAGE}
#
# Setup CustomResourceDefinition(s)
# CustomResourceDefinition is namespace-less and must have unique name
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand Down
7 changes: 0 additions & 7 deletions deploy/operator/clickhouse-operator-install-crd.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# Possible Template Parameters:
#
# -
# altinity/clickhouse-operator:0.9.0
#
# Setup CustomResourceDefinition(s)
# CustomResourceDefinition is namespace-less and must have unique name
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand Down
Loading

0 comments on commit aaee541

Please sign in to comment.