Skip to content

Commit df37ed1

Browse files
authored
[Refactor] Anonymous Inspector functions (#973)
1 parent 45fefba commit df37ed1

File tree

95 files changed

+2246
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+2246
-164
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Feature) Add CoreV1 Endpoints Inspector
55
- (Feature) Add Current ArangoDeployment Inspector
6+
- (Refactor) Anonymous inspector functions
67

78
## [1.2.11](https://github.com/arangodb/kube-arangodb/tree/1.2.11) (2022-04-30)
89
- (Bugfix) Orphan PVC are not removed

pkg/deployment/resources/certificates_client_auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"time"
2727

2828
"github.com/rs/zerolog"
29-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3030

3131
certificates "github.com/arangodb-helper/go-certificates"
3232
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
@@ -41,7 +41,7 @@ const (
4141

4242
// createClientAuthCACertificate creates a client authentication CA certificate and stores it in a secret with name
4343
// specified in the given spec.
44-
func createClientAuthCACertificate(ctx context.Context, log zerolog.Logger, secrets secretv1.ModInterface, spec api.SyncAuthenticationSpec, deploymentName string, ownerRef *metav1.OwnerReference) error {
44+
func createClientAuthCACertificate(ctx context.Context, log zerolog.Logger, secrets secretv1.ModInterface, spec api.SyncAuthenticationSpec, deploymentName string, ownerRef *meta.OwnerReference) error {
4545
log = log.With().Str("secret", spec.GetClientCASecretName()).Logger()
4646
options := certificates.CreateCertificateOptions{
4747
CommonName: fmt.Sprintf("%s Client Authentication Root Certificate", deploymentName),

pkg/deployment/resources/certificates_tls.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3939
secretv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret/v1"
4040
"github.com/rs/zerolog"
41-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
41+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
4242
)
4343

4444
const (
@@ -49,7 +49,7 @@ const (
4949
// createTLSCACertificate creates a CA certificate and stores it in a secret with name
5050
// specified in the given spec.
5151
func createTLSCACertificate(ctx context.Context, log zerolog.Logger, secrets secretv1.ModInterface, spec api.TLSSpec,
52-
deploymentName string, ownerRef *metav1.OwnerReference) error {
52+
deploymentName string, ownerRef *meta.OwnerReference) error {
5353
log = log.With().Str("secret", spec.GetCASecretName()).Logger()
5454

5555
options := certificates.CreateCertificateOptions{
@@ -79,7 +79,7 @@ func createTLSCACertificate(ctx context.Context, log zerolog.Logger, secrets sec
7979
// createTLSServerCertificate creates a TLS certificate for a specific server and stores
8080
// it in a secret with the given name.
8181
func createTLSServerCertificate(ctx context.Context, log zerolog.Logger, cachedStatus inspectorInterface.Inspector, secrets secretv1.ModInterface, names tls.KeyfileInput, spec api.TLSSpec,
82-
secretName string, ownerRef *metav1.OwnerReference) (bool, error) {
82+
secretName string, ownerRef *meta.OwnerReference) (bool, error) {
8383
log = log.With().Str("secret", secretName).Logger()
8484
// Load CA certificate
8585
ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package inspector
22+
23+
import (
24+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous"
25+
"k8s.io/apimachinery/pkg/runtime/schema"
26+
)
27+
28+
func (p *arangoClusterSynchronizationsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) {
29+
g := ArangoClusterSynchronizationGK()
30+
31+
if g.Kind == gvk.Kind && g.Group == gvk.Group {
32+
switch gvk.Version {
33+
case ArangoClusterSynchronizationVersionV1:
34+
return &arangoClusterSynchronizationsInspectorAnonymousV1{i: p.v1}, true
35+
}
36+
}
37+
38+
return nil, false
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package inspector
22+
23+
import (
24+
"context"
25+
26+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
)
28+
29+
type arangoClusterSynchronizationsInspectorAnonymousV1 struct {
30+
i *arangoClusterSynchronizationsInspectorV1
31+
}
32+
33+
func (e *arangoClusterSynchronizationsInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) {
34+
return e.i.Get(ctx, name, opts)
35+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package inspector
22+
23+
import (
24+
"github.com/arangodb/kube-arangodb/pkg/apis/deployment"
25+
deploymentv1 "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
26+
"k8s.io/apimachinery/pkg/runtime/schema"
27+
)
28+
29+
// ArangoClusterSynchronization
30+
const (
31+
ArangoClusterSynchronizationGroup = deployment.ArangoDeploymentGroupName
32+
ArangoClusterSynchronizationResource = deployment.ArangoClusterSynchronizationResourcePlural
33+
ArangoClusterSynchronizationKind = deployment.ArangoClusterSynchronizationResourceKind
34+
ArangoClusterSynchronizationVersionV1 = deploymentv1.ArangoDeploymentVersion
35+
)
36+
37+
func ArangoClusterSynchronizationGK() schema.GroupKind {
38+
return schema.GroupKind{
39+
Group: ArangoClusterSynchronizationGroup,
40+
Kind: ArangoClusterSynchronizationKind,
41+
}
42+
}
43+
44+
func ArangoClusterSynchronizationGKv1() schema.GroupVersionKind {
45+
return schema.GroupVersionKind{
46+
Group: ArangoClusterSynchronizationGroup,
47+
Kind: ArangoClusterSynchronizationKind,
48+
Version: ArangoClusterSynchronizationVersionV1,
49+
}
50+
}
51+
52+
func ArangoClusterSynchronizationGR() schema.GroupResource {
53+
return schema.GroupResource{
54+
Group: ArangoClusterSynchronizationGroup,
55+
Resource: ArangoClusterSynchronizationResource,
56+
}
57+
}
58+
59+
func ArangoClusterSynchronizationGRv1() schema.GroupVersionResource {
60+
return schema.GroupVersionResource{
61+
Group: ArangoClusterSynchronizationGroup,
62+
Resource: ArangoClusterSynchronizationResource,
63+
Version: ArangoClusterSynchronizationVersionV1,
64+
}
65+
}
66+
67+
func (p *arangoClusterSynchronizationsInspectorV1) GroupVersionKind() schema.GroupVersionKind {
68+
return ArangoClusterSynchronizationGKv1()
69+
}
70+
71+
func (p *arangoClusterSynchronizationsInspectorV1) GroupVersionResource() schema.GroupVersionResource {
72+
return ArangoClusterSynchronizationGRv1()
73+
}
74+
75+
func (p *arangoClusterSynchronizationsInspector) GroupKind() schema.GroupKind {
76+
return ArangoClusterSynchronizationGK()
77+
}
78+
79+
func (p *arangoClusterSynchronizationsInspector) GroupResource() schema.GroupResource {
80+
return ArangoClusterSynchronizationGR()
81+
}

pkg/deployment/resources/inspector/acs_v1.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ package inspector
2323
import (
2424
"context"
2525

26-
"github.com/arangodb/kube-arangodb/pkg/apis/deployment"
2726
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
2827
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2928
ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization/v1"
3029
apiErrors "k8s.io/apimachinery/pkg/api/errors"
31-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32-
"k8s.io/apimachinery/pkg/runtime/schema"
30+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3331
)
3432

3533
func (p *arangoClusterSynchronizationsInspector) V1() (ins.Inspector, error) {
@@ -129,12 +127,9 @@ func (p *arangoClusterSynchronizationsInspectorV1) Read() ins.ReadInterface {
129127
return p
130128
}
131129

132-
func (p *arangoClusterSynchronizationsInspectorV1) Get(ctx context.Context, name string, opts metav1.GetOptions) (*api.ArangoClusterSynchronization, error) {
130+
func (p *arangoClusterSynchronizationsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*api.ArangoClusterSynchronization, error) {
133131
if s, ok := p.GetSimple(name); !ok {
134-
return nil, apiErrors.NewNotFound(schema.GroupResource{
135-
Group: deployment.ArangoDeploymentGroupName,
136-
Resource: deployment.ArangoClusterSynchronizationResourcePlural,
137-
}, name)
132+
return nil, apiErrors.NewNotFound(ArangoClusterSynchronizationGR(), name)
138133
} else {
139134
return s, nil
140135
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package inspector
22+
23+
import (
24+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous"
25+
"k8s.io/apimachinery/pkg/runtime/schema"
26+
)
27+
28+
func (p *arangoMembersInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) {
29+
g := ArangoMemberGK()
30+
31+
if g.Kind == gvk.Kind && g.Group == gvk.Group {
32+
switch gvk.Version {
33+
case ArangoMemberVersionV1:
34+
return &arangoMembersInspectorAnonymousV1{i: p.v1}, true
35+
}
36+
}
37+
38+
return nil, false
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package inspector
22+
23+
import (
24+
"context"
25+
26+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
)
28+
29+
type arangoMembersInspectorAnonymousV1 struct {
30+
i *arangoMembersInspectorV1
31+
}
32+
33+
func (e *arangoMembersInspectorAnonymousV1) Get(ctx context.Context, name string, opts meta.GetOptions) (meta.Object, error) {
34+
return e.i.Get(ctx, name, opts)
35+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package inspector
22+
23+
import (
24+
"github.com/arangodb/kube-arangodb/pkg/apis/deployment"
25+
deploymentv1 "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
26+
"k8s.io/apimachinery/pkg/runtime/schema"
27+
)
28+
29+
// ArangoMember
30+
const (
31+
ArangoMemberGroup = deployment.ArangoDeploymentGroupName
32+
ArangoMemberResource = deployment.ArangoMemberResourcePlural
33+
ArangoMemberKind = deployment.ArangoMemberResourceKind
34+
ArangoMemberVersionV1 = deploymentv1.ArangoDeploymentVersion
35+
)
36+
37+
func ArangoMemberGK() schema.GroupKind {
38+
return schema.GroupKind{
39+
Group: ArangoMemberGroup,
40+
Kind: ArangoMemberKind,
41+
}
42+
}
43+
44+
func ArangoMemberGKv1() schema.GroupVersionKind {
45+
return schema.GroupVersionKind{
46+
Group: ArangoMemberGroup,
47+
Kind: ArangoMemberKind,
48+
Version: ArangoMemberVersionV1,
49+
}
50+
}
51+
52+
func ArangoMemberGR() schema.GroupResource {
53+
return schema.GroupResource{
54+
Group: ArangoMemberGroup,
55+
Resource: ArangoMemberResource,
56+
}
57+
}
58+
59+
func ArangoMemberGRv1() schema.GroupVersionResource {
60+
return schema.GroupVersionResource{
61+
Group: ArangoMemberGroup,
62+
Resource: ArangoMemberResource,
63+
Version: ArangoMemberVersionV1,
64+
}
65+
}
66+
67+
func (p *arangoMembersInspectorV1) GroupVersionKind() schema.GroupVersionKind {
68+
return ArangoMemberGKv1()
69+
}
70+
71+
func (p *arangoMembersInspectorV1) GroupVersionResource() schema.GroupVersionResource {
72+
return ArangoMemberGRv1()
73+
}
74+
75+
func (p *arangoMembersInspector) GroupKind() schema.GroupKind {
76+
return ArangoMemberGK()
77+
}
78+
79+
func (p *arangoMembersInspector) GroupResource() schema.GroupResource {
80+
return ArangoMemberGR()
81+
}

0 commit comments

Comments
 (0)