Skip to content

Commit aaee541

Browse files
authored
Merge pull request #267 from Altinity/0.9.1
0.9.1
2 parents 8c600b8 + a4ecf45 commit aaee541

File tree

55 files changed

+531
-372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+531
-372
lines changed

cmd/metrics_exporter/app/metrics_exporter.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ var (
4646
// chopConfigFile defines path to clickhouse-operator config file to be used
4747
chopConfigFile string
4848

49+
// kubeConfigFile defines path to kube config file to be used
50+
kubeConfigFile string
51+
52+
// masterURL defines URL of kubernetes master to be used
53+
masterURL string
54+
4955
// metricsEP defines metrics end-point IP address
5056
metricsEP string
5157

@@ -55,6 +61,8 @@ var (
5561
func init() {
5662
flag.BoolVar(&versionRequest, "version", false, "Display clickhouse-operator version and exit")
5763
flag.StringVar(&chopConfigFile, "config", "", "Path to clickhouse-operator config file.")
64+
flag.StringVar(&kubeConfigFile, "kubeconfig", "", "Path to custom kubernetes config file. Makes sense if runs outside of the cluster only.")
65+
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.")
5866
flag.StringVar(&metricsEP, "metrics-endpoint", defaultMetricsEndpoint, "The Prometheus exporter endpoint.")
5967
flag.StringVar(&chiListEP, "chi-list-endpoint", defaultChiListEP, "The CHI list endpoint.")
6068
flag.Parse()
@@ -78,18 +86,15 @@ func Run() {
7886
os.Exit(1)
7987
}()
8088

81-
//
82-
// Create operator instance
83-
//
84-
chop := chop.NewCHOp(version.Version, nil, chopConfigFile)
85-
if err := chop.Init(); err != nil {
86-
glog.Fatalf("Unable to init CHOp instance %v\n", err)
87-
os.Exit(1)
88-
}
89+
glog.V(1).Infof("Starting metrics exporter. Version:%s GitSHA:%s\n", version.Version, version.GitSHA)
90+
91+
// Initialize k8s API clients
92+
_, chopClient := chop.GetClientset(kubeConfigFile, masterURL)
8993

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

92-
metrics.StartMetricsREST(
97+
exporter := metrics.StartMetricsREST(
9398
metrics.NewCHAccessInfo(
9499
chop.Config().CHUsername,
95100
chop.Config().CHPassword,
@@ -103,5 +108,7 @@ func Run() {
103108
chiListPath,
104109
)
105110

111+
exporter.DiscoveryWatchedCHIs(chop, chopClient)
112+
106113
<-ctx.Done()
107114
}

cmd/operator/app/clickhouse_operator.go

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"fmt"
2121
"os"
2222
"os/signal"
23-
"os/user"
24-
"path/filepath"
2523
"sync"
2624
"syscall"
2725
"time"
@@ -30,15 +28,10 @@ import (
3028
"github.com/altinity/clickhouse-operator/pkg/controller/chi"
3129
"github.com/altinity/clickhouse-operator/pkg/version"
3230

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

36-
kubeinformers "k8s.io/client-go/informers"
37-
kube "k8s.io/client-go/kubernetes"
38-
kuberest "k8s.io/client-go/rest"
39-
kubeclientcmd "k8s.io/client-go/tools/clientcmd"
40-
4133
"github.com/golang/glog"
34+
kubeinformers "k8s.io/client-go/informers"
4235
)
4336

4437
// Prometheus exporter defaults
@@ -89,60 +82,12 @@ func init() {
8982
flag.BoolVar(&versionRequest, "version", false, "Display clickhouse-operator version and exit")
9083
flag.BoolVar(&debugRequest, "debug", false, "Debug run")
9184
flag.StringVar(&chopConfigFile, "config", "", "Path to clickhouse-operator config file.")
92-
flag.StringVar(&kubeConfigFile, "kubeconfig", "", "Path to kubernetes config file. Only required if called outside of the cluster.")
93-
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.")
85+
flag.StringVar(&kubeConfigFile, "kubeconfig", "", "Path to custom kubernetes config file. Makes sense if runs outside of the cluster only.")
86+
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.")
9487
flag.StringVar(&metricsEP, "metrics-endpoint", defaultMetricsEndpoint, "The Prometheus exporter endpoint.")
9588
flag.Parse()
9689
}
9790

98-
// getKubeConfig creates kuberest.Config object based on current environment
99-
func getKubeConfig(kubeConfigFile, masterURL string) (*kuberest.Config, error) {
100-
if len(kubeConfigFile) > 0 {
101-
// kube config file specified as CLI flag
102-
return kubeclientcmd.BuildConfigFromFlags(masterURL, kubeConfigFile)
103-
}
104-
105-
if len(os.Getenv("KUBECONFIG")) > 0 {
106-
// kube config file specified as ENV var
107-
return kubeclientcmd.BuildConfigFromFlags(masterURL, os.Getenv("KUBECONFIG"))
108-
}
109-
110-
if conf, err := kuberest.InClusterConfig(); err == nil {
111-
// in-cluster configuration found
112-
return conf, nil
113-
}
114-
115-
usr, err := user.Current()
116-
if err != nil {
117-
return nil, fmt.Errorf("user not found")
118-
}
119-
120-
// OS user found. Parse ~/.kube/config file
121-
conf, err := kubeclientcmd.BuildConfigFromFlags("", filepath.Join(usr.HomeDir, ".kube", "config"))
122-
if err != nil {
123-
return nil, fmt.Errorf("~/.kube/config not found")
124-
}
125-
126-
// ~/.kube/config found
127-
return conf, nil
128-
}
129-
130-
// createClientsets creates Clientset objects
131-
func createClientsets(config *kuberest.Config) (*kube.Clientset, *chopclientset.Clientset) {
132-
133-
kubeClientset, err := kube.NewForConfig(config)
134-
if err != nil {
135-
glog.Fatalf("Unable to initialize kubernetes API clientset: %s", err.Error())
136-
}
137-
138-
chopClientset, err := chopclientset.NewForConfig(config)
139-
if err != nil {
140-
glog.Fatalf("Unable to initialize clickhouse-operator API clientset: %s", err.Error())
141-
}
142-
143-
return kubeClientset, chopClientset
144-
}
145-
14691
// Run is an entry point of the application
14792
func Run() {
14893
if versionRequest {
@@ -157,28 +102,13 @@ func Run() {
157102

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

160-
//
161105
// Initialize k8s API clients
162-
//
163-
kubeConfig, err := getKubeConfig(kubeConfigFile, masterURL)
164-
if err != nil {
165-
glog.Fatalf("Unable to build kubeconf: %s", err.Error())
166-
os.Exit(1)
167-
}
168-
kubeClient, chopClient := createClientsets(kubeConfig)
106+
kubeClient, chopClient := chop.GetClientset(kubeConfigFile, masterURL)
169107

170-
//
171108
// Create operator instance
172-
//
173-
chop := chop.NewCHOp(version.Version, chopClient, chopConfigFile)
174-
if err := chop.Init(); err != nil {
175-
glog.Fatalf("Unable to init CHOP instance %v\n", err)
176-
os.Exit(1)
177-
}
109+
chop := chop.GetCHOp(chopClient, chopConfigFile)
178110

179-
//
180111
// Create Informers
181-
//
182112
kubeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(
183113
kubeClient,
184114
kubeInformerFactoryResyncPeriod,
@@ -190,9 +120,7 @@ func Run() {
190120
chopinformers.WithNamespace(chop.Config().GetInformerNamespace()),
191121
)
192122

193-
//
194123
// Create Controller
195-
//
196124
chiController := chi.NewController(
197125
chop,
198126
chopClient,

config/config-dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ ChConfigNetworksHostRegexpTemplate: "chi-{chi}-[^.]+\\d+-\\d+\\.{namespace}.svc.
9090
# 1. Metrics requests
9191
# 2. Schema maintenance
9292
# 3. DROP DNS CACHE
93-
# User with such credentials credentials can be specified in additional ClickHouse .xml config files,
93+
# User with such credentials can be specified in additional ClickHouse .xml config files,
9494
# located in `chUsersConfigsPath` folder
9595
chUsername: clickhouse_operator
9696
chPassword: clickhouse_operator_password

config/config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
# List of namespaces where clickhouse-operator watches for events.
88
# Concurrently running operators should watch on different namespaces
9-
# watchNamespaces:
9+
#watchNamespaces:
1010
# - dev
11+
# - test
1112
# - info
1213
# - onemore
1314

@@ -89,7 +90,7 @@ ChConfigNetworksHostRegexpTemplate: "chi-{chi}-[^.]+\\d+-\\d+\\.{namespace}.svc.
8990
# 1. Metrics requests
9091
# 2. Schema maintenance
9192
# 3. DROP DNS CACHE
92-
# User with such credentials credentials can be specified in additional ClickHouse .xml config files,
93+
# User with such credentials can be specified in additional ClickHouse .xml config files,
9394
# located in `chUsersConfigsPath` folder
9495
chUsername: clickhouse_operator
9596
chPassword: clickhouse_operator_password

deploy/dev/clickhouse-operator-install-dev.yaml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
# Possible Template Parameters:
2-
#
3-
# dev
4-
# altinity/clickhouse-operator:0.9.0
5-
#
6-
# Setup CustomResourceDefinition(s)
7-
# CustomResourceDefinition is namespace-less and must have unique name
81
apiVersion: apiextensions.k8s.io/v1beta1
92
kind: CustomResourceDefinition
103
metadata:
@@ -1288,7 +1281,7 @@ subjects:
12881281
# Possible Template Parameters:
12891282
#
12901283
# dev
1291-
# altinity/clickhouse-operator:0.9.0
1284+
# altinity/clickhouse-operator:0.9.1
12921285
# etc-clickhouse-operator-files
12931286
#
12941287
apiVersion: v1
@@ -1308,8 +1301,9 @@ data:
13081301
13091302
# List of namespaces where clickhouse-operator watches for events.
13101303
# Concurrently running operators should watch on different namespaces
1311-
# watchNamespaces:
1304+
#watchNamespaces:
13121305
# - dev
1306+
# - test
13131307
# - info
13141308
# - onemore
13151309
@@ -1391,7 +1385,7 @@ data:
13911385
# 1. Metrics requests
13921386
# 2. Schema maintenance
13931387
# 3. DROP DNS CACHE
1394-
# User with such credentials credentials can be specified in additional ClickHouse .xml config files,
1388+
# User with such credentials can be specified in additional ClickHouse .xml config files,
13951389
# located in `chUsersConfigsPath` folder
13961390
chUsername: clickhouse_operator
13971391
chPassword: clickhouse_operator_password
@@ -1401,7 +1395,7 @@ data:
14011395
# Possible Template Parameters:
14021396
#
14031397
# dev
1404-
# altinity/clickhouse-operator:0.9.0
1398+
# altinity/clickhouse-operator:0.9.1
14051399
# etc-clickhouse-operator-confd-files
14061400
#
14071401
apiVersion: v1
@@ -1416,7 +1410,7 @@ data:
14161410
# Possible Template Parameters:
14171411
#
14181412
# dev
1419-
# altinity/clickhouse-operator:0.9.0
1413+
# altinity/clickhouse-operator:0.9.1
14201414
# etc-clickhouse-operator-configd-files
14211415
#
14221416
apiVersion: v1
@@ -1462,7 +1456,7 @@ data:
14621456
# Possible Template Parameters:
14631457
#
14641458
# dev
1465-
# altinity/clickhouse-operator:0.9.0
1459+
# altinity/clickhouse-operator:0.9.1
14661460
# etc-clickhouse-operator-templatesd-files
14671461
#
14681462
apiVersion: v1
@@ -1561,7 +1555,7 @@ data:
15611555
# Possible Template Parameters:
15621556
#
15631557
# dev
1564-
# altinity/clickhouse-operator:0.9.0
1558+
# altinity/clickhouse-operator:0.9.1
15651559
# etc-clickhouse-operator-usersd-files
15661560
#
15671561
apiVersion: v1
@@ -1610,8 +1604,8 @@ data:
16101604
# Possible Template Parameters:
16111605
#
16121606
# dev
1613-
# altinity/clickhouse-operator:0.9.0
1614-
# altinity/metrics-exporter:0.9.0
1607+
# altinity/clickhouse-operator:0.9.1
1608+
# altinity/metrics-exporter:0.9.1
16151609
#
16161610
# Setup Deployment for clickhouse-operator
16171611
# Deployment would be created in kubectl-specified namespace
@@ -1651,7 +1645,7 @@ spec:
16511645
name: etc-clickhouse-operator-usersd-files
16521646
containers:
16531647
- name: clickhouse-operator
1654-
image: altinity/clickhouse-operator:0.9.0
1648+
image: altinity/clickhouse-operator:0.9.1
16551649
imagePullPolicy: Always
16561650
volumeMounts:
16571651
- name: etc-clickhouse-operator-folder
@@ -1716,7 +1710,7 @@ spec:
17161710
resource: limits.memory
17171711

17181712
- name: metrics-exporter
1719-
image: altinity/metrics-exporter:0.9.0
1713+
image: altinity/metrics-exporter:0.9.1
17201714
imagePullPolicy: Always
17211715
volumeMounts:
17221716
- name: etc-clickhouse-operator-folder

deploy/dev/clickhouse-operator-install-yaml-template-01-section-crd-01-chi.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
# Possible Template Parameters:
2-
#
3-
# ${OPERATOR_NAMESPACE}
4-
# ${OPERATOR_IMAGE}
5-
#
6-
# Setup CustomResourceDefinition(s)
7-
# CustomResourceDefinition is namespace-less and must have unique name
81
apiVersion: apiextensions.k8s.io/v1beta1
92
kind: CustomResourceDefinition
103
metadata:

deploy/operator/clickhouse-operator-install-crd.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
# Possible Template Parameters:
2-
#
3-
# -
4-
# altinity/clickhouse-operator:0.9.0
5-
#
6-
# Setup CustomResourceDefinition(s)
7-
# CustomResourceDefinition is namespace-less and must have unique name
81
apiVersion: apiextensions.k8s.io/v1beta1
92
kind: CustomResourceDefinition
103
metadata:

0 commit comments

Comments
 (0)