2018-02-09 10:11:33 +00:00
//
// DISCLAIMER
//
2021-04-26 08:30:06 +00:00
// Copyright 2020-2021 ArangoDB GmbH, Cologne, Germany
2018-02-09 10:11:33 +00:00
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
2021-04-26 08:30:06 +00:00
// Author Tomasz Mielech
2018-02-09 10:11:33 +00:00
//
package main
2018-02-09 14:27:40 +00:00
import (
2021-03-23 15:47:28 +00:00
"context"
2018-02-13 14:10:58 +00:00
goflag "flag"
2018-02-09 14:27:40 +00:00
"fmt"
"net"
2021-08-26 07:59:16 +00:00
"net/http"
2018-02-09 14:27:40 +00:00
"os"
"strconv"
2018-06-26 10:14:05 +00:00
"strings"
2018-02-09 14:27:40 +00:00
"time"
2021-12-10 12:04:48 +00:00
"github.com/arangodb/kube-arangodb/pkg/util/globals"
2021-08-26 07:59:16 +00:00
operatorHTTP "github.com/arangodb/kube-arangodb/pkg/util/http"
"github.com/gin-gonic/gin"
2021-07-08 10:11:39 +00:00
"github.com/arangodb/kube-arangodb/pkg/version"
2020-08-14 07:35:11 +00:00
"github.com/arangodb/kube-arangodb/pkg/operator/scope"
2020-07-21 07:32:02 +00:00
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
2020-06-08 11:30:32 +00:00
"github.com/rs/zerolog/log"
2020-03-23 20:07:41 +00:00
deploymentApi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/util"
2020-03-10 09:26:38 +00:00
utilsError "github.com/arangodb/kube-arangodb/pkg/util/errors"
2018-02-09 14:27:40 +00:00
"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
2018-02-13 14:10:58 +00:00
flag "github.com/spf13/pflag"
2019-10-18 07:55:40 +00:00
appsv1 "k8s.io/api/apps/v1"
2018-02-09 14:27:40 +00:00
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2018-06-26 08:42:13 +00:00
"k8s.io/apimachinery/pkg/runtime"
2018-02-09 14:27:40 +00:00
"k8s.io/client-go/kubernetes"
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/record"
2018-03-13 15:25:33 +00:00
"github.com/arangodb/kube-arangodb/pkg/client"
2019-10-18 07:55:40 +00:00
"github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/scheme"
2018-03-13 15:25:33 +00:00
"github.com/arangodb/kube-arangodb/pkg/logging"
"github.com/arangodb/kube-arangodb/pkg/operator"
2018-04-05 11:46:04 +00:00
"github.com/arangodb/kube-arangodb/pkg/server"
2018-03-13 15:25:33 +00:00
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
2018-04-03 08:58:05 +00:00
"github.com/arangodb/kube-arangodb/pkg/util/probe"
2018-03-13 15:25:33 +00:00
"github.com/arangodb/kube-arangodb/pkg/util/retry"
2019-05-07 08:10:23 +00:00
v1 "k8s.io/api/core/v1"
"k8s.io/klog"
2018-02-09 14:27:40 +00:00
)
2018-02-13 12:49:04 +00:00
const (
2020-03-23 20:07:41 +00:00
defaultServerHost = "0.0.0.0"
defaultServerPort = 8528
defaultLogLevel = "debug"
defaultAdminSecretName = "arangodb-operator-dashboard"
defaultAlpineImage = "alpine:3.7"
defaultMetricsExporterImage = "arangodb/arangodb-exporter:0.1.6"
defaultArangoImage = "arangodb/arangodb:latest"
UBIImageEnv util . EnvironmentVariable = "RELATED_IMAGE_UBI"
ArangoImageEnv util . EnvironmentVariable = "RELATED_IMAGE_DATABASE"
MetricsExporterImageEnv util . EnvironmentVariable = "RELATED_IMAGE_METRICSEXPORTER"
2018-02-13 12:49:04 +00:00
)
2018-02-09 14:27:40 +00:00
var (
maskAny = errors . WithStack
cmdMain = cobra . Command {
Use : "arangodb_operator" ,
Run : cmdMainRun ,
}
2020-11-23 07:58:40 +00:00
logLevels [ ] string
2018-04-05 11:46:04 +00:00
cliLog = logging . NewRootLogger ( )
logService logging . Service
serverOptions struct {
2018-07-06 10:44:43 +00:00
host string
port int
tlsSecretName string
adminSecretName string // Name of basic authentication secret containing the admin username+password of the dashboard
allowAnonymous bool // If set, anonymous access to dashboard is allowed
2018-02-09 14:27:40 +00:00
}
2018-03-19 10:09:20 +00:00
operatorOptions struct {
2018-05-18 09:54:53 +00:00
enableDeployment bool // Run deployment operator
enableDeploymentReplication bool // Run deployment-replication operator
enableStorage bool // Run local-storage operator
2019-09-27 11:04:23 +00:00
enableBackup bool // Run backup operator
2021-12-31 11:38:53 +00:00
enableApps bool // Run apps operator
2021-08-26 07:59:16 +00:00
versionOnly bool // Run only version endpoint, explicitly disabled with other
2020-03-23 20:07:41 +00:00
2021-12-10 10:52:00 +00:00
scalingIntegrationEnabled bool
2020-03-23 20:07:41 +00:00
alpineImage , metricsExporterImage , arangoImage string
2020-07-21 07:32:02 +00:00
singleMode bool
2020-07-22 12:24:22 +00:00
scope string
2018-03-30 13:40:11 +00:00
}
2021-12-10 12:04:48 +00:00
operatorKubernetesOptions struct {
maxBatchSize int64
}
2021-12-13 14:37:39 +00:00
operatorBackup struct {
concurrentUploads int
}
2021-12-10 12:04:48 +00:00
operatorTimeouts struct {
k8s time . Duration
arangoD time . Duration
reconciliation time . Duration
2021-04-26 08:30:06 +00:00
}
2018-03-30 13:40:11 +00:00
chaosOptions struct {
allowed bool
2018-03-19 10:09:20 +00:00
}
2018-05-18 09:54:53 +00:00
livenessProbe probe . LivenessProbe
deploymentProbe probe . ReadyProbe
deploymentReplicationProbe probe . ReadyProbe
storageProbe probe . ReadyProbe
2019-09-27 11:04:23 +00:00
backupProbe probe . ReadyProbe
2021-12-31 11:38:53 +00:00
appsProbe probe . ReadyProbe
2018-02-09 14:27:40 +00:00
)
func init ( ) {
2020-03-23 20:07:41 +00:00
2018-02-09 14:27:40 +00:00
f := cmdMain . Flags ( )
2018-04-05 11:46:04 +00:00
f . StringVar ( & serverOptions . host , "server.host" , defaultServerHost , "Host to listen on" )
f . IntVar ( & serverOptions . port , "server.port" , defaultServerPort , "Port to listen on" )
f . StringVar ( & serverOptions . tlsSecretName , "server.tls-secret-name" , "" , "Name of secret containing tls.crt & tls.key for HTTPS server (if empty, self-signed certificate is used)" )
2018-07-06 10:44:43 +00:00
f . StringVar ( & serverOptions . adminSecretName , "server.admin-secret-name" , defaultAdminSecretName , "Name of secret containing username + password for login to the dashboard" )
f . BoolVar ( & serverOptions . allowAnonymous , "server.allow-anonymous-access" , false , "Allow anonymous access to the dashboard" )
2021-07-04 17:06:07 +00:00
f . StringArrayVar ( & logLevels , "log.level" , [ ] string { defaultLogLevel } , fmt . Sprintf ( "Set log levels in format <level> or <logger>=<level>. Possible loggers: %s" , strings . Join ( logging . LoggerNames ( ) , ", " ) ) )
2018-03-19 10:09:20 +00:00
f . BoolVar ( & operatorOptions . enableDeployment , "operator.deployment" , false , "Enable to run the ArangoDeployment operator" )
2018-05-18 09:54:53 +00:00
f . BoolVar ( & operatorOptions . enableDeploymentReplication , "operator.deployment-replication" , false , "Enable to run the ArangoDeploymentReplication operator" )
2018-03-19 10:09:20 +00:00
f . BoolVar ( & operatorOptions . enableStorage , "operator.storage" , false , "Enable to run the ArangoLocalStorage operator" )
2019-09-27 11:04:23 +00:00
f . BoolVar ( & operatorOptions . enableBackup , "operator.backup" , false , "Enable to run the ArangoBackup operator" )
2021-12-31 11:38:53 +00:00
f . BoolVar ( & operatorOptions . enableApps , "operator.apps" , false , "Enable to run the ArangoApps operator" )
2021-08-26 07:59:16 +00:00
f . BoolVar ( & operatorOptions . versionOnly , "operator.version" , false , "Enable only version endpoint in Operator" )
2020-03-23 20:07:41 +00:00
f . StringVar ( & operatorOptions . alpineImage , "operator.alpine-image" , UBIImageEnv . GetOrDefault ( defaultAlpineImage ) , "Docker image used for alpine containers" )
2021-07-01 22:29:29 +00:00
f . MarkDeprecated ( "operator.alpine-image" , "Value is not used anymore" )
2020-03-23 20:07:41 +00:00
f . StringVar ( & operatorOptions . metricsExporterImage , "operator.metrics-exporter-image" , MetricsExporterImageEnv . GetOrDefault ( defaultMetricsExporterImage ) , "Docker image used for metrics containers by default" )
f . StringVar ( & operatorOptions . arangoImage , "operator.arango-image" , ArangoImageEnv . GetOrDefault ( defaultArangoImage ) , "Docker image used for arango by default" )
2018-03-30 13:40:11 +00:00
f . BoolVar ( & chaosOptions . allowed , "chaos.allowed" , false , "Set to allow chaos in deployments. Only activated when allowed and enabled in deployment" )
2020-07-21 07:32:02 +00:00
f . BoolVar ( & operatorOptions . singleMode , "mode.single" , false , "Enable single mode in Operator. WARNING: There should be only one replica of Operator, otherwise Operator can take unexpected actions" )
2020-08-14 07:35:11 +00:00
f . StringVar ( & operatorOptions . scope , "scope" , scope . DefaultScope . String ( ) , "Define scope on which Operator works. Legacy - pre 1.1.0 scope with limited cluster access" )
2021-12-10 12:04:48 +00:00
f . DurationVar ( & operatorTimeouts . k8s , "timeout.k8s" , globals . DefaultKubernetesTimeout , "The request timeout to the kubernetes" )
f . DurationVar ( & operatorTimeouts . arangoD , "timeout.arangod" , globals . DefaultArangoDTimeout , "The request timeout to the ArangoDB" )
f . DurationVar ( & operatorTimeouts . reconciliation , "timeout.reconciliation" , globals . DefaultReconciliationTimeout , "The reconciliation timeout to the ArangoDB CR" )
2021-12-13 15:07:02 +00:00
f . BoolVar ( & operatorOptions . scalingIntegrationEnabled , "internal.scaling-integration" , true , "Enable Scaling Integration" )
2021-12-10 12:04:48 +00:00
f . Int64Var ( & operatorKubernetesOptions . maxBatchSize , "kubernetes.max-batch-size" , globals . DefaultKubernetesRequestBatchSize , "Size of batch during objects read" )
2021-12-13 14:37:39 +00:00
f . IntVar ( & operatorBackup . concurrentUploads , "backup-concurrent-uploads" , globals . DefaultBackupConcurrentUploads , "Number of concurrent uploads per deployment" )
2020-07-21 07:32:02 +00:00
features . Init ( & cmdMain )
2018-02-09 14:27:40 +00:00
}
2018-02-09 10:11:33 +00:00
func main ( ) {
2018-02-13 14:10:58 +00:00
flag . CommandLine . AddGoFlagSet ( goflag . CommandLine )
2018-02-09 14:27:40 +00:00
cmdMain . Execute ( )
}
2018-03-05 09:00:23 +00:00
// Show usage
func cmdUsage ( cmd * cobra . Command , args [ ] string ) {
cmd . Usage ( )
}
2018-02-09 14:27:40 +00:00
// Run the operator
func cmdMainRun ( cmd * cobra . Command , args [ ] string ) {
2020-06-08 11:30:32 +00:00
// Set global logger
log . Logger = logging . NewRootLogger ( )
2018-06-26 10:14:05 +00:00
// Get environment
namespace := os . Getenv ( constants . EnvOperatorPodNamespace )
name := os . Getenv ( constants . EnvOperatorPodName )
ip := os . Getenv ( constants . EnvOperatorPodIP )
2020-03-23 20:07:41 +00:00
deploymentApi . DefaultImage = operatorOptions . arangoImage
2021-12-10 12:04:48 +00:00
globals . GetGlobalTimeouts ( ) . Kubernetes ( ) . Set ( operatorTimeouts . k8s )
globals . GetGlobalTimeouts ( ) . ArangoD ( ) . Set ( operatorTimeouts . arangoD )
globals . GetGlobalTimeouts ( ) . Reconciliation ( ) . Set ( operatorTimeouts . reconciliation )
globals . GetGlobals ( ) . Kubernetes ( ) . RequestBatchSize ( ) . Set ( operatorKubernetesOptions . maxBatchSize )
2021-12-13 14:37:39 +00:00
globals . GetGlobals ( ) . Backup ( ) . ConcurrentUploads ( ) . Set ( operatorBackup . concurrentUploads )
2020-03-23 20:07:41 +00:00
2018-06-26 10:14:05 +00:00
// Prepare log service
2018-02-09 14:27:40 +00:00
var err error
2020-11-23 07:58:40 +00:00
logService , err = logging . NewService ( defaultLogLevel , logLevels )
2018-02-09 14:27:40 +00:00
if err != nil {
cliLog . Fatal ( ) . Err ( err ) . Msg ( "Failed to initialize log service" )
}
2018-06-26 10:14:05 +00:00
logService . ConfigureRootLogger ( func ( log zerolog . Logger ) zerolog . Logger {
podNameParts := strings . Split ( name , "-" )
operatorID := podNameParts [ len ( podNameParts ) - 1 ]
cliLog = cliLog . With ( ) . Str ( "operator-id" , operatorID ) . Logger ( )
return log . With ( ) . Str ( "operator-id" , operatorID ) . Logger ( )
} )
2019-05-07 08:10:23 +00:00
2021-07-04 17:06:07 +00:00
klog . SetOutput ( logService . MustGetLogger ( logging . LoggerNameKLog ) )
2019-05-07 08:10:23 +00:00
klog . Info ( "nice to meet you" )
klog . Flush ( )
2018-02-09 14:27:40 +00:00
2018-03-19 10:09:20 +00:00
// Check operating mode
2021-12-31 11:38:53 +00:00
if ! operatorOptions . enableDeployment && ! operatorOptions . enableDeploymentReplication && ! operatorOptions . enableStorage && ! operatorOptions . enableBackup && ! operatorOptions . enableApps {
2021-08-26 07:59:16 +00:00
if ! operatorOptions . versionOnly {
2021-12-31 11:38:53 +00:00
cliLog . Fatal ( ) . Err ( err ) . Msg ( "Turn on --operator.deployment, --operator.deployment-replication, --operator.storage, --operator.backup, --operator.apps or any combination of these" )
2021-08-26 07:59:16 +00:00
}
} else if operatorOptions . versionOnly {
2021-12-31 11:38:53 +00:00
cliLog . Fatal ( ) . Err ( err ) . Msg ( "Options --operator.deployment, --operator.deployment-replication, --operator.storage, --operator.backup, --operator.apps cannot be enabled together with --operator.version" )
2018-03-19 10:09:20 +00:00
}
2018-02-09 16:21:06 +00:00
// Log version
2018-06-26 10:14:05 +00:00
cliLog . Info ( ) .
Str ( "pod-name" , name ) .
Str ( "pod-namespace" , namespace ) .
2021-07-08 10:11:39 +00:00
Msgf ( "Starting arangodb-operator (%s), version %s build %s" , version . GetVersionV1 ( ) . Edition . Title ( ) , version . GetVersionV1 ( ) . Version , version . GetVersionV1 ( ) . Build )
2018-02-09 16:21:06 +00:00
2018-06-26 10:14:05 +00:00
// Check environment
2021-08-26 07:59:16 +00:00
if ! operatorOptions . versionOnly {
if len ( namespace ) == 0 {
cliLog . Fatal ( ) . Msgf ( "%s environment variable missing" , constants . EnvOperatorPodNamespace )
}
if len ( name ) == 0 {
cliLog . Fatal ( ) . Msgf ( "%s environment variable missing" , constants . EnvOperatorPodName )
}
if len ( ip ) == 0 {
cliLog . Fatal ( ) . Msgf ( "%s environment variable missing" , constants . EnvOperatorPodIP )
}
// Get host name
id , err := os . Hostname ( )
if err != nil {
cliLog . Fatal ( ) . Err ( err ) . Msg ( "Failed to get hostname" )
}
// Create kubernetes client
kubecli , err := k8sutil . NewKubeClient ( )
if err != nil {
cliLog . Fatal ( ) . Err ( err ) . Msg ( "Failed to create Kubernetes client" )
}
secrets := kubecli . CoreV1 ( ) . Secrets ( namespace )
// Create operator
cfg , deps , err := newOperatorConfigAndDeps ( id + "-" + name , namespace , name )
if err != nil {
cliLog . Fatal ( ) . Err ( err ) . Msg ( "Failed to create operator config & deps" )
}
o , err := operator . NewOperator ( cfg , deps )
if err != nil {
cliLog . Fatal ( ) . Err ( err ) . Msg ( "Failed to create operator" )
}
listenAddr := net . JoinHostPort ( serverOptions . host , strconv . Itoa ( serverOptions . port ) )
if svr , err := server . NewServer ( kubecli . CoreV1 ( ) , server . Config {
Namespace : namespace ,
Address : listenAddr ,
TLSSecretName : serverOptions . tlsSecretName ,
TLSSecretNamespace : namespace ,
PodName : name ,
PodIP : ip ,
AdminSecretName : serverOptions . adminSecretName ,
AllowAnonymous : serverOptions . allowAnonymous ,
} , server . Dependencies {
Log : logService . MustGetLogger ( logging . LoggerNameServer ) ,
LivenessProbe : & livenessProbe ,
Deployment : server . OperatorDependency {
Enabled : cfg . EnableDeployment ,
Probe : & deploymentProbe ,
} ,
DeploymentReplication : server . OperatorDependency {
Enabled : cfg . EnableDeploymentReplication ,
Probe : & deploymentReplicationProbe ,
} ,
Storage : server . OperatorDependency {
Enabled : cfg . EnableStorage ,
Probe : & storageProbe ,
} ,
Backup : server . OperatorDependency {
Enabled : cfg . EnableBackup ,
Probe : & backupProbe ,
} ,
2021-12-31 11:38:53 +00:00
Apps : server . OperatorDependency {
Enabled : cfg . EnableApps ,
Probe : & appsProbe ,
} ,
2021-08-26 07:59:16 +00:00
Operators : o ,
Secrets : secrets ,
} ) ; err != nil {
cliLog . Fatal ( ) . Err ( err ) . Msg ( "Failed to create HTTP server" )
} else {
go utilsError . LogError ( cliLog , "error while starting service" , svr . Run )
}
// startChaos(context.Background(), cfg.KubeCli, cfg.Namespace, chaosLevel)
// Start operator
o . Run ( )
} else {
if err := startVersionProcess ( ) ; err != nil {
cliLog . Fatal ( ) . Err ( err ) . Msg ( "Failed to create HTTP server" )
}
2018-04-05 11:46:04 +00:00
}
2021-08-26 07:59:16 +00:00
}
2018-02-09 14:27:40 +00:00
2021-08-26 07:59:16 +00:00
func startVersionProcess ( ) error {
// Just expose version
listenAddr := net . JoinHostPort ( serverOptions . host , strconv . Itoa ( serverOptions . port ) )
cliLog . Info ( ) . Str ( "addr" , listenAddr ) . Msgf ( "Starting version endpoint" )
2018-02-09 14:27:40 +00:00
2021-08-26 07:59:16 +00:00
gin . SetMode ( gin . ReleaseMode )
r := gin . New ( )
r . Use ( gin . Recovery ( ) )
2018-04-05 11:46:04 +00:00
2021-08-26 07:59:16 +00:00
versionV1Responser , err := operatorHTTP . NewSimpleJSONResponse ( version . GetVersionV1 ( ) )
2018-07-02 10:40:32 +00:00
if err != nil {
2021-08-26 07:59:16 +00:00
return errors . WithStack ( err )
2018-07-02 10:40:32 +00:00
}
2021-08-26 07:59:16 +00:00
r . GET ( "/_api/version" , gin . WrapF ( versionV1Responser . ServeHTTP ) )
r . GET ( "/api/v1/version" , gin . WrapF ( versionV1Responser . ServeHTTP ) )
2018-07-02 10:40:32 +00:00
2021-08-26 07:59:16 +00:00
s := http . Server {
Addr : listenAddr ,
Handler : r ,
2018-04-05 11:46:04 +00:00
}
2018-02-09 14:27:40 +00:00
2021-08-26 07:59:16 +00:00
return s . ListenAndServe ( )
2018-02-09 14:27:40 +00:00
}
2018-02-27 10:50:28 +00:00
// newOperatorConfigAndDeps creates operator config & dependencies.
2018-03-19 10:09:20 +00:00
func newOperatorConfigAndDeps ( id , namespace , name string ) ( operator . Config , operator . Dependencies , error ) {
2018-02-09 14:27:40 +00:00
kubecli , err := k8sutil . NewKubeClient ( )
if err != nil {
2018-02-27 10:50:28 +00:00
return operator . Config { } , operator . Dependencies { } , maskAny ( err )
2018-02-09 14:27:40 +00:00
}
2020-07-30 06:35:24 +00:00
kubeMonCli , err := k8sutil . NewKubeMonitoringV1Client ( )
if err != nil {
return operator . Config { } , operator . Dependencies { } , maskAny ( err )
}
2018-05-11 12:58:49 +00:00
image , serviceAccount , err := getMyPodInfo ( kubecli , namespace , name )
2018-02-09 14:27:40 +00:00
if err != nil {
2018-02-27 10:50:28 +00:00
return operator . Config { } , operator . Dependencies { } , maskAny ( fmt . Errorf ( "Failed to get my pod's service account: %s" , err ) )
2018-02-09 14:27:40 +00:00
}
kubeExtCli , err := k8sutil . NewKubeExtClient ( )
if err != nil {
2018-02-27 10:50:28 +00:00
return operator . Config { } , operator . Dependencies { } , maskAny ( fmt . Errorf ( "Failed to create k8b api extensions client: %s" , err ) )
2018-02-09 14:27:40 +00:00
}
2020-04-06 11:20:33 +00:00
crCli , err := client . NewClient ( )
2018-02-09 14:27:40 +00:00
if err != nil {
2018-02-27 10:50:28 +00:00
return operator . Config { } , operator . Dependencies { } , maskAny ( fmt . Errorf ( "Failed to created versioned client: %s" , err ) )
2018-02-09 14:27:40 +00:00
}
2018-03-19 10:09:20 +00:00
eventRecorder := createRecorder ( cliLog , kubecli , name , namespace )
2018-02-09 14:27:40 +00:00
2020-08-14 07:35:11 +00:00
scope , ok := scope . AsScope ( operatorOptions . scope )
2020-07-22 12:24:22 +00:00
if ! ok {
return operator . Config { } , operator . Dependencies { } , maskAny ( fmt . Errorf ( "Scope %s is not known by Operator" , operatorOptions . scope ) )
}
2018-02-27 10:50:28 +00:00
cfg := operator . Config {
2018-05-18 09:54:53 +00:00
ID : id ,
Namespace : namespace ,
PodName : name ,
ServiceAccount : serviceAccount ,
2021-10-24 23:09:40 +00:00
OperatorImage : image ,
2018-05-18 09:54:53 +00:00
EnableDeployment : operatorOptions . enableDeployment ,
EnableDeploymentReplication : operatorOptions . enableDeploymentReplication ,
EnableStorage : operatorOptions . enableStorage ,
2019-09-27 11:04:23 +00:00
EnableBackup : operatorOptions . enableBackup ,
2021-12-31 11:38:53 +00:00
EnableApps : operatorOptions . enableApps ,
2018-05-18 09:54:53 +00:00
AllowChaos : chaosOptions . allowed ,
2021-12-10 10:52:00 +00:00
ScalingIntegrationEnabled : operatorOptions . scalingIntegrationEnabled ,
2020-03-23 20:07:41 +00:00
ArangoImage : operatorOptions . arangoImage ,
2020-07-21 07:32:02 +00:00
SingleMode : operatorOptions . singleMode ,
2020-07-22 12:24:22 +00:00
Scope : scope ,
2018-02-09 14:27:40 +00:00
}
2018-02-27 10:50:28 +00:00
deps := operator . Dependencies {
2018-05-18 09:54:53 +00:00
LogService : logService ,
KubeCli : kubecli ,
KubeExtCli : kubeExtCli ,
2020-07-30 06:35:24 +00:00
KubeMonitoringCli : kubeMonCli ,
2018-05-18 09:54:53 +00:00
CRCli : crCli ,
EventRecorder : eventRecorder ,
LivenessProbe : & livenessProbe ,
DeploymentProbe : & deploymentProbe ,
DeploymentReplicationProbe : & deploymentReplicationProbe ,
StorageProbe : & storageProbe ,
2019-09-27 11:04:23 +00:00
BackupProbe : & backupProbe ,
2021-12-31 11:38:53 +00:00
AppsProbe : & appsProbe ,
2018-02-09 14:27:40 +00:00
}
return cfg , deps , nil
}
2018-05-11 12:58:49 +00:00
// getMyPodInfo looks up the image & service account of the pod with given name in given namespace
// Returns image, serviceAccount, error.
func getMyPodInfo ( kubecli kubernetes . Interface , namespace , name string ) ( string , string , error ) {
var image , sa string
2018-02-09 14:27:40 +00:00
op := func ( ) error {
2021-03-23 15:47:28 +00:00
pod , err := kubecli . CoreV1 ( ) . Pods ( namespace ) . Get ( context . Background ( ) , name , metav1 . GetOptions { } )
2018-02-09 14:27:40 +00:00
if err != nil {
cliLog . Error ( ) .
Err ( err ) .
Str ( "name" , name ) .
Msg ( "Failed to get operator pod" )
return maskAny ( err )
}
sa = pod . Spec . ServiceAccountName
2018-11-15 09:22:10 +00:00
image = k8sutil . GetArangoDBImageIDFromPod ( pod )
2018-05-11 12:58:49 +00:00
if image == "" {
// Fallback in case we don't know the id.
image = pod . Spec . Containers [ 0 ] . Image
}
2018-02-09 14:27:40 +00:00
return nil
}
if err := retry . Retry ( op , time . Minute * 5 ) ; err != nil {
2018-05-11 12:58:49 +00:00
return "" , "" , maskAny ( err )
2018-02-09 14:27:40 +00:00
}
2018-05-11 12:58:49 +00:00
return image , sa , nil
2018-02-09 14:27:40 +00:00
}
func createRecorder ( log zerolog . Logger , kubecli kubernetes . Interface , name , namespace string ) record . EventRecorder {
eventBroadcaster := record . NewBroadcaster ( )
eventBroadcaster . StartLogging ( func ( format string , args ... interface { } ) {
log . Info ( ) . Msgf ( format , args ... )
} )
2019-05-07 08:10:23 +00:00
eventBroadcaster . StartRecordingToSink ( & v1core . EventSinkImpl { Interface : v1core . New ( kubecli . CoreV1 ( ) . RESTClient ( ) ) . Events ( namespace ) } )
2018-06-26 08:42:13 +00:00
combinedScheme := runtime . NewScheme ( )
scheme . AddToScheme ( combinedScheme )
v1 . AddToScheme ( combinedScheme )
2019-10-18 07:55:40 +00:00
appsv1 . AddToScheme ( combinedScheme )
2018-06-26 08:42:13 +00:00
return eventBroadcaster . NewRecorder ( combinedScheme , v1 . EventSource { Component : name } )
2018-02-09 10:11:33 +00:00
}