Skip to content

Commit

Permalink
Merge pull request #1323 from Altinity/0.23.0
Browse files Browse the repository at this point in the history
0.23.0 to master
  • Loading branch information
sunsingerus authored Feb 2, 2024
2 parents b0dc549 + 6f783bf commit c50d2d5
Show file tree
Hide file tree
Showing 305 changed files with 22,004 additions and 7,361 deletions.
4 changes: 2 additions & 2 deletions cmd/metrics_exporter/app/metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// Prometheus exporter defaults
const (
defaultMetricsEndpoint = ":8888"
defaultChiListEP = ":8888"
defaultChiListEndPoint = ":8888"

metricsPath = "/metrics"
chiListPath = "/chi"
Expand Down Expand Up @@ -65,7 +65,7 @@ func init() {
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.StringVar(&chiListEP, "chi-list-endpoint", defaultChiListEndPoint, "The CHI list endpoint.")
flag.Parse()
}

Expand Down
169 changes: 0 additions & 169 deletions cmd/operator/app/clickhouse_operator.go

This file was deleted.

109 changes: 109 additions & 0 deletions cmd/operator/app/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright 2019 Altinity Ltd and/or its affiliates. All rights reserved.
//
// 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 app

import (
"context"
"flag"
"fmt"
log "github.com/altinity/clickhouse-operator/pkg/announcer"
"github.com/altinity/clickhouse-operator/pkg/version"
"os"
"os/signal"
"sync"
"syscall"
)

// CLI parameter variables
var (
// versionRequest defines request for clickhouse-operator version report. Operator should exit after version printed
versionRequest bool

// debugRequest defines request for clickhouse-operator debug run
debugRequest bool

// 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
)

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(&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.")
}

// Run is an entry point of the application
func Run() {
flag.Parse()

if versionRequest {
fmt.Printf("%s\n", version.Version)
os.Exit(0)
}

log.S().P()
defer log.E().P()

log.F().Info("Starting clickhouse-operator. Version:%s GitSHA:%s BuiltAt:%s", version.Version, version.GitSHA, version.BuiltAt)

// Create main context with cancel
ctx, cancelFunc := context.WithCancel(context.Background())

// Setup notification signals with cancel
setupNotification(cancelFunc)

initClickHouse(ctx)
initClickHouseReconcilerMetricsExporter(ctx)
initKeeper(ctx)

var wg sync.WaitGroup
wg.Add(3)

go func() {
defer wg.Done()
runClickHouse(ctx)
}()
go func() {
defer wg.Done()
runClickHouseReconcilerMetricsExporter(ctx)
}()
go func() {
defer wg.Done()
runKeeper(ctx)
}()

// Wait for completion
<-ctx.Done()
wg.Wait()
}

// setupNotification sets up OS signals
func setupNotification(cancel context.CancelFunc) {
stopChan := make(chan os.Signal, 2)
signal.Notify(stopChan, os.Interrupt, syscall.SIGTERM)
go func() {
<-stopChan
cancel()
<-stopChan
os.Exit(1)
}()
}
100 changes: 100 additions & 0 deletions cmd/operator/app/thread_chi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2019 Altinity Ltd and/or its affiliates. All rights reserved.
//
// 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 app

import (
"context"
"time"

kubeinformers "k8s.io/client-go/informers"

log "github.com/altinity/clickhouse-operator/pkg/announcer"
"github.com/altinity/clickhouse-operator/pkg/chop"
chopinformers "github.com/altinity/clickhouse-operator/pkg/client/informers/externalversions"
"github.com/altinity/clickhouse-operator/pkg/controller/chi"
)

// Prometheus exporter defaults
const (
defaultInformerFactoryResyncPeriod = 60 * time.Second
defaultInformerFactoryResyncDebugPeriod = 60 * time.Second
)

// CLI parameter variables
var (
// Setting to 0 disables resync
// Informer fires Update() func to periodically verify current state
kubeInformerFactoryResyncPeriod = defaultInformerFactoryResyncPeriod
chopInformerFactoryResyncPeriod = defaultInformerFactoryResyncPeriod
)

func init() {
}

var chiController *chi.Controller

// initClickHouse is an entry point of the application
func initClickHouse(ctx context.Context) {
log.S().P()
defer log.E().P()

if debugRequest {
kubeInformerFactoryResyncPeriod = defaultInformerFactoryResyncDebugPeriod
chopInformerFactoryResyncPeriod = defaultInformerFactoryResyncDebugPeriod
}

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

// Create operator instance
chop.New(kubeClient, chopClient, chopConfigFile)
log.V(1).F().Info("Config parsed:")
log.Info(chop.Config().String(true))

// Create Informers
kubeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(
kubeClient,
kubeInformerFactoryResyncPeriod,
kubeinformers.WithNamespace(chop.Config().GetInformerNamespace()),
)
chopInformerFactory := chopinformers.NewSharedInformerFactoryWithOptions(
chopClient,
chopInformerFactoryResyncPeriod,
chopinformers.WithNamespace(chop.Config().GetInformerNamespace()),
)

// Create Controller
chiController = chi.NewController(
chopClient,
extClient,
kubeClient,
chopInformerFactory,
kubeInformerFactory,
)

// Start Informers
kubeInformerFactory.Start(ctx.Done())
chopInformerFactory.Start(ctx.Done())
}

// runClickHouse is an entry point of the application
func runClickHouse(ctx context.Context) {
log.S().P()
defer log.E().P()

// Start main CHI controller
log.V(1).F().Info("Starting CHI controller")
chiController.Run(ctx)
}
Loading

0 comments on commit c50d2d5

Please sign in to comment.