diff --git a/.golangci.yaml b/.golangci.yaml index 305ce8113..c924eecfc 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -155,6 +155,8 @@ linters-settings: pkg: github.com/envoyproxy/go-control-plane/envoy/config/listener/v3 - alias: pbEnvoyRouteV3 pkg: github.com/envoyproxy/go-control-plane/envoy/config/route/v3 + - alias: monitoringApi + pkg: github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1 - alias: apps pkg: k8s.io/api/apps/v1 - alias: batch diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d2d61565..ff566b40e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - (Bugfix) Improve Profile Tolerations Merge - (Maintenance) Update Envoy to v1.32.5 - (Maintenance) Generate CRD with Schemas +- (Feature) DebugPackage Improvements ## [1.2.47](https://github.com/arangodb/kube-arangodb/tree/1.2.47) (2025-03-28) - (Bugfix) Use Profile Annotations diff --git a/chart/kube-arangodb-arm64/templates/debug/cluster-role-binding.yaml b/chart/kube-arangodb-arm64/templates/debug/cluster-role-binding.yaml new file mode 100644 index 000000000..47bb00b02 --- /dev/null +++ b/chart/kube-arangodb-arm64/templates/debug/cluster-role-binding.yaml @@ -0,0 +1,26 @@ +{{ if .Values.rbac.enabled -}} +{{ if not (eq .Values.operator.scope "namespaced") -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug +subjects: + - kind: ServiceAccount + name: {{ template "kube-arangodb.operatorName" . }} + namespace: {{ .Release.Namespace }} + +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-arm64/templates/debug/cluster-role.yaml b/chart/kube-arangodb-arm64/templates/debug/cluster-role.yaml new file mode 100644 index 000000000..59b1be1fe --- /dev/null +++ b/chart/kube-arangodb-arm64/templates/debug/cluster-role.yaml @@ -0,0 +1,22 @@ +{{ if .Values.rbac.enabled -}} +{{ if not (eq .Values.operator.scope "namespaced") -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +rules: + - apiGroups: ["apiextensions.k8s.io"] + resources: ["customresourcedefinitions"] + verbs: ["get", "list", "watch"] + +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-arm64/templates/debug/role-binding.yaml b/chart/kube-arangodb-arm64/templates/debug/role-binding.yaml new file mode 100644 index 000000000..b54d447cd --- /dev/null +++ b/chart/kube-arangodb-arm64/templates/debug/role-binding.yaml @@ -0,0 +1,25 @@ +{{ if .Values.rbac.enabled -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ template "kube-arangodb.rbac" . }}-debug + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ template "kube-arangodb.rbac" . }}-debug +subjects: + - kind: ServiceAccount + name: {{ template "kube-arangodb.operatorName" . }} + namespace: {{ .Release.Namespace }} + +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-arm64/templates/debug/role.yaml b/chart/kube-arangodb-arm64/templates/debug/role.yaml new file mode 100644 index 000000000..1b05d2022 --- /dev/null +++ b/chart/kube-arangodb-arm64/templates/debug/role.yaml @@ -0,0 +1,29 @@ +{{ if .Values.rbac.enabled -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ template "kube-arangodb.rbac" . }}-debug + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +rules: + - apiGroups: + - "" + - "apps" + - "batch" + resources: ["*"] + verbs: ["get", "list"] + - apiGroups: [""] + resources: ["pods/log"] + verbs: ["get", "list"] + - apiGroups: [""] + resources: ["pods/exec"] + verbs: ["create"] +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-arm64/templates/deployment-operator/role.yaml b/chart/kube-arangodb-arm64/templates/deployment-operator/role.yaml index 375541f68..a3ca5bc75 100644 --- a/chart/kube-arangodb-arm64/templates/deployment-operator/role.yaml +++ b/chart/kube-arangodb-arm64/templates/deployment-operator/role.yaml @@ -44,17 +44,6 @@ rules: - apiGroups: ["backup.arangodb.com"] resources: ["arangobackuppolicies", "arangobackups"] verbs: ["get", "list", "watch"] -{{- if .Values.rbac.extensions.debug }} - - apiGroups: ["events.k8s.io"] - resources: ["pods/log"] - verbs: ["list"] - - apiGroups: [""] - resources: ["pods/log"] - verbs: ["get", "list"] - - apiGroups: [""] - resources: ["pods/exec"] - verbs: ["create"] -{{- end }} {{- if .Values.rbac.extensions.monitoring }} - apiGroups: ["monitoring.coreos.com"] resources: ["servicemonitors"] diff --git a/chart/kube-arangodb-enterprise-arm64/templates/debug/cluster-role-binding.yaml b/chart/kube-arangodb-enterprise-arm64/templates/debug/cluster-role-binding.yaml new file mode 100644 index 000000000..47bb00b02 --- /dev/null +++ b/chart/kube-arangodb-enterprise-arm64/templates/debug/cluster-role-binding.yaml @@ -0,0 +1,26 @@ +{{ if .Values.rbac.enabled -}} +{{ if not (eq .Values.operator.scope "namespaced") -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug +subjects: + - kind: ServiceAccount + name: {{ template "kube-arangodb.operatorName" . }} + namespace: {{ .Release.Namespace }} + +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-enterprise-arm64/templates/debug/cluster-role.yaml b/chart/kube-arangodb-enterprise-arm64/templates/debug/cluster-role.yaml new file mode 100644 index 000000000..59b1be1fe --- /dev/null +++ b/chart/kube-arangodb-enterprise-arm64/templates/debug/cluster-role.yaml @@ -0,0 +1,22 @@ +{{ if .Values.rbac.enabled -}} +{{ if not (eq .Values.operator.scope "namespaced") -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +rules: + - apiGroups: ["apiextensions.k8s.io"] + resources: ["customresourcedefinitions"] + verbs: ["get", "list", "watch"] + +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-enterprise-arm64/templates/debug/role-binding.yaml b/chart/kube-arangodb-enterprise-arm64/templates/debug/role-binding.yaml new file mode 100644 index 000000000..b54d447cd --- /dev/null +++ b/chart/kube-arangodb-enterprise-arm64/templates/debug/role-binding.yaml @@ -0,0 +1,25 @@ +{{ if .Values.rbac.enabled -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ template "kube-arangodb.rbac" . }}-debug + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ template "kube-arangodb.rbac" . }}-debug +subjects: + - kind: ServiceAccount + name: {{ template "kube-arangodb.operatorName" . }} + namespace: {{ .Release.Namespace }} + +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-enterprise-arm64/templates/debug/role.yaml b/chart/kube-arangodb-enterprise-arm64/templates/debug/role.yaml new file mode 100644 index 000000000..1b05d2022 --- /dev/null +++ b/chart/kube-arangodb-enterprise-arm64/templates/debug/role.yaml @@ -0,0 +1,29 @@ +{{ if .Values.rbac.enabled -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ template "kube-arangodb.rbac" . }}-debug + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +rules: + - apiGroups: + - "" + - "apps" + - "batch" + resources: ["*"] + verbs: ["get", "list"] + - apiGroups: [""] + resources: ["pods/log"] + verbs: ["get", "list"] + - apiGroups: [""] + resources: ["pods/exec"] + verbs: ["create"] +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-enterprise-arm64/templates/deployment-operator/role.yaml b/chart/kube-arangodb-enterprise-arm64/templates/deployment-operator/role.yaml index 375541f68..a3ca5bc75 100644 --- a/chart/kube-arangodb-enterprise-arm64/templates/deployment-operator/role.yaml +++ b/chart/kube-arangodb-enterprise-arm64/templates/deployment-operator/role.yaml @@ -44,17 +44,6 @@ rules: - apiGroups: ["backup.arangodb.com"] resources: ["arangobackuppolicies", "arangobackups"] verbs: ["get", "list", "watch"] -{{- if .Values.rbac.extensions.debug }} - - apiGroups: ["events.k8s.io"] - resources: ["pods/log"] - verbs: ["list"] - - apiGroups: [""] - resources: ["pods/log"] - verbs: ["get", "list"] - - apiGroups: [""] - resources: ["pods/exec"] - verbs: ["create"] -{{- end }} {{- if .Values.rbac.extensions.monitoring }} - apiGroups: ["monitoring.coreos.com"] resources: ["servicemonitors"] diff --git a/chart/kube-arangodb-enterprise/templates/debug/cluster-role-binding.yaml b/chart/kube-arangodb-enterprise/templates/debug/cluster-role-binding.yaml new file mode 100644 index 000000000..47bb00b02 --- /dev/null +++ b/chart/kube-arangodb-enterprise/templates/debug/cluster-role-binding.yaml @@ -0,0 +1,26 @@ +{{ if .Values.rbac.enabled -}} +{{ if not (eq .Values.operator.scope "namespaced") -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug +subjects: + - kind: ServiceAccount + name: {{ template "kube-arangodb.operatorName" . }} + namespace: {{ .Release.Namespace }} + +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-enterprise/templates/debug/cluster-role.yaml b/chart/kube-arangodb-enterprise/templates/debug/cluster-role.yaml new file mode 100644 index 000000000..59b1be1fe --- /dev/null +++ b/chart/kube-arangodb-enterprise/templates/debug/cluster-role.yaml @@ -0,0 +1,22 @@ +{{ if .Values.rbac.enabled -}} +{{ if not (eq .Values.operator.scope "namespaced") -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +rules: + - apiGroups: ["apiextensions.k8s.io"] + resources: ["customresourcedefinitions"] + verbs: ["get", "list", "watch"] + +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-enterprise/templates/debug/role-binding.yaml b/chart/kube-arangodb-enterprise/templates/debug/role-binding.yaml new file mode 100644 index 000000000..b54d447cd --- /dev/null +++ b/chart/kube-arangodb-enterprise/templates/debug/role-binding.yaml @@ -0,0 +1,25 @@ +{{ if .Values.rbac.enabled -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ template "kube-arangodb.rbac" . }}-debug + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ template "kube-arangodb.rbac" . }}-debug +subjects: + - kind: ServiceAccount + name: {{ template "kube-arangodb.operatorName" . }} + namespace: {{ .Release.Namespace }} + +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-enterprise/templates/debug/role.yaml b/chart/kube-arangodb-enterprise/templates/debug/role.yaml new file mode 100644 index 000000000..1b05d2022 --- /dev/null +++ b/chart/kube-arangodb-enterprise/templates/debug/role.yaml @@ -0,0 +1,29 @@ +{{ if .Values.rbac.enabled -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ template "kube-arangodb.rbac" . }}-debug + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +rules: + - apiGroups: + - "" + - "apps" + - "batch" + resources: ["*"] + verbs: ["get", "list"] + - apiGroups: [""] + resources: ["pods/log"] + verbs: ["get", "list"] + - apiGroups: [""] + resources: ["pods/exec"] + verbs: ["create"] +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb-enterprise/templates/deployment-operator/role.yaml b/chart/kube-arangodb-enterprise/templates/deployment-operator/role.yaml index 375541f68..a3ca5bc75 100644 --- a/chart/kube-arangodb-enterprise/templates/deployment-operator/role.yaml +++ b/chart/kube-arangodb-enterprise/templates/deployment-operator/role.yaml @@ -44,17 +44,6 @@ rules: - apiGroups: ["backup.arangodb.com"] resources: ["arangobackuppolicies", "arangobackups"] verbs: ["get", "list", "watch"] -{{- if .Values.rbac.extensions.debug }} - - apiGroups: ["events.k8s.io"] - resources: ["pods/log"] - verbs: ["list"] - - apiGroups: [""] - resources: ["pods/log"] - verbs: ["get", "list"] - - apiGroups: [""] - resources: ["pods/exec"] - verbs: ["create"] -{{- end }} {{- if .Values.rbac.extensions.monitoring }} - apiGroups: ["monitoring.coreos.com"] resources: ["servicemonitors"] diff --git a/chart/kube-arangodb/templates/debug/cluster-role-binding.yaml b/chart/kube-arangodb/templates/debug/cluster-role-binding.yaml new file mode 100644 index 000000000..47bb00b02 --- /dev/null +++ b/chart/kube-arangodb/templates/debug/cluster-role-binding.yaml @@ -0,0 +1,26 @@ +{{ if .Values.rbac.enabled -}} +{{ if not (eq .Values.operator.scope "namespaced") -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug +subjects: + - kind: ServiceAccount + name: {{ template "kube-arangodb.operatorName" . }} + namespace: {{ .Release.Namespace }} + +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb/templates/debug/cluster-role.yaml b/chart/kube-arangodb/templates/debug/cluster-role.yaml new file mode 100644 index 000000000..59b1be1fe --- /dev/null +++ b/chart/kube-arangodb/templates/debug/cluster-role.yaml @@ -0,0 +1,22 @@ +{{ if .Values.rbac.enabled -}} +{{ if not (eq .Values.operator.scope "namespaced") -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ template "kube-arangodb.rbac-cluster" . }}-debug + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +rules: + - apiGroups: ["apiextensions.k8s.io"] + resources: ["customresourcedefinitions"] + verbs: ["get", "list", "watch"] + +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb/templates/debug/role-binding.yaml b/chart/kube-arangodb/templates/debug/role-binding.yaml new file mode 100644 index 000000000..b54d447cd --- /dev/null +++ b/chart/kube-arangodb/templates/debug/role-binding.yaml @@ -0,0 +1,25 @@ +{{ if .Values.rbac.enabled -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ template "kube-arangodb.rbac" . }}-debug + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ template "kube-arangodb.rbac" . }}-debug +subjects: + - kind: ServiceAccount + name: {{ template "kube-arangodb.operatorName" . }} + namespace: {{ .Release.Namespace }} + +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb/templates/debug/role.yaml b/chart/kube-arangodb/templates/debug/role.yaml new file mode 100644 index 000000000..1b05d2022 --- /dev/null +++ b/chart/kube-arangodb/templates/debug/role.yaml @@ -0,0 +1,29 @@ +{{ if .Values.rbac.enabled -}} +{{- if .Values.rbac.extensions.debug }} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ template "kube-arangodb.rbac" . }}-debug + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: {{ template "kube-arangodb.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + release: {{ .Release.Name }} +rules: + - apiGroups: + - "" + - "apps" + - "batch" + resources: ["*"] + verbs: ["get", "list"] + - apiGroups: [""] + resources: ["pods/log"] + verbs: ["get", "list"] + - apiGroups: [""] + resources: ["pods/exec"] + verbs: ["create"] +{{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/kube-arangodb/templates/deployment-operator/role.yaml b/chart/kube-arangodb/templates/deployment-operator/role.yaml index 375541f68..a3ca5bc75 100644 --- a/chart/kube-arangodb/templates/deployment-operator/role.yaml +++ b/chart/kube-arangodb/templates/deployment-operator/role.yaml @@ -44,17 +44,6 @@ rules: - apiGroups: ["backup.arangodb.com"] resources: ["arangobackuppolicies", "arangobackups"] verbs: ["get", "list", "watch"] -{{- if .Values.rbac.extensions.debug }} - - apiGroups: ["events.k8s.io"] - resources: ["pods/log"] - verbs: ["list"] - - apiGroups: [""] - resources: ["pods/log"] - verbs: ["get", "list"] - - apiGroups: [""] - resources: ["pods/exec"] - verbs: ["create"] -{{- end }} {{- if .Values.rbac.extensions.monitoring }} - apiGroups: ["monitoring.coreos.com"] resources: ["servicemonitors"] diff --git a/docs/cli/arangodb_operator_ops.md b/docs/cli/arangodb_operator_ops.md index 5a07af109..fe3961598 100644 --- a/docs/cli/arangodb_operator_ops.md +++ b/docs/cli/arangodb_operator_ops.md @@ -101,23 +101,41 @@ Usage: arangodb_operator_ops debug-package [flags] Flags: - --generator.agency-dump Define if generator agency-dump is enabled (default true) - --generator.analytics Define if generator analytics is enabled (default true) - --generator.backupBackup Define if generator backupBackup is enabled (default true) - --generator.deployments Define if generator deployments is enabled (default true) - --generator.kubernetes-configmaps Define if generator kubernetes-configmaps is enabled (default true) - --generator.kubernetes-events Define if generator kubernetes-events is enabled (default true) - --generator.kubernetes-pods Define if generator kubernetes-pods is enabled (default true) - --generator.kubernetes-secrets Define if generator kubernetes-secrets is enabled (default true) - --generator.kubernetes-services Define if generator kubernetes-services is enabled (default true) - --generator.ml Define if generator ml is enabled (default true) - --generator.networking Define if generator networking is enabled (default true) - --generator.platform Define if generator platform is enabled (default true) - --generator.scheduler Define if generator scheduler is enabled (default true) - -h, --help help for debug-package - --hide-sensitive-data Hide sensitive data (default true) - -n, --namespace string Kubernetes namespace (default "default") - -o, --output - Output of the result gz file. If set to - then stdout is used (default "out.tar.gz") - --pod-logs Collect pod logs (default true) + --generator.arango-analytics-gae Define if generator arango-analytics-gae is enabled (default true) + --generator.arango-backup-backup Define if generator arango-backup-backup is enabled (default true) + --generator.arango-backup-backuppolicy Define if generator arango-backup-backuppolicy is enabled (default true) + --generator.arango-database-acs Define if generator arango-database-acs is enabled (default true) + --generator.arango-database-deployment Define if generator arango-database-deployment is enabled (default true) + --generator.arango-database-member Define if generator arango-database-member is enabled (default true) + --generator.arango-database-task Define if generator arango-database-task is enabled (default true) + --generator.arango-ml-batchjob Define if generator arango-ml-batchjob is enabled (default true) + --generator.arango-ml-cronjob Define if generator arango-ml-cronjob is enabled (default true) + --generator.arango-ml-extension Define if generator arango-ml-extension is enabled (default true) + --generator.arango-ml-storage Define if generator arango-ml-storage is enabled (default true) + --generator.arango-networking-route Define if generator arango-networking-route is enabled (default true) + --generator.arango-platform-chart Define if generator arango-platform-chart is enabled (default true) + --generator.arango-platform-storage Define if generator arango-platform-storage is enabled (default true) + --generator.arango-scheduler-batchjob Define if generator arango-scheduler-batchjob is enabled (default true) + --generator.arango-scheduler-cronjob Define if generator arango-scheduler-cronjob is enabled (default true) + --generator.arango-scheduler-deployment Define if generator arango-scheduler-deployment is enabled (default true) + --generator.arango-scheduler-pod Define if generator arango-scheduler-pod is enabled (default true) + --generator.arango-scheduler-profile Define if generator arango-scheduler-profile is enabled (default true) + --generator.helm-releases Define if generator helm-releases is enabled (default true) + --generator.kubernetes-apps-deployment Define if generator kubernetes-apps-deployment is enabled (default true) + --generator.kubernetes-apps-replicaset Define if generator kubernetes-apps-replicaset is enabled (default true) + --generator.kubernetes-apps-statefulset Define if generator kubernetes-apps-statefulset is enabled (default true) + --generator.kubernetes-batch-cronjob Define if generator kubernetes-batch-cronjob is enabled (default true) + --generator.kubernetes-batch-job Define if generator kubernetes-batch-job is enabled (default true) + --generator.kubernetes-core-configmap Define if generator kubernetes-core-configmap is enabled (default true) + --generator.kubernetes-core-event Define if generator kubernetes-core-event is enabled (default true) + --generator.kubernetes-core-pod Define if generator kubernetes-core-pod is enabled (default true) + --generator.kubernetes-core-secret Define if generator kubernetes-core-secret is enabled (default true) + --generator.kubernetes-core-service Define if generator kubernetes-core-service is enabled (default true) + --generator.prometheus-monitoring Define if generator prometheus-monitoring is enabled (default true) + -h, --help help for debug-package + --hide-sensitive-data Hide sensitive data (default true) + -n, --namespace string Kubernetes namespace (default "default") + -o, --output - Output of the result gz file. If set to - then stdout is used (default "out.tar.gz") + --pod-logs Collect pod logs (default true) ``` [END_INJECT]: # (arangodb_operator_ops_cmd_debug_package) diff --git a/integrations/scheduler/v1/batch_job.go b/integrations/scheduler/v1/batch_job.go index c2316ea0e..1e58cf568 100644 --- a/integrations/scheduler/v1/batch_job.go +++ b/integrations/scheduler/v1/batch_job.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024-2025 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,11 +27,11 @@ import ( pbSchedulerV1 "github.com/arangodb/kube-arangodb/integrations/scheduler/v1/definition" 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/scheduler" "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" ) func (i *implementation) CreateBatchJob(ctx context.Context, request *pbSchedulerV1.CreateBatchJobRequest) (*pbSchedulerV1.CreateBatchJobResponse, error) { @@ -155,7 +155,7 @@ func (i *implementation) ListBatchJob(ctx context.Context, request *pbSchedulerV return nil, errors.Errorf("Request is nil") } - objects, err := kubernetes.ListObjects[*schedulerApi.ArangoSchedulerBatchJobList, *schedulerApi.ArangoSchedulerBatchJob](ctx, i.client.Arango().SchedulerV1beta1().ArangoSchedulerBatchJobs(i.cfg.Namespace), func(result *schedulerApi.ArangoSchedulerBatchJobList) []*schedulerApi.ArangoSchedulerBatchJob { + objects, err := list.ListObjects[*schedulerApi.ArangoSchedulerBatchJobList, *schedulerApi.ArangoSchedulerBatchJob](ctx, i.client.Arango().SchedulerV1beta1().ArangoSchedulerBatchJobs(i.cfg.Namespace), func(result *schedulerApi.ArangoSchedulerBatchJobList) []*schedulerApi.ArangoSchedulerBatchJob { r := make([]*schedulerApi.ArangoSchedulerBatchJob, len(result.Items)) for id := range result.Items { diff --git a/integrations/scheduler/v1/cron_job.go b/integrations/scheduler/v1/cron_job.go index 892d91d75..11d8af90f 100644 --- a/integrations/scheduler/v1/cron_job.go +++ b/integrations/scheduler/v1/cron_job.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024-2025 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,11 +28,11 @@ import ( pbSchedulerV1 "github.com/arangodb/kube-arangodb/integrations/scheduler/v1/definition" 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/scheduler" "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" ) func (i *implementation) CreateCronJob(ctx context.Context, request *pbSchedulerV1.CreateCronJobRequest) (*pbSchedulerV1.CreateCronJobResponse, error) { @@ -198,7 +198,7 @@ func (i *implementation) ListCronJob(ctx context.Context, request *pbSchedulerV1 return nil, errors.Errorf("Request is nil") } - objects, err := kubernetes.ListObjects[*schedulerApi.ArangoSchedulerCronJobList, *schedulerApi.ArangoSchedulerCronJob](ctx, i.client.Arango().SchedulerV1beta1().ArangoSchedulerCronJobs(i.cfg.Namespace), func(result *schedulerApi.ArangoSchedulerCronJobList) []*schedulerApi.ArangoSchedulerCronJob { + objects, err := list.ListObjects[*schedulerApi.ArangoSchedulerCronJobList, *schedulerApi.ArangoSchedulerCronJob](ctx, i.client.Arango().SchedulerV1beta1().ArangoSchedulerCronJobs(i.cfg.Namespace), func(result *schedulerApi.ArangoSchedulerCronJobList) []*schedulerApi.ArangoSchedulerCronJob { r := make([]*schedulerApi.ArangoSchedulerCronJob, len(result.Items)) for id := range result.Items { diff --git a/integrations/scheduler/v1/deployment.go b/integrations/scheduler/v1/deployment.go index f342c44c8..e0ac168e3 100644 --- a/integrations/scheduler/v1/deployment.go +++ b/integrations/scheduler/v1/deployment.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024-2025 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,11 +27,11 @@ import ( pbSchedulerV1 "github.com/arangodb/kube-arangodb/integrations/scheduler/v1/definition" 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/scheduler" "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" ) func (i *implementation) CreateDeployment(ctx context.Context, request *pbSchedulerV1.CreateDeploymentRequest) (*pbSchedulerV1.CreateDeploymentResponse, error) { @@ -159,7 +159,7 @@ func (i *implementation) ListDeployment(ctx context.Context, request *pbSchedule return nil, errors.Errorf("Request is nil") } - objects, err := kubernetes.ListObjects[*schedulerApi.ArangoSchedulerDeploymentList, *schedulerApi.ArangoSchedulerDeployment](ctx, i.client.Arango().SchedulerV1beta1().ArangoSchedulerDeployments(i.cfg.Namespace), func(result *schedulerApi.ArangoSchedulerDeploymentList) []*schedulerApi.ArangoSchedulerDeployment { + objects, err := list.ListObjects[*schedulerApi.ArangoSchedulerDeploymentList, *schedulerApi.ArangoSchedulerDeployment](ctx, i.client.Arango().SchedulerV1beta1().ArangoSchedulerDeployments(i.cfg.Namespace), func(result *schedulerApi.ArangoSchedulerDeploymentList) []*schedulerApi.ArangoSchedulerDeployment { r := make([]*schedulerApi.ArangoSchedulerDeployment, len(result.Items)) for id := range result.Items { diff --git a/pkg/debug_package/generator.go b/pkg/debug_package/generator.go index ab90e33b3..b3d98436d 100644 --- a/pkg/debug_package/generator.go +++ b/pkg/debug_package/generator.go @@ -30,25 +30,24 @@ import ( "github.com/spf13/cobra" "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" + "github.com/arangodb/kube-arangodb/pkg/debug_package/generators/arango" + "github.com/arangodb/kube-arangodb/pkg/debug_package/generators/helm" "github.com/arangodb/kube-arangodb/pkg/debug_package/generators/kubernetes" + "github.com/arangodb/kube-arangodb/pkg/debug_package/generators/prometheus" "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" "github.com/arangodb/kube-arangodb/pkg/util/errors" ) -var rootFactories = []shared.Factory{ - kubernetes.Events(), - kubernetes.Pods(), - kubernetes.Secrets(), - kubernetes.ConfigMaps(), - kubernetes.Services(), - kubernetes.Deployments(), - kubernetes.AgencyDump(), - kubernetes.ML(), - kubernetes.Analytics(), - kubernetes.Backup(), - kubernetes.Scheduler(), - kubernetes.Networking(), - kubernetes.Platform(), +var rootFactories []shared.Factory + +func init() { + // Collect all factories + rootFactories = shared.NewFactoryGen(). + Extend(kubernetes.Register). + Extend(arango.Register). + Extend(helm.Register). + Extend(prometheus.Register). + Get() } func InitCommand(cmd *cobra.Command) { diff --git a/pkg/debug_package/generators/arango/arango.go b/pkg/debug_package/generators/arango/arango.go new file mode 100644 index 000000000..8ff22baa8 --- /dev/null +++ b/pkg/debug_package/generators/arango/arango.go @@ -0,0 +1,34 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 arango + +import "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + +func Register(f shared.FactoryGen) { + f.AddSection("arango"). + Extend(Analytics). + Extend(Backup). + Extend(Database). + Extend(ML). + Extend(Networking). + Extend(Platform). + Extend(Scheduler) +} diff --git a/pkg/debug_package/generators/arango/arango_analytics.go b/pkg/debug_package/generators/arango/arango_analytics.go new file mode 100644 index 000000000..28a47db51 --- /dev/null +++ b/pkg/debug_package/generators/arango/arango_analytics.go @@ -0,0 +1,47 @@ +// +// DISCLAIMER +// +// Copyright 2023-2025 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 arango + +import ( + "context" + + analyticsApi "github.com/arangodb/kube-arangodb/pkg/apis/analytics/v1alpha1" + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func Analytics(f shared.FactoryGen) { + f.AddSection("analytics"). + Register("gae", true, shared.WithKubernetesItems[*analyticsApi.GraphAnalyticsEngine](arangoAnalyticsV1Alpha1GraphAnalyticsEngineList, shared.WithDefinitions[*analyticsApi.GraphAnalyticsEngine])) +} + +func arangoAnalyticsV1Alpha1GraphAnalyticsEngineList(ctx context.Context, client kclient.Client, namespace string) ([]*analyticsApi.GraphAnalyticsEngine, error) { + return list.ListObjects[*analyticsApi.GraphAnalyticsEngineList, *analyticsApi.GraphAnalyticsEngine](ctx, client.Arango().AnalyticsV1alpha1().GraphAnalyticsEngines(namespace), func(result *analyticsApi.GraphAnalyticsEngineList) []*analyticsApi.GraphAnalyticsEngine { + q := make([]*analyticsApi.GraphAnalyticsEngine, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} diff --git a/pkg/debug_package/generators/arango/arango_backup.go b/pkg/debug_package/generators/arango/arango_backup.go new file mode 100644 index 000000000..2a1f605ca --- /dev/null +++ b/pkg/debug_package/generators/arango/arango_backup.go @@ -0,0 +1,60 @@ +// +// DISCLAIMER +// +// Copyright 2024-2025 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 arango + +import ( + "context" + + v1 "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1" + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func Backup(f shared.FactoryGen) { + f.AddSection("backup"). + Register("backup", true, shared.WithKubernetesItems[*v1.ArangoBackup](arangoBackupV1ArangoBackupList, shared.WithDefinitions[*v1.ArangoBackup])). + Register("backuppolicy", true, shared.WithKubernetesItems[*v1.ArangoBackupPolicy](arangoBackupPolicyV1ArangoBackupPolicyList, shared.WithDefinitions[*v1.ArangoBackupPolicy])) +} + +func arangoBackupV1ArangoBackupList(ctx context.Context, client kclient.Client, namespace string) ([]*v1.ArangoBackup, error) { + return list.ListObjects[*v1.ArangoBackupList, *v1.ArangoBackup](ctx, client.Arango().BackupV1().ArangoBackups(namespace), func(result *v1.ArangoBackupList) []*v1.ArangoBackup { + q := make([]*v1.ArangoBackup, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoBackupPolicyV1ArangoBackupPolicyList(ctx context.Context, client kclient.Client, namespace string) ([]*v1.ArangoBackupPolicy, error) { + return list.ListObjects[*v1.ArangoBackupPolicyList, *v1.ArangoBackupPolicy](ctx, client.Arango().BackupV1().ArangoBackupPolicies(namespace), func(result *v1.ArangoBackupPolicyList) []*v1.ArangoBackupPolicy { + q := make([]*v1.ArangoBackupPolicy, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} diff --git a/pkg/debug_package/generators/arango/arango_database.go b/pkg/debug_package/generators/arango/arango_database.go new file mode 100644 index 000000000..db4e7f544 --- /dev/null +++ b/pkg/debug_package/generators/arango/arango_database.go @@ -0,0 +1,90 @@ +// +// DISCLAIMER +// +// Copyright 2023-2025 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 arango + +import ( + "context" + + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func Database(f shared.FactoryGen) { + f.AddSection("database"). + Register("deployment", true, shared.WithKubernetesItems[*api.ArangoDeployment](arangoDatabaseV1ArangoDeploymentList, + shared.WithDefinitions[*api.ArangoDeployment], + arangoDatabaseDeploymentMembers, + arangoDatabaseDeploymentAgencyDump, + arangoDatabaseDeploymentPlatform)). + Register("member", true, shared.WithKubernetesItems[*api.ArangoMember](arangoDatabaseV1ArangoMemberList, shared.WithDefinitions[*api.ArangoMember])). + Register("task", true, shared.WithKubernetesItems[*api.ArangoTask](arangoDatabaseV1ArangoTaskList, shared.WithDefinitions[*api.ArangoTask])). + Register("acs", true, shared.WithKubernetesItems[*api.ArangoClusterSynchronization](arangoDatabaseV1ArangoClusterSynchronizationList, shared.WithDefinitions[*api.ArangoClusterSynchronization])) +} + +func arangoDatabaseV1ArangoDeploymentList(ctx context.Context, client kclient.Client, namespace string) ([]*api.ArangoDeployment, error) { + return list.ListObjects[*api.ArangoDeploymentList, *api.ArangoDeployment](ctx, client.Arango().DatabaseV1().ArangoDeployments(namespace), func(result *api.ArangoDeploymentList) []*api.ArangoDeployment { + q := make([]*api.ArangoDeployment, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoDatabaseV1ArangoTaskList(ctx context.Context, client kclient.Client, namespace string) ([]*api.ArangoTask, error) { + return list.ListObjects[*api.ArangoTaskList, *api.ArangoTask](ctx, client.Arango().DatabaseV1().ArangoTasks(namespace), func(result *api.ArangoTaskList) []*api.ArangoTask { + q := make([]*api.ArangoTask, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoDatabaseV1ArangoMemberList(ctx context.Context, client kclient.Client, namespace string) ([]*api.ArangoMember, error) { + return list.ListObjects[*api.ArangoMemberList, *api.ArangoMember](ctx, client.Arango().DatabaseV1().ArangoMembers(namespace), func(result *api.ArangoMemberList) []*api.ArangoMember { + q := make([]*api.ArangoMember, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoDatabaseV1ArangoClusterSynchronizationList(ctx context.Context, client kclient.Client, namespace string) ([]*api.ArangoClusterSynchronization, error) { + return list.ListObjects[*api.ArangoClusterSynchronizationList, *api.ArangoClusterSynchronization](ctx, client.Arango().DatabaseV1().ArangoClusterSynchronizations(namespace), func(result *api.ArangoClusterSynchronizationList) []*api.ArangoClusterSynchronization { + q := make([]*api.ArangoClusterSynchronization, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} diff --git a/pkg/debug_package/generators/arango/arango_database_deployment.go b/pkg/debug_package/generators/arango/arango_database_deployment.go new file mode 100644 index 000000000..0441e0e64 --- /dev/null +++ b/pkg/debug_package/generators/arango/arango_database_deployment.go @@ -0,0 +1,152 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 arango + +import ( + "context" + "fmt" + + "github.com/rs/zerolog" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/yaml" + + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func arangoDatabaseDeploymentAgencyDump(ctx context.Context, logger zerolog.Logger, client kclient.Client, files chan<- shared.File, item *api.ArangoDeployment) error { + if !item.Spec.GetMode().HasAgents() { + return nil + } + + handler, err := shared.DiscoverExecFunc() + if err != nil { + return err + } + + files, c := shared.WithPrefix(files, "agency/") + defer c() + + files <- shared.NewFile("dump.json", func() ([]byte, error) { + out, _, err := handler(logger, "admin", "agency", "dump", "-d", item.GetName()) + + if err != nil { + return nil, err + } + + return out, nil + }) + + files <- shared.NewFile("state.json", func() ([]byte, error) { + out, _, err := handler(logger, "admin", "agency", "state", "-d", item.GetName()) + + if err != nil { + return nil, err + } + + return out, nil + }) + + return nil +} + +func arangoDatabaseDeploymentMembers(ctx context.Context, logger zerolog.Logger, client kclient.Client, files chan<- shared.File, item *api.ArangoDeployment) error { + files, c := shared.WithPrefix(files, "members/") + defer c() + + for _, member := range item.Status.Members.AsList() { + mName := member.Member.ArangoMemberName(item.GetName(), member.Group) + + arangoMember, err := client.Arango().DatabaseV1().ArangoMembers(item.GetNamespace()).Get(ctx, mName, meta.GetOptions{}) + if err != nil { + logger.Err(err).Msgf("Unable to get member") + continue + } + + files <- shared.NewYAMLFile(fmt.Sprintf("%s.yaml", arangoMember.GetName()), func() ([]interface{}, error) { + return []interface{}{arangoMember}, nil + }) + + switch member.Group.Type() { + case api.ServerGroupTypeArangoD: + if err := arangoDeploymentMemberArangoD(logger, files, item, member); err != nil { + return err + } + } + } + + return nil +} + +func arangoDeploymentMemberArangoD(logger zerolog.Logger, files chan<- shared.File, item *api.ArangoDeployment, member api.DeploymentStatusMemberElement) error { + files, c := shared.WithPrefix(files, "%s/", member.Member.ID) + defer c() + + files <- shared.NewFile("async-registry.json", shared.GenerateDataFuncP2(func(depl, member string) ([]byte, error) { + handler, err := shared.DiscoverExecFunc() + if err != nil { + return nil, err + } + + out, _, err := handler(logger, "admin", "member", "request", "get", "-d", depl, "-m", member, "_admin", "async-registry") + + if err != nil { + return nil, err + } + + return out, nil + }, item.GetName(), member.Member.ID)) + + files <- shared.NewFile("stack", shared.GenerateDataFuncP2(func(depl, pod string) ([]byte, error) { + handler, err := shared.RemoteExecFunc("/usr/bin/eu-stack", pod, "server") + if err != nil { + return nil, err + } + + out, _, err := handler(logger, "-n32", "-p1") + + if err != nil { + return nil, err + } + + return out, nil + }, item.GetName(), member.Member.PodName)) + + return nil +} + +func arangoDatabaseDeploymentPlatform(ctx context.Context, logger zerolog.Logger, client kclient.Client, files chan<- shared.File, item *api.ArangoDeployment) error { + files, c := shared.WithPrefix(files, "platform/") + defer c() + + files <- shared.NewFile("package.yaml", func() ([]byte, error) { + p, err := helm.NewPackage(ctx, client, item.GetNamespace(), item.GetName()) + if err != nil { + return nil, err + } + + return yaml.Marshal(p) + }) + + return nil +} diff --git a/pkg/debug_package/generators/arango/arango_ml.go b/pkg/debug_package/generators/arango/arango_ml.go new file mode 100644 index 000000000..0900a869d --- /dev/null +++ b/pkg/debug_package/generators/arango/arango_ml.go @@ -0,0 +1,87 @@ +// +// DISCLAIMER +// +// Copyright 2023-2025 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 arango + +import ( + "context" + + mlApiv1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1alpha1" + mlApi "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1beta1" + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func ML(f shared.FactoryGen) { + f.AddSection("ml"). + Register("batchjob", true, shared.WithKubernetesItems[*mlApiv1alpha1.ArangoMLBatchJob](arangoMLV1Alpha1ArangoMLBatchJobList, shared.WithDefinitions[*mlApiv1alpha1.ArangoMLBatchJob])). + Register("cronjob", true, shared.WithKubernetesItems[*mlApiv1alpha1.ArangoMLCronJob](arangoMLV1Alpha1ArangoMLCronJobList, shared.WithDefinitions[*mlApiv1alpha1.ArangoMLCronJob])). + Register("extension", true, shared.WithKubernetesItems[*mlApi.ArangoMLExtension](arangoMLV1Beta1ArangoMLExtensionList, shared.WithDefinitions[*mlApi.ArangoMLExtension])). + Register("storage", true, shared.WithKubernetesItems[*mlApi.ArangoMLStorage](arangoMLV1Beta1ArangoMLStorageList, shared.WithDefinitions[*mlApi.ArangoMLStorage])) +} + +func arangoMLV1Alpha1ArangoMLBatchJobList(ctx context.Context, client kclient.Client, namespace string) ([]*mlApiv1alpha1.ArangoMLBatchJob, error) { + return list.ListObjects[*mlApiv1alpha1.ArangoMLBatchJobList, *mlApiv1alpha1.ArangoMLBatchJob](ctx, client.Arango().MlV1alpha1().ArangoMLBatchJobs(namespace), func(result *mlApiv1alpha1.ArangoMLBatchJobList) []*mlApiv1alpha1.ArangoMLBatchJob { + q := make([]*mlApiv1alpha1.ArangoMLBatchJob, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoMLV1Alpha1ArangoMLCronJobList(ctx context.Context, client kclient.Client, namespace string) ([]*mlApiv1alpha1.ArangoMLCronJob, error) { + return list.ListObjects[*mlApiv1alpha1.ArangoMLCronJobList, *mlApiv1alpha1.ArangoMLCronJob](ctx, client.Arango().MlV1alpha1().ArangoMLCronJobs(namespace), func(result *mlApiv1alpha1.ArangoMLCronJobList) []*mlApiv1alpha1.ArangoMLCronJob { + q := make([]*mlApiv1alpha1.ArangoMLCronJob, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoMLV1Beta1ArangoMLExtensionList(ctx context.Context, client kclient.Client, namespace string) ([]*mlApi.ArangoMLExtension, error) { + return list.ListObjects[*mlApi.ArangoMLExtensionList, *mlApi.ArangoMLExtension](ctx, client.Arango().MlV1beta1().ArangoMLExtensions(namespace), func(result *mlApi.ArangoMLExtensionList) []*mlApi.ArangoMLExtension { + q := make([]*mlApi.ArangoMLExtension, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoMLV1Beta1ArangoMLStorageList(ctx context.Context, client kclient.Client, namespace string) ([]*mlApi.ArangoMLStorage, error) { + return list.ListObjects[*mlApi.ArangoMLStorageList, *mlApi.ArangoMLStorage](ctx, client.Arango().MlV1beta1().ArangoMLStorages(namespace), func(result *mlApi.ArangoMLStorageList) []*mlApi.ArangoMLStorage { + q := make([]*mlApi.ArangoMLStorage, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} diff --git a/pkg/debug_package/generators/arango/arango_networking.go b/pkg/debug_package/generators/arango/arango_networking.go new file mode 100644 index 000000000..bac2abb62 --- /dev/null +++ b/pkg/debug_package/generators/arango/arango_networking.go @@ -0,0 +1,47 @@ +// +// DISCLAIMER +// +// Copyright 2024-2025 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 arango + +import ( + "context" + + networkingApi "github.com/arangodb/kube-arangodb/pkg/apis/networking/v1alpha1" + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func Networking(f shared.FactoryGen) { + f.AddSection("networking"). + Register("route", true, shared.WithKubernetesItems[*networkingApi.ArangoRoute](arangoNetworkingV1Alpha1ArangoRouteList, shared.WithDefinitions[*networkingApi.ArangoRoute])) +} + +func arangoNetworkingV1Alpha1ArangoRouteList(ctx context.Context, client kclient.Client, namespace string) ([]*networkingApi.ArangoRoute, error) { + return list.ListObjects[*networkingApi.ArangoRouteList, *networkingApi.ArangoRoute](ctx, client.Arango().NetworkingV1alpha1().ArangoRoutes(namespace), func(result *networkingApi.ArangoRouteList) []*networkingApi.ArangoRoute { + q := make([]*networkingApi.ArangoRoute, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} diff --git a/pkg/debug_package/generators/arango/arango_platform.go b/pkg/debug_package/generators/arango/arango_platform.go new file mode 100644 index 000000000..9315d5a1f --- /dev/null +++ b/pkg/debug_package/generators/arango/arango_platform.go @@ -0,0 +1,60 @@ +// +// DISCLAIMER +// +// Copyright 2024-2025 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 arango + +import ( + "context" + + platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1" + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func Platform(f shared.FactoryGen) { + f.AddSection("platform"). + Register("storage", true, shared.WithKubernetesItems[*platformApi.ArangoPlatformStorage](arangoPlatformV1Alpha1ArangoPlatformStorageList, shared.WithDefinitions[*platformApi.ArangoPlatformStorage])). + Register("chart", true, shared.WithKubernetesItems[*platformApi.ArangoPlatformChart](arangoPlatformV1Alpha1ArangoPlatformChartList, shared.WithDefinitions[*platformApi.ArangoPlatformChart], arangoPlatformV1Alpha1ArangoPlatformChartExtract)) +} + +func arangoPlatformV1Alpha1ArangoPlatformStorageList(ctx context.Context, client kclient.Client, namespace string) ([]*platformApi.ArangoPlatformStorage, error) { + return list.ListObjects[*platformApi.ArangoPlatformStorageList, *platformApi.ArangoPlatformStorage](ctx, client.Arango().PlatformV1alpha1().ArangoPlatformStorages(namespace), func(result *platformApi.ArangoPlatformStorageList) []*platformApi.ArangoPlatformStorage { + q := make([]*platformApi.ArangoPlatformStorage, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoPlatformV1Alpha1ArangoPlatformChartList(ctx context.Context, client kclient.Client, namespace string) ([]*platformApi.ArangoPlatformChart, error) { + return list.ListObjects[*platformApi.ArangoPlatformChartList, *platformApi.ArangoPlatformChart](ctx, client.Arango().PlatformV1alpha1().ArangoPlatformCharts(namespace), func(result *platformApi.ArangoPlatformChartList) []*platformApi.ArangoPlatformChart { + q := make([]*platformApi.ArangoPlatformChart, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} diff --git a/pkg/debug_package/generators/kubernetes/arango_networking.go b/pkg/debug_package/generators/arango/arango_platform_charts.go similarity index 58% rename from pkg/debug_package/generators/kubernetes/arango_networking.go rename to pkg/debug_package/generators/arango/arango_platform_charts.go index 8837b089b..6edd1dbb0 100644 --- a/pkg/debug_package/generators/kubernetes/arango_networking.go +++ b/pkg/debug_package/generators/arango/arango_platform_charts.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2025 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,29 +18,28 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package kubernetes +package arango import ( + "context" + "fmt" + "github.com/rs/zerolog" + platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1" "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/kclient" ) -func Networking() shared.Factory { - return shared.NewFactory("networking", true, networking) -} - -func networking(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - if err := networkingArangoRoutes(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting networking arango routes") - return err +func arangoPlatformV1Alpha1ArangoPlatformChartExtract(ctx context.Context, logger zerolog.Logger, client kclient.Client, files chan<- shared.File, item *platformApi.ArangoPlatformChart) error { + if i := item.Status.Info; i != nil { + if i.Valid { + if d := i.Details; d != nil { + files <- shared.NewFile(fmt.Sprintf("%s-%s.tgz", d.Name, d.Version), func() ([]byte, error) { + return i.Definition, nil + }) + } + } } return nil diff --git a/pkg/debug_package/generators/arango/arango_scheduler.go b/pkg/debug_package/generators/arango/arango_scheduler.go new file mode 100644 index 000000000..92a5cfa97 --- /dev/null +++ b/pkg/debug_package/generators/arango/arango_scheduler.go @@ -0,0 +1,99 @@ +// +// DISCLAIMER +// +// Copyright 2023-2025 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 arango + +import ( + "context" + + schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func Scheduler(f shared.FactoryGen) { + f.AddSection("scheduler"). + Register("profile", true, shared.WithKubernetesItems[*schedulerApi.ArangoProfile](arangoSchedulerV1Beta1ArangoProfileList, shared.WithDefinitions[*schedulerApi.ArangoProfile])). + Register("batchjob", true, shared.WithKubernetesItems[*schedulerApi.ArangoSchedulerBatchJob](arangoSchedulerV1Beta1ArangoSchedulerBatchJobList, shared.WithDefinitions[*schedulerApi.ArangoSchedulerBatchJob])). + Register("cronjob", true, shared.WithKubernetesItems[*schedulerApi.ArangoSchedulerCronJob](arangoSchedulerV1Beta1ArangoSchedulerCronJobList, shared.WithDefinitions[*schedulerApi.ArangoSchedulerCronJob])). + Register("deployment", true, shared.WithKubernetesItems[*schedulerApi.ArangoSchedulerDeployment](arangoSchedulerV1Beta1ArangoSchedulerDeploymentList, shared.WithDefinitions[*schedulerApi.ArangoSchedulerDeployment])). + Register("pod", true, shared.WithKubernetesItems[*schedulerApi.ArangoSchedulerPod](arangoSchedulerV1Beta1ArangoSchedulerPodList, shared.WithDefinitions[*schedulerApi.ArangoSchedulerPod])) +} + +func arangoSchedulerV1Beta1ArangoProfileList(ctx context.Context, client kclient.Client, namespace string) ([]*schedulerApi.ArangoProfile, error) { + return list.ListObjects[*schedulerApi.ArangoProfileList, *schedulerApi.ArangoProfile](ctx, client.Arango().SchedulerV1beta1().ArangoProfiles(namespace), func(result *schedulerApi.ArangoProfileList) []*schedulerApi.ArangoProfile { + q := make([]*schedulerApi.ArangoProfile, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoSchedulerV1Beta1ArangoSchedulerBatchJobList(ctx context.Context, client kclient.Client, namespace string) ([]*schedulerApi.ArangoSchedulerBatchJob, error) { + return list.ListObjects[*schedulerApi.ArangoSchedulerBatchJobList, *schedulerApi.ArangoSchedulerBatchJob](ctx, client.Arango().SchedulerV1beta1().ArangoSchedulerBatchJobs(namespace), func(result *schedulerApi.ArangoSchedulerBatchJobList) []*schedulerApi.ArangoSchedulerBatchJob { + q := make([]*schedulerApi.ArangoSchedulerBatchJob, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoSchedulerV1Beta1ArangoSchedulerCronJobList(ctx context.Context, client kclient.Client, namespace string) ([]*schedulerApi.ArangoSchedulerCronJob, error) { + return list.ListObjects[*schedulerApi.ArangoSchedulerCronJobList, *schedulerApi.ArangoSchedulerCronJob](ctx, client.Arango().SchedulerV1beta1().ArangoSchedulerCronJobs(namespace), func(result *schedulerApi.ArangoSchedulerCronJobList) []*schedulerApi.ArangoSchedulerCronJob { + q := make([]*schedulerApi.ArangoSchedulerCronJob, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoSchedulerV1Beta1ArangoSchedulerDeploymentList(ctx context.Context, client kclient.Client, namespace string) ([]*schedulerApi.ArangoSchedulerDeployment, error) { + return list.ListObjects[*schedulerApi.ArangoSchedulerDeploymentList, *schedulerApi.ArangoSchedulerDeployment](ctx, client.Arango().SchedulerV1beta1().ArangoSchedulerDeployments(namespace), func(result *schedulerApi.ArangoSchedulerDeploymentList) []*schedulerApi.ArangoSchedulerDeployment { + q := make([]*schedulerApi.ArangoSchedulerDeployment, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func arangoSchedulerV1Beta1ArangoSchedulerPodList(ctx context.Context, client kclient.Client, namespace string) ([]*schedulerApi.ArangoSchedulerPod, error) { + return list.ListObjects[*schedulerApi.ArangoSchedulerPodList, *schedulerApi.ArangoSchedulerPod](ctx, client.Arango().SchedulerV1beta1().ArangoSchedulerPods(namespace), func(result *schedulerApi.ArangoSchedulerPodList) []*schedulerApi.ArangoSchedulerPod { + q := make([]*schedulerApi.ArangoSchedulerPod, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} diff --git a/pkg/debug_package/generators/helm/helm.go b/pkg/debug_package/generators/helm/helm.go new file mode 100644 index 000000000..69a87c5ba --- /dev/null +++ b/pkg/debug_package/generators/helm/helm.go @@ -0,0 +1,83 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 helm + +import ( + "github.com/rs/zerolog" + "helm.sh/helm/v3/pkg/action" + + "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/errors" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" + "github.com/arangodb/kube-arangodb/pkg/util/shutdown" +) + +func Register(f shared.FactoryGen) { + f.AddSection("helm"). + Register("releases", true, helmReleases) +} + +func helmReleases(logger zerolog.Logger, files chan<- shared.File) error { + client, ok := kclient.GetDefaultFactory().Client() + if !ok { + return errors.Errorf("Client is not initialised") + } + + hclient, err := helm.NewClient(helm.Configuration{ + Namespace: cli.GetInput().Namespace, + Config: client.Config(), + Driver: nil, + }) + if err != nil { + return err + } + + files, c := shared.WithPrefix(files, "helm/") + defer c() + + existingReleases, err := hclient.List(shutdown.Context(), func(in *action.List) { + in.All = true + }) + if err != nil { + return err + } + + for _, release := range existingReleases { + if err := helmRelease(files, release); err != nil { + return err + } + } + + return nil +} + +func helmRelease(files chan<- shared.File, release helm.Release) error { + files, c := shared.WithPrefix(files, "%s/", release.Name) + defer c() + + files <- shared.NewYAMLFile("release.yaml", func() ([]helm.Release, error) { + return []helm.Release{release}, nil + }) + + return nil +} diff --git a/pkg/debug_package/generators/kubernetes/agency.go b/pkg/debug_package/generators/kubernetes/agency.go deleted file mode 100644 index 3c60dc5ff..000000000 --- a/pkg/debug_package/generators/kubernetes/agency.go +++ /dev/null @@ -1,193 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023-2025 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 kubernetes - -import ( - "bytes" - "fmt" - "os" - "os/exec" - - "github.com/rs/zerolog" - - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" - "github.com/arangodb/kube-arangodb/pkg/util/shutdown" -) - -const LocalBinDir = "/usr/bin/arangodb_operator" - -func AgencyDump() shared.Factory { - return shared.NewFactory("agency-dump", true, agencyDump) -} - -func agencyDump(logger zerolog.Logger, files chan<- shared.File) error { - ef, err := discoverExecFunc() - if err != nil { - return err - } - - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - deployments, err := listArangoDeployments(k.Arango())() - if err != nil { - return err - } - - for _, deployment := range deployments { - if !deployment.GetAcceptedSpec().Mode.HasAgents() { - continue - } - - NewDeploymentAgencyInfo(logger, files, deployment.GetName(), ef) - } - - return nil -} - -func NewDeploymentAgencyInfo(logger zerolog.Logger, out chan<- shared.File, name string, handler ArangoOperatorExecFunc) { - out <- shared.NewFile(fmt.Sprintf("kubernetes/arango/deployments/%s/agency/dump.json", name), func() ([]byte, error) { - out, _, err := handler(logger, "admin", "agency", "dump", "-d", name) - - if err != nil { - return nil, err - } - - return out, nil - }) - - out <- shared.NewFile(fmt.Sprintf("kubernetes/arango/deployments/%s/agency/state.json", name), func() ([]byte, error) { - out, _, err := handler(logger, "admin", "agency", "state", "-d", name) - - if err != nil { - return nil, err - } - - return out, nil - }) -} - -type ArangoOperatorExecFunc func(logger zerolog.Logger, args ...string) ([]byte, []byte, error) - -func discoverExecFunc() (ArangoOperatorExecFunc, error) { - if _, err := os.Stat(LocalBinDir); err != nil { - if !os.IsNotExist(err) { - return nil, err - } - - return remoteOperatorExecFunc(LocalBinDir) - } else { - return localExecFunc(LocalBinDir) - } -} - -func localExecFunc(binary string) (ArangoOperatorExecFunc, error) { - return func(logger zerolog.Logger, args ...string) ([]byte, []byte, error) { - logger.Debug().Str("binary", binary).Strs("args", args).Msgf("Executing remote command") - - cmd := exec.Command(binary, args...) - var stderr, stdout bytes.Buffer - - cmd.Stdout = &stdout - cmd.Stderr = &stderr - - err := cmd.Run() - - return stdout.Bytes(), stderr.Bytes(), err - }, nil -} - -func remoteOperatorExecFunc(binary string) (ArangoOperatorExecFunc, error) { - id, err := discoverOperatorPod(binary) - if err != nil { - return nil, err - } - - return remoteExecFunc(binary, id, "operator") -} - -func discoverOperatorPod(binary string) (string, error) { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return "", errors.Errorf("Client is not initialised") - } - - pods, err := listPods(k.Kubernetes())() - if err != nil { - return "", err - } - - var id string - - for _, v := range pods { - if id != "" { - break - } - - for _, container := range v.Spec.Containers { - if container.Name != "operator" { - continue - } - - var stderr, stdout bytes.Buffer - - if err := shared.ExecuteCommandInPod(shutdown.Context(), k, "operator", v.GetName(), v.GetNamespace(), []string{binary, "version"}, nil, &stdout, &stderr); err != nil { - continue - } - - id = v.GetName() - } - } - - if id == "" { - return "", errors.Errorf("Unable to find Operator pod") - } - - return id, nil -} - -func remoteExecFunc(binary, pod, container string) (ArangoOperatorExecFunc, error) { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return nil, errors.Errorf("Client is not initialised") - } - - return func(logger zerolog.Logger, args ...string) ([]byte, []byte, error) { - var stderr, stdout bytes.Buffer - - in := make([]string, len(args)+1) - in[0] = binary - for id := range args { - in[id+1] = args[id] - } - - logger.Debug().Str("binary", binary).Strs("args", args).Str("namespace", cli.GetInput().Namespace).Str("container", container).Str("pod", pod).Msgf("Executing remote command") - - err := shared.ExecuteCommandInPod(shutdown.Context(), k, container, pod, cli.GetInput().Namespace, in, nil, &stdout, &stderr) - - return stdout.Bytes(), stderr.Bytes(), err - }, nil -} diff --git a/pkg/debug_package/generators/kubernetes/analytics_gae.go b/pkg/debug_package/generators/kubernetes/analytics_gae.go deleted file mode 100644 index 6937d332b..000000000 --- a/pkg/debug_package/generators/kubernetes/analytics_gae.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - analyticsApi "github.com/arangodb/kube-arangodb/pkg/apis/analytics/v1alpha1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func analyticsGAEs(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - extensions, err := listAnalyticsGAEs(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(analyticsGAE, client, files, extensions...); err != nil { - logger.Err(err).Msgf("Error while collecting arango ml extensions") - return err - } - - return nil -} - -func analyticsGAE(client kclient.Client, files chan<- shared.File, ext *analyticsApi.GraphAnalyticsEngine) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/analytics/gaes/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listAnalyticsGAEs(client kclient.Client) ([]*analyticsApi.GraphAnalyticsEngine, error) { - return ListObjects[*analyticsApi.GraphAnalyticsEngineList, *analyticsApi.GraphAnalyticsEngine](context.Background(), client.Arango().AnalyticsV1alpha1().GraphAnalyticsEngines(cli.GetInput().Namespace), func(result *analyticsApi.GraphAnalyticsEngineList) []*analyticsApi.GraphAnalyticsEngine { - q := make([]*analyticsApi.GraphAnalyticsEngine, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_backup.go b/pkg/debug_package/generators/kubernetes/arango_backup.go deleted file mode 100644 index fa2b52a4d..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_backup.go +++ /dev/null @@ -1,52 +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 kubernetes - -import ( - "github.com/rs/zerolog" - - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func Backup() shared.Factory { - return shared.NewFactory("backupBackup", true, backup) -} - -func backup(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - if err := backupBackups(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango backup") - return err - } - - if err := backupPolicies(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango backup policye") - return err - } - - return nil -} diff --git a/pkg/debug_package/generators/kubernetes/arango_backup_backup.go b/pkg/debug_package/generators/kubernetes/arango_backup_backup.go deleted file mode 100644 index 368bb3141..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_backup_backup.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func backupBackups(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - backups, err := listBackupBackups(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(backupBackup, client, files, backups...); err != nil { - logger.Err(err).Msgf("Error while collecting arango ml batchjobs") - return err - } - - return nil -} - -func backupBackup(client kclient.Client, files chan<- shared.File, ext *backupApi.ArangoBackup) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/backup/backups/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listBackupBackups(client kclient.Client) ([]*backupApi.ArangoBackup, error) { - return ListObjects[*backupApi.ArangoBackupList, *backupApi.ArangoBackup](context.Background(), client.Arango().BackupV1().ArangoBackups(cli.GetInput().Namespace), func(result *backupApi.ArangoBackupList) []*backupApi.ArangoBackup { - q := make([]*backupApi.ArangoBackup, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_backup_policy.go b/pkg/debug_package/generators/kubernetes/arango_backup_policy.go deleted file mode 100644 index 8a2fc390a..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_backup_policy.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func backupPolicies(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - backups, err := listBackupPolicies(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(backupPolicy, client, files, backups...); err != nil { - logger.Err(err).Msgf("Error while collecting arango ml batchjobs") - return err - } - - return nil -} - -func backupPolicy(client kclient.Client, files chan<- shared.File, ext *backupApi.ArangoBackupPolicy) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/backup/policies/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listBackupPolicies(client kclient.Client) ([]*backupApi.ArangoBackupPolicy, error) { - return ListObjects[*backupApi.ArangoBackupPolicyList, *backupApi.ArangoBackupPolicy](context.Background(), client.Arango().BackupV1().ArangoBackupPolicies(cli.GetInput().Namespace), func(result *backupApi.ArangoBackupPolicyList) []*backupApi.ArangoBackupPolicy { - q := make([]*backupApi.ArangoBackupPolicy, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_deployments.go b/pkg/debug_package/generators/kubernetes/arango_deployments.go deleted file mode 100644 index f2089c083..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_deployments.go +++ /dev/null @@ -1,133 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023-2025 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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - arangoClient "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func Deployments() shared.Factory { - return shared.NewFactory("deployments", true, deployments) -} - -func listArangoDeployments(client arangoClient.Interface) func() ([]*api.ArangoDeployment, error) { - return func() ([]*api.ArangoDeployment, error) { - return ListObjects[*api.ArangoDeploymentList, *api.ArangoDeployment](context.Background(), client.DatabaseV1().ArangoDeployments(cli.GetInput().Namespace), func(result *api.ArangoDeploymentList) []*api.ArangoDeployment { - q := make([]*api.ArangoDeployment, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) - } -} - -func deployments(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - deploymentList, err := listArangoDeployments(k.Arango())() - if err != nil { - return err - } - - if err := errors.ExecuteWithErrorArrayP3(deployment, logger, k, files, deploymentList...); err != nil { - logger.Err(err).Msgf("Error while collecting arango deployments") - return err - } - - return nil -} - -func deployment(logger zerolog.Logger, client kclient.Client, files chan<- shared.File, depl *api.ArangoDeployment) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/deployments/%s.yaml", depl.GetName()), func() ([]interface{}, error) { - return []interface{}{depl}, nil - }) - - if err := deploymentMembers(logger, client, depl, files); err != nil { - return err - } - - return nil -} - -func deploymentMembers(logger zerolog.Logger, client kclient.Client, depl *api.ArangoDeployment, files chan<- shared.File) error { - for _, member := range depl.Status.Members.AsList() { - mName := member.Member.ArangoMemberName(depl.GetName(), member.Group) - - arangoMember, err := client.Arango().DatabaseV1().ArangoMembers(cli.GetInput().Namespace).Get(context.Background(), mName, meta.GetOptions{}) - if err != nil { - return err - } - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/deployments/%s/members/%s.yaml", depl.GetName(), arangoMember.GetName()), func() ([]interface{}, error) { - return []interface{}{arangoMember}, nil - }) - - if member.Group.IsArangod() { - files <- shared.NewFile(fmt.Sprintf("kubernetes/arango/deployments/%s/members/%s/async-registry.json", depl.GetName(), arangoMember.GetName()), shared.GenerateDataFuncP2(func(depl, member string) ([]byte, error) { - handler, err := discoverExecFunc() - if err != nil { - return nil, err - } - - out, _, err := handler(logger, "admin", "member", "request", "get", "-d", depl, "-m", member, "_admin", "async-registry") - - if err != nil { - return nil, err - } - - return out, nil - }, depl.GetName(), member.Member.ID)) - - files <- shared.NewFile(fmt.Sprintf("kubernetes/arango/deployments/%s/members/%s/stack", depl.GetName(), arangoMember.GetName()), shared.GenerateDataFuncP2(func(depl, pod string) ([]byte, error) { - handler, err := remoteExecFunc("/usr/bin/eu-stack", pod, "server") - if err != nil { - return nil, err - } - - out, _, err := handler(logger, "-n32", "-p1") - - if err != nil { - return nil, err - } - - return out, nil - }, depl.GetName(), member.Member.PodName)) - } - } - - return nil -} diff --git a/pkg/debug_package/generators/kubernetes/arango_ml.go b/pkg/debug_package/generators/kubernetes/arango_ml.go deleted file mode 100644 index b10ca72ca..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_ml.go +++ /dev/null @@ -1,62 +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 kubernetes - -import ( - "github.com/rs/zerolog" - - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func ML() shared.Factory { - return shared.NewFactory("ml", true, ml) -} - -func ml(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - if err := mlExtensions(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango ml extension") - return err - } - - if err := mlStorages(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango ml storage") - return err - } - - if err := mlBatchJobs(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango ml batch jobs") - return err - } - - if err := mlCronJobs(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango ml cron jobs") - return err - } - - return nil -} diff --git a/pkg/debug_package/generators/kubernetes/arango_ml_batch_job.go b/pkg/debug_package/generators/kubernetes/arango_ml_batch_job.go deleted file mode 100644 index 25752a478..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_ml_batch_job.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - mlApiv1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1alpha1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func mlBatchJobs(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - batchjobs, err := listMLBatchJobs(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(mlBatchJob, client, files, batchjobs...); err != nil { - logger.Err(err).Msgf("Error while collecting arango ml batchjobs") - return err - } - - return nil -} - -func mlBatchJob(client kclient.Client, files chan<- shared.File, ext *mlApiv1alpha1.ArangoMLBatchJob) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/ml/batchjobs/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listMLBatchJobs(client kclient.Client) ([]*mlApiv1alpha1.ArangoMLBatchJob, error) { - return ListObjects[*mlApiv1alpha1.ArangoMLBatchJobList, *mlApiv1alpha1.ArangoMLBatchJob](context.Background(), client.Arango().MlV1alpha1().ArangoMLBatchJobs(cli.GetInput().Namespace), func(result *mlApiv1alpha1.ArangoMLBatchJobList) []*mlApiv1alpha1.ArangoMLBatchJob { - q := make([]*mlApiv1alpha1.ArangoMLBatchJob, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_ml_cron_job.go b/pkg/debug_package/generators/kubernetes/arango_ml_cron_job.go deleted file mode 100644 index 5051aa1e8..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_ml_cron_job.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - mlApiv1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1alpha1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func mlCronJobs(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - cronjobs, err := listMLCronJobs(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(mlCronJob, client, files, cronjobs...); err != nil { - logger.Err(err).Msgf("Error while collecting arango ml cronjobs") - return err - } - - return nil -} - -func mlCronJob(client kclient.Client, files chan<- shared.File, ext *mlApiv1alpha1.ArangoMLCronJob) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/ml/cronjobs/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listMLCronJobs(client kclient.Client) ([]*mlApiv1alpha1.ArangoMLCronJob, error) { - return ListObjects[*mlApiv1alpha1.ArangoMLCronJobList, *mlApiv1alpha1.ArangoMLCronJob](context.Background(), client.Arango().MlV1alpha1().ArangoMLCronJobs(cli.GetInput().Namespace), func(result *mlApiv1alpha1.ArangoMLCronJobList) []*mlApiv1alpha1.ArangoMLCronJob { - q := make([]*mlApiv1alpha1.ArangoMLCronJob, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_ml_extension.go b/pkg/debug_package/generators/kubernetes/arango_ml_extension.go deleted file mode 100644 index 6cb523c4c..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_ml_extension.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - mlApi "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func mlExtensions(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - extensions, err := listMLExtensions(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(mlExtension, client, files, extensions...); err != nil { - logger.Err(err).Msgf("Error while collecting arango ml extensions") - return err - } - - return nil -} - -func mlExtension(client kclient.Client, files chan<- shared.File, ext *mlApi.ArangoMLExtension) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/ml/extensions/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listMLExtensions(client kclient.Client) ([]*mlApi.ArangoMLExtension, error) { - return ListObjects[*mlApi.ArangoMLExtensionList, *mlApi.ArangoMLExtension](context.Background(), client.Arango().MlV1beta1().ArangoMLExtensions(cli.GetInput().Namespace), func(result *mlApi.ArangoMLExtensionList) []*mlApi.ArangoMLExtension { - q := make([]*mlApi.ArangoMLExtension, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_ml_storage.go b/pkg/debug_package/generators/kubernetes/arango_ml_storage.go deleted file mode 100644 index 5a7c0f6d2..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_ml_storage.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - mlApi "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func mlStorages(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - storages, err := listMLStorages(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(mlStorage, client, files, storages...); err != nil { - logger.Err(err).Msgf("Error while collecting arango ml storages") - return err - } - - return nil -} - -func mlStorage(client kclient.Client, files chan<- shared.File, ext *mlApi.ArangoMLStorage) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/ml/storages/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listMLStorages(client kclient.Client) ([]*mlApi.ArangoMLStorage, error) { - return ListObjects[*mlApi.ArangoMLStorageList, *mlApi.ArangoMLStorage](context.Background(), client.Arango().MlV1beta1().ArangoMLStorages(cli.GetInput().Namespace), func(result *mlApi.ArangoMLStorageList) []*mlApi.ArangoMLStorage { - q := make([]*mlApi.ArangoMLStorage, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_networking_ar.go b/pkg/debug_package/generators/kubernetes/arango_networking_ar.go deleted file mode 100644 index 8d26b0e2f..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_networking_ar.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - networkingApi "github.com/arangodb/kube-arangodb/pkg/apis/networking/v1alpha1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func networkingArangoRoutes(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - arangoRoutes, err := listNetowkingArangoRoutes(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(networkingArangoRoute, client, files, arangoRoutes...); err != nil { - logger.Err(err).Msgf("Error while collecting networking arango routes") - return err - } - - return nil -} - -func networkingArangoRoute(client kclient.Client, files chan<- shared.File, ext *networkingApi.ArangoRoute) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/networking/arangoroutes/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listNetowkingArangoRoutes(client kclient.Client) ([]*networkingApi.ArangoRoute, error) { - return ListObjects[*networkingApi.ArangoRouteList, *networkingApi.ArangoRoute](context.Background(), client.Arango().NetworkingV1alpha1().ArangoRoutes(cli.GetInput().Namespace), func(result *networkingApi.ArangoRouteList) []*networkingApi.ArangoRoute { - q := make([]*networkingApi.ArangoRoute, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_platform.go b/pkg/debug_package/generators/kubernetes/arango_platform.go deleted file mode 100644 index fd78e3fde..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_platform.go +++ /dev/null @@ -1,52 +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 kubernetes - -import ( - "github.com/rs/zerolog" - - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func Platform() shared.Factory { - return shared.NewFactory("platform", true, platform) -} - -func platform(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - if err := platformArangoPlatformStorages(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting platform arango storages") - return err - } - - if err := platformArangoPlatformCharts(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting platform arango charts") - return err - } - - return nil -} diff --git a/pkg/debug_package/generators/kubernetes/arango_platform_c.go b/pkg/debug_package/generators/kubernetes/arango_platform_c.go deleted file mode 100644 index 7611a1602..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_platform_c.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func platformArangoPlatformCharts(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - arangoPlatformStorages, err := listNetowkingArangoPlatformCharts(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(platformArangoPlatformChart, client, files, arangoPlatformStorages...); err != nil { - logger.Err(err).Msgf("Error while collecting platform arango charts") - return err - } - - return nil -} - -func platformArangoPlatformChart(client kclient.Client, files chan<- shared.File, ext *platformApi.ArangoPlatformChart) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/platform/arangoplatformcharts/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listNetowkingArangoPlatformCharts(client kclient.Client) ([]*platformApi.ArangoPlatformChart, error) { - return ListObjects[*platformApi.ArangoPlatformChartList, *platformApi.ArangoPlatformChart](context.Background(), client.Arango().PlatformV1alpha1().ArangoPlatformCharts(cli.GetInput().Namespace), func(result *platformApi.ArangoPlatformChartList) []*platformApi.ArangoPlatformChart { - q := make([]*platformApi.ArangoPlatformChart, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_platform_s.go b/pkg/debug_package/generators/kubernetes/arango_platform_s.go deleted file mode 100644 index 653bcb7d2..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_platform_s.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func platformArangoPlatformStorages(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - arangoPlatformStorages, err := listNetowkingArangoPlatformStorages(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(platformArangoPlatformStorage, client, files, arangoPlatformStorages...); err != nil { - logger.Err(err).Msgf("Error while collecting platform arango storages") - return err - } - - return nil -} - -func platformArangoPlatformStorage(client kclient.Client, files chan<- shared.File, ext *platformApi.ArangoPlatformStorage) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/platform/arangoplatformstorages/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listNetowkingArangoPlatformStorages(client kclient.Client) ([]*platformApi.ArangoPlatformStorage, error) { - return ListObjects[*platformApi.ArangoPlatformStorageList, *platformApi.ArangoPlatformStorage](context.Background(), client.Arango().PlatformV1alpha1().ArangoPlatformStorages(cli.GetInput().Namespace), func(result *platformApi.ArangoPlatformStorageList) []*platformApi.ArangoPlatformStorage { - q := make([]*platformApi.ArangoPlatformStorage, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_scheduler.go b/pkg/debug_package/generators/kubernetes/arango_scheduler.go deleted file mode 100644 index dead1a268..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_scheduler.go +++ /dev/null @@ -1,67 +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 kubernetes - -import ( - "github.com/rs/zerolog" - - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func Scheduler() shared.Factory { - return shared.NewFactory("scheduler", true, scheduler) -} - -func scheduler(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - if err := schedulerProfiles(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango scheduler extension") - return err - } - - if err := schedulerPods(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango scheduler extension") - return err - } - - if err := schedulerDeployments(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango scheduler extension") - return err - } - - if err := schedulerBatchJobs(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango scheduler extension") - return err - } - - if err := schedulerCronJobs(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango scheduler extension") - return err - } - - return nil -} diff --git a/pkg/debug_package/generators/kubernetes/arango_scheduler_batchjobs.go b/pkg/debug_package/generators/kubernetes/arango_scheduler_batchjobs.go deleted file mode 100644 index a12a9b70c..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_scheduler_batchjobs.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func schedulerBatchJobs(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - batchjobs, err := listSchedulerBatchJobs(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(schedulerBatchJob, client, files, batchjobs...); err != nil { - logger.Err(err).Msgf("Error while collecting arango scheduler batchjobs") - return err - } - - return nil -} - -func schedulerBatchJob(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerBatchJob) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulerbatchjobs/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listSchedulerBatchJobs(client kclient.Client) ([]*schedulerApi.ArangoSchedulerBatchJob, error) { - return ListObjects[*schedulerApi.ArangoSchedulerBatchJobList, *schedulerApi.ArangoSchedulerBatchJob](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerBatchJobs(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerBatchJobList) []*schedulerApi.ArangoSchedulerBatchJob { - q := make([]*schedulerApi.ArangoSchedulerBatchJob, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_scheduler_cronjobs.go b/pkg/debug_package/generators/kubernetes/arango_scheduler_cronjobs.go deleted file mode 100644 index 566548feb..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_scheduler_cronjobs.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func schedulerCronJobs(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - cronjobs, err := listSchedulerCronJobs(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(schedulerCronJob, client, files, cronjobs...); err != nil { - logger.Err(err).Msgf("Error while collecting arango scheduler cronjobs") - return err - } - - return nil -} - -func schedulerCronJob(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerCronJob) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulercronjobs/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listSchedulerCronJobs(client kclient.Client) ([]*schedulerApi.ArangoSchedulerCronJob, error) { - return ListObjects[*schedulerApi.ArangoSchedulerCronJobList, *schedulerApi.ArangoSchedulerCronJob](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerCronJobs(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerCronJobList) []*schedulerApi.ArangoSchedulerCronJob { - q := make([]*schedulerApi.ArangoSchedulerCronJob, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_scheduler_deployment.go b/pkg/debug_package/generators/kubernetes/arango_scheduler_deployment.go deleted file mode 100644 index eec21376e..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_scheduler_deployment.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func schedulerDeployments(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - deployments, err := listSchedulerDeployments(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(schedulerDeployment, client, files, deployments...); err != nil { - logger.Err(err).Msgf("Error while collecting arango scheduler deployments") - return err - } - - return nil -} - -func schedulerDeployment(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerDeployment) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulerdeployments/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listSchedulerDeployments(client kclient.Client) ([]*schedulerApi.ArangoSchedulerDeployment, error) { - return ListObjects[*schedulerApi.ArangoSchedulerDeploymentList, *schedulerApi.ArangoSchedulerDeployment](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerDeployments(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerDeploymentList) []*schedulerApi.ArangoSchedulerDeployment { - q := make([]*schedulerApi.ArangoSchedulerDeployment, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_scheduler_pod.go b/pkg/debug_package/generators/kubernetes/arango_scheduler_pod.go deleted file mode 100644 index b3bbe7c80..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_scheduler_pod.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func schedulerPods(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - pods, err := listSchedulerPods(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(schedulerPod, client, files, pods...); err != nil { - logger.Err(err).Msgf("Error while collecting arango scheduler pods") - return err - } - - return nil -} - -func schedulerPod(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerPod) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulerpods/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listSchedulerPods(client kclient.Client) ([]*schedulerApi.ArangoSchedulerPod, error) { - return ListObjects[*schedulerApi.ArangoSchedulerPodList, *schedulerApi.ArangoSchedulerPod](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerPods(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerPodList) []*schedulerApi.ArangoSchedulerPod { - q := make([]*schedulerApi.ArangoSchedulerPod, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/arango_scheduler_profile.go b/pkg/debug_package/generators/kubernetes/arango_scheduler_profile.go deleted file mode 100644 index 9c3c25cb1..000000000 --- a/pkg/debug_package/generators/kubernetes/arango_scheduler_profile.go +++ /dev/null @@ -1,73 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - - schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func schedulerProfiles(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { - profiles, err := listSchedulerProfiles(client) - if err != nil { - if kerrors.IsForbiddenOrNotFound(err) { - return nil - } - - return err - } - - if err := errors.ExecuteWithErrorArrayP2(schedulerProfile, client, files, profiles...); err != nil { - logger.Err(err).Msgf("Error while collecting arango scheduler profiles") - return err - } - - return nil -} - -func schedulerProfile(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoProfile) error { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/profiles/%s.yaml", ext.GetName()), func() ([]interface{}, error) { - return []interface{}{ext}, nil - }) - - return nil -} - -func listSchedulerProfiles(client kclient.Client) ([]*schedulerApi.ArangoProfile, error) { - return ListObjects[*schedulerApi.ArangoProfileList, *schedulerApi.ArangoProfile](context.Background(), client.Arango().SchedulerV1beta1().ArangoProfiles(cli.GetInput().Namespace), func(result *schedulerApi.ArangoProfileList) []*schedulerApi.ArangoProfile { - q := make([]*schedulerApi.ArangoProfile, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) -} diff --git a/pkg/debug_package/generators/kubernetes/configmaps.go b/pkg/debug_package/generators/kubernetes/configmaps.go deleted file mode 100644 index d422ed597..000000000 --- a/pkg/debug_package/generators/kubernetes/configmaps.go +++ /dev/null @@ -1,63 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2025 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 kubernetes - -import ( - "context" - - "github.com/rs/zerolog" - core "k8s.io/api/core/v1" - "k8s.io/client-go/kubernetes" - - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func ConfigMaps() shared.Factory { - return shared.NewFactory("kubernetes-configmaps", true, configmaps) -} - -func listConfigMaps(client kubernetes.Interface) func() ([]*core.ConfigMap, error) { - return func() ([]*core.ConfigMap, error) { - return ListObjects[*core.ConfigMapList, *core.ConfigMap](context.Background(), client.CoreV1().ConfigMaps(cli.GetInput().Namespace), func(result *core.ConfigMapList) []*core.ConfigMap { - q := make([]*core.ConfigMap, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) - } -} - -func configmaps(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - files <- shared.NewYAMLFile("kubernetes/configmaps.yaml", listConfigMaps(k.Kubernetes())) - - return nil -} diff --git a/pkg/debug_package/generators/kubernetes/events.go b/pkg/debug_package/generators/kubernetes/events.go deleted file mode 100644 index 5a2fdb3f4..000000000 --- a/pkg/debug_package/generators/kubernetes/events.go +++ /dev/null @@ -1,63 +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 kubernetes - -import ( - "context" - - "github.com/rs/zerolog" - core "k8s.io/api/core/v1" - "k8s.io/client-go/kubernetes" - - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func Events() shared.Factory { - return shared.NewFactory("kubernetes-events", true, events) -} - -func listEvents(client kubernetes.Interface) func() ([]*core.Event, error) { - return func() ([]*core.Event, error) { - return ListObjects[*core.EventList, *core.Event](context.Background(), client.CoreV1().Events(cli.GetInput().Namespace), func(result *core.EventList) []*core.Event { - q := make([]*core.Event, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) - } -} - -func events(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - files <- shared.NewYAMLFile("kubernetes/events.yaml", listEvents(k.Kubernetes())) - - return nil -} diff --git a/pkg/debug_package/generators/kubernetes/kubernetes.go b/pkg/debug_package/generators/kubernetes/kubernetes.go new file mode 100644 index 000000000..7761f6c5c --- /dev/null +++ b/pkg/debug_package/generators/kubernetes/kubernetes.go @@ -0,0 +1,30 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 kubernetes + +import "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + +func Register(f shared.FactoryGen) { + f.AddSection("kubernetes"). + Extend(KubernetesApps). + Extend(KubernetesBatch). + Extend(KubernetesCore) +} diff --git a/pkg/debug_package/generators/kubernetes/kubernetes_apps.go b/pkg/debug_package/generators/kubernetes/kubernetes_apps.go new file mode 100644 index 000000000..f26a5704e --- /dev/null +++ b/pkg/debug_package/generators/kubernetes/kubernetes_apps.go @@ -0,0 +1,74 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 kubernetes + +import ( + "context" + + apps "k8s.io/api/apps/v1" + + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func KubernetesApps(f shared.FactoryGen) { + f.AddSection("apps"). + Register("replicaset", true, shared.WithKubernetesItems[*apps.ReplicaSet](kubernetesAppsReplicaSetsList, shared.WithDefinitions[*apps.ReplicaSet])). + Register("deployment", true, shared.WithKubernetesItems[*apps.Deployment](kubernetesAppsDeploymentsList, shared.WithDefinitions[*apps.Deployment])). + Register("statefulset", true, shared.WithKubernetesItems[*apps.StatefulSet](kubernetesAppsStatefulSetsList, shared.WithDefinitions[*apps.StatefulSet])) +} + +func kubernetesAppsReplicaSetsList(ctx context.Context, client kclient.Client, namespace string) ([]*apps.ReplicaSet, error) { + return list.ListObjects[*apps.ReplicaSetList, *apps.ReplicaSet](ctx, client.Kubernetes().AppsV1().ReplicaSets(namespace), func(result *apps.ReplicaSetList) []*apps.ReplicaSet { + q := make([]*apps.ReplicaSet, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func kubernetesAppsDeploymentsList(ctx context.Context, client kclient.Client, namespace string) ([]*apps.Deployment, error) { + return list.ListObjects[*apps.DeploymentList, *apps.Deployment](ctx, client.Kubernetes().AppsV1().Deployments(namespace), func(result *apps.DeploymentList) []*apps.Deployment { + q := make([]*apps.Deployment, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func kubernetesAppsStatefulSetsList(ctx context.Context, client kclient.Client, namespace string) ([]*apps.StatefulSet, error) { + return list.ListObjects[*apps.StatefulSetList, *apps.StatefulSet](ctx, client.Kubernetes().AppsV1().StatefulSets(namespace), func(result *apps.StatefulSetList) []*apps.StatefulSet { + q := make([]*apps.StatefulSet, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} diff --git a/pkg/debug_package/generators/kubernetes/kubernetes_batch.go b/pkg/debug_package/generators/kubernetes/kubernetes_batch.go new file mode 100644 index 000000000..0fd2af624 --- /dev/null +++ b/pkg/debug_package/generators/kubernetes/kubernetes_batch.go @@ -0,0 +1,61 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 kubernetes + +import ( + "context" + + batch "k8s.io/api/batch/v1" + + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func KubernetesBatch(f shared.FactoryGen) { + f.AddSection("batch"). + Register("job", true, shared.WithKubernetesItems[*batch.Job](kubernetesBatchJobsList, shared.WithDefinitions[*batch.Job])). + Register("cronjob", true, shared.WithKubernetesItems[*batch.CronJob](kubernetesBatchCronJobsList, shared.WithDefinitions[*batch.CronJob])) +} + +func kubernetesBatchJobsList(ctx context.Context, client kclient.Client, namespace string) ([]*batch.Job, error) { + return list.ListObjects[*batch.JobList, *batch.Job](ctx, client.Kubernetes().BatchV1().Jobs(namespace), func(result *batch.JobList) []*batch.Job { + q := make([]*batch.Job, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func kubernetesBatchCronJobsList(ctx context.Context, client kclient.Client, namespace string) ([]*batch.CronJob, error) { + return list.ListObjects[*batch.CronJobList, *batch.CronJob](ctx, client.Kubernetes().BatchV1().CronJobs(namespace), func(result *batch.CronJobList) []*batch.CronJob { + q := make([]*batch.CronJob, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} diff --git a/pkg/debug_package/generators/kubernetes/kubernetes_core.go b/pkg/debug_package/generators/kubernetes/kubernetes_core.go new file mode 100644 index 000000000..c935121e2 --- /dev/null +++ b/pkg/debug_package/generators/kubernetes/kubernetes_core.go @@ -0,0 +1,100 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 kubernetes + +import ( + "context" + + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func KubernetesCore(f shared.FactoryGen) { + f.AddSection("core"). + Register("configmap", true, shared.WithKubernetesItems[*core.ConfigMap](kubernetesCoreConfigMapsList, shared.WithDefinitions[*core.ConfigMap])). + Register("event", true, shared.WithKubernetesItems[*core.Event](kubernetesCoreEventsList)). + Register("pod", true, shared.WithKubernetesItems[*core.Pod](kubernetesCorePodsList, shared.WithDefinitions[*core.Pod], kubernetesCorePodLogs)). + Register("secret", true, shared.WithKubernetesItems[*core.Secret](kubernetesCoreSecretList, shared.WithModification[*core.Secret](shared.WithDefinitions[*core.Secret], kubernetesCoreSecretModHideSensitiveData))). + Register("service", true, shared.WithKubernetesItems[*core.Service](kubernetesCoreServiceList, shared.WithDefinitions[*core.Service], kubernetesCoreServiceEndpoints)) +} + +func kubernetesCoreConfigMapsList(ctx context.Context, client kclient.Client, namespace string) ([]*core.ConfigMap, error) { + return list.ListObjects[*core.ConfigMapList, *core.ConfigMap](ctx, client.Kubernetes().CoreV1().ConfigMaps(namespace), func(result *core.ConfigMapList) []*core.ConfigMap { + q := make([]*core.ConfigMap, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func kubernetesCoreEventsList(ctx context.Context, client kclient.Client, namespace string) ([]*core.Event, error) { + return list.ListObjects[*core.EventList, *core.Event](ctx, client.Kubernetes().CoreV1().Events(namespace), func(result *core.EventList) []*core.Event { + q := make([]*core.Event, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func kubernetesCorePodsList(ctx context.Context, client kclient.Client, namespace string) ([]*core.Pod, error) { + return list.ListObjects[*core.PodList, *core.Pod](ctx, client.Kubernetes().CoreV1().Pods(namespace), func(result *core.PodList) []*core.Pod { + q := make([]*core.Pod, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func kubernetesCoreSecretList(ctx context.Context, client kclient.Client, namespace string) ([]*core.Secret, error) { + return list.ListObjects[*core.SecretList, *core.Secret](ctx, client.Kubernetes().CoreV1().Secrets(namespace), func(result *core.SecretList) []*core.Secret { + q := make([]*core.Secret, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} + +func kubernetesCoreServiceList(ctx context.Context, client kclient.Client, namespace string) ([]*core.Service, error) { + return list.ListObjects[*core.ServiceList, *core.Service](ctx, client.Kubernetes().CoreV1().Services(namespace), func(result *core.ServiceList) []*core.Service { + q := make([]*core.Service, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} diff --git a/pkg/debug_package/generators/kubernetes/kubernetes_core_pods.go b/pkg/debug_package/generators/kubernetes/kubernetes_core_pods.go new file mode 100644 index 000000000..e9a1dd0ac --- /dev/null +++ b/pkg/debug_package/generators/kubernetes/kubernetes_core_pods.go @@ -0,0 +1,95 @@ +// +// DISCLAIMER +// +// Copyright 2016-2025 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 kubernetes + +import ( + "context" + "fmt" + "io" + + "github.com/rs/zerolog" + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func kubernetesCorePodLogs(ctx context.Context, logger zerolog.Logger, client kclient.Client, files chan<- shared.File, item *core.Pod) error { + if !cli.GetInput().PodLogs { + return nil + } + + if s := item.Status.ContainerStatuses; len(s) > 0 { + for id := range s { + if s[id].State.Waiting != nil { + continue + } + + files <- kubernetesCorePodLogsExtract(ctx, client, item, s[id].Name) + } + } + + if s := item.Status.EphemeralContainerStatuses; len(s) > 0 { + for id := range s { + if s[id].State.Waiting != nil { + continue + } + + files <- kubernetesCorePodLogsExtract(ctx, client, item, s[id].Name) + } + } + + if s := item.Status.InitContainerStatuses; len(s) > 0 { + for id := range s { + if s[id].State.Waiting != nil { + continue + } + + files <- kubernetesCorePodLogsExtract(ctx, client, item, s[id].Name) + } + } + + return nil +} + +func kubernetesCorePodLogsExtract(ctx context.Context, client kclient.Client, item *core.Pod, container string) shared.File { + return shared.NewFile(fmt.Sprintf("logs/container/%s", container), func() ([]byte, error) { + res := client.Kubernetes().CoreV1().Pods(item.GetNamespace()).GetLogs(item.GetName(), &core.PodLogOptions{ + Container: container, + Timestamps: true, + }) + + q, err := res.Stream(ctx) + if err != nil { + return nil, err + } + + defer q.Close() + + d, err := io.ReadAll(q) + if err != nil { + return nil, err + } + + return d, nil + }) +} diff --git a/pkg/debug_package/generators/kubernetes/kubernetes_core_secrets.go b/pkg/debug_package/generators/kubernetes/kubernetes_core_secrets.go new file mode 100644 index 000000000..6a7c3a913 --- /dev/null +++ b/pkg/debug_package/generators/kubernetes/kubernetes_core_secrets.go @@ -0,0 +1,37 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 kubernetes + +import ( + core "k8s.io/api/core/v1" + + "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" + "github.com/arangodb/kube-arangodb/pkg/util" +) + +func kubernetesCoreSecretModHideSensitiveData(in *core.Secret) *core.Secret { + if cli.GetInput().HideSensitiveData { + for k := range in.Data { + in.Data[k] = []byte(util.SHA256(in.Data[k])) + } + } + return in +} diff --git a/pkg/debug_package/generators/kubernetes/analytics.go b/pkg/debug_package/generators/kubernetes/kubernetes_core_services.go similarity index 58% rename from pkg/debug_package/generators/kubernetes/analytics.go rename to pkg/debug_package/generators/kubernetes/kubernetes_core_services.go index 2b0317721..36349fc05 100644 --- a/pkg/debug_package/generators/kubernetes/analytics.go +++ b/pkg/debug_package/generators/kubernetes/kubernetes_core_services.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2025 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,27 +21,25 @@ package kubernetes import ( + "context" + "github.com/rs/zerolog" + core "k8s.io/api/core/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/kclient" ) -func Analytics() shared.Factory { - return shared.NewFactory("analytics", true, analytics) -} - -func analytics(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - if err := analyticsGAEs(logger, files, k); err != nil { - logger.Err(err).Msgf("Error while collecting arango analytics engines") - return err - } +func kubernetesCoreServiceEndpoints(ctx context.Context, logger zerolog.Logger, client kclient.Client, files chan<- shared.File, item *core.Service) error { + files <- shared.NewYAMLFile("endpoint.yaml", func() ([]interface{}, error) { + ep, err := client.Kubernetes().CoreV1().Endpoints(item.GetNamespace()).Get(ctx, item.GetName(), meta.GetOptions{}) + if err != nil { + return nil, err + } + ep.ManagedFields = nil + return []interface{}{ep}, nil + }) return nil } diff --git a/pkg/debug_package/generators/kubernetes/pods.go b/pkg/debug_package/generators/kubernetes/pods.go deleted file mode 100644 index 8b86c4600..000000000 --- a/pkg/debug_package/generators/kubernetes/pods.go +++ /dev/null @@ -1,157 +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 kubernetes - -import ( - "context" - "fmt" - "io" - - "github.com/rs/zerolog" - core "k8s.io/api/core/v1" - "k8s.io/client-go/kubernetes" - - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func Pods() shared.Factory { - return shared.NewFactory("kubernetes-pods", true, pods) -} - -func listPods(client kubernetes.Interface) func() ([]*core.Pod, error) { - return func() ([]*core.Pod, error) { - return ListObjects[*core.PodList, *core.Pod](context.Background(), client.CoreV1().Pods(cli.GetInput().Namespace), func(result *core.PodList) []*core.Pod { - q := make([]*core.Pod, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) - } -} - -func pods(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - pods, err := listPods(k.Kubernetes())() - if err != nil { - return err - } - - files <- shared.NewYAMLFile("kubernetes/pods.yaml", func() ([]*core.Pod, error) { - return pods, nil - }) - - if cli.GetInput().PodLogs { - if err := podsLogs(k, files, pods...); err != nil { - logger.Err(err).Msgf("Error while collecting pod logs") - } - } - - return nil -} - -func podsLogs(client kclient.Client, files chan<- shared.File, pods ...*core.Pod) error { - errs := make([]error, len(pods)) - - for id := range pods { - errs[id] = podLogs(client, files, pods[id]) - } - - return errors.Errors(errs...) -} - -func podLogs(client kclient.Client, files chan<- shared.File, pod *core.Pod) error { - podYaml(files, pod) - - errs := make([]error, 0, len(pod.Status.ContainerStatuses)+len(pod.Status.InitContainerStatuses)+len(pod.Status.EphemeralContainerStatuses)) - - if s := pod.Status.ContainerStatuses; len(s) > 0 { - for id := range s { - if s[id].State.Waiting != nil { - continue - } - - errs = append(errs, errors.Wrapf(podContainerLogs(client, files, pod, s[id].Name), "Unable to read %s Container logs", s[id].Name)) - } - } - - if s := pod.Status.EphemeralContainerStatuses; len(s) > 0 { - for id := range s { - if s[id].State.Waiting != nil { - continue - } - - errs = append(errs, errors.Wrapf(podContainerLogs(client, files, pod, s[id].Name), "Unable to read %s EphemeralContainer logs", s[id].Name)) - } - } - - if s := pod.Status.InitContainerStatuses; len(s) > 0 { - for id := range s { - if s[id].State.Waiting != nil { - continue - } - - errs = append(errs, errors.Wrapf(podContainerLogs(client, files, pod, s[id].Name), "Unable to read %s InitContainer logs", s[id].Name)) - } - } - - return errors.Errors(errs...) -} - -func podYaml(files chan<- shared.File, pod *core.Pod) { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/pods/%s/pod.yaml", pod.GetName()), func() ([]interface{}, error) { - return []interface{}{pod}, nil - }) -} - -func podContainerLogs(client kclient.Client, files chan<- shared.File, pod *core.Pod, container string) error { - res := client.Kubernetes().CoreV1().Pods(pod.GetNamespace()).GetLogs(pod.GetName(), &core.PodLogOptions{ - Container: container, - Timestamps: true, - }) - - q, err := res.Stream(context.Background()) - if err != nil { - return err - } - - defer q.Close() - - d, err := io.ReadAll(q) - if err != nil { - return err - } - - files <- shared.NewFile(fmt.Sprintf("kubernetes/pods/%s/logs/container/%s", pod.GetName(), container), func() ([]byte, error) { - return d, nil - }) - - return nil -} diff --git a/pkg/debug_package/generators/kubernetes/secrets.go b/pkg/debug_package/generators/kubernetes/secrets.go deleted file mode 100644 index 69778d4ee..000000000 --- a/pkg/debug_package/generators/kubernetes/secrets.go +++ /dev/null @@ -1,71 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2025 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 kubernetes - -import ( - "context" - - "github.com/rs/zerolog" - core "k8s.io/api/core/v1" - "k8s.io/client-go/kubernetes" - - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func Secrets() shared.Factory { - return shared.NewFactory("kubernetes-secrets", true, secrets) -} - -func listSecrets(client kubernetes.Interface) func() ([]*core.Secret, error) { - return func() ([]*core.Secret, error) { - return ListObjects[*core.SecretList, *core.Secret](context.Background(), client.CoreV1().Secrets(cli.GetInput().Namespace), func(result *core.SecretList) []*core.Secret { - q := make([]*core.Secret, len(result.Items)) - - for id, e := range result.Items { - z := e.DeepCopy() - - if cli.GetInput().HideSensitiveData { - for k := range z.Data { - z.Data[k] = []byte(util.SHA256(z.Data[k])) - } - } - q[id] = z.DeepCopy() - } - - return q - }) - } -} - -func secrets(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - files <- shared.NewYAMLFile("kubernetes/secrets.yaml", listSecrets(k.Kubernetes())) - - return nil -} diff --git a/pkg/debug_package/generators/kubernetes/services.go b/pkg/debug_package/generators/kubernetes/services.go deleted file mode 100644 index a5aba02af..000000000 --- a/pkg/debug_package/generators/kubernetes/services.go +++ /dev/null @@ -1,87 +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 kubernetes - -import ( - "context" - "fmt" - - "github.com/rs/zerolog" - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/kubernetes" - - "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" - "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" - "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" -) - -func Services() shared.Factory { - return shared.NewFactory("kubernetes-services", true, services) -} - -func listServices(client kubernetes.Interface) func() ([]*core.Service, error) { - return func() ([]*core.Service, error) { - return ListObjects[*core.ServiceList, *core.Service](context.Background(), client.CoreV1().Services(cli.GetInput().Namespace), func(result *core.ServiceList) []*core.Service { - q := make([]*core.Service, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) - } -} - -func services(logger zerolog.Logger, files chan<- shared.File) error { - k, ok := kclient.GetDefaultFactory().Client() - if !ok { - return errors.Errorf("Client is not initialised") - } - - services, err := listServices(k.Kubernetes())() - if err != nil { - return err - } - - files <- shared.NewYAMLFile("kubernetes/services.yaml", func() ([]*core.Service, error) { - return services, nil - }) - - for _, svc := range services { - endpoints(k, svc.GetNamespace(), svc.GetName(), files) - } - - return nil -} - -func endpoints(k kclient.Client, namespace, name string, files chan<- shared.File) { - ep, err := k.Kubernetes().CoreV1().Endpoints(namespace).Get(context.Background(), name, meta.GetOptions{}) - if err == nil { - files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/services/%s/endpoints.yaml", name), func() ([]interface{}, error) { - ep.ManagedFields = nil - - return []interface{}{ep}, nil - }) - } -} diff --git a/pkg/debug_package/generators/prometheus/prometheus.go b/pkg/debug_package/generators/prometheus/prometheus.go new file mode 100644 index 000000000..7d833be78 --- /dev/null +++ b/pkg/debug_package/generators/prometheus/prometheus.go @@ -0,0 +1,30 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 prometheus + +import ( + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" +) + +func Register(f shared.FactoryGen) { + f.AddSection("prometheus"). + Extend(PrometheusMonitoring) +} diff --git a/pkg/debug_package/generators/prometheus/prometheus_monitoring.go b/pkg/debug_package/generators/prometheus/prometheus_monitoring.go new file mode 100644 index 000000000..bf3c08657 --- /dev/null +++ b/pkg/debug_package/generators/prometheus/prometheus_monitoring.go @@ -0,0 +1,47 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 prometheus + +import ( + "context" + + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func PrometheusMonitoring(f shared.FactoryGen) { + f.Register("monitoring", true, shared.WithKubernetesItems[*monitoringApi.ServiceMonitor](kubernetesBackupV1ServiceMonitorList, shared.WithDefinitions[*monitoringApi.ServiceMonitor])) +} + +func kubernetesBackupV1ServiceMonitorList(ctx context.Context, client kclient.Client, namespace string) ([]*monitoringApi.ServiceMonitor, error) { + return list.ListObjects[*monitoringApi.ServiceMonitorList, *monitoringApi.ServiceMonitor](ctx, client.Monitoring().MonitoringV1().ServiceMonitors(namespace), func(result *monitoringApi.ServiceMonitorList) []*monitoringApi.ServiceMonitor { + q := make([]*monitoringApi.ServiceMonitor, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +} diff --git a/pkg/debug_package/shared/exec.go b/pkg/debug_package/shared/exec.go index d14d81fa5..e86d4a633 100644 --- a/pkg/debug_package/shared/exec.go +++ b/pkg/debug_package/shared/exec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2025 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,45 +21,128 @@ package shared import ( - "context" - "io" + "bytes" + "os" + "os/exec" + "github.com/rs/zerolog" core "k8s.io/api/core/v1" - scheme2 "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/tools/remotecommand" + "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" + "github.com/arangodb/kube-arangodb/pkg/util/errors" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" "github.com/arangodb/kube-arangodb/pkg/util/kclient" + "github.com/arangodb/kube-arangodb/pkg/util/shutdown" ) -// ExecuteCommandInPod executes command in pod with the given pod name and namespace. -func ExecuteCommandInPod(ctx context.Context, k kclient.Client, container, podName, namespace string, - command []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error { +const LocalBinDir = "/usr/bin/arangodb_operator" - req := k.Kubernetes().CoreV1().RESTClient().Post().Resource("pods").Name(podName). - Namespace(namespace).SubResource("exec") +type ArangoOperatorExecFunc func(logger zerolog.Logger, args ...string) ([]byte, []byte, error) - option := &core.PodExecOptions{ - Command: command, - Container: container, - Stdin: stdin != nil, - Stdout: true, - Stderr: stderr != nil, - TTY: false, +func DiscoverExecFunc() (ArangoOperatorExecFunc, error) { + if _, err := os.Stat(LocalBinDir); err != nil { + if !os.IsNotExist(err) { + return nil, err + } + + return RemoteOperatorExecFunc(LocalBinDir) + } else { + return LocalExecFunc(LocalBinDir) } +} + +func LocalExecFunc(binary string) (ArangoOperatorExecFunc, error) { + return func(logger zerolog.Logger, args ...string) ([]byte, []byte, error) { + logger.Debug().Str("binary", binary).Strs("args", args).Msgf("Executing remote command") + + cmd := exec.Command(binary, args...) + var stderr, stdout bytes.Buffer + + cmd.Stdout = &stdout + cmd.Stderr = &stderr - req.VersionedParams( - option, - scheme2.ParameterCodec, - ) + err := cmd.Run() - exec, err := remotecommand.NewSPDYExecutor(k.Config(), "POST", req.URL()) + return stdout.Bytes(), stderr.Bytes(), err + }, nil +} + +func RemoteOperatorExecFunc(binary string) (ArangoOperatorExecFunc, error) { + id, err := DiscoverOperatorPod(binary) if err != nil { - return err + return nil, err } - return exec.StreamWithContext(ctx, remotecommand.StreamOptions{ - Stdin: stdin, - Stdout: stdout, - Stderr: stderr, + return RemoteExecFunc(binary, id, "operator") +} + +func DiscoverOperatorPod(binary string) (string, error) { + k, ok := kclient.GetDefaultFactory().Client() + if !ok { + return "", errors.Errorf("Client is not initialised") + } + + pods, err := list.ListObjects[*core.PodList, *core.Pod](shutdown.Context(), k.Kubernetes().CoreV1().Pods(cli.GetInput().Namespace), func(result *core.PodList) []*core.Pod { + q := make([]*core.Pod, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q }) + if err != nil { + return "", err + } + + var id string + + for _, v := range pods { + if id != "" { + break + } + + for _, container := range v.Spec.Containers { + if container.Name != "operator" { + continue + } + + var stderr, stdout bytes.Buffer + + if err := ExecuteCommandInPod(shutdown.Context(), k, "operator", v.GetName(), v.GetNamespace(), []string{binary, "version"}, nil, &stdout, &stderr); err != nil { + continue + } + + id = v.GetName() + } + } + + if id == "" { + return "", errors.Errorf("Unable to find Operator pod") + } + + return id, nil +} + +func RemoteExecFunc(binary, pod, container string) (ArangoOperatorExecFunc, error) { + k, ok := kclient.GetDefaultFactory().Client() + if !ok { + return nil, errors.Errorf("Client is not initialised") + } + + return func(logger zerolog.Logger, args ...string) ([]byte, []byte, error) { + var stderr, stdout bytes.Buffer + + in := make([]string, len(args)+1) + in[0] = binary + for id := range args { + in[id+1] = args[id] + } + + logger.Debug().Str("binary", binary).Strs("args", args).Str("namespace", cli.GetInput().Namespace).Str("container", container).Str("pod", pod).Msgf("Executing remote command") + + err := ExecuteCommandInPod(shutdown.Context(), k, container, pod, cli.GetInput().Namespace, in, nil, &stdout, &stderr) + + return stdout.Bytes(), stderr.Bytes(), err + }, nil } diff --git a/pkg/debug_package/shared/file.go b/pkg/debug_package/shared/file.go index 6f531e4a9..14944188b 100644 --- a/pkg/debug_package/shared/file.go +++ b/pkg/debug_package/shared/file.go @@ -23,6 +23,8 @@ package shared import ( "bytes" "encoding/json" + "fmt" + "sync" "github.com/rs/zerolog" "sigs.k8s.io/yaml" @@ -99,18 +101,18 @@ type Factory interface { Enabled() bool } -func NewFactory(name string, enabled bool, gen GenFunc) Factory { +func NewFactory(name string, enabled bool, gens ...GenFunc) Factory { return factory{ name: name, enabled: enabled, - generate: gen, + generate: gens, } } type factory struct { name string enabled bool - generate GenFunc + generate []GenFunc } func (f factory) Enabled() bool { @@ -122,7 +124,13 @@ func (f factory) Name() string { } func (f factory) Generate(logger zerolog.Logger, files chan<- File) error { - return f.generate(logger, files) + for _, gen := range f.generate { + if err := gen(logger, files); err != nil { + return err + } + } + + return nil } func GenerateDataFuncP1[P1 any](call func(p1 P1) ([]byte, error), p1 P1) DataFunc { @@ -136,3 +144,81 @@ func GenerateDataFuncP2[P1, P2 any](call func(p1 P1, p2 P2) ([]byte, error), p1 return call(p1, p2) } } + +func NewFactoryGen() FactoryGen { + return &rootFactoryGen{} +} + +type FactoryGen interface { + AddSection(name string) FactoryGen + + Register(name string, enabled bool, gens GenFunc) FactoryGen + + Extend(in func(f FactoryGen)) FactoryGen + + Get() []Factory +} + +type rootFactoryGen struct { + lock sync.Mutex + + factories []Factory +} + +func (r *rootFactoryGen) Extend(in func(f FactoryGen)) FactoryGen { + in(r) + return r +} + +func (r *rootFactoryGen) Get() []Factory { + r.lock.Lock() + defer r.lock.Unlock() + + q := make([]Factory, len(r.factories)) + copy(q, r.factories) + + return q +} + +func (r *rootFactoryGen) AddSection(name string) FactoryGen { + return rootFactorySection{ + parent: r, + section: name, + } +} + +func (r *rootFactoryGen) Register(name string, enabled bool, gens GenFunc) FactoryGen { + r.lock.Lock() + defer r.lock.Unlock() + + r.factories = append(r.factories, NewFactory(name, enabled, gens)) + + return r +} + +type rootFactorySection struct { + parent FactoryGen + + section string +} + +func (r rootFactorySection) Get() []Factory { + return r.parent.Get() +} + +func (r rootFactorySection) AddSection(name string) FactoryGen { + return rootFactorySection{ + parent: r, + section: name, + } +} + +func (r rootFactorySection) Register(name string, enabled bool, gens GenFunc) FactoryGen { + r.parent.Register(fmt.Sprintf("%s-%s", r.section, name), enabled, gens) + return r +} + +func (r rootFactorySection) Extend(in func(f FactoryGen)) FactoryGen { + in(r) + return r +} diff --git a/pkg/debug_package/shared/gen.go b/pkg/debug_package/shared/gen.go new file mode 100644 index 000000000..1426af8cc --- /dev/null +++ b/pkg/debug_package/shared/gen.go @@ -0,0 +1,104 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 shared + +import ( + "context" + "reflect" + + "github.com/rs/zerolog" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" + "github.com/arangodb/kube-arangodb/pkg/util" + "github.com/arangodb/kube-arangodb/pkg/util/errors" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" + "github.com/arangodb/kube-arangodb/pkg/util/shutdown" +) + +type IterateOverItemsFunc[T meta.Object] func(ctx context.Context, logger zerolog.Logger, client kclient.Client, files chan<- File, item T) error + +type Extract[T meta.Object] func(ctx context.Context, client kclient.Client, namespace string) ([]T, error) + +func WithKubernetesItems[T meta.Object](extract Extract[T], iterators ...IterateOverItemsFunc[T]) GenFunc { + return func(logger zerolog.Logger, files chan<- File) error { + files, c := WithPrefix(files, "kubernetes/") + defer c() + + k, ok := kclient.GetDefaultFactory().Client() + if !ok { + return errors.Errorf("Client is not initialised") + } + + items, err := extract(shutdown.Context(), k, cli.GetInput().Namespace) + if err != nil { + if kerrors.IsForbiddenOrNotFound(err) { + logger.Err(err).Msgf("Unable to list resources") + return nil + } + + return err + } + + files, c = WithGVRPrefix(files, reflect.TypeOf(items).Elem()) + defer c() + + files <- NewYAMLFile(".yaml", func() ([]T, error) { + return items, nil + }) + + for _, item := range items { + if err := WithItem[T](shutdown.Context(), logger, k, files, item, iterators...); err != nil { + return err + } + } + + return nil + } +} + +func WithItem[T meta.Object](ctx context.Context, logger zerolog.Logger, client kclient.Client, files chan<- File, item T, iterators ...IterateOverItemsFunc[T]) error { + files, c := WithPrefix(files, "/%s/", item.GetName()) + defer c() + for _, iter := range iterators { + if err := iter(ctx, logger, client, files, item); err != nil { + return err + } + } + return nil +} + +func WithModification[T meta.Object](in IterateOverItemsFunc[T], mods ...util.ModR[T]) IterateOverItemsFunc[T] { + return func(ctx context.Context, logger zerolog.Logger, client kclient.Client, files chan<- File, item T) error { + n := util.ApplyModsR(item, mods...) + + return in(ctx, logger, client, files, n) + } +} + +func WithDefinitions[T meta.Object](ctx context.Context, logger zerolog.Logger, client kclient.Client, files chan<- File, item T) error { + files <- NewYAMLFile("definition.yaml", func() ([]T, error) { + return []T{item}, nil + }) + + return nil +} diff --git a/pkg/debug_package/shared/k8s.go b/pkg/debug_package/shared/k8s.go new file mode 100644 index 000000000..417b3f7e0 --- /dev/null +++ b/pkg/debug_package/shared/k8s.go @@ -0,0 +1,65 @@ +// +// DISCLAIMER +// +// Copyright 2023-2025 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 shared + +import ( + "context" + "io" + + core "k8s.io/api/core/v1" + scheme2 "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/tools/remotecommand" + + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +// ExecuteCommandInPod executes command in pod with the given pod name and namespace. +func ExecuteCommandInPod(ctx context.Context, k kclient.Client, container, podName, namespace string, + command []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error { + + req := k.Kubernetes().CoreV1().RESTClient().Post().Resource("pods").Name(podName). + Namespace(namespace).SubResource("exec") + + option := &core.PodExecOptions{ + Command: command, + Container: container, + Stdin: stdin != nil, + Stdout: true, + Stderr: stderr != nil, + TTY: false, + } + + req.VersionedParams( + option, + scheme2.ParameterCodec, + ) + + exec, err := remotecommand.NewSPDYExecutor(k.Config(), "POST", req.URL()) + if err != nil { + return err + } + + return exec.StreamWithContext(ctx, remotecommand.StreamOptions{ + Stdin: stdin, + Stdout: stdout, + Stderr: stderr, + }) +} diff --git a/pkg/debug_package/shared/prefix.go b/pkg/debug_package/shared/prefix.go new file mode 100644 index 000000000..1e5c77219 --- /dev/null +++ b/pkg/debug_package/shared/prefix.go @@ -0,0 +1,81 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 shared + +import ( + "fmt" + "reflect" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" +) + +func WithSlash(files chan<- File) (chan<- File, func()) { + return WithPrefix(files, "/") +} + +func WithGVRPrefix(files chan<- File, t reflect.Type) (chan<- File, func()) { + gvr, ok := constants.ExtractGVR(t) + if !ok { + panic(fmt.Sprintf("Unable to get GVR for %s", t.String())) + } + + if gvr.Group == "" { + gvr.Group = "core" + } + + return WithPrefix(files, "%s/%s/%s", gvr.Group, gvr.Version, gvr.Resource) +} + +func WithPrefix(files chan<- File, f string, args ...any) (chan<- File, func()) { + done := make(chan any) + + r := make(chan File) + + go func() { + defer close(done) + + for el := range r { + files <- prefixedFile{ + prefix: fmt.Sprintf(f, args...), + up: el, + } + } + }() + + return r, func() { + close(r) + + <-done + } +} + +type prefixedFile struct { + prefix string + up File +} + +func (p prefixedFile) Path() string { + return fmt.Sprintf("%s%s", p.prefix, p.up.Path()) +} + +func (p prefixedFile) Write() ([]byte, error) { + return p.up.Write() +} diff --git a/pkg/deployment/context_impl.go b/pkg/deployment/context_impl.go index f1be62490..40944a04a 100644 --- a/pkg/deployment/context_impl.go +++ b/pkg/deployment/context_impl.go @@ -26,7 +26,7 @@ import ( "net" "strconv" - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "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" @@ -578,7 +578,7 @@ func (d *Deployment) PodDisruptionBudgetsModInterface() generic.ModClient[*polic return kclient.NewModInterface(d.deps.Client, d.namespace).PodDisruptionBudgets() } -func (d *Deployment) ServiceMonitorsModInterface() generic.ModClient[*monitoring.ServiceMonitor] { +func (d *Deployment) ServiceMonitorsModInterface() generic.ModClient[*monitoringApi.ServiceMonitor] { d.acs.CurrentClusterCache().GetThrottles().ServiceMonitor().Invalidate() return kclient.NewModInterface(d.deps.Client, d.namespace).ServiceMonitors() } diff --git a/pkg/deployment/resources/annotations.go b/pkg/deployment/resources/annotations.go index c24e5b482..46cec5a96 100644 --- a/pkg/deployment/resources/annotations.go +++ b/pkg/deployment/resources/annotations.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -23,7 +23,7 @@ package resources import ( "context" - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" core "k8s.io/api/core/v1" policy "k8s.io/api/policy/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -251,10 +251,10 @@ func (r *Resources) ensureServiceMonitorsAnnotations(patch PatchFunc, cachedStat } return err } - if err := i.Iterate(func(serviceMonitor *monitoring.ServiceMonitor) error { + if err := i.Iterate(func(serviceMonitor *monitoringApi.ServiceMonitor) error { r.ensureAnnotationsMap(serviceMonitor.Kind, serviceMonitor, spec, patch) return nil - }, func(serviceMonitor *monitoring.ServiceMonitor) bool { + }, func(serviceMonitor *monitoringApi.ServiceMonitor) bool { return tools.IsChildResource(kind, name, namespace, serviceMonitor) }); err != nil { return err diff --git a/pkg/deployment/resources/inspector/ap.go b/pkg/deployment/resources/inspector/ap.go index 12d5343bf..61b28156d 100644 --- a/pkg/deployment/resources/inspector/ap.go +++ b/pkg/deployment/resources/inspector/ap.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024-2025 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. @@ -51,8 +51,8 @@ func (p arangoProfilesInspectorLoader) Load(ctx context.Context, i *inspectorSta var q arangoProfilesInspector q.v1beta1 = newInspectorVersion[*schedulerApi.ArangoProfileList, *schedulerApi.ArangoProfile](ctx, - constants.ArangoProfileGRv1(), - constants.ArangoProfileGKv1(), + constants.ArangoProfileGRv1Beta1(), + constants.ArangoProfileGKv1Beta1(), i.client.Arango().SchedulerV1beta1().ArangoProfiles(i.namespace), arangoprofile.List()) diff --git a/pkg/deployment/resources/inspector/ap_anonymous.go b/pkg/deployment/resources/inspector/ap_anonymous.go index 78bc26245..855e4aa6e 100644 --- a/pkg/deployment/resources/inspector/ap_anonymous.go +++ b/pkg/deployment/resources/inspector/ap_anonymous.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024-2025 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. @@ -29,7 +29,7 @@ import ( ) func (p *arangoProfilesInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { - g := constants.ArangoProfileGKv1() + g := constants.ArangoProfileGKv1Beta1() if g.Kind == gvk.Kind && g.Group == gvk.Group { switch gvk.Version { diff --git a/pkg/deployment/resources/inspector/aps.go b/pkg/deployment/resources/inspector/aps.go index 083baa927..59733d53d 100644 --- a/pkg/deployment/resources/inspector/aps.go +++ b/pkg/deployment/resources/inspector/aps.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024-2025 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. @@ -51,8 +51,8 @@ func (p arangoPlatformStoragesInspectorLoader) Load(ctx context.Context, i *insp var q arangoPlatformStoragesInspector q.v1alpha1 = newInspectorVersion[*platformApi.ArangoPlatformStorageList, *platformApi.ArangoPlatformStorage](ctx, - constants.ArangoPlatformStorageGRv1(), - constants.ArangoPlatformStorageGKv1(), + constants.ArangoPlatformStorageGRv1Alpha1(), + constants.ArangoPlatformStorageGKv1Alpha1(), i.client.Arango().PlatformV1alpha1().ArangoPlatformStorages(i.namespace), arangoplatformstorage.List()) diff --git a/pkg/deployment/resources/inspector/aps_anonymous.go b/pkg/deployment/resources/inspector/aps_anonymous.go index 9c6737835..b7f895551 100644 --- a/pkg/deployment/resources/inspector/aps_anonymous.go +++ b/pkg/deployment/resources/inspector/aps_anonymous.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024-2025 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. @@ -29,11 +29,11 @@ import ( ) func (p *arangoPlatformStoragesInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { - g := constants.ArangoPlatformStorageGKv1() + g := constants.ArangoPlatformStorageGKv1Alpha1() if g.Kind == gvk.Kind && g.Group == gvk.Group { switch gvk.Version { - case constants.ArangoPlatformStorageVersionV1Beta1, DefaultVersion: + case constants.ArangoPlatformStorageVersionV1Alpha1, DefaultVersion: if p.v1alpha1 == nil || p.v1alpha1.err != nil { return nil, false } diff --git a/pkg/deployment/resources/inspector/ar.go b/pkg/deployment/resources/inspector/ar.go index 595bf25d8..fbcb872e0 100644 --- a/pkg/deployment/resources/inspector/ar.go +++ b/pkg/deployment/resources/inspector/ar.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -51,8 +51,8 @@ func (p arangoRoutesInspectorLoader) Load(ctx context.Context, i *inspectorState var q arangoRoutesInspector q.v1alpha1 = newInspectorVersion[*networkingApi.ArangoRouteList, *networkingApi.ArangoRoute](ctx, - constants.ArangoRouteGRv1(), - constants.ArangoRouteGKv1(), + constants.ArangoRouteGRv1Alpha1(), + constants.ArangoRouteGKv1Alpha1(), i.client.Arango().NetworkingV1alpha1().ArangoRoutes(i.namespace), arangoroute.List()) diff --git a/pkg/deployment/resources/inspector/ar_anonymous.go b/pkg/deployment/resources/inspector/ar_anonymous.go index 501ebb1e1..f4dbd8f5d 100644 --- a/pkg/deployment/resources/inspector/ar_anonymous.go +++ b/pkg/deployment/resources/inspector/ar_anonymous.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -29,7 +29,7 @@ import ( ) func (p *arangoRoutesInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { - g := constants.ArangoRouteGKv1() + g := constants.ArangoRouteGKv1Alpha1() if g.Kind == gvk.Kind && g.Group == gvk.Group { switch gvk.Version { diff --git a/pkg/deployment/resources/inspector/metrics_test.go b/pkg/deployment/resources/inspector/metrics_test.go index ce9c556fd..20c8e7db6 100644 --- a/pkg/deployment/resources/inspector/metrics_test.go +++ b/pkg/deployment/resources/inspector/metrics_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2025 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. @@ -24,7 +24,7 @@ import ( "context" "testing" - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/stretchr/testify/require" core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -301,8 +301,8 @@ func Test_Metrics(t *testing.T) { }) t.Run(string(definitions.ServiceMonitor), func(t *testing.T) { - testModClientMetrics[*monitoring.ServiceMonitor](t, definitions.ServiceMonitor, q.ServiceMonitorsModInterface().V1(), func(name string) *monitoring.ServiceMonitor { - return &monitoring.ServiceMonitor{ + testModClientMetrics[*monitoringApi.ServiceMonitor](t, definitions.ServiceMonitor, q.ServiceMonitorsModInterface().V1(), func(name string) *monitoringApi.ServiceMonitor { + return &monitoringApi.ServiceMonitor{ ObjectMeta: meta.ObjectMeta{ Name: name, Namespace: "test", diff --git a/pkg/deployment/resources/inspector/owner_test.go b/pkg/deployment/resources/inspector/owner_test.go index 32069b94a..3fca61355 100644 --- a/pkg/deployment/resources/inspector/owner_test.go +++ b/pkg/deployment/resources/inspector/owner_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -308,6 +308,7 @@ func Test_OwnerRef(t *testing.T) { type GVKEnsurer interface { runtime.Object + meta.Object SetGroupVersionKind(gvk schema.GroupVersionKind) } diff --git a/pkg/deployment/resources/inspector/sm.go b/pkg/deployment/resources/inspector/sm.go index 85478cfc1..52f28049a 100644 --- a/pkg/deployment/resources/inspector/sm.go +++ b/pkg/deployment/resources/inspector/sm.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -24,7 +24,7 @@ import ( "context" "time" - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" @@ -51,7 +51,7 @@ func (p serviceMonitorsInspectorLoader) Component() definitions.Component { func (p serviceMonitorsInspectorLoader) Load(ctx context.Context, i *inspectorState) { var q serviceMonitorsInspector - q.v1 = newInspectorVersion[*monitoring.ServiceMonitorList, *monitoring.ServiceMonitor](ctx, + q.v1 = newInspectorVersion[*monitoringApi.ServiceMonitorList, *monitoringApi.ServiceMonitor](ctx, constants.ServiceMonitorGRv1(), constants.ServiceMonitorGKv1(), i.client.Monitoring().MonitoringV1().ServiceMonitors(i.namespace), @@ -86,7 +86,7 @@ type serviceMonitorsInspector struct { last time.Time - v1 *inspectorVersion[*monitoring.ServiceMonitor] + v1 *inspectorVersion[*monitoringApi.ServiceMonitor] } func (p *serviceMonitorsInspector) LastRefresh() time.Time { @@ -118,7 +118,7 @@ func (p *serviceMonitorsInspector) validate() error { return p.v1.validate() } -func (p *serviceMonitorsInspector) V1() (generic.Inspector[*monitoring.ServiceMonitor], error) { +func (p *serviceMonitorsInspector) V1() (generic.Inspector[*monitoringApi.ServiceMonitor], error) { if p.v1.err != nil { return nil, p.v1.err } diff --git a/pkg/deployment/resources/inspector/sm_anonymous.go b/pkg/deployment/resources/inspector/sm_anonymous.go index 2c1473772..5892ed139 100644 --- a/pkg/deployment/resources/inspector/sm_anonymous.go +++ b/pkg/deployment/resources/inspector/sm_anonymous.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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,7 +21,7 @@ package inspector import ( - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "k8s.io/apimachinery/pkg/runtime/schema" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" @@ -38,7 +38,7 @@ func (p *serviceMonitorsInspector) Anonymous(gvk schema.GroupVersionKind) (anony if p.v1 == nil || p.v1.err != nil { return nil, false } - return anonymous.NewAnonymous[*monitoring.ServiceMonitor](g, p.state.serviceMonitors.v1, generic.WithModStatus[*monitoring.ServiceMonitor](g, p.state.ServiceMonitorsModInterface().V1())), true + return anonymous.NewAnonymous[*monitoringApi.ServiceMonitor](g, p.state.serviceMonitors.v1, generic.WithModStatus[*monitoringApi.ServiceMonitor](g, p.state.ServiceMonitorsModInterface().V1())), true } } diff --git a/pkg/deployment/resources/inspector/sm_mod.go b/pkg/deployment/resources/inspector/sm_mod.go index 6b24ce564..e2b50fb06 100644 --- a/pkg/deployment/resources/inspector/sm_mod.go +++ b/pkg/deployment/resources/inspector/sm_mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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,7 +21,7 @@ package inspector import ( - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" @@ -39,10 +39,10 @@ type serviceMonitorsMod struct { i *inspectorState } -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)) +func (p serviceMonitorsMod) V1() generic.ModClient[*monitoringApi.ServiceMonitor] { + return wrapMod[*monitoringApi.ServiceMonitor](definitions.ServiceMonitor, p.i.GetThrottles, generic.WithModStatusGetter[*monitoringApi.ServiceMonitor](constants.ServiceMonitorGKv1(), p.clientv1)) } -func (p serviceMonitorsMod) clientv1() generic.ModClient[*monitoring.ServiceMonitor] { +func (p serviceMonitorsMod) clientv1() generic.ModClient[*monitoringApi.ServiceMonitor] { return p.i.Client().Monitoring().MonitoringV1().ServiceMonitors(p.i.Namespace()) } diff --git a/pkg/deployment/resources/labels.go b/pkg/deployment/resources/labels.go index 612521612..eb6aaa87e 100644 --- a/pkg/deployment/resources/labels.go +++ b/pkg/deployment/resources/labels.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -23,7 +23,7 @@ package resources import ( "context" - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" core "k8s.io/api/core/v1" policy "k8s.io/api/policy/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -159,7 +159,7 @@ func (r *Resources) EnsureServiceMonitorsLabels(ctx context.Context, cachedStatu } return err } - if err := i.Iterate(func(serviceMonitor *monitoring.ServiceMonitor) error { + if err := i.Iterate(func(serviceMonitor *monitoringApi.ServiceMonitor) error { if r.ensureLabelsMap(serviceMonitor.Kind, serviceMonitor, r.context.GetSpec(), func(name string, d []byte) error { return globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { _, err := cachedStatus.ServiceMonitorsModInterface().V1().Patch(ctxChild, name, types.JSONPatchType, d, meta.PatchOptions{}) @@ -170,7 +170,7 @@ func (r *Resources) EnsureServiceMonitorsLabels(ctx context.Context, cachedStatu } return nil - }, func(serviceMonitor *monitoring.ServiceMonitor) bool { + }, func(serviceMonitor *monitoringApi.ServiceMonitor) bool { return r.isChildResource(serviceMonitor) }); err != nil { return err diff --git a/pkg/deployment/resources/servicemonitor.go b/pkg/deployment/resources/servicemonitor.go index 947fc4884..5ee553977 100644 --- a/pkg/deployment/resources/servicemonitor.go +++ b/pkg/deployment/resources/servicemonitor.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2019-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2019-2025 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. @@ -23,7 +23,7 @@ package resources import ( "context" - coreosv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "k8s.io/apimachinery/pkg/api/equality" apiErrors "k8s.io/apimachinery/pkg/api/errors" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -59,20 +59,20 @@ func LabelsForExporterServiceMonitorSelector(name string) map[string]string { } } -func (r *Resources) makeEndpoint(isSecure bool) coreosv1.Endpoint { +func (r *Resources) makeEndpoint(isSecure bool) monitoringApi.Endpoint { if isSecure { - return coreosv1.Endpoint{ + return monitoringApi.Endpoint{ Port: "exporter", Interval: "10s", Scheme: "https", - TLSConfig: &coreosv1.TLSConfig{ - SafeTLSConfig: coreosv1.SafeTLSConfig{ + TLSConfig: &monitoringApi.TLSConfig{ + SafeTLSConfig: monitoringApi.SafeTLSConfig{ InsecureSkipVerify: true, }, }, } } else { - return coreosv1.Endpoint{ + return monitoringApi.Endpoint{ Port: "exporter", Interval: "10s", Scheme: "http", @@ -80,7 +80,7 @@ func (r *Resources) makeEndpoint(isSecure bool) coreosv1.Endpoint { } } -func (r *Resources) serviceMonitorSpec() (coreosv1.ServiceMonitorSpec, error) { +func (r *Resources) serviceMonitorSpec() (monitoringApi.ServiceMonitorSpec, error) { apiObject := r.context.GetAPIObject() deploymentName := apiObject.GetName() spec := r.context.GetSpec() @@ -89,7 +89,7 @@ func (r *Resources) serviceMonitorSpec() (coreosv1.ServiceMonitorSpec, error) { switch spec.Metrics.Mode.Get() { case deploymentApi.MetricsModeInternal: if spec.Metrics.Authentication.JWTTokenSecretName == nil { - return coreosv1.ServiceMonitorSpec{}, apiErrors.NewNotFound(schema.GroupResource{Group: "v1/secret"}, "metrics-secret") + return monitoringApi.ServiceMonitorSpec{}, apiErrors.NewNotFound(schema.GroupResource{Group: "v1/secret"}, "metrics-secret") } endpoint := r.makeEndpoint(spec.IsSecure()) @@ -100,9 +100,9 @@ func (r *Resources) serviceMonitorSpec() (coreosv1.ServiceMonitorSpec, error) { version := r.context.GetMembersState().State().Version.Version endpoint.Path = getArangoExporterInternalEndpoint(version) - return coreosv1.ServiceMonitorSpec{ + return monitoringApi.ServiceMonitorSpec{ JobLabel: "k8s-app", - Endpoints: []coreosv1.Endpoint{ + Endpoints: []monitoringApi.Endpoint{ endpoint, }, Selector: meta.LabelSelector{ @@ -110,9 +110,9 @@ func (r *Resources) serviceMonitorSpec() (coreosv1.ServiceMonitorSpec, error) { }, }, nil default: - return coreosv1.ServiceMonitorSpec{ + return monitoringApi.ServiceMonitorSpec{ JobLabel: "k8s-app", - Endpoints: []coreosv1.Endpoint{ + Endpoints: []monitoringApi.Endpoint{ r.makeEndpoint(spec.IsSecure()), }, Selector: meta.LabelSelector{ @@ -168,7 +168,7 @@ func (r *Resources) EnsureServiceMonitor(ctx context.Context, enabled bool) erro } // Need to create one: - smon := &coreosv1.ServiceMonitor{ + smon := &monitoringApi.ServiceMonitor{ ObjectMeta: meta.ObjectMeta{ Name: serviceMonitorName, Labels: LabelsForExporterServiceMonitor(r.context.GetName(), r.context.GetSpec()), diff --git a/pkg/platform/helm_registry.go b/pkg/platform/helm_registry.go index acc6fb12d..c225f56c6 100644 --- a/pkg/platform/helm_registry.go +++ b/pkg/platform/helm_registry.go @@ -24,9 +24,8 @@ import ( "github.com/spf13/cobra" platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1" - "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/helm" "github.com/arangodb/kube-arangodb/pkg/util/kclient" ) @@ -41,20 +40,5 @@ func fetchLocallyInstalledCharts(cmd *cobra.Command) (map[string]*platformApi.Ar return nil, err } - l, err := kubernetes.ListObjects[*platformApi.ArangoPlatformChartList, *platformApi.ArangoPlatformChart](cmd.Context(), client.Arango().PlatformV1alpha1().ArangoPlatformCharts(namespace), func(result *platformApi.ArangoPlatformChartList) []*platformApi.ArangoPlatformChart { - q := make([]*platformApi.ArangoPlatformChart, len(result.Items)) - - for id, e := range result.Items { - q[id] = e.DeepCopy() - } - - return q - }) - if err != nil { - return nil, err - } - - return util.ListAsMap(l, func(in *platformApi.ArangoPlatformChart) string { - return in.GetName() - }), nil + return helm.GetLocalCharts(cmd.Context(), client, namespace) } diff --git a/pkg/platform/package.go b/pkg/platform/package.go index b6f69e83c..8325f0dd8 100644 --- a/pkg/platform/package.go +++ b/pkg/platform/package.go @@ -24,21 +24,8 @@ import ( "github.com/spf13/cobra" "github.com/arangodb/kube-arangodb/pkg/util/cli" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm" ) -type Package struct { - Packages map[string]string `json:"packages,omitempty"` - - Releases map[string]Release `json:"releases,omitempty"` -} - -type Release struct { - Package string `json:"package"` - - Overrides helm.Values `json:"overrides,omitempty"` -} - func pkg() (*cobra.Command, error) { var cmd cobra.Command diff --git a/pkg/platform/package_dump.go b/pkg/platform/package_dump.go index bbe8bc306..09d58ba02 100644 --- a/pkg/platform/package_dump.go +++ b/pkg/platform/package_dump.go @@ -24,15 +24,12 @@ import ( "encoding/json" "github.com/spf13/cobra" - "helm.sh/helm/v3/pkg/action" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/yaml" - platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1" "github.com/arangodb/kube-arangodb/pkg/util/cli" - "github.com/arangodb/kube-arangodb/pkg/util/constants" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" ) func packageDump() (*cobra.Command, error) { @@ -51,14 +48,14 @@ func packageDump() (*cobra.Command, error) { } func packageDumpRun(cmd *cobra.Command, args []string) error { - charts, err := fetchLocallyInstalledCharts(cmd) - if err != nil { - return err + client, ok := kclient.GetDefaultFactory().Client() + if !ok { + return errors.Errorf("Unable to get client") } - hclient, err := getHelmClient(cmd) + ns, err := flagNamespace.Get(cmd) if err != nil { - return errors.Wrapf(err, "Unable to get helm client") + return err } if len(args) < 1 { @@ -67,62 +64,9 @@ func packageDumpRun(cmd *cobra.Command, args []string) error { deployment := args[0] - var out Package - - out.Packages = map[string]string{} - - out.Releases = map[string]Release{} - - for name, c := range charts { - if !c.Status.Conditions.IsTrue(platformApi.ReadyCondition) { - return errors.Errorf("Chart `%s` is not in ready condition", name) - } - if info := c.Status.Info; info != nil { - if det := info.Details; det != nil { - out.Packages[name] = c.Status.Info.Details.GetVersion() - } - } - - existingReleases, err := hclient.List(cmd.Context(), func(in *action.List) { - in.Selector = meta.FormatLabelSelector(&meta.LabelSelector{ - MatchLabels: map[string]string{ - constants.HelmLabelArangoDBManaged: "true", - constants.HelmLabelArangoDBDeployment: deployment, - constants.HelmLabelArangoDBChart: name, - constants.HelmLabelArangoDBType: "platform", - }, - }) - }) - if err != nil { - logger.Err(err).Error("Unable to list releases") - return err - } - - for _, release := range existingReleases { - var r Release - - r.Package = name - - data, err := release.Values.Marshal() - if err != nil { - logger.Err(err).Error("Unable to unmarshal values") - return err - } - - delete(data, "arangodb_platform") - - if len(data) != 0 { - values, err := helm.NewValues(data) - if err != nil { - logger.Err(err).Error("Unable to marshal values") - return err - } - - r.Overrides = values - } - - out.Releases[release.Name] = r - } + out, err := helm.NewPackage(cmd.Context(), client, ns, deployment) + if err != nil { + return err } d, err := json.Marshal(out) diff --git a/pkg/platform/package_install.go b/pkg/platform/package_install.go index 9c8dbdd10..3a114f848 100644 --- a/pkg/platform/package_install.go +++ b/pkg/platform/package_install.go @@ -92,7 +92,7 @@ func packageInstallRun(cmd *cobra.Command, args []string) error { return err } - r, err := util.JsonOrYamlUnmarshal[Package](data) + r, err := util.JsonOrYamlUnmarshal[helm.Package](data) if err != nil { logger.Err(err).Error("Unable to read the file") return err diff --git a/pkg/util/k8sutil/helm/charts.go b/pkg/util/k8sutil/helm/charts.go new file mode 100644 index 000000000..0ca4d1560 --- /dev/null +++ b/pkg/util/k8sutil/helm/charts.go @@ -0,0 +1,49 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 helm + +import ( + "context" + + platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1" + "github.com/arangodb/kube-arangodb/pkg/util" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func GetLocalCharts(ctx context.Context, client kclient.Client, namespace string) (map[string]*platformApi.ArangoPlatformChart, error) { + l, err := list.ListObjects[*platformApi.ArangoPlatformChartList, *platformApi.ArangoPlatformChart](ctx, client.Arango().PlatformV1alpha1().ArangoPlatformCharts(namespace), func(result *platformApi.ArangoPlatformChartList) []*platformApi.ArangoPlatformChart { + q := make([]*platformApi.ArangoPlatformChart, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) + if err != nil { + return nil, err + } + + return util.ListAsMap(l, func(in *platformApi.ArangoPlatformChart) string { + return in.GetName() + }), nil +} diff --git a/pkg/util/k8sutil/helm/package.go b/pkg/util/k8sutil/helm/package.go new file mode 100644 index 000000000..16466ed81 --- /dev/null +++ b/pkg/util/k8sutil/helm/package.go @@ -0,0 +1,121 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 helm + +import ( + "context" + + "helm.sh/helm/v3/pkg/action" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + + platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1" + "github.com/arangodb/kube-arangodb/pkg/util/constants" + "github.com/arangodb/kube-arangodb/pkg/util/errors" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +type Package struct { + Packages map[string]string `json:"packages,omitempty"` + + Releases map[string]PackageRelease `json:"releases,omitempty"` +} + +type PackageRelease struct { + Package string `json:"package"` + + Overrides Values `json:"overrides,omitempty"` +} + +func NewPackage(ctx context.Context, client kclient.Client, namespace, deployment string) (*Package, error) { + hclient, err := NewClient(Configuration{ + Namespace: namespace, + Config: client.Config(), + Driver: nil, + }) + if err != nil { + return nil, err + } + + charts, err := GetLocalCharts(ctx, client, namespace) + if err != nil { + return nil, err + } + + var out Package + + out.Packages = map[string]string{} + + out.Releases = map[string]PackageRelease{} + + for name, c := range charts { + if !c.Status.Conditions.IsTrue(platformApi.ReadyCondition) { + return nil, errors.Errorf("Chart `%s` is not in ready condition", name) + } + if info := c.Status.Info; info != nil { + if det := info.Details; det != nil { + out.Packages[name] = c.Status.Info.Details.GetVersion() + } + } + + existingReleases, err := hclient.List(ctx, func(in *action.List) { + in.Selector = meta.FormatLabelSelector(&meta.LabelSelector{ + MatchLabels: map[string]string{ + constants.HelmLabelArangoDBManaged: "true", + constants.HelmLabelArangoDBDeployment: deployment, + constants.HelmLabelArangoDBChart: name, + constants.HelmLabelArangoDBType: "platform", + }, + }) + }) + if err != nil { + logger.Err(err).Error("Unable to list releases") + return nil, err + } + + for _, release := range existingReleases { + var r PackageRelease + + r.Package = name + + data, err := release.Values.Marshal() + if err != nil { + logger.Err(err).Error("Unable to unmarshal values") + return nil, err + } + + delete(data, "arangodb_platform") + + if len(data) != 0 { + values, err := NewValues(data) + if err != nil { + logger.Err(err).Error("Unable to marshal values") + return nil, err + } + + r.Overrides = values + } + + out.Releases[release.Name] = r + } + } + + return &out, nil +} diff --git a/pkg/util/k8sutil/helm/types.go b/pkg/util/k8sutil/helm/types.go index 3c906c7b7..aa0abf544 100644 --- a/pkg/util/k8sutil/helm/types.go +++ b/pkg/util/k8sutil/helm/types.go @@ -83,6 +83,7 @@ func fromHelmReleaseChartMetadata(in *chart.Metadata) *ReleaseChartMetadata { var r ReleaseChartMetadata r.Version = in.Version + r.Name = in.Name return &r } @@ -136,16 +137,16 @@ func fromHelmReleaseInfoResources(in map[string][]runtime.Object) (Resources, er } type Release struct { - Name string + Name string `json:"name,omitempty"` - Info ReleaseInfo - Chart *ReleaseChart + Info ReleaseInfo `json:"info"` + Chart *ReleaseChart `json:"chart,omitempty"` - Values Values + Values Values `json:"values,omitempty"` - Version int - Namespace string - Labels map[string]string + Version int `json:"version,omitempty"` + Namespace string `json:"namespace,omitempty"` + Labels map[string]string `json:"labels,omitempty"` } func (r *Release) GetChart() *ReleaseChart { @@ -157,7 +158,7 @@ func (r *Release) GetChart() *ReleaseChart { } type ReleaseChart struct { - Metadata *ReleaseChartMetadata + Metadata *ReleaseChartMetadata `json:"metadata,omitempty"` } func (r *ReleaseChart) GetMetadata() *ReleaseChartMetadata { @@ -169,7 +170,16 @@ func (r *ReleaseChart) GetMetadata() *ReleaseChartMetadata { } type ReleaseChartMetadata struct { - Version string + Version string `json:"version,omitempty"` + Name string `json:"name,omitempty"` +} + +func (r *ReleaseChartMetadata) GetName() string { + if r == nil { + return "" + } + + return r.Name } func (r *ReleaseChartMetadata) GetVersion() string { @@ -181,13 +191,13 @@ func (r *ReleaseChartMetadata) GetVersion() string { } type ReleaseInfo struct { - FirstDeployed time.Time - LastDeployed time.Time - Deleted time.Time - Description string - Status release.Status - Notes string - Resources Resources + FirstDeployed time.Time `json:"first_deployed,omitempty"` + LastDeployed time.Time `json:"last_deployed,omitempty"` + Deleted time.Time `json:"deleted,omitempty"` + Description string `json:"description,omitempty"` + Status release.Status `json:"status,omitempty"` + Notes string `json:"notes,omitempty"` + Resources Resources `json:"resources,omitempty"` } type Resources []Resource diff --git a/pkg/util/k8sutil/helpers/updator_test.go b/pkg/util/k8sutil/helpers/updator_test.go index c0855cbf5..f3026ba37 100644 --- a/pkg/util/k8sutil/helpers/updator_test.go +++ b/pkg/util/k8sutil/helpers/updator_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024-2025 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. @@ -36,6 +36,7 @@ import ( sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1" "github.com/arangodb/kube-arangodb/pkg/logging" "github.com/arangodb/kube-arangodb/pkg/util" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" "github.com/arangodb/kube-arangodb/pkg/util/tests" ) @@ -51,7 +52,8 @@ func runUpdate[T Object](t *testing.T, iterations int, factory ClientFactory[T], var obj T - o := tests.GVK(t, obj) + o, ok := constants.ExtractGVKFromObject(obj) + require.True(t, ok) update := NewUpdator[T](Config[T]{ Events: nil, diff --git a/pkg/util/k8sutil/inspector/constants/arango_analytics_engine_constants.go b/pkg/util/k8sutil/inspector/constants/arango_analytics_engine_constants.go new file mode 100644 index 000000000..2a0addd9a --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_analytics_engine_constants.go @@ -0,0 +1,70 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/analytics" + analyticsApi "github.com/arangodb/kube-arangodb/pkg/apis/analytics/v1alpha1" +) + +// ArangoAnalyticsGraphAnalyticsEngine +const ( + ArangoAnalyticsGraphAnalyticsEngineGroup = analytics.ArangoAnalyticsGroupName + ArangoAnalyticsGraphAnalyticsEngineResource = analytics.GraphAnalyticsEngineResourcePlural + ArangoAnalyticsGraphAnalyticsEngineKind = analytics.GraphAnalyticsEngineResourceKind + ArangoAnalyticsGraphAnalyticsEngineVersionV1Alpha1 = analyticsApi.ArangoAnalyticsVersion +) + +func init() { + register[*analyticsApi.GraphAnalyticsEngine](ArangoAnalyticsGraphAnalyticsEngineGKv1Alpha1(), ArangoAnalyticsGraphAnalyticsEngineGRv1Alpha1()) +} + +func ArangoAnalyticsGraphAnalyticsEngineGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoAnalyticsGraphAnalyticsEngineGroup, + Kind: ArangoAnalyticsGraphAnalyticsEngineKind, + } +} + +func ArangoAnalyticsGraphAnalyticsEngineGKv1Alpha1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoAnalyticsGraphAnalyticsEngineGroup, + Kind: ArangoAnalyticsGraphAnalyticsEngineKind, + Version: ArangoAnalyticsGraphAnalyticsEngineVersionV1Alpha1, + } +} + +func ArangoAnalyticsGraphAnalyticsEngineGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoAnalyticsGraphAnalyticsEngineGroup, + Resource: ArangoAnalyticsGraphAnalyticsEngineResource, + } +} + +func ArangoAnalyticsGraphAnalyticsEngineGRv1Alpha1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoAnalyticsGraphAnalyticsEngineGroup, + Resource: ArangoAnalyticsGraphAnalyticsEngineResource, + Version: ArangoAnalyticsGraphAnalyticsEngineVersionV1Alpha1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/arango_backup_backup_constants.go b/pkg/util/k8sutil/inspector/constants/arango_backup_backup_constants.go new file mode 100644 index 000000000..92aa080ce --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_backup_backup_constants.go @@ -0,0 +1,70 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/backup" + v1 "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1" +) + +// ArangoBackup +const ( + ArangoBackupGroup = backup.ArangoBackupGroupName + ArangoBackupResource = backup.ArangoBackupResourcePlural + ArangoBackupKind = backup.ArangoBackupResourceKind + ArangoBackupVersionV1Alpha1 = v1.ArangoBackupVersion +) + +func init() { + register[*v1.ArangoBackup](ArangoBackupGKv1(), ArangoBackupGRv1()) +} + +func ArangoBackupGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoBackupGroup, + Kind: ArangoBackupKind, + } +} + +func ArangoBackupGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoBackupGroup, + Kind: ArangoBackupKind, + Version: ArangoBackupVersionV1Alpha1, + } +} + +func ArangoBackupGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoBackupGroup, + Resource: ArangoBackupResource, + } +} + +func ArangoBackupGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoBackupGroup, + Resource: ArangoBackupResource, + Version: ArangoBackupVersionV1Alpha1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/arango_backup_backuppolicy_constants.go b/pkg/util/k8sutil/inspector/constants/arango_backup_backuppolicy_constants.go new file mode 100644 index 000000000..f32eb4e96 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_backup_backuppolicy_constants.go @@ -0,0 +1,70 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/backup" + v1 "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1" +) + +// ArangoBackupPolicy +const ( + ArangoBackupPolicyGroup = backup.ArangoBackupGroupName + ArangoBackupPolicyResource = backup.ArangoBackupPolicyResourcePlural + ArangoBackupPolicyKind = backup.ArangoBackupPolicyResourceKind + ArangoBackupPolicyVersionV1Alpha1 = v1.ArangoBackupVersion +) + +func init() { + register[*v1.ArangoBackupPolicy](ArangoBackupPolicyGKv1(), ArangoBackupPolicyGRv1()) +} + +func ArangoBackupPolicyGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoBackupPolicyGroup, + Kind: ArangoBackupPolicyKind, + } +} + +func ArangoBackupPolicyGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoBackupPolicyGroup, + Kind: ArangoBackupPolicyKind, + Version: ArangoBackupPolicyVersionV1Alpha1, + } +} + +func ArangoBackupPolicyGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoBackupPolicyGroup, + Resource: ArangoBackupPolicyResource, + } +} + +func ArangoBackupPolicyGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoBackupPolicyGroup, + Resource: ArangoBackupPolicyResource, + Version: ArangoBackupPolicyVersionV1Alpha1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/acs_constants.go b/pkg/util/k8sutil/inspector/constants/arango_database_acs_constants.go similarity index 91% rename from pkg/util/k8sutil/inspector/constants/acs_constants.go rename to pkg/util/k8sutil/inspector/constants/arango_database_acs_constants.go index d67a795b7..bf61eef85 100644 --- a/pkg/util/k8sutil/inspector/constants/acs_constants.go +++ b/pkg/util/k8sutil/inspector/constants/arango_database_acs_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -35,6 +35,10 @@ const ( ArangoClusterSynchronizationVersionV1 = deploymentv1.ArangoDeploymentVersion ) +func init() { + register[*deploymentv1.ArangoClusterSynchronization](ArangoClusterSynchronizationGKv1(), ArangoClusterSynchronizationGRv1()) +} + func ArangoClusterSynchronizationGK() schema.GroupKind { return schema.GroupKind{ Group: ArangoClusterSynchronizationGroup, diff --git a/pkg/util/k8sutil/inspector/constants/ad_constants.go b/pkg/util/k8sutil/inspector/constants/arango_database_deployment_constants.go similarity index 91% rename from pkg/util/k8sutil/inspector/constants/ad_constants.go rename to pkg/util/k8sutil/inspector/constants/arango_database_deployment_constants.go index cec6b6a1d..2dbf4ad69 100644 --- a/pkg/util/k8sutil/inspector/constants/ad_constants.go +++ b/pkg/util/k8sutil/inspector/constants/arango_database_deployment_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -35,6 +35,10 @@ const ( ArangoDeploymentVersionV1 = deploymentv1.ArangoDeploymentVersion ) +func init() { + register[*deploymentv1.ArangoDeployment](ArangoDeploymentGKv1(), ArangoDeploymentGRv1()) +} + func ArangoDeploymentGK() schema.GroupKind { return schema.GroupKind{ Group: ArangoDeploymentGroup, diff --git a/pkg/util/k8sutil/inspector/constants/am_constants.go b/pkg/util/k8sutil/inspector/constants/arango_database_member_constants.go similarity index 92% rename from pkg/util/k8sutil/inspector/constants/am_constants.go rename to pkg/util/k8sutil/inspector/constants/arango_database_member_constants.go index fc1e681d8..bd96362f1 100644 --- a/pkg/util/k8sutil/inspector/constants/am_constants.go +++ b/pkg/util/k8sutil/inspector/constants/arango_database_member_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -35,6 +35,10 @@ const ( ArangoMemberVersionV1 = deploymentv1.ArangoDeploymentVersion ) +func init() { + register[*deploymentv1.ArangoMember](ArangoMemberGKv1(), ArangoMemberGRv1()) +} + func ArangoMemberGK() schema.GroupKind { return schema.GroupKind{ Group: ArangoMemberGroup, diff --git a/pkg/util/k8sutil/inspector/constants/at_constants.go b/pkg/util/k8sutil/inspector/constants/arango_database_task_constants.go similarity index 92% rename from pkg/util/k8sutil/inspector/constants/at_constants.go rename to pkg/util/k8sutil/inspector/constants/arango_database_task_constants.go index 7a55f1fa2..85de212ee 100644 --- a/pkg/util/k8sutil/inspector/constants/at_constants.go +++ b/pkg/util/k8sutil/inspector/constants/arango_database_task_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -35,6 +35,10 @@ const ( ArangoTaskVersionV1 = deploymentv1.ArangoDeploymentVersion ) +func init() { + register[*deploymentv1.ArangoTask](ArangoTaskGKv1(), ArangoTaskGRv1()) +} + func ArangoTaskGK() schema.GroupKind { return schema.GroupKind{ Group: ArangoTaskGroup, diff --git a/pkg/util/k8sutil/inspector/constants/arango_ml_batchjob_constants.go b/pkg/util/k8sutil/inspector/constants/arango_ml_batchjob_constants.go new file mode 100644 index 000000000..5e60b856f --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_ml_batchjob_constants.go @@ -0,0 +1,70 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/ml" + mlApiv1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1alpha1" +) + +// ArangoMLBatchJob +const ( + ArangoMLBatchJobGroup = ml.ArangoMLGroupName + ArangoMLBatchJobResource = ml.ArangoMLBatchJobResourcePlural + ArangoMLBatchJobKind = ml.ArangoMLBatchJobResourceKind + ArangoMLBatchJobVersionV1Alpha1 = mlApiv1alpha1.ArangoMLVersion +) + +func init() { + register[*mlApiv1alpha1.ArangoMLBatchJob](ArangoMLBatchJobGKv1Alpha1(), ArangoMLBatchJobGRv1Alpha1()) +} + +func ArangoMLBatchJobGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoMLBatchJobGroup, + Kind: ArangoMLBatchJobKind, + } +} + +func ArangoMLBatchJobGKv1Alpha1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoMLBatchJobGroup, + Kind: ArangoMLBatchJobKind, + Version: ArangoMLBatchJobVersionV1Alpha1, + } +} + +func ArangoMLBatchJobGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoMLBatchJobGroup, + Resource: ArangoMLBatchJobResource, + } +} + +func ArangoMLBatchJobGRv1Alpha1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoMLBatchJobGroup, + Resource: ArangoMLBatchJobResource, + Version: ArangoMLBatchJobVersionV1Alpha1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/arango_ml_cronjob_constants.go b/pkg/util/k8sutil/inspector/constants/arango_ml_cronjob_constants.go new file mode 100644 index 000000000..07de3094a --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_ml_cronjob_constants.go @@ -0,0 +1,70 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/ml" + mlApiv1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1alpha1" +) + +// ArangoMLCronJob +const ( + ArangoMLCronJobGroup = ml.ArangoMLGroupName + ArangoMLCronJobResource = ml.ArangoMLCronJobResourcePlural + ArangoMLCronJobKind = ml.ArangoMLCronJobResourceKind + ArangoMLCronJobVersionV1Alpha1 = mlApiv1alpha1.ArangoMLVersion +) + +func init() { + register[*mlApiv1alpha1.ArangoMLCronJob](ArangoMLCronJobGKv1Alpha1(), ArangoMLCronJobGRv1Alpha1()) +} + +func ArangoMLCronJobGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoMLCronJobGroup, + Kind: ArangoMLCronJobKind, + } +} + +func ArangoMLCronJobGKv1Alpha1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoMLCronJobGroup, + Kind: ArangoMLCronJobKind, + Version: ArangoMLCronJobVersionV1Alpha1, + } +} + +func ArangoMLCronJobGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoMLCronJobGroup, + Resource: ArangoMLCronJobResource, + } +} + +func ArangoMLCronJobGRv1Alpha1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoMLCronJobGroup, + Resource: ArangoMLCronJobResource, + Version: ArangoMLCronJobVersionV1Alpha1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/arango_ml_extension_constants.go b/pkg/util/k8sutil/inspector/constants/arango_ml_extension_constants.go new file mode 100644 index 000000000..0f7064c93 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_ml_extension_constants.go @@ -0,0 +1,89 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/ml" + mlApiv1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1alpha1" + mlApi "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1beta1" +) + +// ArangoMLExtension +const ( + ArangoMLExtensionGroup = ml.ArangoMLGroupName + ArangoMLExtensionResource = ml.ArangoMLExtensionResourcePlural + ArangoMLExtensionKind = ml.ArangoMLExtensionResourceKind + ArangoMLExtensionVersionV1Alpha1 = mlApiv1alpha1.ArangoMLVersion + ArangoMLExtensionVersionV1Beta1 = mlApi.ArangoMLVersion +) + +func init() { + register[*mlApiv1alpha1.ArangoMLExtension](ArangoMLExtensionGKv1Alpha1(), ArangoMLExtensionGRv1Alpha1()) + register[*mlApi.ArangoMLExtension](ArangoMLExtensionGKv1Beta1(), ArangoMLExtensionGRv1Beta1()) +} + +func ArangoMLExtensionGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoMLExtensionGroup, + Kind: ArangoMLExtensionKind, + } +} + +func ArangoMLExtensionGKv1Alpha1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoMLExtensionGroup, + Kind: ArangoMLExtensionKind, + Version: ArangoMLExtensionVersionV1Alpha1, + } +} + +func ArangoMLExtensionGKv1Beta1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoMLExtensionGroup, + Kind: ArangoMLExtensionKind, + Version: ArangoMLExtensionVersionV1Beta1, + } +} + +func ArangoMLExtensionGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoMLExtensionGroup, + Resource: ArangoMLExtensionResource, + } +} + +func ArangoMLExtensionGRv1Alpha1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoMLExtensionGroup, + Resource: ArangoMLExtensionResource, + Version: ArangoMLExtensionVersionV1Alpha1, + } +} + +func ArangoMLExtensionGRv1Beta1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoMLExtensionGroup, + Resource: ArangoMLExtensionResource, + Version: ArangoMLExtensionVersionV1Beta1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/arango_ml_storage_constants.go b/pkg/util/k8sutil/inspector/constants/arango_ml_storage_constants.go new file mode 100644 index 000000000..5698e6361 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_ml_storage_constants.go @@ -0,0 +1,89 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/ml" + mlApiv1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1alpha1" + mlApi "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1beta1" +) + +// ArangoMLStorage +const ( + ArangoMLStorageGroup = ml.ArangoMLGroupName + ArangoMLStorageResource = ml.ArangoMLStorageResourcePlural + ArangoMLStorageKind = ml.ArangoMLStorageResourceKind + ArangoMLStorageVersionV1Alpha1 = mlApiv1alpha1.ArangoMLVersion + ArangoMLStorageVersionV1Beta1 = mlApi.ArangoMLVersion +) + +func init() { + register[*mlApiv1alpha1.ArangoMLStorage](ArangoMLStorageGKv1Alpha1(), ArangoMLStorageGRv1Alpha1()) + register[*mlApi.ArangoMLStorage](ArangoMLStorageGKv1Beta1(), ArangoMLStorageGRv1Beta1()) +} + +func ArangoMLStorageGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoMLStorageGroup, + Kind: ArangoMLStorageKind, + } +} + +func ArangoMLStorageGKv1Alpha1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoMLStorageGroup, + Kind: ArangoMLStorageKind, + Version: ArangoMLStorageVersionV1Alpha1, + } +} + +func ArangoMLStorageGKv1Beta1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoMLStorageGroup, + Kind: ArangoMLStorageKind, + Version: ArangoMLStorageVersionV1Beta1, + } +} + +func ArangoMLStorageGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoMLStorageGroup, + Resource: ArangoMLStorageResource, + } +} + +func ArangoMLStorageGRv1Alpha1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoMLStorageGroup, + Resource: ArangoMLStorageResource, + Version: ArangoMLStorageVersionV1Alpha1, + } +} + +func ArangoMLStorageGRv1Beta1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoMLStorageGroup, + Resource: ArangoMLStorageResource, + Version: ArangoMLStorageVersionV1Beta1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/ar_constants.go b/pkg/util/k8sutil/inspector/constants/arango_networking_route_constants.go similarity index 86% rename from pkg/util/k8sutil/inspector/constants/ar_constants.go rename to pkg/util/k8sutil/inspector/constants/arango_networking_route_constants.go index 13541bd93..1bc6b825d 100644 --- a/pkg/util/k8sutil/inspector/constants/ar_constants.go +++ b/pkg/util/k8sutil/inspector/constants/arango_networking_route_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -35,6 +35,10 @@ const ( ArangoRouteVersionV1Alpha1 = networkingApi.ArangoNetworkingVersion ) +func init() { + register[*networkingApi.ArangoRoute](ArangoRouteGKv1Alpha1(), ArangoRouteGRv1Alpha1()) +} + func ArangoRouteGK() schema.GroupKind { return schema.GroupKind{ Group: ArangoRouteGroup, @@ -42,7 +46,7 @@ func ArangoRouteGK() schema.GroupKind { } } -func ArangoRouteGKv1() schema.GroupVersionKind { +func ArangoRouteGKv1Alpha1() schema.GroupVersionKind { return schema.GroupVersionKind{ Group: ArangoRouteGroup, Kind: ArangoRouteKind, @@ -57,7 +61,7 @@ func ArangoRouteGR() schema.GroupResource { } } -func ArangoRouteGRv1() schema.GroupVersionResource { +func ArangoRouteGRv1Alpha1() schema.GroupVersionResource { return schema.GroupVersionResource{ Group: ArangoRouteGroup, Resource: ArangoRouteResource, diff --git a/pkg/util/k8sutil/inspector/constants/arango_platform_chart_constants.go b/pkg/util/k8sutil/inspector/constants/arango_platform_chart_constants.go new file mode 100644 index 000000000..a405fdeb6 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_platform_chart_constants.go @@ -0,0 +1,70 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/platform" + platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1" +) + +// ArangoPlatformChart +const ( + ArangoPlatformChartGroup = platform.ArangoPlatformGroupName + ArangoPlatformChartResource = platform.ArangoPlatformChartResourcePlural + ArangoPlatformChartKind = platform.ArangoPlatformChartResourceKind + ArangoPlatformChartVersionV1Alpha1 = platformApi.ArangoPlatformVersion +) + +func init() { + register[*platformApi.ArangoPlatformChart](ArangoPlatformChartGKv1Beta1(), ArangoPlatformChartGRv1Beta1()) +} + +func ArangoPlatformChartGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoPlatformChartGroup, + Kind: ArangoPlatformChartKind, + } +} + +func ArangoPlatformChartGKv1Beta1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoPlatformChartGroup, + Kind: ArangoPlatformChartKind, + Version: ArangoPlatformChartVersionV1Alpha1, + } +} + +func ArangoPlatformChartGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoPlatformChartGroup, + Resource: ArangoPlatformChartResource, + } +} + +func ArangoPlatformChartGRv1Beta1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoPlatformChartGroup, + Resource: ArangoPlatformChartResource, + Version: ArangoPlatformChartVersionV1Alpha1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/aps_constants.go b/pkg/util/k8sutil/inspector/constants/arango_platform_storage_constants.go similarity index 66% rename from pkg/util/k8sutil/inspector/constants/aps_constants.go rename to pkg/util/k8sutil/inspector/constants/arango_platform_storage_constants.go index a993b2126..9454d495a 100644 --- a/pkg/util/k8sutil/inspector/constants/aps_constants.go +++ b/pkg/util/k8sutil/inspector/constants/arango_platform_storage_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -29,12 +29,16 @@ import ( // ArangoPlatformStorage const ( - ArangoPlatformStorageGroup = platform.ArangoPlatformGroupName - ArangoPlatformStorageResource = platform.ArangoPlatformStorageResourcePlural - ArangoPlatformStorageKind = platform.ArangoPlatformStorageResourceKind - ArangoPlatformStorageVersionV1Beta1 = platformApi.ArangoPlatformVersion + ArangoPlatformStorageGroup = platform.ArangoPlatformGroupName + ArangoPlatformStorageResource = platform.ArangoPlatformStorageResourcePlural + ArangoPlatformStorageKind = platform.ArangoPlatformStorageResourceKind + ArangoPlatformStorageVersionV1Alpha1 = platformApi.ArangoPlatformVersion ) +func init() { + register[*platformApi.ArangoPlatformStorage](ArangoPlatformStorageGKv1Alpha1(), ArangoPlatformStorageGRv1Alpha1()) +} + func ArangoPlatformStorageGK() schema.GroupKind { return schema.GroupKind{ Group: ArangoPlatformStorageGroup, @@ -42,11 +46,11 @@ func ArangoPlatformStorageGK() schema.GroupKind { } } -func ArangoPlatformStorageGKv1() schema.GroupVersionKind { +func ArangoPlatformStorageGKv1Alpha1() schema.GroupVersionKind { return schema.GroupVersionKind{ Group: ArangoPlatformStorageGroup, Kind: ArangoPlatformStorageKind, - Version: ArangoPlatformStorageVersionV1Beta1, + Version: ArangoPlatformStorageVersionV1Alpha1, } } @@ -57,10 +61,10 @@ func ArangoPlatformStorageGR() schema.GroupResource { } } -func ArangoPlatformStorageGRv1() schema.GroupVersionResource { +func ArangoPlatformStorageGRv1Alpha1() schema.GroupVersionResource { return schema.GroupVersionResource{ Group: ArangoPlatformStorageGroup, Resource: ArangoPlatformStorageResource, - Version: ArangoPlatformStorageVersionV1Beta1, + Version: ArangoPlatformStorageVersionV1Alpha1, } } diff --git a/pkg/util/k8sutil/inspector/constants/arango_scheduler_batchjob_constants.go b/pkg/util/k8sutil/inspector/constants/arango_scheduler_batchjob_constants.go new file mode 100644 index 000000000..1008be7f7 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_scheduler_batchjob_constants.go @@ -0,0 +1,70 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/scheduler" + schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" +) + +// ArangoSchedulerBatchJob +const ( + ArangoSchedulerBatchJobGroup = scheduler.ArangoSchedulerGroupName + ArangoSchedulerBatchJobResource = scheduler.BatchJobResourcePlural + ArangoSchedulerBatchJobKind = scheduler.BatchJobResourceKind + ArangoSchedulerBatchJobVersionV1Beta1 = schedulerApi.ArangoSchedulerVersion +) + +func init() { + register[*schedulerApi.ArangoSchedulerBatchJob](ArangoSchedulerBatchJobGKv1Beta1(), ArangoSchedulerBatchJobGRv1Beta1()) +} + +func ArangoSchedulerBatchJobGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoSchedulerBatchJobGroup, + Kind: ArangoSchedulerBatchJobKind, + } +} + +func ArangoSchedulerBatchJobGKv1Beta1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoSchedulerBatchJobGroup, + Kind: ArangoSchedulerBatchJobKind, + Version: ArangoSchedulerBatchJobVersionV1Beta1, + } +} + +func ArangoSchedulerBatchJobGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoSchedulerBatchJobGroup, + Resource: ArangoSchedulerBatchJobResource, + } +} + +func ArangoSchedulerBatchJobGRv1Beta1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoSchedulerBatchJobGroup, + Resource: ArangoSchedulerBatchJobResource, + Version: ArangoSchedulerBatchJobVersionV1Beta1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/arango_scheduler_cronjob_constants.go b/pkg/util/k8sutil/inspector/constants/arango_scheduler_cronjob_constants.go new file mode 100644 index 000000000..3f8014c54 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_scheduler_cronjob_constants.go @@ -0,0 +1,70 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/scheduler" + schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" +) + +// ArangoSchedulerCronJob +const ( + ArangoSchedulerCronJobGroup = scheduler.ArangoSchedulerGroupName + ArangoSchedulerCronJobResource = scheduler.CronJobResourcePlural + ArangoSchedulerCronJobKind = scheduler.CronJobResourceKind + ArangoSchedulerCronJobVersionV1Beta1 = schedulerApi.ArangoSchedulerVersion +) + +func init() { + register[*schedulerApi.ArangoSchedulerCronJob](ArangoSchedulerCronJobGKv1Beta1(), ArangoSchedulerCronJobGRv1Beta1()) +} + +func ArangoSchedulerCronJobGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoSchedulerCronJobGroup, + Kind: ArangoSchedulerCronJobKind, + } +} + +func ArangoSchedulerCronJobGKv1Beta1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoSchedulerCronJobGroup, + Kind: ArangoSchedulerCronJobKind, + Version: ArangoSchedulerCronJobVersionV1Beta1, + } +} + +func ArangoSchedulerCronJobGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoSchedulerCronJobGroup, + Resource: ArangoSchedulerCronJobResource, + } +} + +func ArangoSchedulerCronJobGRv1Beta1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoSchedulerCronJobGroup, + Resource: ArangoSchedulerCronJobResource, + Version: ArangoSchedulerCronJobVersionV1Beta1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/arango_scheduler_deployment_constants.go b/pkg/util/k8sutil/inspector/constants/arango_scheduler_deployment_constants.go new file mode 100644 index 000000000..a42a5e4e3 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_scheduler_deployment_constants.go @@ -0,0 +1,70 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/scheduler" + schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" +) + +// ArangoSchedulerDeployment +const ( + ArangoSchedulerDeploymentGroup = scheduler.ArangoSchedulerGroupName + ArangoSchedulerDeploymentResource = scheduler.DeploymentResourcePlural + ArangoSchedulerDeploymentKind = scheduler.DeploymentResourceKind + ArangoSchedulerDeploymentVersionV1Beta1 = schedulerApi.ArangoSchedulerVersion +) + +func init() { + register[*schedulerApi.ArangoSchedulerDeployment](ArangoSchedulerDeploymentGKv1Beta1(), ArangoSchedulerDeploymentGRv1Beta1()) +} + +func ArangoSchedulerDeploymentGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoSchedulerDeploymentGroup, + Kind: ArangoSchedulerDeploymentKind, + } +} + +func ArangoSchedulerDeploymentGKv1Beta1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoSchedulerDeploymentGroup, + Kind: ArangoSchedulerDeploymentKind, + Version: ArangoSchedulerDeploymentVersionV1Beta1, + } +} + +func ArangoSchedulerDeploymentGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoSchedulerDeploymentGroup, + Resource: ArangoSchedulerDeploymentResource, + } +} + +func ArangoSchedulerDeploymentGRv1Beta1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoSchedulerDeploymentGroup, + Resource: ArangoSchedulerDeploymentResource, + Version: ArangoSchedulerDeploymentVersionV1Beta1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/arango_scheduler_pod_constants.go b/pkg/util/k8sutil/inspector/constants/arango_scheduler_pod_constants.go new file mode 100644 index 000000000..c7f8a5a5e --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/arango_scheduler_pod_constants.go @@ -0,0 +1,70 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/apis/scheduler" + schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" +) + +// ArangoSchedulerPod +const ( + ArangoSchedulerPodGroup = scheduler.ArangoSchedulerGroupName + ArangoSchedulerPodResource = scheduler.PodResourcePlural + ArangoSchedulerPodKind = scheduler.PodResourceKind + ArangoSchedulerPodVersionV1Beta1 = schedulerApi.ArangoSchedulerVersion +) + +func init() { + register[*schedulerApi.ArangoSchedulerPod](ArangoSchedulerPodGKv1Beta1(), ArangoSchedulerPodGRv1Beta1()) +} + +func ArangoSchedulerPodGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoSchedulerPodGroup, + Kind: ArangoSchedulerPodKind, + } +} + +func ArangoSchedulerPodGKv1Beta1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoSchedulerPodGroup, + Kind: ArangoSchedulerPodKind, + Version: ArangoSchedulerPodVersionV1Beta1, + } +} + +func ArangoSchedulerPodGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoSchedulerPodGroup, + Resource: ArangoSchedulerPodResource, + } +} + +func ArangoSchedulerPodGRv1Beta1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoSchedulerPodGroup, + Resource: ArangoSchedulerPodResource, + Version: ArangoSchedulerPodVersionV1Beta1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/ap_constants.go b/pkg/util/k8sutil/inspector/constants/arango_scheduler_profile_constants.go similarity index 85% rename from pkg/util/k8sutil/inspector/constants/ap_constants.go rename to pkg/util/k8sutil/inspector/constants/arango_scheduler_profile_constants.go index fdcb4960b..34459f387 100644 --- a/pkg/util/k8sutil/inspector/constants/ap_constants.go +++ b/pkg/util/k8sutil/inspector/constants/arango_scheduler_profile_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -35,6 +35,10 @@ const ( ArangoProfileVersionV1Beta1 = schedulerApi.ArangoSchedulerVersion ) +func init() { + register[*schedulerApi.ArangoProfile](ArangoProfileGKv1Beta1(), ArangoProfileGRv1Beta1()) +} + func ArangoProfileGK() schema.GroupKind { return schema.GroupKind{ Group: ArangoProfileGroup, @@ -42,7 +46,7 @@ func ArangoProfileGK() schema.GroupKind { } } -func ArangoProfileGKv1() schema.GroupVersionKind { +func ArangoProfileGKv1Beta1() schema.GroupVersionKind { return schema.GroupVersionKind{ Group: ArangoProfileGroup, Kind: ArangoProfileKind, @@ -57,7 +61,7 @@ func ArangoProfileGR() schema.GroupResource { } } -func ArangoProfileGRv1() schema.GroupVersionResource { +func ArangoProfileGRv1Beta1() schema.GroupVersionResource { return schema.GroupVersionResource{ Group: ArangoProfileGroup, Resource: ArangoProfileResource, diff --git a/pkg/util/k8sutil/inspector/constants/gvk.go b/pkg/util/k8sutil/inspector/constants/gvk.go deleted file mode 100644 index e1128171d..000000000 --- a/pkg/util/k8sutil/inspector/constants/gvk.go +++ /dev/null @@ -1,71 +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 constants - -import ( - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - core "k8s.io/api/core/v1" - policy "k8s.io/api/policy/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - - 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" -) - -func ExtractGVKFromObject(in interface{}) (schema.GroupVersionKind, bool) { - if in != nil { - switch in.(type) { - case *api.ArangoClusterSynchronization, api.ArangoClusterSynchronization: - return ArangoClusterSynchronizationGKv1(), true - case *api.ArangoMember, api.ArangoMember: - return ArangoMemberGKv1(), true - case *api.ArangoTask, api.ArangoTask: - return ArangoTaskGKv1(), true - case *schedulerApi.ArangoProfile, schedulerApi.ArangoProfile: - return ArangoProfileGKv1(), true - case *networkingApi.ArangoRoute, networkingApi.ArangoRoute: - return ArangoRouteGKv1(), true - case *core.Endpoints, core.Endpoints: - return EndpointsGKv1(), true - case *core.Node, core.Node: - return NodeGKv1(), true - case *policy.PodDisruptionBudget, policy.PodDisruptionBudget: - return PodDisruptionBudgetGKv1(), true - case *core.Pod, core.Pod: - return PodGKv1(), true - case *core.ServiceAccount, core.ServiceAccount: - return ServiceAccountGKv1(), true - case *core.PersistentVolumeClaim, core.PersistentVolumeClaim: - return PersistentVolumeClaimGKv1(), true - case *core.Secret, core.Secret: - return SecretGKv1(), true - case *core.Service, core.Service: - return ServiceGKv1(), true - case *monitoring.ServiceMonitor, monitoring.ServiceMonitor: - return ServiceMonitorGKv1(), true - case *api.ArangoDeployment, api.ArangoDeployment: - return ArangoDeploymentGKv1(), true - } - } - - return schema.GroupVersionKind{}, false -} diff --git a/pkg/util/k8sutil/inspector/constants/gvk_test.go b/pkg/util/k8sutil/inspector/constants/gvk_test.go index de91cb980..3410ad65f 100644 --- a/pkg/util/k8sutil/inspector/constants/gvk_test.go +++ b/pkg/util/k8sutil/inspector/constants/gvk_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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,13 +21,13 @@ package constants import ( - "reflect" "testing" - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "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/apimachinery/pkg/runtime/schema" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" @@ -36,33 +36,28 @@ import ( ) func Test_GVK(t *testing.T) { - testGVK(t, ArangoClusterSynchronizationGKv1(), &api.ArangoClusterSynchronization{}, api.ArangoClusterSynchronization{}) - testGVK(t, ArangoMemberGKv1(), &api.ArangoMember{}, api.ArangoMember{}) - testGVK(t, ArangoTaskGKv1(), &api.ArangoTask{}, api.ArangoTask{}) - testGVK(t, ArangoRouteGKv1(), &networkingApi.ArangoRoute{}, networkingApi.ArangoRoute{}) - testGVK(t, ArangoProfileGKv1(), &schedulerApi.ArangoProfile{}, schedulerApi.ArangoProfile{}) - testGVK(t, ArangoTaskGKv1(), &api.ArangoTask{}, api.ArangoTask{}) - testGVK(t, EndpointsGKv1(), &core.Endpoints{}, core.Endpoints{}) - testGVK(t, NodeGKv1(), &core.Node{}, core.Node{}) - testGVK(t, PodDisruptionBudgetGKv1(), &policy.PodDisruptionBudget{}, policy.PodDisruptionBudget{}) - testGVK(t, PodGKv1(), &core.Pod{}, core.Pod{}) - testGVK(t, ServiceAccountGKv1(), &core.ServiceAccount{}, core.ServiceAccount{}) - testGVK(t, ServiceGKv1(), &core.Service{}, core.Service{}) - testGVK(t, PersistentVolumeClaimGKv1(), &core.PersistentVolumeClaim{}, core.PersistentVolumeClaim{}) - testGVK(t, SecretGKv1(), &core.Secret{}, core.Secret{}) - testGVK(t, ServiceMonitorGKv1(), &monitoring.ServiceMonitor{}, monitoring.ServiceMonitor{}) - testGVK(t, ArangoDeploymentGKv1(), &api.ArangoDeployment{}, api.ArangoDeployment{}) + testGVK(t, ArangoClusterSynchronizationGKv1(), &api.ArangoClusterSynchronization{}) + testGVK(t, ArangoMemberGKv1(), &api.ArangoMember{}) + testGVK(t, ArangoTaskGKv1(), &api.ArangoTask{}) + testGVK(t, ArangoRouteGKv1Alpha1(), &networkingApi.ArangoRoute{}) + testGVK(t, ArangoProfileGKv1Beta1(), &schedulerApi.ArangoProfile{}) + testGVK(t, ArangoTaskGKv1(), &api.ArangoTask{}) + testGVK(t, EndpointsGKv1(), &core.Endpoints{}) + testGVK(t, NodeGKv1(), &core.Node{}) + testGVK(t, PodDisruptionBudgetGKv1(), &policy.PodDisruptionBudget{}) + testGVK(t, PodGKv1(), &core.Pod{}) + testGVK(t, ServiceAccountGKv1(), &core.ServiceAccount{}) + testGVK(t, ServiceGKv1(), &core.Service{}) + testGVK(t, PersistentVolumeClaimGKv1(), &core.PersistentVolumeClaim{}) + testGVK(t, SecretGKv1(), &core.Secret{}) + testGVK(t, ServiceMonitorGKv1(), &monitoringApi.ServiceMonitor{}) + testGVK(t, ArangoDeploymentGKv1(), &api.ArangoDeployment{}) } -func testGVK(t *testing.T, gvk schema.GroupVersionKind, in ...interface{}) { +func testGVK[T meta.Object](t *testing.T, gvk schema.GroupVersionKind, in T) { t.Run(gvk.String(), func(t *testing.T) { - for _, z := range in { - zt := reflect.TypeOf(z) - t.Run(zt.String(), func(t *testing.T) { - g, ok := ExtractGVKFromObject(z) - require.True(t, ok) - require.Equal(t, gvk, g) - }) - } + g, ok := ExtractGVKFromObject(in) + require.True(t, ok) + require.Equal(t, gvk, g) }) } diff --git a/pkg/util/k8sutil/inspector/constants/kubernetes_apps_deployment_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_apps_deployment_constants.go new file mode 100644 index 000000000..5dbc7134a --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_apps_deployment_constants.go @@ -0,0 +1,68 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + apps "k8s.io/api/apps/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// Deployment +const ( + DeploymentGroup = apps.GroupName + DeploymentResource = "deployments" + DeploymentKind = "Deployment" + DeploymentVersionV1 = "v1" +) + +func init() { + register[*apps.Deployment](DeploymentGKv1(), DeploymentGRv1()) +} + +func DeploymentGK() schema.GroupKind { + return schema.GroupKind{ + Group: DeploymentGroup, + Kind: DeploymentKind, + } +} + +func DeploymentGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: DeploymentGroup, + Kind: DeploymentKind, + Version: DeploymentVersionV1, + } +} + +func DeploymentGR() schema.GroupResource { + return schema.GroupResource{ + Group: DeploymentGroup, + Resource: DeploymentResource, + } +} + +func DeploymentGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: DeploymentGroup, + Resource: DeploymentResource, + Version: DeploymentVersionV1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/kubernetes_apps_rs_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_apps_rs_constants.go new file mode 100644 index 000000000..e4b7d5264 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_apps_rs_constants.go @@ -0,0 +1,68 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + apps "k8s.io/api/apps/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// ReplicaSet +const ( + ReplicaSetGroup = apps.GroupName + ReplicaSetResource = "replicasets" + ReplicaSetKind = "ReplicaSet" + ReplicaSetVersionV1 = "v1" +) + +func init() { + register[*apps.ReplicaSet](ReplicaSetGKv1(), ReplicaSetGRv1()) +} + +func ReplicaSetGK() schema.GroupKind { + return schema.GroupKind{ + Group: ReplicaSetGroup, + Kind: ReplicaSetKind, + } +} + +func ReplicaSetGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ReplicaSetGroup, + Kind: ReplicaSetKind, + Version: ReplicaSetVersionV1, + } +} + +func ReplicaSetGR() schema.GroupResource { + return schema.GroupResource{ + Group: ReplicaSetGroup, + Resource: ReplicaSetResource, + } +} + +func ReplicaSetGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ReplicaSetGroup, + Resource: ReplicaSetResource, + Version: ReplicaSetVersionV1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/kubernetes_apps_sts_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_apps_sts_constants.go new file mode 100644 index 000000000..dcb4cb584 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_apps_sts_constants.go @@ -0,0 +1,68 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + apps "k8s.io/api/apps/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// StatefulSet +const ( + StatefulSetGroup = apps.GroupName + StatefulSetResource = "statefulsets" + StatefulSetKind = "StatefulSet" + StatefulSetVersionV1 = "v1" +) + +func init() { + register[*apps.StatefulSet](StatefulSetGKv1(), StatefulSetGRv1()) +} + +func StatefulSetGK() schema.GroupKind { + return schema.GroupKind{ + Group: StatefulSetGroup, + Kind: StatefulSetKind, + } +} + +func StatefulSetGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: StatefulSetGroup, + Kind: StatefulSetKind, + Version: StatefulSetVersionV1, + } +} + +func StatefulSetGR() schema.GroupResource { + return schema.GroupResource{ + Group: StatefulSetGroup, + Resource: StatefulSetResource, + } +} + +func StatefulSetGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: StatefulSetGroup, + Resource: StatefulSetResource, + Version: StatefulSetVersionV1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/kubernetes_batch_cronjob_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_batch_cronjob_constants.go new file mode 100644 index 000000000..7656dbe9f --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_batch_cronjob_constants.go @@ -0,0 +1,68 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + batch "k8s.io/api/batch/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// CronJob +const ( + CronJobGroup = batch.GroupName + CronJobResource = "cronjobs" + CronJobKind = "CronJob" + CronJobVersionV1 = "v1" +) + +func init() { + register[*batch.CronJob](CronJobGKv1(), CronJobGRv1()) +} + +func CronJobGK() schema.GroupKind { + return schema.GroupKind{ + Group: CronJobGroup, + Kind: CronJobKind, + } +} + +func CronJobGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: CronJobGroup, + Kind: CronJobKind, + Version: CronJobVersionV1, + } +} + +func CronJobGR() schema.GroupResource { + return schema.GroupResource{ + Group: CronJobGroup, + Resource: CronJobResource, + } +} + +func CronJobGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: CronJobGroup, + Resource: CronJobResource, + Version: CronJobVersionV1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/kubernetes_batch_job_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_batch_job_constants.go new file mode 100644 index 000000000..e5c86dc8b --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_batch_job_constants.go @@ -0,0 +1,68 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + batch "k8s.io/api/batch/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// Job +const ( + JobGroup = batch.GroupName + JobResource = "jobs" + JobKind = "Job" + JobVersionV1 = "v1" +) + +func init() { + register[*batch.Job](JobGKv1(), JobGRv1()) +} + +func JobGK() schema.GroupKind { + return schema.GroupKind{ + Group: JobGroup, + Kind: JobKind, + } +} + +func JobGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: JobGroup, + Kind: JobKind, + Version: JobVersionV1, + } +} + +func JobGR() schema.GroupResource { + return schema.GroupResource{ + Group: JobGroup, + Resource: JobResource, + } +} + +func JobGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: JobGroup, + Resource: JobResource, + Version: JobVersionV1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/configmaps_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_core_configmap_constants.go similarity index 91% rename from pkg/util/k8sutil/inspector/constants/configmaps_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_core_configmap_constants.go index 8ed8844d2..a0836af63 100644 --- a/pkg/util/k8sutil/inspector/constants/configmaps_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_core_configmap_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024-2025 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. @@ -33,6 +33,10 @@ const ( ConfigMapVersionV1 = "v1" ) +func init() { + register[*core.ConfigMap](ConfigMapGKv1(), ConfigMapGRv1()) +} + func ConfigMapGK() schema.GroupKind { return schema.GroupKind{ Group: ConfigMapGroup, diff --git a/pkg/util/k8sutil/inspector/constants/endpoints_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_core_endpoint_constants.go similarity index 91% rename from pkg/util/k8sutil/inspector/constants/endpoints_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_core_endpoint_constants.go index 1106582e4..b9a91046e 100644 --- a/pkg/util/k8sutil/inspector/constants/endpoints_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_core_endpoint_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -33,6 +33,10 @@ const ( EndpointsVersionV1 = "v1" ) +func init() { + register[*core.Endpoints](EndpointsGKv1(), EndpointsGRv1()) +} + func EndpointsGK() schema.GroupKind { return schema.GroupKind{ Group: EndpointsGroup, diff --git a/pkg/util/k8sutil/inspector/constants/kubernetes_core_event_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_core_event_constants.go new file mode 100644 index 000000000..4dad5acc1 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_core_event_constants.go @@ -0,0 +1,68 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + core "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// Event +const ( + EventGroup = core.GroupName + EventResource = "events" + EventKind = "Event" + EventVersionV1 = "v1" +) + +func init() { + register[*core.Event](EventGKv1(), EventGRv1()) +} + +func EventGK() schema.GroupKind { + return schema.GroupKind{ + Group: EventGroup, + Kind: EventKind, + } +} + +func EventGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: EventGroup, + Kind: EventKind, + Version: EventVersionV1, + } +} + +func EventGR() schema.GroupResource { + return schema.GroupResource{ + Group: EventGroup, + Resource: EventResource, + } +} + +func EventGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: EventGroup, + Resource: EventResource, + Version: EventVersionV1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/nodes_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_core_node_constants.go similarity index 92% rename from pkg/util/k8sutil/inspector/constants/nodes_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_core_node_constants.go index e03bc05d7..407f29fbd 100644 --- a/pkg/util/k8sutil/inspector/constants/nodes_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_core_node_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -33,6 +33,10 @@ const ( NodeVersionV1 = "v1" ) +func init() { + register[*core.Node](NodeGKv1(), NodeGRv1()) +} + func NodeGK() schema.GroupKind { return schema.GroupKind{ Group: NodeGroup, diff --git a/pkg/util/k8sutil/inspector/constants/ns_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_core_ns_constants.go similarity index 95% rename from pkg/util/k8sutil/inspector/constants/ns_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_core_ns_constants.go index c42a594cb..b2a0324f0 100644 --- a/pkg/util/k8sutil/inspector/constants/ns_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_core_ns_constants.go @@ -33,6 +33,10 @@ const ( NamespaceVersionV1 = "v1" ) +func init() { + register[*core.Namespace](NamespaceGKv1(), NamespaceGRv1()) +} + func NamespaceGK() schema.GroupKind { return schema.GroupKind{ Group: NamespaceGroup, diff --git a/pkg/util/k8sutil/inspector/constants/pods_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_core_pod_constants.go similarity index 92% rename from pkg/util/k8sutil/inspector/constants/pods_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_core_pod_constants.go index c2834c43f..074f38bee 100644 --- a/pkg/util/k8sutil/inspector/constants/pods_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_core_pod_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -33,6 +33,10 @@ const ( PodVersionV1 = "v1" ) +func init() { + register[*core.Pod](PodGKv1(), PodGRv1()) +} + func PodGK() schema.GroupKind { return schema.GroupKind{ Group: PodGroup, diff --git a/pkg/util/k8sutil/inspector/constants/pvs_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_core_pv_constants.go similarity index 91% rename from pkg/util/k8sutil/inspector/constants/pvs_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_core_pv_constants.go index ffde3f3a7..ec343dc14 100644 --- a/pkg/util/k8sutil/inspector/constants/pvs_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_core_pv_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -33,6 +33,10 @@ const ( PersistentVolumeVersionV1 = "v1" ) +func init() { + register[*core.PersistentVolume](PersistentVolumeGKv1(), PersistentVolumeGRv1()) +} + func PersistentVolumeGK() schema.GroupKind { return schema.GroupKind{ Group: PersistentVolumeGroup, diff --git a/pkg/util/k8sutil/inspector/constants/pvcs_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_core_pvc_constants.go similarity index 91% rename from pkg/util/k8sutil/inspector/constants/pvcs_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_core_pvc_constants.go index ce3a3768d..1838b9b64 100644 --- a/pkg/util/k8sutil/inspector/constants/pvcs_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_core_pvc_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -33,6 +33,10 @@ const ( PersistentVolumeClaimVersionV1 = "v1" ) +func init() { + register[*core.PersistentVolumeClaim](PersistentVolumeClaimGKv1(), PersistentVolumeClaimGRv1()) +} + func PersistentVolumeClaimGK() schema.GroupKind { return schema.GroupKind{ Group: PersistentVolumeClaimGroup, diff --git a/pkg/util/k8sutil/inspector/constants/sa_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_core_sa_constants.go similarity index 91% rename from pkg/util/k8sutil/inspector/constants/sa_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_core_sa_constants.go index 622743824..bc3473742 100644 --- a/pkg/util/k8sutil/inspector/constants/sa_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_core_sa_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -33,6 +33,10 @@ const ( ServiceAccountVersionV1 = "v1" ) +func init() { + register[*core.ServiceAccount](ServiceAccountGKv1(), ServiceAccountGRv1()) +} + func ServiceAccountGK() schema.GroupKind { return schema.GroupKind{ Group: ServiceAccountGroup, diff --git a/pkg/util/k8sutil/inspector/constants/secrets_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_core_secret_constants.go similarity index 92% rename from pkg/util/k8sutil/inspector/constants/secrets_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_core_secret_constants.go index 82e248f0b..1d2738f2f 100644 --- a/pkg/util/k8sutil/inspector/constants/secrets_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_core_secret_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -33,6 +33,10 @@ const ( SecretVersionV1 = "v1" ) +func init() { + register[*core.Secret](SecretGKv1(), SecretGRv1()) +} + func SecretGK() schema.GroupKind { return schema.GroupKind{ Group: SecretGroup, diff --git a/pkg/util/k8sutil/inspector/constants/services_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_core_service_constants.go similarity index 92% rename from pkg/util/k8sutil/inspector/constants/services_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_core_service_constants.go index d866a3946..e67612dad 100644 --- a/pkg/util/k8sutil/inspector/constants/services_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_core_service_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -33,6 +33,10 @@ const ( ServiceVersionV1 = "v1" ) +func init() { + register[*core.Service](ServiceGKv1(), ServiceGRv1()) +} + func ServiceGK() schema.GroupKind { return schema.GroupKind{ Group: ServiceGroup, diff --git a/pkg/util/k8sutil/inspector/constants/crd_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_extension_crd_constants.go similarity index 90% rename from pkg/util/k8sutil/inspector/constants/crd_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_extension_crd_constants.go index 0922c7702..4788264ec 100644 --- a/pkg/util/k8sutil/inspector/constants/crd_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_extension_crd_constants.go @@ -21,6 +21,7 @@ package constants import ( + "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -32,6 +33,10 @@ const ( CustomResourceDefinitionVersionV1 = "v1" ) +func init() { + register[*apiextensions.CustomResourceDefinition](CustomResourceDefinitionGKv1(), CustomResourceDefinitionGRv1()) +} + func CustomResourceDefinitionGK() schema.GroupKind { return schema.GroupKind{ Group: CustomResourceDefinitionGroup, diff --git a/pkg/util/k8sutil/inspector/constants/pdbs_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_policy_pdb_constants.go similarity index 91% rename from pkg/util/k8sutil/inspector/constants/pdbs_constants.go rename to pkg/util/k8sutil/inspector/constants/kubernetes_policy_pdb_constants.go index 07b3ba41c..a4e483245 100644 --- a/pkg/util/k8sutil/inspector/constants/pdbs_constants.go +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_policy_pdb_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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,6 +34,10 @@ const ( PodDisruptionBudgetVersionV1 = "v1" ) +func init() { + register[*policy.PodDisruptionBudget](PodDisruptionBudgetGKv1(), PodDisruptionBudgetGRv1()) +} + func PodDisruptionBudgetGK() schema.GroupKind { return schema.GroupKind{ Group: PodDisruptionBudgetGroup, diff --git a/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_cr_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_cr_constants.go new file mode 100644 index 000000000..81e5e6715 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_cr_constants.go @@ -0,0 +1,68 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + rbac "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// ClusterRole +const ( + ClusterRoleGroup = rbac.GroupName + ClusterRoleResource = "clusterroles" + ClusterRoleKind = "ClusterRole" + ClusterRoleVersionV1 = "v1" +) + +func init() { + register[*rbac.ClusterRole](ClusterRoleGKv1(), ClusterRoleGRv1()) +} + +func ClusterRoleGK() schema.GroupKind { + return schema.GroupKind{ + Group: ClusterRoleGroup, + Kind: ClusterRoleKind, + } +} + +func ClusterRoleGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ClusterRoleGroup, + Kind: ClusterRoleKind, + Version: ClusterRoleVersionV1, + } +} + +func ClusterRoleGR() schema.GroupResource { + return schema.GroupResource{ + Group: ClusterRoleGroup, + Resource: ClusterRoleResource, + } +} + +func ClusterRoleGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ClusterRoleGroup, + Resource: ClusterRoleResource, + Version: ClusterRoleVersionV1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_crb_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_crb_constants.go new file mode 100644 index 000000000..781fc0dbe --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_crb_constants.go @@ -0,0 +1,68 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + rbac "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// ClusterRoleBinding +const ( + ClusterRoleBindingGroup = rbac.GroupName + ClusterRoleBindingResource = "clusterrolebindings" + ClusterRoleBindingKind = "ClusterRoleBinding" + ClusterRoleBindingVersionV1 = "v1" +) + +func init() { + register[*rbac.ClusterRoleBinding](ClusterRoleBindingGKv1(), ClusterRoleBindingGRv1()) +} + +func ClusterRoleBindingGK() schema.GroupKind { + return schema.GroupKind{ + Group: ClusterRoleBindingGroup, + Kind: ClusterRoleBindingKind, + } +} + +func ClusterRoleBindingGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ClusterRoleBindingGroup, + Kind: ClusterRoleBindingKind, + Version: ClusterRoleBindingVersionV1, + } +} + +func ClusterRoleBindingGR() schema.GroupResource { + return schema.GroupResource{ + Group: ClusterRoleBindingGroup, + Resource: ClusterRoleBindingResource, + } +} + +func ClusterRoleBindingGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ClusterRoleBindingGroup, + Resource: ClusterRoleBindingResource, + Version: ClusterRoleBindingVersionV1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_r_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_r_constants.go new file mode 100644 index 000000000..4c77d1297 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_r_constants.go @@ -0,0 +1,68 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + rbac "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// Role +const ( + RoleGroup = rbac.GroupName + RoleResource = "roles" + RoleKind = "Role" + RoleVersionV1 = "v1" +) + +func init() { + register[*rbac.Role](RoleGKv1(), RoleGRv1()) +} + +func RoleGK() schema.GroupKind { + return schema.GroupKind{ + Group: RoleGroup, + Kind: RoleKind, + } +} + +func RoleGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: RoleGroup, + Kind: RoleKind, + Version: RoleVersionV1, + } +} + +func RoleGR() schema.GroupResource { + return schema.GroupResource{ + Group: RoleGroup, + Resource: RoleResource, + } +} + +func RoleGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: RoleGroup, + Resource: RoleResource, + Version: RoleVersionV1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_rb_constants.go b/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_rb_constants.go new file mode 100644 index 000000000..900d7b704 --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/kubernetes_rbac_rb_constants.go @@ -0,0 +1,68 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + rbac "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// RoleBinding +const ( + RoleBindingGroup = rbac.GroupName + RoleBindingResource = "rolebindings" + RoleBindingKind = "RoleBinding" + RoleBindingVersionV1 = "v1" +) + +func init() { + register[*rbac.RoleBinding](RoleBindingGKv1(), RoleBindingGRv1()) +} + +func RoleBindingGK() schema.GroupKind { + return schema.GroupKind{ + Group: RoleBindingGroup, + Kind: RoleBindingKind, + } +} + +func RoleBindingGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: RoleBindingGroup, + Kind: RoleBindingKind, + Version: RoleBindingVersionV1, + } +} + +func RoleBindingGR() schema.GroupResource { + return schema.GroupResource{ + Group: RoleBindingGroup, + Resource: RoleBindingResource, + } +} + +func RoleBindingGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: RoleBindingGroup, + Resource: RoleBindingResource, + Version: RoleBindingVersionV1, + } +} diff --git a/pkg/util/k8sutil/inspector/constants/sm_constants.go b/pkg/util/k8sutil/inspector/constants/prometheus_monitoring_sm_constants.go similarity index 86% rename from pkg/util/k8sutil/inspector/constants/sm_constants.go rename to pkg/util/k8sutil/inspector/constants/prometheus_monitoring_sm_constants.go index 155147eb2..7e43bda23 100644 --- a/pkg/util/k8sutil/inspector/constants/sm_constants.go +++ b/pkg/util/k8sutil/inspector/constants/prometheus_monitoring_sm_constants.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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,6 +21,7 @@ package constants import ( + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -32,6 +33,10 @@ const ( ServiceMonitorVersionV1 = "v1" ) +func init() { + register[*monitoringApi.ServiceMonitor](ServiceMonitorGKv1(), ServiceMonitorGRv1()) +} + func ServiceMonitorGK() schema.GroupKind { return schema.GroupKind{ Group: ServiceMonitorGroup, diff --git a/pkg/util/k8sutil/inspector/constants/register.go b/pkg/util/k8sutil/inspector/constants/register.go new file mode 100644 index 000000000..afc12b53c --- /dev/null +++ b/pkg/util/k8sutil/inspector/constants/register.go @@ -0,0 +1,74 @@ +// +// DISCLAIMER +// +// Copyright 2025 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 constants + +import ( + "reflect" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/arangodb/kube-arangodb/pkg/util" +) + +type registration struct { + GVK schema.GroupVersionKind + GVR schema.GroupVersionResource +} + +var ( + registerer = util.NewRegisterer[reflect.Type, registration]() +) + +func register[T meta.Object](GVK schema.GroupVersionKind, GVR schema.GroupVersionResource) { + registerer.MustRegister(util.TypeOf[T](), registration{ + GVK: GVK, + GVR: GVR, + }) +} + +func getRegistration(t reflect.Type) (registration, bool) { + for _, i := range registerer.Items() { + if i.K == t { + return i.V, true + } + } + + return registration{}, false +} + +func ExtractGVK(t reflect.Type) (schema.GroupVersionKind, bool) { + k, v := getRegistration(t) + return k.GVK, v +} + +func ExtractGVKFromObject[T meta.Object](obj T) (schema.GroupVersionKind, bool) { + return ExtractGVK(reflect.TypeOf(obj)) +} + +func ExtractGVR(t reflect.Type) (schema.GroupVersionResource, bool) { + k, v := getRegistration(t) + return k.GVR, v +} + +func ExtractGVRFromObject[T meta.Object](obj T) (schema.GroupVersionResource, bool) { + return ExtractGVR(reflect.TypeOf(obj)) +} diff --git a/pkg/util/k8sutil/inspector/mods/mods.go b/pkg/util/k8sutil/inspector/mods/mods.go index 4532967dd..51da0f0c7 100644 --- a/pkg/util/k8sutil/inspector/mods/mods.go +++ b/pkg/util/k8sutil/inspector/mods/mods.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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,7 +21,7 @@ package mods import ( - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" core "k8s.io/api/core/v1" policy "k8s.io/api/policy/v1" @@ -61,7 +61,7 @@ type EndpointsMods interface { } type ServiceMonitorsMods interface { - V1() generic.ModClient[*monitoring.ServiceMonitor] + V1() generic.ModClient[*monitoringApi.ServiceMonitor] } type PodDisruptionBudgetsMods interface { diff --git a/pkg/util/k8sutil/inspector/servicemonitor/definition.go b/pkg/util/k8sutil/inspector/servicemonitor/definition.go index 3cb87cee7..0f822bf51 100644 --- a/pkg/util/k8sutil/inspector/servicemonitor/definition.go +++ b/pkg/util/k8sutil/inspector/servicemonitor/definition.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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,7 +21,7 @@ package servicemonitor import ( - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "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" @@ -34,5 +34,5 @@ type Inspector interface { type Definition interface { base.Inspector - V1() (generic.Inspector[*monitoring.ServiceMonitor], error) + V1() (generic.Inspector[*monitoringApi.ServiceMonitor], error) } diff --git a/pkg/util/k8sutil/inspector/servicemonitor/generic.go b/pkg/util/k8sutil/inspector/servicemonitor/generic.go index 711c31572..885f4188f 100644 --- a/pkg/util/k8sutil/inspector/servicemonitor/generic.go +++ b/pkg/util/k8sutil/inspector/servicemonitor/generic.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024-2025 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,14 @@ package servicemonitor import ( - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" ) -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)) +func List(filter ...generic.Filter[*monitoringApi.ServiceMonitor]) generic.ExtractorList[*monitoringApi.ServiceMonitorList, *monitoringApi.ServiceMonitor] { + return func(in *monitoringApi.ServiceMonitorList) []*monitoringApi.ServiceMonitor { + ret := make([]*monitoringApi.ServiceMonitor, 0, len(in.Items)) for _, el := range in.Items { z := el.DeepCopy() diff --git a/pkg/util/k8sutil/kerrors/resources.go b/pkg/util/k8sutil/kerrors/resources.go index d286a8099..4d4c14eff 100644 --- a/pkg/util/k8sutil/kerrors/resources.go +++ b/pkg/util/k8sutil/kerrors/resources.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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,22 +34,19 @@ func NewResourceError(cause error, obj interface{}) error { return nil } - if gvk, ok := constants.ExtractGVKFromObject(obj); !ok { - return cause - } else { - if meta, ok := obj.(meta.Object); ok { + if meta, ok := obj.(meta.Object); ok { + if gvk, ok := constants.ExtractGVKFromObject(meta); !ok { + return cause + } else { return ResourceError{ GVK: gvk, Namespace: meta.GetNamespace(), Name: meta.GetName(), cause: cause, } - } else { - return ResourceError{ - GVK: gvk, - cause: cause, - } } + } else { + return cause } } diff --git a/pkg/debug_package/generators/kubernetes/lister.go b/pkg/util/k8sutil/list/lister.go similarity index 87% rename from pkg/debug_package/generators/kubernetes/lister.go rename to pkg/util/k8sutil/list/lister.go index 9d0ac163d..5a6d932cc 100644 --- a/pkg/debug_package/generators/kubernetes/lister.go +++ b/pkg/util/k8sutil/list/lister.go @@ -18,7 +18,7 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package kubernetes +package list import ( "context" @@ -26,11 +26,10 @@ import ( meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/list" ) func ListObjects[L generic.ListContinue, T meta.Object](ctx context.Context, k generic.ListInterface[L], extract func(result L) []T) ([]T, error) { - return list.APIList[L, T](ctx, k, meta.ListOptions{}, func(in L) []T { + return APIList[L, T](ctx, k, meta.ListOptions{}, func(in L) []T { z := extract(in) for id := range z { diff --git a/pkg/util/kclient/fake.go b/pkg/util/kclient/fake.go index 36d084ebc..0e4e8d7b9 100644 --- a/pkg/util/kclient/fake.go +++ b/pkg/util/kclient/fake.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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. @@ -23,7 +23,7 @@ package kclient import ( "sync" - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" monitoringFake "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned/fake" core "k8s.io/api/core/v1" policy "k8s.io/api/policy/v1" @@ -128,7 +128,7 @@ type FakeDataInput struct { PVCS map[string]*core.PersistentVolumeClaim ServiceAccounts map[string]*core.ServiceAccount PDBSV1 map[string]*policy.PodDisruptionBudget - ServiceMonitors map[string]*monitoring.ServiceMonitor + ServiceMonitors map[string]*monitoringApi.ServiceMonitor ArangoMembers map[string]*api.ArangoMember Nodes map[string]*core.Node ACS map[string]*api.ArangoClusterSynchronization diff --git a/pkg/util/kclient/mod.go b/pkg/util/kclient/mod.go index 50ff401c1..d97db8ab3 100644 --- a/pkg/util/kclient/mod.go +++ b/pkg/util/kclient/mod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2025 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,7 +21,7 @@ package kclient import ( - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + monitoringApi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" core "k8s.io/api/core/v1" policy "k8s.io/api/policy/v1" @@ -43,7 +43,7 @@ type ModInterface interface { ServiceAccounts() generic.ModClient[*core.ServiceAccount] PersistentVolumeClaims() generic.ModClient[*core.PersistentVolumeClaim] PodDisruptionBudgets() generic.ModClient[*policy.PodDisruptionBudget] - ServiceMonitors() generic.ModClient[*monitoring.ServiceMonitor] + ServiceMonitors() generic.ModClient[*monitoringApi.ServiceMonitor] ArangoMembers() generic.ModStatusClient[*api.ArangoMember] } @@ -60,7 +60,7 @@ func (m modInterface) PodDisruptionBudgets() generic.ModClient[*policy.PodDisrup return m.client.Kubernetes().PolicyV1().PodDisruptionBudgets(m.namespace) } -func (m modInterface) ServiceMonitors() generic.ModClient[*monitoring.ServiceMonitor] { +func (m modInterface) ServiceMonitors() generic.ModClient[*monitoringApi.ServiceMonitor] { return m.client.Monitoring().MonitoringV1().ServiceMonitors(m.namespace) } diff --git a/pkg/util/mod.go b/pkg/util/mod.go index 0b28663d1..2851090f4 100644 --- a/pkg/util/mod.go +++ b/pkg/util/mod.go @@ -91,3 +91,24 @@ func ApplyModsEP1[T, P1 any](in *T, p1 P1, mods ...ModEP1[T, P1]) error { return nil } + +func emptyModR[T any](z T) T { return z } + +type ModR[T any] func(in T) T + +func (m ModR[T]) Optional() ModR[T] { + if m == nil { + return emptyModR[T] + } + + return m +} + +func ApplyModsR[T any](in T, mods ...ModR[T]) T { + for _, mod := range mods { + if mod != nil { + mod(in) + } + } + return in +} diff --git a/pkg/util/refs.go b/pkg/util/refs.go index b3948aefb..6647ab74a 100644 --- a/pkg/util/refs.go +++ b/pkg/util/refs.go @@ -184,6 +184,13 @@ func initDeepType(v reflect.Value) error { return nil } +// TypeOf returns type of the generic +func TypeOf[T any]() reflect.Type { + var z [0]T + + return reflect.TypeOf(z).Elem() +} + type ConditionalFunction[T interface{}] func() (T, bool) type ConditionalP1Function[T, P1 interface{}] func(p1 P1) (T, bool) diff --git a/pkg/util/tests/kubernetes.go b/pkg/util/tests/kubernetes.go index afd6d0c89..69d081ae7 100644 --- a/pkg/util/tests/kubernetes.go +++ b/pkg/util/tests/kubernetes.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2025 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. @@ -32,7 +32,6 @@ import ( core "k8s.io/api/core/v1" rbac "k8s.io/api/rbac/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/client-go/kubernetes" @@ -57,6 +56,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/operatorV2/operation" "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/errors" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" "github.com/arangodb/kube-arangodb/pkg/util/kclient" ) @@ -1533,212 +1533,6 @@ func IsNamespaced(in meta.Object) bool { } } -func GVK(t *testing.T, object meta.Object) schema.GroupVersionKind { - switch v := object.(type) { - case *batch.CronJob: - return schema.GroupVersionKind{ - Group: "batch", - Version: "v1", - Kind: " ArangoSchedulerCronJob", - } - case *batch.Job: - return schema.GroupVersionKind{ - Group: "batch", - Version: "v1", - Kind: "Job", - } - case *core.Pod: - return schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: " ArangoSchedulerPod", - } - case *core.Secret: - return schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "Secret", - } - case *core.ConfigMap: - return schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "ConfigMap", - } - case *core.Service: - return schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "Service", - } - case *core.Endpoints: - return schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "Endpoints", - } - case *core.ServiceAccount: - return schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "ServiceAccount", - } - case *apps.StatefulSet: - return schema.GroupVersionKind{ - Group: "apps", - Version: "v1", - Kind: "StatefulSet", - } - case *apps.Deployment: - return schema.GroupVersionKind{ - Group: "apps", - Version: "v1", - Kind: "Deployment", - } - case *api.ArangoDeployment: - return schema.GroupVersionKind{ - Group: deployment.ArangoDeploymentGroupName, - Version: api.ArangoDeploymentVersion, - Kind: deployment.ArangoDeploymentResourceKind, - } - case *api.ArangoClusterSynchronization: - return schema.GroupVersionKind{ - Group: deployment.ArangoDeploymentGroupName, - Version: api.ArangoDeploymentVersion, - Kind: deployment.ArangoClusterSynchronizationResourceKind, - } - case *backupApi.ArangoBackup: - return schema.GroupVersionKind{ - Group: backup.ArangoBackupGroupName, - Version: backupApi.ArangoBackupVersion, - Kind: backup.ArangoBackupResourceKind, - } - case *backupApi.ArangoBackupPolicy: - return schema.GroupVersionKind{ - Group: backup.ArangoBackupGroupName, - Version: backupApi.ArangoBackupVersion, - Kind: backup.ArangoBackupPolicyResourceKind, - } - case *mlApi.ArangoMLExtension: - return schema.GroupVersionKind{ - Group: ml.ArangoMLGroupName, - Version: mlApi.ArangoMLVersion, - Kind: ml.ArangoMLExtensionResourceKind, - } - case *mlApi.ArangoMLStorage: - return schema.GroupVersionKind{ - Group: ml.ArangoMLGroupName, - Version: mlApi.ArangoMLVersion, - Kind: ml.ArangoMLStorageResourceKind, - } - case *mlApiv1alpha1.ArangoMLExtension: - return schema.GroupVersionKind{ - Group: ml.ArangoMLGroupName, - Version: mlApiv1alpha1.ArangoMLVersion, - Kind: ml.ArangoMLExtensionResourceKind, - } - case *mlApiv1alpha1.ArangoMLStorage: - return schema.GroupVersionKind{ - Group: ml.ArangoMLGroupName, - Version: mlApiv1alpha1.ArangoMLVersion, - Kind: ml.ArangoMLStorageResourceKind, - } - case *mlApiv1alpha1.ArangoMLBatchJob: - return schema.GroupVersionKind{ - Group: ml.ArangoMLGroupName, - Version: mlApiv1alpha1.ArangoMLVersion, - Kind: ml.ArangoMLBatchJobResourceKind, - } - case *mlApiv1alpha1.ArangoMLCronJob: - return schema.GroupVersionKind{ - Group: ml.ArangoMLGroupName, - Version: mlApiv1alpha1.ArangoMLVersion, - Kind: ml.ArangoMLCronJobResourceKind, - } - case *rbac.ClusterRole: - return schema.GroupVersionKind{ - Group: "rbac.authorization.k8s.io", - Version: "v1", - Kind: "ClusterRole", - } - case *rbac.ClusterRoleBinding: - return schema.GroupVersionKind{ - Group: "rbac.authorization.k8s.io", - Version: "v1", - Kind: "ClusterRoleBinding", - } - case *rbac.Role: - return schema.GroupVersionKind{ - Group: "rbac.authorization.k8s.io", - Version: "v1", - Kind: "Role", - } - case *rbac.RoleBinding: - return schema.GroupVersionKind{ - Group: "rbac.authorization.k8s.io", - Version: "v1", - Kind: "RoleBinding", - } - case *schedulerApi.ArangoProfile: - return schema.GroupVersionKind{ - Group: scheduler.ArangoSchedulerGroupName, - Version: schedulerApi.ArangoSchedulerVersion, - Kind: scheduler.ArangoProfileResourceKind, - } - case *schedulerApi.ArangoSchedulerPod: - return schema.GroupVersionKind{ - Group: scheduler.ArangoSchedulerGroupName, - Version: schedulerApi.ArangoSchedulerVersion, - Kind: scheduler.PodResourceKind, - } - case *schedulerApi.ArangoSchedulerDeployment: - return schema.GroupVersionKind{ - Group: scheduler.ArangoSchedulerGroupName, - Version: schedulerApi.ArangoSchedulerVersion, - Kind: scheduler.DeploymentResourceKind, - } - case *schedulerApi.ArangoSchedulerBatchJob: - return schema.GroupVersionKind{ - Group: scheduler.ArangoSchedulerGroupName, - Version: schedulerApi.ArangoSchedulerVersion, - Kind: scheduler.BatchJobResourceKind, - } - case *schedulerApi.ArangoSchedulerCronJob: - return schema.GroupVersionKind{ - Group: scheduler.ArangoSchedulerGroupName, - Version: schedulerApi.ArangoSchedulerVersion, - Kind: scheduler.CronJobResourceKind, - } - case *analyticsApi.GraphAnalyticsEngine: - return schema.GroupVersionKind{ - Group: analytics.ArangoAnalyticsGroupName, - Version: analyticsApi.ArangoAnalyticsVersion, - Kind: analytics.GraphAnalyticsEngineResourceKind, - } - case *networkingApi.ArangoRoute: - return schema.GroupVersionKind{ - Group: networking.ArangoNetworkingGroupName, - Version: networkingApi.ArangoNetworkingVersion, - Kind: networking.ArangoRouteResourceKind, - } - case *platformApi.ArangoPlatformStorage: - return schema.GroupVersionKind{ - Group: platform.ArangoPlatformGroupName, - Version: platformApi.ArangoPlatformVersion, - Kind: platform.ArangoPlatformStorageResourceKind, - } - case *platformApi.ArangoPlatformChart: - return schema.GroupVersionKind{ - Group: platform.ArangoPlatformGroupName, - Version: platformApi.ArangoPlatformVersion, - Kind: platform.ArangoPlatformChartResourceKind, - } - default: - require.Fail(t, fmt.Sprintf("Unable to create object: %s", reflect.TypeOf(v).String())) - return schema.GroupVersionKind{} - } -} - func NewItem(t *testing.T, o operation.Operation, object meta.Object) operation.Item { item := operation.Item{ Operation: o, @@ -1747,7 +1541,8 @@ func NewItem(t *testing.T, o operation.Operation, object meta.Object) operation. Name: object.GetName(), } - gvk := GVK(t, object) + gvk, ok := constants.ExtractGVKFromObject(object) + require.True(t, ok, reflect.TypeOf(object).String()) item.Group = gvk.Group item.Version = gvk.Version