diff --git a/CHANGELOG.md b/CHANGELOG.md index f8b164aa8..8028ddec7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - (Maintenance) Proto Lint - (Feature) (Integration) SchedulerV2 - (Feature) (Integration) Basic Envs +- (Maintenance) Inspector Generics ## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14) - (Feature) ArangoRoute CRD diff --git a/README.md b/README.md index f19fd9497..0edb27155 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ Flags: --kubernetes.max-batch-size int Size of batch during objects read (default 256) --kubernetes.qps float32 Number of queries per second for k8s API (default 15) --log.format string Set log format. Allowed values: 'pretty', 'JSON'. If empty, default format is used (default "pretty") - --log.level stringArray Set log levels in format or =. Possible loggers: action, agency, api-server, assertion, backup-operator, chaos-monkey, crd, deployment, deployment-ci, deployment-reconcile, deployment-replication, deployment-resilience, deployment-resources, deployment-storage, deployment-storage-pc, deployment-storage-service, generic-parent-operator, http, inspector, integration-config-v1, integration-envoy-auth-v3, integrations, k8s-client, kubernetes-informer, monitor, networking-route-operator, operator, operator-arangojob-handler, operator-v2, operator-v2-event, operator-v2-worker, panics, pod_compare, root, root-event-recorder, scheduler-batchjob-operator, scheduler-cronjob-operator, scheduler-deployment-operator, scheduler-pod-operator, scheduler-profile-operator, server, server-authentication (default [info]) + --log.level stringArray Set log levels in format or =. Possible loggers: action, agency, api-server, assertion, backup-operator, chaos-monkey, crd, deployment, deployment-ci, deployment-reconcile, deployment-replication, deployment-resilience, deployment-resources, deployment-storage, deployment-storage-pc, deployment-storage-service, generic-parent-operator, helm, http, inspector, integration-config-v1, integration-envoy-auth-v3, integration-scheduler-v2, integrations, k8s-client, kubernetes-informer, monitor, networking-route-operator, operator, operator-arangojob-handler, operator-v2, operator-v2-event, operator-v2-worker, panics, pod_compare, root, root-event-recorder, scheduler-batchjob-operator, scheduler-cronjob-operator, scheduler-deployment-operator, scheduler-pod-operator, scheduler-profile-operator, server, server-authentication (default [info]) --log.sampling If true, operator will try to minimize duplication of logging events (default true) --memory-limit uint Define memory limit for hard shutdown and the dump of goroutines. Used for testing --metrics.excluded-prefixes stringArray List of the excluded metrics prefixes diff --git a/cmd/admin.go b/cmd/admin.go index decdc9f80..266b8a7df 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -47,7 +47,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/kclient" ) @@ -296,7 +296,7 @@ func createClient(endpoints []string, certCA *x509.CertPool, auth connection.Aut } // getJWTTokenFromSecrets returns token from the secret. -func getJWTTokenFromSecrets(ctx context.Context, secrets secretv1.ReadInterface, name string) (connection.Authentication, error) { +func getJWTTokenFromSecrets(ctx context.Context, secrets generic.ReadClient[*core.Secret], name string) (connection.Authentication, error) { ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() @@ -314,7 +314,7 @@ func getJWTTokenFromSecrets(ctx context.Context, secrets secretv1.ReadInterface, } // getCACertificate returns CA certificate from the secret. -func getCACertificate(ctx context.Context, secrets secretv1.ReadInterface, name string) (*x509.CertPool, error) { +func getCACertificate(ctx context.Context, secrets generic.ReadClient[*core.Secret], name string) (*x509.CertPool, error) { ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() diff --git a/docs/cli/arangodb_operator.md b/docs/cli/arangodb_operator.md index 390ac513b..6702a4a1f 100644 --- a/docs/cli/arangodb_operator.md +++ b/docs/cli/arangodb_operator.md @@ -80,7 +80,7 @@ Flags: --kubernetes.max-batch-size int Size of batch during objects read (default 256) --kubernetes.qps float32 Number of queries per second for k8s API (default 15) --log.format string Set log format. Allowed values: 'pretty', 'JSON'. If empty, default format is used (default "pretty") - --log.level stringArray Set log levels in format or =. Possible loggers: action, agency, api-server, assertion, backup-operator, chaos-monkey, crd, deployment, deployment-ci, deployment-reconcile, deployment-replication, deployment-resilience, deployment-resources, deployment-storage, deployment-storage-pc, deployment-storage-service, generic-parent-operator, http, inspector, integration-config-v1, integration-envoy-auth-v3, integrations, k8s-client, kubernetes-informer, monitor, networking-route-operator, operator, operator-arangojob-handler, operator-v2, operator-v2-event, operator-v2-worker, panics, pod_compare, root, root-event-recorder, scheduler-batchjob-operator, scheduler-cronjob-operator, scheduler-deployment-operator, scheduler-pod-operator, scheduler-profile-operator, server, server-authentication (default [info]) + --log.level stringArray Set log levels in format or =. Possible loggers: action, agency, api-server, assertion, backup-operator, chaos-monkey, crd, deployment, deployment-ci, deployment-reconcile, deployment-replication, deployment-resilience, deployment-resources, deployment-storage, deployment-storage-pc, deployment-storage-service, generic-parent-operator, helm, http, inspector, integration-config-v1, integration-envoy-auth-v3, integration-scheduler-v2, integrations, k8s-client, kubernetes-informer, monitor, networking-route-operator, operator, operator-arangojob-handler, operator-v2, operator-v2-event, operator-v2-worker, panics, pod_compare, root, root-event-recorder, scheduler-batchjob-operator, scheduler-cronjob-operator, scheduler-deployment-operator, scheduler-pod-operator, scheduler-profile-operator, server, server-authentication (default [info]) --log.sampling If true, operator will try to minimize duplication of logging events (default true) --memory-limit uint Define memory limit for hard shutdown and the dump of goroutines. Used for testing --metrics.excluded-prefixes stringArray List of the excluded metrics prefixes diff --git a/docs/cli/arangodb_operator_integration.md b/docs/cli/arangodb_operator_integration.md index f0bbe9a5c..5412debd9 100644 --- a/docs/cli/arangodb_operator_integration.md +++ b/docs/cli/arangodb_operator_integration.md @@ -51,6 +51,11 @@ Flags: --integration.scheduler.v1.internal Defones if Internal access to service scheduler.v1 is enabled (Env: INTEGRATION_SCHEDULER_V1_INTERNAL) (default true) --integration.scheduler.v1.namespace string Kubernetes Namespace (Env: INTEGRATION_SCHEDULER_V1_NAMESPACE) (default "default") --integration.scheduler.v1.verify-access Verify the CRD Access (Env: INTEGRATION_SCHEDULER_V1_VERIFY_ACCESS) (default true) + --integration.scheduler.v2 SchedulerV2 Integration (Env: INTEGRATION_SCHEDULER_V2) + --integration.scheduler.v2.deployment string ArangoDeployment Name (Env: INTEGRATION_SCHEDULER_V2_DEPLOYMENT) + --integration.scheduler.v2.external Defones if External access to service scheduler.v2 is enabled (Env: INTEGRATION_SCHEDULER_V2_EXTERNAL) + --integration.scheduler.v2.internal Defones if Internal access to service scheduler.v2 is enabled (Env: INTEGRATION_SCHEDULER_V2_INTERNAL) (default true) + --integration.scheduler.v2.namespace string Kubernetes Namespace (Env: INTEGRATION_SCHEDULER_V2_NAMESPACE) (default "default") --integration.shutdown.v1 ShutdownV1 Handler (Env: INTEGRATION_SHUTDOWN_V1) --integration.shutdown.v1.external Defones if External access to service shutdown.v1 is enabled (Env: INTEGRATION_SHUTDOWN_V1_EXTERNAL) --integration.shutdown.v1.internal Defones if Internal access to service shutdown.v1 is enabled (Env: INTEGRATION_SHUTDOWN_V1_INTERNAL) (default true) diff --git a/pkg/api/jwt.go b/pkg/api/jwt.go index 4e6a99d08..8621da4e8 100644 --- a/pkg/api/jwt.go +++ b/pkg/api/jwt.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,13 +26,14 @@ import ( "time" jg "github.com/golang-jwt/jwt" + core "k8s.io/api/core/v1" typedCore "k8s.io/client-go/kubernetes/typed/core/v1" "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - secret "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" ) @@ -67,7 +68,7 @@ func ensureJWT(cli typedCore.CoreV1Interface, cfg ServerConfig) (string, error) // generateAndSaveJWT tries to generate new JWT using signing key retrieved from secret. // If it is not present, it creates a new key. // The resulting JWT is stored in secrets. -func generateAndSaveJWT(secrets secret.Interface, cfg ServerConfig) error { +func generateAndSaveJWT(secrets generic.InspectorInterface[*core.Secret], cfg ServerConfig) error { claims := jg.MapClaims{ "iss": fmt.Sprintf("kube-arangodb/%s", cfg.ServerName), "iat": time.Now().Unix(), @@ -79,7 +80,7 @@ func generateAndSaveJWT(secrets secret.Interface, cfg ServerConfig) error { return err } -func createSigningKey(secrets secret.ModInterface, keySecretName string) (string, error) { +func createSigningKey(secrets generic.ModClient[*core.Secret], keySecretName string) (string, error) { signingKey := make([]byte, 32) _, err := util.Rand().Read(signingKey) if err != nil { diff --git a/pkg/crd/crds/analytics-graphanalyticsengine.schema.generated.yaml b/pkg/crd/crds/analytics-graphanalyticsengine.schema.generated.yaml index 2c3f7244f..eff820c4c 100644 --- a/pkg/crd/crds/analytics-graphanalyticsengine.schema.generated.yaml +++ b/pkg/crd/crds/analytics-graphanalyticsengine.schema.generated.yaml @@ -619,6 +619,13 @@ v1alpha1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -655,6 +662,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -769,6 +778,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -786,6 +797,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -962,6 +980,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1348,6 +1368,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -1991,6 +2018,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -2006,6 +2035,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -2137,6 +2173,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: diff --git a/pkg/crd/crds/apps-job.schema.generated.yaml b/pkg/crd/crds/apps-job.schema.generated.yaml index c89c53c1f..3974be78d 100644 --- a/pkg/crd/crds/apps-job.schema.generated.yaml +++ b/pkg/crd/crds/apps-job.schema.generated.yaml @@ -23,6 +23,8 @@ v1: completions: format: int32 type: integer + managedBy: + type: string manualSelector: type: boolean maxFailedIndexes: @@ -84,6 +86,19 @@ v1: type: string type: object type: object + successPolicy: + properties: + rules: + items: + properties: + succeededCount: + format: int32 + type: integer + succeededIndexes: + type: string + type: object + type: array + type: object suspend: type: boolean template: @@ -842,6 +857,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -859,6 +876,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1009,6 +1033,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1383,6 +1409,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1400,6 +1428,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1552,6 +1587,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1930,6 +1967,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1947,6 +1986,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -2097,6 +2143,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2141,13 +2189,10 @@ v1: properties: name: type: string - source: - properties: - resourceClaimName: - type: string - resourceClaimTemplateName: - type: string - type: object + resourceClaimName: + type: string + resourceClaimTemplateName: + type: string type: object type: array restartPolicy: @@ -2165,6 +2210,13 @@ v1: type: array securityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -2201,6 +2253,8 @@ v1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -2674,6 +2728,13 @@ v1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: diff --git a/pkg/crd/crds/database-deployment.schema.generated.yaml b/pkg/crd/crds/database-deployment.schema.generated.yaml index 76649f8de..8286063a4 100644 --- a/pkg/crd/crds/database-deployment.schema.generated.yaml +++ b/pkg/crd/crds/database-deployment.schema.generated.yaml @@ -695,6 +695,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -712,6 +714,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -862,6 +871,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1168,6 +1179,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1625,6 +1638,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1642,6 +1657,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1792,6 +1814,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2052,6 +2076,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2914,6 +2940,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -2931,6 +2959,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -3081,6 +3116,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -3387,6 +3424,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -3844,6 +3883,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -3861,6 +3902,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -4011,6 +4059,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -4271,6 +4321,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -5051,6 +5103,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -5068,6 +5122,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -5218,6 +5279,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -5524,6 +5587,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -5981,6 +6046,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -5998,6 +6065,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -6148,6 +6222,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -6408,6 +6484,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -7270,6 +7348,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -7287,6 +7367,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -7437,6 +7524,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -7743,6 +7832,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -8200,6 +8291,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -8217,6 +8310,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -8367,6 +8467,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -8627,6 +8729,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -9071,6 +9175,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -9543,6 +9649,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -9558,6 +9666,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -9689,6 +9804,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -9737,6 +9854,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -9798,6 +9917,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -10583,6 +10704,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -10600,6 +10723,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -10750,6 +10880,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -11056,6 +11188,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -11513,6 +11647,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -11530,6 +11666,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -11680,6 +11823,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -11940,6 +12085,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -12863,6 +13010,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -12880,6 +13029,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -13030,6 +13186,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -13336,6 +13494,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -13793,6 +13953,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -13810,6 +13972,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -13960,6 +14129,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -14220,6 +14391,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -14993,6 +15166,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -15010,6 +15185,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -15160,6 +15342,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -15466,6 +15650,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -15923,6 +16109,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -15940,6 +16128,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -16090,6 +16285,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -16350,6 +16547,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -17223,6 +17422,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -17240,6 +17441,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -17390,6 +17598,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -17696,6 +17906,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -18153,6 +18365,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -18170,6 +18384,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -18320,6 +18541,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -18580,6 +18803,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -19442,6 +19667,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -19459,6 +19686,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -19609,6 +19843,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -19915,6 +20151,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -20372,6 +20610,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -20389,6 +20629,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -20539,6 +20786,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -20799,6 +21048,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -21579,6 +21830,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -21596,6 +21849,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -21746,6 +22006,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -22052,6 +22314,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -22509,6 +22773,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -22526,6 +22792,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -22676,6 +22949,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -22936,6 +23211,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -23798,6 +24075,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -23815,6 +24094,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -23965,6 +24251,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -24271,6 +24559,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -24728,6 +25018,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -24745,6 +25037,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -24895,6 +25194,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -25155,6 +25456,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -25599,6 +25902,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -26071,6 +26376,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -26086,6 +26393,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -26217,6 +26531,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -26265,6 +26581,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -26326,6 +26644,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -27111,6 +27431,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -27128,6 +27450,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -27278,6 +27607,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -27584,6 +27915,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -28041,6 +28374,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -28058,6 +28393,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -28208,6 +28550,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -28468,6 +28812,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -29391,6 +29737,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -29408,6 +29756,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -29558,6 +29913,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -29864,6 +30221,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -30321,6 +30680,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -30338,6 +30699,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -30488,6 +30856,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -30748,6 +31118,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -31521,6 +31893,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -31538,6 +31912,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -31688,6 +32069,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -31994,6 +32377,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -32451,6 +32836,8 @@ v1alpha: properties: name: type: string + request: + type: string type: object type: array limits: @@ -32468,6 +32855,13 @@ v1alpha: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -32618,6 +33012,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -32878,6 +33274,8 @@ v1alpha: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -33751,6 +34149,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -33768,6 +34168,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -33918,6 +34325,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -34224,6 +34633,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -34681,6 +35092,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -34698,6 +35111,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -34848,6 +35268,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -35108,6 +35530,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -35970,6 +36394,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -35987,6 +36413,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -36137,6 +36570,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -36443,6 +36878,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -36900,6 +37337,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -36917,6 +37356,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -37067,6 +37513,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -37327,6 +37775,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -38107,6 +38557,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -38124,6 +38576,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -38274,6 +38733,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -38580,6 +39041,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -39037,6 +39500,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -39054,6 +39519,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -39204,6 +39676,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -39464,6 +39938,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -40326,6 +40802,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -40343,6 +40821,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -40493,6 +40978,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -40799,6 +41286,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -41256,6 +41745,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -41273,6 +41764,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -41423,6 +41921,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -41683,6 +42183,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -42127,6 +42629,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -42599,6 +43103,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -42614,6 +43120,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -42745,6 +43258,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -42793,6 +43308,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -42854,6 +43371,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -43639,6 +44158,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -43656,6 +44177,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -43806,6 +44334,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -44112,6 +44642,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -44569,6 +45101,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -44586,6 +45120,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -44736,6 +45277,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -44996,6 +45539,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -45919,6 +46464,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -45936,6 +46483,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -46086,6 +46640,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -46392,6 +46948,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -46849,6 +47407,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -46866,6 +47426,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -47016,6 +47583,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -47276,6 +47845,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -48049,6 +48620,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -48066,6 +48639,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -48216,6 +48796,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -48522,6 +49104,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -48979,6 +49563,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -48996,6 +49582,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -49146,6 +49739,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -49406,6 +50001,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: diff --git a/pkg/crd/crds/database-member.schema.generated.yaml b/pkg/crd/crds/database-member.schema.generated.yaml index 0582ff8ca..54c387a9b 100644 --- a/pkg/crd/crds/database-member.schema.generated.yaml +++ b/pkg/crd/crds/database-member.schema.generated.yaml @@ -29,6 +29,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1005,6 +1007,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1022,6 +1026,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1172,6 +1183,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1546,6 +1559,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1563,6 +1578,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1715,6 +1737,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2093,6 +2117,8 @@ v1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -2110,6 +2136,13 @@ v1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -2260,6 +2293,8 @@ v1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2304,13 +2339,10 @@ v1: properties: name: type: string - source: - properties: - resourceClaimName: - type: string - resourceClaimTemplateName: - type: string - type: object + resourceClaimName: + type: string + resourceClaimTemplateName: + type: string type: object type: array restartPolicy: @@ -2328,6 +2360,13 @@ v1: type: array securityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -2364,6 +2403,8 @@ v1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -2837,6 +2878,13 @@ v1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -3180,6 +3228,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -4156,6 +4206,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -4173,6 +4225,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -4323,6 +4382,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -4697,6 +4758,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -4714,6 +4777,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -4866,6 +4936,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -5244,6 +5316,8 @@ v2alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -5261,6 +5335,13 @@ v2alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -5411,6 +5492,8 @@ v2alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -5455,13 +5538,10 @@ v2alpha1: properties: name: type: string - source: - properties: - resourceClaimName: - type: string - resourceClaimTemplateName: - type: string - type: object + resourceClaimName: + type: string + resourceClaimTemplateName: + type: string type: object type: array restartPolicy: @@ -5479,6 +5559,13 @@ v2alpha1: type: array securityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -5515,6 +5602,8 @@ v2alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -5988,6 +6077,13 @@ v2alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: diff --git a/pkg/crd/crds/ml-extension.schema.generated.yaml b/pkg/crd/crds/ml-extension.schema.generated.yaml index 17e450dfe..e5ff82aa6 100644 --- a/pkg/crd/crds/ml-extension.schema.generated.yaml +++ b/pkg/crd/crds/ml-extension.schema.generated.yaml @@ -620,6 +620,13 @@ v1alpha1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -656,6 +663,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -774,6 +783,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -791,6 +802,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -967,6 +985,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1353,6 +1373,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -2270,6 +2297,13 @@ v1alpha1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -2306,6 +2340,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -2416,6 +2452,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -2433,6 +2471,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -2584,6 +2629,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2970,6 +3017,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -3893,6 +3947,13 @@ v1alpha1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -3929,6 +3990,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -4039,6 +4102,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -4056,6 +4121,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -4207,6 +4279,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -4593,6 +4667,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -5510,6 +5591,13 @@ v1alpha1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -5546,6 +5634,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -5656,6 +5746,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -5673,6 +5765,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -5824,6 +5923,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -6210,6 +6311,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -7131,6 +7239,13 @@ v1alpha1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -7167,6 +7282,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -7277,6 +7394,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -7294,6 +7413,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -7445,6 +7571,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -7831,6 +7959,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -8748,6 +8883,13 @@ v1alpha1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -8784,6 +8926,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -8894,6 +9038,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -8911,6 +9057,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -9062,6 +9215,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -9448,6 +9603,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -10369,6 +10531,13 @@ v1alpha1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -10405,6 +10574,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -10515,6 +10686,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -10532,6 +10705,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -10683,6 +10863,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -11069,6 +11251,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -11986,6 +12175,13 @@ v1alpha1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -12022,6 +12218,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -12132,6 +12330,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -12149,6 +12349,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -12300,6 +12507,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -12686,6 +12895,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -13649,6 +13865,13 @@ v1beta1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -13685,6 +13908,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -13801,6 +14026,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -13818,6 +14045,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -13985,6 +14219,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -14371,6 +14607,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -15289,6 +15532,13 @@ v1beta1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -15325,6 +15575,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -15435,6 +15687,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -15452,6 +15706,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -15603,6 +15864,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -15989,6 +16252,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -16628,6 +16898,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -16643,6 +16915,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -16774,6 +17053,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -17402,6 +17683,13 @@ v1beta1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -17438,6 +17726,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -17548,6 +17838,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -17565,6 +17857,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -17716,6 +18015,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -18102,6 +18403,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -19020,6 +19328,13 @@ v1beta1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -19056,6 +19371,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -19166,6 +19483,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -19183,6 +19502,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -19334,6 +19660,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -19720,6 +20048,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -20641,6 +20976,13 @@ v1beta1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -20677,6 +21019,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -20787,6 +21131,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -20804,6 +21150,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -20955,6 +21308,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -21341,6 +21696,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -22259,6 +22621,13 @@ v1beta1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -22295,6 +22664,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -22405,6 +22776,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -22422,6 +22795,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -22573,6 +22953,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -22959,6 +23341,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -23880,6 +24269,13 @@ v1beta1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -23916,6 +24312,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -24026,6 +24424,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -24043,6 +24443,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -24194,6 +24601,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -24580,6 +24989,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -25498,6 +25914,13 @@ v1beta1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -25534,6 +25957,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -25644,6 +26069,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -25661,6 +26088,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -25812,6 +26246,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -26198,6 +26634,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: diff --git a/pkg/crd/crds/ml-job-batch.schema.generated.yaml b/pkg/crd/crds/ml-job-batch.schema.generated.yaml index c3710170e..241368011 100644 --- a/pkg/crd/crds/ml-job-batch.schema.generated.yaml +++ b/pkg/crd/crds/ml-job-batch.schema.generated.yaml @@ -17,6 +17,8 @@ v1alpha1: completions: format: int32 type: integer + managedBy: + type: string manualSelector: type: boolean maxFailedIndexes: @@ -78,6 +80,19 @@ v1alpha1: type: string type: object type: object + successPolicy: + properties: + rules: + items: + properties: + succeededCount: + format: int32 + type: integer + succeededIndexes: + type: string + type: object + type: array + type: object suspend: type: boolean template: @@ -836,6 +851,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -853,6 +870,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1003,6 +1027,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1377,6 +1403,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1394,6 +1422,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1546,6 +1581,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1924,6 +1961,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1941,6 +1980,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -2091,6 +2137,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2135,13 +2183,10 @@ v1alpha1: properties: name: type: string - source: - properties: - resourceClaimName: - type: string - resourceClaimTemplateName: - type: string - type: object + resourceClaimName: + type: string + resourceClaimTemplateName: + type: string type: object type: array restartPolicy: @@ -2159,6 +2204,13 @@ v1alpha1: type: array securityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -2195,6 +2247,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -2668,6 +2722,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: diff --git a/pkg/crd/crds/ml-job-cron.schema.generated.yaml b/pkg/crd/crds/ml-job-cron.schema.generated.yaml index daf4b5fe8..7873cad9e 100644 --- a/pkg/crd/crds/ml-job-cron.schema.generated.yaml +++ b/pkg/crd/crds/ml-job-cron.schema.generated.yaml @@ -102,6 +102,8 @@ v1alpha1: completions: format: int32 type: integer + managedBy: + type: string manualSelector: type: boolean maxFailedIndexes: @@ -163,6 +165,19 @@ v1alpha1: type: string type: object type: object + successPolicy: + properties: + rules: + items: + properties: + succeededCount: + format: int32 + type: integer + succeededIndexes: + type: string + type: object + type: array + type: object suspend: type: boolean template: @@ -921,6 +936,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -938,6 +955,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1088,6 +1112,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1462,6 +1488,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1479,6 +1507,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1631,6 +1666,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2009,6 +2046,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -2026,6 +2065,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -2176,6 +2222,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2220,13 +2268,10 @@ v1alpha1: properties: name: type: string - source: - properties: - resourceClaimName: - type: string - resourceClaimTemplateName: - type: string - type: object + resourceClaimName: + type: string + resourceClaimTemplateName: + type: string type: object type: array restartPolicy: @@ -2244,6 +2289,13 @@ v1alpha1: type: array securityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -2280,6 +2332,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -2753,6 +2807,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: diff --git a/pkg/crd/crds/ml-storage.schema.generated.yaml b/pkg/crd/crds/ml-storage.schema.generated.yaml index 1a235f2a7..ba6474cfd 100644 --- a/pkg/crd/crds/ml-storage.schema.generated.yaml +++ b/pkg/crd/crds/ml-storage.schema.generated.yaml @@ -408,6 +408,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -423,6 +425,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -554,6 +563,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: diff --git a/pkg/crd/crds/scheduler-batchjob.schema.generated.yaml b/pkg/crd/crds/scheduler-batchjob.schema.generated.yaml index ffa23976a..eeaf58df4 100644 --- a/pkg/crd/crds/scheduler-batchjob.schema.generated.yaml +++ b/pkg/crd/crds/scheduler-batchjob.schema.generated.yaml @@ -17,6 +17,8 @@ v1beta1: completions: format: int32 type: integer + managedBy: + type: string manualSelector: type: boolean maxFailedIndexes: @@ -82,6 +84,19 @@ v1beta1: type: string type: object type: object + successPolicy: + properties: + rules: + items: + properties: + succeededCount: + format: int32 + type: integer + succeededIndexes: + type: string + type: object + type: array + type: object suspend: type: boolean template: @@ -840,6 +855,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -857,6 +874,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1007,6 +1031,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1381,6 +1407,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1398,6 +1426,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1550,6 +1585,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1928,6 +1965,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1945,6 +1984,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -2095,6 +2141,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2139,13 +2187,10 @@ v1beta1: properties: name: type: string - source: - properties: - resourceClaimName: - type: string - resourceClaimTemplateName: - type: string - type: object + resourceClaimName: + type: string + resourceClaimTemplateName: + type: string type: object type: array restartPolicy: @@ -2163,6 +2208,13 @@ v1beta1: type: array securityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -2199,6 +2251,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -2672,6 +2726,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: diff --git a/pkg/crd/crds/scheduler-cronjob.schema.generated.yaml b/pkg/crd/crds/scheduler-cronjob.schema.generated.yaml index a37961c59..1913cbbcf 100644 --- a/pkg/crd/crds/scheduler-cronjob.schema.generated.yaml +++ b/pkg/crd/crds/scheduler-cronjob.schema.generated.yaml @@ -102,6 +102,8 @@ v1beta1: completions: format: int32 type: integer + managedBy: + type: string manualSelector: type: boolean maxFailedIndexes: @@ -163,6 +165,19 @@ v1beta1: type: string type: object type: object + successPolicy: + properties: + rules: + items: + properties: + succeededCount: + format: int32 + type: integer + succeededIndexes: + type: string + type: object + type: array + type: object suspend: type: boolean template: @@ -921,6 +936,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -938,6 +955,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1088,6 +1112,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1462,6 +1488,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1479,6 +1507,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1631,6 +1666,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2009,6 +2046,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -2026,6 +2065,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -2176,6 +2222,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2220,13 +2268,10 @@ v1beta1: properties: name: type: string - source: - properties: - resourceClaimName: - type: string - resourceClaimTemplateName: - type: string - type: object + resourceClaimName: + type: string + resourceClaimTemplateName: + type: string type: object type: array restartPolicy: @@ -2244,6 +2289,13 @@ v1beta1: type: array securityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -2280,6 +2332,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -2753,6 +2807,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: diff --git a/pkg/crd/crds/scheduler-deployment.schema.generated.yaml b/pkg/crd/crds/scheduler-deployment.schema.generated.yaml index 7956b594d..b05cef7ad 100644 --- a/pkg/crd/crds/scheduler-deployment.schema.generated.yaml +++ b/pkg/crd/crds/scheduler-deployment.schema.generated.yaml @@ -811,6 +811,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -828,6 +830,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -978,6 +987,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1352,6 +1363,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1369,6 +1382,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1521,6 +1541,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1899,6 +1921,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1916,6 +1940,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -2066,6 +2097,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2110,13 +2143,10 @@ v1beta1: properties: name: type: string - source: - properties: - resourceClaimName: - type: string - resourceClaimTemplateName: - type: string - type: object + resourceClaimName: + type: string + resourceClaimTemplateName: + type: string type: object type: array restartPolicy: @@ -2134,6 +2164,13 @@ v1beta1: type: array securityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -2170,6 +2207,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -2643,6 +2682,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: diff --git a/pkg/crd/crds/scheduler-pod.schema.generated.yaml b/pkg/crd/crds/scheduler-pod.schema.generated.yaml index d38077167..ff933e2f7 100644 --- a/pkg/crd/crds/scheduler-pod.schema.generated.yaml +++ b/pkg/crd/crds/scheduler-pod.schema.generated.yaml @@ -679,6 +679,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -696,6 +698,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -846,6 +855,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1220,6 +1231,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1237,6 +1250,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1389,6 +1409,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1767,6 +1789,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -1784,6 +1808,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -1934,6 +1965,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -1982,13 +2015,10 @@ v1beta1: properties: name: type: string - source: - properties: - resourceClaimName: - type: string - resourceClaimTemplateName: - type: string - type: object + resourceClaimName: + type: string + resourceClaimTemplateName: + type: string type: object type: array restartPolicy: @@ -2006,6 +2036,13 @@ v1beta1: type: array securityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -2042,6 +2079,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -2515,6 +2554,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: diff --git a/pkg/crd/crds/scheduler-profile.schema.generated.yaml b/pkg/crd/crds/scheduler-profile.schema.generated.yaml index 04ddea193..32d5ca1dd 100644 --- a/pkg/crd/crds/scheduler-profile.schema.generated.yaml +++ b/pkg/crd/crds/scheduler-profile.schema.generated.yaml @@ -113,6 +113,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -449,6 +451,8 @@ v1alpha1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -464,6 +468,13 @@ v1alpha1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -595,6 +606,8 @@ v1alpha1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -982,6 +995,13 @@ v1alpha1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -1018,6 +1038,8 @@ v1alpha1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -1441,6 +1463,13 @@ v1alpha1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: @@ -1864,6 +1893,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2202,6 +2233,8 @@ v1beta1: properties: name: type: string + request: + type: string type: object type: array limits: @@ -2217,6 +2250,13 @@ v1beta1: properties: allowPrivilegeEscalation: type: boolean + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object capabilities: properties: add: @@ -2348,6 +2388,8 @@ v1beta1: type: string readOnly: type: boolean + recursiveReadOnly: + type: string subPath: type: string subPathExpr: @@ -2735,6 +2777,13 @@ v1beta1: type: array podSecurityContext: properties: + appArmorProfile: + properties: + localhostProfile: + type: string + type: + type: string + type: object fsGroup: format: int64 type: integer @@ -2771,6 +2820,8 @@ v1beta1: format: int64 type: integer type: array + supplementalGroupsPolicy: + type: string sysctls: items: properties: @@ -3194,6 +3245,13 @@ v1beta1: type: type: string type: object + image: + properties: + pullPolicy: + type: string + reference: + type: string + type: object iscsi: properties: chapAuthDiscovery: diff --git a/pkg/debug_package/generators/kubernetes/lister.go b/pkg/debug_package/generators/kubernetes/lister.go index bbde1f949..e580d3643 100644 --- a/pkg/debug_package/generators/kubernetes/lister.go +++ b/pkg/debug_package/generators/kubernetes/lister.go @@ -24,60 +24,11 @@ import ( "context" meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "github.com/arangodb/kube-arangodb/pkg/util" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" ) -type ObjectList[T meta.Object] map[types.UID]T - -func (d ObjectList[T]) ByName(name string) (T, bool) { - for _, obj := range d { - if obj.GetName() == name { - return obj, true - } - } - - return util.Default[T](), false -} - -func (d ObjectList[T]) AsList() util.List[T] { - list := make([]T, 0, len(d)) - for _, p := range d { - list = append(list, p) - } - - return list -} - -func MapObjects[L generic.ListContinue, T meta.Object](ctx context.Context, k generic.ListInterface[L], extract func(result L) []T) (ObjectList[T], error) { - objects := ObjectList[T]{} - - if err := k8sutil.APIList[L](ctx, k, meta.ListOptions{}, func(result L, err error) error { - if err != nil { - return err - } - for _, obj := range extract(result) { - obj.SetManagedFields(nil) - - objects[obj.GetUID()] = obj - } - - return nil - }); err != nil { - return nil, err - } - - return objects, nil -} - func ListObjects[L generic.ListContinue, T meta.Object](ctx context.Context, k generic.ListInterface[L], extract func(result L) []T) ([]T, error) { - objects, err := MapObjects[L, T](ctx, k, extract) - if err != nil { - return nil, err - } - - return objects.AsList(), nil + return list.APIList[L, T](ctx, k, meta.ListOptions{}, extract) } diff --git a/pkg/deployment/cleanup.go b/pkg/deployment/cleanup.go index e621efb31..d0320588c 100644 --- a/pkg/deployment/cleanup.go +++ b/pkg/deployment/cleanup.go @@ -31,8 +31,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - pvcv1 "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/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" ) @@ -63,7 +62,7 @@ func (d *Deployment) removePodFinalizers(ctx context.Context, cachedStatus inspe } } return nil - }, podv1.FilterPodsByLabels(k8sutil.LabelsForDeployment(d.GetName(), ""))); err != nil { + }, generic.FilterByLabels[*core.Pod](k8sutil.LabelsForDeployment(d.GetName(), ""))); err != nil { return false, err } @@ -85,7 +84,7 @@ func (d *Deployment) removePVCFinalizers(ctx context.Context, cachedStatus inspe found = true } return nil - }, pvcv1.FilterPersistentVolumeClaimsByLabels(k8sutil.LabelsForDeployment(d.GetName(), ""))); err != nil { + }, generic.FilterByLabels[*core.PersistentVolumeClaim](k8sutil.LabelsForDeployment(d.GetName(), ""))); err != nil { return false, err } diff --git a/pkg/deployment/context_impl.go b/pkg/deployment/context_impl.go index a2c1b0668..f3f151231 100644 --- a/pkg/deployment/context_impl.go +++ b/pkg/deployment/context_impl.go @@ -26,7 +26,9 @@ import ( "net" "strconv" + monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" core "k8s.io/api/core/v1" + policy "k8s.io/api/policy/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -57,13 +59,7 @@ import ( operatorHTTP "github.com/arangodb/kube-arangodb/pkg/util/http" "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" - poddisruptionbudgetv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1" - 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" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" "github.com/arangodb/kube-arangodb/pkg/util/kclient" ) @@ -557,37 +553,37 @@ func (d *Deployment) WithStatusUpdate(ctx context.Context, action reconciler.Dep }) } -func (d *Deployment) SecretsModInterface() secretv1.ModInterface { +func (d *Deployment) SecretsModInterface() generic.ModClient[*core.Secret] { d.acs.CurrentClusterCache().GetThrottles().Secret().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).Secrets() } -func (d *Deployment) PodsModInterface() podv1.ModInterface { +func (d *Deployment) PodsModInterface() generic.ModClient[*core.Pod] { d.acs.CurrentClusterCache().GetThrottles().Pod().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).Pods() } -func (d *Deployment) ServiceAccountsModInterface() serviceaccountv1.ModInterface { +func (d *Deployment) ServiceAccountsModInterface() generic.ModClient[*core.ServiceAccount] { d.acs.CurrentClusterCache().GetThrottles().ServiceAccount().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).ServiceAccounts() } -func (d *Deployment) ServicesModInterface() servicev1.ModInterface { +func (d *Deployment) ServicesModInterface() generic.ModClient[*core.Service] { d.acs.CurrentClusterCache().GetThrottles().Service().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).Services() } -func (d *Deployment) PersistentVolumeClaimsModInterface() persistentvolumeclaimv1.ModInterface { +func (d *Deployment) PersistentVolumeClaimsModInterface() generic.ModClient[*core.PersistentVolumeClaim] { d.acs.CurrentClusterCache().GetThrottles().PersistentVolumeClaim().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).PersistentVolumeClaims() } -func (d *Deployment) PodDisruptionBudgetsModInterface() poddisruptionbudgetv1.ModInterface { +func (d *Deployment) PodDisruptionBudgetsModInterface() generic.ModClient[*policy.PodDisruptionBudget] { d.acs.CurrentClusterCache().GetThrottles().PodDisruptionBudget().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).PodDisruptionBudgets() } -func (d *Deployment) ServiceMonitorsModInterface() servicemonitorv1.ModInterface { +func (d *Deployment) ServiceMonitorsModInterface() generic.ModClient[*monitoring.ServiceMonitor] { d.acs.CurrentClusterCache().GetThrottles().ServiceMonitor().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).ServiceMonitors() } diff --git a/pkg/deployment/deployment_pod_tls_sni_test.go b/pkg/deployment/deployment_pod_tls_sni_test.go index ef79e5413..2a33838d1 100644 --- a/pkg/deployment/deployment_pod_tls_sni_test.go +++ b/pkg/deployment/deployment_pod_tls_sni_test.go @@ -34,10 +34,10 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -func createTLSSNISecret(t *testing.T, client secretv1.ModInterface, name, namespace string) { +func createTLSSNISecret(t *testing.T, client generic.ModClient[*core.Secret], name, namespace string) { secret := core.Secret{ ObjectMeta: meta.ObjectMeta{ Name: name, diff --git a/pkg/deployment/deployment_run_test.go b/pkg/deployment/deployment_run_test.go index 848c1f21a..e161d3ee9 100644 --- a/pkg/deployment/deployment_run_test.go +++ b/pkg/deployment/deployment_run_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -233,7 +233,6 @@ func runTestCase(t *testing.T, testCase testCaseStruct) { // Assert if testCase.ExpectedError != nil { - if !assert.EqualError(t, err, testCase.ExpectedError.Error()) { println(fmt.Sprintf("%+v", err)) } diff --git a/pkg/deployment/pod/encryption.go b/pkg/deployment/pod/encryption.go index 1a5c5ab56..14d08f3b4 100644 --- a/pkg/deployment/pod/encryption.go +++ b/pkg/deployment/pod/encryption.go @@ -36,7 +36,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" ) @@ -66,7 +66,7 @@ func GroupEncryptionSupported(mode api.DeploymentMode, group api.ServerGroup) bo } } -func GetEncryptionKey(ctx context.Context, secrets secretv1.ReadInterface, name string) (string, []byte, bool, error) { +func GetEncryptionKey(ctx context.Context, secrets generic.ReadClient[*core.Secret], name string) (string, []byte, bool, error) { ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() diff --git a/pkg/deployment/reconcile/action_pvc_resize.go b/pkg/deployment/reconcile/action_pvc_resize.go index eeaff9f3e..9667458be 100644 --- a/pkg/deployment/reconcile/action_pvc_resize.go +++ b/pkg/deployment/reconcile/action_pvc_resize.go @@ -29,6 +29,7 @@ import ( meta "k8s.io/apimachinery/pkg/apis/meta/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" @@ -89,7 +90,7 @@ func (a *actionPVCResize) Start(ctx context.Context) (bool, error) { return true, nil } - am := cache.ArangoMember().V1().GetSimpleOptional(m.ArangoMemberName(a.actionCtx.GetName(), group)) + am := util.InitOptional(cache.ArangoMember().V1().GetSimple(m.ArangoMemberName(a.actionCtx.GetName(), group))) var res core.ResourceList if am.Spec.Overrides.HasVolumeClaimTemplate(&groupSpec) { diff --git a/pkg/deployment/reconcile/condition_member_recreation.go b/pkg/deployment/reconcile/condition_member_recreation.go index e9c8313b1..d55d522be 100644 --- a/pkg/deployment/reconcile/condition_member_recreation.go +++ b/pkg/deployment/reconcile/condition_member_recreation.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -113,7 +113,7 @@ func (r *Reconciler) isStorageClassChanged(_ context.Context, apiObject k8sutil. return false, "", nil } - am := cache.ArangoMember().V1().GetSimpleOptional(member.ArangoMemberName(context.GetName(), group)) + am := util.InitOptional(cache.ArangoMember().V1().GetSimple(member.ArangoMemberName(context.GetName(), group))) groupSpec := spec.GetServerGroupSpec(group) storageClassName := am.Spec.Overrides.GetStorageClassName(&groupSpec) @@ -186,7 +186,7 @@ func (r *Reconciler) isVolumeSizeChanged(_ context.Context, _ k8sutil.APIObject, return false, "", nil } - am := cache.ArangoMember().V1().GetSimpleOptional(member.ArangoMemberName(context.GetName(), group)) + am := util.InitOptional(cache.ArangoMember().V1().GetSimple(member.ArangoMemberName(context.GetName(), group))) pvc, ok := cache.PersistentVolumeClaim().V1().GetSimple(member.PersistentVolumeClaim.GetName()) if !ok { diff --git a/pkg/deployment/reconcile/plan_builder_storage.go b/pkg/deployment/reconcile/plan_builder_storage.go index e27201870..62fcba9cc 100644 --- a/pkg/deployment/reconcile/plan_builder_storage.go +++ b/pkg/deployment/reconcile/plan_builder_storage.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -28,6 +28,7 @@ import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/deployment/actions" sharedReconcile "github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared" + "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" ) @@ -97,7 +98,7 @@ func (r *Reconciler) createRotateServerStorageResizePlanInternal(spec api.Deploy continue } - am := cache.ArangoMember().V1().GetSimpleOptional(member.Member.ArangoMemberName(context.GetName(), member.Group)) + am := util.InitOptional(cache.ArangoMember().V1().GetSimple(member.Member.ArangoMemberName(context.GetName(), member.Group))) if groupSpec.VolumeResizeMode.Get() != mode { continue diff --git a/pkg/deployment/reconcile/plan_builder_test.go b/pkg/deployment/reconcile/plan_builder_test.go index c212e444e..7adb522c8 100644 --- a/pkg/deployment/reconcile/plan_builder_test.go +++ b/pkg/deployment/reconcile/plan_builder_test.go @@ -31,6 +31,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" core "k8s.io/api/core/v1" + policy "k8s.io/api/policy/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" @@ -59,14 +60,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/errors/panics" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - arangomemberv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember/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" - poddisruptionbudgetv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1" - 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" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/kclient" "github.com/arangodb/kube-arangodb/pkg/util/tests" ) @@ -184,35 +178,35 @@ func (c *testContext) GetAgencyCache() (state.State, bool) { return state.State{}, true } -func (c *testContext) SecretsModInterface() secretv1.ModInterface { +func (c *testContext) SecretsModInterface() generic.ModClient[*core.Secret] { panic("implement me") } -func (c *testContext) PodsModInterface() podv1.ModInterface { +func (c *testContext) PodsModInterface() generic.ModClient[*core.Pod] { panic("implement me") } -func (c *testContext) ServiceAccountsModInterface() serviceaccountv1.ModInterface { +func (c *testContext) ServiceAccountsModInterface() generic.ModClient[*core.ServiceAccount] { panic("implement me") } -func (c *testContext) ServicesModInterface() servicev1.ModInterface { +func (c *testContext) ServicesModInterface() generic.ReadClient[*core.Service] { panic("implement me") } -func (c *testContext) PersistentVolumeClaimsModInterface() persistentvolumeclaimv1.ModInterface { +func (c *testContext) PersistentVolumeClaimsModInterface() generic.ModClient[*core.PersistentVolumeClaim] { panic("implement me") } -func (c *testContext) PodDisruptionBudgetsModInterface() poddisruptionbudgetv1.ModInterface { +func (c *testContext) PodDisruptionBudgetsModInterface() generic.ModClient[*policy.PodDisruptionBudget] { panic("implement me") } -func (c *testContext) ServiceMonitorsModInterface() servicemonitorv1.ModInterface { +func (c *testContext) ServiceMonitorsModInterface() generic.ModClient[*core.Service] { panic("implement me") } -func (c *testContext) ArangoMembersModInterface() arangomemberv1.ModInterface { +func (c *testContext) ArangoMembersModInterface() generic.ModClient[*api.ArangoMember] { panic("implement me") } @@ -264,7 +258,7 @@ func (c *testContext) GetBackup(_ context.Context, backup string) (*backupApi.Ar panic("implement me") } -func (c *testContext) SecretsInterface() secretv1.Interface { +func (c *testContext) SecretsInterface() generic.ModClient[*core.Secret] { panic("implement me") } diff --git a/pkg/deployment/reconcile/utils_timezone.go b/pkg/deployment/reconcile/utils_timezone.go index be5ee21b2..af59bb495 100644 --- a/pkg/deployment/reconcile/utils_timezone.go +++ b/pkg/deployment/reconcile/utils_timezone.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,10 +21,12 @@ package reconcile import ( + core "k8s.io/api/core/v1" + "github.com/arangodb/kube-arangodb/pkg/deployment/pod" "github.com/arangodb/kube-arangodb/pkg/generated/timezones" "github.com/arangodb/kube-arangodb/pkg/util" - secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) const defaultTimezone = "UTC" @@ -36,7 +38,7 @@ func GetTimezone(tz *string) (timezones.Timezone, bool) { return timezones.GetTimezone(*tz) } -func IsTimezoneValid(cache secretv1.Inspector, name string, timezone timezones.Timezone) bool { +func IsTimezoneValid(cache generic.Inspector[*core.Secret], name string, timezone timezones.Timezone) bool { sn := pod.TimezoneSecret(name) tzd, ok := timezone.GetData() diff --git a/pkg/deployment/resources/certificates_client_auth.go b/pkg/deployment/resources/certificates_client_auth.go index 6d803d7ff..9c7ebf1c0 100644 --- a/pkg/deployment/resources/certificates_client_auth.go +++ b/pkg/deployment/resources/certificates_client_auth.go @@ -24,19 +24,20 @@ import ( "context" "fmt" + core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" ktls "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/tls" ) // createClientAuthCACertificate creates a client authentication CA certificate and stores it in a secret with name // specified in the given spec. -func (r *Resources) createClientAuthCACertificate(ctx context.Context, secrets secretv1.ModInterface, spec api.SyncAuthenticationSpec, deploymentName string, ownerRef *meta.OwnerReference) error { +func (r *Resources) createClientAuthCACertificate(ctx context.Context, secrets generic.ModClient[*core.Secret], spec api.SyncAuthenticationSpec, deploymentName string, ownerRef *meta.OwnerReference) error { log := r.log.Str("section", "secrets") cert, priv, err := ktls.CreateTLSCACertificate(fmt.Sprintf("%s Client Authentication Root Certificate", deploymentName)) diff --git a/pkg/deployment/resources/certificates_tls.go b/pkg/deployment/resources/certificates_tls.go index 06daaa109..e94bdac4c 100644 --- a/pkg/deployment/resources/certificates_tls.go +++ b/pkg/deployment/resources/certificates_tls.go @@ -24,6 +24,7 @@ import ( "context" "fmt" + core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" @@ -33,14 +34,14 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" ktls "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/tls" ) // createTLSCACertificate creates a CA certificate and stores it in a secret with name // specified in the given spec. -func (r *Resources) createTLSCACertificate(ctx context.Context, secrets secretv1.ModInterface, spec api.TLSSpec, +func (r *Resources) createTLSCACertificate(ctx context.Context, secrets generic.ModClient[*core.Secret], spec api.TLSSpec, deploymentName string, ownerRef *meta.OwnerReference) error { log := r.log.Str("section", "tls").Str("secret", spec.GetCASecretName()) @@ -64,7 +65,7 @@ func (r *Resources) createTLSCACertificate(ctx context.Context, secrets secretv1 // createTLSServerCertificate creates a TLS certificate for a specific server and stores // it in a secret with the given name. -func createTLSServerCertificate(ctx context.Context, log logging.Logger, cachedStatus inspectorInterface.Inspector, secrets secretv1.ModInterface, names ktls.KeyfileInput, spec api.TLSSpec, +func createTLSServerCertificate(ctx context.Context, log logging.Logger, cachedStatus inspectorInterface.Inspector, secrets generic.ModClient[*core.Secret], names ktls.KeyfileInput, spec api.TLSSpec, secretName string, ownerRef *meta.OwnerReference) (bool, error) { log = log.Str("secret", secretName) // Setup defaults diff --git a/pkg/deployment/resources/config_map_gateway.go b/pkg/deployment/resources/config_map_gateway.go index 420f5f117..8efaf7d51 100644 --- a/pkg/deployment/resources/config_map_gateway.go +++ b/pkg/deployment/resources/config_map_gateway.go @@ -40,11 +40,11 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - configMapsV1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/patcher" ) -func (r *Resources) ensureGatewayConfig(ctx context.Context, cachedStatus inspectorInterface.Inspector, configMaps configMapsV1.ModInterface) error { +func (r *Resources) ensureGatewayConfig(ctx context.Context, cachedStatus inspectorInterface.Inspector, configMaps generic.ModClient[*core.ConfigMap]) error { deploymentName := r.context.GetAPIObject().GetName() configMapName := GetGatewayConfigMapName(deploymentName) diff --git a/pkg/deployment/resources/config_maps_member.go b/pkg/deployment/resources/config_maps_member.go index f65dc2bec..90bd1117d 100644 --- a/pkg/deployment/resources/config_maps_member.go +++ b/pkg/deployment/resources/config_maps_member.go @@ -33,7 +33,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - configMapsV1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/patcher" ) @@ -49,7 +49,7 @@ const ( type memberConfigMapRenderer func(ctx context.Context, cachedStatus inspectorInterface.Inspector, member api.DeploymentStatusMemberElement) (map[string]string, error) -func (r *Resources) ensureMemberConfig(ctx context.Context, cachedStatus inspectorInterface.Inspector, configMaps configMapsV1.ModInterface) error { +func (r *Resources) ensureMemberConfig(ctx context.Context, cachedStatus inspectorInterface.Inspector, configMaps generic.ModClient[*core.ConfigMap]) error { status := r.context.GetStatus() log := r.log.Str("section", "member-config-render") diff --git a/pkg/deployment/resources/inspector/acs.go b/pkg/deployment/resources/inspector/acs.go index e0e5cbd33..ffbc60563 100644 --- a/pkg/deployment/resources/inspector/acs.go +++ b/pkg/deployment/resources/inspector/acs.go @@ -24,12 +24,12 @@ import ( "context" "time" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +49,18 @@ func (p arangoClusterSynchronizationsInspectorLoader) Component() definitions.Co func (p arangoClusterSynchronizationsInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q arangoClusterSynchronizationsInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*api.ArangoClusterSynchronizationList, *api.ArangoClusterSynchronization](ctx, + constants.ArangoClusterSynchronizationGRv1(), + constants.ArangoClusterSynchronizationGKv1(), + i.client.Arango().DatabaseV1().ArangoClusterSynchronizations(i.namespace), + arangoclustersynchronization.List()) + i.arangoClusterSynchronizations = &q q.state = i q.last = time.Now() } -func (p arangoClusterSynchronizationsInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *arangoClusterSynchronizationsInspector) { - var z arangoClusterSynchronizationsInspectorV1 - - z.arangoClusterSynchronizationInspector = q - - z.arangoClusterSynchronizations, z.err = p.getV1ArangoClusterSynchronizations(ctx, i) - - q.v1 = &z -} - -func (p arangoClusterSynchronizationsInspectorLoader) getV1ArangoClusterSynchronizations(ctx context.Context, i *inspectorState) (map[string]*api.ArangoClusterSynchronization, error) { - objs, err := p.getV1ArangoClusterSynchronizationsList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*api.ArangoClusterSynchronization, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p arangoClusterSynchronizationsInspectorLoader) getV1ArangoClusterSynchronizationsList(ctx context.Context, i *inspectorState) ([]*api.ArangoClusterSynchronization, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Arango().DatabaseV1().ArangoClusterSynchronizations(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*api.ArangoClusterSynchronization, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1ArangoClusterSynchronizationsListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p arangoClusterSynchronizationsInspectorLoader) getV1ArangoClusterSynchronizationsListRequest(ctx context.Context, i *inspectorState, cont string) ([]api.ArangoClusterSynchronization, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Arango().DatabaseV1().ArangoClusterSynchronizations(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p arangoClusterSynchronizationsInspectorLoader) Verify(i *inspectorState) error { return nil } @@ -159,7 +85,7 @@ type arangoClusterSynchronizationsInspector struct { last time.Time - v1 *arangoClusterSynchronizationsInspectorV1 + v1 *inspectorVersion[*api.ArangoClusterSynchronization] } func (p *arangoClusterSynchronizationsInspector) LastRefresh() time.Time { @@ -190,3 +116,11 @@ func (p *arangoClusterSynchronizationsInspector) validate() error { return p.v1.validate() } + +func (p *arangoClusterSynchronizationsInspector) V1() (generic.Inspector[*api.ArangoClusterSynchronization], error) { + if p.v1.err != nil { + return nil, p.v1.err + } + + return p.v1, nil +} diff --git a/pkg/deployment/resources/inspector/acs_gvk.go b/pkg/deployment/resources/inspector/acs_gvk.go index 822f4d6a1..9d08630af 100644 --- a/pkg/deployment/resources/inspector/acs_gvk.go +++ b/pkg/deployment/resources/inspector/acs_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *arangoClusterSynchronizationsInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.ArangoClusterSynchronizationGKv1() -} - -func (p *arangoClusterSynchronizationsInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.ArangoClusterSynchronizationGRv1() -} - func (p *arangoClusterSynchronizationsInspector) GroupKind() schema.GroupKind { return constants.ArangoClusterSynchronizationGK() } diff --git a/pkg/deployment/resources/inspector/acs_mod.go b/pkg/deployment/resources/inspector/acs_mod.go index 49ada8bbd..27b3410a3 100644 --- a/pkg/deployment/resources/inspector/acs_mod.go +++ b/pkg/deployment/resources/inspector/acs_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -22,7 +22,6 @@ package inspector import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - arangoclustersynchronizationv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" @@ -38,7 +37,7 @@ type arangoClusterSynchronizationMod struct { i *inspectorState } -func (p arangoClusterSynchronizationMod) V1() arangoclustersynchronizationv1.ModInterface { +func (p arangoClusterSynchronizationMod) V1() generic.ModStatusClient[*api.ArangoClusterSynchronization] { return wrapMod[*api.ArangoClusterSynchronization](definitions.ArangoClusterSynchronization, p.i.GetThrottles, p.clientv1) } diff --git a/pkg/deployment/resources/inspector/acs_v1.go b/pkg/deployment/resources/inspector/acs_v1.go deleted file mode 100644 index e5f175ba7..000000000 --- a/pkg/deployment/resources/inspector/acs_v1.go +++ /dev/null @@ -1,138 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" -) - -func (p *arangoClusterSynchronizationsInspector) V1() (ins.Inspector, error) { - if p.v1.err != nil { - return nil, p.v1.err - } - - return p.v1, nil -} - -type arangoClusterSynchronizationsInspectorV1 struct { - arangoClusterSynchronizationInspector *arangoClusterSynchronizationsInspector - - arangoClusterSynchronizations map[string]*api.ArangoClusterSynchronization - err error -} - -func (p *arangoClusterSynchronizationsInspectorV1) Filter(filters ...ins.Filter) []*api.ArangoClusterSynchronization { - z := p.ListSimple() - - r := make([]*api.ArangoClusterSynchronization, 0, len(z)) - - for _, o := range z { - if !ins.FilterObject(o, filters...) { - continue - } - - r = append(r, o) - } - - return r -} - -func (p *arangoClusterSynchronizationsInspectorV1) validate() error { - if p == nil { - return errors.Errorf("ArangoClusterSynchronizationsV1Inspector is nil") - } - - if p.arangoClusterSynchronizationInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.arangoClusterSynchronizations == nil && p.err == nil { - return errors.Errorf("ListSimple or err should be not nil") - } - - if p.arangoClusterSynchronizations != nil && p.err != nil { - return errors.Errorf("ListSimple or err cannot be not nil together") - } - - return nil -} - -func (p *arangoClusterSynchronizationsInspectorV1) ListSimple() []*api.ArangoClusterSynchronization { - var r []*api.ArangoClusterSynchronization - for _, arangoClusterSynchronization := range p.arangoClusterSynchronizations { - r = append(r, arangoClusterSynchronization) - } - - return r -} - -func (p *arangoClusterSynchronizationsInspectorV1) GetSimple(name string) (*api.ArangoClusterSynchronization, bool) { - arangoClusterSynchronization, ok := p.arangoClusterSynchronizations[name] - if !ok { - return nil, false - } - - return arangoClusterSynchronization, true -} - -func (p *arangoClusterSynchronizationsInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, arangoClusterSynchronization := range p.arangoClusterSynchronizations { - if err := p.iterateArangoClusterSynchronization(arangoClusterSynchronization, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *arangoClusterSynchronizationsInspectorV1) iterateArangoClusterSynchronization(arangoClusterSynchronization *api.ArangoClusterSynchronization, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(arangoClusterSynchronization) { - return nil - } - } - - return action(arangoClusterSynchronization) -} - -func (p *arangoClusterSynchronizationsInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *arangoClusterSynchronizationsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*api.ArangoClusterSynchronization, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.ArangoClusterSynchronizationGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/am.go b/pkg/deployment/resources/inspector/am.go index 57845e8c7..4f2a56846 100644 --- a/pkg/deployment/resources/inspector/am.go +++ b/pkg/deployment/resources/inspector/am.go @@ -24,12 +24,12 @@ import ( "context" "time" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +49,18 @@ func (p arangoMembersInspectorLoader) Component() definitions.Component { func (p arangoMembersInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q arangoMembersInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*api.ArangoMemberList, *api.ArangoMember](ctx, + constants.ArangoMemberGRv1(), + constants.ArangoMemberGKv1(), + i.client.Arango().DatabaseV1().ArangoMembers(i.namespace), + arangomember.List()) + i.arangoMembers = &q q.state = i q.last = time.Now() } -func (p arangoMembersInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *arangoMembersInspector) { - var z arangoMembersInspectorV1 - - z.arangoMemberInspector = q - - z.arangoMembers, z.err = p.getV1ArangoMembers(ctx, i) - - q.v1 = &z -} - -func (p arangoMembersInspectorLoader) getV1ArangoMembers(ctx context.Context, i *inspectorState) (map[string]*api.ArangoMember, error) { - objs, err := p.getV1ArangoMembersList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*api.ArangoMember, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p arangoMembersInspectorLoader) getV1ArangoMembersList(ctx context.Context, i *inspectorState) ([]*api.ArangoMember, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Arango().DatabaseV1().ArangoMembers(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*api.ArangoMember, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1ArangoMembersListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p arangoMembersInspectorLoader) getV1ArangoMembersListRequest(ctx context.Context, i *inspectorState, cont string) ([]api.ArangoMember, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Arango().DatabaseV1().ArangoMembers(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p arangoMembersInspectorLoader) Verify(i *inspectorState) error { if err := i.arangoMembers.v1.err; err != nil { return err @@ -163,7 +89,7 @@ type arangoMembersInspector struct { last time.Time - v1 *arangoMembersInspectorV1 + v1 *inspectorVersion[*api.ArangoMember] } func (p *arangoMembersInspector) LastRefresh() time.Time { @@ -194,3 +120,7 @@ func (p *arangoMembersInspector) validate() error { return p.v1.validate() } + +func (p *arangoMembersInspector) V1() generic.Inspector[*api.ArangoMember] { + return p.v1 +} diff --git a/pkg/deployment/resources/inspector/am_gvk.go b/pkg/deployment/resources/inspector/am_gvk.go index 520ab8147..a813015de 100644 --- a/pkg/deployment/resources/inspector/am_gvk.go +++ b/pkg/deployment/resources/inspector/am_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *arangoMembersInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.ArangoMemberGKv1() -} - -func (p *arangoMembersInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.ArangoMemberGRv1() -} - func (p *arangoMembersInspector) GroupKind() schema.GroupKind { return constants.ArangoMemberGK() } diff --git a/pkg/deployment/resources/inspector/am_mod.go b/pkg/deployment/resources/inspector/am_mod.go index c33515096..c254e2296 100644 --- a/pkg/deployment/resources/inspector/am_mod.go +++ b/pkg/deployment/resources/inspector/am_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -22,7 +22,6 @@ package inspector import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - arangomemberv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" @@ -38,7 +37,7 @@ type arangoMemberMod struct { i *inspectorState } -func (p arangoMemberMod) V1() arangomemberv1.ModInterface { +func (p arangoMemberMod) V1() generic.ModStatusClient[*api.ArangoMember] { return wrapMod[*api.ArangoMember](definitions.ArangoMember, p.i.GetThrottles, p.clientv1) } diff --git a/pkg/deployment/resources/inspector/am_v1.go b/pkg/deployment/resources/inspector/am_v1.go deleted file mode 100644 index dc34359e5..000000000 --- a/pkg/deployment/resources/inspector/am_v1.go +++ /dev/null @@ -1,126 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" -) - -func (p *arangoMembersInspector) V1() ins.Inspector { - return p.v1 -} - -type arangoMembersInspectorV1 struct { - arangoMemberInspector *arangoMembersInspector - - arangoMembers map[string]*api.ArangoMember - err error -} - -func (p *arangoMembersInspectorV1) validate() error { - if p == nil { - return errors.Errorf("ArangoMembersV1Inspector is nil") - } - - if p.arangoMemberInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.arangoMembers == nil { - return errors.Errorf("ArangoMembers or err should be not nil") - } - - if p.err != nil { - return errors.Errorf("ArangoMembers or err cannot be not nil together") - } - - return nil -} - -func (p *arangoMembersInspectorV1) ArangoMembers() []*api.ArangoMember { - var r []*api.ArangoMember - for _, arangoMember := range p.arangoMembers { - r = append(r, arangoMember) - } - - return r -} - -func (p *arangoMembersInspectorV1) GetSimple(name string) (*api.ArangoMember, bool) { - arangoMember, ok := p.arangoMembers[name] - if !ok { - return nil, false - } - - return arangoMember, true -} - -func (p *arangoMembersInspectorV1) GetSimpleOptional(name string) *api.ArangoMember { - a, ok := p.GetSimple(name) - if !ok { - return &api.ArangoMember{} - } - return a -} - -func (p *arangoMembersInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, arangoMember := range p.arangoMembers { - if err := p.iterateArangoMember(arangoMember, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *arangoMembersInspectorV1) iterateArangoMember(arangoMember *api.ArangoMember, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(arangoMember) { - return nil - } - } - - return action(arangoMember) -} - -func (p *arangoMembersInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *arangoMembersInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*api.ArangoMember, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.ArangoMemberGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/ap.go b/pkg/deployment/resources/inspector/ap.go index 611c85ec8..12d5343bf 100644 --- a/pkg/deployment/resources/inspector/ap.go +++ b/pkg/deployment/resources/inspector/ap.go @@ -24,12 +24,12 @@ import ( "context" "time" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoprofile" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +49,18 @@ func (p arangoProfilesInspectorLoader) Component() definitions.Component { func (p arangoProfilesInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q arangoProfilesInspector - p.loadV1Beta1(ctx, i, &q) + + q.v1beta1 = newInspectorVersion[*schedulerApi.ArangoProfileList, *schedulerApi.ArangoProfile](ctx, + constants.ArangoProfileGRv1(), + constants.ArangoProfileGKv1(), + i.client.Arango().SchedulerV1beta1().ArangoProfiles(i.namespace), + arangoprofile.List()) + i.arangoProfiles = &q q.state = i q.last = time.Now() } -func (p arangoProfilesInspectorLoader) loadV1Beta1(ctx context.Context, i *inspectorState, q *arangoProfilesInspector) { - var z arangoProfilesInspectorV1Beta1 - - z.arangoProfileInspector = q - - z.arangoProfiles, z.err = p.getV1ArangoProfiles(ctx, i) - - q.v1beta1 = &z -} - -func (p arangoProfilesInspectorLoader) getV1ArangoProfiles(ctx context.Context, i *inspectorState) (map[string]*schedulerApi.ArangoProfile, error) { - objs, err := p.getV1ArangoProfilesList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*schedulerApi.ArangoProfile, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p arangoProfilesInspectorLoader) getV1ArangoProfilesList(ctx context.Context, i *inspectorState) ([]*schedulerApi.ArangoProfile, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Arango().SchedulerV1beta1().ArangoProfiles(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*schedulerApi.ArangoProfile, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1ArangoProfilesListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p arangoProfilesInspectorLoader) getV1ArangoProfilesListRequest(ctx context.Context, i *inspectorState, cont string) ([]schedulerApi.ArangoProfile, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Arango().SchedulerV1beta1().ArangoProfiles(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p arangoProfilesInspectorLoader) Verify(i *inspectorState) error { return nil } @@ -159,7 +85,7 @@ type arangoProfilesInspector struct { last time.Time - v1beta1 *arangoProfilesInspectorV1Beta1 + v1beta1 *inspectorVersion[*schedulerApi.ArangoProfile] } func (p *arangoProfilesInspector) LastRefresh() time.Time { @@ -190,3 +116,11 @@ func (p *arangoProfilesInspector) validate() error { return p.v1beta1.validate() } + +func (p *arangoProfilesInspector) V1Beta1() (generic.Inspector[*schedulerApi.ArangoProfile], error) { + if p.v1beta1.err != nil { + return nil, p.v1beta1.err + } + + return p.v1beta1, nil +} diff --git a/pkg/deployment/resources/inspector/ap_gvk.go b/pkg/deployment/resources/inspector/ap_gvk.go index f73892fde..60b6e6674 100644 --- a/pkg/deployment/resources/inspector/ap_gvk.go +++ b/pkg/deployment/resources/inspector/ap_gvk.go @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *arangoProfilesInspectorV1Beta1) GroupVersionKind() schema.GroupVersionKind { - return constants.ArangoProfileGKv1() -} - -func (p *arangoProfilesInspectorV1Beta1) GroupVersionResource() schema.GroupVersionResource { - return constants.ArangoProfileGRv1() -} - func (p *arangoProfilesInspector) GroupKind() schema.GroupKind { return constants.ArangoProfileGK() } diff --git a/pkg/deployment/resources/inspector/ap_mod.go b/pkg/deployment/resources/inspector/ap_mod.go index 276bb8935..d81a96c10 100644 --- a/pkg/deployment/resources/inspector/ap_mod.go +++ b/pkg/deployment/resources/inspector/ap_mod.go @@ -22,7 +22,6 @@ package inspector import ( schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" - arangoProfilev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoprofile/v1beta1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" @@ -38,7 +37,7 @@ type arangoProfileMod struct { i *inspectorState } -func (p arangoProfileMod) V1Beta1() arangoProfilev1.ModInterface { +func (p arangoProfileMod) V1Beta1() generic.ModStatusClient[*schedulerApi.ArangoProfile] { return wrapMod[*schedulerApi.ArangoProfile](definitions.ArangoProfile, p.i.GetThrottles, p.clientv1beta1) } diff --git a/pkg/deployment/resources/inspector/ap_v1beta1.go b/pkg/deployment/resources/inspector/ap_v1beta1.go deleted file mode 100644 index add18b85c..000000000 --- a/pkg/deployment/resources/inspector/ap_v1beta1.go +++ /dev/null @@ -1,138 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2024 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" - - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoprofile/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" -) - -func (p *arangoProfilesInspector) V1Beta1() (ins.Inspector, error) { - if p.v1beta1.err != nil { - return nil, p.v1beta1.err - } - - return p.v1beta1, nil -} - -type arangoProfilesInspectorV1Beta1 struct { - arangoProfileInspector *arangoProfilesInspector - - arangoProfiles map[string]*schedulerApi.ArangoProfile - err error -} - -func (p *arangoProfilesInspectorV1Beta1) Filter(filters ...ins.Filter) []*schedulerApi.ArangoProfile { - z := p.ListSimple() - - r := make([]*schedulerApi.ArangoProfile, 0, len(z)) - - for _, o := range z { - if !ins.FilterObject(o, filters...) { - continue - } - - r = append(r, o) - } - - return r -} - -func (p *arangoProfilesInspectorV1Beta1) validate() error { - if p == nil { - return errors.Errorf("ArangoProfilesV1AlphaInspector is nil") - } - - if p.arangoProfileInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.arangoProfiles == nil && p.err == nil { - return errors.Errorf("ArangoProfiles or err should be not nil") - } - - if p.arangoProfiles != nil && p.err != nil { - return errors.Errorf("ArangoProfiles or err cannot be not nil together") - } - - return nil -} - -func (p *arangoProfilesInspectorV1Beta1) ListSimple() []*schedulerApi.ArangoProfile { - var r []*schedulerApi.ArangoProfile - for _, arangoProfile := range p.arangoProfiles { - r = append(r, arangoProfile) - } - - return r -} - -func (p *arangoProfilesInspectorV1Beta1) GetSimple(name string) (*schedulerApi.ArangoProfile, bool) { - arangoProfile, ok := p.arangoProfiles[name] - if !ok { - return nil, false - } - - return arangoProfile, true -} - -func (p *arangoProfilesInspectorV1Beta1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, arangoProfile := range p.arangoProfiles { - if err := p.iterateArangoProfile(arangoProfile, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *arangoProfilesInspectorV1Beta1) iterateArangoProfile(arangoProfile *schedulerApi.ArangoProfile, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(arangoProfile) { - return nil - } - } - - return action(arangoProfile) -} - -func (p *arangoProfilesInspectorV1Beta1) Read() ins.ReadInterface { - return p -} - -func (p *arangoProfilesInspectorV1Beta1) Get(ctx context.Context, name string, opts meta.GetOptions) (*schedulerApi.ArangoProfile, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.ArangoProfileGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/ar.go b/pkg/deployment/resources/inspector/ar.go index cdb37e4c5..595bf25d8 100644 --- a/pkg/deployment/resources/inspector/ar.go +++ b/pkg/deployment/resources/inspector/ar.go @@ -24,12 +24,12 @@ import ( "context" "time" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - networkingApi "github.com/arangodb/kube-arangodb/pkg/apis/networking/v1alpha1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoroute" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +49,18 @@ func (p arangoRoutesInspectorLoader) Component() definitions.Component { func (p arangoRoutesInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q arangoRoutesInspector - p.loadV1Alpha1(ctx, i, &q) + + q.v1alpha1 = newInspectorVersion[*networkingApi.ArangoRouteList, *networkingApi.ArangoRoute](ctx, + constants.ArangoRouteGRv1(), + constants.ArangoRouteGKv1(), + i.client.Arango().NetworkingV1alpha1().ArangoRoutes(i.namespace), + arangoroute.List()) + i.arangoRoutes = &q q.state = i q.last = time.Now() } -func (p arangoRoutesInspectorLoader) loadV1Alpha1(ctx context.Context, i *inspectorState, q *arangoRoutesInspector) { - var z arangoRoutesInspectorV1Alpha1 - - z.arangoRouteInspector = q - - z.arangoRoutes, z.err = p.getV1ArangoRoutes(ctx, i) - - q.v1alpha1 = &z -} - -func (p arangoRoutesInspectorLoader) getV1ArangoRoutes(ctx context.Context, i *inspectorState) (map[string]*networkingApi.ArangoRoute, error) { - objs, err := p.getV1ArangoRoutesList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*networkingApi.ArangoRoute, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p arangoRoutesInspectorLoader) getV1ArangoRoutesList(ctx context.Context, i *inspectorState) ([]*networkingApi.ArangoRoute, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Arango().NetworkingV1alpha1().ArangoRoutes(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*networkingApi.ArangoRoute, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1ArangoRoutesListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p arangoRoutesInspectorLoader) getV1ArangoRoutesListRequest(ctx context.Context, i *inspectorState, cont string) ([]networkingApi.ArangoRoute, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Arango().NetworkingV1alpha1().ArangoRoutes(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p arangoRoutesInspectorLoader) Verify(i *inspectorState) error { return nil } @@ -159,7 +85,7 @@ type arangoRoutesInspector struct { last time.Time - v1alpha1 *arangoRoutesInspectorV1Alpha1 + v1alpha1 *inspectorVersion[*networkingApi.ArangoRoute] } func (p *arangoRoutesInspector) LastRefresh() time.Time { @@ -190,3 +116,11 @@ func (p *arangoRoutesInspector) validate() error { return p.v1alpha1.validate() } + +func (p *arangoRoutesInspector) V1Alpha1() (generic.Inspector[*networkingApi.ArangoRoute], error) { + if p.v1alpha1.err != nil { + return nil, p.v1alpha1.err + } + + return p.v1alpha1, nil +} diff --git a/pkg/deployment/resources/inspector/ar_gvk.go b/pkg/deployment/resources/inspector/ar_gvk.go index a1bb4caed..17603fc61 100644 --- a/pkg/deployment/resources/inspector/ar_gvk.go +++ b/pkg/deployment/resources/inspector/ar_gvk.go @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *arangoRoutesInspectorV1Alpha1) GroupVersionKind() schema.GroupVersionKind { - return constants.ArangoRouteGKv1() -} - -func (p *arangoRoutesInspectorV1Alpha1) GroupVersionResource() schema.GroupVersionResource { - return constants.ArangoRouteGRv1() -} - func (p *arangoRoutesInspector) GroupKind() schema.GroupKind { return constants.ArangoRouteGK() } diff --git a/pkg/deployment/resources/inspector/ar_mod.go b/pkg/deployment/resources/inspector/ar_mod.go index eb9fd854f..217fb21a3 100644 --- a/pkg/deployment/resources/inspector/ar_mod.go +++ b/pkg/deployment/resources/inspector/ar_mod.go @@ -22,7 +22,6 @@ package inspector import ( networkingApi "github.com/arangodb/kube-arangodb/pkg/apis/networking/v1alpha1" - arangoRoutev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoroute/v1alpha1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" @@ -38,7 +37,7 @@ type arangoRouteMod struct { i *inspectorState } -func (p arangoRouteMod) V1Alpha1() arangoRoutev1.ModInterface { +func (p arangoRouteMod) V1Alpha1() generic.ModStatusClient[*networkingApi.ArangoRoute] { return wrapMod[*networkingApi.ArangoRoute](definitions.ArangoRoute, p.i.GetThrottles, p.clientv1alpha1) } diff --git a/pkg/deployment/resources/inspector/ar_v1alpha1.go b/pkg/deployment/resources/inspector/ar_v1alpha1.go deleted file mode 100644 index 7d7c0d655..000000000 --- a/pkg/deployment/resources/inspector/ar_v1alpha1.go +++ /dev/null @@ -1,138 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - networkingApi "github.com/arangodb/kube-arangodb/pkg/apis/networking/v1alpha1" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoroute/v1alpha1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" -) - -func (p *arangoRoutesInspector) V1Alpha1() (ins.Inspector, error) { - if p.v1alpha1.err != nil { - return nil, p.v1alpha1.err - } - - return p.v1alpha1, nil -} - -type arangoRoutesInspectorV1Alpha1 struct { - arangoRouteInspector *arangoRoutesInspector - - arangoRoutes map[string]*networkingApi.ArangoRoute - err error -} - -func (p *arangoRoutesInspectorV1Alpha1) Filter(filters ...ins.Filter) []*networkingApi.ArangoRoute { - z := p.ListSimple() - - r := make([]*networkingApi.ArangoRoute, 0, len(z)) - - for _, o := range z { - if !ins.FilterObject(o, filters...) { - continue - } - - r = append(r, o) - } - - return r -} - -func (p *arangoRoutesInspectorV1Alpha1) validate() error { - if p == nil { - return errors.Errorf("ArangoRoutesV1AlphaInspector is nil") - } - - if p.arangoRouteInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.arangoRoutes == nil && p.err == nil { - return errors.Errorf("ArangoRoutes or err should be not nil") - } - - if p.arangoRoutes != nil && p.err != nil { - return errors.Errorf("ArangoRoutes or err cannot be not nil together") - } - - return nil -} - -func (p *arangoRoutesInspectorV1Alpha1) ListSimple() []*networkingApi.ArangoRoute { - var r []*networkingApi.ArangoRoute - for _, arangoRoute := range p.arangoRoutes { - r = append(r, arangoRoute) - } - - return r -} - -func (p *arangoRoutesInspectorV1Alpha1) GetSimple(name string) (*networkingApi.ArangoRoute, bool) { - arangoRoute, ok := p.arangoRoutes[name] - if !ok { - return nil, false - } - - return arangoRoute, true -} - -func (p *arangoRoutesInspectorV1Alpha1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, arangoRoute := range p.arangoRoutes { - if err := p.iterateArangoRoute(arangoRoute, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *arangoRoutesInspectorV1Alpha1) iterateArangoRoute(arangoRoute *networkingApi.ArangoRoute, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(arangoRoute) { - return nil - } - } - - return action(arangoRoute) -} - -func (p *arangoRoutesInspectorV1Alpha1) Read() ins.ReadInterface { - return p -} - -func (p *arangoRoutesInspectorV1Alpha1) Get(ctx context.Context, name string, opts meta.GetOptions) (*networkingApi.ArangoRoute, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.ArangoRouteGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/at.go b/pkg/deployment/resources/inspector/at.go index d07da7d77..f9c83662c 100644 --- a/pkg/deployment/resources/inspector/at.go +++ b/pkg/deployment/resources/inspector/at.go @@ -24,12 +24,12 @@ import ( "context" "time" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +49,18 @@ func (p arangoTasksInspectorLoader) Component() definitions.Component { func (p arangoTasksInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q arangoTasksInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*api.ArangoTaskList, *api.ArangoTask](ctx, + constants.ArangoTaskGRv1(), + constants.ArangoTaskGKv1(), + i.client.Arango().DatabaseV1().ArangoTasks(i.namespace), + arangotask.List()) + i.arangoTasks = &q q.state = i q.last = time.Now() } -func (p arangoTasksInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *arangoTasksInspector) { - var z arangoTasksInspectorV1 - - z.arangoTaskInspector = q - - z.arangoTasks, z.err = p.getV1ArangoTasks(ctx, i) - - q.v1 = &z -} - -func (p arangoTasksInspectorLoader) getV1ArangoTasks(ctx context.Context, i *inspectorState) (map[string]*api.ArangoTask, error) { - objs, err := p.getV1ArangoTasksList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*api.ArangoTask, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p arangoTasksInspectorLoader) getV1ArangoTasksList(ctx context.Context, i *inspectorState) ([]*api.ArangoTask, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Arango().DatabaseV1().ArangoTasks(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*api.ArangoTask, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1ArangoTasksListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p arangoTasksInspectorLoader) getV1ArangoTasksListRequest(ctx context.Context, i *inspectorState, cont string) ([]api.ArangoTask, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Arango().DatabaseV1().ArangoTasks(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p arangoTasksInspectorLoader) Verify(i *inspectorState) error { return nil } @@ -159,7 +85,7 @@ type arangoTasksInspector struct { last time.Time - v1 *arangoTasksInspectorV1 + v1 *inspectorVersion[*api.ArangoTask] } func (p *arangoTasksInspector) LastRefresh() time.Time { @@ -190,3 +116,11 @@ func (p *arangoTasksInspector) validate() error { return p.v1.validate() } + +func (p *arangoTasksInspector) V1() (generic.Inspector[*api.ArangoTask], error) { + if p.v1.err != nil { + return nil, p.v1.err + } + + return p.v1, nil +} diff --git a/pkg/deployment/resources/inspector/at_gvk.go b/pkg/deployment/resources/inspector/at_gvk.go index fcaeace77..98c063b37 100644 --- a/pkg/deployment/resources/inspector/at_gvk.go +++ b/pkg/deployment/resources/inspector/at_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *arangoTasksInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.ArangoTaskGKv1() -} - -func (p *arangoTasksInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.ArangoTaskGRv1() -} - func (p *arangoTasksInspector) GroupKind() schema.GroupKind { return constants.ArangoTaskGK() } diff --git a/pkg/deployment/resources/inspector/at_mod.go b/pkg/deployment/resources/inspector/at_mod.go index 14b93990b..5909b32b2 100644 --- a/pkg/deployment/resources/inspector/at_mod.go +++ b/pkg/deployment/resources/inspector/at_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -22,7 +22,6 @@ package inspector import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - arangotaskv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" @@ -38,7 +37,7 @@ type arangoTaskMod struct { i *inspectorState } -func (p arangoTaskMod) V1() arangotaskv1.ModInterface { +func (p arangoTaskMod) V1() generic.ModStatusClient[*api.ArangoTask] { return wrapMod[*api.ArangoTask](definitions.ArangoTask, p.i.GetThrottles, p.clientv1) } diff --git a/pkg/deployment/resources/inspector/at_v1.go b/pkg/deployment/resources/inspector/at_v1.go deleted file mode 100644 index 9a05d1dcd..000000000 --- a/pkg/deployment/resources/inspector/at_v1.go +++ /dev/null @@ -1,138 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" -) - -func (p *arangoTasksInspector) V1() (ins.Inspector, error) { - if p.v1.err != nil { - return nil, p.v1.err - } - - return p.v1, nil -} - -type arangoTasksInspectorV1 struct { - arangoTaskInspector *arangoTasksInspector - - arangoTasks map[string]*api.ArangoTask - err error -} - -func (p *arangoTasksInspectorV1) Filter(filters ...ins.Filter) []*api.ArangoTask { - z := p.ListSimple() - - r := make([]*api.ArangoTask, 0, len(z)) - - for _, o := range z { - if !ins.FilterObject(o, filters...) { - continue - } - - r = append(r, o) - } - - return r -} - -func (p *arangoTasksInspectorV1) validate() error { - if p == nil { - return errors.Errorf("ArangoTasksV1Inspector is nil") - } - - if p.arangoTaskInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.arangoTasks == nil && p.err == nil { - return errors.Errorf("ArangoTasks or err should be not nil") - } - - if p.arangoTasks != nil && p.err != nil { - return errors.Errorf("ArangoTasks or err cannot be not nil together") - } - - return nil -} - -func (p *arangoTasksInspectorV1) ListSimple() []*api.ArangoTask { - var r []*api.ArangoTask - for _, arangoTask := range p.arangoTasks { - r = append(r, arangoTask) - } - - return r -} - -func (p *arangoTasksInspectorV1) GetSimple(name string) (*api.ArangoTask, bool) { - arangoTask, ok := p.arangoTasks[name] - if !ok { - return nil, false - } - - return arangoTask, true -} - -func (p *arangoTasksInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, arangoTask := range p.arangoTasks { - if err := p.iterateArangoTask(arangoTask, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *arangoTasksInspectorV1) iterateArangoTask(arangoTask *api.ArangoTask, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(arangoTask) { - return nil - } - } - - return action(arangoTask) -} - -func (p *arangoTasksInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *arangoTasksInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*api.ArangoTask, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.ArangoTaskGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/configmaps.go b/pkg/deployment/resources/inspector/configmaps.go index bc235e162..8f79a11ad 100644 --- a/pkg/deployment/resources/inspector/configmaps.go +++ b/pkg/deployment/resources/inspector/configmaps.go @@ -25,11 +25,12 @@ import ( "time" core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +50,18 @@ func (p configMapsInspectorLoader) Component() definitions.Component { func (p configMapsInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q configMapsInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*core.ConfigMapList, *core.ConfigMap](ctx, + constants.ConfigMapGRv1(), + constants.ConfigMapGKv1(), + i.client.Kubernetes().CoreV1().ConfigMaps(i.namespace), + configmap.List()) + i.configMaps = &q q.state = i q.last = time.Now() } -func (p configMapsInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *configMapsInspector) { - var z configMapsInspectorV1 - - z.configMapInspector = q - - z.configMaps, z.err = p.getV1ConfigMaps(ctx, i) - - q.v1 = &z -} - -func (p configMapsInspectorLoader) getV1ConfigMaps(ctx context.Context, i *inspectorState) (map[string]*core.ConfigMap, error) { - objs, err := p.getV1ConfigMapsList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*core.ConfigMap, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p configMapsInspectorLoader) getV1ConfigMapsList(ctx context.Context, i *inspectorState) ([]*core.ConfigMap, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().ConfigMaps(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*core.ConfigMap, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1ConfigMapsListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p configMapsInspectorLoader) getV1ConfigMapsListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.ConfigMap, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().ConfigMaps(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p configMapsInspectorLoader) Verify(i *inspectorState) error { if err := i.configMaps.v1.err; err != nil { return err @@ -163,7 +90,7 @@ type configMapsInspector struct { last time.Time - v1 *configMapsInspectorV1 + v1 *inspectorVersion[*core.ConfigMap] } func (p *configMapsInspector) LastRefresh() time.Time { @@ -194,3 +121,7 @@ func (p *configMapsInspector) validate() error { return p.v1.validate() } + +func (p *configMapsInspector) V1() generic.Inspector[*core.ConfigMap] { + return p.v1 +} diff --git a/pkg/deployment/resources/inspector/configmaps_gvk.go b/pkg/deployment/resources/inspector/configmaps_gvk.go index 053a96549..33e253a22 100644 --- a/pkg/deployment/resources/inspector/configmaps_gvk.go +++ b/pkg/deployment/resources/inspector/configmaps_gvk.go @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *configMapsInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.ConfigMapGKv1() -} - -func (p *configMapsInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.ConfigMapGRv1() -} - func (p *configMapsInspector) GroupKind() schema.GroupKind { return constants.ConfigMapGK() } diff --git a/pkg/deployment/resources/inspector/configmaps_mod.go b/pkg/deployment/resources/inspector/configmaps_mod.go index 3791df565..2ceec955b 100644 --- a/pkg/deployment/resources/inspector/configmaps_mod.go +++ b/pkg/deployment/resources/inspector/configmaps_mod.go @@ -23,7 +23,6 @@ package inspector import ( core "k8s.io/api/core/v1" - configMapv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" @@ -40,7 +39,7 @@ type configMapsMod struct { i *inspectorState } -func (p configMapsMod) V1() configMapv1.ModInterface { +func (p configMapsMod) V1() generic.ModClient[*core.ConfigMap] { return wrapMod[*core.ConfigMap](definitions.ConfigMap, p.i.GetThrottles, generic.WithModStatusGetter[*core.ConfigMap](constants.ConfigMapGKv1(), p.clientv1)) } diff --git a/pkg/deployment/resources/inspector/configmaps_v1.go b/pkg/deployment/resources/inspector/configmaps_v1.go deleted file mode 100644 index b7a2f90fb..000000000 --- a/pkg/deployment/resources/inspector/configmaps_v1.go +++ /dev/null @@ -1,118 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2024 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" - - core "k8s.io/api/core/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" -) - -func (p *configMapsInspector) V1() ins.Inspector { - return p.v1 -} - -type configMapsInspectorV1 struct { - configMapInspector *configMapsInspector - - configMaps map[string]*core.ConfigMap - err error -} - -func (p *configMapsInspectorV1) validate() error { - if p == nil { - return errors.Errorf("ConfigMapsV1Inspector is nil") - } - - if p.configMapInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.configMaps == nil { - return errors.Errorf("ConfigMaps or err should be not nil") - } - - if p.err != nil { - return errors.Errorf("ConfigMaps or err cannot be not nil together") - } - - return nil -} - -func (p *configMapsInspectorV1) ListSimple() []*core.ConfigMap { - var r []*core.ConfigMap - for _, configMap := range p.configMaps { - r = append(r, configMap) - } - - return r -} - -func (p *configMapsInspectorV1) GetSimple(name string) (*core.ConfigMap, bool) { - configMap, ok := p.configMaps[name] - if !ok { - return nil, false - } - - return configMap, true -} - -func (p *configMapsInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, configMap := range p.configMaps { - if err := p.iterateConfigMap(configMap, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *configMapsInspectorV1) iterateConfigMap(configMap *core.ConfigMap, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(configMap) { - return nil - } - } - - return action(configMap) -} - -func (p *configMapsInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *configMapsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.ConfigMap, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.ConfigMapGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/endpoints.go b/pkg/deployment/resources/inspector/endpoints.go index ce02d6814..7ef635277 100644 --- a/pkg/deployment/resources/inspector/endpoints.go +++ b/pkg/deployment/resources/inspector/endpoints.go @@ -25,11 +25,12 @@ import ( "time" core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +50,18 @@ func (p endpointsInspectorLoader) Component() definitions.Component { func (p endpointsInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q endpointsInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*core.EndpointsList, *core.Endpoints](ctx, + constants.EndpointsGRv1(), + constants.EndpointsGKv1(), + i.client.Kubernetes().CoreV1().Endpoints(i.namespace), + endpoints.List()) + i.endpoints = &q q.state = i q.last = time.Now() } -func (p endpointsInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *endpointsInspector) { - var z endpointsInspectorV1 - - z.endpointsInspector = q - - z.endpoints, z.err = p.getV1Endpoints(ctx, i) - - q.v1 = &z -} - -func (p endpointsInspectorLoader) getV1Endpoints(ctx context.Context, i *inspectorState) (map[string]*core.Endpoints, error) { - objs, err := p.getV1EndpointsList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*core.Endpoints, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p endpointsInspectorLoader) getV1EndpointsList(ctx context.Context, i *inspectorState) ([]*core.Endpoints, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().Endpoints(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*core.Endpoints, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1EndpointsListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p endpointsInspectorLoader) getV1EndpointsListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.Endpoints, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().Endpoints(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p endpointsInspectorLoader) Verify(i *inspectorState) error { return nil } @@ -159,7 +86,7 @@ type endpointsInspector struct { last time.Time - v1 *endpointsInspectorV1 + v1 *inspectorVersion[*core.Endpoints] } func (p *endpointsInspector) LastRefresh() time.Time { @@ -190,3 +117,11 @@ func (p *endpointsInspector) validate() error { return p.v1.validate() } + +func (p *endpointsInspector) V1() (generic.Inspector[*core.Endpoints], error) { + if p.v1.err != nil { + return nil, p.v1.err + } + + return p.v1, nil +} diff --git a/pkg/deployment/resources/inspector/endpoints_gvk.go b/pkg/deployment/resources/inspector/endpoints_gvk.go index 0e9e2f3fa..eaaf57014 100644 --- a/pkg/deployment/resources/inspector/endpoints_gvk.go +++ b/pkg/deployment/resources/inspector/endpoints_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *endpointsInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.EndpointsGKv1() -} - -func (p *endpointsInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.EndpointsGRv1() -} - func (p *endpointsInspector) GroupKind() schema.GroupKind { return constants.EndpointsGK() } diff --git a/pkg/deployment/resources/inspector/endpoints_mod.go b/pkg/deployment/resources/inspector/endpoints_mod.go index e48fb6093..c806df5b4 100644 --- a/pkg/deployment/resources/inspector/endpoints_mod.go +++ b/pkg/deployment/resources/inspector/endpoints_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -25,7 +25,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" - endpointsv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" ) @@ -40,7 +39,7 @@ type endpointsMod struct { i *inspectorState } -func (p endpointsMod) V1() endpointsv1.ModInterface { +func (p endpointsMod) V1() generic.ModClient[*core.Endpoints] { return wrapMod[*core.Endpoints](definitions.Endpoints, p.i.GetThrottles, generic.WithModStatusGetter[*core.Endpoints](constants.EndpointsGKv1(), p.clientv1)) } diff --git a/pkg/deployment/resources/inspector/endpoints_v1.go b/pkg/deployment/resources/inspector/endpoints_v1.go deleted file mode 100644 index 9c502d715..000000000 --- a/pkg/deployment/resources/inspector/endpoints_v1.go +++ /dev/null @@ -1,138 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - core "k8s.io/api/core/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints/v1" -) - -func (p *endpointsInspector) V1() (ins.Inspector, error) { - if p.v1.err != nil { - return nil, p.v1.err - } - - return p.v1, nil -} - -type endpointsInspectorV1 struct { - endpointsInspector *endpointsInspector - - endpoints map[string]*core.Endpoints - err error -} - -func (p *endpointsInspectorV1) Filter(filters ...ins.Filter) []*core.Endpoints { - z := p.ListSimple() - - r := make([]*core.Endpoints, 0, len(z)) - - for _, o := range z { - if !ins.FilterObject(o, filters...) { - continue - } - - r = append(r, o) - } - - return r -} - -func (p *endpointsInspectorV1) validate() error { - if p == nil { - return errors.Errorf("EndpointsV1Inspector is nil") - } - - if p.endpointsInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.endpoints == nil && p.err == nil { - return errors.Errorf("Endpoints or err should be not nil") - } - - if p.endpoints != nil && p.err != nil { - return errors.Errorf("Endpoints or err cannot be not nil together") - } - - return nil -} - -func (p *endpointsInspectorV1) ListSimple() []*core.Endpoints { - var r []*core.Endpoints - for _, endpoints := range p.endpoints { - r = append(r, endpoints) - } - - return r -} - -func (p *endpointsInspectorV1) GetSimple(name string) (*core.Endpoints, bool) { - endpoints, ok := p.endpoints[name] - if !ok { - return nil, false - } - - return endpoints, true -} - -func (p *endpointsInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, endpoints := range p.endpoints { - if err := p.iterateEndpoints(endpoints, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *endpointsInspectorV1) iterateEndpoints(endpoints *core.Endpoints, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(endpoints) { - return nil - } - } - - return action(endpoints) -} - -func (p *endpointsInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *endpointsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Endpoints, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.EndpointsGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/generic.go b/pkg/deployment/resources/inspector/generic.go new file mode 100644 index 000000000..449c26694 --- /dev/null +++ b/pkg/deployment/resources/inspector/generic.go @@ -0,0 +1,154 @@ +// +// DISCLAIMER +// +// Copyright 2024 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" + + "github.com/pkg/errors" + apiErrors "k8s.io/apimachinery/pkg/api/errors" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/util" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" +) + +func List[L generic.ListContinue, S meta.Object](ctx context.Context, i generic.ListInterface[L], call generic.ExtractorList[L, S]) (map[string]S, error) { + return list.APIMap[L, S](ctx, i, meta.ListOptions{}, call) +} + +func newInspectorVersion[L generic.ListContinue, S meta.Object](ctx context.Context, + gvr schema.GroupVersionResource, + gvk schema.GroupVersionKind, + i generic.ListInterface[L], + call generic.ExtractorList[L, S]) *inspectorVersion[S] { + var r inspectorVersion[S] + + r.gvr = gvr + r.gvk = gvk + + r.items, r.err = List(ctx, i, call) + + return &r +} + +type inspectorVersion[S meta.Object] struct { + items map[string]S + gvr schema.GroupVersionResource + gvk schema.GroupVersionKind + err error +} + +func (p *inspectorVersion[S]) GroupVersionKind() schema.GroupVersionKind { + return p.gvk +} + +func (p *inspectorVersion[S]) GroupVersionResource() schema.GroupVersionResource { + return p.gvr +} + +func (p *inspectorVersion[S]) Filter(filters ...generic.Filter[S]) []S { + z := p.ListSimple() + + r := make([]S, 0, len(z)) + + for _, o := range z { + if !generic.FilterObject(o, filters...) { + continue + } + + r = append(r, o) + } + + return r +} + +func (p *inspectorVersion[S]) validate() error { + if p == nil { + return errors.Errorf("Inspector is nil") + } + + if p.items == nil && p.err == nil { + return errors.Errorf("Items or err should be not nil") + } + + if p.items != nil && p.err != nil { + return errors.Errorf("Items or err cannot be not nil together") + } + + return nil +} + +func (p *inspectorVersion[S]) ListSimple() []S { + var r []S + for _, item := range p.items { + r = append(r, item) + } + + return r +} + +func (p *inspectorVersion[S]) GetSimple(name string) (S, bool) { + item, ok := p.items[name] + if !ok { + return util.Default[S](), false + } + + return item, true +} + +func (p *inspectorVersion[S]) Iterate(action generic.Action[S], filters ...generic.Filter[S]) error { + for _, item := range p.items { + if err := p.iterateArangoProfile(item, action, filters...); err != nil { + return err + } + } + + return nil +} + +func (p *inspectorVersion[S]) iterateArangoProfile(item S, action generic.Action[S], filters ...generic.Filter[S]) error { + for _, f := range filters { + if f == nil { + continue + } + + if !f(item) { + return nil + } + } + + return action(item) +} + +func (p *inspectorVersion[S]) Read() generic.ReadClient[S] { + return p +} + +func (p *inspectorVersion[S]) Get(ctx context.Context, name string, opts meta.GetOptions) (S, error) { + if s, ok := p.GetSimple(name); !ok { + return util.Default[S](), apiErrors.NewNotFound(p.gvr.GroupResource(), name) + } else { + return s, nil + } +} diff --git a/pkg/deployment/resources/inspector/inspector.go b/pkg/deployment/resources/inspector/inspector.go index 1a8d7a434..cea92e378 100644 --- a/pkg/deployment/resources/inspector/inspector.go +++ b/pkg/deployment/resources/inspector/inspector.go @@ -174,7 +174,7 @@ func (i *inspectorState) RegisterInformers(k8s informers.SharedInformerFactory, arango.Database().V1().ArangoTasks().Informer().AddEventHandler(i.eventHandler(definitions.ArangoTask)) } - if _, err := i.ArangoProfiles().V1Beta1(); err == nil { + if _, err := i.ArangoProfile().V1Beta1(); err == nil { arango.Scheduler().V1beta1().ArangoProfiles().Informer().AddEventHandler(i.eventHandler(definitions.ArangoProfile)) } @@ -346,10 +346,6 @@ func (i *inspectorState) ArangoProfile() arangoprofile.Definition { return i.arangoProfiles } -func (i *inspectorState) ArangoProfiles() arangoprofile.Definition { - return i.arangoProfiles -} - func (i *inspectorState) Refresh(ctx context.Context) error { return i.refresh(ctx, inspectorLoadersList...) } diff --git a/pkg/deployment/resources/inspector/nodes.go b/pkg/deployment/resources/inspector/nodes.go index 6da09e025..7e973ed00 100644 --- a/pkg/deployment/resources/inspector/nodes.go +++ b/pkg/deployment/resources/inspector/nodes.go @@ -25,11 +25,12 @@ import ( "time" core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/node" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +50,18 @@ func (p nodesInspectorLoader) Component() definitions.Component { func (p nodesInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q nodesInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*core.NodeList, *core.Node](ctx, + constants.NodeGRv1(), + constants.NodeGKv1(), + i.client.Kubernetes().CoreV1().Nodes(), + node.List()) + i.nodes = &q q.state = i q.last = time.Now() } -func (p nodesInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *nodesInspector) { - var z nodesInspectorV1 - - z.nodeInspector = q - - z.nodes, z.err = p.getV1Nodes(ctx, i) - - q.v1 = &z -} - -func (p nodesInspectorLoader) getV1Nodes(ctx context.Context, i *inspectorState) (map[string]*core.Node, error) { - objs, err := p.getV1NodesList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*core.Node, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p nodesInspectorLoader) getV1NodesList(ctx context.Context, i *inspectorState) ([]*core.Node, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().Nodes().List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*core.Node, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1NodesListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p nodesInspectorLoader) getV1NodesListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.Node, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().Nodes().List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p nodesInspectorLoader) Verify(i *inspectorState) error { return nil } @@ -159,7 +86,7 @@ type nodesInspector struct { last time.Time - v1 *nodesInspectorV1 + v1 *inspectorVersion[*core.Node] } func (p *nodesInspector) LastRefresh() time.Time { @@ -190,3 +117,11 @@ func (p *nodesInspector) validate() error { return p.v1.validate() } + +func (p *nodesInspector) V1() (generic.Inspector[*core.Node], error) { + if p.v1.err != nil { + return nil, p.v1.err + } + + return p.v1, nil +} diff --git a/pkg/deployment/resources/inspector/nodes_gvk.go b/pkg/deployment/resources/inspector/nodes_gvk.go index e300845dc..5fae37ad3 100644 --- a/pkg/deployment/resources/inspector/nodes_gvk.go +++ b/pkg/deployment/resources/inspector/nodes_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *nodesInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.NodeGKv1() -} - -func (p *nodesInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.NodeGRv1() -} - func (p *nodesInspector) GroupKind() schema.GroupKind { return constants.NodeGK() } diff --git a/pkg/deployment/resources/inspector/nodes_v1.go b/pkg/deployment/resources/inspector/nodes_v1.go deleted file mode 100644 index 5fac5a7b0..000000000 --- a/pkg/deployment/resources/inspector/nodes_v1.go +++ /dev/null @@ -1,122 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - core "k8s.io/api/core/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/node/v1" -) - -func (p *nodesInspector) V1() (ins.Inspector, error) { - if p.v1.err != nil { - return nil, p.v1.err - } - - return p.v1, nil -} - -type nodesInspectorV1 struct { - nodeInspector *nodesInspector - - nodes map[string]*core.Node - err error -} - -func (p *nodesInspectorV1) validate() error { - if p == nil { - return errors.Errorf("NodesV1Inspector is nil") - } - - if p.nodeInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.nodes == nil && p.err == nil { - return errors.Errorf("Nodes or err should be not nil") - } - - if p.nodes != nil && p.err != nil { - return errors.Errorf("Nodes or err cannot be not nil together") - } - - return nil -} - -func (p *nodesInspectorV1) ListSimple() []*core.Node { - var r []*core.Node - for _, node := range p.nodes { - r = append(r, node) - } - - return r -} - -func (p *nodesInspectorV1) GetSimple(name string) (*core.Node, bool) { - node, ok := p.nodes[name] - if !ok { - return nil, false - } - - return node, true -} - -func (p *nodesInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, node := range p.nodes { - if err := p.iterateNode(node, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *nodesInspectorV1) iterateNode(node *core.Node, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(node) { - return nil - } - } - - return action(node) -} - -func (p *nodesInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *nodesInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Node, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.NodeGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/pdbs.go b/pkg/deployment/resources/inspector/pdbs.go index ac1b7c8ec..f80b7dba2 100644 --- a/pkg/deployment/resources/inspector/pdbs.go +++ b/pkg/deployment/resources/inspector/pdbs.go @@ -25,11 +25,12 @@ import ( "time" policy "k8s.io/api/policy/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -51,11 +52,14 @@ func (p podDisruptionBudgetsInspectorLoader) Load(ctx context.Context, i *inspec var q podDisruptionBudgetsInspector if i.versionInfo.CompareTo("1.21") >= 1 { - p.loadV1(ctx, i, &q) + q.v1 = newInspectorVersion[*policy.PodDisruptionBudgetList, *policy.PodDisruptionBudget](ctx, + constants.PodDisruptionBudgetGRv1(), + constants.PodDisruptionBudgetGKv1(), + i.client.Kubernetes().PolicyV1().PodDisruptionBudgets(i.namespace), + poddisruptionbudget.List()) } else { - q.v1 = &podDisruptionBudgetsInspectorV1{ - podDisruptionBudgetInspector: &q, - err: newMinK8SVersion("1.20"), + q.v1 = &inspectorVersion[*policy.PodDisruptionBudget]{ + err: newMinK8SVersion("1.20"), } } @@ -64,86 +68,6 @@ func (p podDisruptionBudgetsInspectorLoader) Load(ctx context.Context, i *inspec q.last = time.Now() } -func (p podDisruptionBudgetsInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *podDisruptionBudgetsInspector) { - var z podDisruptionBudgetsInspectorV1 - - z.podDisruptionBudgetInspector = q - - z.podDisruptionBudgets, z.err = p.getV1PodDisruptionBudgets(ctx, i) - - q.v1 = &z -} - -func (p podDisruptionBudgetsInspectorLoader) getV1PodDisruptionBudgets(ctx context.Context, i *inspectorState) (map[string]*policy.PodDisruptionBudget, error) { - objs, err := p.getV1PodDisruptionBudgetsList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*policy.PodDisruptionBudget, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p podDisruptionBudgetsInspectorLoader) getV1PodDisruptionBudgetsList(ctx context.Context, i *inspectorState) ([]*policy.PodDisruptionBudget, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().PolicyV1().PodDisruptionBudgets(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*policy.PodDisruptionBudget, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1PodDisruptionBudgetsListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p podDisruptionBudgetsInspectorLoader) getV1PodDisruptionBudgetsListRequest(ctx context.Context, i *inspectorState, cont string) ([]policy.PodDisruptionBudget, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().PolicyV1().PodDisruptionBudgets(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p podDisruptionBudgetsInspectorLoader) Verify(i *inspectorState) error { return nil } @@ -168,7 +92,7 @@ type podDisruptionBudgetsInspector struct { last time.Time - v1 *podDisruptionBudgetsInspectorV1 + v1 *inspectorVersion[*policy.PodDisruptionBudget] } func (p *podDisruptionBudgetsInspector) LastRefresh() time.Time { @@ -205,3 +129,11 @@ func (p *podDisruptionBudgetsInspector) validate() error { return nil } + +func (p *podDisruptionBudgetsInspector) V1() (generic.Inspector[*policy.PodDisruptionBudget], error) { + if p.v1.err != nil { + return nil, p.v1.err + } + + return p.v1, nil +} diff --git a/pkg/deployment/resources/inspector/pdbs_gvk.go b/pkg/deployment/resources/inspector/pdbs_gvk.go index 9031b9392..9511ffaa0 100644 --- a/pkg/deployment/resources/inspector/pdbs_gvk.go +++ b/pkg/deployment/resources/inspector/pdbs_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *podDisruptionBudgetsInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.PodDisruptionBudgetGKv1() -} - -func (p *podDisruptionBudgetsInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.PodDisruptionBudgetGRv1() -} - func (p *podDisruptionBudgetsInspector) GroupKind() schema.GroupKind { return constants.PodDisruptionBudgetGK() } diff --git a/pkg/deployment/resources/inspector/pdbs_mod.go b/pkg/deployment/resources/inspector/pdbs_mod.go index 9fc8d0c57..bceb587c8 100644 --- a/pkg/deployment/resources/inspector/pdbs_mod.go +++ b/pkg/deployment/resources/inspector/pdbs_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -27,7 +27,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" - policyv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1" ) func (i *inspectorState) PodDisruptionBudgetsModInterface() mods.PodDisruptionBudgetsMods { @@ -40,7 +39,7 @@ type podDisruptionBudgetsMod struct { i *inspectorState } -func (p podDisruptionBudgetsMod) V1() policyv1.ModInterface { +func (p podDisruptionBudgetsMod) V1() generic.ModClient[*policy.PodDisruptionBudget] { return wrapMod[*policy.PodDisruptionBudget](definitions.PodDisruptionBudget, p.i.GetThrottles, generic.WithModStatusGetter[*policy.PodDisruptionBudget](constants.PodDisruptionBudgetGKv1(), p.clientv1)) } diff --git a/pkg/deployment/resources/inspector/pdbs_v1.go b/pkg/deployment/resources/inspector/pdbs_v1.go deleted file mode 100644 index 5a17bfd63..000000000 --- a/pkg/deployment/resources/inspector/pdbs_v1.go +++ /dev/null @@ -1,122 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - policy "k8s.io/api/policy/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1" -) - -func (p *podDisruptionBudgetsInspector) V1() (ins.Inspector, error) { - if p.v1.err != nil { - return nil, p.v1.err - } - - return p.v1, nil -} - -type podDisruptionBudgetsInspectorV1 struct { - podDisruptionBudgetInspector *podDisruptionBudgetsInspector - - podDisruptionBudgets map[string]*policy.PodDisruptionBudget - err error -} - -func (p *podDisruptionBudgetsInspectorV1) validate() error { - if p == nil { - return errors.Errorf("PodDisruptionBudgetsV1Inspector is nil") - } - - if p.podDisruptionBudgetInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.podDisruptionBudgets == nil && p.err == nil { - return errors.Errorf("PodDisruptionBudgets or err should be not nil") - } - - if p.podDisruptionBudgets != nil && p.err != nil { - return errors.Errorf("PodDisruptionBudgets or err cannot be not nil together") - } - - return nil -} - -func (p *podDisruptionBudgetsInspectorV1) PodDisruptionBudgets() []*policy.PodDisruptionBudget { - var r []*policy.PodDisruptionBudget - for _, podDisruptionBudget := range p.podDisruptionBudgets { - r = append(r, podDisruptionBudget) - } - - return r -} - -func (p *podDisruptionBudgetsInspectorV1) GetSimple(name string) (*policy.PodDisruptionBudget, bool) { - podDisruptionBudget, ok := p.podDisruptionBudgets[name] - if !ok { - return nil, false - } - - return podDisruptionBudget, true -} - -func (p *podDisruptionBudgetsInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, podDisruptionBudget := range p.podDisruptionBudgets { - if err := p.iteratePodDisruptionBudget(podDisruptionBudget, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *podDisruptionBudgetsInspectorV1) iteratePodDisruptionBudget(podDisruptionBudget *policy.PodDisruptionBudget, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(podDisruptionBudget) { - return nil - } - } - - return action(podDisruptionBudget) -} - -func (p *podDisruptionBudgetsInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *podDisruptionBudgetsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*policy.PodDisruptionBudget, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.PodDisruptionBudgetGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/pods.go b/pkg/deployment/resources/inspector/pods.go index af3dc4092..a16908a6b 100644 --- a/pkg/deployment/resources/inspector/pods.go +++ b/pkg/deployment/resources/inspector/pods.go @@ -25,11 +25,12 @@ import ( "time" core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +50,18 @@ func (p podsInspectorLoader) Component() definitions.Component { func (p podsInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q podsInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*core.PodList, *core.Pod](ctx, + constants.PodGRv1(), + constants.PodGKv1(), + i.client.Kubernetes().CoreV1().Pods(i.namespace), + pod.List()) + i.pods = &q q.state = i q.last = time.Now() } -func (p podsInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *podsInspector) { - var z podsInspectorV1 - - z.podInspector = q - - z.pods, z.err = p.getV1Pods(ctx, i) - - q.v1 = &z -} - -func (p podsInspectorLoader) getV1Pods(ctx context.Context, i *inspectorState) (map[string]*core.Pod, error) { - objs, err := p.getV1PodsList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*core.Pod, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p podsInspectorLoader) getV1PodsList(ctx context.Context, i *inspectorState) ([]*core.Pod, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().Pods(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*core.Pod, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1PodsListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p podsInspectorLoader) getV1PodsListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.Pod, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().Pods(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p podsInspectorLoader) Verify(i *inspectorState) error { if err := i.pods.v1.err; err != nil { return err @@ -163,7 +90,7 @@ type podsInspector struct { last time.Time - v1 *podsInspectorV1 + v1 *inspectorVersion[*core.Pod] } func (p *podsInspector) LastRefresh() time.Time { @@ -194,3 +121,8 @@ func (p *podsInspector) validate() error { return p.v1.validate() } + +func (p *podsInspector) V1() generic.Inspector[*core.Pod] { + + return p.v1 +} diff --git a/pkg/deployment/resources/inspector/pods_gvk.go b/pkg/deployment/resources/inspector/pods_gvk.go index dc953e927..7e54a7a8e 100644 --- a/pkg/deployment/resources/inspector/pods_gvk.go +++ b/pkg/deployment/resources/inspector/pods_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *podsInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.PodGKv1() -} - -func (p *podsInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.PodGRv1() -} - func (p *podsInspector) GroupKind() schema.GroupKind { return constants.PodGK() } diff --git a/pkg/deployment/resources/inspector/pods_mod.go b/pkg/deployment/resources/inspector/pods_mod.go index 1262e9221..0d95c4543 100644 --- a/pkg/deployment/resources/inspector/pods_mod.go +++ b/pkg/deployment/resources/inspector/pods_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -27,7 +27,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" - podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" ) func (i *inspectorState) PodsModInterface() mods.PodsMods { @@ -40,7 +39,7 @@ type podsMod struct { i *inspectorState } -func (p podsMod) V1() podv1.ModInterface { +func (p podsMod) V1() generic.ModClient[*core.Pod] { return wrapMod[*core.Pod](definitions.Pod, p.i.GetThrottles, generic.WithModStatusGetter[*core.Pod](constants.PodGKv1(), p.clientv1)) } diff --git a/pkg/deployment/resources/inspector/pods_v1.go b/pkg/deployment/resources/inspector/pods_v1.go deleted file mode 100644 index 23c562bfa..000000000 --- a/pkg/deployment/resources/inspector/pods_v1.go +++ /dev/null @@ -1,119 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - core "k8s.io/api/core/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" -) - -func (p *podsInspector) V1() ins.Inspector { - - return p.v1 -} - -type podsInspectorV1 struct { - podInspector *podsInspector - - pods map[string]*core.Pod - err error -} - -func (p *podsInspectorV1) validate() error { - if p == nil { - return errors.Errorf("PodsV1Inspector is nil") - } - - if p.podInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.pods == nil { - return errors.Errorf("Pods or err should be not nil") - } - - if p.err != nil { - return errors.Errorf("Pods or err cannot be not nil together") - } - - return nil -} - -func (p *podsInspectorV1) ListSimple() []*core.Pod { - var r []*core.Pod - for _, pod := range p.pods { - r = append(r, pod) - } - - return r -} - -func (p *podsInspectorV1) GetSimple(name string) (*core.Pod, bool) { - pod, ok := p.pods[name] - if !ok { - return nil, false - } - - return pod, true -} - -func (p *podsInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, pod := range p.pods { - if err := p.iteratePod(pod, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *podsInspectorV1) iteratePod(pod *core.Pod, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(pod) { - return nil - } - } - - return action(pod) -} - -func (p *podsInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *podsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Pod, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.PodGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/pvcs.go b/pkg/deployment/resources/inspector/pvcs.go index 9ecdc11f8..eb9a4e1d3 100644 --- a/pkg/deployment/resources/inspector/pvcs.go +++ b/pkg/deployment/resources/inspector/pvcs.go @@ -25,11 +25,12 @@ import ( "time" core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +50,18 @@ func (p persistentVolumeClaimsInspectorLoader) Component() definitions.Component func (p persistentVolumeClaimsInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q persistentVolumeClaimsInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*core.PersistentVolumeClaimList, *core.PersistentVolumeClaim](ctx, + constants.PersistentVolumeClaimGRv1(), + constants.PersistentVolumeClaimGKv1(), + i.client.Kubernetes().CoreV1().PersistentVolumeClaims(i.namespace), + persistentvolumeclaim.List()) + i.persistentVolumeClaims = &q q.state = i q.last = time.Now() } -func (p persistentVolumeClaimsInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *persistentVolumeClaimsInspector) { - var z persistentVolumeClaimsInspectorV1 - - z.persistentVolumeClaimInspector = q - - z.persistentVolumeClaims, z.err = p.getV1PersistentVolumeClaims(ctx, i) - - q.v1 = &z -} - -func (p persistentVolumeClaimsInspectorLoader) getV1PersistentVolumeClaims(ctx context.Context, i *inspectorState) (map[string]*core.PersistentVolumeClaim, error) { - objs, err := p.getV1PersistentVolumeClaimsList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*core.PersistentVolumeClaim, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p persistentVolumeClaimsInspectorLoader) getV1PersistentVolumeClaimsList(ctx context.Context, i *inspectorState) ([]*core.PersistentVolumeClaim, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().PersistentVolumeClaims(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*core.PersistentVolumeClaim, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1PersistentVolumeClaimsListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p persistentVolumeClaimsInspectorLoader) getV1PersistentVolumeClaimsListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.PersistentVolumeClaim, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().PersistentVolumeClaims(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p persistentVolumeClaimsInspectorLoader) Verify(i *inspectorState) error { if err := i.persistentVolumeClaims.v1.err; err != nil { return err @@ -163,7 +90,7 @@ type persistentVolumeClaimsInspector struct { last time.Time - v1 *persistentVolumeClaimsInspectorV1 + v1 *inspectorVersion[*core.PersistentVolumeClaim] } func (p *persistentVolumeClaimsInspector) LastRefresh() time.Time { @@ -194,3 +121,7 @@ func (p *persistentVolumeClaimsInspector) validate() error { return p.v1.validate() } + +func (p *persistentVolumeClaimsInspector) V1() generic.Inspector[*core.PersistentVolumeClaim] { + return p.v1 +} diff --git a/pkg/deployment/resources/inspector/pvcs_gvk.go b/pkg/deployment/resources/inspector/pvcs_gvk.go index b4095fa26..c1096783a 100644 --- a/pkg/deployment/resources/inspector/pvcs_gvk.go +++ b/pkg/deployment/resources/inspector/pvcs_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *persistentVolumeClaimsInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.PersistentVolumeClaimGKv1() -} - -func (p *persistentVolumeClaimsInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.PersistentVolumeClaimGRv1() -} - func (p *persistentVolumeClaimsInspector) GroupKind() schema.GroupKind { return constants.PersistentVolumeClaimGK() } diff --git a/pkg/deployment/resources/inspector/pvcs_mod.go b/pkg/deployment/resources/inspector/pvcs_mod.go index 95dcce9c3..05a49f358 100644 --- a/pkg/deployment/resources/inspector/pvcs_mod.go +++ b/pkg/deployment/resources/inspector/pvcs_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -27,7 +27,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" - persistentvolumeclaimv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1" ) func (i *inspectorState) PersistentVolumeClaimsModInterface() mods.PersistentVolumeClaimsMods { @@ -40,7 +39,7 @@ type persistentVolumeClaimsMod struct { i *inspectorState } -func (p persistentVolumeClaimsMod) V1() persistentvolumeclaimv1.ModInterface { +func (p persistentVolumeClaimsMod) V1() generic.ModClient[*core.PersistentVolumeClaim] { return wrapMod[*core.PersistentVolumeClaim](definitions.PersistentVolumeClaim, p.i.GetThrottles, generic.WithModStatusGetter[*core.PersistentVolumeClaim](constants.PersistentVolumeClaimGKv1(), p.clientv1)) } diff --git a/pkg/deployment/resources/inspector/pvcs_v1.go b/pkg/deployment/resources/inspector/pvcs_v1.go deleted file mode 100644 index e375a31ca..000000000 --- a/pkg/deployment/resources/inspector/pvcs_v1.go +++ /dev/null @@ -1,118 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - core "k8s.io/api/core/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1" -) - -func (p *persistentVolumeClaimsInspector) V1() ins.Inspector { - return p.v1 -} - -type persistentVolumeClaimsInspectorV1 struct { - persistentVolumeClaimInspector *persistentVolumeClaimsInspector - - persistentVolumeClaims map[string]*core.PersistentVolumeClaim - err error -} - -func (p *persistentVolumeClaimsInspectorV1) validate() error { - if p == nil { - return errors.Errorf("PersistentVolumeClaimsV1Inspector is nil") - } - - if p.persistentVolumeClaimInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.persistentVolumeClaims == nil { - return errors.Errorf("PersistentVolumeClaims or err should be not nil") - } - - if p.err != nil { - return errors.Errorf("PersistentVolumeClaims or err cannot be not nil together") - } - - return nil -} - -func (p *persistentVolumeClaimsInspectorV1) ListSimple() []*core.PersistentVolumeClaim { - var r []*core.PersistentVolumeClaim - for _, persistentVolumeClaim := range p.persistentVolumeClaims { - r = append(r, persistentVolumeClaim) - } - - return r -} - -func (p *persistentVolumeClaimsInspectorV1) GetSimple(name string) (*core.PersistentVolumeClaim, bool) { - persistentVolumeClaim, ok := p.persistentVolumeClaims[name] - if !ok { - return nil, false - } - - return persistentVolumeClaim, true -} - -func (p *persistentVolumeClaimsInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, persistentVolumeClaim := range p.persistentVolumeClaims { - if err := p.iteratePersistentVolumeClaim(persistentVolumeClaim, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *persistentVolumeClaimsInspectorV1) iteratePersistentVolumeClaim(persistentVolumeClaim *core.PersistentVolumeClaim, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(persistentVolumeClaim) { - return nil - } - } - - return action(persistentVolumeClaim) -} - -func (p *persistentVolumeClaimsInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *persistentVolumeClaimsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.PersistentVolumeClaim, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.PersistentVolumeClaimGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/pvs.go b/pkg/deployment/resources/inspector/pvs.go index 2ef931ea8..b73c24b1b 100644 --- a/pkg/deployment/resources/inspector/pvs.go +++ b/pkg/deployment/resources/inspector/pvs.go @@ -25,11 +25,12 @@ import ( "time" core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolume" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +50,18 @@ func (p persistentVolumesInspectorLoader) Component() definitions.Component { func (p persistentVolumesInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q persistentVolumesInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*core.PersistentVolumeList, *core.PersistentVolume](ctx, + constants.PersistentVolumeGRv1(), + constants.PersistentVolumeGKv1(), + i.client.Kubernetes().CoreV1().PersistentVolumes(), + persistentvolume.List()) + i.persistentVolumes = &q q.state = i q.last = time.Now() } -func (p persistentVolumesInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *persistentVolumesInspector) { - var z persistentVolumesInspectorV1 - - z.persistentVolumeInspector = q - - z.persistentVolumes, z.err = p.getV1PersistentVolumes(ctx, i) - - q.v1 = &z -} - -func (p persistentVolumesInspectorLoader) getV1PersistentVolumes(ctx context.Context, i *inspectorState) (map[string]*core.PersistentVolume, error) { - objs, err := p.getV1PersistentVolumesList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*core.PersistentVolume, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p persistentVolumesInspectorLoader) getV1PersistentVolumesList(ctx context.Context, i *inspectorState) ([]*core.PersistentVolume, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().PersistentVolumes().List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*core.PersistentVolume, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1PersistentVolumesListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p persistentVolumesInspectorLoader) getV1PersistentVolumesListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.PersistentVolume, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().PersistentVolumes().List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p persistentVolumesInspectorLoader) Verify(i *inspectorState) error { return nil } @@ -159,7 +86,7 @@ type persistentVolumesInspector struct { last time.Time - v1 *persistentVolumesInspectorV1 + v1 *inspectorVersion[*core.PersistentVolume] } func (p *persistentVolumesInspector) LastRefresh() time.Time { @@ -190,3 +117,11 @@ func (p *persistentVolumesInspector) validate() error { return p.v1.validate() } + +func (p *persistentVolumesInspector) V1() (generic.Inspector[*core.PersistentVolume], error) { + if p.v1.err != nil { + return nil, p.v1.err + } + + return p.v1, nil +} diff --git a/pkg/deployment/resources/inspector/pvs_gvk.go b/pkg/deployment/resources/inspector/pvs_gvk.go index 055c622fa..3d7d1c856 100644 --- a/pkg/deployment/resources/inspector/pvs_gvk.go +++ b/pkg/deployment/resources/inspector/pvs_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *persistentVolumesInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.PersistentVolumeGKv1() -} - -func (p *persistentVolumesInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.PersistentVolumeGRv1() -} - func (p *persistentVolumesInspector) GroupKind() schema.GroupKind { return constants.PersistentVolumeGK() } diff --git a/pkg/deployment/resources/inspector/pvs_v1.go b/pkg/deployment/resources/inspector/pvs_v1.go deleted file mode 100644 index 818762e95..000000000 --- a/pkg/deployment/resources/inspector/pvs_v1.go +++ /dev/null @@ -1,122 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023-2024 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" - - core "k8s.io/api/core/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolume/v1" -) - -func (p *persistentVolumesInspector) V1() (ins.Inspector, error) { - if p.v1.err != nil { - return nil, p.v1.err - } - - return p.v1, nil -} - -type persistentVolumesInspectorV1 struct { - persistentVolumeInspector *persistentVolumesInspector - - persistentVolumes map[string]*core.PersistentVolume - err error -} - -func (p *persistentVolumesInspectorV1) validate() error { - if p == nil { - return errors.Errorf("PersistentVolumesV1Inspector is nil") - } - - if p.persistentVolumeInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.persistentVolumes == nil && p.err == nil { - return errors.Errorf("PersistentVolumes or err should be not nil") - } - - if p.persistentVolumes != nil && p.err != nil { - return errors.Errorf("PersistentVolumes or err cannot be not nil together") - } - - return nil -} - -func (p *persistentVolumesInspectorV1) ListSimple() []*core.PersistentVolume { - var r []*core.PersistentVolume - for _, persistentVolume := range p.persistentVolumes { - r = append(r, persistentVolume) - } - - return r -} - -func (p *persistentVolumesInspectorV1) GetSimple(name string) (*core.PersistentVolume, bool) { - persistentVolume, ok := p.persistentVolumes[name] - if !ok { - return nil, false - } - - return persistentVolume, true -} - -func (p *persistentVolumesInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, persistentVolume := range p.persistentVolumes { - if err := p.iteratePersistentVolume(persistentVolume, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *persistentVolumesInspectorV1) iteratePersistentVolume(persistentVolume *core.PersistentVolume, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(persistentVolume) { - return nil - } - } - - return action(persistentVolume) -} - -func (p *persistentVolumesInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *persistentVolumesInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.PersistentVolume, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.PersistentVolumeGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/sa.go b/pkg/deployment/resources/inspector/sa.go index a9896ee92..1be1058e5 100644 --- a/pkg/deployment/resources/inspector/sa.go +++ b/pkg/deployment/resources/inspector/sa.go @@ -25,11 +25,12 @@ import ( "time" core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +50,18 @@ func (p serviceAccountsInspectorLoader) Component() definitions.Component { func (p serviceAccountsInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q serviceAccountsInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*core.ServiceAccountList, *core.ServiceAccount](ctx, + constants.ServiceAccountGRv1(), + constants.ServiceAccountGKv1(), + i.client.Kubernetes().CoreV1().ServiceAccounts(i.namespace), + serviceaccount.List()) + i.serviceAccounts = &q q.state = i q.last = time.Now() } -func (p serviceAccountsInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *serviceAccountsInspector) { - var z serviceAccountsInspectorV1 - - z.serviceAccountInspector = q - - z.serviceAccounts, z.err = p.getV1ServiceAccounts(ctx, i) - - q.v1 = &z -} - -func (p serviceAccountsInspectorLoader) getV1ServiceAccounts(ctx context.Context, i *inspectorState) (map[string]*core.ServiceAccount, error) { - objs, err := p.getV1ServiceAccountsList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*core.ServiceAccount, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p serviceAccountsInspectorLoader) getV1ServiceAccountsList(ctx context.Context, i *inspectorState) ([]*core.ServiceAccount, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().ServiceAccounts(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*core.ServiceAccount, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1ServiceAccountsListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p serviceAccountsInspectorLoader) getV1ServiceAccountsListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.ServiceAccount, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().ServiceAccounts(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p serviceAccountsInspectorLoader) Verify(i *inspectorState) error { if err := i.serviceAccounts.v1.err; err != nil { return err @@ -163,7 +90,7 @@ type serviceAccountsInspector struct { last time.Time - v1 *serviceAccountsInspectorV1 + v1 *inspectorVersion[*core.ServiceAccount] } func (p *serviceAccountsInspector) LastRefresh() time.Time { @@ -194,3 +121,7 @@ func (p *serviceAccountsInspector) validate() error { return p.v1.validate() } + +func (p *serviceAccountsInspector) V1() generic.Inspector[*core.ServiceAccount] { + return p.v1 +} diff --git a/pkg/deployment/resources/inspector/sa_gvk.go b/pkg/deployment/resources/inspector/sa_gvk.go index 7a1f778b1..76e2e8ca6 100644 --- a/pkg/deployment/resources/inspector/sa_gvk.go +++ b/pkg/deployment/resources/inspector/sa_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *serviceAccountsInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.ServiceAccountGKv1() -} - -func (p *serviceAccountsInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.ServiceAccountGRv1() -} - func (p *serviceAccountsInspector) GroupKind() schema.GroupKind { return constants.ServiceAccountGK() } diff --git a/pkg/deployment/resources/inspector/sa_mod.go b/pkg/deployment/resources/inspector/sa_mod.go index 0918097b9..b305c0c8f 100644 --- a/pkg/deployment/resources/inspector/sa_mod.go +++ b/pkg/deployment/resources/inspector/sa_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -27,7 +27,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" - serviceaccountv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount/v1" ) func (i *inspectorState) ServiceAccountsModInterface() mods.ServiceAccountsMods { @@ -40,7 +39,7 @@ type serviceAccountsMod struct { i *inspectorState } -func (p serviceAccountsMod) V1() serviceaccountv1.ModInterface { +func (p serviceAccountsMod) V1() generic.ModClient[*core.ServiceAccount] { return wrapMod[*core.ServiceAccount](definitions.ServiceAccount, p.i.GetThrottles, generic.WithModStatusGetter[*core.ServiceAccount](constants.ServiceAccountGKv1(), p.clientv1)) } diff --git a/pkg/deployment/resources/inspector/sa_v1.go b/pkg/deployment/resources/inspector/sa_v1.go deleted file mode 100644 index 1746b8275..000000000 --- a/pkg/deployment/resources/inspector/sa_v1.go +++ /dev/null @@ -1,118 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - core "k8s.io/api/core/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount/v1" -) - -func (p *serviceAccountsInspector) V1() ins.Inspector { - return p.v1 -} - -type serviceAccountsInspectorV1 struct { - serviceAccountInspector *serviceAccountsInspector - - serviceAccounts map[string]*core.ServiceAccount - err error -} - -func (p *serviceAccountsInspectorV1) validate() error { - if p == nil { - return errors.Errorf("ServiceAccountsV1Inspector is nil") - } - - if p.serviceAccountInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.serviceAccounts == nil { - return errors.Errorf("ServiceAccounts or err should be not nil") - } - - if p.err != nil { - return errors.Errorf("ServiceAccounts or err cannot be not nil together") - } - - return nil -} - -func (p *serviceAccountsInspectorV1) ServiceAccounts() []*core.ServiceAccount { - var r []*core.ServiceAccount - for _, serviceAccount := range p.serviceAccounts { - r = append(r, serviceAccount) - } - - return r -} - -func (p *serviceAccountsInspectorV1) GetSimple(name string) (*core.ServiceAccount, bool) { - serviceAccount, ok := p.serviceAccounts[name] - if !ok { - return nil, false - } - - return serviceAccount, true -} - -func (p *serviceAccountsInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, serviceAccount := range p.serviceAccounts { - if err := p.iterateServiceAccount(serviceAccount, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *serviceAccountsInspectorV1) iterateServiceAccount(serviceAccount *core.ServiceAccount, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(serviceAccount) { - return nil - } - } - - return action(serviceAccount) -} - -func (p *serviceAccountsInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *serviceAccountsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.ServiceAccount, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.ServiceAccountGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/secrets.go b/pkg/deployment/resources/inspector/secrets.go index 326b25b8c..c3f0b1ba2 100644 --- a/pkg/deployment/resources/inspector/secrets.go +++ b/pkg/deployment/resources/inspector/secrets.go @@ -25,11 +25,12 @@ import ( "time" core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +50,18 @@ func (p secretsInspectorLoader) Component() definitions.Component { func (p secretsInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q secretsInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*core.SecretList, *core.Secret](ctx, + constants.SecretGRv1(), + constants.SecretGKv1(), + i.client.Kubernetes().CoreV1().Secrets(i.namespace), + secret.List()) + i.secrets = &q q.state = i q.last = time.Now() } -func (p secretsInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *secretsInspector) { - var z secretsInspectorV1 - - z.secretInspector = q - - z.secrets, z.err = p.getV1Secrets(ctx, i) - - q.v1 = &z -} - -func (p secretsInspectorLoader) getV1Secrets(ctx context.Context, i *inspectorState) (map[string]*core.Secret, error) { - objs, err := p.getV1SecretsList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*core.Secret, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p secretsInspectorLoader) getV1SecretsList(ctx context.Context, i *inspectorState) ([]*core.Secret, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().Secrets(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*core.Secret, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1SecretsListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p secretsInspectorLoader) getV1SecretsListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.Secret, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().Secrets(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p secretsInspectorLoader) Verify(i *inspectorState) error { if err := i.secrets.v1.err; err != nil { return err @@ -163,7 +90,7 @@ type secretsInspector struct { last time.Time - v1 *secretsInspectorV1 + v1 *inspectorVersion[*core.Secret] } func (p *secretsInspector) LastRefresh() time.Time { @@ -194,3 +121,7 @@ func (p *secretsInspector) validate() error { return p.v1.validate() } + +func (p *secretsInspector) V1() generic.Inspector[*core.Secret] { + return p.v1 +} diff --git a/pkg/deployment/resources/inspector/secrets_gvk.go b/pkg/deployment/resources/inspector/secrets_gvk.go index b38f4369c..28f101233 100644 --- a/pkg/deployment/resources/inspector/secrets_gvk.go +++ b/pkg/deployment/resources/inspector/secrets_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *secretsInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.SecretGKv1() -} - -func (p *secretsInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.SecretGRv1() -} - func (p *secretsInspector) GroupKind() schema.GroupKind { return constants.SecretGK() } diff --git a/pkg/deployment/resources/inspector/secrets_mod.go b/pkg/deployment/resources/inspector/secrets_mod.go index 3b6429afd..8fda662c9 100644 --- a/pkg/deployment/resources/inspector/secrets_mod.go +++ b/pkg/deployment/resources/inspector/secrets_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -27,7 +27,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" - secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" ) func (i *inspectorState) SecretsModInterface() mods.SecretsMods { @@ -40,7 +39,7 @@ type secretsMod struct { i *inspectorState } -func (p secretsMod) V1() secretv1.ModInterface { +func (p secretsMod) V1() generic.ModClient[*core.Secret] { return wrapMod[*core.Secret](definitions.Secret, p.i.GetThrottles, generic.WithModStatusGetter[*core.Secret](constants.SecretGKv1(), p.clientv1)) } diff --git a/pkg/deployment/resources/inspector/secrets_v1.go b/pkg/deployment/resources/inspector/secrets_v1.go deleted file mode 100644 index 6925d8f5f..000000000 --- a/pkg/deployment/resources/inspector/secrets_v1.go +++ /dev/null @@ -1,118 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - core "k8s.io/api/core/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" -) - -func (p *secretsInspector) V1() ins.Inspector { - return p.v1 -} - -type secretsInspectorV1 struct { - secretInspector *secretsInspector - - secrets map[string]*core.Secret - err error -} - -func (p *secretsInspectorV1) validate() error { - if p == nil { - return errors.Errorf("SecretsV1Inspector is nil") - } - - if p.secretInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.secrets == nil { - return errors.Errorf("Secrets or err should be not nil") - } - - if p.err != nil { - return errors.Errorf("Secrets or err cannot be not nil together") - } - - return nil -} - -func (p *secretsInspectorV1) ListSimple() []*core.Secret { - var r []*core.Secret - for _, secret := range p.secrets { - r = append(r, secret) - } - - return r -} - -func (p *secretsInspectorV1) GetSimple(name string) (*core.Secret, bool) { - secret, ok := p.secrets[name] - if !ok { - return nil, false - } - - return secret, true -} - -func (p *secretsInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, secret := range p.secrets { - if err := p.iterateSecret(secret, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *secretsInspectorV1) iterateSecret(secret *core.Secret, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(secret) { - return nil - } - } - - return action(secret) -} - -func (p *secretsInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *secretsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Secret, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.SecretGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/services.go b/pkg/deployment/resources/inspector/services.go index 58e210e4d..2313ecd54 100644 --- a/pkg/deployment/resources/inspector/services.go +++ b/pkg/deployment/resources/inspector/services.go @@ -25,11 +25,12 @@ import ( "time" core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,92 +50,18 @@ func (p servicesInspectorLoader) Component() definitions.Component { func (p servicesInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q servicesInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*core.ServiceList, *core.Service](ctx, + constants.ServiceGRv1(), + constants.ServiceGKv1(), + i.client.Kubernetes().CoreV1().Services(i.namespace), + service.List()) + i.services = &q q.state = i q.last = time.Now() } -func (p servicesInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *servicesInspector) { - var z servicesInspectorV1 - - z.serviceInspector = q - - z.services, z.err = p.getV1Services(ctx, i) - - q.v1 = &z -} - -func (p servicesInspectorLoader) getV1Services(ctx context.Context, i *inspectorState) (map[string]*core.Service, error) { - objs, err := p.getV1ServicesList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*core.Service, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p servicesInspectorLoader) getV1ServicesList(ctx context.Context, i *inspectorState) ([]*core.Service, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().Services(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*core.Service, 0, s) - - for { - for id := range items { - ptrs = append(ptrs, &items[id]) - } - - if cont == "" { - break - } - - items, cont, err = p.getV1ServicesListRequest(ctx, i, cont) - - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p servicesInspectorLoader) getV1ServicesListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.Service, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Kubernetes().CoreV1().Services(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p servicesInspectorLoader) Verify(i *inspectorState) error { if err := i.services.v1.err; err != nil { return err @@ -163,7 +90,7 @@ type servicesInspector struct { last time.Time - v1 *servicesInspectorV1 + v1 *inspectorVersion[*core.Service] } func (p *servicesInspector) LastRefresh() time.Time { @@ -194,3 +121,7 @@ func (p *servicesInspector) validate() error { return p.v1.validate() } + +func (p *servicesInspector) V1() generic.Inspector[*core.Service] { + return p.v1 +} diff --git a/pkg/deployment/resources/inspector/services_gvk.go b/pkg/deployment/resources/inspector/services_gvk.go index 1225fb972..d7ba274b3 100644 --- a/pkg/deployment/resources/inspector/services_gvk.go +++ b/pkg/deployment/resources/inspector/services_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *servicesInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.ServiceGKv1() -} - -func (p *servicesInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.ServiceGRv1() -} - func (p *servicesInspector) GroupKind() schema.GroupKind { return constants.ServiceGK() } diff --git a/pkg/deployment/resources/inspector/services_mod.go b/pkg/deployment/resources/inspector/services_mod.go index 6d9d3e794..e3af1879f 100644 --- a/pkg/deployment/resources/inspector/services_mod.go +++ b/pkg/deployment/resources/inspector/services_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -27,7 +27,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" - servicev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" ) func (i *inspectorState) ServicesModInterface() mods.ServicesMods { @@ -40,7 +39,7 @@ type servicesMod struct { i *inspectorState } -func (p servicesMod) V1() servicev1.ModInterface { +func (p servicesMod) V1() generic.ModClient[*core.Service] { return wrapMod[*core.Service](definitions.Service, p.i.GetThrottles, generic.WithModStatusGetter[*core.Service](constants.ServiceGKv1(), p.clientv1)) } diff --git a/pkg/deployment/resources/inspector/services_v1.go b/pkg/deployment/resources/inspector/services_v1.go deleted file mode 100644 index b7ad1b28a..000000000 --- a/pkg/deployment/resources/inspector/services_v1.go +++ /dev/null @@ -1,109 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - core "k8s.io/api/core/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" -) - -func (p *servicesInspector) V1() ins.Inspector { - return p.v1 -} - -type servicesInspectorV1 struct { - serviceInspector *servicesInspector - - services map[string]*core.Service - err error -} - -func (p *servicesInspectorV1) validate() error { - if p == nil { - return errors.Errorf("ServicesV1Inspector is nil") - } - - if p.serviceInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.services == nil { - return errors.Errorf("Services or err should be not nil") - } - - if p.err != nil { - return errors.Errorf("Services or err cannot be not nil together") - } - - return nil -} - -func (p *servicesInspectorV1) GetSimple(name string) (*core.Service, bool) { - service, ok := p.services[name] - if !ok { - return nil, false - } - - return service, true -} - -func (p *servicesInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, service := range p.services { - if err := p.iterateService(service, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *servicesInspectorV1) iterateService(service *core.Service, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(service) { - return nil - } - } - - return action(service) -} - -func (p *servicesInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *servicesInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Service, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.ServiceGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/inspector/sm.go b/pkg/deployment/resources/inspector/sm.go index 1f1e59700..85478cfc1 100644 --- a/pkg/deployment/resources/inspector/sm.go +++ b/pkg/deployment/resources/inspector/sm.go @@ -25,11 +25,12 @@ import ( "time" monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) @@ -49,88 +50,18 @@ func (p serviceMonitorsInspectorLoader) Component() definitions.Component { func (p serviceMonitorsInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q serviceMonitorsInspector - p.loadV1(ctx, i, &q) + + q.v1 = newInspectorVersion[*monitoring.ServiceMonitorList, *monitoring.ServiceMonitor](ctx, + constants.ServiceMonitorGRv1(), + constants.ServiceMonitorGKv1(), + i.client.Monitoring().MonitoringV1().ServiceMonitors(i.namespace), + servicemonitor.List()) + i.serviceMonitors = &q q.state = i q.last = time.Now() } -func (p serviceMonitorsInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *serviceMonitorsInspector) { - var z serviceMonitorsInspectorV1 - - z.serviceMonitorInspector = q - - z.serviceMonitors, z.err = p.getV1ServiceMonitors(ctx, i) - - q.v1 = &z -} - -func (p serviceMonitorsInspectorLoader) getV1ServiceMonitors(ctx context.Context, i *inspectorState) (map[string]*monitoring.ServiceMonitor, error) { - objs, err := p.getV1ServiceMonitorsList(ctx, i) - if err != nil { - return nil, err - } - - r := make(map[string]*monitoring.ServiceMonitor, len(objs)) - - for id := range objs { - r[objs[id].GetName()] = objs[id] - } - - return r, nil -} - -func (p serviceMonitorsInspectorLoader) getV1ServiceMonitorsList(ctx context.Context, i *inspectorState) ([]*monitoring.ServiceMonitor, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Monitoring().MonitoringV1().ServiceMonitors(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }) - - if err != nil { - return nil, err - } - - items := obj.Items - cont := obj.Continue - var s = int64(len(items)) - - if z := obj.RemainingItemCount; z != nil { - s += *z - } - - ptrs := make([]*monitoring.ServiceMonitor, 0, s) - - for { - ptrs = append(ptrs, items...) - if cont == "" { - break - } - - items, cont, err = p.getV1ServiceMonitorsListRequest(ctx, i, cont) - if err != nil { - return nil, err - } - } - - return ptrs, nil -} - -func (p serviceMonitorsInspectorLoader) getV1ServiceMonitorsListRequest(ctx context.Context, i *inspectorState, cont string) ([]*monitoring.ServiceMonitor, string, error) { - ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer cancel() - obj, err := i.client.Monitoring().MonitoringV1().ServiceMonitors(i.namespace).List(ctxChild, meta.ListOptions{ - Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - Continue: cont, - }) - - if err != nil { - return nil, "", err - } - - return obj.Items, obj.Continue, err -} - func (p serviceMonitorsInspectorLoader) Verify(i *inspectorState) error { return nil } @@ -155,7 +86,7 @@ type serviceMonitorsInspector struct { last time.Time - v1 *serviceMonitorsInspectorV1 + v1 *inspectorVersion[*monitoring.ServiceMonitor] } func (p *serviceMonitorsInspector) LastRefresh() time.Time { @@ -186,3 +117,11 @@ func (p *serviceMonitorsInspector) validate() error { return p.v1.validate() } + +func (p *serviceMonitorsInspector) V1() (generic.Inspector[*monitoring.ServiceMonitor], error) { + if p.v1.err != nil { + return nil, p.v1.err + } + + return p.v1, nil +} diff --git a/pkg/deployment/resources/inspector/sm_gvk.go b/pkg/deployment/resources/inspector/sm_gvk.go index 892d67d8b..948e03696 100644 --- a/pkg/deployment/resources/inspector/sm_gvk.go +++ b/pkg/deployment/resources/inspector/sm_gvk.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -26,14 +26,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" ) -func (p *serviceMonitorsInspectorV1) GroupVersionKind() schema.GroupVersionKind { - return constants.ServiceMonitorGKv1() -} - -func (p *serviceMonitorsInspectorV1) GroupVersionResource() schema.GroupVersionResource { - return constants.ServiceMonitorGRv1() -} - func (p *serviceMonitorsInspector) GroupKind() schema.GroupKind { return constants.ServiceMonitorGK() } diff --git a/pkg/deployment/resources/inspector/sm_mod.go b/pkg/deployment/resources/inspector/sm_mod.go index 9991a9c3b..6b24ce564 100644 --- a/pkg/deployment/resources/inspector/sm_mod.go +++ b/pkg/deployment/resources/inspector/sm_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -27,7 +27,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods" - servicemonitorv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor/v1" ) func (i *inspectorState) ServiceMonitorsModInterface() mods.ServiceMonitorsMods { @@ -40,7 +39,7 @@ type serviceMonitorsMod struct { i *inspectorState } -func (p serviceMonitorsMod) V1() servicemonitorv1.ModInterface { +func (p serviceMonitorsMod) V1() generic.ModClient[*monitoring.ServiceMonitor] { return wrapMod[*monitoring.ServiceMonitor](definitions.ServiceMonitor, p.i.GetThrottles, generic.WithModStatusGetter[*monitoring.ServiceMonitor](constants.ServiceMonitorGKv1(), p.clientv1)) } diff --git a/pkg/deployment/resources/inspector/sm_v1.go b/pkg/deployment/resources/inspector/sm_v1.go deleted file mode 100644 index 53c6258a7..000000000 --- a/pkg/deployment/resources/inspector/sm_v1.go +++ /dev/null @@ -1,122 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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" - - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" - ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor/v1" -) - -func (p *serviceMonitorsInspector) V1() (ins.Inspector, error) { - if p.v1.err != nil { - return nil, p.v1.err - } - - return p.v1, nil -} - -type serviceMonitorsInspectorV1 struct { - serviceMonitorInspector *serviceMonitorsInspector - - serviceMonitors map[string]*monitoring.ServiceMonitor - err error -} - -func (p *serviceMonitorsInspectorV1) validate() error { - if p == nil { - return errors.Errorf("ServiceMonitorsV1Inspector is nil") - } - - if p.serviceMonitorInspector == nil { - return errors.Errorf("Parent is nil") - } - - if p.serviceMonitors == nil && p.err == nil { - return errors.Errorf("ServiceMonitors or err should be not nil") - } - - if p.serviceMonitors != nil && p.err != nil { - return errors.Errorf("ServiceMonitors or err cannot be not nil together") - } - - return nil -} - -func (p *serviceMonitorsInspectorV1) ServiceMonitors() []*monitoring.ServiceMonitor { - var r []*monitoring.ServiceMonitor - for _, serviceMonitor := range p.serviceMonitors { - r = append(r, serviceMonitor) - } - - return r -} - -func (p *serviceMonitorsInspectorV1) GetSimple(name string) (*monitoring.ServiceMonitor, bool) { - serviceMonitor, ok := p.serviceMonitors[name] - if !ok { - return nil, false - } - - return serviceMonitor, true -} - -func (p *serviceMonitorsInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error { - for _, serviceMonitor := range p.serviceMonitors { - if err := p.iterateServiceMonitor(serviceMonitor, action, filters...); err != nil { - return err - } - } - - return nil -} - -func (p *serviceMonitorsInspectorV1) iterateServiceMonitor(serviceMonitor *monitoring.ServiceMonitor, action ins.Action, filters ...ins.Filter) error { - for _, f := range filters { - if f == nil { - continue - } - - if !f(serviceMonitor) { - return nil - } - } - - return action(serviceMonitor) -} - -func (p *serviceMonitorsInspectorV1) Read() ins.ReadInterface { - return p -} - -func (p *serviceMonitorsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*monitoring.ServiceMonitor, error) { - if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(constants.ServiceMonitorGR(), name) - } else { - return s, nil - } -} diff --git a/pkg/deployment/resources/member_cleanup.go b/pkg/deployment/resources/member_cleanup.go index f604c86c8..05594265a 100644 --- a/pkg/deployment/resources/member_cleanup.go +++ b/pkg/deployment/resources/member_cleanup.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -34,7 +34,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - arangomemberv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember/v1" ) const ( @@ -190,7 +189,9 @@ func (r *Resources) EnsureArangoMembers(ctx context.Context, cachedStatus inspec } return nil - }, arangomemberv1.FilterByDeploymentUID(obj.GetUID())); err != nil { + }, func(obj *api.ArangoMember) bool { + return obj != nil && obj.Spec.DeploymentUID == obj.GetUID() + }); err != nil { return err } diff --git a/pkg/deployment/resources/pod_cleanup.go b/pkg/deployment/resources/pod_cleanup.go index 7276f7f9d..e1a136f20 100644 --- a/pkg/deployment/resources/pod_cleanup.go +++ b/pkg/deployment/resources/pod_cleanup.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -34,7 +34,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/info" - podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" ) @@ -104,7 +104,7 @@ func (r *Resources) CleanupTerminatedPods(ctx context.Context) (util.Interval, e } return nil - }, podv1.FilterPodsByLabels(k8sutil.LabelsForDeployment(r.context.GetAPIObject().GetName(), ""))) + }, generic.FilterByLabels[*core.Pod](k8sutil.LabelsForDeployment(r.context.GetAPIObject().GetName(), ""))) }); err != nil { return 0, err } diff --git a/pkg/deployment/resources/pod_creator.go b/pkg/deployment/resources/pod_creator.go index 518f43b6a..50a322062 100644 --- a/pkg/deployment/resources/pod_creator.go +++ b/pkg/deployment/resources/pod_creator.go @@ -49,7 +49,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" ktls "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/tls" @@ -715,7 +715,7 @@ func RenderArangoPod(ctx context.Context, cachedStatus inspectorInterface.Inspec // CreateArangoPod creates a new Pod with container provided by parameter 'containerCreator' // If the pod already exists, nil is returned. // If another error occurs, that error is returned. -func CreateArangoPod(ctx context.Context, c podv1.ModInterface, deployment k8sutil.APIObject, +func CreateArangoPod(ctx context.Context, c generic.ModClient[*core.Pod], deployment k8sutil.APIObject, deploymentSpec api.DeploymentSpec, group api.ServerGroup, pod *core.Pod) (string, types.UID, error) { podName, uid, err := k8sutil.CreatePod(ctx, c, pod, deployment.GetNamespace(), deployment.AsOwner()) if err != nil { diff --git a/pkg/deployment/resources/pod_inspector.go b/pkg/deployment/resources/pod_inspector.go index bf85c699a..a734d5358 100644 --- a/pkg/deployment/resources/pod_inspector.go +++ b/pkg/deployment/resources/pod_inspector.go @@ -42,7 +42,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/info" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" kresources "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources" ) @@ -474,7 +474,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter } return nil - }, podv1.FilterPodsByLabels(k8sutil.LabelsForDeployment(deploymentName, ""))) + }, generic.FilterByLabels[*core.Pod](k8sutil.LabelsForDeployment(deploymentName, ""))) if err != nil { return 0, err } diff --git a/pkg/deployment/resources/pvc_inspector.go b/pkg/deployment/resources/pvc_inspector.go index f369f3be2..2fdad5ad8 100644 --- a/pkg/deployment/resources/pvc_inspector.go +++ b/pkg/deployment/resources/pvc_inspector.go @@ -36,7 +36,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - pvcv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) var ( @@ -157,7 +157,7 @@ func (r *Resources) InspectPVCs(ctx context.Context, cachedStatus inspectorInter } return nil - }, pvcv1.FilterPersistentVolumeClaimsByLabels(k8sutil.LabelsForDeployment(deploymentName, ""))); err != nil { + }, generic.FilterByLabels[*core.PersistentVolumeClaim](k8sutil.LabelsForDeployment(deploymentName, ""))); err != nil { return 0, err } diff --git a/pkg/deployment/resources/secrets.go b/pkg/deployment/resources/secrets.go index e08302238..72d03c607 100644 --- a/pkg/deployment/resources/secrets.go +++ b/pkg/deployment/resources/secrets.go @@ -47,7 +47,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" ktls "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/tls" "github.com/arangodb/kube-arangodb/pkg/util/token" @@ -197,7 +197,7 @@ func (r *Resources) EnsureSecrets(ctx context.Context, cachedStatus inspectorInt return reconcileRequired.Reconcile(ctx) } -func (r *Resources) ensureTokenSecretFolder(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets secretv1.ModInterface, secretName, folderSecretName string) error { +func (r *Resources) ensureTokenSecretFolder(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets generic.ModClient[*core.Secret], secretName, folderSecretName string) error { if f, exists := cachedStatus.Secret().V1().GetSimple(folderSecretName); exists { if len(f.Data) == 0 { s, exists := cachedStatus.Secret().V1().GetSimple(secretName) @@ -295,7 +295,7 @@ func (r *Resources) ensureTokenSecretFolder(ctx context.Context, cachedStatus in return nil } -func (r *Resources) ensureTokenSecret(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets secretv1.ModInterface, secretName string) error { +func (r *Resources) ensureTokenSecret(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets generic.ModClient[*core.Secret], secretName string) error { if _, exists := cachedStatus.Secret().V1().GetSimple(secretName); !exists { return r.createTokenSecret(ctx, secrets, secretName) } @@ -303,7 +303,7 @@ func (r *Resources) ensureTokenSecret(ctx context.Context, cachedStatus inspecto return nil } -func (r *Resources) ensureSecretWithEmptyKey(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets secretv1.ModInterface, secretName, keyName string) error { +func (r *Resources) ensureSecretWithEmptyKey(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets generic.ModClient[*core.Secret], secretName, keyName string) error { if _, exists := cachedStatus.Secret().V1().GetSimple(secretName); !exists { return r.createSecretWithKey(ctx, secrets, secretName, keyName, nil) } @@ -311,7 +311,7 @@ func (r *Resources) ensureSecretWithEmptyKey(ctx context.Context, cachedStatus i return nil } -func (r *Resources) createSecretWithMod(ctx context.Context, secrets secretv1.ModInterface, secretName string, f func(s *core.Secret)) error { +func (r *Resources) createSecretWithMod(ctx context.Context, secrets generic.ModClient[*core.Secret], secretName string, f func(s *core.Secret)) error { // Create secret secret := &core.Secret{ ObjectMeta: meta.ObjectMeta{ @@ -337,13 +337,13 @@ func (r *Resources) createSecretWithMod(ctx context.Context, secrets secretv1.Mo return errors.Reconcile() } -func (r *Resources) createSecretWithKey(ctx context.Context, secrets secretv1.ModInterface, secretName, keyName string, value []byte) error { +func (r *Resources) createSecretWithKey(ctx context.Context, secrets generic.ModClient[*core.Secret], secretName, keyName string, value []byte) error { return r.createSecretWithMod(ctx, secrets, secretName, func(s *core.Secret) { s.Data[keyName] = value }) } -func (r *Resources) createTokenSecret(ctx context.Context, secrets secretv1.ModInterface, secretName string) error { +func (r *Resources) createTokenSecret(ctx context.Context, secrets generic.ModClient[*core.Secret], secretName string) error { tokenData := make([]byte, 32) util.Rand().Read(tokenData) token := hex.EncodeToString(tokenData) @@ -364,7 +364,7 @@ func (r *Resources) createTokenSecret(ctx context.Context, secrets secretv1.ModI return errors.Reconcile() } -func (r *Resources) ensureEncryptionKeyfolderSecret(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets secretv1.ModInterface, keyfileSecretName, secretName string) error { +func (r *Resources) ensureEncryptionKeyfolderSecret(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets generic.ModClient[*core.Secret], keyfileSecretName, secretName string) error { _, folderExists := cachedStatus.Secret().V1().GetSimple(secretName) keyfile, exists := cachedStatus.Secret().V1().GetSimple(keyfileSecretName) @@ -401,7 +401,7 @@ func (r *Resources) ensureEncryptionKeyfolderSecret(ctx context.Context, cachedS } func AppendKeyfileToKeyfolder(ctx context.Context, cachedStatus inspectorInterface.Inspector, - secrets secretv1.ModInterface, ownerRef *meta.OwnerReference, secretName string, encryptionKey []byte) error { + secrets generic.ModClient[*core.Secret], ownerRef *meta.OwnerReference, secretName string, encryptionKey []byte) error { encSha := fmt.Sprintf("%0x", sha256.Sum256(encryptionKey)) if _, exists := cachedStatus.Secret().V1().GetSimple(secretName); !exists { @@ -443,7 +443,7 @@ var ( // ensureExporterTokenSecret checks if a secret with given name exists in the namespace // of the deployment. If not, it will add such a secret with correct access. func (r *Resources) ensureExporterTokenSecret(ctx context.Context, cachedStatus inspectorInterface.Inspector, - secrets secretv1.ModInterface, tokenSecretName, secretSecretName string) error { + secrets generic.ModClient[*core.Secret], tokenSecretName, secretSecretName string) error { if update, exists, err := r.ensureExporterTokenSecretCreateRequired(cachedStatus, tokenSecretName, secretSecretName); err != nil { return err } else if update { @@ -513,7 +513,7 @@ func (r *Resources) ensureExporterTokenSecretCreateRequired(cachedStatus inspect // ensureTLSCACertificateSecret checks if a secret with given name exists in the namespace // of the deployment. If not, it will add such a secret with a generated CA certificate. -func (r *Resources) ensureTLSCACertificateSecret(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets secretv1.ModInterface, spec api.TLSSpec) error { +func (r *Resources) ensureTLSCACertificateSecret(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets generic.ModClient[*core.Secret], spec api.TLSSpec) error { if _, exists := cachedStatus.Secret().V1().GetSimple(spec.GetCASecretName()); !exists { // Secret not found, create it apiObject := r.context.GetAPIObject() @@ -537,7 +537,7 @@ func (r *Resources) ensureTLSCACertificateSecret(ctx context.Context, cachedStat // ensureClientAuthCACertificateSecret checks if a secret with given name exists in the namespace // of the deployment. If not, it will add such a secret with a generated CA certificate. -func (r *Resources) ensureClientAuthCACertificateSecret(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets secretv1.ModInterface, spec api.SyncAuthenticationSpec) error { +func (r *Resources) ensureClientAuthCACertificateSecret(ctx context.Context, cachedStatus inspectorInterface.Inspector, secrets generic.ModClient[*core.Secret], spec api.SyncAuthenticationSpec) error { if _, exists := cachedStatus.Secret().V1().GetSimple(spec.GetClientCASecretName()); !exists { // Secret not found, create it apiObject := r.context.GetAPIObject() diff --git a/pkg/deployment/resources/services.go b/pkg/deployment/resources/services.go index 6e691e41a..96bca9ffc 100644 --- a/pkg/deployment/resources/services.go +++ b/pkg/deployment/resources/services.go @@ -38,8 +38,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember/v1" - servicev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/patcher" ) @@ -302,7 +301,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn // ensureExternalAccessServices ensures all services needed for a deployment. func (r *Resources) ensureExternalAccessServices(ctx context.Context, cachedStatus inspectorInterface.Inspector, - svcs servicev1.ModInterface, eaServiceName, role string, port int, noneIsClusterIP bool, withLeader bool, + svcs generic.ModClient[*core.Service], eaServiceName, role string, port int, noneIsClusterIP bool, withLeader bool, spec api.ExternalAccessSpec, apiObject k8sutil.APIObject) error { eaPorts, eaSelector := k8sutil.ExternalAccessDetails(port, spec.GetNodePort(), apiObject.GetName(), role, withLeader) @@ -475,7 +474,7 @@ func (r *Resources) ensureExternalAccessManagedServices(ctx context.Context, cac } // CreateServerServicePortsWithSidecars returns ports for the service. -func CreateServerServicePortsWithSidecars(amInspector v1.Inspector, am string) []core.ServicePort { +func CreateServerServicePortsWithSidecars(amInspector generic.Inspector[*api.ArangoMember], am string) []core.ServicePort { // Create service port for the `server` container. ports := []core.ServicePort{CreateServerServicePort()} diff --git a/pkg/handlers/policy/handler.go b/pkg/handlers/policy/handler.go index cc9201d50..94c669faa 100644 --- a/pkg/handlers/policy/handler.go +++ b/pkg/handlers/policy/handler.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -40,8 +40,8 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" ) const ( @@ -222,12 +222,10 @@ func (*handler) CanBeHandled(item operation.Item) bool { func (h *handler) listAllBackupsForPolicy(ctx context.Context, d *deployment.ArangoDeployment, policyName string) (util.List[*backupApi.ArangoBackup], error) { var r []*backupApi.ArangoBackup - if err := k8sutil.APIList[*backupApi.ArangoBackupList](ctx, h.client.BackupV1().ArangoBackups(d.Namespace), meta.ListOptions{ + r, err := list.APIList[*backupApi.ArangoBackupList, *backupApi.ArangoBackup](ctx, h.client.BackupV1().ArangoBackups(d.Namespace), meta.ListOptions{ Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(), - }, func(result *backupApi.ArangoBackupList, err error) error { - if err != nil { - return err - } + }, func(result *backupApi.ArangoBackupList) []*backupApi.ArangoBackup { + q := make([]*backupApi.ArangoBackup, 0, len(result.Items)) for _, b := range result.Items { if b.Spec.PolicyName == nil || *b.Spec.PolicyName != policyName { @@ -237,10 +235,14 @@ func (h *handler) listAllBackupsForPolicy(ctx context.Context, d *deployment.Ara continue } r = append(r, b.DeepCopy()) + + q = append(q, b.DeepCopy()) } - return nil - }); err != nil { + return q + }) + + if err != nil { return nil, errors.Wrap(err, "Failed to list ArangoBackups") } diff --git a/pkg/scheduler/profiles.go b/pkg/scheduler/profiles.go index 25cb34af2..c6adef1bb 100644 --- a/pkg/scheduler/profiles.go +++ b/pkg/scheduler/profiles.go @@ -23,16 +23,18 @@ package scheduler import ( "context" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/generators/kubernetes" "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" "github.com/arangodb/kube-arangodb/pkg/util/strings" ) func Profiles(ctx context.Context, client generic.ListInterface[*schedulerApi.ArangoProfileList], labels map[string]string, profiles ...string) ([]util.KV[string, schedulerApi.ProfileAcceptedTemplate], string, error) { - profileMap, err := kubernetes.MapObjects[*schedulerApi.ArangoProfileList, *schedulerApi.ArangoProfile](ctx, client, func(result *schedulerApi.ArangoProfileList) []*schedulerApi.ArangoProfile { + profileList, err := list.APIList[*schedulerApi.ArangoProfileList, *schedulerApi.ArangoProfile](ctx, client, meta.ListOptions{}, func(result *schedulerApi.ArangoProfileList) []*schedulerApi.ArangoProfile { q := make([]*schedulerApi.ArangoProfile, len(result.Items)) for id, e := range result.Items { @@ -41,12 +43,15 @@ func Profiles(ctx context.Context, client generic.ListInterface[*schedulerApi.Ar return q }) - if err != nil { return nil, "", err } - extractedProfiles := profileMap.AsList().Filter(func(a *schedulerApi.ArangoProfile) bool { + profileMap := util.ListAsMap(profileList, func(in *schedulerApi.ArangoProfile) string { + return in.GetName() + }) + + extractedProfiles := util.List[*schedulerApi.ArangoProfile](profileList).Filter(func(a *schedulerApi.ArangoProfile) bool { return a != nil && a.Spec.Template != nil }).Filter(func(a *schedulerApi.ArangoProfile) bool { if a.Spec.Selectors == nil { @@ -61,7 +66,7 @@ func Profiles(ctx context.Context, client generic.ListInterface[*schedulerApi.Ar }) for _, name := range profiles { - p, ok := profileMap.ByName(name) + p, ok := profileMap[name] if !ok { return nil, "", errors.Errorf("Profile with name `%s` is missing", name) } diff --git a/pkg/storage/pv_inspector.go b/pkg/storage/pv_inspector.go index 5d42d1a17..3dfc42de7 100644 --- a/pkg/storage/pv_inspector.go +++ b/pkg/storage/pv_inspector.go @@ -32,7 +32,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/deployment/features" "github.com/arangodb/kube-arangodb/pkg/deployment/patch" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" ) // inspectPVs queries all PersistentVolume's and triggers a cleanup for @@ -41,13 +41,16 @@ import ( func (ls *LocalStorage) inspectPVs() (int, error) { var volumes []*core.PersistentVolume - if err := k8sutil.APIList[*core.PersistentVolumeList](context.Background(), ls.deps.Client.Kubernetes().CoreV1().PersistentVolumes(), meta.ListOptions{}, func(result *core.PersistentVolumeList, err error) error { - for _, r := range result.Items { - volumes = append(volumes, r.DeepCopy()) + volumes, err := list.APIList[*core.PersistentVolumeList](context.Background(), ls.deps.Client.Kubernetes().CoreV1().PersistentVolumes(), meta.ListOptions{}, func(result *core.PersistentVolumeList) []*core.PersistentVolume { + q := make([]*core.PersistentVolume, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() } - return nil - }); err != nil { + return q + }) + if err != nil { if err != nil { return 0, errors.WithStack(err) } diff --git a/pkg/util/k8sutil/inspector/configmap/v1/loader.go b/pkg/util/k8sutil/base/base.go similarity index 71% rename from pkg/util/k8sutil/inspector/configmap/v1/loader.go rename to pkg/util/k8sutil/base/base.go index 72902ce96..1ba69aa1b 100644 --- a/pkg/util/k8sutil/inspector/configmap/v1/loader.go +++ b/pkg/util/k8sutil/base/base.go @@ -18,23 +18,20 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1 +package base import ( - core "k8s.io/api/core/v1" - + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" ) -// Inspector for configmaps type Inspector interface { - gvk.GVK + refresh.Inspector - ListSimple() []*core.ConfigMap - GetSimple(name string) (*core.ConfigMap, bool) - Iterate(action Action, filters ...Filter) error - Read() ReadInterface + gvk.GK + anonymous.Impl + + Version() version.Version } - -type Filter func(pod *core.ConfigMap) bool -type Action func(pod *core.ConfigMap) error diff --git a/pkg/util/k8sutil/configmaps.go b/pkg/util/k8sutil/configmaps.go index 1741c89e9..44c1d29c4 100644 --- a/pkg/util/k8sutil/configmaps.go +++ b/pkg/util/k8sutil/configmaps.go @@ -26,11 +26,11 @@ import ( core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" - configMapsV1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" ) -func CreateConfigMap(ctx context.Context, configMaps configMapsV1.ModInterface, cm *core.ConfigMap, ownerRef *meta.OwnerReference) error { +func CreateConfigMap(ctx context.Context, configMaps generic.ModClient[*core.ConfigMap], cm *core.ConfigMap, ownerRef *meta.OwnerReference) error { AddOwnerRefToObject(cm, ownerRef) if _, err := configMaps.Create(ctx, cm, meta.CreateOptions{}); err != nil { diff --git a/pkg/util/k8sutil/inspector/arangoclustersynchronization/definition.go b/pkg/util/k8sutil/inspector/arangoclustersynchronization/definition.go index 100f4b130..b1d93d6ba 100644 --- a/pkg/util/k8sutil/inspector/arangoclustersynchronization/definition.go +++ b/pkg/util/k8sutil/inspector/arangoclustersynchronization/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,9 @@ package arangoclustersynchronization import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +31,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() (v1.Inspector, error) + V1() (generic.Inspector[*api.ArangoClusterSynchronization], error) } diff --git a/pkg/util/k8sutil/inspector/arangotask/v1/loader.go b/pkg/util/k8sutil/inspector/arangoclustersynchronization/generic.go similarity index 57% rename from pkg/util/k8sutil/inspector/arangotask/v1/loader.go rename to pkg/util/k8sutil/inspector/arangoclustersynchronization/generic.go index 05f83ddf3..92274a760 100644 --- a/pkg/util/k8sutil/inspector/arangotask/v1/loader.go +++ b/pkg/util/k8sutil/inspector/arangoclustersynchronization/generic.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,36 +18,26 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1 +package arangoclustersynchronization import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -type Inspector interface { - gvk.GVK +func List(filter ...generic.Filter[*api.ArangoClusterSynchronization]) generic.ExtractorList[*api.ArangoClusterSynchronizationList, *api.ArangoClusterSynchronization] { + return func(in *api.ArangoClusterSynchronizationList) []*api.ArangoClusterSynchronization { + ret := make([]*api.ArangoClusterSynchronization, 0, len(in.Items)) - ListSimple() []*api.ArangoTask - GetSimple(name string) (*api.ArangoTask, bool) - Filter(filters ...Filter) []*api.ArangoTask - Iterate(action Action, filters ...Filter) error - Read() ReadInterface -} + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } -type Filter func(at *api.ArangoTask) bool -type Action func(at *api.ArangoTask) error - -func FilterObject(at *api.ArangoTask, filters ...Filter) bool { - for _, f := range filters { - if f == nil { - continue + ret = append(ret, z) } - if !f(at) { - return false - } + return ret } - - return true } diff --git a/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1/loader.go b/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1/loader.go deleted file mode 100644 index 5432e5f1f..000000000 --- a/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1/loader.go +++ /dev/null @@ -1,53 +0,0 @@ -// -// 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 v1 - -import ( - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" -) - -type Inspector interface { - gvk.GVK - - ListSimple() []*api.ArangoClusterSynchronization - GetSimple(name string) (*api.ArangoClusterSynchronization, bool) - Filter(filters ...Filter) []*api.ArangoClusterSynchronization - Iterate(action Action, filters ...Filter) error - Read() ReadInterface -} - -type Filter func(acs *api.ArangoClusterSynchronization) bool -type Action func(acs *api.ArangoClusterSynchronization) error - -func FilterObject(acs *api.ArangoClusterSynchronization, filters ...Filter) bool { - for _, f := range filters { - if f == nil { - continue - } - - if !f(acs) { - return false - } - } - - return true -} diff --git a/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1/reader.go b/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1/reader.go deleted file mode 100644 index e70982ba7..000000000 --- a/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1/reader.go +++ /dev/null @@ -1,50 +0,0 @@ -// -// 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 v1 - -import ( - "context" - - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" -) - -// ModInterface has methods to work with GetSimple resources only for creation -type ModInterface interface { - Create(ctx context.Context, acs *api.ArangoClusterSynchronization, opts meta.CreateOptions) (*api.ArangoClusterSynchronization, error) - Update(ctx context.Context, acs *api.ArangoClusterSynchronization, opts meta.UpdateOptions) (*api.ArangoClusterSynchronization, error) - UpdateStatus(ctx context.Context, acs *api.ArangoClusterSynchronization, opts meta.UpdateOptions) (*api.ArangoClusterSynchronization, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *api.ArangoClusterSynchronization, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// Interface has methods to work with GetSimple resources. -type Interface interface { - ModInterface - ReadInterface -} - -// ReadInterface has methods to work with GetSimple resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*api.ArangoClusterSynchronization, error) -} diff --git a/pkg/util/k8sutil/inspector/arangomember/definition.go b/pkg/util/k8sutil/inspector/arangomember/definition.go index 6569f63a4..5e8df90f8 100644 --- a/pkg/util/k8sutil/inspector/arangomember/definition.go +++ b/pkg/util/k8sutil/inspector/arangomember/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,9 @@ package arangomember import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +31,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() v1.Inspector + V1() generic.Inspector[*api.ArangoMember] } diff --git a/pkg/util/k8sutil/inspector/arangomember/v1/reader.go b/pkg/util/k8sutil/inspector/arangomember/generic.go similarity index 61% rename from pkg/util/k8sutil/inspector/arangomember/v1/reader.go rename to pkg/util/k8sutil/inspector/arangomember/generic.go index 92a63a174..0e857de9d 100644 --- a/pkg/util/k8sutil/inspector/arangomember/v1/reader.go +++ b/pkg/util/k8sutil/inspector/arangomember/generic.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,25 +18,26 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1 +package arangomember import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -// ModInterface has methods to work with ArangoMember resources only for creation -type ModInterface interface { - generic.ModStatusClient[*api.ArangoMember] -} +func List(filter ...generic.Filter[*api.ArangoMember]) generic.ExtractorList[*api.ArangoMemberList, *api.ArangoMember] { + return func(in *api.ArangoMemberList) []*api.ArangoMember { + ret := make([]*api.ArangoMember, 0, len(in.Items)) -// Interface has methods to work with ArangoMember resources. -type Interface interface { - ModInterface - ReadInterface -} + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } -// ReadInterface has methods to work with ArangoMember resources with ReadOnly mode. -type ReadInterface interface { - generic.ReadClient[*api.ArangoMember] + ret = append(ret, z) + } + + return ret + } } diff --git a/pkg/util/k8sutil/inspector/arangoprofile/definition.go b/pkg/util/k8sutil/inspector/arangoprofile/definition.go index cf6e79851..4172f3cb8 100644 --- a/pkg/util/k8sutil/inspector/arangoprofile/definition.go +++ b/pkg/util/k8sutil/inspector/arangoprofile/definition.go @@ -21,11 +21,9 @@ package arangoprofile import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - v1beta1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoprofile/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +31,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1Beta1() (v1beta1.Inspector, error) + V1Beta1() (generic.Inspector[*schedulerApi.ArangoProfile], error) } diff --git a/pkg/util/k8sutil/inspector/arangoprofile/v1beta1/loader.go b/pkg/util/k8sutil/inspector/arangoprofile/generic.go similarity index 55% rename from pkg/util/k8sutil/inspector/arangoprofile/v1beta1/loader.go rename to pkg/util/k8sutil/inspector/arangoprofile/generic.go index 64844795f..e8d275358 100644 --- a/pkg/util/k8sutil/inspector/arangoprofile/v1beta1/loader.go +++ b/pkg/util/k8sutil/inspector/arangoprofile/generic.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,36 +18,26 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1beta1 +package arangoprofile import ( schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -type Inspector interface { - gvk.GVK +func List(filter ...generic.Filter[*schedulerApi.ArangoProfile]) generic.ExtractorList[*schedulerApi.ArangoProfileList, *schedulerApi.ArangoProfile] { + return func(in *schedulerApi.ArangoProfileList) []*schedulerApi.ArangoProfile { + ret := make([]*schedulerApi.ArangoProfile, 0, len(in.Items)) - ListSimple() []*schedulerApi.ArangoProfile - GetSimple(name string) (*schedulerApi.ArangoProfile, bool) - Filter(filters ...Filter) []*schedulerApi.ArangoProfile - Iterate(action Action, filters ...Filter) error - Read() ReadInterface -} + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } -type Filter func(at *schedulerApi.ArangoProfile) bool -type Action func(at *schedulerApi.ArangoProfile) error - -func FilterObject(at *schedulerApi.ArangoProfile, filters ...Filter) bool { - for _, f := range filters { - if f == nil { - continue + ret = append(ret, z) } - if !f(at) { - return false - } + return ret } - - return true } diff --git a/pkg/util/k8sutil/inspector/arangoprofile/v1beta1/reader.go b/pkg/util/k8sutil/inspector/arangoprofile/v1beta1/reader.go deleted file mode 100644 index d0328fe5b..000000000 --- a/pkg/util/k8sutil/inspector/arangoprofile/v1beta1/reader.go +++ /dev/null @@ -1,50 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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 v1beta1 - -import ( - "context" - - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - - schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" -) - -// ModInterface has methods to work with ArangoTask resources only for creation -type ModInterface interface { - Create(ctx context.Context, arangoProfile *schedulerApi.ArangoProfile, opts meta.CreateOptions) (*schedulerApi.ArangoProfile, error) - Update(ctx context.Context, arangoProfile *schedulerApi.ArangoProfile, opts meta.UpdateOptions) (*schedulerApi.ArangoProfile, error) - UpdateStatus(ctx context.Context, arangoProfile *schedulerApi.ArangoProfile, opts meta.UpdateOptions) (*schedulerApi.ArangoProfile, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *schedulerApi.ArangoProfile, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// Interface has methods to work with ArangoTask resources. -type Interface interface { - ModInterface - ReadInterface -} - -// ReadInterface has methods to work with ArangoTask resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*schedulerApi.ArangoProfile, error) -} diff --git a/pkg/util/k8sutil/inspector/arangoroute/definition.go b/pkg/util/k8sutil/inspector/arangoroute/definition.go index e78513740..5cb2abd6b 100644 --- a/pkg/util/k8sutil/inspector/arangoroute/definition.go +++ b/pkg/util/k8sutil/inspector/arangoroute/definition.go @@ -21,11 +21,9 @@ package arangoroute import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - v1alpha1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoroute/v1alpha1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + networkingApi "github.com/arangodb/kube-arangodb/pkg/apis/networking/v1alpha1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +31,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1Alpha1() (v1alpha1.Inspector, error) + V1Alpha1() (generic.Inspector[*networkingApi.ArangoRoute], error) } diff --git a/pkg/util/k8sutil/inspector/arangoroute/v1alpha1/loader.go b/pkg/util/k8sutil/inspector/arangoroute/generic.go similarity index 56% rename from pkg/util/k8sutil/inspector/arangoroute/v1alpha1/loader.go rename to pkg/util/k8sutil/inspector/arangoroute/generic.go index 8fc237eed..b06ae6b74 100644 --- a/pkg/util/k8sutil/inspector/arangoroute/v1alpha1/loader.go +++ b/pkg/util/k8sutil/inspector/arangoroute/generic.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,36 +18,26 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1alpha1 +package arangoroute import ( networkingApi "github.com/arangodb/kube-arangodb/pkg/apis/networking/v1alpha1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -type Inspector interface { - gvk.GVK +func List(filter ...generic.Filter[*networkingApi.ArangoRoute]) generic.ExtractorList[*networkingApi.ArangoRouteList, *networkingApi.ArangoRoute] { + return func(in *networkingApi.ArangoRouteList) []*networkingApi.ArangoRoute { + ret := make([]*networkingApi.ArangoRoute, 0, len(in.Items)) - ListSimple() []*networkingApi.ArangoRoute - GetSimple(name string) (*networkingApi.ArangoRoute, bool) - Filter(filters ...Filter) []*networkingApi.ArangoRoute - Iterate(action Action, filters ...Filter) error - Read() ReadInterface -} + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } -type Filter func(at *networkingApi.ArangoRoute) bool -type Action func(at *networkingApi.ArangoRoute) error - -func FilterObject(at *networkingApi.ArangoRoute, filters ...Filter) bool { - for _, f := range filters { - if f == nil { - continue + ret = append(ret, z) } - if !f(at) { - return false - } + return ret } - - return true } diff --git a/pkg/util/k8sutil/inspector/arangoroute/v1alpha1/reader.go b/pkg/util/k8sutil/inspector/arangoroute/v1alpha1/reader.go deleted file mode 100644 index bd51d3ef6..000000000 --- a/pkg/util/k8sutil/inspector/arangoroute/v1alpha1/reader.go +++ /dev/null @@ -1,50 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2024 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 v1alpha1 - -import ( - "context" - - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - - networkingApi "github.com/arangodb/kube-arangodb/pkg/apis/networking/v1alpha1" -) - -// ModInterface has methods to work with ArangoTask resources only for creation -type ModInterface interface { - Create(ctx context.Context, arangotask *networkingApi.ArangoRoute, opts meta.CreateOptions) (*networkingApi.ArangoRoute, error) - Update(ctx context.Context, arangotask *networkingApi.ArangoRoute, opts meta.UpdateOptions) (*networkingApi.ArangoRoute, error) - UpdateStatus(ctx context.Context, arangotask *networkingApi.ArangoRoute, opts meta.UpdateOptions) (*networkingApi.ArangoRoute, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *networkingApi.ArangoRoute, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// Interface has methods to work with ArangoTask resources. -type Interface interface { - ModInterface - ReadInterface -} - -// ReadInterface has methods to work with ArangoTask resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*networkingApi.ArangoRoute, error) -} diff --git a/pkg/util/k8sutil/inspector/arangotask/definition.go b/pkg/util/k8sutil/inspector/arangotask/definition.go index 5b7b277a4..7f9e9f538 100644 --- a/pkg/util/k8sutil/inspector/arangotask/definition.go +++ b/pkg/util/k8sutil/inspector/arangotask/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,9 @@ package arangotask import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +31,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() (v1.Inspector, error) + V1() (generic.Inspector[*api.ArangoTask], error) } diff --git a/pkg/util/k8sutil/inspector/arangomember/v1/loader.go b/pkg/util/k8sutil/inspector/arangotask/generic.go similarity index 62% rename from pkg/util/k8sutil/inspector/arangomember/v1/loader.go rename to pkg/util/k8sutil/inspector/arangotask/generic.go index 21157129c..a69729275 100644 --- a/pkg/util/k8sutil/inspector/arangomember/v1/loader.go +++ b/pkg/util/k8sutil/inspector/arangotask/generic.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,21 +18,26 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1 +package arangotask import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -type Inspector interface { - gvk.GVK +func List(filter ...generic.Filter[*api.ArangoTask]) generic.ExtractorList[*api.ArangoTaskList, *api.ArangoTask] { + return func(in *api.ArangoTaskList) []*api.ArangoTask { + ret := make([]*api.ArangoTask, 0, len(in.Items)) - GetSimple(name string) (*api.ArangoMember, bool) - GetSimpleOptional(name string) *api.ArangoMember - Iterate(action Action, filters ...Filter) error - Read() ReadInterface + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } } - -type Filter func(pod *api.ArangoMember) bool -type Action func(pod *api.ArangoMember) error diff --git a/pkg/util/k8sutil/inspector/arangotask/v1/reader.go b/pkg/util/k8sutil/inspector/arangotask/v1/reader.go deleted file mode 100644 index dded62250..000000000 --- a/pkg/util/k8sutil/inspector/arangotask/v1/reader.go +++ /dev/null @@ -1,50 +0,0 @@ -// -// 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 v1 - -import ( - "context" - - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" -) - -// ModInterface has methods to work with ArangoTask resources only for creation -type ModInterface interface { - Create(ctx context.Context, arangotask *api.ArangoTask, opts meta.CreateOptions) (*api.ArangoTask, error) - Update(ctx context.Context, arangotask *api.ArangoTask, opts meta.UpdateOptions) (*api.ArangoTask, error) - UpdateStatus(ctx context.Context, arangotask *api.ArangoTask, opts meta.UpdateOptions) (*api.ArangoTask, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *api.ArangoTask, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// Interface has methods to work with ArangoTask resources. -type Interface interface { - ModInterface - ReadInterface -} - -// ReadInterface has methods to work with ArangoTask resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*api.ArangoTask, error) -} diff --git a/pkg/util/k8sutil/inspector/configmap/definition.go b/pkg/util/k8sutil/inspector/configmap/definition.go index bc5e23a71..3cb63218b 100644 --- a/pkg/util/k8sutil/inspector/configmap/definition.go +++ b/pkg/util/k8sutil/inspector/configmap/definition.go @@ -21,11 +21,10 @@ package configmap import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +32,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() v1.Inspector + V1() generic.Inspector[*core.ConfigMap] } diff --git a/pkg/util/k8sutil/inspector/configmap/generic.go b/pkg/util/k8sutil/inspector/configmap/generic.go new file mode 100644 index 000000000..6237af2ab --- /dev/null +++ b/pkg/util/k8sutil/inspector/configmap/generic.go @@ -0,0 +1,44 @@ +// +// DISCLAIMER +// +// Copyright 2024 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 configmap + +import ( + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" +) + +func List(filter ...generic.Filter[*core.ConfigMap]) generic.ExtractorList[*core.ConfigMapList, *core.ConfigMap] { + return func(in *core.ConfigMapList) []*core.ConfigMap { + ret := make([]*core.ConfigMap, 0, len(in.Items)) + + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } +} diff --git a/pkg/util/k8sutil/inspector/configmap/v1/reader.go b/pkg/util/k8sutil/inspector/configmap/v1/reader.go deleted file mode 100644 index b2262fefd..000000000 --- a/pkg/util/k8sutil/inspector/configmap/v1/reader.go +++ /dev/null @@ -1,48 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2024 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 v1 - -import ( - "context" - - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -// ModInterface has methods to work with ConfigMap resources only for creation -type ModInterface interface { - Create(ctx context.Context, configmap *core.ConfigMap, opts meta.CreateOptions) (*core.ConfigMap, error) - Update(ctx context.Context, configmap *core.ConfigMap, opts meta.UpdateOptions) (*core.ConfigMap, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.ConfigMap, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// Interface has methods to work with ConfigMap resources. -type Interface interface { - ModInterface - ReadInterface -} - -// ReadInterface has methods to work with ConfigMap resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*core.ConfigMap, error) -} diff --git a/pkg/util/k8sutil/inspector/endpoints/definition.go b/pkg/util/k8sutil/inspector/endpoints/definition.go index 6c431135d..481cdb752 100644 --- a/pkg/util/k8sutil/inspector/endpoints/definition.go +++ b/pkg/util/k8sutil/inspector/endpoints/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,10 @@ package endpoints import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +32,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() (v1.Inspector, error) + V1() (generic.Inspector[*core.Endpoints], error) } diff --git a/pkg/util/k8sutil/inspector/endpoints/generic.go b/pkg/util/k8sutil/inspector/endpoints/generic.go new file mode 100644 index 000000000..34844530a --- /dev/null +++ b/pkg/util/k8sutil/inspector/endpoints/generic.go @@ -0,0 +1,44 @@ +// +// DISCLAIMER +// +// Copyright 2024 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 endpoints + +import ( + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" +) + +func List(filter ...generic.Filter[*core.Endpoints]) generic.ExtractorList[*core.EndpointsList, *core.Endpoints] { + return func(in *core.EndpointsList) []*core.Endpoints { + ret := make([]*core.Endpoints, 0, len(in.Items)) + + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } +} diff --git a/pkg/util/k8sutil/inspector/endpoints/v1/reader.go b/pkg/util/k8sutil/inspector/endpoints/v1/reader.go deleted file mode 100644 index dfd9e1d18..000000000 --- a/pkg/util/k8sutil/inspector/endpoints/v1/reader.go +++ /dev/null @@ -1,48 +0,0 @@ -// -// 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 v1 - -import ( - "context" - - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -// ModInterface has methods to work with Endpoints resources only for creation -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) - 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 -} - -// Interface has methods to work with Endpoints resources. -type Interface interface { - ModInterface - ReadInterface -} - -// ReadInterface has methods to work with Endpoints resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Endpoints, error) -} diff --git a/pkg/util/k8sutil/inspector/arangomember/v1/filters.go b/pkg/util/k8sutil/inspector/generic/inspector.go similarity index 65% rename from pkg/util/k8sutil/inspector/arangomember/v1/filters.go rename to pkg/util/k8sutil/inspector/generic/inspector.go index 13510eda5..54251c12a 100644 --- a/pkg/util/k8sutil/inspector/arangomember/v1/filters.go +++ b/pkg/util/k8sutil/inspector/generic/inspector.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,16 +18,16 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1 +package generic -import ( - "k8s.io/apimachinery/pkg/types" +import meta "k8s.io/apimachinery/pkg/apis/meta/v1" - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" -) - -func FilterByDeploymentUID(uid types.UID) Filter { - return func(pod *api.ArangoMember) bool { - return pod.Spec.DeploymentUID == "" || pod.Spec.DeploymentUID == uid - } +type InspectorInterface[S meta.Object] interface { + ModClient[S] + ReadClient[S] +} + +type InspectorStatusInterface[S meta.Object] interface { + ModStatusClient[S] + ReadClient[S] } diff --git a/pkg/util/k8sutil/inspector/endpoints/v1/loader.go b/pkg/util/k8sutil/inspector/generic/inspector_filter.go similarity index 51% rename from pkg/util/k8sutil/inspector/endpoints/v1/loader.go rename to pkg/util/k8sutil/inspector/generic/inspector_filter.go index 6d6067124..d3f65b4bf 100644 --- a/pkg/util/k8sutil/inspector/endpoints/v1/loader.go +++ b/pkg/util/k8sutil/inspector/generic/inspector_filter.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,37 +18,55 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1 +package generic import ( - core "k8s.io/api/core/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" ) -type Inspector interface { +type Inspector[S meta.Object] interface { gvk.GVK - ListSimple() []*core.Endpoints - GetSimple(name string) (*core.Endpoints, bool) - Filter(filters ...Filter) []*core.Endpoints - Iterate(action Action, filters ...Filter) error - Read() ReadInterface + ListSimple() []S + GetSimple(name string) (S, bool) + Filter(filters ...Filter[S]) []S + Iterate(action Action[S], filters ...Filter[S]) error + Read() ReadClient[S] } -type Filter func(at *core.Endpoints) bool -type Action func(at *core.Endpoints) error +type Filter[S meta.Object] func(obj S) bool +type Action[S meta.Object] func(obj S) error -func FilterObject(at *core.Endpoints, filters ...Filter) bool { +func FilterObject[S meta.Object](obj S, filters ...Filter[S]) bool { for _, f := range filters { if f == nil { continue } - if !f(at) { + if !f(obj) { return false } } return true } + +func FilterByLabels[S meta.Object](labels map[string]string) Filter[S] { + return func(obj S) bool { + objLabels := obj.GetLabels() + for key, value := range labels { + v, ok := objLabels[key] + if !ok { + return false + } + + if v != value { + return false + } + } + + return true + } +} diff --git a/pkg/util/k8sutil/inspector/generic/mod.go b/pkg/util/k8sutil/inspector/generic/mod.go index 37a0c2e25..93da1457d 100644 --- a/pkg/util/k8sutil/inspector/generic/mod.go +++ b/pkg/util/k8sutil/inspector/generic/mod.go @@ -31,6 +31,8 @@ type ListContinue interface { GetContinue() string } +type ExtractorList[L ListContinue, S meta.Object] func(in L) []S + type ListInterface[S ListContinue] interface { List(ctx context.Context, opts meta.ListOptions) (S, error) } @@ -67,7 +69,6 @@ type ModClient[S meta.Object] interface { CreateInterface[S] UpdateInterface[S] PatchInterface[S] - PatchInterface[S] DeleteInterface[S] } diff --git a/pkg/util/k8sutil/inspector/mods/mods.go b/pkg/util/k8sutil/inspector/mods/mods.go index 62eeb6295..09c622437 100644 --- a/pkg/util/k8sutil/inspector/mods/mods.go +++ b/pkg/util/k8sutil/inspector/mods/mods.go @@ -21,76 +21,70 @@ package mods import ( - arangoclustersynchronizationv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1" - arangomemberv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember/v1" - arangoProfilev1beta1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoprofile/v1beta1" - arangoroutev1alpha1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoroute/v1alpha1" - arangotaskv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask/v1" - configMapv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap/v1" - 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" - poddisruptionbudgetv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1" - 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" + monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + core "k8s.io/api/core/v1" + policy "k8s.io/api/policy/v1" + + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + networkingApi "github.com/arangodb/kube-arangodb/pkg/apis/networking/v1alpha1" + schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type PodsMods interface { - V1() podv1.ModInterface + V1() generic.ModClient[*core.Pod] } type ServiceAccountsMods interface { - V1() serviceaccountv1.ModInterface + V1() generic.ModClient[*core.ServiceAccount] } type SecretsMods interface { - V1() secretv1.ModInterface + V1() generic.ModClient[*core.Secret] } type ConfigMapsMods interface { - V1() configMapv1.ModInterface + V1() generic.ModClient[*core.ConfigMap] } type PersistentVolumeClaimsMods interface { - V1() persistentvolumeclaimv1.ModInterface + V1() generic.ModClient[*core.PersistentVolumeClaim] } type ServicesMods interface { - V1() servicev1.ModInterface + V1() generic.ModClient[*core.Service] } type EndpointsMods interface { - V1() endpointsv1.ModInterface + V1() generic.ModClient[*core.Endpoints] } type ServiceMonitorsMods interface { - V1() servicemonitorv1.ModInterface + V1() generic.ModClient[*monitoring.ServiceMonitor] } type PodDisruptionBudgetsMods interface { - V1() poddisruptionbudgetv1.ModInterface + V1() generic.ModClient[*policy.PodDisruptionBudget] } type ArangoMemberMods interface { - V1() arangomemberv1.ModInterface + V1() generic.ModStatusClient[*api.ArangoMember] } type ArangoTaskMods interface { - V1() arangotaskv1.ModInterface + V1() generic.ModStatusClient[*api.ArangoTask] } type ArangoClusterSynchronizationMods interface { - V1() arangoclustersynchronizationv1.ModInterface + V1() generic.ModStatusClient[*api.ArangoClusterSynchronization] } type ArangoRouteMods interface { - V1Alpha1() arangoroutev1alpha1.ModInterface + V1Alpha1() generic.ModStatusClient[*networkingApi.ArangoRoute] } type ArangoProfileMods interface { - V1Beta1() arangoProfilev1beta1.ModInterface + V1Beta1() generic.ModStatusClient[*schedulerApi.ArangoProfile] } type Mods interface { diff --git a/pkg/util/k8sutil/inspector/node/definition.go b/pkg/util/k8sutil/inspector/node/definition.go index 39a0619f5..0f60a7c02 100644 --- a/pkg/util/k8sutil/inspector/node/definition.go +++ b/pkg/util/k8sutil/inspector/node/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,10 @@ package node import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/node/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +32,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() (v1.Inspector, error) + V1() (generic.Inspector[*core.Node], error) } diff --git a/pkg/util/k8sutil/inspector/node/v1/loader.go b/pkg/util/k8sutil/inspector/node/generic.go similarity index 63% rename from pkg/util/k8sutil/inspector/node/v1/loader.go rename to pkg/util/k8sutil/inspector/node/generic.go index f59878000..dbd1b2f75 100644 --- a/pkg/util/k8sutil/inspector/node/v1/loader.go +++ b/pkg/util/k8sutil/inspector/node/generic.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,22 +18,27 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1 +package node import ( core "k8s.io/api/core/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -type Inspector interface { - gvk.GVK +func List(filter ...generic.Filter[*core.Node]) generic.ExtractorList[*core.NodeList, *core.Node] { + return func(in *core.NodeList) []*core.Node { + ret := make([]*core.Node, 0, len(in.Items)) - ListSimple() []*core.Node - GetSimple(name string) (*core.Node, bool) - Iterate(action Action, filters ...Filter) error - Read() ReadInterface + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } } - -type Filter func(podDisruptionBudget *core.Node) bool -type Action func(podDisruptionBudget *core.Node) error diff --git a/pkg/util/k8sutil/inspector/node/v1/reader.go b/pkg/util/k8sutil/inspector/node/v1/reader.go deleted file mode 100644 index a3661d1a8..000000000 --- a/pkg/util/k8sutil/inspector/node/v1/reader.go +++ /dev/null @@ -1,38 +0,0 @@ -// -// 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 v1 - -import ( - "context" - - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// Interface has methods to work with Node resources. -type Interface interface { - ReadInterface -} - -// ReadInterface has methods to work with Node resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Node, error) -} diff --git a/pkg/util/k8sutil/inspector/persistentvolume/definition.go b/pkg/util/k8sutil/inspector/persistentvolume/definition.go index 3b7e5c595..f31f70205 100644 --- a/pkg/util/k8sutil/inspector/persistentvolume/definition.go +++ b/pkg/util/k8sutil/inspector/persistentvolume/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 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. @@ -21,11 +21,10 @@ package persistentvolume import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolume/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +32,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() (v1.Inspector, error) + V1() (generic.Inspector[*core.PersistentVolume], error) } diff --git a/pkg/util/k8sutil/inspector/persistentvolume/generic.go b/pkg/util/k8sutil/inspector/persistentvolume/generic.go new file mode 100644 index 000000000..a1f79478f --- /dev/null +++ b/pkg/util/k8sutil/inspector/persistentvolume/generic.go @@ -0,0 +1,44 @@ +// +// DISCLAIMER +// +// Copyright 2024 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 persistentvolume + +import ( + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" +) + +func List(filter ...generic.Filter[*core.PersistentVolume]) generic.ExtractorList[*core.PersistentVolumeList, *core.PersistentVolume] { + return func(in *core.PersistentVolumeList) []*core.PersistentVolume { + ret := make([]*core.PersistentVolume, 0, len(in.Items)) + + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } +} diff --git a/pkg/util/k8sutil/inspector/persistentvolume/v1/reader.go b/pkg/util/k8sutil/inspector/persistentvolume/v1/reader.go deleted file mode 100644 index fa8348d90..000000000 --- a/pkg/util/k8sutil/inspector/persistentvolume/v1/reader.go +++ /dev/null @@ -1,38 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023 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 v1 - -import ( - "context" - - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// Interface has methods to work with PersistentVolume resources. -type Interface interface { - ReadInterface -} - -// ReadInterface has methods to work with PersistentVolume resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*core.PersistentVolume, error) -} diff --git a/pkg/util/k8sutil/inspector/persistentvolumeclaim/definition.go b/pkg/util/k8sutil/inspector/persistentvolumeclaim/definition.go index a61b8ead8..1ca96e738 100644 --- a/pkg/util/k8sutil/inspector/persistentvolumeclaim/definition.go +++ b/pkg/util/k8sutil/inspector/persistentvolumeclaim/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,10 @@ package persistentvolumeclaim import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +32,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() v1.Inspector + V1() generic.Inspector[*core.PersistentVolumeClaim] } diff --git a/pkg/util/k8sutil/inspector/persistentvolumeclaim/generic.go b/pkg/util/k8sutil/inspector/persistentvolumeclaim/generic.go new file mode 100644 index 000000000..0116c3cc6 --- /dev/null +++ b/pkg/util/k8sutil/inspector/persistentvolumeclaim/generic.go @@ -0,0 +1,44 @@ +// +// DISCLAIMER +// +// Copyright 2024 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 persistentvolumeclaim + +import ( + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" +) + +func List(filter ...generic.Filter[*core.PersistentVolumeClaim]) generic.ExtractorList[*core.PersistentVolumeClaimList, *core.PersistentVolumeClaim] { + return func(in *core.PersistentVolumeClaimList) []*core.PersistentVolumeClaim { + ret := make([]*core.PersistentVolumeClaim, 0, len(in.Items)) + + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } +} diff --git a/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/filters.go b/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/filters.go deleted file mode 100644 index 2741880db..000000000 --- a/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/filters.go +++ /dev/null @@ -1,42 +0,0 @@ -// -// 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 v1 - -import ( - core "k8s.io/api/core/v1" -) - -func FilterPersistentVolumeClaimsByLabels(labels map[string]string) Filter { - return func(pvc *core.PersistentVolumeClaim) bool { - for key, value := range labels { - v, ok := pvc.Labels[key] - if !ok { - return false - } - - if v != value { - return false - } - } - - return true - } -} diff --git a/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/reader.go b/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/reader.go deleted file mode 100644 index c0d825b6e..000000000 --- a/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/reader.go +++ /dev/null @@ -1,48 +0,0 @@ -// -// 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 v1 - -import ( - "context" - - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -// ModInterface has methods to work with PersistentVolumeClaim resources only for creation -type ModInterface interface { - Create(ctx context.Context, persistentvolumeclaim *core.PersistentVolumeClaim, opts meta.CreateOptions) (*core.PersistentVolumeClaim, error) - Update(ctx context.Context, persistentvolumeclaim *core.PersistentVolumeClaim, opts meta.UpdateOptions) (*core.PersistentVolumeClaim, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.PersistentVolumeClaim, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// Interface has methods to work with PersistentVolumeClaim resources. -type Interface interface { - ModInterface - ReadInterface -} - -// ReadInterface has methods to work with PersistentVolumeClaim resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*core.PersistentVolumeClaim, error) -} diff --git a/pkg/util/k8sutil/inspector/pod/definition.go b/pkg/util/k8sutil/inspector/pod/definition.go index e1e652efd..3e124cbae 100644 --- a/pkg/util/k8sutil/inspector/pod/definition.go +++ b/pkg/util/k8sutil/inspector/pod/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,10 @@ package pod import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +32,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() v1.Inspector + V1() generic.Inspector[*core.Pod] } diff --git a/pkg/util/k8sutil/inspector/persistentvolume/v1/loader.go b/pkg/util/k8sutil/inspector/pod/generic.go similarity index 64% rename from pkg/util/k8sutil/inspector/persistentvolume/v1/loader.go rename to pkg/util/k8sutil/inspector/pod/generic.go index 2a52f8d86..6a30ea0f2 100644 --- a/pkg/util/k8sutil/inspector/persistentvolume/v1/loader.go +++ b/pkg/util/k8sutil/inspector/pod/generic.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,22 +18,27 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1 +package pod import ( core "k8s.io/api/core/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -type Inspector interface { - gvk.GVK +func List(filter ...generic.Filter[*core.Pod]) generic.ExtractorList[*core.PodList, *core.Pod] { + return func(in *core.PodList) []*core.Pod { + ret := make([]*core.Pod, 0, len(in.Items)) - ListSimple() []*core.PersistentVolume - GetSimple(name string) (*core.PersistentVolume, bool) - Iterate(action Action, filters ...Filter) error - Read() ReadInterface + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } } - -type Filter func(pv *core.PersistentVolume) bool -type Action func(pv *core.PersistentVolume) error diff --git a/pkg/util/k8sutil/inspector/pod/v1/filters.go b/pkg/util/k8sutil/inspector/pod/v1/filters.go deleted file mode 100644 index 201242799..000000000 --- a/pkg/util/k8sutil/inspector/pod/v1/filters.go +++ /dev/null @@ -1,42 +0,0 @@ -// -// 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 v1 - -import ( - core "k8s.io/api/core/v1" -) - -func FilterPodsByLabels(labels map[string]string) Filter { - return func(pod *core.Pod) bool { - for key, value := range labels { - v, ok := pod.Labels[key] - if !ok { - return false - } - - if v != value { - return false - } - } - - return true - } -} diff --git a/pkg/util/k8sutil/inspector/pod/v1/loader.go b/pkg/util/k8sutil/inspector/pod/v1/loader.go deleted file mode 100644 index a7b94bc1d..000000000 --- a/pkg/util/k8sutil/inspector/pod/v1/loader.go +++ /dev/null @@ -1,39 +0,0 @@ -// -// 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 v1 - -import ( - core "k8s.io/api/core/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" -) - -type Inspector interface { - gvk.GVK - - ListSimple() []*core.Pod - GetSimple(name string) (*core.Pod, bool) - Iterate(action Action, filters ...Filter) error - Read() ReadInterface -} - -type Filter func(pod *core.Pod) bool -type Action func(pod *core.Pod) error diff --git a/pkg/util/k8sutil/inspector/pod/v1/reader.go b/pkg/util/k8sutil/inspector/pod/v1/reader.go deleted file mode 100644 index a344515e7..000000000 --- a/pkg/util/k8sutil/inspector/pod/v1/reader.go +++ /dev/null @@ -1,47 +0,0 @@ -// -// 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 v1 - -import ( - "context" - - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -// ModInterface has methods to work with Pod resources only for creation -type ModInterface interface { - Create(ctx context.Context, pod *core.Pod, opts meta.CreateOptions) (*core.Pod, error) - Update(ctx context.Context, pod *core.Pod, opts meta.UpdateOptions) (*core.Pod, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.Pod, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// Interface has methods to work with Pod resources. -type Interface interface { - ModInterface -} - -// ReadInterface has methods to work with Pod resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Pod, error) -} diff --git a/pkg/util/k8sutil/inspector/poddisruptionbudget/definition.go b/pkg/util/k8sutil/inspector/poddisruptionbudget/definition.go index bd5fcdab4..ec6175e10 100644 --- a/pkg/util/k8sutil/inspector/poddisruptionbudget/definition.go +++ b/pkg/util/k8sutil/inspector/poddisruptionbudget/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,10 @@ package poddisruptionbudget import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + policy "k8s.io/api/policy/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +32,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() (v1.Inspector, error) + V1() (generic.Inspector[*policy.PodDisruptionBudget], error) } diff --git a/pkg/util/k8sutil/inspector/poddisruptionbudget/v1/loader.go b/pkg/util/k8sutil/inspector/poddisruptionbudget/generic.go similarity index 58% rename from pkg/util/k8sutil/inspector/poddisruptionbudget/v1/loader.go rename to pkg/util/k8sutil/inspector/poddisruptionbudget/generic.go index c7ac6e105..fc7ec15c3 100644 --- a/pkg/util/k8sutil/inspector/poddisruptionbudget/v1/loader.go +++ b/pkg/util/k8sutil/inspector/poddisruptionbudget/generic.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,21 +18,27 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1 +package poddisruptionbudget import ( policy "k8s.io/api/policy/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -type Inspector interface { - gvk.GVK +func List(filter ...generic.Filter[*policy.PodDisruptionBudget]) generic.ExtractorList[*policy.PodDisruptionBudgetList, *policy.PodDisruptionBudget] { + return func(in *policy.PodDisruptionBudgetList) []*policy.PodDisruptionBudget { + ret := make([]*policy.PodDisruptionBudget, 0, len(in.Items)) - GetSimple(name string) (*policy.PodDisruptionBudget, bool) - Iterate(action Action, filters ...Filter) error - Read() ReadInterface + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } } - -type Filter func(podDisruptionBudget *policy.PodDisruptionBudget) bool -type Action func(podDisruptionBudget *policy.PodDisruptionBudget) error diff --git a/pkg/util/k8sutil/inspector/poddisruptionbudget/v1/reader.go b/pkg/util/k8sutil/inspector/poddisruptionbudget/v1/reader.go deleted file mode 100644 index 49575866e..000000000 --- a/pkg/util/k8sutil/inspector/poddisruptionbudget/v1/reader.go +++ /dev/null @@ -1,48 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2023 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 v1 - -import ( - "context" - - policy "k8s.io/api/policy/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -// ModInterface has methods to work with PodDisruptionBudget resources only for creation -type ModInterface interface { - Create(ctx context.Context, poddisruptionbudget *policy.PodDisruptionBudget, opts meta.CreateOptions) (*policy.PodDisruptionBudget, error) - Update(ctx context.Context, poddisruptionbudget *policy.PodDisruptionBudget, opts meta.UpdateOptions) (*policy.PodDisruptionBudget, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *policy.PodDisruptionBudget, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// Interface has methods to work with PodDisruptionBudget resources. -type Interface interface { - ModInterface - ReadInterface -} - -// ReadInterface has methods to work with PodDisruptionBudget resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*policy.PodDisruptionBudget, error) -} diff --git a/pkg/util/k8sutil/inspector/secret/definition.go b/pkg/util/k8sutil/inspector/secret/definition.go index 577c747c9..8b54de399 100644 --- a/pkg/util/k8sutil/inspector/secret/definition.go +++ b/pkg/util/k8sutil/inspector/secret/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,10 @@ package secret import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +32,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() v1.Inspector + V1() generic.Inspector[*core.Secret] } diff --git a/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/loader.go b/pkg/util/k8sutil/inspector/secret/generic.go similarity index 62% rename from pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/loader.go rename to pkg/util/k8sutil/inspector/secret/generic.go index 12fe2b124..70538c909 100644 --- a/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/loader.go +++ b/pkg/util/k8sutil/inspector/secret/generic.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,22 +18,27 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1 +package secret import ( core "k8s.io/api/core/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -type Inspector interface { - gvk.GVK +func List(filter ...generic.Filter[*core.Secret]) generic.ExtractorList[*core.SecretList, *core.Secret] { + return func(in *core.SecretList) []*core.Secret { + ret := make([]*core.Secret, 0, len(in.Items)) - ListSimple() []*core.PersistentVolumeClaim - GetSimple(name string) (*core.PersistentVolumeClaim, bool) - Iterate(action Action, filters ...Filter) error - Read() ReadInterface + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } } - -type Filter func(pvc *core.PersistentVolumeClaim) bool -type Action func(pvc *core.PersistentVolumeClaim) error diff --git a/pkg/util/k8sutil/inspector/secret/v1/loader.go b/pkg/util/k8sutil/inspector/secret/v1/loader.go deleted file mode 100644 index 3bdf6d689..000000000 --- a/pkg/util/k8sutil/inspector/secret/v1/loader.go +++ /dev/null @@ -1,40 +0,0 @@ -// -// 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 v1 - -import ( - core "k8s.io/api/core/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" -) - -// Inspector for secrets -type Inspector interface { - gvk.GVK - - ListSimple() []*core.Secret - GetSimple(name string) (*core.Secret, bool) - Iterate(action Action, filters ...Filter) error - Read() ReadInterface -} - -type Filter func(pod *core.Secret) bool -type Action func(pod *core.Secret) error diff --git a/pkg/util/k8sutil/inspector/secret/v1/reader.go b/pkg/util/k8sutil/inspector/secret/v1/reader.go deleted file mode 100644 index dcbcff5a1..000000000 --- a/pkg/util/k8sutil/inspector/secret/v1/reader.go +++ /dev/null @@ -1,48 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2023 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 v1 - -import ( - "context" - - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -// ModInterface has methods to work with Secret resources only for creation -type ModInterface interface { - Create(ctx context.Context, secret *core.Secret, opts meta.CreateOptions) (*core.Secret, error) - Update(ctx context.Context, secret *core.Secret, opts meta.UpdateOptions) (*core.Secret, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.Secret, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// Interface has methods to work with Secret resources. -type Interface interface { - ModInterface - ReadInterface -} - -// ReadInterface has methods to work with Secret resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Secret, error) -} diff --git a/pkg/util/k8sutil/inspector/service/definition.go b/pkg/util/k8sutil/inspector/service/definition.go index 5ffbf8a26..bba5fcc7e 100644 --- a/pkg/util/k8sutil/inspector/service/definition.go +++ b/pkg/util/k8sutil/inspector/service/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,10 @@ package service import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +32,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() v1.Inspector + V1() generic.Inspector[*core.Service] } diff --git a/pkg/util/k8sutil/inspector/service/generic.go b/pkg/util/k8sutil/inspector/service/generic.go new file mode 100644 index 000000000..a28991f8e --- /dev/null +++ b/pkg/util/k8sutil/inspector/service/generic.go @@ -0,0 +1,44 @@ +// +// DISCLAIMER +// +// Copyright 2024 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 service + +import ( + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" +) + +func List(filter ...generic.Filter[*core.Service]) generic.ExtractorList[*core.ServiceList, *core.Service] { + return func(in *core.ServiceList) []*core.Service { + ret := make([]*core.Service, 0, len(in.Items)) + + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } +} diff --git a/pkg/util/k8sutil/inspector/service/v1/loader.go b/pkg/util/k8sutil/inspector/service/v1/loader.go deleted file mode 100644 index e116f2a24..000000000 --- a/pkg/util/k8sutil/inspector/service/v1/loader.go +++ /dev/null @@ -1,38 +0,0 @@ -// -// 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 v1 - -import ( - core "k8s.io/api/core/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" -) - -type Inspector interface { - gvk.GVK - - GetSimple(name string) (*core.Service, bool) - Iterate(action Action, filters ...Filter) error - Read() ReadInterface -} - -type Filter func(pod *core.Service) bool -type Action func(pod *core.Service) error diff --git a/pkg/util/k8sutil/inspector/service/v1/reader.go b/pkg/util/k8sutil/inspector/service/v1/reader.go deleted file mode 100644 index aeb2fc0b0..000000000 --- a/pkg/util/k8sutil/inspector/service/v1/reader.go +++ /dev/null @@ -1,48 +0,0 @@ -// -// 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 v1 - -import ( - "context" - - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -// ModInterface has methods to work with Service resources only for creation -type ModInterface interface { - Create(ctx context.Context, service *core.Service, opts meta.CreateOptions) (*core.Service, error) - Update(ctx context.Context, service *core.Service, opts meta.UpdateOptions) (*core.Service, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.Service, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// ReadInterface has methods to work with Secret resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Service, error) -} - -// Interface has methods to work with Service resources. -type Interface interface { - ModInterface - ReadInterface -} diff --git a/pkg/util/k8sutil/inspector/serviceaccount/definition.go b/pkg/util/k8sutil/inspector/serviceaccount/definition.go index 3b2ae52dc..a6da69e32 100644 --- a/pkg/util/k8sutil/inspector/serviceaccount/definition.go +++ b/pkg/util/k8sutil/inspector/serviceaccount/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,10 @@ package serviceaccount import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +32,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() v1.Inspector + V1() generic.Inspector[*core.ServiceAccount] } diff --git a/pkg/util/k8sutil/inspector/serviceaccount/generic.go b/pkg/util/k8sutil/inspector/serviceaccount/generic.go new file mode 100644 index 000000000..39472872b --- /dev/null +++ b/pkg/util/k8sutil/inspector/serviceaccount/generic.go @@ -0,0 +1,44 @@ +// +// DISCLAIMER +// +// Copyright 2024 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 serviceaccount + +import ( + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" +) + +func List(filter ...generic.Filter[*core.ServiceAccount]) generic.ExtractorList[*core.ServiceAccountList, *core.ServiceAccount] { + return func(in *core.ServiceAccountList) []*core.ServiceAccount { + ret := make([]*core.ServiceAccount, 0, len(in.Items)) + + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } +} diff --git a/pkg/util/k8sutil/inspector/serviceaccount/v1/loader.go b/pkg/util/k8sutil/inspector/serviceaccount/v1/loader.go deleted file mode 100644 index 2300261b4..000000000 --- a/pkg/util/k8sutil/inspector/serviceaccount/v1/loader.go +++ /dev/null @@ -1,38 +0,0 @@ -// -// 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 v1 - -import ( - core "k8s.io/api/core/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" -) - -type Inspector interface { - gvk.GVK - - GetSimple(name string) (*core.ServiceAccount, bool) - Iterate(action Action, filters ...Filter) error - Read() ReadInterface -} - -type Filter func(pod *core.ServiceAccount) bool -type Action func(pod *core.ServiceAccount) error diff --git a/pkg/util/k8sutil/inspector/serviceaccount/v1/reader.go b/pkg/util/k8sutil/inspector/serviceaccount/v1/reader.go deleted file mode 100644 index 2b9838374..000000000 --- a/pkg/util/k8sutil/inspector/serviceaccount/v1/reader.go +++ /dev/null @@ -1,52 +0,0 @@ -// -// 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 v1 - -import ( - "context" - - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" -) - -// ModInterface has methods to work with ServiceAccount resources only for creation -type ModInterface interface { - Create(ctx context.Context, serviceaccount *core.ServiceAccount, opts meta.CreateOptions) (*core.ServiceAccount, error) - Update(ctx context.Context, serviceaccount *core.ServiceAccount, opts meta.UpdateOptions) (*core.ServiceAccount, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.ServiceAccount, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// Interface has methods to work with ServiceAccount resources. -type Interface interface { - anonymous.Impl - - ModInterface - ReadInterface -} - -// ReadInterface has methods to work with ServiceAccount resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*core.ServiceAccount, error) -} diff --git a/pkg/util/k8sutil/inspector/servicemonitor/definition.go b/pkg/util/k8sutil/inspector/servicemonitor/definition.go index f5cb6e73d..3cb87cee7 100644 --- a/pkg/util/k8sutil/inspector/servicemonitor/definition.go +++ b/pkg/util/k8sutil/inspector/servicemonitor/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,11 +21,10 @@ package servicemonitor import ( - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" - v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version" + monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/base" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) type Inspector interface { @@ -33,12 +32,7 @@ type Inspector interface { } type Definition interface { - refresh.Inspector + base.Inspector - gvk.GK - anonymous.Impl - - Version() version.Version - - V1() (v1.Inspector, error) + V1() (generic.Inspector[*monitoring.ServiceMonitor], error) } diff --git a/pkg/util/k8sutil/inspector/servicemonitor/v1/loader.go b/pkg/util/k8sutil/inspector/servicemonitor/generic.go similarity index 60% rename from pkg/util/k8sutil/inspector/servicemonitor/v1/loader.go rename to pkg/util/k8sutil/inspector/servicemonitor/generic.go index 9b559ecd4..711c31572 100644 --- a/pkg/util/k8sutil/inspector/servicemonitor/v1/loader.go +++ b/pkg/util/k8sutil/inspector/servicemonitor/generic.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 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. @@ -18,21 +18,27 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package v1 +package servicemonitor import ( monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -type Inspector interface { - gvk.GVK +func List(filter ...generic.Filter[*monitoring.ServiceMonitor]) generic.ExtractorList[*monitoring.ServiceMonitorList, *monitoring.ServiceMonitor] { + return func(in *monitoring.ServiceMonitorList) []*monitoring.ServiceMonitor { + ret := make([]*monitoring.ServiceMonitor, 0, len(in.Items)) - GetSimple(name string) (*monitoring.ServiceMonitor, bool) - Iterate(action Action, filters ...Filter) error - Read() ReadInterface + for _, el := range in.Items { + z := el.DeepCopy() + if !generic.FilterObject(z, filter...) { + continue + } + + ret = append(ret, z) + } + + return ret + } } - -type Filter func(serviceMonitor *monitoring.ServiceMonitor) bool -type Action func(serviceMonitor *monitoring.ServiceMonitor) error diff --git a/pkg/util/k8sutil/inspector/servicemonitor/v1/reader.go b/pkg/util/k8sutil/inspector/servicemonitor/v1/reader.go deleted file mode 100644 index f7e607149..000000000 --- a/pkg/util/k8sutil/inspector/servicemonitor/v1/reader.go +++ /dev/null @@ -1,52 +0,0 @@ -// -// 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 v1 - -import ( - "context" - - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" -) - -// ModInterface has methods to work with ServiceMonitor resources only for creation -type ModInterface interface { - Create(ctx context.Context, servicemonitor *monitoring.ServiceMonitor, opts meta.CreateOptions) (*monitoring.ServiceMonitor, error) - Update(ctx context.Context, servicemonitor *monitoring.ServiceMonitor, opts meta.UpdateOptions) (*monitoring.ServiceMonitor, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *monitoring.ServiceMonitor, err error) - Delete(ctx context.Context, name string, opts meta.DeleteOptions) error -} - -// Interface has methods to work with ServiceMonitor resources. -type Interface interface { - anonymous.Impl - - ModInterface - ReadInterface -} - -// ReadInterface has methods to work with ServiceMonitor resources with ReadOnly mode. -type ReadInterface interface { - Get(ctx context.Context, name string, opts meta.GetOptions) (*monitoring.ServiceMonitor, error) -} diff --git a/pkg/util/k8sutil/list.go b/pkg/util/k8sutil/list.go deleted file mode 100644 index 8202f5d1a..000000000 --- a/pkg/util/k8sutil/list.go +++ /dev/null @@ -1,46 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023-2024 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 k8sutil - -import ( - "context" - - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" -) - -func APIList[T generic.ListContinue](ctx context.Context, api generic.ListInterface[T], opts meta.ListOptions, parser func(result T, err error) error) error { - result, err := api.List(ctx, opts) - for { - if err := parser(result, err); err != nil { - return err - } - - if c := result.GetContinue(); c == "" { - return nil - } else { - result, err = api.List(ctx, meta.ListOptions{ - Continue: result.GetContinue(), - }) - } - } -} diff --git a/pkg/util/k8sutil/list/list.go b/pkg/util/k8sutil/list/list.go new file mode 100644 index 000000000..d51f77f62 --- /dev/null +++ b/pkg/util/k8sutil/list/list.go @@ -0,0 +1,79 @@ +// +// DISCLAIMER +// +// Copyright 2024 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 list + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/arangodb/kube-arangodb/pkg/util/errors" + "github.com/arangodb/kube-arangodb/pkg/util/globals" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" +) + +func APIMap[L generic.ListContinue, S meta.Object](ctx context.Context, i generic.ListInterface[L], opts meta.ListOptions, call generic.ExtractorList[L, S]) (map[string]S, error) { + res, err := APIList(ctx, i, opts, call) + if err != nil { + return nil, err + } + + result := make(map[string]S, len(res)) + + for _, el := range res { + if _, ok := result[el.GetName()]; ok { + return nil, errors.Errorf("Key %s already exists", el.GetName()) + } + + result[el.GetName()] = el + } + + return result, nil +} + +func APIList[L generic.ListContinue, S meta.Object](ctx context.Context, i generic.ListInterface[L], opts meta.ListOptions, call generic.ExtractorList[L, S]) ([]S, error) { + var results []S + + var cont string + + for { + opts.Continue = cont + if v := globals.GetGlobals().Kubernetes().RequestBatchSize().Get(); opts.Limit <= 0 || opts.Limit > v { + opts.Limit = v + } + res, err := i.List(ctx, opts) + if err != nil { + return nil, err + } + + objs := call(res) + + results = append(results, objs...) + + if res.GetContinue() == "" { + break + } + + cont = res.GetContinue() + } + + return results, nil +} diff --git a/pkg/util/k8sutil/pods.go b/pkg/util/k8sutil/pods.go index 5d27339e4..95751059c 100644 --- a/pkg/util/k8sutil/pods.go +++ b/pkg/util/k8sutil/pods.go @@ -45,7 +45,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/constants" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" - podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" ) @@ -607,7 +607,7 @@ func GetPodSpecChecksum(podSpec core.PodSpec) (string, error) { // CreatePod adds an owner to the given pod and calls the k8s api-server to created it. // If the pod already exists, nil is returned. // If another error occurs, that error is returned. -func CreatePod(ctx context.Context, c podv1.ModInterface, pod *core.Pod, ns string, +func CreatePod(ctx context.Context, c generic.ModClient[*core.Pod], pod *core.Pod, ns string, owner meta.OwnerReference) (string, types.UID, error) { AddOwnerRefToObject(pod.GetObjectMeta(), &owner) @@ -691,7 +691,7 @@ func CreateEnvSecretKeySelector(name, SecretKeyName, secretKey string) core.EnvV } } -func EnsureFinalizerAbsent(ctx context.Context, pods podv1.Interface, pod *core.Pod, finalizers ...string) error { +func EnsureFinalizerAbsent(ctx context.Context, pods generic.ModClient[*core.Pod], pod *core.Pod, finalizers ...string) error { var newFinalizers []string c := utils.StringList(finalizers) @@ -709,7 +709,7 @@ func EnsureFinalizerAbsent(ctx context.Context, pods podv1.Interface, pod *core. return SetFinalizers(ctx, pods, pod, newFinalizers...) } -func EnsureFinalizerPresent(ctx context.Context, pods podv1.Interface, pod *core.Pod, finalizers ...string) error { +func EnsureFinalizerPresent(ctx context.Context, pods generic.ModClient[*core.Pod], pod *core.Pod, finalizers ...string) error { var newFinalizers []string newFinalizers = append(newFinalizers, pod.Finalizers...) @@ -729,7 +729,7 @@ func EnsureFinalizerPresent(ctx context.Context, pods podv1.Interface, pod *core return SetFinalizers(ctx, pods, pod, newFinalizers...) } -func SetFinalizers(ctx context.Context, pods podv1.Interface, pod *core.Pod, finalizers ...string) error { +func SetFinalizers(ctx context.Context, pods generic.ModClient[*core.Pod], pod *core.Pod, finalizers ...string) error { d, err := patch.NewPatch(patch.ItemReplace(patch.NewPath("metadata", "finalizers"), finalizers)).Marshal() if err != nil { return err diff --git a/pkg/util/k8sutil/pvc.go b/pkg/util/k8sutil/pvc.go index e0babd031..621227b13 100644 --- a/pkg/util/k8sutil/pvc.go +++ b/pkg/util/k8sutil/pvc.go @@ -29,7 +29,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/constants" "github.com/arangodb/kube-arangodb/pkg/util/errors" - persistentvolumeclaimv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" kresources "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources" ) @@ -66,7 +66,7 @@ func IsPersistentVolumeClaimResizing(pvc *core.PersistentVolumeClaim) bool { // CreatePersistentVolumeClaim creates a persistent volume claim with given name and configuration. // If the pvc already exists, nil is returned. // If another error occurs, that error is returned. -func CreatePersistentVolumeClaim(ctx context.Context, pvcs persistentvolumeclaimv1.ModInterface, pvcName, deploymentName, +func CreatePersistentVolumeClaim(ctx context.Context, pvcs generic.ModClient[*core.PersistentVolumeClaim], pvcName, deploymentName, storageClassName, role string, enforceAntiAffinity bool, resources core.ResourceRequirements, vct *core.PersistentVolumeClaim, finalizers []string, owner meta.OwnerReference) error { labels := LabelsForDeployment(deploymentName, role) diff --git a/pkg/util/k8sutil/secrets.go b/pkg/util/k8sutil/secrets.go index 4ae62fa73..84302b938 100644 --- a/pkg/util/k8sutil/secrets.go +++ b/pkg/util/k8sutil/secrets.go @@ -32,14 +32,14 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/crypto" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" - secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" "github.com/arangodb/kube-arangodb/pkg/util/token" ) // ValidateEncryptionKeySecret checks that a secret with given name in given namespace // exists and it contains a 'key' data field of exactly 32 bytes. -func ValidateEncryptionKeySecret(secrets secretv1.Interface, secretName string) error { +func ValidateEncryptionKeySecret(secrets generic.InspectorInterface[*core.Secret], secretName string) error { s, err := secrets.Get(context.Background(), secretName, meta.GetOptions{}) if err != nil { return errors.WithStack(err) @@ -60,7 +60,7 @@ func ValidateEncryptionKeyFromSecret(s *core.Secret) error { } // CreateEncryptionKeySecret creates a secret used to store a RocksDB encryption key. -func CreateEncryptionKeySecret(secrets secretv1.ModInterface, secretName string, key []byte) error { +func CreateEncryptionKeySecret(secrets generic.ModClient[*core.Secret], secretName string, key []byte) error { if len(key) != 32 { return errors.WithStack(errors.Errorf("Key in secret '%s' is expected to be 32 bytes long, got %d", secretName, len(key))) } @@ -82,7 +82,7 @@ func CreateEncryptionKeySecret(secrets secretv1.ModInterface, secretName string, // ValidateCACertificateSecret checks that a secret with given name in given namespace // exists and it contains a 'ca.crt' data field. -func ValidateCACertificateSecret(ctx context.Context, secrets secretv1.ReadInterface, secretName string) error { +func ValidateCACertificateSecret(ctx context.Context, secrets generic.ReadClient[*core.Secret], secretName string) error { s, err := secrets.Get(ctx, secretName, meta.GetOptions{}) if err != nil { return errors.WithStack(err) @@ -100,7 +100,7 @@ func ValidateCACertificateSecret(ctx context.Context, secrets secretv1.ReadInter // If the secret does not exists the field is missing, // an error is returned. // Returns: certificate, error -func GetCACertficateSecret(ctx context.Context, secrets secretv1.ReadInterface, secretName string) (string, error) { +func GetCACertficateSecret(ctx context.Context, secrets generic.ReadClient[*core.Secret], secretName string) (string, error) { ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() @@ -121,7 +121,7 @@ func GetCACertficateSecret(ctx context.Context, secrets secretv1.ReadInterface, // If the secret does not exists or one of the fields is missing, // an error is returned. // Returns: certificate, private-key, isOwnedByDeployment, error -func GetCASecret(ctx context.Context, secrets secretv1.ReadInterface, secretName string, +func GetCASecret(ctx context.Context, secrets generic.ReadClient[*core.Secret], secretName string, ownerRef *meta.OwnerReference) (string, string, bool, error) { s, err := secrets.Get(ctx, secretName, meta.GetOptions{}) if err != nil { @@ -172,7 +172,7 @@ func GetKeyCertFromSecret(secret *core.Secret, certName, keyName string) (crypto } // CreateCASecret creates a secret used to store a PEM encoded CA certificate & private key. -func CreateCASecret(ctx context.Context, secrets secretv1.ModInterface, secretName string, certificate, key string, +func CreateCASecret(ctx context.Context, secrets generic.ModClient[*core.Secret], secretName string, certificate, key string, ownerRef *meta.OwnerReference) error { // Create secret secret := &core.Secret{ @@ -196,7 +196,7 @@ func CreateCASecret(ctx context.Context, secrets secretv1.ModInterface, secretNa // GetTLSKeyfileSecret loads a secret used to store a PEM encoded keyfile // in the format ArangoDB accepts it for its `--ssl.keyfile` option. // Returns: keyfile (pem encoded), error -func GetTLSKeyfileSecret(secrets secretv1.ReadInterface, secretName string) (string, error) { +func GetTLSKeyfileSecret(secrets generic.ReadClient[*core.Secret], secretName string) (string, error) { s, err := secrets.Get(context.Background(), secretName, meta.GetOptions{}) if err != nil { return "", errors.WithStack(err) @@ -232,7 +232,7 @@ func RenderTLSKeyfileSecret(secretName string, keyfile string, ownerRef *meta.Ow // CreateTLSKeyfileSecret creates a secret used to store a PEM encoded keyfile // in the format ArangoDB accepts it for its `--ssl.keyfile` option. -func CreateTLSKeyfileSecret(ctx context.Context, secrets secretv1.ModInterface, secretName string, keyfile string, +func CreateTLSKeyfileSecret(ctx context.Context, secrets generic.ModClient[*core.Secret], secretName string, keyfile string, ownerRef *meta.OwnerReference) (*core.Secret, error) { secret := RenderTLSKeyfileSecret(secretName, keyfile, ownerRef) if s, err := secrets.Create(ctx, secret, meta.CreateOptions{}); err != nil { @@ -245,7 +245,7 @@ func CreateTLSKeyfileSecret(ctx context.Context, secrets secretv1.ModInterface, // ValidateTokenSecret checks that a secret with given name in given namespace // exists and it contains a 'token' data field. -func ValidateTokenSecret(ctx context.Context, secrets secretv1.ReadInterface, secretName string) error { +func ValidateTokenSecret(ctx context.Context, secrets generic.ReadClient[*core.Secret], secretName string) error { s, err := secrets.Get(ctx, secretName, meta.GetOptions{}) if err != nil { return errors.WithStack(err) @@ -263,7 +263,7 @@ func ValidateTokenFromSecret(s *core.Secret) error { } // GetTokenSecret loads the token secret from a Secret with given name. -func GetTokenSecret(ctx context.Context, secrets secretv1.ReadInterface, secretName string) (string, error) { +func GetTokenSecret(ctx context.Context, secrets generic.ReadClient[*core.Secret], secretName string) (string, error) { s, err := secrets.Get(ctx, secretName, meta.GetOptions{}) if err != nil { return "", errors.WithStack(err) @@ -283,7 +283,7 @@ func GetTokenFromSecret(s *core.Secret) (string, error) { // CreateTokenSecret creates a secret with given name in given namespace // with a given token as value. -func CreateTokenSecret(ctx context.Context, secrets secretv1.ModInterface, secretName, token string, +func CreateTokenSecret(ctx context.Context, secrets generic.ModClient[*core.Secret], secretName, token string, ownerRef *meta.OwnerReference) error { // Create secret secret := &core.Secret{ @@ -305,7 +305,7 @@ func CreateTokenSecret(ctx context.Context, secrets secretv1.ModInterface, secre // UpdateTokenSecret updates a secret with given name in given namespace // with a given token as value. -func UpdateTokenSecret(ctx context.Context, secrets secretv1.ModInterface, secret *core.Secret, token string) error { +func UpdateTokenSecret(ctx context.Context, secrets generic.ModClient[*core.Secret], secret *core.Secret, token string) error { secret.Data = map[string][]byte{ constants.SecretKeyToken: []byte(token), } @@ -318,7 +318,7 @@ func UpdateTokenSecret(ctx context.Context, secrets secretv1.ModInterface, secre // CreateJWTFromSecret creates a JWT using the secret stored in secretSecretName and stores the // result in a new secret called tokenSecretName -func CreateJWTFromSecret(ctx context.Context, cachedSecrets secretv1.ReadInterface, secrets secretv1.ModInterface, tokenSecretName, secretSecretName string, claims map[string]interface{}, ownerRef *meta.OwnerReference) error { +func CreateJWTFromSecret(ctx context.Context, cachedSecrets generic.ReadClient[*core.Secret], secrets generic.ModClient[*core.Secret], tokenSecretName, secretSecretName string, claims map[string]interface{}, ownerRef *meta.OwnerReference) error { secret, err := GetTokenSecret(ctx, cachedSecrets, secretSecretName) if err != nil { return errors.WithStack(err) @@ -336,7 +336,7 @@ func CreateJWTFromSecret(ctx context.Context, cachedSecrets secretv1.ReadInterfa // UpdateJWTFromSecret updates a JWT using the secret stored in secretSecretName and stores the // result in a new secret called tokenSecretName -func UpdateJWTFromSecret(ctx context.Context, cachedSecrets secretv1.ReadInterface, secrets secretv1.ModInterface, tokenSecretName, secretSecretName string, claims map[string]interface{}) error { +func UpdateJWTFromSecret(ctx context.Context, cachedSecrets generic.ReadClient[*core.Secret], secrets generic.ModClient[*core.Secret], tokenSecretName, secretSecretName string, claims map[string]interface{}) error { current, err := cachedSecrets.Get(ctx, tokenSecretName, meta.GetOptions{}) if err != nil { return errors.WithStack(err) @@ -359,7 +359,7 @@ func UpdateJWTFromSecret(ctx context.Context, cachedSecrets secretv1.ReadInterfa // CreateBasicAuthSecret creates a secret with given name in given namespace // with a given username and password as value. -func CreateBasicAuthSecret(ctx context.Context, secrets secretv1.ModInterface, secretName, username, password string, +func CreateBasicAuthSecret(ctx context.Context, secrets generic.ModClient[*core.Secret], secretName, username, password string, ownerRef *meta.OwnerReference) error { // Create secret secret := &core.Secret{ @@ -389,7 +389,7 @@ func CreateBasicAuthSecret(ctx context.Context, secrets secretv1.ModInterface, s // If the secret does not exists or one of the fields is missing, // an error is returned. // Returns: username, password, error -func GetBasicAuthSecret(secrets secretv1.Interface, secretName string) (string, string, error) { +func GetBasicAuthSecret(secrets generic.ReadClient[*core.Secret], secretName string) (string, string, error) { s, err := secrets.Get(context.Background(), secretName, meta.GetOptions{}) if err != nil { return "", "", errors.WithStack(err) diff --git a/pkg/util/k8sutil/services.go b/pkg/util/k8sutil/services.go index f4cbc065b..47a63f7a9 100644 --- a/pkg/util/k8sutil/services.go +++ b/pkg/util/k8sutil/services.go @@ -35,7 +35,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - servicev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/patcher" ) @@ -126,7 +126,7 @@ func ExporterServiceDetails(deploymentName string) ([]core.ServicePort, map[stri // If the service already exists, nil is returned. // If another error occurs, that error is returned. // The returned bool is true if the service is created, or false when the service already existed. -func CreateHeadlessService(ctx context.Context, svcs servicev1.ModInterface, deployment meta.Object, +func CreateHeadlessService(ctx context.Context, svcs generic.ModClient[*core.Service], deployment meta.Object, ports []core.ServicePort, selectors map[string]string, owner meta.OwnerReference) (string, bool, error) { deploymentName := deployment.GetName() @@ -158,7 +158,7 @@ func HeadlessServiceDetails(deploymentName string) ([]core.ServicePort, map[stri // If the service already exists, nil is returned. // If another error occurs, that error is returned. // The returned bool is true if the service is created, or false when the service already existed. -func CreateDatabaseClientService(ctx context.Context, svcs servicev1.ModInterface, deployment meta.Object, +func CreateDatabaseClientService(ctx context.Context, svcs generic.ModClient[*core.Service], deployment meta.Object, ports []core.ServicePort, selectors map[string]string, owner meta.OwnerReference) (string, bool, error) { deploymentName := deployment.GetName() svcName := CreateDatabaseClientServiceName(deploymentName) @@ -193,7 +193,7 @@ func DatabaseClientDetails(deploymentName string, role string, withLeader bool) // If the service already exists, nil is returned. // If another error occurs, that error is returned. // The returned bool is true if the service is created, or false when the service already existed. -func CreateExternalAccessService(ctx context.Context, svcs servicev1.ModInterface, svcName string, serviceType core.ServiceType, +func CreateExternalAccessService(ctx context.Context, svcs generic.ModClient[*core.Service], svcName string, serviceType core.ServiceType, ports []core.ServicePort, selectors map[string]string, loadBalancerIP string, loadBalancerSourceRanges []string, owner meta.OwnerReference) (string, bool, error) { @@ -228,7 +228,7 @@ func ExternalAccessDetails(port, nodePort int, deploymentName, role string, with // If the service already exists, nil is returned. // If another error occurs, that error is returned. // The returned bool is true if the service is created, or false when the service already existed. -func createService(ctx context.Context, svcs servicev1.ModInterface, svcName, clusterIP string, +func createService(ctx context.Context, svcs generic.ModClient[*core.Service], svcName, clusterIP string, serviceType core.ServiceType, ports []core.ServicePort, selectors map[string]string, loadBalancerIP string, loadBalancerSourceRanges []string, publishNotReadyAddresses bool, owner meta.OwnerReference) (bool, error) { svc := &core.Service{ diff --git a/pkg/util/kclient/mod.go b/pkg/util/kclient/mod.go index 09f69e6b4..50ff401c1 100644 --- a/pkg/util/kclient/mod.go +++ b/pkg/util/kclient/mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 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. @@ -21,14 +21,12 @@ package kclient import ( - arangomemberv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember/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" - poddisruptionbudgetv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1" - 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" + monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + core "k8s.io/api/core/v1" + policy "k8s.io/api/policy/v1" + + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) func NewModInterface(client Client, namespace string) ModInterface { @@ -39,14 +37,14 @@ func NewModInterface(client Client, namespace string) ModInterface { } type ModInterface interface { - Secrets() secretv1.ModInterface - Pods() podv1.ModInterface - Services() servicev1.ModInterface - ServiceAccounts() serviceaccountv1.ModInterface - PersistentVolumeClaims() persistentvolumeclaimv1.ModInterface - PodDisruptionBudgets() poddisruptionbudgetv1.ModInterface - ServiceMonitors() servicemonitorv1.ModInterface - ArangoMembers() arangomemberv1.ModInterface + Secrets() generic.ModClient[*core.Secret] + Pods() generic.ModClient[*core.Pod] + Services() generic.ModClient[*core.Service] + ServiceAccounts() generic.ModClient[*core.ServiceAccount] + PersistentVolumeClaims() generic.ModClient[*core.PersistentVolumeClaim] + PodDisruptionBudgets() generic.ModClient[*policy.PodDisruptionBudget] + ServiceMonitors() generic.ModClient[*monitoring.ServiceMonitor] + ArangoMembers() generic.ModStatusClient[*api.ArangoMember] } type modInterface struct { @@ -54,34 +52,34 @@ type modInterface struct { namespace string } -func (m modInterface) PersistentVolumeClaims() persistentvolumeclaimv1.ModInterface { +func (m modInterface) PersistentVolumeClaims() generic.ModClient[*core.PersistentVolumeClaim] { return m.client.Kubernetes().CoreV1().PersistentVolumeClaims(m.namespace) } -func (m modInterface) PodDisruptionBudgets() poddisruptionbudgetv1.ModInterface { +func (m modInterface) PodDisruptionBudgets() generic.ModClient[*policy.PodDisruptionBudget] { return m.client.Kubernetes().PolicyV1().PodDisruptionBudgets(m.namespace) } -func (m modInterface) ServiceMonitors() servicemonitorv1.ModInterface { +func (m modInterface) ServiceMonitors() generic.ModClient[*monitoring.ServiceMonitor] { return m.client.Monitoring().MonitoringV1().ServiceMonitors(m.namespace) } -func (m modInterface) ArangoMembers() arangomemberv1.ModInterface { +func (m modInterface) ArangoMembers() generic.ModStatusClient[*api.ArangoMember] { return m.client.Arango().DatabaseV1().ArangoMembers(m.namespace) } -func (m modInterface) Services() servicev1.ModInterface { +func (m modInterface) Services() generic.ModClient[*core.Service] { return m.client.Kubernetes().CoreV1().Services(m.namespace) } -func (m modInterface) ServiceAccounts() serviceaccountv1.ModInterface { +func (m modInterface) ServiceAccounts() generic.ModClient[*core.ServiceAccount] { return m.client.Kubernetes().CoreV1().ServiceAccounts(m.namespace) } -func (m modInterface) Pods() podv1.ModInterface { +func (m modInterface) Pods() generic.ModClient[*core.Pod] { return m.client.Kubernetes().CoreV1().Pods(m.namespace) } -func (m modInterface) Secrets() secretv1.ModInterface { +func (m modInterface) Secrets() generic.ModClient[*core.Secret] { return m.client.Kubernetes().CoreV1().Secrets(m.namespace) } diff --git a/pkg/util/list.go b/pkg/util/list.go index 1d1e76ce7..30e438d7d 100644 --- a/pkg/util/list.go +++ b/pkg/util/list.go @@ -81,6 +81,16 @@ func (l List[T]) Unique(f func(existing List[T], a T) bool) List[T] { return r } +func ListAsMap[K comparable, V any](in []V, extract func(in V) K) map[K]V { + ret := make(map[K]V, len(in)) + + for _, el := range in { + ret[extract(el)] = el + } + + return ret +} + func PickFromList[V any](in []V, q func(v V) bool) (V, bool) { for _, v := range in { if q(v) { diff --git a/pkg/util/refs.go b/pkg/util/refs.go index f32cac7ce..33578874f 100644 --- a/pkg/util/refs.go +++ b/pkg/util/refs.go @@ -188,3 +188,12 @@ func JSONRemarshal[A, B any](in A) (B, error) { return o, nil } + +func InitOptional[T any](in *T, ok bool) *T { + if ok { + return in + } + + var z T + return &z +}