diff --git a/CHANGELOG.md b/CHANGELOG.md index e5a1994ba..784798ced 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Add Recovery during PlanBuild operation - Fix Exporter in Deployments without authentication - Allow to disable ClusterScalingIntegration and add proper Scheduled label to pods +- Add additional timeout parameters and kubernetes batch size ## [1.2.5](https://github.com/arangodb/kube-arangodb/tree/1.2.5) (2021-10-25) - Split & Unify Lifecycle management functionality diff --git a/Makefile b/Makefile index 289e2b70b..10e7f7437 100644 --- a/Makefile +++ b/Makefile @@ -367,10 +367,7 @@ run-unit-tests: $(SOURCES) $(REPOPATH)/pkg/apis/storage/... \ $(REPOPATH)/pkg/deployment/... \ $(REPOPATH)/pkg/storage \ - $(REPOPATH)/pkg/util/k8sutil \ - $(REPOPATH)/pkg/util/k8sutil/test \ - $(REPOPATH)/pkg/util/probe \ - $(REPOPATH)/pkg/util/validation \ + $(REPOPATH)/pkg/util/... \ $(REPOPATH)/pkg/backup/... # Release building diff --git a/admin.go b/admin.go index 51090fc4c..03ed54a2c 100644 --- a/admin.go +++ b/admin.go @@ -33,6 +33,8 @@ import ( "strconv" "syscall" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/pkg/errors" "github.com/spf13/cobra" v1 "k8s.io/api/core/v1" @@ -288,7 +290,7 @@ func createClient(endpoints []string, certCA *x509.CertPool, auth connection.Aut // getJWTTokenFromSecrets returns token from the secret. func getJWTTokenFromSecrets(ctx context.Context, secrets secret.ReadInterface, name string) (connection.Authentication, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() token, err := k8sutil.GetTokenSecret(ctxChild, secrets, name) @@ -306,7 +308,7 @@ func getJWTTokenFromSecrets(ctx context.Context, secrets secret.ReadInterface, n // getCACertificate returns CA certificate from the secret. func getCACertificate(ctx context.Context, secrets secret.ReadInterface, name string) (*x509.CertPool, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() s, err := secrets.Get(ctxChild, name, metav1.GetOptions{}) @@ -331,7 +333,7 @@ func getDeployment(ctx context.Context, namespace, deplName string) (v12.ArangoD return v12.ArangoDeployment{}, errors.WithMessage(err, "failed to create Arango extension client") } - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() deployments, err := extCli.DatabaseV1().ArangoDeployments(namespace).List(ctxChild, metav1.ListOptions{}) diff --git a/main.go b/main.go index b8a763fdf..8a444a55b 100644 --- a/main.go +++ b/main.go @@ -34,13 +34,13 @@ import ( "strings" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + operatorHTTP "github.com/arangodb/kube-arangodb/pkg/util/http" "github.com/gin-gonic/gin" "github.com/arangodb/kube-arangodb/pkg/version" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" - "github.com/arangodb/kube-arangodb/pkg/operator/scope" "github.com/arangodb/kube-arangodb/pkg/deployment/features" @@ -123,9 +123,13 @@ var ( singleMode bool scope string } - timeouts struct { - k8s time.Duration - arangoD time.Duration + operatorKubernetesOptions struct { + maxBatchSize int64 + } + operatorTimeouts struct { + k8s time.Duration + arangoD time.Duration + reconciliation time.Duration } chaosOptions struct { allowed bool @@ -158,9 +162,11 @@ func init() { f.BoolVar(&chaosOptions.allowed, "chaos.allowed", false, "Set to allow chaos in deployments. Only activated when allowed and enabled in deployment") 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") f.StringVar(&operatorOptions.scope, "scope", scope.DefaultScope.String(), "Define scope on which Operator works. Legacy - pre 1.1.0 scope with limited cluster access") - f.DurationVar(&timeouts.k8s, "timeout.k8s", time.Second*3, "The request timeout to the kubernetes") - f.DurationVar(&timeouts.arangoD, "timeout.arangod", time.Second*10, "The request timeout to the ArangoDB") - f.BoolVar(&operatorOptions.scalingIntegrationEnabled, "scaling-integration", false, "Enable Scaling Integration") + 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") + f.BoolVar(&operatorOptions.scalingIntegrationEnabled, "internal.scaling-integration", false, "Enable Scaling Integration") + f.Int64Var(&operatorKubernetesOptions.maxBatchSize, "kubernetes.max-batch-size", globals.DefaultKubernetesRequestBatchSize, "Size of batch during objects read") features.Init(&cmdMain) } @@ -185,8 +191,11 @@ func cmdMainRun(cmd *cobra.Command, args []string) { ip := os.Getenv(constants.EnvOperatorPodIP) deploymentApi.DefaultImage = operatorOptions.arangoImage - k8sutil.SetRequestTimeout(timeouts.k8s) - arangod.SetRequestTimeout(timeouts.arangoD) + + 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) // Prepare log service var err error diff --git a/pkg/backup/handlers/arango/backup/arango_client_impl.go b/pkg/backup/handlers/arango/backup/arango_client_impl.go index 9e7d341d2..4836e241d 100644 --- a/pkg/backup/handlers/arango/backup/arango_client_impl.go +++ b/pkg/backup/handlers/arango/backup/arango_client_impl.go @@ -29,6 +29,8 @@ import ( "fmt" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/go-driver" @@ -130,7 +132,7 @@ func (ac *arangoClientBackupImpl) Get(backupID driver.BackupID) (driver.BackupMe } func (ac *arangoClientBackupImpl) getCredentialsFromSecret(ctx context.Context, secretName string) (interface{}, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() token, err := k8sutil.GetTokenSecret(ctxChild, ac.kubecli.CoreV1().Secrets(ac.backup.Namespace), secretName) if err != nil { diff --git a/pkg/deployment/access_package.go b/pkg/deployment/access_package.go index f67987f26..3f981c8fe 100644 --- a/pkg/deployment/access_package.go +++ b/pkg/deployment/access_package.go @@ -28,6 +28,8 @@ import ( "strings" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" certificates "github.com/arangodb-helper/go-certificates" @@ -67,7 +69,7 @@ func (d *Deployment) createAccessPackages(ctx context.Context) error { } // Remove all access packages that we did build, but are no longer needed - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() secretList, err := secrets.List(ctxChild, metav1.ListOptions{}) if err != nil { @@ -80,7 +82,7 @@ func (d *Deployment) createAccessPackages(ctx context.Context) error { // Secret is an access package if _, wanted := apNameMap[secret.GetName()]; !wanted { // We found an obsolete access package secret. Remove it. - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return secrets.Delete(ctxChild, secret.GetName(), metav1.DeleteOptions{ Preconditions: &metav1.Preconditions{UID: &secret.UID}, }) @@ -110,7 +112,7 @@ func (d *Deployment) ensureAccessPackage(ctx context.Context, apSecretName strin secrets := d.deps.KubeCli.CoreV1().Secrets(ns) spec := d.apiObject.Spec - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := secrets.Get(ctxChild, apSecretName, metav1.GetOptions{}) return err }) @@ -124,7 +126,7 @@ func (d *Deployment) ensureAccessPackage(ctx context.Context, apSecretName strin // Fetch client authentication CA clientAuthSecretName := spec.Sync.Authentication.GetClientCASecretName() - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() clientAuthCert, clientAuthKey, _, err := k8sutil.GetCASecret(ctxChild, secrets, clientAuthSecretName, nil) if err != nil { @@ -220,7 +222,7 @@ func (d *Deployment) ensureAccessPackage(ctx context.Context, apSecretName strin } // Attach secret to owner secret.SetOwnerReferences(append(secret.GetOwnerReferences(), d.apiObject.AsOwner())) - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := secrets.Create(ctxChild, secret, metav1.CreateOptions{}) return err }) diff --git a/pkg/deployment/cleanup.go b/pkg/deployment/cleanup.go index f0966cf02..be65b8e3b 100644 --- a/pkg/deployment/cleanup.go +++ b/pkg/deployment/cleanup.go @@ -26,6 +26,8 @@ package deployment import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -45,7 +47,7 @@ func (d *Deployment) removePodFinalizers(ctx context.Context, cachedStatus inspe return err } - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() if err := d.PodsModInterface().Delete(ctxChild, pod.GetName(), meta.DeleteOptions{ diff --git a/pkg/deployment/cluster_scaling_integration.go b/pkg/deployment/cluster_scaling_integration.go index 748591f5f..051b336a4 100644 --- a/pkg/deployment/cluster_scaling_integration.go +++ b/pkg/deployment/cluster_scaling_integration.go @@ -28,6 +28,8 @@ import ( "sync" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/rs/zerolog" @@ -152,14 +154,14 @@ func (ci *clusterScalingIntegration) ListenForClusterEvents(stopCh <-chan struct func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectSuccess bool) error { log := ci.log - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := ci.depl.clientCache.GetDatabase(ctxChild) if err != nil { return errors.WithStack(err) } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() req, err := arangod.GetNumberOfServers(ctxChild, c.Connection()) if err != nil { @@ -204,7 +206,7 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS } // Let's update the spec apiObject := ci.depl.apiObject - ctxChild, cancel = context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() current, err := ci.depl.deps.DatabaseCRCli.DatabaseV1().ArangoDeployments(apiObject.Namespace).Get(ctxChild, apiObject.Name, metav1.GetOptions{}) if err != nil { diff --git a/pkg/deployment/context_impl.go b/pkg/deployment/context_impl.go index ea52ff6f5..a79691529 100644 --- a/pkg/deployment/context_impl.go +++ b/pkg/deployment/context_impl.go @@ -31,6 +31,8 @@ import ( "strconv" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/deployment/patch" "k8s.io/apimachinery/pkg/types" @@ -86,7 +88,7 @@ var _ resources.Context = &Deployment{} // GetBackup receives information about a backup resource func (d *Deployment) GetBackup(ctx context.Context, backup string) (*backupApi.ArangoBackup, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() return d.deps.DatabaseCRCli.BackupV1().ArangoBackups(d.Namespace()).Get(ctxChild, backup, meta.GetOptions{}) @@ -392,7 +394,7 @@ func (d *Deployment) GetPod(ctx context.Context, podName string) (*core.Pod, err // of the deployment. If the pod does not exist, the error is ignored. func (d *Deployment) DeletePod(ctx context.Context, podName string) error { log := d.deps.Log - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return d.PodsModInterface().Delete(ctxChild, podName, meta.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { @@ -409,7 +411,7 @@ func (d *Deployment) CleanupPod(ctx context.Context, p *core.Pod) error { podName := p.GetName() options := meta.NewDeleteOptions(0) options.Preconditions = meta.NewUIDPreconditions(string(p.GetUID())) - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return d.PodsModInterface().Delete(ctxChild, podName, *options) }) if err != nil && !k8sutil.IsNotFound(err) { @@ -424,7 +426,7 @@ func (d *Deployment) CleanupPod(ctx context.Context, p *core.Pod) error { func (d *Deployment) RemovePodFinalizers(ctx context.Context, podName string) error { log := d.deps.Log - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() p, err := d.GetCachedStatus().PodReadInterface().Get(ctxChild, podName, meta.GetOptions{}) if err != nil { @@ -445,7 +447,7 @@ func (d *Deployment) RemovePodFinalizers(ctx context.Context, podName string) er // of the deployment. If the pvc does not exist, the error is ignored. func (d *Deployment) DeletePvc(ctx context.Context, pvcName string) error { log := d.deps.Log - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return d.PersistentVolumeClaimsModInterface().Delete(ctxChild, pvcName, meta.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { @@ -458,7 +460,7 @@ func (d *Deployment) DeletePvc(ctx context.Context, pvcName string) error { // UpdatePvc updated a persistent volume claim in the namespace // of the deployment. If the pvc does not exist, the error is ignored. func (d *Deployment) UpdatePvc(ctx context.Context, pvc *core.PersistentVolumeClaim) error { - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := d.PersistentVolumeClaimsModInterface().Update(ctxChild, pvc, meta.UpdateOptions{}) return err }) @@ -488,7 +490,7 @@ func (d *Deployment) GetOwnedPVCs() ([]core.PersistentVolumeClaim, error) { // GetPvc gets a PVC by the given name, in the samespace of the deployment. func (d *Deployment) GetPvc(ctx context.Context, pvcName string) (*core.PersistentVolumeClaim, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() pvc, err := d.GetCachedStatus().PersistentVolumeClaimReadInterface().Get(ctxChild, pvcName, meta.GetOptions{}) @@ -514,7 +516,7 @@ func (d *Deployment) GetTLSKeyfile(group api.ServerGroup, member api.MemberStatu // If the secret does not exist, the error is ignored. func (d *Deployment) DeleteTLSKeyfile(ctx context.Context, group api.ServerGroup, member api.MemberStatus) error { secretName := k8sutil.CreateTLSKeyfileSecretName(d.GetName(), group.AsRole(), member.ID) - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return d.SecretsModInterface().Delete(ctxChild, secretName, meta.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { @@ -724,7 +726,7 @@ func (d *Deployment) ApplyPatchOnPod(ctx context.Context, pod *core.Pod, p ...pa c := d.deps.KubeCli.CoreV1().Pods(pod.GetNamespace()) - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() _, err = c.Patch(ctxChild, pod.GetName(), types.JSONPatchType, data, meta.PatchOptions{}) if err != nil { diff --git a/pkg/deployment/deployment.go b/pkg/deployment/deployment.go index be8d32756..9ead235c3 100644 --- a/pkg/deployment/deployment.go +++ b/pkg/deployment/deployment.go @@ -30,6 +30,8 @@ import ( "sync/atomic" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/deployment/agency" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" @@ -165,7 +167,7 @@ func (d *Deployment) SetAgencyMaintenanceMode(ctx context.Context, enabled bool) return nil } - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() client, err := d.GetDatabaseClient(ctxChild) if err != nil { @@ -376,7 +378,7 @@ func (d *Deployment) handleArangoDeploymentUpdatedEvent(ctx context.Context) err log := d.deps.Log.With().Str("deployment", d.apiObject.GetName()).Logger() // Get the most recent version of the deployment from the API server - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() current, err := d.deps.DatabaseCRCli.DatabaseV1().ArangoDeployments(d.apiObject.GetNamespace()).Get(ctxChild, d.apiObject.GetName(), metav1.GetOptions{}) if err != nil { @@ -474,7 +476,7 @@ func (d *Deployment) updateCRStatus(ctx context.Context, force ...bool) error { } var newAPIObject *api.ArangoDeployment - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { var err error newAPIObject, err = depls.Update(ctxChild, update, metav1.UpdateOptions{}) @@ -490,7 +492,7 @@ func (d *Deployment) updateCRStatus(ctx context.Context, force ...bool) error { // Reload api object and try again var current *api.ArangoDeployment - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { var err error current, err = depls.Get(ctxChild, update.GetName(), metav1.GetOptions{}) @@ -530,7 +532,7 @@ func (d *Deployment) updateCRSpec(ctx context.Context, newSpec api.DeploymentSpe update.Status = d.status.last ns := d.apiObject.GetNamespace() var newAPIObject *api.ArangoDeployment - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { var err error newAPIObject, err = d.deps.DatabaseCRCli.DatabaseV1().ArangoDeployments(ns).Update(ctxChild, update, metav1.UpdateOptions{}) @@ -546,7 +548,7 @@ func (d *Deployment) updateCRSpec(ctx context.Context, newSpec api.DeploymentSpe // Reload api object and try again var current *api.ArangoDeployment - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { var err error current, err = d.deps.DatabaseCRCli.DatabaseV1().ArangoDeployments(ns).Get(ctxChild, update.GetName(), metav1.GetOptions{}) @@ -605,14 +607,14 @@ func (d *Deployment) lookForServiceMonitorCRD() { // SetNumberOfServers adjust number of DBservers and coordinators in arangod func (d *Deployment) SetNumberOfServers(ctx context.Context, noCoordinators, noDBServers *int) error { - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := d.clientCache.GetDatabase(ctxChild) if err != nil { return errors.WithStack(err) } - err = arangod.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().ArangoD().RunWithTimeout(ctx, func(ctxChild context.Context) error { return arangod.SetNumberOfServers(ctxChild, c.Connection(), noCoordinators, noDBServers) }) @@ -636,7 +638,7 @@ func (d *Deployment) ApplyPatch(ctx context.Context, p ...patch.Item) error { c := d.deps.DatabaseCRCli.DatabaseV1().ArangoDeployments(d.apiObject.GetNamespace()) - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() depl, err := c.Patch(ctxChild, d.apiObject.GetName(), types.JSONPatchType, data, metav1.PatchOptions{}) if err != nil { diff --git a/pkg/deployment/deployment_core_test.go b/pkg/deployment/deployment_core_test.go index b704eabe8..056229f7d 100644 --- a/pkg/deployment/deployment_core_test.go +++ b/pkg/deployment/deployment_core_test.go @@ -1309,7 +1309,7 @@ func testArangodbInternalExporterContainer(secure, auth bool, resources core.Res c := core.Container{ Name: k8sutil.ExporterContainerName, Image: testImage, - Command: createTestInternalExporterCommand(secure, port), + Command: createTestInternalExporterCommand(secure, auth, port), Ports: []core.ContainerPort{ { Name: string(api.MetricsModeExporter), @@ -1339,7 +1339,7 @@ func testArangodbInternalExporterContainer(secure, auth bool, resources core.Res return c } -func createTestInternalExporterCommand(secure bool, port int32) []string { +func createTestInternalExporterCommand(secure, auth bool, port int32) []string { binaryPath, err := os.Executable() if err != nil { return []string{} @@ -1353,7 +1353,9 @@ func createTestInternalExporterCommand(secure bool, port int32) []string { args = append(args, "--arangodb.endpoint=http://localhost:8529/_admin/metrics") } - args = append(args, "--arangodb.jwt-file=/secrets/exporter/jwt/token") + if auth { + args = append(args, "--arangodb.jwt-file=/secrets/exporter/jwt/token") + } if port != k8sutil.ArangoExporterPort { args = append(args, fmt.Sprintf("--server.address=:%d", port)) diff --git a/pkg/deployment/deployment_finalizers.go b/pkg/deployment/deployment_finalizers.go index 8229e0beb..0932ac1a8 100644 --- a/pkg/deployment/deployment_finalizers.go +++ b/pkg/deployment/deployment_finalizers.go @@ -26,6 +26,8 @@ package deployment import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -57,7 +59,7 @@ func (d *Deployment) runDeploymentFinalizers(ctx context.Context, cachedStatus i var removalList []string depls := d.deps.DatabaseCRCli.DatabaseV1().ArangoDeployments(d.GetNamespace()) - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() updated, err := depls.Get(ctxChild, d.apiObject.GetName(), metav1.GetOptions{}) if err != nil { @@ -102,7 +104,7 @@ func removeDeploymentFinalizers(ctx context.Context, log zerolog.Logger, cli ver depl *api.ArangoDeployment, finalizers []string) error { depls := cli.DatabaseV1().ArangoDeployments(depl.GetNamespace()) getFunc := func() (metav1.Object, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() result, err := depls.Get(ctxChild, depl.GetName(), metav1.GetOptions{}) @@ -113,7 +115,7 @@ func removeDeploymentFinalizers(ctx context.Context, log zerolog.Logger, cli ver } updateFunc := func(updated metav1.Object) error { updatedDepl := updated.(*api.ArangoDeployment) - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() result, err := depls.Update(ctxChild, updatedDepl, metav1.UpdateOptions{}) diff --git a/pkg/deployment/deployment_inspector.go b/pkg/deployment/deployment_inspector.go index 150ae5f9e..5ff3d6988 100644 --- a/pkg/deployment/deployment_inspector.go +++ b/pkg/deployment/deployment_inspector.go @@ -27,6 +27,8 @@ import ( "context" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/deployment/features" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" @@ -48,27 +50,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -const ( - timeoutReconciliationPerNode = time.Second * 20 -) - var ( inspectDeploymentDurationGauges = metrics.MustRegisterGaugeVec(metricsComponent, "inspect_deployment_duration", "Amount of time taken by a single inspection of a deployment (in sec)", metrics.DeploymentName) ) -// getReconciliationTimeout gets timeout for the reconciliation loop. -// The whole reconciliation loop timeout depends on the number of nodes but not less then one minute. -func (d *Deployment) getReconciliationTimeout() time.Duration { - if nodes, ok := d.GetCachedStatus().GetNodes(); ok { - if timeout := timeoutReconciliationPerNode * time.Duration(len(nodes.Nodes())); timeout > time.Minute { - return timeout - } - } - - // The minimum timeout for the reconciliation loop. - return time.Minute -} - // inspectDeployment inspects the entire deployment, creates // a plan to update if needed and inspects underlying resources. // This function should be called when: @@ -80,9 +65,7 @@ func (d *Deployment) inspectDeployment(lastInterval util.Interval) util.Interval log := d.deps.Log start := time.Now() - timeout := d.getReconciliationTimeout() - - ctxReconciliation, cancelReconciliation := context.WithTimeout(context.Background(), timeout) + ctxReconciliation, cancelReconciliation := globals.GetGlobalTimeouts().Reconciliation().WithTimeout(context.Background()) defer cancelReconciliation() defer func() { d.deps.Log.Info().Msgf("Inspect loop took %s", time.Since(start)) @@ -102,7 +85,7 @@ func (d *Deployment) inspectDeployment(lastInterval util.Interval) util.Interval // Check deployment still exists var updated *api.ArangoDeployment - err = k8sutil.RunWithTimeout(ctxReconciliation, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctxReconciliation, func(ctxChild context.Context) error { var err error updated, err = d.deps.DatabaseCRCli.DatabaseV1().ArangoDeployments(d.GetNamespace()).Get(ctxChild, deploymentName, metav1.GetOptions{}) return err diff --git a/pkg/deployment/images.go b/pkg/deployment/images.go index baf96094a..ef96405c6 100644 --- a/pkg/deployment/images.go +++ b/pkg/deployment/images.go @@ -27,6 +27,8 @@ import ( "strings" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/rs/zerolog" core "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -134,7 +136,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac Logger() // Check if pod exists - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() pod, err := ib.Context.GetCachedStatus().PodReadInterface().Get(ctxChild, podName, metav1.GetOptions{}) if err == nil { @@ -142,7 +144,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac if k8sutil.IsPodFailed(pod) { // Wait some time before deleting the pod if time.Now().After(pod.GetCreationTimestamp().Add(30 * time.Second)) { - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return ib.Context.PodsModInterface().Delete(ctxChild, podName, metav1.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { @@ -173,7 +175,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac log.Warn().Err(err).Msg("Failed to create Image ID Pod client") return true, nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() v, err := client.Version(ctxChild) if err != nil { @@ -184,7 +186,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac enterprise := strings.ToLower(v.License) == "enterprise" // We have all the info we need now, kill the pod and store the image info. - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return ib.Context.PodsModInterface().Delete(ctxChild, podName, metav1.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { @@ -231,7 +233,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac return true, errors.WithStack(err) } - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, _, err := resources.CreateArangoPod(ctxChild, ib.Context.PodsModInterface(), ib.APIObject, ib.Spec, api.ServerGroupImageDiscovery, pod) return err }) diff --git a/pkg/deployment/pod/encryption.go b/pkg/deployment/pod/encryption.go index bf6a9b586..1cbc24d26 100644 --- a/pkg/deployment/pod/encryption.go +++ b/pkg/deployment/pod/encryption.go @@ -29,6 +29,8 @@ import ( "fmt" "path/filepath" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces" @@ -71,7 +73,7 @@ func GroupEncryptionSupported(mode api.DeploymentMode, group api.ServerGroup) bo } func GetEncryptionKey(ctx context.Context, secrets secret.ReadInterface, name string) (string, []byte, bool, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() keyfile, err := secrets.Get(ctxChild, name, meta.GetOptions{}) diff --git a/pkg/deployment/reconcile/action_backup_restore.go b/pkg/deployment/reconcile/action_backup_restore.go index 3fddd3f0e..8527e65c7 100644 --- a/pkg/deployment/reconcile/action_backup_restore.go +++ b/pkg/deployment/reconcile/action_backup_restore.go @@ -26,11 +26,12 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/go-driver" "github.com/rs/zerolog" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" ) func init() { @@ -66,7 +67,7 @@ func (a actionBackupRestore) Start(ctx context.Context) (bool, error) { return true, nil } - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() dbc, err := a.actionCtx.GetDatabaseClient(ctxChild) if err != nil { diff --git a/pkg/deployment/reconcile/action_bootstrap_set_password.go b/pkg/deployment/reconcile/action_bootstrap_set_password.go index 3e244c844..ea17c7dcd 100644 --- a/pkg/deployment/reconcile/action_bootstrap_set_password.go +++ b/pkg/deployment/reconcile/action_bootstrap_set_password.go @@ -28,7 +28,7 @@ import ( "crypto/rand" "encoding/hex" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" + "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -103,7 +103,7 @@ func (a actionBootstrapSetPassword) Start(ctx context.Context) (bool, error) { func (a actionBootstrapSetPassword) setUserPassword(ctx context.Context, user, secret string) (string, error) { a.log.Debug().Msgf("Bootstrapping user %s, secret %s", user, secret) - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() client, err := a.actionCtx.GetDatabaseClient(ctxChild) if err != nil { @@ -116,21 +116,21 @@ func (a actionBootstrapSetPassword) setUserPassword(ctx context.Context, user, s } // Obtain the user - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() if u, err := client.User(ctxChild, user); err != nil { if !driver.IsNotFound(err) { return "", err } - err = arangod.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().ArangoD().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := client.CreateUser(ctxChild, user, &driver.UserOptions{Password: password}) return err }) return password, errors.WithStack(err) } else { - err = arangod.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().ArangoD().RunWithTimeout(ctx, func(ctxChild context.Context) error { return u.Update(ctxChild, driver.UserOptions{ Password: password, }) diff --git a/pkg/deployment/reconcile/action_cleanout_member.go b/pkg/deployment/reconcile/action_cleanout_member.go index 1578b3815..e673b86e7 100644 --- a/pkg/deployment/reconcile/action_cleanout_member.go +++ b/pkg/deployment/reconcile/action_cleanout_member.go @@ -26,6 +26,8 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" driver "github.com/arangodb/go-driver" @@ -71,7 +73,7 @@ func (a *actionCleanoutMember) Start(ctx context.Context) (bool, error) { } log := a.log - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := a.actionCtx.GetDatabaseClient(ctxChild) if err != nil { @@ -79,7 +81,7 @@ func (a *actionCleanoutMember) Start(ctx context.Context) (bool, error) { return false, errors.WithStack(err) } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() cluster, err := c.Cluster(ctxChild) if err != nil { @@ -87,7 +89,7 @@ func (a *actionCleanoutMember) Start(ctx context.Context) (bool, error) { return false, errors.WithStack(err) } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() var jobID string ctxJobID := driver.WithJobIDResponse(ctxChild, &jobID) @@ -123,7 +125,7 @@ func (a *actionCleanoutMember) CheckProgress(ctx context.Context) (bool, bool, e return true, false, nil } - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := a.actionCtx.GetDatabaseClient(ctxChild) if err != nil { @@ -131,7 +133,7 @@ func (a *actionCleanoutMember) CheckProgress(ctx context.Context) (bool, bool, e return false, false, nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() cluster, err := c.Cluster(ctxChild) if err != nil { @@ -139,7 +141,7 @@ func (a *actionCleanoutMember) CheckProgress(ctx context.Context) (bool, bool, e return false, false, nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() cleanedOut, err := cluster.IsCleanedOut(ctxChild, a.action.MemberID) if err != nil { @@ -150,7 +152,7 @@ func (a *actionCleanoutMember) CheckProgress(ctx context.Context) (bool, bool, e // We're not done yet, check job status log.Debug().Msg("IsCleanedOut returned false") - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := a.actionCtx.GetDatabaseClient(ctxChild) if err != nil { @@ -158,7 +160,7 @@ func (a *actionCleanoutMember) CheckProgress(ctx context.Context) (bool, bool, e return false, false, nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() agency, err := a.actionCtx.GetAgency(ctxChild) if err != nil { @@ -166,7 +168,7 @@ func (a *actionCleanoutMember) CheckProgress(ctx context.Context) (bool, bool, e return false, false, nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() jobStatus, err := arangod.CleanoutServerJobStatus(ctxChild, m.CleanoutJobID, c, agency) if err != nil { diff --git a/pkg/deployment/reconcile/action_cluster_member_cleanup.go b/pkg/deployment/reconcile/action_cluster_member_cleanup.go index eb7447aa7..d58233c17 100644 --- a/pkg/deployment/reconcile/action_cluster_member_cleanup.go +++ b/pkg/deployment/reconcile/action_cluster_member_cleanup.go @@ -26,7 +26,7 @@ package reconcile import ( "context" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" + "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/go-driver" @@ -71,21 +71,21 @@ func (a *actionClusterMemberCleanup) Start(ctx context.Context) (bool, error) { func (a *actionClusterMemberCleanup) start(ctx context.Context) error { id := driver.ServerID(a.MemberID()) - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := a.actionCtx.GetDatabaseClient(ctxChild) if err != nil { return err } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() cluster, err := c.Cluster(ctxChild) if err != nil { return err } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() health, err := cluster.Health(ctxChild) if err != nil { @@ -96,7 +96,7 @@ func (a *actionClusterMemberCleanup) start(ctx context.Context) error { return nil } - return arangod.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().ArangoD().RunWithTimeout(ctx, func(ctxChild context.Context) error { return cluster.RemoveServer(ctxChild, id) }) } diff --git a/pkg/deployment/reconcile/action_encryption_add.go b/pkg/deployment/reconcile/action_encryption_add.go index 922c1f9be..f60620ec7 100644 --- a/pkg/deployment/reconcile/action_encryption_add.go +++ b/pkg/deployment/reconcile/action_encryption_add.go @@ -27,7 +27,7 @@ import ( "context" "encoding/base64" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" + "github.com/arangodb/kube-arangodb/pkg/util/globals" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -107,7 +107,7 @@ func (a *encryptionKeyAddAction) Start(ctx context.Context) (bool, error) { return true, nil } - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := a.actionCtx.SecretsModInterface().Patch(ctxChild, pod.GetEncryptionFolderSecretName(a.actionCtx.GetAPIObject().GetName()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) diff --git a/pkg/deployment/reconcile/action_encryption_refresh.go b/pkg/deployment/reconcile/action_encryption_refresh.go index 831a4dafd..4c5f159e6 100644 --- a/pkg/deployment/reconcile/action_encryption_refresh.go +++ b/pkg/deployment/reconcile/action_encryption_refresh.go @@ -26,14 +26,14 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/rs/zerolog" meta "k8s.io/apimachinery/pkg/apis/meta/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/deployment/client" "github.com/arangodb/kube-arangodb/pkg/deployment/pod" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" ) func init() { @@ -58,7 +58,7 @@ func (a *encryptionKeyRefreshAction) Start(ctx context.Context) (bool, error) { } func (a *encryptionKeyRefreshAction) CheckProgress(ctx context.Context) (bool, bool, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() keyfolder, err := a.actionCtx.GetCachedStatus().SecretReadInterface().Get(ctxChild, pod.GetEncryptionFolderSecretName(a.actionCtx.GetName()), meta.GetOptions{}) if err != nil { @@ -66,7 +66,7 @@ func (a *encryptionKeyRefreshAction) CheckProgress(ctx context.Context) (bool, b return true, false, nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := a.actionCtx.GetServerClient(ctxChild, a.action.Group, a.action.MemberID) if err != nil { @@ -75,7 +75,7 @@ func (a *encryptionKeyRefreshAction) CheckProgress(ctx context.Context) (bool, b } client := client.NewClient(c.Connection()) - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() e, err := client.RefreshEncryption(ctxChild) if err != nil { diff --git a/pkg/deployment/reconcile/action_encryption_remove.go b/pkg/deployment/reconcile/action_encryption_remove.go index 7dc72dc39..4efe01a7b 100644 --- a/pkg/deployment/reconcile/action_encryption_remove.go +++ b/pkg/deployment/reconcile/action_encryption_remove.go @@ -26,6 +26,8 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -82,7 +84,7 @@ func (a *encryptionKeyRemoveAction) Start(ctx context.Context) (bool, error) { return true, nil } - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := a.actionCtx.SecretsModInterface().Patch(ctxChild, pod.GetEncryptionFolderSecretName(a.actionCtx.GetAPIObject().GetName()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) diff --git a/pkg/deployment/reconcile/action_encryption_status_update.go b/pkg/deployment/reconcile/action_encryption_status_update.go index c434bf373..a9730dd1d 100644 --- a/pkg/deployment/reconcile/action_encryption_status_update.go +++ b/pkg/deployment/reconcile/action_encryption_status_update.go @@ -26,7 +26,7 @@ package reconcile import ( "context" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" + "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -60,7 +60,7 @@ func (a *encryptionKeyStatusUpdateAction) Start(ctx context.Context) (bool, erro return true, nil } - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() f, err := a.actionCtx.GetCachedStatus().SecretReadInterface().Get(ctxChild, pod.GetEncryptionFolderSecretName(a.actionCtx.GetAPIObject().GetName()), meta.GetOptions{}) diff --git a/pkg/deployment/reconcile/action_jwt_add.go b/pkg/deployment/reconcile/action_jwt_add.go index 371096ebb..d233bac7a 100644 --- a/pkg/deployment/reconcile/action_jwt_add.go +++ b/pkg/deployment/reconcile/action_jwt_add.go @@ -27,6 +27,8 @@ import ( "context" "encoding/base64" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -117,7 +119,7 @@ func (a *jwtAddAction) Start(ctx context.Context) (bool, error) { return true, nil } - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := a.actionCtx.SecretsModInterface().Patch(ctxChild, pod.JWTSecretFolder(a.actionCtx.GetName()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) diff --git a/pkg/deployment/reconcile/action_jwt_clean.go b/pkg/deployment/reconcile/action_jwt_clean.go index 6cdcbb7df..3b63ac6b4 100644 --- a/pkg/deployment/reconcile/action_jwt_clean.go +++ b/pkg/deployment/reconcile/action_jwt_clean.go @@ -26,6 +26,8 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -108,7 +110,7 @@ func (a *jwtCleanAction) Start(ctx context.Context) (bool, error) { return true, nil } - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := a.actionCtx.SecretsModInterface().Patch(ctxChild, pod.JWTSecretFolder(a.actionCtx.GetName()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) diff --git a/pkg/deployment/reconcile/action_jwt_refresh.go b/pkg/deployment/reconcile/action_jwt_refresh.go index 4a9792dae..a005aed2b 100644 --- a/pkg/deployment/reconcile/action_jwt_refresh.go +++ b/pkg/deployment/reconcile/action_jwt_refresh.go @@ -26,10 +26,11 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/deployment/client" "github.com/arangodb/kube-arangodb/pkg/deployment/pod" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" "github.com/rs/zerolog" ) @@ -60,7 +61,7 @@ func (a *jwtRefreshAction) CheckProgress(ctx context.Context) (bool, bool, error return true, false, nil } - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := a.actionCtx.GetServerClient(ctxChild, a.action.Group, a.action.MemberID) if err != nil { @@ -68,7 +69,7 @@ func (a *jwtRefreshAction) CheckProgress(ctx context.Context) (bool, bool, error return true, false, nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() if invalid, err := isMemberJWTTokenInvalid(ctxChild, client.NewClient(c.Connection()), folder.Data, true); err != nil { a.log.Warn().Err(err).Msg("Error while getting JWT Status") diff --git a/pkg/deployment/reconcile/action_jwt_set_active.go b/pkg/deployment/reconcile/action_jwt_set_active.go index 9a12d88a8..6ffba06a4 100644 --- a/pkg/deployment/reconcile/action_jwt_set_active.go +++ b/pkg/deployment/reconcile/action_jwt_set_active.go @@ -27,6 +27,8 @@ import ( "context" "encoding/base64" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -119,7 +121,7 @@ func (a *jwtSetActiveAction) Start(ctx context.Context) (bool, error) { return true, nil } - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := a.actionCtx.SecretsModInterface().Patch(ctxChild, pod.JWTSecretFolder(a.actionCtx.GetName()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) diff --git a/pkg/deployment/reconcile/action_remove_member.go b/pkg/deployment/reconcile/action_remove_member.go index c5d0d7945..9556cf4aa 100644 --- a/pkg/deployment/reconcile/action_remove_member.go +++ b/pkg/deployment/reconcile/action_remove_member.go @@ -26,6 +26,8 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + apiErrors "k8s.io/apimachinery/pkg/api/errors" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -71,14 +73,14 @@ func (a *actionRemoveMember) Start(ctx context.Context) (bool, error) { } // For safety, remove from cluster if a.action.Group == api.ServerGroupCoordinators || a.action.Group == api.ServerGroupDBServers { - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() client, err := a.actionCtx.GetDatabaseClient(ctxChild) if err != nil { return false, errors.WithStack(err) } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() if err := arangod.RemoveServerFromCluster(ctxChild, client.Connection(), driver.ServerID(m.ID)); err != nil { if !driver.IsNotFound(err) && !driver.IsPreconditionFailed(err) { diff --git a/pkg/deployment/reconcile/action_resign_leadership.go b/pkg/deployment/reconcile/action_resign_leadership.go index 03a9acc9e..4480dc679 100644 --- a/pkg/deployment/reconcile/action_resign_leadership.go +++ b/pkg/deployment/reconcile/action_resign_leadership.go @@ -26,6 +26,8 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/go-driver" "github.com/arangodb/kube-arangodb/pkg/util/arangod" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -68,7 +70,7 @@ func (a *actionResignLeadership) Start(ctx context.Context) (bool, error) { return true, nil } - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() client, err := a.actionCtx.GetDatabaseClient(ctxChild) if err != nil { @@ -87,7 +89,7 @@ func (a *actionResignLeadership) Start(ctx context.Context) (bool, error) { return true, nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() cluster, err := client.Cluster(ctxChild) if err != nil { @@ -96,7 +98,7 @@ func (a *actionResignLeadership) Start(ctx context.Context) (bool, error) { } var jobID string - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() jobCtx := driver.WithJobIDResponse(ctxChild, &jobID) log.Debug().Msg("Temporary shutdown, resign leadership") @@ -140,7 +142,7 @@ func (a *actionResignLeadership) CheckProgress(ctx context.Context) (bool, bool, return true, false, nil } - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() agency, err := a.actionCtx.GetAgency(ctxChild) if err != nil { @@ -148,7 +150,7 @@ func (a *actionResignLeadership) CheckProgress(ctx context.Context) (bool, bool, return false, false, nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := a.actionCtx.GetDatabaseClient(ctxChild) if err != nil { @@ -156,7 +158,7 @@ func (a *actionResignLeadership) CheckProgress(ctx context.Context) (bool, bool, return false, false, nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() jobStatus, err := arangod.CleanoutServerJobStatus(ctxChild, m.CleanoutJobID, c, agency) if err != nil { diff --git a/pkg/deployment/reconcile/action_runtime_container_args_udpate.go b/pkg/deployment/reconcile/action_runtime_container_args_udpate.go index e7b7d596c..634f286a3 100644 --- a/pkg/deployment/reconcile/action_runtime_container_args_udpate.go +++ b/pkg/deployment/reconcile/action_runtime_container_args_udpate.go @@ -27,13 +27,14 @@ import ( "fmt" "strings" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/pkg/errors" "github.com/rs/zerolog" core "k8s.io/api/core/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/deployment/rotation" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" ) @@ -242,7 +243,7 @@ func (a actionRuntimeContainerArgsUpdate) setLogLevel(ctx context.Context, logLe return nil } - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() cli, err := a.actionCtx.GetServerClient(ctxChild, a.action.Group, a.action.MemberID) if err != nil { @@ -259,7 +260,7 @@ func (a actionRuntimeContainerArgsUpdate) setLogLevel(ctx context.Context, logLe return err } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() resp, err := conn.Do(ctxChild, req) if err != nil { diff --git a/pkg/deployment/reconcile/action_tls_ca_append.go b/pkg/deployment/reconcile/action_tls_ca_append.go index f72fe9890..510577930 100644 --- a/pkg/deployment/reconcile/action_tls_ca_append.go +++ b/pkg/deployment/reconcile/action_tls_ca_append.go @@ -27,6 +27,8 @@ import ( "context" "encoding/base64" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -116,7 +118,7 @@ func (a *appendTLSCACertificateAction) Start(ctx context.Context) (bool, error) return true, nil } - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := a.actionCtx.SecretsModInterface().Patch(ctxChild, resources.GetCASecretName(a.actionCtx.GetAPIObject()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) diff --git a/pkg/deployment/reconcile/action_tls_ca_clean.go b/pkg/deployment/reconcile/action_tls_ca_clean.go index 5357e6179..94ff5fb37 100644 --- a/pkg/deployment/reconcile/action_tls_ca_clean.go +++ b/pkg/deployment/reconcile/action_tls_ca_clean.go @@ -26,6 +26,8 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -119,7 +121,7 @@ func (a *cleanTLSCACertificateAction) Start(ctx context.Context) (bool, error) { a.log.Info().Msgf("Removing key %s from truststore", certChecksum) - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := a.actionCtx.SecretsModInterface().Patch(ctxChild, resources.GetCASecretName(a.actionCtx.GetAPIObject()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) diff --git a/pkg/deployment/reconcile/action_tls_ca_renew.go b/pkg/deployment/reconcile/action_tls_ca_renew.go index b9346f2de..cca990648 100644 --- a/pkg/deployment/reconcile/action_tls_ca_renew.go +++ b/pkg/deployment/reconcile/action_tls_ca_renew.go @@ -26,6 +26,8 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/rs/zerolog" @@ -55,7 +57,7 @@ func (a *renewTLSCACertificateAction) Start(ctx context.Context) (bool, error) { return true, nil } - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return a.actionCtx.SecretsModInterface().Delete(ctxChild, a.actionCtx.GetSpec().TLS.GetCASecretName(), meta.DeleteOptions{}) }) if err != nil { diff --git a/pkg/deployment/reconcile/action_tls_keyfile_refresh.go b/pkg/deployment/reconcile/action_tls_keyfile_refresh.go index d15eec61c..f46753a24 100644 --- a/pkg/deployment/reconcile/action_tls_keyfile_refresh.go +++ b/pkg/deployment/reconcile/action_tls_keyfile_refresh.go @@ -26,9 +26,10 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/deployment/client" "github.com/arangodb/kube-arangodb/pkg/util" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" "github.com/arangodb/kube-arangodb/pkg/util/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" @@ -54,7 +55,7 @@ type refreshTLSKeyfileCertificateAction struct { } func (a *refreshTLSKeyfileCertificateAction) CheckProgress(ctx context.Context) (bool, bool, error) { - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := a.actionCtx.GetServerClient(ctxChild, a.action.Group, a.action.MemberID) if err != nil { @@ -78,7 +79,7 @@ func (a *refreshTLSKeyfileCertificateAction) CheckProgress(ctx context.Context) client := client.NewClient(c.Connection()) - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() e, err := client.RefreshTLS(ctxChild) if err != nil { diff --git a/pkg/deployment/reconcile/action_tls_sni_update.go b/pkg/deployment/reconcile/action_tls_sni_update.go index 0cf647a3a..d458febb1 100644 --- a/pkg/deployment/reconcile/action_tls_sni_update.go +++ b/pkg/deployment/reconcile/action_tls_sni_update.go @@ -26,8 +26,9 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" "github.com/rs/zerolog" ) @@ -70,7 +71,7 @@ func (t *tlsSNIUpdate) CheckProgress(ctx context.Context) (bool, bool, error) { return true, false, nil } - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := t.actionCtx.GetServerClient(ctxChild, t.action.Group, t.action.MemberID) if err != nil { @@ -78,7 +79,7 @@ func (t *tlsSNIUpdate) CheckProgress(ctx context.Context) (bool, bool, error) { return true, false, nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() if ok, err := compareTLSSNIConfig(ctxChild, c.Connection(), fetchedSecrets, true); err != nil { t.log.Warn().Err(err).Msg("Unable to compare TLS config") diff --git a/pkg/deployment/reconcile/action_tls_status_update.go b/pkg/deployment/reconcile/action_tls_status_update.go index d5a637592..ff1d7b668 100644 --- a/pkg/deployment/reconcile/action_tls_status_update.go +++ b/pkg/deployment/reconcile/action_tls_status_update.go @@ -26,9 +26,10 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/deployment/resources" "github.com/arangodb/kube-arangodb/pkg/util" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" meta "k8s.io/apimachinery/pkg/apis/meta/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" @@ -58,7 +59,7 @@ func (a *tlsKeyStatusUpdateAction) Start(ctx context.Context) (bool, error) { return true, nil } - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() f, err := a.actionCtx.GetCachedStatus().SecretReadInterface().Get(ctxChild, resources.GetCASecretName(a.actionCtx.GetAPIObject()), meta.GetOptions{}) if err != nil { diff --git a/pkg/deployment/reconcile/action_wait_for_member_up.go b/pkg/deployment/reconcile/action_wait_for_member_up.go index abbf72aea..e35bb4bf4 100644 --- a/pkg/deployment/reconcile/action_wait_for_member_up.go +++ b/pkg/deployment/reconcile/action_wait_for_member_up.go @@ -28,7 +28,8 @@ import ( "context" "time" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" driver "github.com/arangodb/go-driver" @@ -79,7 +80,7 @@ func (a *actionWaitForMemberUp) CheckProgress(ctx context.Context) (bool, bool, return true, false, nil } - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() if a.action.Group.IsArangosync() { diff --git a/pkg/deployment/reconcile/helper_shutdown.go b/pkg/deployment/reconcile/helper_shutdown.go index 64615f679..39c954b4b 100644 --- a/pkg/deployment/reconcile/helper_shutdown.go +++ b/pkg/deployment/reconcile/helper_shutdown.go @@ -26,10 +26,11 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/deployment/features" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/rs/zerolog" @@ -80,7 +81,7 @@ func (s shutdownHelperAPI) Start(ctx context.Context) (bool, error) { if group.IsArangod() { // Invoke shutdown endpoint - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := s.actionCtx.GetServerClient(ctxChild, group, s.action.MemberID) if err != nil { diff --git a/pkg/deployment/reconcile/plan_builder_clean_out.go b/pkg/deployment/reconcile/plan_builder_clean_out.go index f8ee91965..adf7ce99a 100644 --- a/pkg/deployment/reconcile/plan_builder_clean_out.go +++ b/pkg/deployment/reconcile/plan_builder_clean_out.go @@ -26,11 +26,12 @@ import ( "context" "strconv" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/go-driver" "github.com/rs/zerolog" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" ) @@ -54,7 +55,7 @@ func createCleanOutPlan(ctx context.Context, log zerolog.Logger, _ k8sutil.APIOb return nil } - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() health, err := cluster.Health(ctxChild) if err != nil { diff --git a/pkg/deployment/reconcile/plan_builder_cluster.go b/pkg/deployment/reconcile/plan_builder_cluster.go index 5acb825c0..df50d0913 100644 --- a/pkg/deployment/reconcile/plan_builder_cluster.go +++ b/pkg/deployment/reconcile/plan_builder_cluster.go @@ -27,10 +27,11 @@ import ( "context" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/go-driver" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" "github.com/rs/zerolog" @@ -47,14 +48,14 @@ func createClusterOperationPlan(ctx context.Context, return nil } - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := planCtx.GetDatabaseClient(ctxChild) if err != nil { return nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() cluster, err := c.Cluster(ctxChild) if err != nil { @@ -62,7 +63,7 @@ func createClusterOperationPlan(ctx context.Context, return nil } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() health, err := cluster.Health(ctxChild) if err != nil { diff --git a/pkg/deployment/reconcile/plan_builder_encryption.go b/pkg/deployment/reconcile/plan_builder_encryption.go index 60899ad13..a20eeb31e 100644 --- a/pkg/deployment/reconcile/plan_builder_encryption.go +++ b/pkg/deployment/reconcile/plan_builder_encryption.go @@ -26,9 +26,9 @@ package reconcile import ( "context" - "github.com/arangodb/kube-arangodb/pkg/deployment/features" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/deployment/features" core "k8s.io/api/core/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" @@ -274,7 +274,7 @@ func isEncryptionKeyUpToDate(ctx context.Context, mlog := log.With().Str("group", group.AsRole()).Str("member", m.ID).Logger() - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := planCtx.GetServerClient(ctxChild, group, m.ID) if err != nil { @@ -284,7 +284,7 @@ func isEncryptionKeyUpToDate(ctx context.Context, client := client.NewClient(c.Connection()) - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() e, err := client.GetEncryption(ctxChild) if err != nil { diff --git a/pkg/deployment/reconcile/plan_builder_tls_sni.go b/pkg/deployment/reconcile/plan_builder_tls_sni.go index 1eee2e955..e2b16b6ef 100644 --- a/pkg/deployment/reconcile/plan_builder_tls_sni.go +++ b/pkg/deployment/reconcile/plan_builder_tls_sni.go @@ -26,11 +26,11 @@ package reconcile import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/go-driver" "github.com/arangodb/kube-arangodb/pkg/deployment/features" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" @@ -85,7 +85,7 @@ func createRotateTLSServerSNIPlan(ctx context.Context, } var c driver.Client - err := arangod.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().ArangoD().RunWithTimeout(ctx, func(ctxChild context.Context) error { var err error c, err = planCtx.GetServerClient(ctxChild, group, m.ID) return err @@ -96,7 +96,7 @@ func createRotateTLSServerSNIPlan(ctx context.Context, } var ok bool - err = arangod.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().ArangoD().RunWithTimeout(ctx, func(ctxChild context.Context) error { var err error ok, err = compareTLSSNIConfig(ctxChild, c.Connection(), fetchedSecrets, false) return err diff --git a/pkg/deployment/reconcile/utils.go b/pkg/deployment/reconcile/utils.go index fcddbc84d..4b202351d 100644 --- a/pkg/deployment/reconcile/utils.go +++ b/pkg/deployment/reconcile/utils.go @@ -27,11 +27,12 @@ import ( "context" "sort" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/go-driver" core "k8s.io/api/core/v1" "github.com/arangodb/kube-arangodb/pkg/util" - "github.com/arangodb/kube-arangodb/pkg/util/arangod" "github.com/arangodb/kube-arangodb/pkg/util/errors" ) @@ -53,14 +54,14 @@ func secretKeysToList(s *core.Secret) []string { // getCluster returns the cluster connection. func getCluster(ctx context.Context, planCtx PlanBuilderContext) (driver.Cluster, error) { - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := planCtx.GetDatabaseClient(ctxChild) if err != nil { return nil, errors.WithStack(errors.Wrapf(err, "Unable to get database client")) } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() cluster, err := c.Cluster(ctxChild) if err != nil { diff --git a/pkg/deployment/resilience/member_failure.go b/pkg/deployment/resilience/member_failure.go index 82da4f4b8..fbc87035f 100644 --- a/pkg/deployment/resilience/member_failure.go +++ b/pkg/deployment/resilience/member_failure.go @@ -27,6 +27,8 @@ import ( "context" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/go-driver/agency" @@ -132,7 +134,7 @@ func (r *Resilience) isMemberFailureAcceptable(ctx context.Context, group api.Se switch group { case api.ServerGroupAgents: // All good when remaining agents are health - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() clients, err := r.context.GetAgencyClients(ctxChild, func(id string) bool { return id != m.ID }) if err != nil { @@ -143,7 +145,7 @@ func (r *Resilience) isMemberFailureAcceptable(ctx context.Context, group api.Se } return true, "", nil case api.ServerGroupDBServers: - ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() client, err := r.context.GetDatabaseClient(ctxChild) if err != nil { diff --git a/pkg/deployment/resources/annotations.go b/pkg/deployment/resources/annotations.go index cadc63b61..cbd76132f 100644 --- a/pkg/deployment/resources/annotations.go +++ b/pkg/deployment/resources/annotations.go @@ -26,6 +26,8 @@ package resources import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/deployment/patch" "github.com/arangodb/kube-arangodb/pkg/util/collection" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" @@ -47,7 +49,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto log.Info().Msgf("Ensuring annotations") patchSecret := func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.SecretsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err @@ -64,7 +66,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto } patchServiceAccount := func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.ServiceAccountsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err @@ -81,7 +83,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto } patchService := func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.ServicesModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err @@ -98,7 +100,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto } patchPDB := func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.PodDisruptionBudgetsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err @@ -115,7 +117,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto } patchPVC := func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.PersistentVolumeClaimsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err @@ -132,7 +134,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto } patchPod := func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.PodsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err @@ -149,7 +151,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto } patchServiceMonitor := func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.ServiceMonitorsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err diff --git a/pkg/deployment/resources/certificates_tls.go b/pkg/deployment/resources/certificates_tls.go index 12118d2ed..45884b2ec 100644 --- a/pkg/deployment/resources/certificates_tls.go +++ b/pkg/deployment/resources/certificates_tls.go @@ -29,6 +29,8 @@ import ( "strings" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" @@ -85,7 +87,7 @@ func createTLSServerCertificate(ctx context.Context, log zerolog.Logger, cachedS log = log.With().Str("secret", secretName).Logger() // Load CA certificate - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() caCert, caKey, _, err := k8sutil.GetCASecret(ctxChild, cachedStatus.SecretReadInterface(), spec.GetCASecretName(), nil) if err != nil { @@ -115,7 +117,7 @@ func createTLSServerCertificate(ctx context.Context, log zerolog.Logger, cachedS keyfile := strings.TrimSpace(cert) + "\n" + strings.TrimSpace(priv) - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return k8sutil.CreateTLSKeyfileSecret(ctxChild, secrets, secretName, keyfile, ownerRef) }) if err != nil { diff --git a/pkg/deployment/resources/inspector/members.go b/pkg/deployment/resources/inspector/members.go index fa206de1b..5a08abcc8 100644 --- a/pkg/deployment/resources/inspector/members.go +++ b/pkg/deployment/resources/inspector/members.go @@ -26,12 +26,12 @@ package inspector import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/apis/deployment" apiErrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -130,10 +130,10 @@ func arangoMemberPointer(pod api.ArangoMember) *api.ArangoMember { } func getArangoMembers(ctx context.Context, k versioned.Interface, namespace, cont string) ([]api.ArangoMember, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() arangoMembers, err := k.DatabaseV1().ArangoMembers(namespace).List(ctxChild, meta.ListOptions{ - Limit: 128, + Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), Continue: cont, }) diff --git a/pkg/deployment/resources/inspector/nodes.go b/pkg/deployment/resources/inspector/nodes.go index b3d76eb3b..0e9c1581a 100644 --- a/pkg/deployment/resources/inspector/nodes.go +++ b/pkg/deployment/resources/inspector/nodes.go @@ -23,8 +23,9 @@ package inspector import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/node" core "k8s.io/api/core/v1" policy "k8s.io/api/policy/v1beta1" @@ -145,10 +146,10 @@ func nodesToMap(ctx context.Context, inspector *inspector, k kubernetes.Interfac } func getNodes(ctx context.Context, k kubernetes.Interface, cont string) ([]core.Node, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() nodes, err := k.CoreV1().Nodes().List(ctxChild, meta.ListOptions{ - Limit: 128, + Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), Continue: cont, }) diff --git a/pkg/deployment/resources/inspector/pdbs.go b/pkg/deployment/resources/inspector/pdbs.go index eafd09c10..344b792cf 100644 --- a/pkg/deployment/resources/inspector/pdbs.go +++ b/pkg/deployment/resources/inspector/pdbs.go @@ -26,11 +26,11 @@ package inspector import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + apiErrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget" policy "k8s.io/api/policy/v1beta1" @@ -129,10 +129,10 @@ func podDisruptionBudgetPointer(podDisruptionBudget policy.PodDisruptionBudget) } func getPodDisruptionBudgets(ctx context.Context, k kubernetes.Interface, namespace, cont string) ([]policy.PodDisruptionBudget, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() podDisruptionBudgets, err := k.PolicyV1beta1().PodDisruptionBudgets(namespace).List(ctxChild, meta.ListOptions{ - Limit: 128, + Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), Continue: cont, }) diff --git a/pkg/deployment/resources/inspector/pods.go b/pkg/deployment/resources/inspector/pods.go index f4709fb0f..3c04d3162 100644 --- a/pkg/deployment/resources/inspector/pods.go +++ b/pkg/deployment/resources/inspector/pods.go @@ -26,11 +26,12 @@ package inspector import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + apiErrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod" core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -128,10 +129,10 @@ func podPointer(pod core.Pod) *core.Pod { } func getPods(ctx context.Context, k kubernetes.Interface, namespace, cont string) ([]core.Pod, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() pods, err := k.CoreV1().Pods(namespace).List(ctxChild, meta.ListOptions{ - Limit: 128, + Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), Continue: cont, }) diff --git a/pkg/deployment/resources/inspector/pvcs.go b/pkg/deployment/resources/inspector/pvcs.go index b74ee43a2..59dc6b17e 100644 --- a/pkg/deployment/resources/inspector/pvcs.go +++ b/pkg/deployment/resources/inspector/pvcs.go @@ -26,11 +26,11 @@ package inspector import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + apiErrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim" core "k8s.io/api/core/v1" @@ -129,10 +129,10 @@ func pvcPointer(pvc core.PersistentVolumeClaim) *core.PersistentVolumeClaim { } func getPersistentVolumeClaims(ctx context.Context, k kubernetes.Interface, namespace, cont string) ([]core.PersistentVolumeClaim, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() pvcs, err := k.CoreV1().PersistentVolumeClaims(namespace).List(ctxChild, meta.ListOptions{ - Limit: 128, + Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), Continue: cont, }) diff --git a/pkg/deployment/resources/inspector/sa.go b/pkg/deployment/resources/inspector/sa.go index bd4ade751..8c64a362f 100644 --- a/pkg/deployment/resources/inspector/sa.go +++ b/pkg/deployment/resources/inspector/sa.go @@ -26,11 +26,11 @@ package inspector import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + apiErrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount" core "k8s.io/api/core/v1" @@ -129,10 +129,10 @@ func serviceAccountPointer(serviceAccount core.ServiceAccount) *core.ServiceAcco } func getServiceAccounts(ctx context.Context, k kubernetes.Interface, namespace, cont string) ([]core.ServiceAccount, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() serviceAccounts, err := k.CoreV1().ServiceAccounts(namespace).List(ctxChild, meta.ListOptions{ - Limit: 128, + Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), Continue: cont, }) diff --git a/pkg/deployment/resources/inspector/secrets.go b/pkg/deployment/resources/inspector/secrets.go index ba5a7bd75..e08e4345f 100644 --- a/pkg/deployment/resources/inspector/secrets.go +++ b/pkg/deployment/resources/inspector/secrets.go @@ -26,7 +26,7 @@ package inspector import ( "context" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" + "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret" @@ -128,10 +128,10 @@ func secretPointer(pod core.Secret) *core.Secret { } func getSecrets(ctx context.Context, k kubernetes.Interface, namespace, cont string) ([]core.Secret, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() secrets, err := k.CoreV1().Secrets(namespace).List(ctxChild, meta.ListOptions{ - Limit: 128, + Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), Continue: cont, }) diff --git a/pkg/deployment/resources/inspector/services.go b/pkg/deployment/resources/inspector/services.go index c607f46d6..d00333c8f 100644 --- a/pkg/deployment/resources/inspector/services.go +++ b/pkg/deployment/resources/inspector/services.go @@ -26,11 +26,11 @@ package inspector import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + apiErrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service" core "k8s.io/api/core/v1" @@ -129,10 +129,10 @@ func servicePointer(pod core.Service) *core.Service { } func getServices(ctx context.Context, k kubernetes.Interface, namespace, cont string) ([]core.Service, error) { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() services, err := k.CoreV1().Services(namespace).List(ctxChild, meta.ListOptions{ - Limit: 128, + Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), Continue: cont, }) diff --git a/pkg/deployment/resources/inspector/sms.go b/pkg/deployment/resources/inspector/sms.go index a50a28234..e10e27abf 100644 --- a/pkg/deployment/resources/inspector/sms.go +++ b/pkg/deployment/resources/inspector/sms.go @@ -26,11 +26,11 @@ package inspector import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + apiErrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor" monitoringGroup "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring" @@ -123,10 +123,10 @@ func serviceMonitorsToMap(ctx context.Context, inspector *inspector, m monitorin } func getServiceMonitors(ctx context.Context, m monitoringClient.MonitoringV1Interface, namespace, cont string) []*monitoring.ServiceMonitor { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() serviceMonitors, err := m.ServiceMonitors(namespace).List(ctxChild, meta.ListOptions{ - Limit: 128, + Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), Continue: cont, }) diff --git a/pkg/deployment/resources/labels.go b/pkg/deployment/resources/labels.go index 3a3ad5e34..edad6d6c0 100644 --- a/pkg/deployment/resources/labels.go +++ b/pkg/deployment/resources/labels.go @@ -26,8 +26,9 @@ package resources import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" core "k8s.io/api/core/v1" @@ -74,7 +75,7 @@ func (r *Resources) EnsureSecretLabels(ctx context.Context, cachedStatus inspect changed := false if err := cachedStatus.IterateSecrets(func(secret *core.Secret) error { if ensureLabelsMap(secret.Kind, secret, r.context.GetSpec(), func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.SecretsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err @@ -101,7 +102,7 @@ func (r *Resources) EnsureServiceAccountsLabels(ctx context.Context, cachedStatu changed := false if err := cachedStatus.IterateServiceAccounts(func(serviceAccount *core.ServiceAccount) error { if ensureLabelsMap(serviceAccount.Kind, serviceAccount, r.context.GetSpec(), func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.ServiceAccountsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -127,7 +128,7 @@ func (r *Resources) EnsureServicesLabels(ctx context.Context, cachedStatus inspe changed := false if err := cachedStatus.IterateServices(func(service *core.Service) error { if ensureLabelsMap(service.Kind, service, r.context.GetSpec(), func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.ServicesModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -153,7 +154,7 @@ func (r *Resources) EnsureServiceMonitorsLabels(ctx context.Context, cachedStatu changed := false if err := cachedStatus.IterateServiceMonitors(func(serviceMonitor *monitoring.ServiceMonitor) error { if ensureLabelsMap(serviceMonitor.Kind, serviceMonitor, r.context.GetSpec(), func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.ServiceMonitorsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -179,7 +180,7 @@ func (r *Resources) EnsurePodsLabels(ctx context.Context, cachedStatus inspector changed := false if err := cachedStatus.IteratePods(func(pod *core.Pod) error { if ensureGroupLabelsMap(pod.Kind, pod, r.context.GetSpec(), func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.PodsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -205,7 +206,7 @@ func (r *Resources) EnsurePersistentVolumeClaimsLabels(ctx context.Context, cach changed := false if err := cachedStatus.IteratePersistentVolumeClaims(func(persistentVolumeClaim *core.PersistentVolumeClaim) error { if ensureGroupLabelsMap(persistentVolumeClaim.Kind, persistentVolumeClaim, r.context.GetSpec(), func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.PersistentVolumeClaimsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -231,7 +232,7 @@ func (r *Resources) EnsurePodDisruptionBudgetsLabels(ctx context.Context, cached changed := false if err := cachedStatus.IteratePodDisruptionBudgets(func(budget *policy.PodDisruptionBudget) error { if ensureLabelsMap(budget.Kind, budget, r.context.GetSpec(), func(name string, d []byte) error { - return k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.PodDisruptionBudgetsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) diff --git a/pkg/deployment/resources/member_cleanup.go b/pkg/deployment/resources/member_cleanup.go index 26f2abb7e..bc2a9454c 100644 --- a/pkg/deployment/resources/member_cleanup.go +++ b/pkg/deployment/resources/member_cleanup.go @@ -27,6 +27,8 @@ import ( "context" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" @@ -196,7 +198,7 @@ func (r *Resources) EnsureArangoMembers(ctx context.Context, cachedStatus inspec }, } - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.ArangoMembersModInterface().Create(ctxChild, &a, metav1.CreateOptions{}) return err }) @@ -221,7 +223,7 @@ func (r *Resources) EnsureArangoMembers(ctx context.Context, cachedStatus inspec } if changed { - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.ArangoMembersModInterface().Update(ctxChild, m, metav1.UpdateOptions{}) return err }) @@ -250,7 +252,7 @@ func (r *Resources) EnsureArangoMembers(ctx context.Context, cachedStatus inspec if !ok || g != member.Spec.Group { // Remove member - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return r.context.ArangoMembersModInterface().Delete(ctxChild, member.GetName(), metav1.DeleteOptions{}) }) if err != nil { diff --git a/pkg/deployment/resources/pdbs.go b/pkg/deployment/resources/pdbs.go index 4e533e922..9661e47c9 100644 --- a/pkg/deployment/resources/pdbs.go +++ b/pkg/deployment/resources/pdbs.go @@ -28,6 +28,8 @@ import ( "fmt" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" @@ -113,7 +115,7 @@ func (r *Resources) ensurePDBForGroup(ctx context.Context, group api.ServerGroup for { var pdb *policyv1beta1.PodDisruptionBudget - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { var err error pdb, err = r.context.GetCachedStatus().PodDisruptionBudgetReadInterface().Get(ctxChild, pdbname, metav1.GetOptions{}) return err @@ -123,7 +125,7 @@ func (r *Resources) ensurePDBForGroup(ctx context.Context, group api.ServerGroup // No PDB found - create new pdb := newPDB(wantedMinAvail, deplname, group, r.context.GetAPIObject().AsOwner()) log.Debug().Msg("Creating new PDB") - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := r.context.PodDisruptionBudgetsModInterface().Create(ctxChild, pdb, metav1.CreateOptions{}) return err }) @@ -148,7 +150,7 @@ func (r *Resources) ensurePDBForGroup(ctx context.Context, group api.ServerGroup // Trigger deletion only if not already deleted if pdb.GetDeletionTimestamp() == nil { // Update the PDB - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return r.context.PodDisruptionBudgetsModInterface().Delete(ctxChild, pdbname, metav1.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { diff --git a/pkg/deployment/resources/pod_creator.go b/pkg/deployment/resources/pod_creator.go index 414628ca5..39135a7da 100644 --- a/pkg/deployment/resources/pod_creator.go +++ b/pkg/deployment/resources/pod_creator.go @@ -33,6 +33,8 @@ import ( "sync" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/deployment/member" podMod "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod" @@ -483,7 +485,7 @@ func (r *Resources) createPodForMember(ctx context.Context, cachedStatus inspect newPhase = api.MemberPhaseUpgrading } - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() podName, uid, err := CreateArangoPod(ctxChild, r.context.PodsModInterface(), apiObject, spec, group, CreatePodFromTemplate(template.PodSpec)) if err != nil { @@ -537,7 +539,7 @@ func (r *Resources) createPodForMember(ctx context.Context, cachedStatus inspect } } - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() podName, uid, err := CreateArangoPod(ctxChild, r.context.PodsModInterface(), apiObject, spec, group, CreatePodFromTemplate(template.PodSpec)) if err != nil { diff --git a/pkg/deployment/resources/pod_creator_sync.go b/pkg/deployment/resources/pod_creator_sync.go index e6ef2ae1e..78ec63a10 100644 --- a/pkg/deployment/resources/pod_creator_sync.go +++ b/pkg/deployment/resources/pod_creator_sync.go @@ -26,6 +26,8 @@ import ( "context" "math" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -317,7 +319,7 @@ func (m *MemberSyncPod) Init(ctx context.Context, cachedStatus interfaces.Inspec pod.Spec.PriorityClassName = m.groupSpec.PriorityClassName m.masterJWTSecretName = m.spec.Sync.Authentication.GetJWTSecretName() - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return k8sutil.ValidateTokenSecret(ctxChild, cachedStatus.SecretReadInterface(), m.masterJWTSecretName) }) if err != nil { @@ -325,7 +327,7 @@ func (m *MemberSyncPod) Init(ctx context.Context, cachedStatus interfaces.Inspec } monitoringTokenSecretName := m.spec.Sync.Monitoring.GetTokenSecretName() - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return k8sutil.ValidateTokenSecret(ctxChild, cachedStatus.SecretReadInterface(), monitoringTokenSecretName) }) if err != nil { @@ -338,7 +340,7 @@ func (m *MemberSyncPod) Init(ctx context.Context, cachedStatus interfaces.Inspec // Check cluster JWT secret if m.spec.IsAuthenticated() { m.clusterJWTSecretName = m.spec.Authentication.GetJWTSecretName() - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return k8sutil.ValidateTokenSecret(ctxChild, cachedStatus.SecretReadInterface(), m.clusterJWTSecretName) }) if err != nil { @@ -347,7 +349,7 @@ func (m *MemberSyncPod) Init(ctx context.Context, cachedStatus interfaces.Inspec } // Check client-auth CA certificate secret m.clientAuthCASecretName = m.spec.Sync.Authentication.GetClientCASecretName() - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return k8sutil.ValidateCACertificateSecret(ctxChild, cachedStatus.SecretReadInterface(), m.clientAuthCASecretName) }) if err != nil { diff --git a/pkg/deployment/resources/pod_finalizers.go b/pkg/deployment/resources/pod_finalizers.go index 208091cca..3f5a2493f 100644 --- a/pkg/deployment/resources/pod_finalizers.go +++ b/pkg/deployment/resources/pod_finalizers.go @@ -27,6 +27,8 @@ import ( "context" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/rs/zerolog" @@ -143,7 +145,7 @@ func (r *Resources) inspectFinalizerPodAgencyServing(ctx context.Context, log ze // Remaining agents are healthy, if we need to perform complete recovery // of the agent, also remove the PVC if memberStatus.Conditions.IsTrue(api.ConditionTypeAgentRecoveryNeeded) { - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return r.context.PersistentVolumeClaimsModInterface().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, metav1.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { @@ -172,7 +174,7 @@ func (r *Resources) inspectFinalizerPodDrainDBServer(ctx context.Context, log ze // If this DBServer is cleaned out, we need to remove the PVC. if memberStatus.Conditions.IsTrue(api.ConditionTypeCleanedOut) || memberStatus.Phase == api.MemberPhaseDrain { - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return r.context.PersistentVolumeClaimsModInterface().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, metav1.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { diff --git a/pkg/deployment/resources/pod_inspector.go b/pkg/deployment/resources/pod_inspector.go index d37ddc16d..726d1e64e 100644 --- a/pkg/deployment/resources/pod_inspector.go +++ b/pkg/deployment/resources/pod_inspector.go @@ -187,7 +187,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter } if k8sutil.IsPodScheduled(pod) { - if _, ok := pod.Labels[k8sutil.LabelKeyArangoScheduled]; k8sutil.IsPodScheduled(pod) && !ok { + if _, ok := pod.Labels[k8sutil.LabelKeyArangoScheduled]; !ok { // Adding scheduled label to the pod l := pod.Labels if l == nil { diff --git a/pkg/deployment/resources/pod_termination.go b/pkg/deployment/resources/pod_termination.go index c8a5f2609..15ff07b80 100644 --- a/pkg/deployment/resources/pod_termination.go +++ b/pkg/deployment/resources/pod_termination.go @@ -27,6 +27,8 @@ import ( "context" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/rs/zerolog" @@ -70,7 +72,7 @@ func (r *Resources) prepareAgencyPodTermination(ctx context.Context, log zerolog } // Check PVC - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() pvc, err := r.context.GetCachedStatus().PersistentVolumeClaimReadInterface().Get(ctxChild, memberStatus.PersistentVolumeClaimName, metav1.GetOptions{}) if err != nil { @@ -155,7 +157,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, log zerol } // Check PVC - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() pvc, err := r.context.GetCachedStatus().PersistentVolumeClaimReadInterface().Get(ctxChild, memberStatus.PersistentVolumeClaimName, metav1.GetOptions{}) if err != nil { @@ -172,14 +174,14 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, log zerol } // Inspect cleaned out state - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := r.context.GetDatabaseClient(ctxChild) if err != nil { log.Debug().Err(err).Msg("Failed to create member client") return errors.WithStack(err) } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() cluster, err := c.Cluster(ctxChild) if err != nil { @@ -194,7 +196,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, log zerol } return errors.WithStack(err) } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() cleanedOut, err := cluster.IsCleanedOut(ctxChild, memberStatus.ID) if err != nil { @@ -234,7 +236,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, log zerol if memberStatus.Phase == api.MemberPhaseCreated { // No cleanout job triggered var jobID string - ctxChild, cancelChild := context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancelChild := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancelChild() ctxJobID := driver.WithJobIDResponse(ctxChild, &jobID) @@ -262,14 +264,14 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, log zerol } } else if memberStatus.Phase == api.MemberPhaseDrain { // Check the job progress - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() agency, err := r.context.GetAgency(ctxChild) if err != nil { log.Debug().Err(err).Msg("Failed to create agency client") return errors.WithStack(err) } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() jobStatus, err := arangod.CleanoutServerJobStatus(ctxChild, memberStatus.CleanoutJobID, c, agency) if err != nil { @@ -293,7 +295,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, log zerol } } else if memberStatus.Phase == api.MemberPhaseResign { // Check the job progress - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() agency, err := r.context.GetAgency(ctxChild) if err != nil { @@ -301,7 +303,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, log zerol return errors.WithStack(err) } - ctxChild, cancel = context.WithTimeout(ctx, arangod.GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() jobStatus, err := arangod.CleanoutServerJobStatus(ctxChild, memberStatus.CleanoutJobID, c, agency) if err != nil { diff --git a/pkg/deployment/resources/pvc_finalizers.go b/pkg/deployment/resources/pvc_finalizers.go index 740fcdf18..585b58cb0 100644 --- a/pkg/deployment/resources/pvc_finalizers.go +++ b/pkg/deployment/resources/pvc_finalizers.go @@ -27,6 +27,8 @@ import ( "context" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/rs/zerolog" @@ -106,7 +108,7 @@ func (r *Resources) inspectFinalizerPVCMemberExists(ctx context.Context, log zer // Member still exists, let's trigger a delete of it if memberStatus.PodName != "" { log.Info().Msg("Removing Pod of member, because PVC is being removed") - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return r.context.PodsModInterface().Delete(ctxChild, memberStatus.PodName, metav1.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { diff --git a/pkg/deployment/resources/pvcs.go b/pkg/deployment/resources/pvcs.go index 7768a9d5a..860fd2ec7 100644 --- a/pkg/deployment/resources/pvcs.go +++ b/pkg/deployment/resources/pvcs.go @@ -26,6 +26,8 @@ package resources import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/constants" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -63,7 +65,7 @@ func (r *Resources) EnsurePVCs(ctx context.Context, cachedStatus inspectorInterf resources := spec.Resources vct := spec.VolumeClaimTemplate finalizers := r.createPVCFinalizers(group) - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return k8sutil.CreatePersistentVolumeClaim(ctxChild, r.context.PersistentVolumeClaimsModInterface(), m.PersistentVolumeClaimName, deploymentName, ns, storageClassName, role, enforceAntiAffinity, resources, vct, finalizers, owner) }) if err != nil { diff --git a/pkg/deployment/resources/secrets.go b/pkg/deployment/resources/secrets.go index 71eb4ff13..b895d93d9 100644 --- a/pkg/deployment/resources/secrets.go +++ b/pkg/deployment/resources/secrets.go @@ -31,6 +31,8 @@ import ( "fmt" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/tls" @@ -216,7 +218,7 @@ func (r *Resources) ensureTokenSecretFolder(ctx context.Context, cachedStatus in f.Data[pod.ActiveJWTKey] = token f.Data[constants.SecretKeyToken] = token - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := secrets.Update(ctxChild, f, meta.UpdateOptions{}) return err }) @@ -241,7 +243,7 @@ func (r *Resources) ensureTokenSecretFolder(ctx context.Context, cachedStatus in return err } - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := secrets.Patch(ctxChild, folderSecretName, types.JSONPatchType, pdata, meta.PatchOptions{}) return err }) @@ -264,7 +266,7 @@ func (r *Resources) ensureTokenSecretFolder(ctx context.Context, cachedStatus in return err } - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := secrets.Patch(ctxChild, folderSecretName, types.JSONPatchType, pdata, meta.PatchOptions{}) return err }) @@ -327,7 +329,7 @@ func (r *Resources) createSecretWithMod(ctx context.Context, secrets secret.ModI f(secret) - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := secrets.Create(ctxChild, secret, meta.CreateOptions{}) return err }) @@ -352,7 +354,7 @@ func (r *Resources) createTokenSecret(ctx context.Context, secrets secret.ModInt // Create secret owner := r.context.GetAPIObject().AsOwner() - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return k8sutil.CreateTokenSecret(ctxChild, secrets, secretName, token, &owner) }) if k8sutil.IsAlreadyExists(err) { @@ -393,7 +395,7 @@ func (r *Resources) ensureEncryptionKeyfolderSecret(ctx context.Context, cachedS } owner := r.context.GetAPIObject().AsOwner() - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return AppendKeyfileToKeyfolder(ctxChild, cachedStatus, secrets, &owner, secretName, d) }) if err != nil { @@ -509,7 +511,7 @@ func (r *Resources) ensureTLSCACertificateSecret(ctx context.Context, cachedStat apiObject := r.context.GetAPIObject() owner := apiObject.AsOwner() deploymentName := apiObject.GetName() - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return createTLSCACertificate(ctxChild, r.log, secrets, spec, deploymentName, &owner) }) if k8sutil.IsAlreadyExists(err) { @@ -533,7 +535,7 @@ func (r *Resources) ensureClientAuthCACertificateSecret(ctx context.Context, cac apiObject := r.context.GetAPIObject() owner := apiObject.AsOwner() deploymentName := apiObject.GetName() - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return createClientAuthCACertificate(ctxChild, r.log, secrets, spec, deploymentName, &owner) }) if k8sutil.IsAlreadyExists(err) { diff --git a/pkg/deployment/resources/servicemonitor.go b/pkg/deployment/resources/servicemonitor.go index a510c21fc..4d750fc19 100644 --- a/pkg/deployment/resources/servicemonitor.go +++ b/pkg/deployment/resources/servicemonitor.go @@ -26,6 +26,8 @@ package resources import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/apis/deployment" deploymentApi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/constants" @@ -167,7 +169,7 @@ func (r *Resources) EnsureServiceMonitor(ctx context.Context) error { // Check if ServiceMonitor already exists serviceMonitors := mClient.ServiceMonitors(ns) - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() servMon, err := serviceMonitors.Get(ctxChild, serviceMonitorName, metav1.GetOptions{}) if err != nil { @@ -191,7 +193,7 @@ func (r *Resources) EnsureServiceMonitor(ctx context.Context) error { Spec: spec, } - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := serviceMonitors.Create(ctxChild, smon, metav1.CreateOptions{}) return err }) @@ -236,7 +238,7 @@ func (r *Resources) EnsureServiceMonitor(ctx context.Context) error { servMon.Spec = spec - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := serviceMonitors.Update(ctxChild, servMon, metav1.UpdateOptions{}) return err }) @@ -247,7 +249,7 @@ func (r *Resources) EnsureServiceMonitor(ctx context.Context) error { return nil } // Need to get rid of the ServiceMonitor: - err = k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return serviceMonitors.Delete(ctxChild, serviceMonitorName, metav1.DeleteOptions{}) }) if err == nil { diff --git a/pkg/deployment/resources/services.go b/pkg/deployment/resources/services.go index ea1ef445d..147ed0414 100644 --- a/pkg/deployment/resources/services.go +++ b/pkg/deployment/resources/services.go @@ -28,6 +28,8 @@ import ( "strings" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service" "k8s.io/apimachinery/pkg/api/equality" @@ -101,7 +103,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn }, } - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := svcs.Create(ctxChild, s, metav1.CreateOptions{}) return err }) @@ -131,7 +133,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn if !equality.Semantic.DeepDerivative(*spec, s.Spec) { s.Spec = *spec - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := svcs.Update(ctxChild, s, metav1.UpdateOptions{}) return err }) @@ -153,7 +155,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn // Headless service counterMetric.Inc() if _, exists := cachedStatus.Service(k8sutil.CreateHeadlessServiceName(deploymentName)); !exists { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() svcName, newlyCreated, err := k8sutil.CreateHeadlessService(ctxChild, svcs, apiObject, owner) if err != nil { @@ -169,7 +171,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn single := spec.GetMode().HasSingleServers() counterMetric.Inc() if _, exists := cachedStatus.Service(k8sutil.CreateDatabaseClientServiceName(deploymentName)); !exists { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() svcName, newlyCreated, err := k8sutil.CreateDatabaseClientService(ctxChild, svcs, apiObject, single, owner) if err != nil { @@ -218,7 +220,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn } if spec.Metrics.IsEnabled() { - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() name, _, err := k8sutil.CreateExporterService(ctxChild, cachedStatus, svcs, apiObject, apiObject.AsOwner()) if err != nil { @@ -296,7 +298,7 @@ func (r *Resources) ensureExternalAccessServices(ctx context.Context, cachedStat } } if updateExternalAccessService && !createExternalAccessService && !deleteExternalAccessService { - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := svcs.Update(ctxChild, existing, metav1.UpdateOptions{}) return err }) @@ -314,7 +316,7 @@ func (r *Resources) ensureExternalAccessServices(ctx context.Context, cachedStat if deleteExternalAccessService { log.Info().Str("service", eaServiceName).Msgf("Removing obsolete %s external access service", title) - err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return svcs.Delete(ctxChild, eaServiceName, metav1.DeleteOptions{}) }) if err != nil { @@ -327,7 +329,7 @@ func (r *Resources) ensureExternalAccessServices(ctx context.Context, cachedStat nodePort := spec.GetNodePort() loadBalancerIP := spec.GetLoadBalancerIP() loadBalancerSourceRanges := spec.LoadBalancerSourceRanges - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() _, newlyCreated, err := k8sutil.CreateExternalAccessService(ctxChild, svcs, eaServiceName, svcRole, apiObject, eaServiceType, port, nodePort, loadBalancerIP, loadBalancerSourceRanges, apiObject.AsOwner()) if err != nil { diff --git a/pkg/util/arangod/client.go b/pkg/util/arangod/client.go index 715e39bd2..d70633272 100644 --- a/pkg/util/arangod/client.go +++ b/pkg/util/arangod/client.go @@ -31,6 +31,8 @@ import ( "strconv" "time" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" driver "github.com/arangodb/go-driver" @@ -49,36 +51,6 @@ type ( requireAuthenticationKey struct{} ) -type TimeoutRunFunc k8sutil.TimeoutRunFunc - -const ( - minArangoDDefaultTimeout = time.Second * 10 -) - -var requestTimeout = minArangoDDefaultTimeout - -// GetRequestTimeout gets request timeout for one call to kubernetes. -func GetRequestTimeout() time.Duration { - return requestTimeout -} - -// RunWithTimeout runs the function with the provided timeout or with default timeout. -func RunWithTimeout(ctx context.Context, run TimeoutRunFunc, timeout ...time.Duration) error { - t := GetRequestTimeout() - if len(timeout) > 0 { - t = timeout[0] - } - - return k8sutil.RunWithTimeout(ctx, k8sutil.TimeoutRunFunc(run), t) -} - -// SetRequestTimeout sets request timeout for one call to kubernetes. -func SetRequestTimeout(timeout time.Duration) { - if timeout > minArangoDDefaultTimeout { - requestTimeout = timeout - } -} - // WithSkipAuthentication prepares a context that when given to functions in // this file will avoid creating any authentication for arango clients. func WithSkipAuthentication(ctx context.Context) context.Context { @@ -233,7 +205,7 @@ func createArangodClientAuthentication(ctx context.Context, cli corev1.CoreV1Int // Should we skip using it? if ctx.Value(skipAuthenticationKey{}) == nil { secrets := cli.Secrets(apiObject.GetNamespace()) - ctxChild, cancel := context.WithTimeout(ctx, k8sutil.GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() s, err := k8sutil.GetTokenSecret(ctxChild, secrets, apiObject.Spec.Authentication.GetJWTSecretName()) if err != nil { diff --git a/pkg/util/arangod/dbserver.go b/pkg/util/arangod/dbserver.go index 559ed4932..fcdfde1b5 100644 --- a/pkg/util/arangod/dbserver.go +++ b/pkg/util/arangod/dbserver.go @@ -26,6 +26,8 @@ package arangod import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/errors" driver "github.com/arangodb/go-driver" @@ -37,14 +39,14 @@ import ( // The functions returns an error when the check could not be completed or the dbserver // is not empty, or nil when the dbserver is found to be empty. func IsDBServerEmpty(ctx context.Context, id string, client driver.Client) error { - ctxChild, cancel := context.WithTimeout(ctx, GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() c, err := client.Cluster(ctxChild) if err != nil { return errors.WithStack(errors.Wrapf(err, "Cannot obtain Cluster")) } - ctxChild, cancel = context.WithTimeout(ctx, GetRequestTimeout()) + ctxChild, cancel = globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) defer cancel() dbs, err := client.Databases(ctxChild) if err != nil { @@ -53,7 +55,7 @@ func IsDBServerEmpty(ctx context.Context, id string, client driver.Client) error var inventory driver.DatabaseInventory for _, db := range dbs { - err := RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().ArangoD().RunWithTimeout(ctx, func(ctxChild context.Context) error { var err error inventory, err = c.DatabaseInventory(ctxChild, db) diff --git a/pkg/util/globals/global.go b/pkg/util/globals/global.go new file mode 100644 index 000000000..e9f7cd370 --- /dev/null +++ b/pkg/util/globals/global.go @@ -0,0 +1,103 @@ +// +// DISCLAIMER +// +// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany +// +// 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 +// + +package globals + +import "time" + +const ( + DefaultKubernetesTimeout = 2 * time.Second + DefaultArangoDTimeout = time.Second * 10 + DefaultReconciliationTimeout = time.Minute + + DefaultKubernetesRequestBatchSize = 256 +) + +var globalObj = &globals{ + timeouts: &globalTimeouts{ + requests: NewTimeout(DefaultKubernetesTimeout), + arangod: NewTimeout(DefaultArangoDTimeout), + reconciliation: NewTimeout(DefaultReconciliationTimeout), + }, + kubernetes: &globalKubernetes{ + requestBatchSize: NewInt(DefaultKubernetesRequestBatchSize), + }, +} + +func GetGlobals() Globals { + return globalObj +} + +func GetGlobalTimeouts() GlobalTimeouts { + return globalObj.timeouts +} + +type Globals interface { + Timeouts() GlobalTimeouts + Kubernetes() GlobalKubernetes +} + +type globals struct { + timeouts *globalTimeouts + kubernetes *globalKubernetes +} + +func (g globals) Kubernetes() GlobalKubernetes { + return g.kubernetes +} + +func (g globals) Timeouts() GlobalTimeouts { + return g.timeouts +} + +type GlobalKubernetes interface { + RequestBatchSize() Int64 +} + +type globalKubernetes struct { + requestBatchSize Int64 +} + +func (g *globalKubernetes) RequestBatchSize() Int64 { + return g.requestBatchSize +} + +type GlobalTimeouts interface { + Reconciliation() Timeout + + Kubernetes() Timeout + ArangoD() Timeout +} + +type globalTimeouts struct { + requests, arangod, reconciliation Timeout +} + +func (g *globalTimeouts) Reconciliation() Timeout { + return g.reconciliation +} + +func (g *globalTimeouts) ArangoD() Timeout { + return g.arangod +} + +func (g *globalTimeouts) Kubernetes() Timeout { + return g.requests +} diff --git a/pkg/util/globals/globals_test.go b/pkg/util/globals/globals_test.go new file mode 100644 index 000000000..c4084b484 --- /dev/null +++ b/pkg/util/globals/globals_test.go @@ -0,0 +1,50 @@ +// +// DISCLAIMER +// +// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany +// +// 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 +// + +package globals + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_Globals(t *testing.T) { + t.Run("Defaults", func(t *testing.T) { + require.EqualValues(t, DefaultKubernetesRequestBatchSize, GetGlobals().Kubernetes().RequestBatchSize().Get()) + require.EqualValues(t, DefaultKubernetesTimeout, GetGlobals().Timeouts().Kubernetes().Get()) + require.EqualValues(t, DefaultArangoDTimeout, GetGlobals().Timeouts().ArangoD().Get()) + require.EqualValues(t, DefaultReconciliationTimeout, GetGlobals().Timeouts().Reconciliation().Get()) + }) + + t.Run("Override", func(t *testing.T) { + GetGlobals().Kubernetes().RequestBatchSize().Set(0) + GetGlobals().Timeouts().Kubernetes().Set(0) + GetGlobals().Timeouts().ArangoD().Set(0) + GetGlobals().Timeouts().Reconciliation().Set(0) + }) + + t.Run("Check", func(t *testing.T) { + require.EqualValues(t, 0, GetGlobals().Kubernetes().RequestBatchSize().Get()) + require.EqualValues(t, 0, GetGlobals().Timeouts().Kubernetes().Get()) + require.EqualValues(t, 0, GetGlobals().Timeouts().ArangoD().Get()) + require.EqualValues(t, 0, GetGlobals().Timeouts().Reconciliation().Get()) + }) +} diff --git a/pkg/util/globals/int.go b/pkg/util/globals/int.go new file mode 100644 index 000000000..3a9ffaa7c --- /dev/null +++ b/pkg/util/globals/int.go @@ -0,0 +1,42 @@ +// +// DISCLAIMER +// +// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany +// +// 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 +// + +package globals + +type Int64 interface { + Set(in int64) + Get() int64 +} + +func NewInt(def int64) Int64 { + return &intObj{i: def} +} + +type intObj struct { + i int64 +} + +func (i *intObj) Set(in int64) { + i.i = in +} + +func (i *intObj) Get() int64 { + return i.i +} diff --git a/pkg/util/globals/timeout.go b/pkg/util/globals/timeout.go new file mode 100644 index 000000000..bafbb754b --- /dev/null +++ b/pkg/util/globals/timeout.go @@ -0,0 +1,74 @@ +// +// DISCLAIMER +// +// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany +// +// 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 +// + +package globals + +import ( + "context" + "time" +) + +type TimeoutRunFunc func(ctxChild context.Context) error + +type Timeout interface { + Set(duration time.Duration) + Get() time.Duration + + WithTimeout(ctx context.Context) (context.Context, context.CancelFunc) + + Run(run TimeoutRunFunc) error + RunWithTimeout(ctx context.Context, run TimeoutRunFunc) error +} + +func NewTimeout(duration time.Duration) Timeout { + return &timeout{ + duration: duration, + } +} + +type timeout struct { + duration time.Duration +} + +func (t *timeout) Set(duration time.Duration) { + t.duration = duration +} + +func (t *timeout) Get() time.Duration { + return t.duration +} + +func (t *timeout) WithTimeout(ctx context.Context) (context.Context, context.CancelFunc) { + if t.duration == 0 { + return ctx, func() {} + } + + return context.WithTimeout(ctx, t.duration) +} + +func (t *timeout) Run(run TimeoutRunFunc) error { + return t.RunWithTimeout(context.Background(), run) +} + +func (t *timeout) RunWithTimeout(ctx context.Context, run TimeoutRunFunc) error { + newCtx, c := t.WithTimeout(ctx) + defer c() + return run(newCtx) +} diff --git a/pkg/util/k8sutil/finalizers.go b/pkg/util/k8sutil/finalizers.go index de36fd4ca..1b830733d 100644 --- a/pkg/util/k8sutil/finalizers.go +++ b/pkg/util/k8sutil/finalizers.go @@ -26,6 +26,8 @@ package k8sutil import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod" @@ -43,7 +45,7 @@ const ( func RemovePodFinalizers(ctx context.Context, cachedStatus pod.Inspector, log zerolog.Logger, c pod.ModInterface, p *core.Pod, finalizers []string, ignoreNotFound bool) error { getFunc := func() (metav1.Object, error) { - ctxChild, cancel := context.WithTimeout(ctx, GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() if err := cachedStatus.Refresh(ctxChild); err != nil { @@ -58,7 +60,7 @@ func RemovePodFinalizers(ctx context.Context, cachedStatus pod.Inspector, log ze } updateFunc := func(updated metav1.Object) error { updatedPod := updated.(*core.Pod) - ctxChild, cancel := context.WithTimeout(ctx, GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() result, err := c.Update(ctxChild, updatedPod, metav1.UpdateOptions{}) @@ -78,7 +80,7 @@ func RemovePodFinalizers(ctx context.Context, cachedStatus pod.Inspector, log ze func RemovePVCFinalizers(ctx context.Context, cachedStatus persistentvolumeclaim.Inspector, log zerolog.Logger, c persistentvolumeclaim.ModInterface, p *core.PersistentVolumeClaim, finalizers []string, ignoreNotFound bool) error { getFunc := func() (metav1.Object, error) { - ctxChild, cancel := context.WithTimeout(ctx, GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() if err := cachedStatus.Refresh(ctxChild); err != nil { @@ -93,7 +95,7 @@ func RemovePVCFinalizers(ctx context.Context, cachedStatus persistentvolumeclaim } updateFunc := func(updated metav1.Object) error { updatedPVC := updated.(*core.PersistentVolumeClaim) - ctxChild, cancel := context.WithTimeout(ctx, GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() result, err := c.Update(ctxChild, updatedPVC, metav1.UpdateOptions{}) diff --git a/pkg/util/k8sutil/secrets.go b/pkg/util/k8sutil/secrets.go index cbc79de97..8ab68fafc 100644 --- a/pkg/util/k8sutil/secrets.go +++ b/pkg/util/k8sutil/secrets.go @@ -26,6 +26,8 @@ package k8sutil import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret" "github.com/arangodb/kube-arangodb/pkg/util/constants" @@ -99,7 +101,7 @@ func ValidateCACertificateSecret(ctx context.Context, secrets secret.ReadInterfa // an error is returned. // Returns: certificate, error func GetCACertficateSecret(ctx context.Context, secrets secret.Interface, secretName string) (string, error) { - ctxChild, cancel := context.WithTimeout(ctx, GetRequestTimeout()) + ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() s, err := secrets.Get(ctxChild, secretName, meta.GetOptions{}) @@ -306,7 +308,7 @@ func CreateJWTFromSecret(ctx context.Context, cachedSecrets secret.ReadInterface return errors.WithStack(err) } - return RunWithTimeout(ctx, func(ctxChild context.Context) error { + return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { return CreateTokenSecret(ctxChild, secrets, tokenSecretName, signedToken, ownerRef) }) } @@ -327,7 +329,7 @@ func CreateBasicAuthSecret(ctx context.Context, secrets secret.ModInterface, sec } // Attach secret to owner AddOwnerRefToObject(secret, ownerRef) - err := RunWithTimeout(ctx, func(ctxChild context.Context) error { + err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := secrets.Create(ctxChild, secret, meta.CreateOptions{}) return err }) diff --git a/pkg/util/k8sutil/util.go b/pkg/util/k8sutil/util.go index e3ae55c2d..a7214c358 100644 --- a/pkg/util/k8sutil/util.go +++ b/pkg/util/k8sutil/util.go @@ -24,15 +24,10 @@ package k8sutil import ( - "context" - "time" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" ) -type TimeoutRunFunc func(ctxChild context.Context) error - const ( // LabelKeyArangoDeployment is the key of the label used to store the ArangoDeployment name in LabelKeyArangoDeployment = "arango_deployment" @@ -55,38 +50,8 @@ const ( // AppName is the fixed value for the "app" label AppName = "arangodb" - - // minDefaultRequestTimeout is minimum default request timeout to k8s. - minDefaultRequestTimeout = time.Second * 3 ) -var requestTimeout = minDefaultRequestTimeout - -// GetRequestTimeout gets request timeout for one call to kubernetes. -func GetRequestTimeout() time.Duration { - return requestTimeout -} - -// RunWithTimeout runs the function with the provided timeout or with default timeout. -func RunWithTimeout(ctx context.Context, run TimeoutRunFunc, timeout ...time.Duration) error { - t := GetRequestTimeout() - if len(timeout) > 0 { - t = timeout[0] - } - - ctxChild, cancel := context.WithTimeout(ctx, t) - defer cancel() - - return run(ctxChild) -} - -// SetRequestTimeout sets request timeout for one call to kubernetes. -func SetRequestTimeout(timeout time.Duration) { - if timeout > minDefaultRequestTimeout { - requestTimeout = timeout - } -} - // AddOwnerRefToObject adds given owner reference to given object func AddOwnerRefToObject(obj metav1.Object, ownerRef *metav1.OwnerReference) { if ownerRef != nil {