From 282e0f492102ae3fec91c9e07630ca217599a52b Mon Sep 17 00:00:00 2001 From: ajanikow <12255597+ajanikow@users.noreply.github.com> Date: Tue, 24 May 2022 07:25:49 +0000 Subject: [PATCH] [Feature] Replace DEP management --- CHANGELOG.md | 1 + pkg/deployment/access_package.go | 8 +- pkg/deployment/context_impl.go | 16 ++-- pkg/deployment/deployment.go | 26 +++--- pkg/deployment/deployment_inspector.go | 4 +- pkg/deployment/deployment_run_test.go | 6 +- pkg/deployment/deployment_suite_test.go | 21 ++--- pkg/deployment/images.go | 8 +- pkg/deployment/images_test.go | 2 +- pkg/deployment/informers.go | 24 +++--- pkg/deployment/metrics.go | 2 +- .../action_bootstrap_set_password.go | 2 +- pkg/deployment/reconcile/action_context.go | 36 --------- .../reconcile/action_encryption_add.go | 2 +- .../reconcile/action_encryption_remove.go | 2 +- pkg/deployment/reconcile/action_jwt_add.go | 2 +- pkg/deployment/reconcile/action_jwt_clean.go | 2 +- .../reconcile/action_jwt_set_active.go | 2 +- .../action_runtime_container_image_update.go | 2 +- .../reconcile/action_tls_ca_append.go | 2 +- .../reconcile/action_tls_ca_clean.go | 2 +- .../reconcile/action_tls_ca_renew.go | 2 +- pkg/deployment/reconcile/context.go | 1 - .../reconcile/plan_builder_context.go | 1 - pkg/deployment/reconciler/context.go | 31 -------- pkg/deployment/resources/annotations.go | 14 ++-- pkg/deployment/resources/context.go | 2 - .../resources/inspector/endpoints_mod.go | 35 ++++++++ .../resources/inspector/endpoints_mod_v1.go | 79 +++++++++++++++++++ .../resources/inspector/pdbs_mod.go | 35 ++++++++ .../resources/inspector/pdbs_mod_v1beta1.go | 79 +++++++++++++++++++ .../resources/inspector/pods_mod.go | 35 ++++++++ .../resources/inspector/pods_mod_v1.go | 79 +++++++++++++++++++ .../resources/inspector/pvcs_mod.go | 35 ++++++++ .../resources/inspector/pvcs_mod_v1.go | 79 +++++++++++++++++++ pkg/deployment/resources/inspector/sa_mod.go | 35 ++++++++ .../resources/inspector/sa_mod_v1.go | 79 +++++++++++++++++++ .../resources/inspector/secrets_mod.go | 35 ++++++++ .../resources/inspector/secrets_mod_v1.go | 79 +++++++++++++++++++ .../resources/inspector/service_mod.go | 35 ++++++++ .../resources/inspector/service_mod_v1.go | 79 +++++++++++++++++++ pkg/deployment/resources/inspector/sm_mod.go | 35 ++++++++ .../resources/inspector/sm_mod_v1.go | 79 +++++++++++++++++++ pkg/deployment/resources/labels.go | 14 ++-- pkg/deployment/resources/pdbs.go | 6 +- pkg/deployment/resources/pod_creator.go | 6 +- pkg/deployment/resources/pod_finalizers.go | 6 +- pkg/deployment/resources/pod_inspector.go | 2 +- pkg/deployment/resources/pod_leader.go | 2 +- pkg/deployment/resources/pod_termination.go | 8 +- pkg/deployment/resources/pvc_finalizers.go | 4 +- pkg/deployment/resources/pvc_inspector.go | 4 +- pkg/deployment/resources/pvcs.go | 2 +- pkg/deployment/resources/secrets.go | 8 +- pkg/deployment/resources/services.go | 4 +- pkg/deployment/server_api.go | 4 +- .../k8sutil/inspector/endpoints/v1/reader.go | 1 - pkg/util/k8sutil/inspector/inspector.go | 3 + pkg/util/k8sutil/inspector/mods/mods.go | 75 ++++++++++++++++++ 59 files changed, 1101 insertions(+), 183 deletions(-) create mode 100644 pkg/deployment/resources/inspector/endpoints_mod.go create mode 100644 pkg/deployment/resources/inspector/endpoints_mod_v1.go create mode 100644 pkg/deployment/resources/inspector/pdbs_mod.go create mode 100644 pkg/deployment/resources/inspector/pdbs_mod_v1beta1.go create mode 100644 pkg/deployment/resources/inspector/pods_mod.go create mode 100644 pkg/deployment/resources/inspector/pods_mod_v1.go create mode 100644 pkg/deployment/resources/inspector/pvcs_mod.go create mode 100644 pkg/deployment/resources/inspector/pvcs_mod_v1.go create mode 100644 pkg/deployment/resources/inspector/sa_mod.go create mode 100644 pkg/deployment/resources/inspector/sa_mod_v1.go create mode 100644 pkg/deployment/resources/inspector/secrets_mod.go create mode 100644 pkg/deployment/resources/inspector/secrets_mod_v1.go create mode 100644 pkg/deployment/resources/inspector/service_mod.go create mode 100644 pkg/deployment/resources/inspector/service_mod_v1.go create mode 100644 pkg/deployment/resources/inspector/sm_mod.go create mode 100644 pkg/deployment/resources/inspector/sm_mod_v1.go create mode 100644 pkg/util/k8sutil/inspector/mods/mods.go diff --git a/CHANGELOG.md b/CHANGELOG.md index caba253c8..79fd566a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - (Feature) Add `ACSDeploymentSynced` condition type and fix comparison of `SecretHashes` method - (Feature) Add agency leader service - (Feature) Add HostPath and PVC Volume types and allow templating +- (Feature) Replace mod ## [1.2.12](https://github.com/arangodb/kube-arangodb/tree/1.2.12) (2022-05-10) - (Feature) Add CoreV1 Endpoints Inspector diff --git a/pkg/deployment/access_package.go b/pkg/deployment/access_package.go index dbfb29c1b..f902506f8 100644 --- a/pkg/deployment/access_package.go +++ b/pkg/deployment/access_package.go @@ -65,7 +65,7 @@ func (d *Deployment) createAccessPackages(ctx context.Context) error { } // Remove all access packages that we did build, but are no longer needed - secretList := d.currentState.Secret().V1().ListSimple() + secretList := d.acs.CurrentClusterCache().Secret().V1().ListSimple() for _, secret := range secretList { if d.isOwnerOf(secret) { if _, found := secret.Data[constants.SecretAccessPackageYaml]; found { @@ -100,7 +100,7 @@ func (d *Deployment) ensureAccessPackage(ctx context.Context, apSecretName strin log := d.deps.Log spec := d.apiObject.Spec - _, err := d.currentState.Secret().V1().Read().Get(ctx, apSecretName, metav1.GetOptions{}) + _, err := d.acs.CurrentClusterCache().Secret().V1().Read().Get(ctx, apSecretName, metav1.GetOptions{}) if err == nil { // Secret already exists return nil @@ -111,7 +111,7 @@ func (d *Deployment) ensureAccessPackage(ctx context.Context, apSecretName strin // Fetch client authentication CA clientAuthSecretName := spec.Sync.Authentication.GetClientCASecretName() - clientAuthCert, clientAuthKey, _, err := k8sutil.GetCASecret(ctx, d.currentState.Secret().V1().Read(), clientAuthSecretName, nil) + clientAuthCert, clientAuthKey, _, err := k8sutil.GetCASecret(ctx, d.acs.CurrentClusterCache().Secret().V1().Read(), clientAuthSecretName, nil) if err != nil { log.Debug().Err(err).Msg("Failed to get client-auth CA secret") return errors.WithStack(err) @@ -119,7 +119,7 @@ func (d *Deployment) ensureAccessPackage(ctx context.Context, apSecretName strin // Fetch TLS CA public key tlsCASecretName := spec.Sync.TLS.GetCASecretName() - tlsCACert, err := k8sutil.GetCACertficateSecret(ctx, d.currentState.Secret().V1().Read(), tlsCASecretName) + tlsCACert, err := k8sutil.GetCACertficateSecret(ctx, d.acs.CurrentClusterCache().Secret().V1().Read(), tlsCASecretName) if err != nil { log.Debug().Err(err).Msg("Failed to get TLS CA secret") return errors.WithStack(err) diff --git a/pkg/deployment/context_impl.go b/pkg/deployment/context_impl.go index 5b392da71..b622f6e45 100644 --- a/pkg/deployment/context_impl.go +++ b/pkg/deployment/context_impl.go @@ -624,37 +624,37 @@ func (d *Deployment) WithStatusUpdate(ctx context.Context, action reconciler.Dep } func (d *Deployment) SecretsModInterface() secretv1.ModInterface { - d.currentState.GetThrottles().Secret().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Secret().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).Secrets() } func (d *Deployment) PodsModInterface() podv1.ModInterface { - d.currentState.GetThrottles().Pod().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Pod().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).Pods() } func (d *Deployment) ServiceAccountsModInterface() serviceaccountv1.ModInterface { - d.currentState.GetThrottles().ServiceAccount().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().ServiceAccount().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).ServiceAccounts() } func (d *Deployment) ServicesModInterface() servicev1.ModInterface { - d.currentState.GetThrottles().Service().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Service().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).Services() } func (d *Deployment) PersistentVolumeClaimsModInterface() persistentvolumeclaimv1.ModInterface { - d.currentState.GetThrottles().PersistentVolumeClaim().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().PersistentVolumeClaim().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).PersistentVolumeClaims() } func (d *Deployment) PodDisruptionBudgetsModInterface() poddisruptionbudgetv1beta1.ModInterface { - d.currentState.GetThrottles().PodDisruptionBudget().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().PodDisruptionBudget().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).PodDisruptionBudgets() } func (d *Deployment) ServiceMonitorsModInterface() servicemonitorv1.ModInterface { - d.currentState.GetThrottles().ServiceMonitor().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().ServiceMonitor().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).ServiceMonitors() } @@ -679,7 +679,7 @@ func (d *Deployment) GetOwnedPods(ctx context.Context) ([]core.Pod, error) { } func (d *Deployment) GetCachedStatus() inspectorInterface.Inspector { - return d.currentState + return d.acs.CurrentClusterCache() } func (d *Deployment) ApplyPatchOnPod(ctx context.Context, pod *core.Pod, p ...patch.Item) error { diff --git a/pkg/deployment/deployment.go b/pkg/deployment/deployment.go index 6c8b8d6b5..ef510af38 100644 --- a/pkg/deployment/deployment.go +++ b/pkg/deployment/deployment.go @@ -123,7 +123,6 @@ type Deployment struct { inspectCRDTrigger trigger.Trigger updateDeploymentTrigger trigger.Trigger clientCache deploymentClient.Cache - currentState inspectorInterface.Inspector agencyCache agency.Cache recentInspectionErrors int clusterScalingIntegration *clusterScalingIntegration @@ -143,7 +142,7 @@ func (d *Deployment) WithArangoMember(cache inspectorInterface.Inspector, timeou } func (d *Deployment) WithCurrentArangoMember(name string) reconciler.ArangoMemberModContext { - return d.WithArangoMember(d.currentState, globals.GetGlobals().Timeouts().Kubernetes().Get(), name) + return d.WithArangoMember(d.acs.CurrentClusterCache(), globals.GetGlobals().Timeouts().Kubernetes().Get(), name) } func (d *Deployment) GetMembersState() memberState.StateInspector { @@ -227,16 +226,15 @@ func New(config Config, deps Dependencies, apiObject *api.ArangoDeployment) (*De i := inspector.NewInspector(inspector.NewDefaultThrottle(), deps.Client, apiObject.GetNamespace(), apiObject.GetName()) d := &Deployment{ - apiObject: apiObject, - name: apiObject.GetName(), - namespace: apiObject.GetNamespace(), - config: config, - deps: deps, - eventCh: make(chan *deploymentEvent, deploymentEventQueueSize), - stopCh: make(chan struct{}), - agencyCache: agency.NewCache(apiObject.Spec.Mode), - currentState: i, - acs: acs.NewACS(apiObject.GetUID(), i), + apiObject: apiObject, + name: apiObject.GetName(), + namespace: apiObject.GetNamespace(), + config: config, + deps: deps, + eventCh: make(chan *deploymentEvent, deploymentEventQueueSize), + stopCh: make(chan struct{}), + agencyCache: agency.NewCache(apiObject.Spec.Mode), + acs: acs.NewACS(apiObject.GetUID(), i), } d.memberState = memberState.NewStateInspector(d) @@ -348,7 +346,7 @@ func (d *Deployment) run() { for { select { case <-d.stopCh: - err := d.currentState.Refresh(context.Background()) + err := d.acs.CurrentClusterCache().Refresh(context.Background()) if err != nil { log.Error().Err(err).Msg("Unable to get resources") } @@ -596,7 +594,7 @@ func (d *Deployment) isOwnerOf(obj meta.Object) bool { func (d *Deployment) lookForServiceMonitorCRD() { var err error if d.GetScope().IsNamespaced() { - _, err = d.currentState.ServiceMonitor().V1() + _, err = d.acs.CurrentClusterCache().ServiceMonitor().V1() if k8sutil.IsForbiddenOrNotFound(err) { return } diff --git a/pkg/deployment/deployment_inspector.go b/pkg/deployment/deployment_inspector.go index ea94796df..9b2a9e8f4 100644 --- a/pkg/deployment/deployment_inspector.go +++ b/pkg/deployment/deployment_inspector.go @@ -72,14 +72,14 @@ func (d *Deployment) inspectDeployment(lastInterval util.Interval) util.Interval deploymentName := d.GetName() defer metrics.SetDuration(inspectDeploymentDurationGauges.WithLabelValues(deploymentName), start) - err := d.currentState.Refresh(ctxReconciliation) + err := d.acs.CurrentClusterCache().Refresh(ctxReconciliation) if err != nil { log.Error().Err(err).Msg("Unable to get resources") return minInspectionInterval // Retry ASAP } // Check deployment still exists - updated, err := d.currentState.GetCurrentArangoDeployment() + updated, err := d.acs.CurrentClusterCache().GetCurrentArangoDeployment() if k8sutil.IsNotFound(err) { // Deployment is gone log.Info().Msg("Deployment is gone") diff --git a/pkg/deployment/deployment_run_test.go b/pkg/deployment/deployment_run_test.go index b5a900ff7..04957def7 100644 --- a/pkg/deployment/deployment_run_test.go +++ b/pkg/deployment/deployment_run_test.go @@ -67,7 +67,7 @@ func runTestCase(t *testing.T, testCase testCaseStruct) { errs := 0 for { - require.NoError(t, d.currentState.Refresh(context.Background())) + require.NoError(t, d.acs.CurrentClusterCache().Refresh(context.Background())) err := d.resources.EnsureSecrets(context.Background(), log.Logger, d.GetCachedStatus()) if err == nil { break @@ -172,7 +172,7 @@ func runTestCase(t *testing.T, testCase testCaseStruct) { return err } - require.NoError(t, d.currentState.Refresh(context.Background())) + require.NoError(t, d.acs.CurrentClusterCache().Refresh(context.Background())) groupSpec := d.apiObject.Spec.GetServerGroupSpec(group) @@ -217,7 +217,7 @@ func runTestCase(t *testing.T, testCase testCaseStruct) { } // Act - require.NoError(t, d.currentState.Refresh(context.Background())) + require.NoError(t, d.acs.CurrentClusterCache().Refresh(context.Background())) err = d.resources.EnsurePods(context.Background(), d.GetCachedStatus()) // Assert diff --git a/pkg/deployment/deployment_suite_test.go b/pkg/deployment/deployment_suite_test.go index b35533721..682f4b3cb 100644 --- a/pkg/deployment/deployment_suite_test.go +++ b/pkg/deployment/deployment_suite_test.go @@ -480,20 +480,21 @@ func createTestDeployment(t *testing.T, config Config, arangoDeployment *api.Ara Client: kclient.NewStaticClient(kubernetesClientSet, kubernetesExtClientSet, arangoClientSet, monitoringClientSet), } + i := inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), deps.Client, arangoDeployment.GetNamespace(), arangoDeployment.GetName()) + d := &Deployment{ - apiObject: arangoDeployment, - name: arangoDeployment.GetName(), - namespace: arangoDeployment.GetNamespace(), - config: config, - deps: deps, - eventCh: make(chan *deploymentEvent, deploymentEventQueueSize), - stopCh: make(chan struct{}), - currentState: inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), deps.Client, arangoDeployment.GetNamespace(), arangoDeployment.GetName()), + apiObject: arangoDeployment, + name: arangoDeployment.GetName(), + namespace: arangoDeployment.GetNamespace(), + config: config, + deps: deps, + eventCh: make(chan *deploymentEvent, deploymentEventQueueSize), + stopCh: make(chan struct{}), } d.clientCache = client.NewClientCache(d, conn.NewFactory(d.getAuth, d.getConnConfig)) - d.acs = acs.NewACS("", d.currentState) + d.acs = acs.NewACS("", i) - require.NoError(t, d.currentState.Refresh(context.Background())) + require.NoError(t, d.acs.CurrentClusterCache().Refresh(context.Background())) arangoDeployment.Spec.SetDefaults(arangoDeployment.GetName()) d.resources = resources.NewResources(deps.Log, d) diff --git a/pkg/deployment/images.go b/pkg/deployment/images.go index 5d6a1da1c..1e7eadc1f 100644 --- a/pkg/deployment/images.go +++ b/pkg/deployment/images.go @@ -140,14 +140,14 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac // Check if pod exists ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() - pod, err := ib.Context.GetCachedStatus().Pod().V1().Read().Get(ctxChild, podName, metav1.GetOptions{}) + pod, err := ib.Context.ACS().CurrentClusterCache().Pod().V1().Read().Get(ctxChild, podName, metav1.GetOptions{}) if err == nil { // Pod found if k8sutil.IsPodFailed(pod, utils.StringList{shared.ServerContainerName}) { // Wait some time before deleting the pod if time.Now().After(pod.GetCreationTimestamp().Add(30 * time.Second)) { err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return ib.Context.PodsModInterface().Delete(ctxChild, podName, metav1.DeleteOptions{}) + return ib.Context.ACS().CurrentClusterCache().PodsModInterface().V1().Delete(ctxChild, podName, metav1.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { log.Warn().Err(err).Msg("Failed to delete Image ID Pod") @@ -189,7 +189,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac // We have all the info we need now, kill the pod and store the image info. err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return ib.Context.PodsModInterface().Delete(ctxChild, podName, metav1.DeleteOptions{}) + return ib.Context.ACS().CurrentClusterCache().PodsModInterface().V1().Delete(ctxChild, podName, metav1.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { log.Warn().Err(err).Msg("Failed to delete Image ID Pod") @@ -236,7 +236,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac } 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) + _, _, err := resources.CreateArangoPod(ctxChild, ib.Context.ACS().CurrentClusterCache().PodsModInterface().V1(), ib.APIObject, ib.Spec, api.ServerGroupImageDiscovery, pod) return err }) if err != nil { diff --git a/pkg/deployment/images_test.go b/pkg/deployment/images_test.go index 5ae14000f..360599885 100644 --- a/pkg/deployment/images_test.go +++ b/pkg/deployment/images_test.go @@ -325,7 +325,7 @@ func TestEnsureImages(t *testing.T) { _, err := d.deps.Client.Arango().DatabaseV1().ArangoDeployments(testNamespace).Create(context.Background(), d.apiObject, metav1.CreateOptions{}) require.NoError(t, err) - require.NoError(t, d.currentState.Refresh(context.Background())) + require.NoError(t, d.acs.CurrentClusterCache().Refresh(context.Background())) // Act retrySoon, _, err := d.ensureImages(context.Background(), d.apiObject, d.GetCachedStatus()) diff --git a/pkg/deployment/informers.go b/pkg/deployment/informers.go index 58ede4ed1..9568412ee 100644 --- a/pkg/deployment/informers.go +++ b/pkg/deployment/informers.go @@ -51,19 +51,19 @@ func (d *Deployment) listenForPodEvents(stopCh <-chan struct{}) { &v1.Pod{}, cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - d.currentState.GetThrottles().Pod().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Pod().Invalidate() if p, ok := getPod(obj); ok && d.isOwnerOf(p) { d.triggerInspection() } }, UpdateFunc: func(oldObj, newObj interface{}) { - d.currentState.GetThrottles().Pod().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Pod().Invalidate() if p, ok := getPod(newObj); ok && d.isOwnerOf(p) { d.triggerInspection() } }, DeleteFunc: func(obj interface{}) { - d.currentState.GetThrottles().Pod().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Pod().Invalidate() if p, ok := getPod(obj); ok && d.isOwnerOf(p) { d.triggerInspection() } @@ -96,19 +96,19 @@ func (d *Deployment) listenForPVCEvents(stopCh <-chan struct{}) { &v1.PersistentVolumeClaim{}, cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - d.currentState.GetThrottles().PersistentVolumeClaim().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().PersistentVolumeClaim().Invalidate() if p, ok := getPVC(obj); ok && d.isOwnerOf(p) { d.triggerInspection() } }, UpdateFunc: func(oldObj, newObj interface{}) { - d.currentState.GetThrottles().PersistentVolumeClaim().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().PersistentVolumeClaim().Invalidate() if p, ok := getPVC(newObj); ok && d.isOwnerOf(p) { d.triggerInspection() } }, DeleteFunc: func(obj interface{}) { - d.currentState.GetThrottles().PersistentVolumeClaim().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().PersistentVolumeClaim().Invalidate() if p, ok := getPVC(obj); ok && d.isOwnerOf(p) { d.triggerInspection() } @@ -142,19 +142,19 @@ func (d *Deployment) listenForSecretEvents(stopCh <-chan struct{}) { cache.ResourceEventHandlerFuncs{ // Note: For secrets we look at all of them because they do not have to be owned by this deployment. AddFunc: func(obj interface{}) { - d.currentState.GetThrottles().Secret().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Secret().Invalidate() if getSecret(obj) { d.triggerInspection() } }, UpdateFunc: func(oldObj, newObj interface{}) { - d.currentState.GetThrottles().Secret().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Secret().Invalidate() if getSecret(newObj) { d.triggerInspection() } }, DeleteFunc: func(obj interface{}) { - d.currentState.GetThrottles().Secret().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Secret().Invalidate() if getSecret(obj) { d.triggerInspection() } @@ -187,19 +187,19 @@ func (d *Deployment) listenForServiceEvents(stopCh <-chan struct{}) { &v1.Service{}, cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - d.currentState.GetThrottles().Service().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Service().Invalidate() if s, ok := getService(obj); ok && d.isOwnerOf(s) { d.triggerInspection() } }, UpdateFunc: func(oldObj, newObj interface{}) { - d.currentState.GetThrottles().Service().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Service().Invalidate() if s, ok := getService(newObj); ok && d.isOwnerOf(s) { d.triggerInspection() } }, DeleteFunc: func(obj interface{}) { - d.currentState.GetThrottles().Service().Invalidate() + d.acs.CurrentClusterCache().GetThrottles().Service().Invalidate() if s, ok := getService(obj); ok && d.isOwnerOf(s) { d.triggerInspection() } diff --git a/pkg/deployment/metrics.go b/pkg/deployment/metrics.go index 38870acb8..9f539732b 100644 --- a/pkg/deployment/metrics.go +++ b/pkg/deployment/metrics.go @@ -78,7 +78,7 @@ func (i *inventory) Collect(m chan<- prometheus.Metric) { for _, deployment := range deployments { p.Push(i.deploymentsMetric.Gauge(1, deployment.GetNamespace(), deployment.GetName())) - if state := deployment.currentState; state != nil { + if state := deployment.acs.CurrentClusterCache(); state != nil { t := state.GetThrottles() for _, c := range throttle.AllComponents() { diff --git a/pkg/deployment/reconcile/action_bootstrap_set_password.go b/pkg/deployment/reconcile/action_bootstrap_set_password.go index 889b45a3f..808a66eb4 100644 --- a/pkg/deployment/reconcile/action_bootstrap_set_password.go +++ b/pkg/deployment/reconcile/action_bootstrap_set_password.go @@ -147,7 +147,7 @@ func (a actionBootstrapSetPassword) ensureUserPasswordSecret(ctx context.Context token := hex.EncodeToString(tokenData) owner := a.actionCtx.GetAPIObject().AsOwner() - err := k8sutil.CreateBasicAuthSecret(ctx, a.actionCtx.SecretsModInterface(), secret, user, token, &owner) + err := k8sutil.CreateBasicAuthSecret(ctx, a.actionCtx.ACS().CurrentClusterCache().SecretsModInterface().V1(), secret, user, token, &owner) if err != nil { return "", err } diff --git a/pkg/deployment/reconcile/action_context.go b/pkg/deployment/reconcile/action_context.go index bbfd5d1ae..1a4b510cd 100644 --- a/pkg/deployment/reconcile/action_context.go +++ b/pkg/deployment/reconcile/action_context.go @@ -40,13 +40,6 @@ import ( "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" - persistentvolumeclaimv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1" - podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" - poddisruptionbudgetv1beta1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1beta1" - secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" - servicev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" - serviceaccountv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount/v1" - servicemonitorv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor/v1" ) // ActionContext provides methods to the Action implementations @@ -56,7 +49,6 @@ type ActionContext interface { reconciler.DeploymentAgencyMaintenance reconciler.ArangoMemberContext reconciler.DeploymentPodRenderer - reconciler.DeploymentModInterfaces reconciler.ArangoAgencyGet reconciler.DeploymentInfoGetter reconciler.DeploymentClient @@ -239,34 +231,6 @@ func (ac *actionContext) WithStatusUpdate(ctx context.Context, action reconciler return ac.context.WithStatusUpdate(ctx, action, force...) } -func (ac *actionContext) SecretsModInterface() secretv1.ModInterface { - return ac.context.SecretsModInterface() -} - -func (ac *actionContext) PodsModInterface() podv1.ModInterface { - return ac.context.PodsModInterface() -} - -func (ac *actionContext) ServiceAccountsModInterface() serviceaccountv1.ModInterface { - return ac.context.ServiceAccountsModInterface() -} - -func (ac *actionContext) ServicesModInterface() servicev1.ModInterface { - return ac.context.ServicesModInterface() -} - -func (ac *actionContext) PersistentVolumeClaimsModInterface() persistentvolumeclaimv1.ModInterface { - return ac.context.PersistentVolumeClaimsModInterface() -} - -func (ac *actionContext) PodDisruptionBudgetsModInterface() poddisruptionbudgetv1beta1.ModInterface { - return ac.context.PodDisruptionBudgetsModInterface() -} - -func (ac *actionContext) ServiceMonitorsModInterface() servicemonitorv1.ModInterface { - return ac.context.ServiceMonitorsModInterface() -} - func (ac *actionContext) UpdateClusterCondition(ctx context.Context, conditionType api.ConditionType, status bool, reason, message string) error { return ac.context.WithStatusUpdate(ctx, func(s *api.DeploymentStatus) bool { return s.Conditions.Update(conditionType, status, reason, message) diff --git a/pkg/deployment/reconcile/action_encryption_add.go b/pkg/deployment/reconcile/action_encryption_add.go index 989b32f3e..4c15af4f6 100644 --- a/pkg/deployment/reconcile/action_encryption_add.go +++ b/pkg/deployment/reconcile/action_encryption_add.go @@ -105,7 +105,7 @@ func (a *encryptionKeyAddAction) Start(ctx context.Context) (bool, 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{}) + _, err := a.actionCtx.ACS().CurrentClusterCache().SecretsModInterface().V1().Patch(ctxChild, pod.GetEncryptionFolderSecretName(a.actionCtx.GetAPIObject().GetName()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) if err != nil { diff --git a/pkg/deployment/reconcile/action_encryption_remove.go b/pkg/deployment/reconcile/action_encryption_remove.go index c850dc6c7..846858039 100644 --- a/pkg/deployment/reconcile/action_encryption_remove.go +++ b/pkg/deployment/reconcile/action_encryption_remove.go @@ -82,7 +82,7 @@ func (a *encryptionKeyRemoveAction) Start(ctx context.Context) (bool, 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{}) + _, err := a.actionCtx.ACS().CurrentClusterCache().SecretsModInterface().V1().Patch(ctxChild, pod.GetEncryptionFolderSecretName(a.actionCtx.GetAPIObject().GetName()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) if err != nil { diff --git a/pkg/deployment/reconcile/action_jwt_add.go b/pkg/deployment/reconcile/action_jwt_add.go index 0f7f0bf2d..72116d3c7 100644 --- a/pkg/deployment/reconcile/action_jwt_add.go +++ b/pkg/deployment/reconcile/action_jwt_add.go @@ -117,7 +117,7 @@ func (a *jwtAddAction) Start(ctx context.Context) (bool, 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{}) + _, err := a.actionCtx.ACS().CurrentClusterCache().SecretsModInterface().V1().Patch(ctxChild, pod.JWTSecretFolder(a.actionCtx.GetName()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) if err != nil { diff --git a/pkg/deployment/reconcile/action_jwt_clean.go b/pkg/deployment/reconcile/action_jwt_clean.go index d4ef47359..82e8b4f68 100644 --- a/pkg/deployment/reconcile/action_jwt_clean.go +++ b/pkg/deployment/reconcile/action_jwt_clean.go @@ -108,7 +108,7 @@ func (a *jwtCleanAction) Start(ctx context.Context) (bool, 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{}) + _, err := a.actionCtx.ACS().CurrentClusterCache().SecretsModInterface().V1().Patch(ctxChild, pod.JWTSecretFolder(a.actionCtx.GetName()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) if err != nil { diff --git a/pkg/deployment/reconcile/action_jwt_set_active.go b/pkg/deployment/reconcile/action_jwt_set_active.go index 534872637..a34d33aa2 100644 --- a/pkg/deployment/reconcile/action_jwt_set_active.go +++ b/pkg/deployment/reconcile/action_jwt_set_active.go @@ -119,7 +119,7 @@ func (a *jwtSetActiveAction) Start(ctx context.Context) (bool, 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{}) + _, err := a.actionCtx.ACS().CurrentClusterCache().SecretsModInterface().V1().Patch(ctxChild, pod.JWTSecretFolder(a.actionCtx.GetName()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) if err != nil { diff --git a/pkg/deployment/reconcile/action_runtime_container_image_update.go b/pkg/deployment/reconcile/action_runtime_container_image_update.go index e5abc018f..9e40cda78 100644 --- a/pkg/deployment/reconcile/action_runtime_container_image_update.go +++ b/pkg/deployment/reconcile/action_runtime_container_image_update.go @@ -192,7 +192,7 @@ func (a actionRuntimeContainerImageUpdate) Start(ctx context.Context) (bool, err // Update pod image pod.Spec.Containers[id].Image = image - if _, err := a.actionCtx.PodsModInterface().Update(ctx, pod, v1.UpdateOptions{}); err != nil { + if _, err := a.actionCtx.ACS().CurrentClusterCache().PodsModInterface().V1().Update(ctx, pod, v1.UpdateOptions{}); err != nil { return true, err } diff --git a/pkg/deployment/reconcile/action_tls_ca_append.go b/pkg/deployment/reconcile/action_tls_ca_append.go index 067346270..230db57f1 100644 --- a/pkg/deployment/reconcile/action_tls_ca_append.go +++ b/pkg/deployment/reconcile/action_tls_ca_append.go @@ -116,7 +116,7 @@ func (a *appendTLSCACertificateAction) Start(ctx context.Context) (bool, 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{}) + _, err := a.actionCtx.ACS().CurrentClusterCache().SecretsModInterface().V1().Patch(ctxChild, resources.GetCASecretName(a.actionCtx.GetAPIObject()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) if err != nil { diff --git a/pkg/deployment/reconcile/action_tls_ca_clean.go b/pkg/deployment/reconcile/action_tls_ca_clean.go index 2ef8e4f35..cbe56d434 100644 --- a/pkg/deployment/reconcile/action_tls_ca_clean.go +++ b/pkg/deployment/reconcile/action_tls_ca_clean.go @@ -119,7 +119,7 @@ func (a *cleanTLSCACertificateAction) Start(ctx context.Context) (bool, error) { a.log.Info().Msgf("Removing key %s from truststore", certChecksum) 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{}) + _, err := a.actionCtx.ACS().CurrentClusterCache().SecretsModInterface().V1().Patch(ctxChild, resources.GetCASecretName(a.actionCtx.GetAPIObject()), types.JSONPatchType, patch, meta.PatchOptions{}) return err }) if err != nil { diff --git a/pkg/deployment/reconcile/action_tls_ca_renew.go b/pkg/deployment/reconcile/action_tls_ca_renew.go index 775d846e1..77f116120 100644 --- a/pkg/deployment/reconcile/action_tls_ca_renew.go +++ b/pkg/deployment/reconcile/action_tls_ca_renew.go @@ -55,7 +55,7 @@ func (a *renewTLSCACertificateAction) Start(ctx context.Context) (bool, 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{}) + return a.actionCtx.ACS().CurrentClusterCache().SecretsModInterface().V1().Delete(ctxChild, a.actionCtx.GetSpec().TLS.GetCASecretName(), meta.DeleteOptions{}) }) if err != nil { if !k8sutil.IsNotFound(err) { diff --git a/pkg/deployment/reconcile/context.go b/pkg/deployment/reconcile/context.go index 1f498e756..3caac6c10 100644 --- a/pkg/deployment/reconcile/context.go +++ b/pkg/deployment/reconcile/context.go @@ -40,7 +40,6 @@ type Context interface { reconciler.ArangoMemberContext reconciler.DeploymentPodRenderer reconciler.DeploymentImageManager - reconciler.DeploymentModInterfaces reconciler.ArangoAgencyGet reconciler.ArangoApplier reconciler.DeploymentInfoGetter diff --git a/pkg/deployment/reconcile/plan_builder_context.go b/pkg/deployment/reconcile/plan_builder_context.go index 81777aa16..dfea98951 100644 --- a/pkg/deployment/reconcile/plan_builder_context.go +++ b/pkg/deployment/reconcile/plan_builder_context.go @@ -38,7 +38,6 @@ type PlanBuilderContext interface { reconciler.ArangoMemberContext reconciler.DeploymentPodRenderer reconciler.DeploymentImageManager - reconciler.DeploymentModInterfaces reconciler.ArangoAgencyGet reconciler.DeploymentClient reconciler.KubernetesEventGenerator diff --git a/pkg/deployment/reconciler/context.go b/pkg/deployment/reconciler/context.go index ba9884220..33511539a 100644 --- a/pkg/deployment/reconciler/context.go +++ b/pkg/deployment/reconciler/context.go @@ -33,14 +33,6 @@ import ( agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency" "github.com/arangodb/kube-arangodb/pkg/deployment/patch" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - persistentvolumeclaimv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1" - podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" - poddisruptionbudgetv1beta1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1beta1" - secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" - servicev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" - serviceaccountv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount/v1" - servicemonitorv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor/v1" ) // ServerGroupIterator provides a helper to callback on every server @@ -99,29 +91,6 @@ type DeploymentImageManager interface { SelectImageForMember(spec api.DeploymentSpec, status api.DeploymentStatus, member api.MemberStatus) (api.ImageInfo, bool) } -type DeploymentModInterfaces interface { - // SecretsModInterface define secret modification interface - SecretsModInterface() secretv1.ModInterface - // PodsModInterface define pod modification interface - PodsModInterface() podv1.ModInterface - // ServiceAccountsModInterface define serviceaccounts modification interface - ServiceAccountsModInterface() serviceaccountv1.ModInterface - // ServicesModInterface define services modification interface - ServicesModInterface() servicev1.ModInterface - // PersistentVolumeClaimsModInterface define persistentvolumeclaims modification interface - PersistentVolumeClaimsModInterface() persistentvolumeclaimv1.ModInterface - // PodDisruptionBudgetsModInterface define poddisruptionbudgets modification interface - PodDisruptionBudgetsModInterface() poddisruptionbudgetv1beta1.ModInterface - - // ServiceMonitorsModInterface define servicemonitor modification interface - ServiceMonitorsModInterface() servicemonitorv1.ModInterface -} - -type DeploymentCachedStatus interface { - // GetCachedStatus current cached state of deployment - GetCachedStatus() inspectorInterface.Inspector -} - type ArangoAgencyGet interface { GetAgencyCache() (agencyCache.State, bool) GetAgencyHealth() (agencyCache.Health, bool) diff --git a/pkg/deployment/resources/annotations.go b/pkg/deployment/resources/annotations.go index 1478c7464..5f9259731 100644 --- a/pkg/deployment/resources/annotations.go +++ b/pkg/deployment/resources/annotations.go @@ -47,7 +47,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto patchSecret := func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.SecretsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, + _, err := cachedStatus.SecretsModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -64,7 +64,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto patchServiceAccount := func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.ServiceAccountsModInterface().Patch(ctxChild, name, + _, err := cachedStatus.ServiceAccountsModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -81,7 +81,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto patchService := func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.ServicesModInterface().Patch(ctxChild, name, types.JSONPatchType, d, + _, err := cachedStatus.ServicesModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -98,7 +98,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto patchPDB := func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.PodDisruptionBudgetsModInterface().Patch(ctxChild, name, + _, err := cachedStatus.PodDisruptionBudgetsModInterface().V1Beta1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -115,7 +115,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto patchPVC := func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.PersistentVolumeClaimsModInterface().Patch(ctxChild, name, + _, err := cachedStatus.PersistentVolumeClaimsModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -132,7 +132,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto patchPod := func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.PodsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, + _, err := cachedStatus.PodsModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -149,7 +149,7 @@ func (r *Resources) EnsureAnnotations(ctx context.Context, cachedStatus inspecto patchServiceMonitor := func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.ServiceMonitorsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, + _, err := cachedStatus.ServiceMonitorsModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) diff --git a/pkg/deployment/resources/context.go b/pkg/deployment/resources/context.go index be9eafabd..a392e3e45 100644 --- a/pkg/deployment/resources/context.go +++ b/pkg/deployment/resources/context.go @@ -40,8 +40,6 @@ type Context interface { reconciler.DeploymentAgencyMaintenance reconciler.ArangoMemberContext reconciler.DeploymentImageManager - reconciler.DeploymentModInterfaces - reconciler.DeploymentCachedStatus reconciler.ArangoAgency reconciler.ArangoApplier reconciler.DeploymentInfoGetter diff --git a/pkg/deployment/resources/inspector/endpoints_mod.go b/pkg/deployment/resources/inspector/endpoints_mod.go new file mode 100644 index 000000000..08e306093 --- /dev/null +++ b/pkg/deployment/resources/inspector/endpoints_mod.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" +) + +func (i *inspectorState) EndpointsModInterface() mods.EndpointsMods { + return endpointsMod{ + i: i, + } +} + +type endpointsMod struct { + i *inspectorState +} diff --git a/pkg/deployment/resources/inspector/endpoints_mod_v1.go b/pkg/deployment/resources/inspector/endpoints_mod_v1.go new file mode 100644 index 000000000..f35957bed --- /dev/null +++ b/pkg/deployment/resources/inspector/endpoints_mod_v1.go @@ -0,0 +1,79 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "context" + + endpointsv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints/v1" + core "k8s.io/api/core/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + typedCore "k8s.io/client-go/kubernetes/typed/core/v1" +) + +func (p endpointsMod) V1() endpointsv1.ModInterface { + return endpointsModV1(p) +} + +type endpointsModV1 struct { + i *inspectorState +} + +func (p endpointsModV1) client() typedCore.EndpointsInterface { + return p.i.Client().Kubernetes().CoreV1().Endpoints(p.i.Namespace()) +} + +func (p endpointsModV1) Create(ctx context.Context, endpoint *core.Endpoints, opts meta.CreateOptions) (*core.Endpoints, error) { + if endpoint, err := p.client().Create(ctx, endpoint, opts); err != nil { + return endpoint, err + } else { + p.i.GetThrottles().Endpoints().Invalidate() + return endpoint, err + } +} + +func (p endpointsModV1) Update(ctx context.Context, endpoint *core.Endpoints, opts meta.UpdateOptions) (*core.Endpoints, error) { + if endpoint, err := p.client().Update(ctx, endpoint, opts); err != nil { + return endpoint, err + } else { + p.i.GetThrottles().Endpoints().Invalidate() + return endpoint, err + } +} + +func (p endpointsModV1) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.Endpoints, err error) { + if endpoint, err := p.client().Patch(ctx, name, pt, data, opts, subresources...); err != nil { + return endpoint, err + } else { + p.i.GetThrottles().Endpoints().Invalidate() + return endpoint, err + } +} + +func (p endpointsModV1) Delete(ctx context.Context, name string, opts meta.DeleteOptions) error { + if err := p.client().Delete(ctx, name, opts); err != nil { + return err + } else { + p.i.GetThrottles().Endpoints().Invalidate() + return err + } +} diff --git a/pkg/deployment/resources/inspector/pdbs_mod.go b/pkg/deployment/resources/inspector/pdbs_mod.go new file mode 100644 index 000000000..ede05c0f7 --- /dev/null +++ b/pkg/deployment/resources/inspector/pdbs_mod.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" +) + +func (i *inspectorState) PodDisruptionBudgetsModInterface() mods.PodDisruptionBudgetsMods { + return podDisruptionBudgetsMod{ + i: i, + } +} + +type podDisruptionBudgetsMod struct { + i *inspectorState +} diff --git a/pkg/deployment/resources/inspector/pdbs_mod_v1beta1.go b/pkg/deployment/resources/inspector/pdbs_mod_v1beta1.go new file mode 100644 index 000000000..35a1b04c7 --- /dev/null +++ b/pkg/deployment/resources/inspector/pdbs_mod_v1beta1.go @@ -0,0 +1,79 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "context" + + podDisruptionBudgetv1beta1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1beta1" + policy "k8s.io/api/policy/v1beta1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + policyTyped "k8s.io/client-go/kubernetes/typed/policy/v1beta1" +) + +func (p podDisruptionBudgetsMod) V1Beta1() podDisruptionBudgetv1beta1.ModInterface { + return podDisruptionBudgetsModV1(p) +} + +type podDisruptionBudgetsModV1 struct { + i *inspectorState +} + +func (p podDisruptionBudgetsModV1) client() policyTyped.PodDisruptionBudgetInterface { + return p.i.Client().Kubernetes().PolicyV1beta1().PodDisruptionBudgets(p.i.Namespace()) +} + +func (p podDisruptionBudgetsModV1) Create(ctx context.Context, podDisruptionBudget *policy.PodDisruptionBudget, opts meta.CreateOptions) (*policy.PodDisruptionBudget, error) { + if podDisruptionBudget, err := p.client().Create(ctx, podDisruptionBudget, opts); err != nil { + return podDisruptionBudget, err + } else { + p.i.GetThrottles().PodDisruptionBudget().Invalidate() + return podDisruptionBudget, err + } +} + +func (p podDisruptionBudgetsModV1) Update(ctx context.Context, podDisruptionBudget *policy.PodDisruptionBudget, opts meta.UpdateOptions) (*policy.PodDisruptionBudget, error) { + if podDisruptionBudget, err := p.client().Update(ctx, podDisruptionBudget, opts); err != nil { + return podDisruptionBudget, err + } else { + p.i.GetThrottles().PodDisruptionBudget().Invalidate() + return podDisruptionBudget, err + } +} + +func (p podDisruptionBudgetsModV1) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *policy.PodDisruptionBudget, err error) { + if podDisruptionBudget, err := p.client().Patch(ctx, name, pt, data, opts, subresources...); err != nil { + return podDisruptionBudget, err + } else { + p.i.GetThrottles().PodDisruptionBudget().Invalidate() + return podDisruptionBudget, err + } +} + +func (p podDisruptionBudgetsModV1) Delete(ctx context.Context, name string, opts meta.DeleteOptions) error { + if err := p.client().Delete(ctx, name, opts); err != nil { + return err + } else { + p.i.GetThrottles().PodDisruptionBudget().Invalidate() + return err + } +} diff --git a/pkg/deployment/resources/inspector/pods_mod.go b/pkg/deployment/resources/inspector/pods_mod.go new file mode 100644 index 000000000..accdd4e6b --- /dev/null +++ b/pkg/deployment/resources/inspector/pods_mod.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" +) + +func (i *inspectorState) PodsModInterface() mods.PodsMods { + return podsMod{ + i: i, + } +} + +type podsMod struct { + i *inspectorState +} diff --git a/pkg/deployment/resources/inspector/pods_mod_v1.go b/pkg/deployment/resources/inspector/pods_mod_v1.go new file mode 100644 index 000000000..ee3d84341 --- /dev/null +++ b/pkg/deployment/resources/inspector/pods_mod_v1.go @@ -0,0 +1,79 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "context" + + podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" + core "k8s.io/api/core/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + typedCore "k8s.io/client-go/kubernetes/typed/core/v1" +) + +func (p podsMod) V1() podv1.ModInterface { + return podsModV1(p) +} + +type podsModV1 struct { + i *inspectorState +} + +func (p podsModV1) client() typedCore.PodInterface { + return p.i.Client().Kubernetes().CoreV1().Pods(p.i.Namespace()) +} + +func (p podsModV1) Create(ctx context.Context, pod *core.Pod, opts meta.CreateOptions) (*core.Pod, error) { + if pod, err := p.client().Create(ctx, pod, opts); err != nil { + return pod, err + } else { + p.i.GetThrottles().Pod().Invalidate() + return pod, err + } +} + +func (p podsModV1) Update(ctx context.Context, pod *core.Pod, opts meta.UpdateOptions) (*core.Pod, error) { + if pod, err := p.client().Update(ctx, pod, opts); err != nil { + return pod, err + } else { + p.i.GetThrottles().Pod().Invalidate() + return pod, err + } +} + +func (p podsModV1) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.Pod, err error) { + if pod, err := p.client().Patch(ctx, name, pt, data, opts, subresources...); err != nil { + return pod, err + } else { + p.i.GetThrottles().Pod().Invalidate() + return pod, err + } +} + +func (p podsModV1) Delete(ctx context.Context, name string, opts meta.DeleteOptions) error { + if err := p.client().Delete(ctx, name, opts); err != nil { + return err + } else { + p.i.GetThrottles().Pod().Invalidate() + return err + } +} diff --git a/pkg/deployment/resources/inspector/pvcs_mod.go b/pkg/deployment/resources/inspector/pvcs_mod.go new file mode 100644 index 000000000..53529a4e3 --- /dev/null +++ b/pkg/deployment/resources/inspector/pvcs_mod.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" +) + +func (i *inspectorState) PersistentVolumeClaimsModInterface() mods.PersistentVolumeClaimsMods { + return persistentVolumeClaimsMod{ + i: i, + } +} + +type persistentVolumeClaimsMod struct { + i *inspectorState +} diff --git a/pkg/deployment/resources/inspector/pvcs_mod_v1.go b/pkg/deployment/resources/inspector/pvcs_mod_v1.go new file mode 100644 index 000000000..33b13181a --- /dev/null +++ b/pkg/deployment/resources/inspector/pvcs_mod_v1.go @@ -0,0 +1,79 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "context" + + persistentVolumeClaimv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1" + core "k8s.io/api/core/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + typedCore "k8s.io/client-go/kubernetes/typed/core/v1" +) + +func (p persistentVolumeClaimsMod) V1() persistentVolumeClaimv1.ModInterface { + return persistentVolumeClaimsModV1(p) +} + +type persistentVolumeClaimsModV1 struct { + i *inspectorState +} + +func (p persistentVolumeClaimsModV1) client() typedCore.PersistentVolumeClaimInterface { + return p.i.Client().Kubernetes().CoreV1().PersistentVolumeClaims(p.i.Namespace()) +} + +func (p persistentVolumeClaimsModV1) Create(ctx context.Context, persistentVolumeClaim *core.PersistentVolumeClaim, opts meta.CreateOptions) (*core.PersistentVolumeClaim, error) { + if persistentVolumeClaim, err := p.client().Create(ctx, persistentVolumeClaim, opts); err != nil { + return persistentVolumeClaim, err + } else { + p.i.GetThrottles().PersistentVolumeClaim().Invalidate() + return persistentVolumeClaim, err + } +} + +func (p persistentVolumeClaimsModV1) Update(ctx context.Context, persistentVolumeClaim *core.PersistentVolumeClaim, opts meta.UpdateOptions) (*core.PersistentVolumeClaim, error) { + if persistentVolumeClaim, err := p.client().Update(ctx, persistentVolumeClaim, opts); err != nil { + return persistentVolumeClaim, err + } else { + p.i.GetThrottles().PersistentVolumeClaim().Invalidate() + return persistentVolumeClaim, err + } +} + +func (p persistentVolumeClaimsModV1) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.PersistentVolumeClaim, err error) { + if persistentVolumeClaim, err := p.client().Patch(ctx, name, pt, data, opts, subresources...); err != nil { + return persistentVolumeClaim, err + } else { + p.i.GetThrottles().PersistentVolumeClaim().Invalidate() + return persistentVolumeClaim, err + } +} + +func (p persistentVolumeClaimsModV1) Delete(ctx context.Context, name string, opts meta.DeleteOptions) error { + if err := p.client().Delete(ctx, name, opts); err != nil { + return err + } else { + p.i.GetThrottles().PersistentVolumeClaim().Invalidate() + return err + } +} diff --git a/pkg/deployment/resources/inspector/sa_mod.go b/pkg/deployment/resources/inspector/sa_mod.go new file mode 100644 index 000000000..0af136036 --- /dev/null +++ b/pkg/deployment/resources/inspector/sa_mod.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" +) + +func (i *inspectorState) ServiceAccountsModInterface() mods.ServiceAccountsMods { + return serviceAccountsMod{ + i: i, + } +} + +type serviceAccountsMod struct { + i *inspectorState +} diff --git a/pkg/deployment/resources/inspector/sa_mod_v1.go b/pkg/deployment/resources/inspector/sa_mod_v1.go new file mode 100644 index 000000000..d7d58b4d0 --- /dev/null +++ b/pkg/deployment/resources/inspector/sa_mod_v1.go @@ -0,0 +1,79 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "context" + + serviceAccountv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount/v1" + core "k8s.io/api/core/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + typedCore "k8s.io/client-go/kubernetes/typed/core/v1" +) + +func (p serviceAccountsMod) V1() serviceAccountv1.ModInterface { + return serviceAccountsModV1(p) +} + +type serviceAccountsModV1 struct { + i *inspectorState +} + +func (p serviceAccountsModV1) client() typedCore.ServiceAccountInterface { + return p.i.Client().Kubernetes().CoreV1().ServiceAccounts(p.i.Namespace()) +} + +func (p serviceAccountsModV1) Create(ctx context.Context, serviceAccount *core.ServiceAccount, opts meta.CreateOptions) (*core.ServiceAccount, error) { + if serviceAccount, err := p.client().Create(ctx, serviceAccount, opts); err != nil { + return serviceAccount, err + } else { + p.i.GetThrottles().ServiceAccount().Invalidate() + return serviceAccount, err + } +} + +func (p serviceAccountsModV1) Update(ctx context.Context, serviceAccount *core.ServiceAccount, opts meta.UpdateOptions) (*core.ServiceAccount, error) { + if serviceAccount, err := p.client().Update(ctx, serviceAccount, opts); err != nil { + return serviceAccount, err + } else { + p.i.GetThrottles().ServiceAccount().Invalidate() + return serviceAccount, err + } +} + +func (p serviceAccountsModV1) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.ServiceAccount, err error) { + if serviceAccount, err := p.client().Patch(ctx, name, pt, data, opts, subresources...); err != nil { + return serviceAccount, err + } else { + p.i.GetThrottles().ServiceAccount().Invalidate() + return serviceAccount, err + } +} + +func (p serviceAccountsModV1) Delete(ctx context.Context, name string, opts meta.DeleteOptions) error { + if err := p.client().Delete(ctx, name, opts); err != nil { + return err + } else { + p.i.GetThrottles().ServiceAccount().Invalidate() + return err + } +} diff --git a/pkg/deployment/resources/inspector/secrets_mod.go b/pkg/deployment/resources/inspector/secrets_mod.go new file mode 100644 index 000000000..1023635d3 --- /dev/null +++ b/pkg/deployment/resources/inspector/secrets_mod.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" +) + +func (i *inspectorState) SecretsModInterface() mods.SecretsMods { + return secretsMod{ + i: i, + } +} + +type secretsMod struct { + i *inspectorState +} diff --git a/pkg/deployment/resources/inspector/secrets_mod_v1.go b/pkg/deployment/resources/inspector/secrets_mod_v1.go new file mode 100644 index 000000000..e153695ba --- /dev/null +++ b/pkg/deployment/resources/inspector/secrets_mod_v1.go @@ -0,0 +1,79 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "context" + + secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" + core "k8s.io/api/core/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + typedCore "k8s.io/client-go/kubernetes/typed/core/v1" +) + +func (p secretsMod) V1() secretv1.ModInterface { + return secretsModV1(p) +} + +type secretsModV1 struct { + i *inspectorState +} + +func (p secretsModV1) client() typedCore.SecretInterface { + return p.i.Client().Kubernetes().CoreV1().Secrets(p.i.Namespace()) +} + +func (p secretsModV1) Create(ctx context.Context, secret *core.Secret, opts meta.CreateOptions) (*core.Secret, error) { + if secret, err := p.client().Create(ctx, secret, opts); err != nil { + return secret, err + } else { + p.i.GetThrottles().Secret().Invalidate() + return secret, err + } +} + +func (p secretsModV1) Update(ctx context.Context, secret *core.Secret, opts meta.UpdateOptions) (*core.Secret, error) { + if secret, err := p.client().Update(ctx, secret, opts); err != nil { + return secret, err + } else { + p.i.GetThrottles().Secret().Invalidate() + return secret, err + } +} + +func (p secretsModV1) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.Secret, err error) { + if secret, err := p.client().Patch(ctx, name, pt, data, opts, subresources...); err != nil { + return secret, err + } else { + p.i.GetThrottles().Secret().Invalidate() + return secret, err + } +} + +func (p secretsModV1) Delete(ctx context.Context, name string, opts meta.DeleteOptions) error { + if err := p.client().Delete(ctx, name, opts); err != nil { + return err + } else { + p.i.GetThrottles().Secret().Invalidate() + return err + } +} diff --git a/pkg/deployment/resources/inspector/service_mod.go b/pkg/deployment/resources/inspector/service_mod.go new file mode 100644 index 000000000..ef846eb11 --- /dev/null +++ b/pkg/deployment/resources/inspector/service_mod.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" +) + +func (i *inspectorState) ServicesModInterface() mods.ServicesMods { + return servicesMod{ + i: i, + } +} + +type servicesMod struct { + i *inspectorState +} diff --git a/pkg/deployment/resources/inspector/service_mod_v1.go b/pkg/deployment/resources/inspector/service_mod_v1.go new file mode 100644 index 000000000..5fca11ca1 --- /dev/null +++ b/pkg/deployment/resources/inspector/service_mod_v1.go @@ -0,0 +1,79 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "context" + + servicev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" + core "k8s.io/api/core/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + typedCore "k8s.io/client-go/kubernetes/typed/core/v1" +) + +func (p servicesMod) V1() servicev1.ModInterface { + return servicesModV1(p) +} + +type servicesModV1 struct { + i *inspectorState +} + +func (p servicesModV1) client() typedCore.ServiceInterface { + return p.i.Client().Kubernetes().CoreV1().Services(p.i.Namespace()) +} + +func (p servicesModV1) Create(ctx context.Context, service *core.Service, opts meta.CreateOptions) (*core.Service, error) { + if service, err := p.client().Create(ctx, service, opts); err != nil { + return service, err + } else { + p.i.GetThrottles().Service().Invalidate() + return service, err + } +} + +func (p servicesModV1) Update(ctx context.Context, service *core.Service, opts meta.UpdateOptions) (*core.Service, error) { + if service, err := p.client().Update(ctx, service, opts); err != nil { + return service, err + } else { + p.i.GetThrottles().Service().Invalidate() + return service, err + } +} + +func (p servicesModV1) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.Service, err error) { + if service, err := p.client().Patch(ctx, name, pt, data, opts, subresources...); err != nil { + return service, err + } else { + p.i.GetThrottles().Service().Invalidate() + return service, err + } +} + +func (p servicesModV1) Delete(ctx context.Context, name string, opts meta.DeleteOptions) error { + if err := p.client().Delete(ctx, name, opts); err != nil { + return err + } else { + p.i.GetThrottles().Service().Invalidate() + return err + } +} diff --git a/pkg/deployment/resources/inspector/sm_mod.go b/pkg/deployment/resources/inspector/sm_mod.go new file mode 100644 index 000000000..9e4697747 --- /dev/null +++ b/pkg/deployment/resources/inspector/sm_mod.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" +) + +func (i *inspectorState) ServiceMonitorsModInterface() mods.ServiceMonitorsMods { + return serviceMonitorsMod{ + i: i, + } +} + +type serviceMonitorsMod struct { + i *inspectorState +} diff --git a/pkg/deployment/resources/inspector/sm_mod_v1.go b/pkg/deployment/resources/inspector/sm_mod_v1.go new file mode 100644 index 000000000..6e6c7786f --- /dev/null +++ b/pkg/deployment/resources/inspector/sm_mod_v1.go @@ -0,0 +1,79 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 inspector + +import ( + "context" + + serviceMonitorv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor/v1" + monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned/typed/monitoring/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" +) + +func (p serviceMonitorsMod) V1() serviceMonitorv1.ModInterface { + return serviceMonitorsModV1(p) +} + +type serviceMonitorsModV1 struct { + i *inspectorState +} + +func (p serviceMonitorsModV1) client() monitoringv1.ServiceMonitorInterface { + return p.i.Client().Monitoring().MonitoringV1().ServiceMonitors(p.i.Namespace()) +} + +func (p serviceMonitorsModV1) Create(ctx context.Context, serviceMonitor *monitoring.ServiceMonitor, opts meta.CreateOptions) (*monitoring.ServiceMonitor, error) { + if serviceMonitor, err := p.client().Create(ctx, serviceMonitor, opts); err != nil { + return serviceMonitor, err + } else { + p.i.GetThrottles().ServiceMonitor().Invalidate() + return serviceMonitor, err + } +} + +func (p serviceMonitorsModV1) Update(ctx context.Context, serviceMonitor *monitoring.ServiceMonitor, opts meta.UpdateOptions) (*monitoring.ServiceMonitor, error) { + if serviceMonitor, err := p.client().Update(ctx, serviceMonitor, opts); err != nil { + return serviceMonitor, err + } else { + p.i.GetThrottles().ServiceMonitor().Invalidate() + return serviceMonitor, err + } +} + +func (p serviceMonitorsModV1) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *monitoring.ServiceMonitor, err error) { + if serviceMonitor, err := p.client().Patch(ctx, name, pt, data, opts, subresources...); err != nil { + return serviceMonitor, err + } else { + p.i.GetThrottles().ServiceMonitor().Invalidate() + return serviceMonitor, err + } +} + +func (p serviceMonitorsModV1) Delete(ctx context.Context, name string, opts meta.DeleteOptions) error { + if err := p.client().Delete(ctx, name, opts); err != nil { + return err + } else { + p.i.GetThrottles().ServiceMonitor().Invalidate() + return err + } +} diff --git a/pkg/deployment/resources/labels.go b/pkg/deployment/resources/labels.go index 9dffd976f..06a4805df 100644 --- a/pkg/deployment/resources/labels.go +++ b/pkg/deployment/resources/labels.go @@ -74,7 +74,7 @@ func (r *Resources) EnsureSecretLabels(ctx context.Context, cachedStatus inspect if err := cachedStatus.Secret().V1().Iterate(func(secret *core.Secret) error { if ensureLabelsMap(secret.Kind, secret, r.context.GetSpec(), func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.SecretsModInterface().Patch(ctxChild, + _, err := cachedStatus.SecretsModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) @@ -101,7 +101,7 @@ func (r *Resources) EnsureServiceAccountsLabels(ctx context.Context, cachedStatu if err := cachedStatus.ServiceAccount().V1().Iterate(func(serviceAccount *core.ServiceAccount) error { if ensureLabelsMap(serviceAccount.Kind, serviceAccount, r.context.GetSpec(), func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.ServiceAccountsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) + _, err := cachedStatus.ServiceAccountsModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) }) { @@ -127,7 +127,7 @@ func (r *Resources) EnsureServicesLabels(ctx context.Context, cachedStatus inspe if err := cachedStatus.Service().V1().Iterate(func(service *core.Service) error { if ensureLabelsMap(service.Kind, service, r.context.GetSpec(), func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.ServicesModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) + _, err := cachedStatus.ServicesModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) }) { @@ -160,7 +160,7 @@ func (r *Resources) EnsureServiceMonitorsLabels(ctx context.Context, cachedStatu if err := i.Iterate(func(serviceMonitor *monitoring.ServiceMonitor) error { if ensureLabelsMap(serviceMonitor.Kind, serviceMonitor, r.context.GetSpec(), func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.ServiceMonitorsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) + _, err := cachedStatus.ServiceMonitorsModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) }) { @@ -186,7 +186,7 @@ func (r *Resources) EnsurePodsLabels(ctx context.Context, cachedStatus inspector if err := cachedStatus.Pod().V1().Iterate(func(pod *core.Pod) error { if ensureGroupLabelsMap(pod.Kind, pod, r.context.GetSpec(), func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.PodsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) + _, err := cachedStatus.PodsModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) }) { @@ -213,7 +213,7 @@ func (r *Resources) EnsurePersistentVolumeClaimsLabels(ctx context.Context, cach actionFn := func(persistentVolumeClaim *core.PersistentVolumeClaim) error { if ensureGroupLabelsMap(persistentVolumeClaim.Kind, persistentVolumeClaim, r.context.GetSpec(), func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.PersistentVolumeClaimsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) + _, err := cachedStatus.PersistentVolumeClaimsModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) }) { @@ -247,7 +247,7 @@ func (r *Resources) EnsurePodDisruptionBudgetsLabels(ctx context.Context, cached if err := i.Iterate(func(budget *policy.PodDisruptionBudget) error { if ensureLabelsMap(budget.Kind, budget, r.context.GetSpec(), func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.PodDisruptionBudgetsModInterface().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) + _, err := cachedStatus.PodDisruptionBudgetsModInterface().V1Beta1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) return err }) }) { diff --git a/pkg/deployment/resources/pdbs.go b/pkg/deployment/resources/pdbs.go index 9890b3544..af6e017b3 100644 --- a/pkg/deployment/resources/pdbs.go +++ b/pkg/deployment/resources/pdbs.go @@ -106,7 +106,7 @@ func newPDB(minAvail int, deplname string, group api.ServerGroup, owner meta.Own // ensurePDBForGroup ensure pdb for a specific server group, if wantMinAvail is zero, the PDB is removed and not recreated func (r *Resources) ensurePDBForGroup(ctx context.Context, group api.ServerGroup, wantedMinAvail int) error { - i, err := r.context.GetCachedStatus().PodDisruptionBudget().V1Beta1() + i, err := r.context.ACS().CurrentClusterCache().PodDisruptionBudget().V1Beta1() if err != nil { return err } @@ -128,7 +128,7 @@ func (r *Resources) ensurePDBForGroup(ctx context.Context, group api.ServerGroup pdb := newPDB(wantedMinAvail, deplname, group, r.context.GetAPIObject().AsOwner()) log.Debug().Msg("Creating new PDB") err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.PodDisruptionBudgetsModInterface().Create(ctxChild, pdb, meta.CreateOptions{}) + _, err := r.context.ACS().CurrentClusterCache().PodDisruptionBudgetsModInterface().V1Beta1().Create(ctxChild, pdb, meta.CreateOptions{}) return err }) if err != nil { @@ -153,7 +153,7 @@ func (r *Resources) ensurePDBForGroup(ctx context.Context, group api.ServerGroup if pdb.GetDeletionTimestamp() == nil { // Update the PDB err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return r.context.PodDisruptionBudgetsModInterface().Delete(ctxChild, pdbname, meta.DeleteOptions{}) + return r.context.ACS().CurrentClusterCache().PodDisruptionBudgetsModInterface().V1Beta1().Delete(ctxChild, pdbname, meta.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { log.Error().Err(err).Msg("PDB deletion failed") diff --git a/pkg/deployment/resources/pod_creator.go b/pkg/deployment/resources/pod_creator.go index 77bbcfb89..fb6f1e121 100644 --- a/pkg/deployment/resources/pod_creator.go +++ b/pkg/deployment/resources/pod_creator.go @@ -504,7 +504,7 @@ func (r *Resources) createPodForMember(ctx context.Context, cachedStatus inspect ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() - podName, uid, err := CreateArangoPod(ctxChild, r.context.PodsModInterface(), apiObject, spec, group, CreatePodFromTemplate(template.PodSpec)) + podName, uid, err := CreateArangoPod(ctxChild, cachedStatus.PodsModInterface().V1(), apiObject, spec, group, CreatePodFromTemplate(template.PodSpec)) if err != nil { return errors.WithStack(err) } @@ -547,7 +547,7 @@ func (r *Resources) createPodForMember(ctx context.Context, cachedStatus inspect } } owner := apiObject.AsOwner() - _, err = createTLSServerCertificate(ctx, log, cachedStatus, r.context.SecretsModInterface(), names, spec.Sync.TLS, tlsKeyfileSecretName, &owner) + _, err = createTLSServerCertificate(ctx, log, cachedStatus, cachedStatus.SecretsModInterface().V1(), names, spec.Sync.TLS, tlsKeyfileSecretName, &owner) if err != nil && !k8sutil.IsAlreadyExists(err) { return errors.WithStack(errors.Wrapf(err, "Failed to create TLS keyfile secret")) } @@ -555,7 +555,7 @@ func (r *Resources) createPodForMember(ctx context.Context, cachedStatus inspect ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() - podName, uid, err := CreateArangoPod(ctxChild, r.context.PodsModInterface(), apiObject, spec, group, CreatePodFromTemplate(template.PodSpec)) + podName, uid, err := CreateArangoPod(ctxChild, cachedStatus.PodsModInterface().V1(), apiObject, spec, group, CreatePodFromTemplate(template.PodSpec)) if err != nil { return errors.WithStack(err) } diff --git a/pkg/deployment/resources/pod_finalizers.go b/pkg/deployment/resources/pod_finalizers.go index 136cee88a..182cf4565 100644 --- a/pkg/deployment/resources/pod_finalizers.go +++ b/pkg/deployment/resources/pod_finalizers.go @@ -117,7 +117,7 @@ func (r *Resources) runPodFinalizers(ctx context.Context, p *v1.Pod, memberStatu } // Remove finalizers (if needed) if len(removalList) > 0 { - if _, err := k8sutil.RemovePodFinalizers(ctx, r.context.GetCachedStatus(), log, r.context.PodsModInterface(), p, removalList, false); err != nil { + if _, err := k8sutil.RemovePodFinalizers(ctx, r.context.ACS().CurrentClusterCache(), log, r.context.ACS().CurrentClusterCache().PodsModInterface().V1(), p, removalList, false); err != nil { log.Debug().Err(err).Msg("Failed to update pod (to remove finalizers)") return 0, errors.WithStack(err) } @@ -147,7 +147,7 @@ func (r *Resources) inspectFinalizerPodAgencyServing(ctx context.Context, log ze // of the agent, also remove the PVC if memberStatus.Conditions.IsTrue(api.ConditionTypeAgentRecoveryNeeded) { err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return r.context.PersistentVolumeClaimsModInterface().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, meta.DeleteOptions{}) + return r.context.ACS().CurrentClusterCache().PersistentVolumeClaimsModInterface().V1().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, meta.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { log.Warn().Err(err).Msg("Failed to delete PVC for member") @@ -176,7 +176,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 := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return r.context.PersistentVolumeClaimsModInterface().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, meta.DeleteOptions{}) + return r.context.ACS().CurrentClusterCache().PersistentVolumeClaimsModInterface().V1().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, meta.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { log.Warn().Err(err).Msg("Failed to delete PVC for member") diff --git a/pkg/deployment/resources/pod_inspector.go b/pkg/deployment/resources/pod_inspector.go index 73e8fb2fe..7819407ab 100644 --- a/pkg/deployment/resources/pod_inspector.go +++ b/pkg/deployment/resources/pod_inspector.go @@ -85,7 +85,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter // Strange, pod belongs to us, but we have no member for it. // Remove all finalizers, so it can be removed. log.Warn().Msg("Pod belongs to this deployment, but we don't know the member. Removing all finalizers") - _, err := k8sutil.RemovePodFinalizers(ctx, r.context.GetCachedStatus(), log, r.context.PodsModInterface(), pod, pod.GetFinalizers(), false) + _, err := k8sutil.RemovePodFinalizers(ctx, r.context.ACS().CurrentClusterCache(), log, cachedStatus.PodsModInterface().V1(), pod, pod.GetFinalizers(), false) if err != nil { log.Debug().Err(err).Msg("Failed to update pod (to remove all finalizers)") return errors.WithStack(err) diff --git a/pkg/deployment/resources/pod_leader.go b/pkg/deployment/resources/pod_leader.go index 32124457f..a921eae44 100644 --- a/pkg/deployment/resources/pod_leader.go +++ b/pkg/deployment/resources/pod_leader.go @@ -137,7 +137,7 @@ func (r *Resources) EnsureLeader(ctx context.Context, cachedStatus inspectorInte s := r.createService(leaderAgentSvcName, r.context.GetNamespace(), r.context.GetAPIObject().AsOwner(), shared.ArangoPort, selector) err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.ServicesModInterface().Create(ctxChild, s, meta.CreateOptions{}) + _, err := cachedStatus.ServicesModInterface().V1().Create(ctxChild, s, meta.CreateOptions{}) return err }) if err != nil { diff --git a/pkg/deployment/resources/pod_termination.go b/pkg/deployment/resources/pod_termination.go index 4660431de..6825ffccc 100644 --- a/pkg/deployment/resources/pod_termination.go +++ b/pkg/deployment/resources/pod_termination.go @@ -58,7 +58,7 @@ func (r *Resources) prepareAgencyPodTermination(ctx context.Context, log zerolog // Check node the pod is scheduled on. Only if not in namespaced scope agentDataWillBeGone := false - if nodes, err := r.context.GetCachedStatus().Node().V1(); err == nil { + if nodes, err := r.context.ACS().CurrentClusterCache().Node().V1(); err == nil { if !r.context.GetScope().IsNamespaced() && p.Spec.NodeName != "" { node, ok := nodes.GetSimple(p.Spec.NodeName) if !ok { @@ -72,7 +72,7 @@ func (r *Resources) prepareAgencyPodTermination(ctx context.Context, log zerolog // Check PVC ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() - pvc, err := r.context.GetCachedStatus().PersistentVolumeClaim().V1().Read().Get(ctxChild, memberStatus.PersistentVolumeClaimName, meta.GetOptions{}) + pvc, err := r.context.ACS().CurrentClusterCache().PersistentVolumeClaim().V1().Read().Get(ctxChild, memberStatus.PersistentVolumeClaimName, meta.GetOptions{}) if err != nil { log.Warn().Err(err).Msg("Failed to get PVC for member") return errors.WithStack(err) @@ -143,7 +143,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, log zerol // Check node the pod is scheduled on dbserverDataWillBeGone := false - if nodes, err := r.context.GetCachedStatus().Node().V1(); err == nil { + if nodes, err := r.context.ACS().CurrentClusterCache().Node().V1(); err == nil { node, ok := nodes.GetSimple(p.Spec.NodeName) if !ok { log.Warn().Msg("Node not found") @@ -157,7 +157,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, log zerol // Check PVC ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() - pvc, err := r.context.GetCachedStatus().PersistentVolumeClaim().V1().Read().Get(ctxChild, memberStatus.PersistentVolumeClaimName, meta.GetOptions{}) + pvc, err := r.context.ACS().CurrentClusterCache().PersistentVolumeClaim().V1().Read().Get(ctxChild, memberStatus.PersistentVolumeClaimName, meta.GetOptions{}) if err != nil { log.Warn().Err(err).Msg("Failed to get PVC for member") return errors.WithStack(err) diff --git a/pkg/deployment/resources/pvc_finalizers.go b/pkg/deployment/resources/pvc_finalizers.go index b4783ac88..4d6796183 100644 --- a/pkg/deployment/resources/pvc_finalizers.go +++ b/pkg/deployment/resources/pvc_finalizers.go @@ -60,7 +60,7 @@ func (r *Resources) runPVCFinalizers(ctx context.Context, p *v1.PersistentVolume } // Remove finalizers (if needed) if len(removalList) > 0 { - _, err := k8sutil.RemovePVCFinalizers(ctx, r.context.GetCachedStatus(), log, r.context.PersistentVolumeClaimsModInterface(), p, removalList, false) + _, err := k8sutil.RemovePVCFinalizers(ctx, r.context.ACS().CurrentClusterCache(), log, r.context.ACS().CurrentClusterCache().PersistentVolumeClaimsModInterface().V1(), p, removalList, false) if err != nil { log.Debug().Err(err).Msg("Failed to update PVC (to remove finalizers)") return 0, errors.WithStack(err) @@ -106,7 +106,7 @@ func (r *Resources) inspectFinalizerPVCMemberExists(ctx context.Context, log zer if memberStatus.PodName != "" { log.Info().Msg("Removing Pod of member, because PVC is being removed") err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return r.context.PodsModInterface().Delete(ctxChild, memberStatus.PodName, meta.DeleteOptions{}) + return r.context.ACS().CurrentClusterCache().PodsModInterface().V1().Delete(ctxChild, memberStatus.PodName, meta.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { log.Debug().Err(err).Msg("Failed to delete pod") diff --git a/pkg/deployment/resources/pvc_inspector.go b/pkg/deployment/resources/pvc_inspector.go index a1238b891..de90fbaa6 100644 --- a/pkg/deployment/resources/pvc_inspector.go +++ b/pkg/deployment/resources/pvc_inspector.go @@ -70,7 +70,7 @@ func (r *Resources) InspectPVCs(ctx context.Context, cachedStatus inspectorInter // Strange, pvc belongs to us, but we have no member for it. // Remove all finalizers, so it can be removed. log.Warn().Msg("PVC belongs to this deployment, but we don't know the member. Removing all finalizers") - _, err := k8sutil.RemovePVCFinalizers(ctx, r.context.GetCachedStatus(), log, r.context.PersistentVolumeClaimsModInterface(), pvc, pvc.GetFinalizers(), false) + _, err := k8sutil.RemovePVCFinalizers(ctx, r.context.ACS().CurrentClusterCache(), log, cachedStatus.PersistentVolumeClaimsModInterface().V1(), pvc, pvc.GetFinalizers(), false) if err != nil { log.Debug().Err(err).Msg("Failed to update PVC (to remove all finalizers)") return errors.WithStack(err) @@ -89,7 +89,7 @@ func (r *Resources) InspectPVCs(ctx context.Context, cachedStatus inspectorInter } err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.PersistentVolumeClaimsModInterface().Patch(ctxChild, pvc.GetName(), types.JSONPatchType, d, meta.PatchOptions{}) + _, err := cachedStatus.PersistentVolumeClaimsModInterface().V1().Patch(ctxChild, pvc.GetName(), types.JSONPatchType, d, meta.PatchOptions{}) return err }) diff --git a/pkg/deployment/resources/pvcs.go b/pkg/deployment/resources/pvcs.go index 3ba8e1447..8d460f165 100644 --- a/pkg/deployment/resources/pvcs.go +++ b/pkg/deployment/resources/pvcs.go @@ -62,7 +62,7 @@ func (r *Resources) EnsurePVCs(ctx context.Context, cachedStatus inspectorInterf vct := spec.VolumeClaimTemplate finalizers := r.createPVCFinalizers(group) err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return k8sutil.CreatePersistentVolumeClaim(ctxChild, r.context.PersistentVolumeClaimsModInterface(), + return k8sutil.CreatePersistentVolumeClaim(ctxChild, cachedStatus.PersistentVolumeClaimsModInterface().V1(), m.PersistentVolumeClaimName, deploymentName, storageClassName, role, enforceAntiAffinity, resources, vct, finalizers, owner) }) diff --git a/pkg/deployment/resources/secrets.go b/pkg/deployment/resources/secrets.go index 3509456e5..9a010812b 100644 --- a/pkg/deployment/resources/secrets.go +++ b/pkg/deployment/resources/secrets.go @@ -79,7 +79,7 @@ func GetCASecretName(apiObject k8sutil.APIObject) string { func (r *Resources) EnsureSecrets(ctx context.Context, log zerolog.Logger, cachedStatus inspectorInterface.Inspector) error { start := time.Now() spec := r.context.GetSpec() - secrets := r.context.SecretsModInterface() + secrets := cachedStatus.SecretsModInterface().V1() status, _ := r.context.GetStatus() apiObject := r.context.GetAPIObject() deploymentName := apiObject.GetName() @@ -554,7 +554,7 @@ func (r *Resources) getJWTSecret(spec api.DeploymentSpec) (string, error) { return "", nil } secretName := spec.Authentication.GetJWTSecretName() - s, err := k8sutil.GetTokenSecret(context.Background(), r.context.GetCachedStatus().Secret().V1().Read(), secretName) + s, err := k8sutil.GetTokenSecret(context.Background(), r.context.ACS().CurrentClusterCache().Secret().V1().Read(), secretName) if err != nil { r.log.Debug().Err(err).Str("secret-name", secretName).Msg("Failed to get JWT secret") return "", errors.WithStack(err) @@ -565,7 +565,7 @@ func (r *Resources) getJWTSecret(spec api.DeploymentSpec) (string, error) { // getSyncJWTSecret loads the JWT secret used for syncmasters from a Secret configured in apiObject.Spec.Sync.Authentication.JWTSecretName. func (r *Resources) getSyncJWTSecret(spec api.DeploymentSpec) (string, error) { secretName := spec.Sync.Authentication.GetJWTSecretName() - s, err := k8sutil.GetTokenSecret(context.Background(), r.context.GetCachedStatus().Secret().V1().Read(), secretName) + s, err := k8sutil.GetTokenSecret(context.Background(), r.context.ACS().CurrentClusterCache().Secret().V1().Read(), secretName) if err != nil { r.log.Debug().Err(err).Str("secret-name", secretName).Msg("Failed to get sync JWT secret") return "", errors.WithStack(err) @@ -576,7 +576,7 @@ func (r *Resources) getSyncJWTSecret(spec api.DeploymentSpec) (string, error) { // getSyncMonitoringToken loads the token secret used for monitoring sync masters & workers. func (r *Resources) getSyncMonitoringToken(spec api.DeploymentSpec) (string, error) { secretName := spec.Sync.Monitoring.GetTokenSecretName() - s, err := k8sutil.GetTokenSecret(context.Background(), r.context.GetCachedStatus().Secret().V1().Read(), secretName) + s, err := k8sutil.GetTokenSecret(context.Background(), r.context.ACS().CurrentClusterCache().Secret().V1().Read(), secretName) if err != nil { r.log.Debug().Err(err).Str("secret-name", secretName).Msg("Failed to get sync monitoring secret") return "", errors.WithStack(err) diff --git a/pkg/deployment/resources/services.go b/pkg/deployment/resources/services.go index 013ac9f64..cb6b597be 100644 --- a/pkg/deployment/resources/services.go +++ b/pkg/deployment/resources/services.go @@ -81,7 +81,7 @@ func (r *Resources) createService(name, namespace string, owner meta.OwnerRefere // adjustService checks whether service contains is valid and if not than it reconciles service. // Returns true if service is adjusted. func (r *Resources) adjustService(ctx context.Context, s *core.Service, targetPort int32, selector map[string]string) (error, bool) { - services := r.context.ServicesModInterface() + services := r.context.ACS().CurrentClusterCache().ServicesModInterface().V1() spec := s.Spec.DeepCopy() spec.Type = core.ServiceTypeClusterIP @@ -128,7 +128,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn counterMetric := inspectedServicesCounters.WithLabelValues(deploymentName) // Fetch existing services - svcs := r.context.ServicesModInterface() + svcs := cachedStatus.ServicesModInterface().V1() reconcileRequired := k8sutil.NewReconcile(cachedStatus) diff --git a/pkg/deployment/server_api.go b/pkg/deployment/server_api.go index b989441d9..02d206c1b 100644 --- a/pkg/deployment/server_api.go +++ b/pkg/deployment/server_api.go @@ -190,7 +190,7 @@ func (d *Deployment) StorageClasses() []string { // Empty string means that the database is not reachable outside the Kubernetes cluster. func (d *Deployment) DatabaseURL() string { eaSvcName := k8sutil.CreateDatabaseExternalAccessServiceName(d.Name()) - svc, err := d.currentState.Service().V1().Read().Get(context.Background(), eaSvcName, metav1.GetOptions{}) + svc, err := d.acs.CurrentClusterCache().Service().V1().Read().Get(context.Background(), eaSvcName, metav1.GetOptions{}) if err != nil { return "" } @@ -199,7 +199,7 @@ func (d *Deployment) DatabaseURL() string { scheme = "http" } nodeFetcher := func() ([]*core.Node, error) { - if n, err := d.currentState.Node().V1(); err != nil { + if n, err := d.acs.CurrentClusterCache().Node().V1(); err != nil { return nil, nil } else { return n.ListSimple(), nil diff --git a/pkg/util/k8sutil/inspector/endpoints/v1/reader.go b/pkg/util/k8sutil/inspector/endpoints/v1/reader.go index 45a3428be..dfd9e1d18 100644 --- a/pkg/util/k8sutil/inspector/endpoints/v1/reader.go +++ b/pkg/util/k8sutil/inspector/endpoints/v1/reader.go @@ -32,7 +32,6 @@ import ( type ModInterface interface { Create(ctx context.Context, endpoints *core.Endpoints, opts meta.CreateOptions) (*core.Endpoints, error) Update(ctx context.Context, endpoints *core.Endpoints, opts meta.UpdateOptions) (*core.Endpoints, error) - UpdateStatus(ctx context.Context, endpoints *core.Endpoints, opts meta.UpdateOptions) (*core.Endpoints, error) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.Endpoints, err error) Delete(ctx context.Context, name string, opts meta.DeleteOptions) error } diff --git a/pkg/util/k8sutil/inspector/inspector.go b/pkg/util/k8sutil/inspector/inspector.go index a3c7a6b49..7d952de83 100644 --- a/pkg/util/k8sutil/inspector/inspector.go +++ b/pkg/util/k8sutil/inspector/inspector.go @@ -33,6 +33,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget" @@ -85,4 +86,6 @@ type Inspector interface { node.Inspector arangoclustersynchronization.Inspector arangotask.Inspector + + mods.Mods } diff --git a/pkg/util/k8sutil/inspector/mods/mods.go b/pkg/util/k8sutil/inspector/mods/mods.go new file mode 100644 index 000000000..b26ec392f --- /dev/null +++ b/pkg/util/k8sutil/inspector/mods/mods.go @@ -0,0 +1,75 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 mods + +import ( + endpointsv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints/v1" + persistentvolumeclaimv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1" + podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1beta1" + secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" + servicev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" + serviceaccountv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount/v1" + servicemonitorv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor/v1" +) + +type PodsMods interface { + V1() podv1.ModInterface +} + +type ServiceAccountsMods interface { + V1() serviceaccountv1.ModInterface +} + +type SecretsMods interface { + V1() secretv1.ModInterface +} + +type PersistentVolumeClaimsMods interface { + V1() persistentvolumeclaimv1.ModInterface +} + +type ServicesMods interface { + V1() servicev1.ModInterface +} + +type EndpointsMods interface { + V1() endpointsv1.ModInterface +} + +type ServiceMonitorsMods interface { + V1() servicemonitorv1.ModInterface +} + +type PodDisruptionBudgetsMods interface { + V1Beta1() v1beta1.ModInterface +} + +type Mods interface { + PodsModInterface() PodsMods + ServiceAccountsModInterface() ServiceAccountsMods + SecretsModInterface() SecretsMods + PersistentVolumeClaimsModInterface() PersistentVolumeClaimsMods + ServicesModInterface() ServicesMods + EndpointsModInterface() EndpointsMods + ServiceMonitorsModInterface() ServiceMonitorsMods + PodDisruptionBudgetsModInterface() PodDisruptionBudgetsMods +}