-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1323 from Altinity/0.23.0
0.23.0 to master
- Loading branch information
Showing
305 changed files
with
22,004 additions
and
7,361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.