From df37ed1bf84571b0a10028ca2f6e5bf551aba426 Mon Sep 17 00:00:00 2001 From: Adam Janikowski <12255597+ajanikow@users.noreply.github.com> Date: Tue, 3 May 2022 10:31:30 +0200 Subject: [PATCH] [Refactor] Anonymous Inspector functions (#973) --- CHANGELOG.md | 1 + .../resources/certificates_client_auth.go | 4 +- pkg/deployment/resources/certificates_tls.go | 6 +- .../resources/inspector/acs_anonymous.go | 39 +++++++ .../resources/inspector/acs_anonymous_v1.go | 35 ++++++ .../resources/inspector/acs_constants.go | 81 ++++++++++++++ pkg/deployment/resources/inspector/acs_v1.go | 11 +- .../resources/inspector/am_anonymous.go | 39 +++++++ .../resources/inspector/am_anonymous_v1.go | 35 ++++++ .../resources/inspector/am_constants.go | 81 ++++++++++++++ pkg/deployment/resources/inspector/am_v1.go | 11 +- .../resources/inspector/at_anonymous.go | 39 +++++++ .../resources/inspector/at_anonymous_v1.go | 35 ++++++ .../resources/inspector/at_constants.go | 81 ++++++++++++++ pkg/deployment/resources/inspector/at_v1.go | 11 +- .../inspector/endpoints_anonymous.go | 39 +++++++ .../inspector/endpoints_anonymous_v1.go | 35 ++++++ .../inspector/endpoints_constants.go | 80 +++++++++++++ .../resources/inspector/endpoints_v1.go | 10 +- .../resources/inspector/inspector.go | 34 ++++++ .../resources/inspector/nodes_anonymous.go | 39 +++++++ .../resources/inspector/nodes_anonymous_v1.go | 35 ++++++ .../resources/inspector/nodes_constants.go | 80 +++++++++++++ .../resources/inspector/nodes_v1.go | 10 +- .../resources/inspector/pdbs_anonymous.go | 41 +++++++ .../resources/inspector/pdbs_anonymous_v1.go | 35 ++++++ .../inspector/pdbs_anonymous_v1beta1.go | 35 ++++++ .../resources/inspector/pdbs_constants.go | 105 ++++++++++++++++++ pkg/deployment/resources/inspector/pdbs_v1.go | 10 +- .../resources/inspector/pdbs_v1beta1.go | 10 +- .../resources/inspector/pods_anonymous.go | 39 +++++++ .../resources/inspector/pods_anonymous_v1.go | 35 ++++++ .../resources/inspector/pods_constants.go | 80 +++++++++++++ pkg/deployment/resources/inspector/pods_v1.go | 10 +- .../resources/inspector/pvcs_anonymous.go | 39 +++++++ .../resources/inspector/pvcs_anonymous_v1.go | 35 ++++++ .../resources/inspector/pvcs_constants.go | 80 +++++++++++++ pkg/deployment/resources/inspector/pvcs_v1.go | 10 +- .../resources/inspector/sa_anonymous.go | 39 +++++++ .../resources/inspector/sa_anonymous_v1.go | 35 ++++++ .../resources/inspector/sa_constants.go | 80 +++++++++++++ pkg/deployment/resources/inspector/sa_v1.go | 10 +- .../resources/inspector/secrets_anonymous.go | 39 +++++++ .../inspector/secrets_anonymous_v1.go | 35 ++++++ .../resources/inspector/secrets_constants.go | 80 +++++++++++++ .../resources/inspector/secrets_v1.go | 10 +- .../resources/inspector/services_anonymous.go | 39 +++++++ .../inspector/services_anonymous_v1.go | 35 ++++++ .../resources/inspector/services_constants.go | 80 +++++++++++++ .../resources/inspector/services_v1.go | 10 +- .../resources/inspector/sm_anonymous.go | 39 +++++++ .../resources/inspector/sm_anonymous_v1.go | 35 ++++++ .../resources/inspector/sm_constants.go | 80 +++++++++++++ pkg/deployment/resources/inspector/sm_v1.go | 14 +-- pkg/deployment/resources/member_cleanup.go | 8 +- pkg/deployment/resources/pdbs.go | 16 +-- .../resources/pod_creator_agent_args_test.go | 14 +-- .../pod_creator_coordinator_args_test.go | 14 +-- .../pod_creator_dbserver_args_test.go | 14 +-- .../resources/pod_creator_single_args_test.go | 4 +- pkg/deployment/resources/pod_finalizers.go | 6 +- pkg/deployment/resources/pod_inspector.go | 10 +- pkg/deployment/resources/pod_termination.go | 6 +- pkg/deployment/resources/pvc_finalizers.go | 4 +- pkg/deployment/resources/servicemonitor.go | 18 +-- .../k8sutil/inspector/anonymous/anonymous.go | 36 ++++++ .../definition.go | 5 + .../arangoclustersynchronization/v1/loader.go | 3 + .../inspector/arangomember/definition.go | 5 + .../inspector/arangomember/v1/loader.go | 3 + .../inspector/arangotask/definition.go | 5 + .../k8sutil/inspector/arangotask/v1/loader.go | 3 + .../k8sutil/inspector/endpoints/definition.go | 5 + .../k8sutil/inspector/endpoints/v1/loader.go | 7 +- pkg/util/k8sutil/inspector/gvk/gvk.go | 35 ++++++ pkg/util/k8sutil/inspector/inspector.go | 5 + pkg/util/k8sutil/inspector/node/definition.go | 5 + pkg/util/k8sutil/inspector/node/v1/loader.go | 3 + .../persistentvolumeclaim/definition.go | 5 + .../persistentvolumeclaim/v1/loader.go | 3 + pkg/util/k8sutil/inspector/pod/definition.go | 5 + pkg/util/k8sutil/inspector/pod/v1/loader.go | 3 + .../poddisruptionbudget/definition.go | 5 + .../poddisruptionbudget/v1/loader.go | 7 +- .../poddisruptionbudget/v1beta1/loader.go | 7 +- .../k8sutil/inspector/secret/definition.go | 5 + .../k8sutil/inspector/secret/v1/loader.go | 3 + .../k8sutil/inspector/service/definition.go | 5 + .../k8sutil/inspector/service/v1/loader.go | 3 + .../inspector/serviceaccount/definition.go | 5 + .../inspector/serviceaccount/v1/loader.go | 7 +- .../inspector/serviceaccount/v1/reader.go | 3 + .../inspector/servicemonitor/definition.go | 5 + .../inspector/servicemonitor/v1/loader.go | 7 +- .../inspector/servicemonitor/v1/reader.go | 3 + 95 files changed, 2246 insertions(+), 164 deletions(-) create mode 100644 pkg/deployment/resources/inspector/acs_anonymous.go create mode 100644 pkg/deployment/resources/inspector/acs_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/acs_constants.go create mode 100644 pkg/deployment/resources/inspector/am_anonymous.go create mode 100644 pkg/deployment/resources/inspector/am_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/am_constants.go create mode 100644 pkg/deployment/resources/inspector/at_anonymous.go create mode 100644 pkg/deployment/resources/inspector/at_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/at_constants.go create mode 100644 pkg/deployment/resources/inspector/endpoints_anonymous.go create mode 100644 pkg/deployment/resources/inspector/endpoints_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/endpoints_constants.go create mode 100644 pkg/deployment/resources/inspector/nodes_anonymous.go create mode 100644 pkg/deployment/resources/inspector/nodes_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/nodes_constants.go create mode 100644 pkg/deployment/resources/inspector/pdbs_anonymous.go create mode 100644 pkg/deployment/resources/inspector/pdbs_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/pdbs_anonymous_v1beta1.go create mode 100644 pkg/deployment/resources/inspector/pdbs_constants.go create mode 100644 pkg/deployment/resources/inspector/pods_anonymous.go create mode 100644 pkg/deployment/resources/inspector/pods_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/pods_constants.go create mode 100644 pkg/deployment/resources/inspector/pvcs_anonymous.go create mode 100644 pkg/deployment/resources/inspector/pvcs_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/pvcs_constants.go create mode 100644 pkg/deployment/resources/inspector/sa_anonymous.go create mode 100644 pkg/deployment/resources/inspector/sa_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/sa_constants.go create mode 100644 pkg/deployment/resources/inspector/secrets_anonymous.go create mode 100644 pkg/deployment/resources/inspector/secrets_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/secrets_constants.go create mode 100644 pkg/deployment/resources/inspector/services_anonymous.go create mode 100644 pkg/deployment/resources/inspector/services_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/services_constants.go create mode 100644 pkg/deployment/resources/inspector/sm_anonymous.go create mode 100644 pkg/deployment/resources/inspector/sm_anonymous_v1.go create mode 100644 pkg/deployment/resources/inspector/sm_constants.go create mode 100644 pkg/util/k8sutil/inspector/anonymous/anonymous.go create mode 100644 pkg/util/k8sutil/inspector/gvk/gvk.go diff --git a/CHANGELOG.md b/CHANGELOG.md index a3befe651..11d2297f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A) - (Feature) Add CoreV1 Endpoints Inspector - (Feature) Add Current ArangoDeployment Inspector +- (Refactor) Anonymous inspector functions ## [1.2.11](https://github.com/arangodb/kube-arangodb/tree/1.2.11) (2022-04-30) - (Bugfix) Orphan PVC are not removed diff --git a/pkg/deployment/resources/certificates_client_auth.go b/pkg/deployment/resources/certificates_client_auth.go index 852879dc3..153a69639 100644 --- a/pkg/deployment/resources/certificates_client_auth.go +++ b/pkg/deployment/resources/certificates_client_auth.go @@ -26,7 +26,7 @@ import ( "time" "github.com/rs/zerolog" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" certificates "github.com/arangodb-helper/go-certificates" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" @@ -41,7 +41,7 @@ const ( // createClientAuthCACertificate creates a client authentication CA certificate and stores it in a secret with name // specified in the given spec. -func createClientAuthCACertificate(ctx context.Context, log zerolog.Logger, secrets secretv1.ModInterface, spec api.SyncAuthenticationSpec, deploymentName string, ownerRef *metav1.OwnerReference) error { +func createClientAuthCACertificate(ctx context.Context, log zerolog.Logger, secrets secretv1.ModInterface, spec api.SyncAuthenticationSpec, deploymentName string, ownerRef *meta.OwnerReference) error { log = log.With().Str("secret", spec.GetClientCASecretName()).Logger() options := certificates.CreateCertificateOptions{ CommonName: fmt.Sprintf("%s Client Authentication Root Certificate", deploymentName), diff --git a/pkg/deployment/resources/certificates_tls.go b/pkg/deployment/resources/certificates_tls.go index c7f7cf6f6..202038dee 100644 --- a/pkg/deployment/resources/certificates_tls.go +++ b/pkg/deployment/resources/certificates_tls.go @@ -38,7 +38,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" "github.com/rs/zerolog" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( @@ -49,7 +49,7 @@ const ( // createTLSCACertificate creates a CA certificate and stores it in a secret with name // specified in the given spec. func createTLSCACertificate(ctx context.Context, log zerolog.Logger, secrets secretv1.ModInterface, spec api.TLSSpec, - deploymentName string, ownerRef *metav1.OwnerReference) error { + deploymentName string, ownerRef *meta.OwnerReference) error { log = log.With().Str("secret", spec.GetCASecretName()).Logger() options := certificates.CreateCertificateOptions{ @@ -79,7 +79,7 @@ func createTLSCACertificate(ctx context.Context, log zerolog.Logger, secrets sec // createTLSServerCertificate creates a TLS certificate for a specific server and stores // it in a secret with the given name. func createTLSServerCertificate(ctx context.Context, log zerolog.Logger, cachedStatus inspectorInterface.Inspector, secrets secretv1.ModInterface, names tls.KeyfileInput, spec api.TLSSpec, - secretName string, ownerRef *metav1.OwnerReference) (bool, error) { + secretName string, ownerRef *meta.OwnerReference) (bool, error) { log = log.With().Str("secret", secretName).Logger() // Load CA certificate ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) diff --git a/pkg/deployment/resources/inspector/acs_anonymous.go b/pkg/deployment/resources/inspector/acs_anonymous.go new file mode 100644 index 000000000..9fe487c49 --- /dev/null +++ b/pkg/deployment/resources/inspector/acs_anonymous.go @@ -0,0 +1,39 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *arangoClusterSynchronizationsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := ArangoClusterSynchronizationGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case ArangoClusterSynchronizationVersionV1: + return &arangoClusterSynchronizationsInspectorAnonymousV1{i: p.v1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/acs_anonymous_v1.go b/pkg/deployment/resources/inspector/acs_anonymous_v1.go new file mode 100644 index 000000000..6244e19b0 --- /dev/null +++ b/pkg/deployment/resources/inspector/acs_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type arangoClusterSynchronizationsInspectorAnonymousV1 struct { + i *arangoClusterSynchronizationsInspectorV1 +} + +func (e *arangoClusterSynchronizationsInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/acs_constants.go b/pkg/deployment/resources/inspector/acs_constants.go new file mode 100644 index 000000000..755dcb2ec --- /dev/null +++ b/pkg/deployment/resources/inspector/acs_constants.go @@ -0,0 +1,81 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/apis/deployment" + deploymentv1 "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// ArangoClusterSynchronization +const ( + ArangoClusterSynchronizationGroup = deployment.ArangoDeploymentGroupName + ArangoClusterSynchronizationResource = deployment.ArangoClusterSynchronizationResourcePlural + ArangoClusterSynchronizationKind = deployment.ArangoClusterSynchronizationResourceKind + ArangoClusterSynchronizationVersionV1 = deploymentv1.ArangoDeploymentVersion +) + +func ArangoClusterSynchronizationGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoClusterSynchronizationGroup, + Kind: ArangoClusterSynchronizationKind, + } +} + +func ArangoClusterSynchronizationGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoClusterSynchronizationGroup, + Kind: ArangoClusterSynchronizationKind, + Version: ArangoClusterSynchronizationVersionV1, + } +} + +func ArangoClusterSynchronizationGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoClusterSynchronizationGroup, + Resource: ArangoClusterSynchronizationResource, + } +} + +func ArangoClusterSynchronizationGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoClusterSynchronizationGroup, + Resource: ArangoClusterSynchronizationResource, + Version: ArangoClusterSynchronizationVersionV1, + } +} + +func (p *arangoClusterSynchronizationsInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return ArangoClusterSynchronizationGKv1() +} + +func (p *arangoClusterSynchronizationsInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return ArangoClusterSynchronizationGRv1() +} + +func (p *arangoClusterSynchronizationsInspector) GroupKind() schema.GroupKind { + return ArangoClusterSynchronizationGK() +} + +func (p *arangoClusterSynchronizationsInspector) GroupResource() schema.GroupResource { + return ArangoClusterSynchronizationGR() +} diff --git a/pkg/deployment/resources/inspector/acs_v1.go b/pkg/deployment/resources/inspector/acs_v1.go index bff16d68c..e61794f91 100644 --- a/pkg/deployment/resources/inspector/acs_v1.go +++ b/pkg/deployment/resources/inspector/acs_v1.go @@ -23,13 +23,11 @@ package inspector import ( "context" - "github.com/arangodb/kube-arangodb/pkg/apis/deployment" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *arangoClusterSynchronizationsInspector) V1() (ins.Inspector, error) { @@ -129,12 +127,9 @@ func (p *arangoClusterSynchronizationsInspectorV1) Read() ins.ReadInterface { return p } -func (p *arangoClusterSynchronizationsInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*api.ArangoClusterSynchronization, error) { +func (p *arangoClusterSynchronizationsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*api.ArangoClusterSynchronization, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: deployment.ArangoDeploymentGroupName, - Resource: deployment.ArangoClusterSynchronizationResourcePlural, - }, name) + return nil, apiErrors.NewNotFound(ArangoClusterSynchronizationGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/am_anonymous.go b/pkg/deployment/resources/inspector/am_anonymous.go new file mode 100644 index 000000000..ffa78dadf --- /dev/null +++ b/pkg/deployment/resources/inspector/am_anonymous.go @@ -0,0 +1,39 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *arangoMembersInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := ArangoMemberGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case ArangoMemberVersionV1: + return &arangoMembersInspectorAnonymousV1{i: p.v1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/am_anonymous_v1.go b/pkg/deployment/resources/inspector/am_anonymous_v1.go new file mode 100644 index 000000000..58b6e1beb --- /dev/null +++ b/pkg/deployment/resources/inspector/am_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type arangoMembersInspectorAnonymousV1 struct { + i *arangoMembersInspectorV1 +} + +func (e *arangoMembersInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/am_constants.go b/pkg/deployment/resources/inspector/am_constants.go new file mode 100644 index 000000000..41fdfc99c --- /dev/null +++ b/pkg/deployment/resources/inspector/am_constants.go @@ -0,0 +1,81 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/apis/deployment" + deploymentv1 "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// ArangoMember +const ( + ArangoMemberGroup = deployment.ArangoDeploymentGroupName + ArangoMemberResource = deployment.ArangoMemberResourcePlural + ArangoMemberKind = deployment.ArangoMemberResourceKind + ArangoMemberVersionV1 = deploymentv1.ArangoDeploymentVersion +) + +func ArangoMemberGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoMemberGroup, + Kind: ArangoMemberKind, + } +} + +func ArangoMemberGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoMemberGroup, + Kind: ArangoMemberKind, + Version: ArangoMemberVersionV1, + } +} + +func ArangoMemberGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoMemberGroup, + Resource: ArangoMemberResource, + } +} + +func ArangoMemberGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoMemberGroup, + Resource: ArangoMemberResource, + Version: ArangoMemberVersionV1, + } +} + +func (p *arangoMembersInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return ArangoMemberGKv1() +} + +func (p *arangoMembersInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return ArangoMemberGRv1() +} + +func (p *arangoMembersInspector) GroupKind() schema.GroupKind { + return ArangoMemberGK() +} + +func (p *arangoMembersInspector) GroupResource() schema.GroupResource { + return ArangoMemberGR() +} diff --git a/pkg/deployment/resources/inspector/am_v1.go b/pkg/deployment/resources/inspector/am_v1.go index b4e5a83dd..e5a6084ad 100644 --- a/pkg/deployment/resources/inspector/am_v1.go +++ b/pkg/deployment/resources/inspector/am_v1.go @@ -23,13 +23,11 @@ package inspector import ( "context" - "github.com/arangodb/kube-arangodb/pkg/apis/deployment" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *arangoMembersInspector) V1() ins.Inspector { @@ -109,12 +107,9 @@ func (p *arangoMembersInspectorV1) Read() ins.ReadInterface { return p } -func (p *arangoMembersInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*api.ArangoMember, error) { +func (p *arangoMembersInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*api.ArangoMember, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: deployment.ArangoDeploymentGroupName, - Resource: deployment.ArangoMemberResourcePlural, - }, name) + return nil, apiErrors.NewNotFound(ArangoMemberGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/at_anonymous.go b/pkg/deployment/resources/inspector/at_anonymous.go new file mode 100644 index 000000000..7ab452625 --- /dev/null +++ b/pkg/deployment/resources/inspector/at_anonymous.go @@ -0,0 +1,39 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *arangoTasksInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := ArangoTaskGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case ArangoTaskVersionV1: + return &arangoTasksInspectorAnonymousV1{i: p.v1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/at_anonymous_v1.go b/pkg/deployment/resources/inspector/at_anonymous_v1.go new file mode 100644 index 000000000..62e996b30 --- /dev/null +++ b/pkg/deployment/resources/inspector/at_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type arangoTasksInspectorAnonymousV1 struct { + i *arangoTasksInspectorV1 +} + +func (e *arangoTasksInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/at_constants.go b/pkg/deployment/resources/inspector/at_constants.go new file mode 100644 index 000000000..4550e0958 --- /dev/null +++ b/pkg/deployment/resources/inspector/at_constants.go @@ -0,0 +1,81 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/apis/deployment" + deploymentv1 "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// ArangoTask +const ( + ArangoTaskGroup = deployment.ArangoDeploymentGroupName + ArangoTaskResource = deployment.ArangoTaskResourcePlural + ArangoTaskKind = deployment.ArangoTaskResourceKind + ArangoTaskVersionV1 = deploymentv1.ArangoDeploymentVersion +) + +func ArangoTaskGK() schema.GroupKind { + return schema.GroupKind{ + Group: ArangoTaskGroup, + Kind: ArangoTaskKind, + } +} + +func ArangoTaskGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ArangoTaskGroup, + Kind: ArangoTaskKind, + Version: ArangoTaskVersionV1, + } +} + +func ArangoTaskGR() schema.GroupResource { + return schema.GroupResource{ + Group: ArangoTaskGroup, + Resource: ArangoTaskResource, + } +} + +func ArangoTaskGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ArangoTaskGroup, + Resource: ArangoTaskResource, + Version: ArangoTaskVersionV1, + } +} + +func (p *arangoTasksInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return ArangoTaskGKv1() +} + +func (p *arangoTasksInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return ArangoTaskGRv1() +} + +func (p *arangoTasksInspector) GroupKind() schema.GroupKind { + return ArangoTaskGK() +} + +func (p *arangoTasksInspector) GroupResource() schema.GroupResource { + return ArangoTaskGR() +} diff --git a/pkg/deployment/resources/inspector/at_v1.go b/pkg/deployment/resources/inspector/at_v1.go index 6ef4a8f4d..2e12216d1 100644 --- a/pkg/deployment/resources/inspector/at_v1.go +++ b/pkg/deployment/resources/inspector/at_v1.go @@ -23,13 +23,11 @@ package inspector import ( "context" - "github.com/arangodb/kube-arangodb/pkg/apis/deployment" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *arangoTasksInspector) V1() (ins.Inspector, error) { @@ -129,12 +127,9 @@ func (p *arangoTasksInspectorV1) Read() ins.ReadInterface { return p } -func (p *arangoTasksInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*api.ArangoTask, error) { +func (p *arangoTasksInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*api.ArangoTask, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: deployment.ArangoDeploymentGroupName, - Resource: deployment.ArangoTaskResourcePlural, - }, name) + return nil, apiErrors.NewNotFound(ArangoTaskGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/endpoints_anonymous.go b/pkg/deployment/resources/inspector/endpoints_anonymous.go new file mode 100644 index 000000000..fd311eaf2 --- /dev/null +++ b/pkg/deployment/resources/inspector/endpoints_anonymous.go @@ -0,0 +1,39 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *endpointsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := EndpointsGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case EndpointsVersionV1: + return &endpointsInspectorAnonymousV1{i: p.v1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/endpoints_anonymous_v1.go b/pkg/deployment/resources/inspector/endpoints_anonymous_v1.go new file mode 100644 index 000000000..7b5750beb --- /dev/null +++ b/pkg/deployment/resources/inspector/endpoints_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type endpointsInspectorAnonymousV1 struct { + i *endpointsInspectorV1 +} + +func (e *endpointsInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/endpoints_constants.go b/pkg/deployment/resources/inspector/endpoints_constants.go new file mode 100644 index 000000000..a05d29fae --- /dev/null +++ b/pkg/deployment/resources/inspector/endpoints_constants.go @@ -0,0 +1,80 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + core "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// Endpoints +const ( + EndpointsGroup = core.GroupName + EndpointsResource = "endpoints" + EndpointsKind = "Endpoints" + EndpointsVersionV1 = "v1" +) + +func EndpointsGK() schema.GroupKind { + return schema.GroupKind{ + Group: EndpointsGroup, + Kind: EndpointsKind, + } +} + +func EndpointsGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: EndpointsGroup, + Kind: EndpointsKind, + Version: EndpointsVersionV1, + } +} + +func EndpointsGR() schema.GroupResource { + return schema.GroupResource{ + Group: EndpointsGroup, + Resource: EndpointsResource, + } +} + +func EndpointsGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: EndpointsGroup, + Resource: EndpointsResource, + Version: EndpointsVersionV1, + } +} + +func (p *endpointsInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return EndpointsGKv1() +} + +func (p *endpointsInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return EndpointsGRv1() +} + +func (p *endpointsInspector) GroupKind() schema.GroupKind { + return EndpointsGK() +} + +func (p *endpointsInspector) GroupResource() schema.GroupResource { + return EndpointsGR() +} diff --git a/pkg/deployment/resources/inspector/endpoints_v1.go b/pkg/deployment/resources/inspector/endpoints_v1.go index 952cc7a17..c7ae28e6a 100644 --- a/pkg/deployment/resources/inspector/endpoints_v1.go +++ b/pkg/deployment/resources/inspector/endpoints_v1.go @@ -27,8 +27,7 @@ import ( ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints/v1" core "k8s.io/api/core/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *endpointsInspector) V1() (ins.Inspector, error) { @@ -128,12 +127,9 @@ func (p *endpointsInspectorV1) Read() ins.ReadInterface { return p } -func (p *endpointsInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*core.Endpoints, error) { +func (p *endpointsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Endpoints, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: core.GroupName, - Resource: "endpoints", - }, name) + return nil, apiErrors.NewNotFound(EndpointsGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/inspector.go b/pkg/deployment/resources/inspector/inspector.go index b4cf0acf3..712ebf647 100644 --- a/pkg/deployment/resources/inspector/inspector.go +++ b/pkg/deployment/resources/inspector/inspector.go @@ -32,6 +32,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask" @@ -48,6 +49,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/kclient" "github.com/rs/zerolog" meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" ) var ( @@ -157,6 +159,38 @@ type inspectorState struct { initialised bool } +func (i *inspectorState) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + for _, o := range i.AnonymousObjects() { + if o == nil { + continue + } + + obj, ok := o.Anonymous(gvk) + if ok { + return obj, true + } + } + + return nil, false +} + +func (i *inspectorState) AnonymousObjects() []anonymous.Impl { + return []anonymous.Impl{ + i.pods, + i.secrets, + i.persistentVolumeClaims, + i.services, + i.serviceAccounts, + i.nodes, + i.podDisruptionBudgets, + i.serviceMonitors, + i.arangoMembers, + i.arangoTasks, + i.arangoClusterSynchronizations, + i.endpoints, + } +} + func (i *inspectorState) GetCurrentArangoDeployment() (*api.ArangoDeployment, error) { if i.deploymentResult == nil { return nil, errors.Newf("Deployment not initialised") diff --git a/pkg/deployment/resources/inspector/nodes_anonymous.go b/pkg/deployment/resources/inspector/nodes_anonymous.go new file mode 100644 index 000000000..3ac5a4edb --- /dev/null +++ b/pkg/deployment/resources/inspector/nodes_anonymous.go @@ -0,0 +1,39 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *nodesInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := NodeGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case NodeVersionV1: + return &nodesInspectorAnonymousV1{i: p.v1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/nodes_anonymous_v1.go b/pkg/deployment/resources/inspector/nodes_anonymous_v1.go new file mode 100644 index 000000000..a00676008 --- /dev/null +++ b/pkg/deployment/resources/inspector/nodes_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type nodesInspectorAnonymousV1 struct { + i *nodesInspectorV1 +} + +func (e *nodesInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/nodes_constants.go b/pkg/deployment/resources/inspector/nodes_constants.go new file mode 100644 index 000000000..7dc93f287 --- /dev/null +++ b/pkg/deployment/resources/inspector/nodes_constants.go @@ -0,0 +1,80 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + core "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// Node +const ( + NodeGroup = core.GroupName + NodeResource = "nodes" + NodeKind = "Node" + NodeVersionV1 = "v1" +) + +func NodeGK() schema.GroupKind { + return schema.GroupKind{ + Group: NodeGroup, + Kind: NodeKind, + } +} + +func NodeGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: NodeGroup, + Kind: NodeKind, + Version: NodeVersionV1, + } +} + +func NodeGR() schema.GroupResource { + return schema.GroupResource{ + Group: NodeGroup, + Resource: NodeResource, + } +} + +func NodeGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: NodeGroup, + Resource: NodeResource, + Version: NodeVersionV1, + } +} + +func (p *nodesInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return NodeGKv1() +} + +func (p *nodesInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return NodeGRv1() +} + +func (p *nodesInspector) GroupKind() schema.GroupKind { + return NodeGK() +} + +func (p *nodesInspector) GroupResource() schema.GroupResource { + return NodeGR() +} diff --git a/pkg/deployment/resources/inspector/nodes_v1.go b/pkg/deployment/resources/inspector/nodes_v1.go index d17facd5a..c87dfba35 100644 --- a/pkg/deployment/resources/inspector/nodes_v1.go +++ b/pkg/deployment/resources/inspector/nodes_v1.go @@ -27,8 +27,7 @@ import ( ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/node/v1" core "k8s.io/api/core/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *nodesInspector) V1() (ins.Inspector, error) { @@ -112,12 +111,9 @@ func (p *nodesInspectorV1) Read() ins.ReadInterface { return p } -func (p *nodesInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*core.Node, error) { +func (p *nodesInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Node, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: core.GroupName, - Resource: "nodes", - }, name) + return nil, apiErrors.NewNotFound(NodeGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/pdbs_anonymous.go b/pkg/deployment/resources/inspector/pdbs_anonymous.go new file mode 100644 index 000000000..22d09071c --- /dev/null +++ b/pkg/deployment/resources/inspector/pdbs_anonymous.go @@ -0,0 +1,41 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *podDisruptionBudgetsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := PodDisruptionBudgetGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case PodDisruptionBudgetVersionV1: + return &podDisruptionBudgetsInspectorAnonymousV1{i: p.v1}, true + case PodDisruptionBudgetVersionV1Beta1: + return &podDisruptionBudgetsInspectorAnonymousV1Beta1{i: p.v1beta1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/pdbs_anonymous_v1.go b/pkg/deployment/resources/inspector/pdbs_anonymous_v1.go new file mode 100644 index 000000000..82b2cd2bc --- /dev/null +++ b/pkg/deployment/resources/inspector/pdbs_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type podDisruptionBudgetsInspectorAnonymousV1 struct { + i *podDisruptionBudgetsInspectorV1 +} + +func (e *podDisruptionBudgetsInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/pdbs_anonymous_v1beta1.go b/pkg/deployment/resources/inspector/pdbs_anonymous_v1beta1.go new file mode 100644 index 000000000..626bc3ce5 --- /dev/null +++ b/pkg/deployment/resources/inspector/pdbs_anonymous_v1beta1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type podDisruptionBudgetsInspectorAnonymousV1Beta1 struct { + i *podDisruptionBudgetsInspectorV1Beta1 +} + +func (e *podDisruptionBudgetsInspectorAnonymousV1Beta1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/pdbs_constants.go b/pkg/deployment/resources/inspector/pdbs_constants.go new file mode 100644 index 000000000..01c15d52e --- /dev/null +++ b/pkg/deployment/resources/inspector/pdbs_constants.go @@ -0,0 +1,105 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + policy "k8s.io/api/policy/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// PodDisruptionBudget +const ( + PodDisruptionBudgetGroup = policy.GroupName + PodDisruptionBudgetResource = "poddisruptionbudgets" + PodDisruptionBudgetKind = "PodDisruptionBudget" + PodDisruptionBudgetVersionV1Beta1 = "v1beta1" + PodDisruptionBudgetVersionV1 = "v1" +) + +func PodDisruptionBudgetGK() schema.GroupKind { + return schema.GroupKind{ + Group: PodDisruptionBudgetGroup, + Kind: PodDisruptionBudgetKind, + } +} + +func PodDisruptionBudgetGKv1Beta1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: PodDisruptionBudgetGroup, + Kind: PodDisruptionBudgetKind, + Version: PodDisruptionBudgetVersionV1Beta1, + } +} + +func PodDisruptionBudgetGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: PodDisruptionBudgetGroup, + Kind: PodDisruptionBudgetKind, + Version: PodDisruptionBudgetVersionV1, + } +} + +func PodDisruptionBudgetGR() schema.GroupResource { + return schema.GroupResource{ + Group: PodDisruptionBudgetGroup, + Resource: PodDisruptionBudgetResource, + } +} + +func PodDisruptionBudgetGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: PodDisruptionBudgetGroup, + Resource: PodDisruptionBudgetResource, + Version: PodDisruptionBudgetVersionV1, + } +} + +func PodDisruptionBudgetGRv1Beta1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: PodDisruptionBudgetGroup, + Resource: PodDisruptionBudgetResource, + Version: PodDisruptionBudgetVersionV1Beta1, + } +} + +func (p *podDisruptionBudgetsInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return PodDisruptionBudgetGKv1() +} + +func (p *podDisruptionBudgetsInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return PodDisruptionBudgetGRv1() +} + +func (p *podDisruptionBudgetsInspectorV1Beta1) GroupVersionKind() schema.GroupVersionKind { + return PodDisruptionBudgetGKv1Beta1() +} + +func (p *podDisruptionBudgetsInspectorV1Beta1) GroupVersionResource() schema.GroupVersionResource { + return PodDisruptionBudgetGRv1Beta1() +} + +func (p *podDisruptionBudgetsInspector) GroupKind() schema.GroupKind { + return PodDisruptionBudgetGK() +} + +func (p *podDisruptionBudgetsInspector) GroupResource() schema.GroupResource { + return PodDisruptionBudgetGR() +} diff --git a/pkg/deployment/resources/inspector/pdbs_v1.go b/pkg/deployment/resources/inspector/pdbs_v1.go index 60a2653d6..6962de04b 100644 --- a/pkg/deployment/resources/inspector/pdbs_v1.go +++ b/pkg/deployment/resources/inspector/pdbs_v1.go @@ -27,8 +27,7 @@ import ( ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1" policy "k8s.io/api/policy/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *podDisruptionBudgetsInspector) V1() (ins.Inspector, error) { @@ -112,12 +111,9 @@ func (p *podDisruptionBudgetsInspectorV1) Read() ins.ReadInterface { return p } -func (p *podDisruptionBudgetsInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*policy.PodDisruptionBudget, error) { +func (p *podDisruptionBudgetsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*policy.PodDisruptionBudget, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: policy.GroupName, - Resource: "podDisruptionBudgets", - }, name) + return nil, apiErrors.NewNotFound(PodDisruptionBudgetGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/pdbs_v1beta1.go b/pkg/deployment/resources/inspector/pdbs_v1beta1.go index bdca5ea10..458b07a1e 100644 --- a/pkg/deployment/resources/inspector/pdbs_v1beta1.go +++ b/pkg/deployment/resources/inspector/pdbs_v1beta1.go @@ -27,8 +27,7 @@ import ( ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1beta1" policy "k8s.io/api/policy/v1beta1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *podDisruptionBudgetsInspector) V1Beta1() (ins.Inspector, error) { @@ -112,12 +111,9 @@ func (p *podDisruptionBudgetsInspectorV1Beta1) Read() ins.ReadInterface { return p } -func (p *podDisruptionBudgetsInspectorV1Beta1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*policy.PodDisruptionBudget, error) { +func (p *podDisruptionBudgetsInspectorV1Beta1) Get(ctx context.Context, name string, opts meta.GetOptions) (*policy.PodDisruptionBudget, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: policy.GroupName, - Resource: "podDisruptionBudgets", - }, name) + return nil, apiErrors.NewNotFound(PodDisruptionBudgetGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/pods_anonymous.go b/pkg/deployment/resources/inspector/pods_anonymous.go new file mode 100644 index 000000000..b5c0b9dee --- /dev/null +++ b/pkg/deployment/resources/inspector/pods_anonymous.go @@ -0,0 +1,39 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *podsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := PodGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case PodVersionV1: + return &podsInspectorAnonymousV1{i: p.v1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/pods_anonymous_v1.go b/pkg/deployment/resources/inspector/pods_anonymous_v1.go new file mode 100644 index 000000000..80c99a5df --- /dev/null +++ b/pkg/deployment/resources/inspector/pods_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type podsInspectorAnonymousV1 struct { + i *podsInspectorV1 +} + +func (e *podsInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/pods_constants.go b/pkg/deployment/resources/inspector/pods_constants.go new file mode 100644 index 000000000..7fb59b36e --- /dev/null +++ b/pkg/deployment/resources/inspector/pods_constants.go @@ -0,0 +1,80 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + core "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// Pod +const ( + PodGroup = core.GroupName + PodResource = "pods" + PodKind = "Pod" + PodVersionV1 = "v1" +) + +func PodGK() schema.GroupKind { + return schema.GroupKind{ + Group: PodGroup, + Kind: PodKind, + } +} + +func PodGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: PodGroup, + Kind: PodKind, + Version: PodVersionV1, + } +} + +func PodGR() schema.GroupResource { + return schema.GroupResource{ + Group: PodGroup, + Resource: PodResource, + } +} + +func PodGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: PodGroup, + Resource: PodResource, + Version: PodVersionV1, + } +} + +func (p *podsInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return PodGKv1() +} + +func (p *podsInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return PodGRv1() +} + +func (p *podsInspector) GroupKind() schema.GroupKind { + return PodGK() +} + +func (p *podsInspector) GroupResource() schema.GroupResource { + return PodGR() +} diff --git a/pkg/deployment/resources/inspector/pods_v1.go b/pkg/deployment/resources/inspector/pods_v1.go index 2a5cedc29..dcd3895b8 100644 --- a/pkg/deployment/resources/inspector/pods_v1.go +++ b/pkg/deployment/resources/inspector/pods_v1.go @@ -27,8 +27,7 @@ import ( ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" core "k8s.io/api/core/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *podsInspector) V1() ins.Inspector { @@ -109,12 +108,9 @@ func (p *podsInspectorV1) Read() ins.ReadInterface { return p } -func (p *podsInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*core.Pod, error) { +func (p *podsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Pod, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: core.GroupName, - Resource: "pods", - }, name) + return nil, apiErrors.NewNotFound(PodGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/pvcs_anonymous.go b/pkg/deployment/resources/inspector/pvcs_anonymous.go new file mode 100644 index 000000000..8762d7f14 --- /dev/null +++ b/pkg/deployment/resources/inspector/pvcs_anonymous.go @@ -0,0 +1,39 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *persistentVolumeClaimsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := PersistentVolumeClaimGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case PersistentVolumeClaimVersionV1: + return &persistentVolumeClaimsInspectorAnonymousV1{i: p.v1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/pvcs_anonymous_v1.go b/pkg/deployment/resources/inspector/pvcs_anonymous_v1.go new file mode 100644 index 000000000..0b6e0462d --- /dev/null +++ b/pkg/deployment/resources/inspector/pvcs_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type persistentVolumeClaimsInspectorAnonymousV1 struct { + i *persistentVolumeClaimsInspectorV1 +} + +func (e *persistentVolumeClaimsInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/pvcs_constants.go b/pkg/deployment/resources/inspector/pvcs_constants.go new file mode 100644 index 000000000..6e3ac4fda --- /dev/null +++ b/pkg/deployment/resources/inspector/pvcs_constants.go @@ -0,0 +1,80 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + core "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// PersistentVolumeClaim +const ( + PersistentVolumeClaimGroup = core.GroupName + PersistentVolumeClaimResource = "persistentvolumeclaims" + PersistentVolumeClaimKind = "PersistentVolumeClaim" + PersistentVolumeClaimVersionV1 = "v1" +) + +func PersistentVolumeClaimGK() schema.GroupKind { + return schema.GroupKind{ + Group: PersistentVolumeClaimGroup, + Kind: PersistentVolumeClaimKind, + } +} + +func PersistentVolumeClaimGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: PersistentVolumeClaimGroup, + Kind: PersistentVolumeClaimKind, + Version: PersistentVolumeClaimVersionV1, + } +} + +func PersistentVolumeClaimGR() schema.GroupResource { + return schema.GroupResource{ + Group: PersistentVolumeClaimGroup, + Resource: PersistentVolumeClaimResource, + } +} + +func PersistentVolumeClaimGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: PersistentVolumeClaimGroup, + Resource: PersistentVolumeClaimResource, + Version: PersistentVolumeClaimVersionV1, + } +} + +func (p *persistentVolumeClaimsInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return PersistentVolumeClaimGKv1() +} + +func (p *persistentVolumeClaimsInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return PersistentVolumeClaimGRv1() +} + +func (p *persistentVolumeClaimsInspector) GroupKind() schema.GroupKind { + return PersistentVolumeClaimGK() +} + +func (p *persistentVolumeClaimsInspector) GroupResource() schema.GroupResource { + return PersistentVolumeClaimGR() +} diff --git a/pkg/deployment/resources/inspector/pvcs_v1.go b/pkg/deployment/resources/inspector/pvcs_v1.go index 815cc2f2d..42f6d2b2a 100644 --- a/pkg/deployment/resources/inspector/pvcs_v1.go +++ b/pkg/deployment/resources/inspector/pvcs_v1.go @@ -27,8 +27,7 @@ import ( ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1" core "k8s.io/api/core/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *persistentVolumeClaimsInspector) V1() ins.Inspector { @@ -108,12 +107,9 @@ func (p *persistentVolumeClaimsInspectorV1) Read() ins.ReadInterface { return p } -func (p *persistentVolumeClaimsInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*core.PersistentVolumeClaim, error) { +func (p *persistentVolumeClaimsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.PersistentVolumeClaim, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: core.GroupName, - Resource: "persistentVolumeClaims", - }, name) + return nil, apiErrors.NewNotFound(PersistentVolumeClaimGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/sa_anonymous.go b/pkg/deployment/resources/inspector/sa_anonymous.go new file mode 100644 index 000000000..fd972fa1c --- /dev/null +++ b/pkg/deployment/resources/inspector/sa_anonymous.go @@ -0,0 +1,39 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *serviceAccountsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := ServiceAccountGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case ServiceAccountVersionV1: + return &serviceAccountsInspectorAnonymousV1{i: p.v1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/sa_anonymous_v1.go b/pkg/deployment/resources/inspector/sa_anonymous_v1.go new file mode 100644 index 000000000..8f4452922 --- /dev/null +++ b/pkg/deployment/resources/inspector/sa_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type serviceAccountsInspectorAnonymousV1 struct { + i *serviceAccountsInspectorV1 +} + +func (e *serviceAccountsInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/sa_constants.go b/pkg/deployment/resources/inspector/sa_constants.go new file mode 100644 index 000000000..6aa12eafd --- /dev/null +++ b/pkg/deployment/resources/inspector/sa_constants.go @@ -0,0 +1,80 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + core "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// ServiceAccount +const ( + ServiceAccountGroup = core.GroupName + ServiceAccountResource = "serviceaccounts" + ServiceAccountKind = "ServiceAccount" + ServiceAccountVersionV1 = "v1" +) + +func ServiceAccountGK() schema.GroupKind { + return schema.GroupKind{ + Group: ServiceAccountGroup, + Kind: ServiceAccountKind, + } +} + +func ServiceAccountGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ServiceAccountGroup, + Kind: ServiceAccountKind, + Version: ServiceAccountVersionV1, + } +} + +func ServiceAccountGR() schema.GroupResource { + return schema.GroupResource{ + Group: ServiceAccountGroup, + Resource: ServiceAccountResource, + } +} + +func ServiceAccountGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ServiceAccountGroup, + Resource: ServiceAccountResource, + Version: ServiceAccountVersionV1, + } +} + +func (p *serviceAccountsInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return ServiceAccountGKv1() +} + +func (p *serviceAccountsInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return ServiceAccountGRv1() +} + +func (p *serviceAccountsInspector) GroupKind() schema.GroupKind { + return ServiceAccountGK() +} + +func (p *serviceAccountsInspector) GroupResource() schema.GroupResource { + return ServiceAccountGR() +} diff --git a/pkg/deployment/resources/inspector/sa_v1.go b/pkg/deployment/resources/inspector/sa_v1.go index 2bf08ee2f..45add9e9c 100644 --- a/pkg/deployment/resources/inspector/sa_v1.go +++ b/pkg/deployment/resources/inspector/sa_v1.go @@ -27,8 +27,7 @@ import ( ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount/v1" core "k8s.io/api/core/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *serviceAccountsInspector) V1() ins.Inspector { @@ -108,12 +107,9 @@ func (p *serviceAccountsInspectorV1) Read() ins.ReadInterface { return p } -func (p *serviceAccountsInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*core.ServiceAccount, error) { +func (p *serviceAccountsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.ServiceAccount, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: core.GroupName, - Resource: "serviceAccounts", - }, name) + return nil, apiErrors.NewNotFound(ServiceAccountGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/secrets_anonymous.go b/pkg/deployment/resources/inspector/secrets_anonymous.go new file mode 100644 index 000000000..464dbde0b --- /dev/null +++ b/pkg/deployment/resources/inspector/secrets_anonymous.go @@ -0,0 +1,39 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *secretsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := SecretGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case SecretVersionV1: + return &secretsInspectorAnonymousV1{i: p.v1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/secrets_anonymous_v1.go b/pkg/deployment/resources/inspector/secrets_anonymous_v1.go new file mode 100644 index 000000000..d485a41d6 --- /dev/null +++ b/pkg/deployment/resources/inspector/secrets_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type secretsInspectorAnonymousV1 struct { + i *secretsInspectorV1 +} + +func (e *secretsInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/secrets_constants.go b/pkg/deployment/resources/inspector/secrets_constants.go new file mode 100644 index 000000000..a7f73aa38 --- /dev/null +++ b/pkg/deployment/resources/inspector/secrets_constants.go @@ -0,0 +1,80 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + core "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// Secret +const ( + SecretGroup = core.GroupName + SecretResource = "secrets" + SecretKind = "Secret" + SecretVersionV1 = "v1" +) + +func SecretGK() schema.GroupKind { + return schema.GroupKind{ + Group: SecretGroup, + Kind: SecretKind, + } +} + +func SecretGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: SecretGroup, + Kind: SecretKind, + Version: SecretVersionV1, + } +} + +func SecretGR() schema.GroupResource { + return schema.GroupResource{ + Group: SecretGroup, + Resource: SecretResource, + } +} + +func SecretGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: SecretGroup, + Resource: SecretResource, + Version: SecretVersionV1, + } +} + +func (p *secretsInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return SecretGKv1() +} + +func (p *secretsInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return SecretGRv1() +} + +func (p *secretsInspector) GroupKind() schema.GroupKind { + return SecretGK() +} + +func (p *secretsInspector) GroupResource() schema.GroupResource { + return SecretGR() +} diff --git a/pkg/deployment/resources/inspector/secrets_v1.go b/pkg/deployment/resources/inspector/secrets_v1.go index 8fcf468c8..7987ea9da 100644 --- a/pkg/deployment/resources/inspector/secrets_v1.go +++ b/pkg/deployment/resources/inspector/secrets_v1.go @@ -27,8 +27,7 @@ import ( ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" core "k8s.io/api/core/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *secretsInspector) V1() ins.Inspector { @@ -108,12 +107,9 @@ func (p *secretsInspectorV1) Read() ins.ReadInterface { return p } -func (p *secretsInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*core.Secret, error) { +func (p *secretsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Secret, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: core.GroupName, - Resource: "secrets", - }, name) + return nil, apiErrors.NewNotFound(SecretGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/services_anonymous.go b/pkg/deployment/resources/inspector/services_anonymous.go new file mode 100644 index 000000000..311b1c482 --- /dev/null +++ b/pkg/deployment/resources/inspector/services_anonymous.go @@ -0,0 +1,39 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *servicesInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := ServiceGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case ServiceVersionV1: + return &servicesInspectorAnonymousV1{i: p.v1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/services_anonymous_v1.go b/pkg/deployment/resources/inspector/services_anonymous_v1.go new file mode 100644 index 000000000..85a0bbd4d --- /dev/null +++ b/pkg/deployment/resources/inspector/services_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type servicesInspectorAnonymousV1 struct { + i *servicesInspectorV1 +} + +func (e *servicesInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/services_constants.go b/pkg/deployment/resources/inspector/services_constants.go new file mode 100644 index 000000000..65732e4fe --- /dev/null +++ b/pkg/deployment/resources/inspector/services_constants.go @@ -0,0 +1,80 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + core "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// Service +const ( + ServiceGroup = core.GroupName + ServiceResource = "services" + ServiceKind = "Service" + ServiceVersionV1 = "v1" +) + +func ServiceGK() schema.GroupKind { + return schema.GroupKind{ + Group: ServiceGroup, + Kind: ServiceKind, + } +} + +func ServiceGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ServiceGroup, + Kind: ServiceKind, + Version: ServiceVersionV1, + } +} + +func ServiceGR() schema.GroupResource { + return schema.GroupResource{ + Group: ServiceGroup, + Resource: ServiceResource, + } +} + +func ServiceGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ServiceGroup, + Resource: ServiceResource, + Version: ServiceVersionV1, + } +} + +func (p *servicesInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return ServiceGKv1() +} + +func (p *servicesInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return ServiceGRv1() +} + +func (p *servicesInspector) GroupKind() schema.GroupKind { + return ServiceGK() +} + +func (p *servicesInspector) GroupResource() schema.GroupResource { + return ServiceGR() +} diff --git a/pkg/deployment/resources/inspector/services_v1.go b/pkg/deployment/resources/inspector/services_v1.go index 89028e66b..3dd741a06 100644 --- a/pkg/deployment/resources/inspector/services_v1.go +++ b/pkg/deployment/resources/inspector/services_v1.go @@ -27,8 +27,7 @@ import ( ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" core "k8s.io/api/core/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *servicesInspector) V1() ins.Inspector { @@ -108,12 +107,9 @@ func (p *servicesInspectorV1) Read() ins.ReadInterface { return p } -func (p *servicesInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*core.Service, error) { +func (p *servicesInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.Service, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: core.GroupName, - Resource: "services", - }, name) + return nil, apiErrors.NewNotFound(ServiceGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/inspector/sm_anonymous.go b/pkg/deployment/resources/inspector/sm_anonymous.go new file mode 100644 index 000000000..cc9df7a67 --- /dev/null +++ b/pkg/deployment/resources/inspector/sm_anonymous.go @@ -0,0 +1,39 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func (p *serviceMonitorsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) { + g := ServiceMonitorGK() + + if g.Kind == gvk.Kind && g.Group == gvk.Group { + switch gvk.Version { + case ServiceMonitorVersionV1: + return &serviceMonitorsInspectorAnonymousV1{i: p.v1}, true + } + } + + return nil, false +} diff --git a/pkg/deployment/resources/inspector/sm_anonymous_v1.go b/pkg/deployment/resources/inspector/sm_anonymous_v1.go new file mode 100644 index 000000000..10f089564 --- /dev/null +++ b/pkg/deployment/resources/inspector/sm_anonymous_v1.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type serviceMonitorsInspectorAnonymousV1 struct { + i *serviceMonitorsInspectorV1 +} + +func (e *serviceMonitorsInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) { + return e.i.Get(ctx, name, opts) +} diff --git a/pkg/deployment/resources/inspector/sm_constants.go b/pkg/deployment/resources/inspector/sm_constants.go new file mode 100644 index 000000000..5d414454c --- /dev/null +++ b/pkg/deployment/resources/inspector/sm_constants.go @@ -0,0 +1,80 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package inspector + +import ( + monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// ServiceMonitor +const ( + ServiceMonitorGroup = monitoring.GroupName + ServiceMonitorResource = "servicemonitors" + ServiceMonitorKind = "ServiceMonitor" + ServiceMonitorVersionV1 = "v1" +) + +func ServiceMonitorGK() schema.GroupKind { + return schema.GroupKind{ + Group: ServiceMonitorGroup, + Kind: ServiceMonitorKind, + } +} + +func ServiceMonitorGKv1() schema.GroupVersionKind { + return schema.GroupVersionKind{ + Group: ServiceMonitorGroup, + Kind: ServiceMonitorKind, + Version: ServiceMonitorVersionV1, + } +} + +func ServiceMonitorGR() schema.GroupResource { + return schema.GroupResource{ + Group: ServiceMonitorGroup, + Resource: ServiceMonitorResource, + } +} + +func ServiceMonitorGRv1() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: ServiceMonitorGroup, + Resource: ServiceMonitorResource, + Version: ServiceMonitorVersionV1, + } +} + +func (p *serviceMonitorsInspectorV1) GroupVersionKind() schema.GroupVersionKind { + return ServiceMonitorGKv1() +} + +func (p *serviceMonitorsInspectorV1) GroupVersionResource() schema.GroupVersionResource { + return ServiceMonitorGRv1() +} + +func (p *serviceMonitorsInspector) GroupKind() schema.GroupKind { + return ServiceMonitorGK() +} + +func (p *serviceMonitorsInspector) GroupResource() schema.GroupResource { + return ServiceMonitorGR() +} diff --git a/pkg/deployment/resources/inspector/sm_v1.go b/pkg/deployment/resources/inspector/sm_v1.go index 221aca0d3..c7f065071 100644 --- a/pkg/deployment/resources/inspector/sm_v1.go +++ b/pkg/deployment/resources/inspector/sm_v1.go @@ -25,12 +25,9 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/errors" ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor/v1" - core "k8s.io/api/core/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + apiErrors "k8s.io/apimachinery/pkg/api/errors" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (p *serviceMonitorsInspector) V1() (ins.Inspector, error) { @@ -114,12 +111,9 @@ func (p *serviceMonitorsInspectorV1) Read() ins.ReadInterface { return p } -func (p *serviceMonitorsInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*monitoring.ServiceMonitor, error) { +func (p *serviceMonitorsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*monitoring.ServiceMonitor, error) { if s, ok := p.GetSimple(name); !ok { - return nil, apiErrors.NewNotFound(schema.GroupResource{ - Group: core.GroupName, - Resource: "serviceMonitors", - }, name) + return nil, apiErrors.NewNotFound(ServiceMonitorGR(), name) } else { return s, nil } diff --git a/pkg/deployment/resources/member_cleanup.go b/pkg/deployment/resources/member_cleanup.go index 6afdbea00..919751942 100644 --- a/pkg/deployment/resources/member_cleanup.go +++ b/pkg/deployment/resources/member_cleanup.go @@ -25,7 +25,7 @@ import ( "time" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -137,9 +137,9 @@ func (r *Resources) EnsureArangoMembers(ctx context.Context, cachedStatus inspec if !c.Exists(ctx) { // Create ArangoMember obj := &api.ArangoMember{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: name, - OwnerReferences: []metav1.OwnerReference{ + OwnerReferences: []meta.OwnerReference{ obj.AsOwner(), }, }, @@ -159,7 +159,7 @@ func (r *Resources) EnsureArangoMembers(ctx context.Context, cachedStatus inspec if err := c.Update(ctx, func(m *api.ArangoMember) bool { changed := false if len(m.OwnerReferences) == 0 { - m.OwnerReferences = []metav1.OwnerReference{ + m.OwnerReferences = []meta.OwnerReference{ obj.AsOwner(), } changed = true diff --git a/pkg/deployment/resources/pdbs.go b/pkg/deployment/resources/pdbs.go index 56af02e56..9890b3544 100644 --- a/pkg/deployment/resources/pdbs.go +++ b/pkg/deployment/resources/pdbs.go @@ -32,7 +32,7 @@ import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" policyv1beta1 "k8s.io/api/policy/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -89,15 +89,15 @@ func PDBNameForGroup(depl string, group api.ServerGroup) string { return fmt.Sprintf("%s-%s-pdb", depl, group.AsRole()) } -func newPDB(minAvail int, deplname string, group api.ServerGroup, owner metav1.OwnerReference) *policyv1beta1.PodDisruptionBudget { +func newPDB(minAvail int, deplname string, group api.ServerGroup, owner meta.OwnerReference) *policyv1beta1.PodDisruptionBudget { return &policyv1beta1.PodDisruptionBudget{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: PDBNameForGroup(deplname, group), - OwnerReferences: []metav1.OwnerReference{owner}, + OwnerReferences: []meta.OwnerReference{owner}, }, Spec: policyv1beta1.PodDisruptionBudgetSpec{ MinAvailable: newFromInt(minAvail), - Selector: &metav1.LabelSelector{ + Selector: &meta.LabelSelector{ MatchLabels: k8sutil.LabelsForDeployment(deplname, group.AsRole()), }, }, @@ -119,7 +119,7 @@ func (r *Resources) ensurePDBForGroup(ctx context.Context, group api.ServerGroup var pdb *policyv1beta1.PodDisruptionBudget err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { var err error - pdb, err = i.Read().Get(ctxChild, pdbname, metav1.GetOptions{}) + pdb, err = i.Read().Get(ctxChild, pdbname, meta.GetOptions{}) return err }) if k8sutil.IsNotFound(err) { @@ -128,7 +128,7 @@ func (r *Resources) ensurePDBForGroup(ctx context.Context, group api.ServerGroup pdb := newPDB(wantedMinAvail, deplname, group, r.context.GetAPIObject().AsOwner()) log.Debug().Msg("Creating new PDB") err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := r.context.PodDisruptionBudgetsModInterface().Create(ctxChild, pdb, metav1.CreateOptions{}) + _, err := r.context.PodDisruptionBudgetsModInterface().Create(ctxChild, pdb, meta.CreateOptions{}) return err }) if err != nil { @@ -153,7 +153,7 @@ func (r *Resources) ensurePDBForGroup(ctx context.Context, group api.ServerGroup if pdb.GetDeletionTimestamp() == nil { // Update the PDB err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return r.context.PodDisruptionBudgetsModInterface().Delete(ctxChild, pdbname, metav1.DeleteOptions{}) + return r.context.PodDisruptionBudgetsModInterface().Delete(ctxChild, pdbname, meta.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { log.Error().Err(err).Msg("PDB deletion failed") diff --git a/pkg/deployment/resources/pod_creator_agent_args_test.go b/pkg/deployment/resources/pod_creator_agent_args_test.go index 00bcd42fd..aa0d028a5 100644 --- a/pkg/deployment/resources/pod_creator_agent_args_test.go +++ b/pkg/deployment/resources/pod_creator_agent_args_test.go @@ -28,7 +28,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/assert" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "context" @@ -47,7 +47,7 @@ func createClient(f kclient.FakeClientBuilder, apiObject *api.ArangoDeployment, memberName := a.ArangoMemberName(apiObject.GetName(), group) svc := core.Service{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: memberName, Namespace: tests.FakeNamespace, }, @@ -75,7 +75,7 @@ func TestCreateArangodArgsAgent(t *testing.T) { // Default deployment { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -135,7 +135,7 @@ func TestCreateArangodArgsAgent(t *testing.T) { // Default+AutoUpgrade deployment { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -197,7 +197,7 @@ func TestCreateArangodArgsAgent(t *testing.T) { // Default+TLS disabled deployment { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -259,7 +259,7 @@ func TestCreateArangodArgsAgent(t *testing.T) { // No authentication, mmfiles { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -320,7 +320,7 @@ func TestCreateArangodArgsAgent(t *testing.T) { // Custom args { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, diff --git a/pkg/deployment/resources/pod_creator_coordinator_args_test.go b/pkg/deployment/resources/pod_creator_coordinator_args_test.go index 71590f405..d337eebdb 100644 --- a/pkg/deployment/resources/pod_creator_coordinator_args_test.go +++ b/pkg/deployment/resources/pod_creator_coordinator_args_test.go @@ -29,7 +29,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/deployment/pod" "github.com/stretchr/testify/assert" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/apis/shared" @@ -45,7 +45,7 @@ func TestCreateArangodArgsCoordinator(t *testing.T) { // Default deployment { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -104,7 +104,7 @@ func TestCreateArangodArgsCoordinator(t *testing.T) { // Default+AutoUpgrade deployment { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -164,7 +164,7 @@ func TestCreateArangodArgsCoordinator(t *testing.T) { // Default+AutoUpgrade deployment for 3.6.0 { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -224,7 +224,7 @@ func TestCreateArangodArgsCoordinator(t *testing.T) { // Default+TLS disabled deployment { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -284,7 +284,7 @@ func TestCreateArangodArgsCoordinator(t *testing.T) { // No authentication { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -343,7 +343,7 @@ func TestCreateArangodArgsCoordinator(t *testing.T) { // Custom args, RocksDB { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, diff --git a/pkg/deployment/resources/pod_creator_dbserver_args_test.go b/pkg/deployment/resources/pod_creator_dbserver_args_test.go index 0bb27ec45..bc48fe8a3 100644 --- a/pkg/deployment/resources/pod_creator_dbserver_args_test.go +++ b/pkg/deployment/resources/pod_creator_dbserver_args_test.go @@ -29,7 +29,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/deployment/pod" "github.com/stretchr/testify/assert" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/apis/shared" @@ -45,7 +45,7 @@ func TestCreateArangodArgsDBServer(t *testing.T) { // Default deployment { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -104,7 +104,7 @@ func TestCreateArangodArgsDBServer(t *testing.T) { // Default+AutoUpgrade deployment { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -164,7 +164,7 @@ func TestCreateArangodArgsDBServer(t *testing.T) { // Default+ClusterDomain deployment { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -225,7 +225,7 @@ func TestCreateArangodArgsDBServer(t *testing.T) { // Default+TLS disabled deployment { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -285,7 +285,7 @@ func TestCreateArangodArgsDBServer(t *testing.T) { // No authentication { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, @@ -344,7 +344,7 @@ func TestCreateArangodArgsDBServer(t *testing.T) { // Custom args, MMFiles { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, diff --git a/pkg/deployment/resources/pod_creator_single_args_test.go b/pkg/deployment/resources/pod_creator_single_args_test.go index 3ac268e5e..df10f138b 100644 --- a/pkg/deployment/resources/pod_creator_single_args_test.go +++ b/pkg/deployment/resources/pod_creator_single_args_test.go @@ -28,7 +28,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/deployment/pod" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/apis/shared" @@ -309,7 +309,7 @@ func TestCreateArangodArgsSingle(t *testing.T) { // ActiveFailover { apiObject := &api.ArangoDeployment{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: "name", Namespace: tests.FakeNamespace, }, diff --git a/pkg/deployment/resources/pod_finalizers.go b/pkg/deployment/resources/pod_finalizers.go index 94e772a3b..136cee88a 100644 --- a/pkg/deployment/resources/pod_finalizers.go +++ b/pkg/deployment/resources/pod_finalizers.go @@ -30,7 +30,7 @@ import ( "github.com/rs/zerolog" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util" @@ -147,7 +147,7 @@ func (r *Resources) inspectFinalizerPodAgencyServing(ctx context.Context, log ze // of the agent, also remove the PVC if memberStatus.Conditions.IsTrue(api.ConditionTypeAgentRecoveryNeeded) { err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return r.context.PersistentVolumeClaimsModInterface().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, metav1.DeleteOptions{}) + return r.context.PersistentVolumeClaimsModInterface().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, meta.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { log.Warn().Err(err).Msg("Failed to delete PVC for member") @@ -176,7 +176,7 @@ func (r *Resources) inspectFinalizerPodDrainDBServer(ctx context.Context, log ze // If this DBServer is cleaned out, we need to remove the PVC. if memberStatus.Conditions.IsTrue(api.ConditionTypeCleanedOut) || memberStatus.Phase == api.MemberPhaseDrain { err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return r.context.PersistentVolumeClaimsModInterface().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, metav1.DeleteOptions{}) + return r.context.PersistentVolumeClaimsModInterface().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, meta.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { log.Warn().Err(err).Msg("Failed to delete PVC for member") diff --git a/pkg/deployment/resources/pod_inspector.go b/pkg/deployment/resources/pod_inspector.go index 26ee0e6f8..73e8fb2fe 100644 --- a/pkg/deployment/resources/pod_inspector.go +++ b/pkg/deployment/resources/pod_inspector.go @@ -31,7 +31,7 @@ import ( inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "strings" @@ -108,7 +108,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter nextInterval = nextInterval.ReduceTo(recheckSoonPodInspectorInterval) if !wasTerminated { // Record termination time - now := metav1.Now() + now := meta.Now() memberStatus.RecentTerminations = append(memberStatus.RecentTerminations, now) } } @@ -173,7 +173,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter nextInterval = nextInterval.ReduceTo(recheckSoonPodInspectorInterval) if !wasTerminated { // Record termination time - now := metav1.Now() + now := meta.Now() memberStatus.RecentTerminations = append(memberStatus.RecentTerminations, now) } } @@ -327,7 +327,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter if m.Conditions.Update(api.ConditionTypeTerminated, true, "Pod Terminated", "") { if !wasTerminated { // Record termination time - now := metav1.Now() + now := meta.Now() m.RecentTerminations = append(m.RecentTerminations, now) } // Save it @@ -349,7 +349,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter if m.Conditions.Update(api.ConditionTypeTerminated, true, "Pod Does Not Exist", "") { if !wasTerminated { // Record termination time - now := metav1.Now() + now := meta.Now() m.RecentTerminations = append(m.RecentTerminations, now) } updateMemberNeeded = true diff --git a/pkg/deployment/resources/pod_termination.go b/pkg/deployment/resources/pod_termination.go index 61f7b6f44..4660431de 100644 --- a/pkg/deployment/resources/pod_termination.go +++ b/pkg/deployment/resources/pod_termination.go @@ -29,7 +29,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/rs/zerolog" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" driver "github.com/arangodb/go-driver" "github.com/arangodb/go-driver/agency" @@ -72,7 +72,7 @@ func (r *Resources) prepareAgencyPodTermination(ctx context.Context, log zerolog // Check PVC ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() - pvc, err := r.context.GetCachedStatus().PersistentVolumeClaim().V1().Read().Get(ctxChild, memberStatus.PersistentVolumeClaimName, metav1.GetOptions{}) + pvc, err := r.context.GetCachedStatus().PersistentVolumeClaim().V1().Read().Get(ctxChild, memberStatus.PersistentVolumeClaimName, meta.GetOptions{}) if err != nil { log.Warn().Err(err).Msg("Failed to get PVC for member") return errors.WithStack(err) @@ -157,7 +157,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, log zerol // Check PVC ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() - pvc, err := r.context.GetCachedStatus().PersistentVolumeClaim().V1().Read().Get(ctxChild, memberStatus.PersistentVolumeClaimName, metav1.GetOptions{}) + pvc, err := r.context.GetCachedStatus().PersistentVolumeClaim().V1().Read().Get(ctxChild, memberStatus.PersistentVolumeClaimName, meta.GetOptions{}) if err != nil { log.Warn().Err(err).Msg("Failed to get PVC for member") return errors.WithStack(err) diff --git a/pkg/deployment/resources/pvc_finalizers.go b/pkg/deployment/resources/pvc_finalizers.go index 7c0245241..b4783ac88 100644 --- a/pkg/deployment/resources/pvc_finalizers.go +++ b/pkg/deployment/resources/pvc_finalizers.go @@ -30,7 +30,7 @@ import ( "github.com/rs/zerolog" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util" @@ -106,7 +106,7 @@ func (r *Resources) inspectFinalizerPVCMemberExists(ctx context.Context, log zer if memberStatus.PodName != "" { log.Info().Msg("Removing Pod of member, because PVC is being removed") err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return r.context.PodsModInterface().Delete(ctxChild, memberStatus.PodName, metav1.DeleteOptions{}) + return r.context.PodsModInterface().Delete(ctxChild, memberStatus.PodName, meta.DeleteOptions{}) }) if err != nil && !k8sutil.IsNotFound(err) { log.Debug().Err(err).Msg("Failed to delete pod") diff --git a/pkg/deployment/resources/servicemonitor.go b/pkg/deployment/resources/servicemonitor.go index 1e56adc2c..572dcf87f 100644 --- a/pkg/deployment/resources/servicemonitor.go +++ b/pkg/deployment/resources/servicemonitor.go @@ -37,7 +37,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/apis/shared" "github.com/arangodb/kube-arangodb/pkg/util/kclient" coreosv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) func LabelsForExporterServiceMonitor(name string, obj deploymentApi.DeploymentSpec) map[string]string { @@ -103,7 +103,7 @@ func (r *Resources) serviceMonitorSpec() (coreosv1.ServiceMonitorSpec, error) { Endpoints: []coreosv1.Endpoint{ endpoint, }, - Selector: metav1.LabelSelector{ + Selector: meta.LabelSelector{ MatchLabels: LabelsForExporterServiceMonitorSelector(r.context.GetName()), }, }, nil @@ -113,7 +113,7 @@ func (r *Resources) serviceMonitorSpec() (coreosv1.ServiceMonitorSpec, error) { Endpoints: []coreosv1.Endpoint{ r.makeEndpoint(spec.IsSecure()), }, - Selector: metav1.LabelSelector{ + Selector: meta.LabelSelector{ MatchLabels: LabelsForExporterServiceMonitorSelector(deploymentName), }, }, nil @@ -149,7 +149,7 @@ func (r *Resources) EnsureServiceMonitor(ctx context.Context) error { serviceMonitors := mClient.MonitoringV1().ServiceMonitors(ns) ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) defer cancel() - servMon, err := serviceMonitors.Get(ctxChild, serviceMonitorName, metav1.GetOptions{}) + servMon, err := serviceMonitors.Get(ctxChild, serviceMonitorName, meta.GetOptions{}) if err != nil { if k8sutil.IsNotFound(err) { if !wantMetrics { @@ -163,16 +163,16 @@ func (r *Resources) EnsureServiceMonitor(ctx context.Context) error { // Need to create one: smon := &coreosv1.ServiceMonitor{ - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: meta.ObjectMeta{ Name: serviceMonitorName, Labels: LabelsForExporterServiceMonitor(r.context.GetName(), r.context.GetSpec()), - OwnerReferences: []metav1.OwnerReference{owner}, + OwnerReferences: []meta.OwnerReference{owner}, }, Spec: spec, } err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := serviceMonitors.Create(ctxChild, smon, metav1.CreateOptions{}) + _, err := serviceMonitors.Create(ctxChild, smon, meta.CreateOptions{}) return err }) if err != nil { @@ -217,7 +217,7 @@ func (r *Resources) EnsureServiceMonitor(ctx context.Context) error { servMon.Spec = spec err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - _, err := serviceMonitors.Update(ctxChild, servMon, metav1.UpdateOptions{}) + _, err := serviceMonitors.Update(ctxChild, servMon, meta.UpdateOptions{}) return err }) if err != nil { @@ -228,7 +228,7 @@ func (r *Resources) EnsureServiceMonitor(ctx context.Context) error { } // Need to get rid of the ServiceMonitor: err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error { - return serviceMonitors.Delete(ctxChild, serviceMonitorName, metav1.DeleteOptions{}) + return serviceMonitors.Delete(ctxChild, serviceMonitorName, meta.DeleteOptions{}) }) if err == nil { log.Debug().Msgf("Deleted ServiceMonitor %s", serviceMonitorName) diff --git a/pkg/util/k8sutil/inspector/anonymous/anonymous.go b/pkg/util/k8sutil/inspector/anonymous/anonymous.go new file mode 100644 index 000000000..0db404a2b --- /dev/null +++ b/pkg/util/k8sutil/inspector/anonymous/anonymous.go @@ -0,0 +1,36 @@ +// // +// // DISCLAIMER +// // +// // Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// // +// // Licensed under the Apache License, Version 2.0 (the "License"); +// // you may not use this file except in compliance with the License. +// // You may obtain a copy of the License at +// // +// // http://www.apache.org/licenses/LICENSE-2.0 +// // +// // Unless required by applicable law or agreed to in writing, software +// // distributed under the License is distributed on an "AS IS" BASIS, +// // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// // See the License for the specific language governing permissions and +// // limitations under the License. +// // +// // Copyright holder is ArangoDB GmbH, Cologne, Germany +// // + +package anonymous + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +type Impl interface { + Anonymous(gvk schema.GroupVersionKind) (Interface, bool) +} + +type Interface interface { + Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) +} diff --git a/pkg/util/k8sutil/inspector/arangoclustersynchronization/definition.go b/pkg/util/k8sutil/inspector/arangoclustersynchronization/definition.go index 19ad12779..a04333759 100644 --- a/pkg/util/k8sutil/inspector/arangoclustersynchronization/definition.go +++ b/pkg/util/k8sutil/inspector/arangoclustersynchronization/definition.go @@ -21,7 +21,9 @@ package arangoclustersynchronization import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" ) @@ -32,5 +34,8 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() (v1.Inspector, error) } diff --git a/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1/loader.go b/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1/loader.go index ac9d081be..5432e5f1f 100644 --- a/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1/loader.go +++ b/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1/loader.go @@ -22,9 +22,12 @@ package v1 import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" ) type Inspector interface { + gvk.GVK + ListSimple() []*api.ArangoClusterSynchronization GetSimple(name string) (*api.ArangoClusterSynchronization, bool) Filter(filters ...Filter) []*api.ArangoClusterSynchronization diff --git a/pkg/util/k8sutil/inspector/arangomember/definition.go b/pkg/util/k8sutil/inspector/arangomember/definition.go index 1db66b43c..162cd0447 100644 --- a/pkg/util/k8sutil/inspector/arangomember/definition.go +++ b/pkg/util/k8sutil/inspector/arangomember/definition.go @@ -21,7 +21,9 @@ package arangomember import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" ) @@ -32,5 +34,8 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() v1.Inspector } diff --git a/pkg/util/k8sutil/inspector/arangomember/v1/loader.go b/pkg/util/k8sutil/inspector/arangomember/v1/loader.go index 7e53568ba..338ebbc72 100644 --- a/pkg/util/k8sutil/inspector/arangomember/v1/loader.go +++ b/pkg/util/k8sutil/inspector/arangomember/v1/loader.go @@ -22,9 +22,12 @@ package v1 import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" ) type Inspector interface { + gvk.GVK + GetSimple(name string) (*api.ArangoMember, bool) Iterate(action Action, filters ...Filter) error Read() ReadInterface diff --git a/pkg/util/k8sutil/inspector/arangotask/definition.go b/pkg/util/k8sutil/inspector/arangotask/definition.go index 8aae54224..2312621f1 100644 --- a/pkg/util/k8sutil/inspector/arangotask/definition.go +++ b/pkg/util/k8sutil/inspector/arangotask/definition.go @@ -21,7 +21,9 @@ package arangotask import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" ) @@ -32,5 +34,8 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() (v1.Inspector, error) } diff --git a/pkg/util/k8sutil/inspector/arangotask/v1/loader.go b/pkg/util/k8sutil/inspector/arangotask/v1/loader.go index c94534530..05f83ddf3 100644 --- a/pkg/util/k8sutil/inspector/arangotask/v1/loader.go +++ b/pkg/util/k8sutil/inspector/arangotask/v1/loader.go @@ -22,9 +22,12 @@ package v1 import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" ) type Inspector interface { + gvk.GVK + ListSimple() []*api.ArangoTask GetSimple(name string) (*api.ArangoTask, bool) Filter(filters ...Filter) []*api.ArangoTask diff --git a/pkg/util/k8sutil/inspector/endpoints/definition.go b/pkg/util/k8sutil/inspector/endpoints/definition.go index 713bab570..6580d32ad 100644 --- a/pkg/util/k8sutil/inspector/endpoints/definition.go +++ b/pkg/util/k8sutil/inspector/endpoints/definition.go @@ -21,7 +21,9 @@ package endpoints import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" ) @@ -32,5 +34,8 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() (v1.Inspector, error) } diff --git a/pkg/util/k8sutil/inspector/endpoints/v1/loader.go b/pkg/util/k8sutil/inspector/endpoints/v1/loader.go index f0144312a..17bba65b1 100644 --- a/pkg/util/k8sutil/inspector/endpoints/v1/loader.go +++ b/pkg/util/k8sutil/inspector/endpoints/v1/loader.go @@ -20,9 +20,14 @@ package v1 -import core "k8s.io/api/core/v1" +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + core "k8s.io/api/core/v1" +) type Inspector interface { + gvk.GVK + ListSimple() []*core.Endpoints GetSimple(name string) (*core.Endpoints, bool) Filter(filters ...Filter) []*core.Endpoints diff --git a/pkg/util/k8sutil/inspector/gvk/gvk.go b/pkg/util/k8sutil/inspector/gvk/gvk.go new file mode 100644 index 000000000..f6788b9cc --- /dev/null +++ b/pkg/util/k8sutil/inspector/gvk/gvk.go @@ -0,0 +1,35 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package gvk + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" +) + +type GK interface { + GroupKind() schema.GroupKind + GroupResource() schema.GroupResource +} + +type GVK interface { + GroupVersionKind() schema.GroupVersionKind + GroupVersionResource() schema.GroupVersionResource +} diff --git a/pkg/util/k8sutil/inspector/inspector.go b/pkg/util/k8sutil/inspector/inspector.go index ea464cd08..2356ef656 100644 --- a/pkg/util/k8sutil/inspector/inspector.go +++ b/pkg/util/k8sutil/inspector/inspector.go @@ -25,6 +25,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/server" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangodeployment" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember" @@ -47,6 +48,10 @@ type Inspector interface { Initialised() bool + anonymous.Impl + + AnonymousObjects() []anonymous.Impl + refresh.Inspector throttle.Inspector diff --git a/pkg/util/k8sutil/inspector/node/definition.go b/pkg/util/k8sutil/inspector/node/definition.go index eead59e0c..e198f876e 100644 --- a/pkg/util/k8sutil/inspector/node/definition.go +++ b/pkg/util/k8sutil/inspector/node/definition.go @@ -21,6 +21,8 @@ package node import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/node/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" ) @@ -32,5 +34,8 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() (v1.Inspector, error) } diff --git a/pkg/util/k8sutil/inspector/node/v1/loader.go b/pkg/util/k8sutil/inspector/node/v1/loader.go index cc613a4e4..87ca7779a 100644 --- a/pkg/util/k8sutil/inspector/node/v1/loader.go +++ b/pkg/util/k8sutil/inspector/node/v1/loader.go @@ -21,10 +21,13 @@ package v1 import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" core "k8s.io/api/core/v1" ) type Inspector interface { + gvk.GVK + ListSimple() []*core.Node GetSimple(name string) (*core.Node, bool) Iterate(action Action, filters ...Filter) error diff --git a/pkg/util/k8sutil/inspector/persistentvolumeclaim/definition.go b/pkg/util/k8sutil/inspector/persistentvolumeclaim/definition.go index 223910856..bcecab5ae 100644 --- a/pkg/util/k8sutil/inspector/persistentvolumeclaim/definition.go +++ b/pkg/util/k8sutil/inspector/persistentvolumeclaim/definition.go @@ -21,6 +21,8 @@ package persistentvolumeclaim import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" ) @@ -32,5 +34,8 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() v1.Inspector } diff --git a/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/loader.go b/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/loader.go index 6738b3148..911a13f53 100644 --- a/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/loader.go +++ b/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1/loader.go @@ -21,10 +21,13 @@ package v1 import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" core "k8s.io/api/core/v1" ) type Inspector interface { + gvk.GVK + ListSimple() []*core.PersistentVolumeClaim GetSimple(name string) (*core.PersistentVolumeClaim, bool) Iterate(action Action, filters ...Filter) error diff --git a/pkg/util/k8sutil/inspector/pod/definition.go b/pkg/util/k8sutil/inspector/pod/definition.go index 7b4df666a..1c434134b 100644 --- a/pkg/util/k8sutil/inspector/pod/definition.go +++ b/pkg/util/k8sutil/inspector/pod/definition.go @@ -21,6 +21,8 @@ package pod import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" ) @@ -32,5 +34,8 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() v1.Inspector } diff --git a/pkg/util/k8sutil/inspector/pod/v1/loader.go b/pkg/util/k8sutil/inspector/pod/v1/loader.go index 76b77aaba..3606ef7a2 100644 --- a/pkg/util/k8sutil/inspector/pod/v1/loader.go +++ b/pkg/util/k8sutil/inspector/pod/v1/loader.go @@ -21,10 +21,13 @@ package v1 import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" core "k8s.io/api/core/v1" ) type Inspector interface { + gvk.GVK + ListSimple() []*core.Pod GetSimple(name string) (*core.Pod, bool) Iterate(action Action, filters ...Filter) error diff --git a/pkg/util/k8sutil/inspector/poddisruptionbudget/definition.go b/pkg/util/k8sutil/inspector/poddisruptionbudget/definition.go index c34d00524..f3ba617c4 100644 --- a/pkg/util/k8sutil/inspector/poddisruptionbudget/definition.go +++ b/pkg/util/k8sutil/inspector/poddisruptionbudget/definition.go @@ -21,6 +21,8 @@ package poddisruptionbudget import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget/v1beta1" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" @@ -33,6 +35,9 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() (v1.Inspector, error) V1Beta1() (v1beta1.Inspector, error) } diff --git a/pkg/util/k8sutil/inspector/poddisruptionbudget/v1/loader.go b/pkg/util/k8sutil/inspector/poddisruptionbudget/v1/loader.go index a882fe4f4..9e08f12d6 100644 --- a/pkg/util/k8sutil/inspector/poddisruptionbudget/v1/loader.go +++ b/pkg/util/k8sutil/inspector/poddisruptionbudget/v1/loader.go @@ -20,9 +20,14 @@ package v1beta1 -import policy "k8s.io/api/policy/v1" +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + policy "k8s.io/api/policy/v1" +) type Inspector interface { + gvk.GVK + GetSimple(name string) (*policy.PodDisruptionBudget, bool) Iterate(action Action, filters ...Filter) error Read() ReadInterface diff --git a/pkg/util/k8sutil/inspector/poddisruptionbudget/v1beta1/loader.go b/pkg/util/k8sutil/inspector/poddisruptionbudget/v1beta1/loader.go index 4a683fc68..2126a548c 100644 --- a/pkg/util/k8sutil/inspector/poddisruptionbudget/v1beta1/loader.go +++ b/pkg/util/k8sutil/inspector/poddisruptionbudget/v1beta1/loader.go @@ -20,9 +20,14 @@ package v1beta1 -import policy "k8s.io/api/policy/v1beta1" +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + policy "k8s.io/api/policy/v1beta1" +) type Inspector interface { + gvk.GVK + GetSimple(name string) (*policy.PodDisruptionBudget, bool) Iterate(action Action, filters ...Filter) error Read() ReadInterface diff --git a/pkg/util/k8sutil/inspector/secret/definition.go b/pkg/util/k8sutil/inspector/secret/definition.go index 7a7d08aa1..79e32ac8e 100644 --- a/pkg/util/k8sutil/inspector/secret/definition.go +++ b/pkg/util/k8sutil/inspector/secret/definition.go @@ -21,6 +21,8 @@ package secret import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1" ) @@ -32,5 +34,8 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() v1.Inspector } diff --git a/pkg/util/k8sutil/inspector/secret/v1/loader.go b/pkg/util/k8sutil/inspector/secret/v1/loader.go index 7ad0337b6..3356d1b8d 100644 --- a/pkg/util/k8sutil/inspector/secret/v1/loader.go +++ b/pkg/util/k8sutil/inspector/secret/v1/loader.go @@ -21,11 +21,14 @@ package v1 import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" core "k8s.io/api/core/v1" ) // Inspector for secrets type Inspector interface { + gvk.GVK + ListSimple() []*core.Secret GetSimple(name string) (*core.Secret, bool) Iterate(action Action, filters ...Filter) error diff --git a/pkg/util/k8sutil/inspector/service/definition.go b/pkg/util/k8sutil/inspector/service/definition.go index 2cfd2c0b3..cba9469c6 100644 --- a/pkg/util/k8sutil/inspector/service/definition.go +++ b/pkg/util/k8sutil/inspector/service/definition.go @@ -21,6 +21,8 @@ package service import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" ) @@ -32,5 +34,8 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() v1.Inspector } diff --git a/pkg/util/k8sutil/inspector/service/v1/loader.go b/pkg/util/k8sutil/inspector/service/v1/loader.go index 72015a1f2..f86a70475 100644 --- a/pkg/util/k8sutil/inspector/service/v1/loader.go +++ b/pkg/util/k8sutil/inspector/service/v1/loader.go @@ -21,10 +21,13 @@ package v1 import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" core "k8s.io/api/core/v1" ) type Inspector interface { + gvk.GVK + GetSimple(name string) (*core.Service, bool) Iterate(action Action, filters ...Filter) error Read() ReadInterface diff --git a/pkg/util/k8sutil/inspector/serviceaccount/definition.go b/pkg/util/k8sutil/inspector/serviceaccount/definition.go index d6202b422..6f79c8217 100644 --- a/pkg/util/k8sutil/inspector/serviceaccount/definition.go +++ b/pkg/util/k8sutil/inspector/serviceaccount/definition.go @@ -21,6 +21,8 @@ package serviceaccount import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount/v1" ) @@ -32,5 +34,8 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() v1.Inspector } diff --git a/pkg/util/k8sutil/inspector/serviceaccount/v1/loader.go b/pkg/util/k8sutil/inspector/serviceaccount/v1/loader.go index 62a5121ba..f79ba0a65 100644 --- a/pkg/util/k8sutil/inspector/serviceaccount/v1/loader.go +++ b/pkg/util/k8sutil/inspector/serviceaccount/v1/loader.go @@ -20,9 +20,14 @@ package v1 -import core "k8s.io/api/core/v1" +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + core "k8s.io/api/core/v1" +) type Inspector interface { + gvk.GVK + GetSimple(name string) (*core.ServiceAccount, bool) Iterate(action Action, filters ...Filter) error Read() ReadInterface diff --git a/pkg/util/k8sutil/inspector/serviceaccount/v1/reader.go b/pkg/util/k8sutil/inspector/serviceaccount/v1/reader.go index 0e2192c4f..94e2ce32e 100644 --- a/pkg/util/k8sutil/inspector/serviceaccount/v1/reader.go +++ b/pkg/util/k8sutil/inspector/serviceaccount/v1/reader.go @@ -23,6 +23,7 @@ package v1 import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -38,6 +39,8 @@ type ModInterface interface { // Interface has methods to work with ServiceAccount resources. type Interface interface { + anonymous.Impl + ModInterface ReadInterface } diff --git a/pkg/util/k8sutil/inspector/servicemonitor/definition.go b/pkg/util/k8sutil/inspector/servicemonitor/definition.go index c13bd54fd..3e09acc0a 100644 --- a/pkg/util/k8sutil/inspector/servicemonitor/definition.go +++ b/pkg/util/k8sutil/inspector/servicemonitor/definition.go @@ -21,6 +21,8 @@ package servicemonitor import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh" v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor/v1" ) @@ -32,5 +34,8 @@ type Inspector interface { type Definition interface { refresh.Inspector + gvk.GK + anonymous.Impl + V1() (v1.Inspector, error) } diff --git a/pkg/util/k8sutil/inspector/servicemonitor/v1/loader.go b/pkg/util/k8sutil/inspector/servicemonitor/v1/loader.go index b5a73d5ae..b826f97b1 100644 --- a/pkg/util/k8sutil/inspector/servicemonitor/v1/loader.go +++ b/pkg/util/k8sutil/inspector/servicemonitor/v1/loader.go @@ -20,9 +20,14 @@ package v1 -import monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" +import ( + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk" + monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" +) type Inspector interface { + gvk.GVK + GetSimple(name string) (*monitoring.ServiceMonitor, bool) Iterate(action Action, filters ...Filter) error Read() ReadInterface diff --git a/pkg/util/k8sutil/inspector/servicemonitor/v1/reader.go b/pkg/util/k8sutil/inspector/servicemonitor/v1/reader.go index 6eb6ff10e..394f6664a 100644 --- a/pkg/util/k8sutil/inspector/servicemonitor/v1/reader.go +++ b/pkg/util/k8sutil/inspector/servicemonitor/v1/reader.go @@ -23,6 +23,7 @@ package v1 import ( "context" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous" monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -38,6 +39,8 @@ type ModInterface interface { // Interface has methods to work with ServiceMonitor resources. type Interface interface { + anonymous.Impl + ModInterface ReadInterface }