Skip to content

Commit f7e6318

Browse files
committed
refactor: reduce dependency between internal and api
see https://gravitee.atlassian.net/browse/GKO-290
1 parent 4b62950 commit f7e6318

36 files changed

+408
-297
lines changed

api/model/api/base/status.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (C) 2015 The Gravitee team (http://gravitee.io)
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package base
16+
17+
import "github.com/gravitee-io/gravitee-kubernetes-operator/pkg/types/k8s/custom"
18+
19+
type Status struct {
20+
// The organization ID, if a management context has been defined to sync with an APIM instance
21+
OrgID string `json:"organizationId,omitempty"`
22+
// The environment ID, if a management context has been defined to sync with an APIM instance
23+
EnvID string `json:"environmentId,omitempty"`
24+
// The ID of the API definition in the Gravitee API Management instance (if an API context has been configured).
25+
ID string `json:"id,omitempty"`
26+
// The Cross ID is used to identify an API that has been promoted from one environment to another.
27+
CrossID string `json:"crossId,omitempty"`
28+
// The processing status of the API definition.
29+
ProcessingStatus custom.ProcessingStatus `json:"processingStatus,omitempty"`
30+
// The state of the API. Can be either STARTED or STOPPED.
31+
State ApiState `json:"state,omitempty"`
32+
// This is the object generation observed during the latest reconcile.
33+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
34+
}

api/model/api/base/zz_generated.deepcopy.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/model/api/v4/status.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2015 The Gravitee team (http://gravitee.io)
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v4
16+
17+
import "github.com/gravitee-io/gravitee-kubernetes-operator/api/model/api/base"
18+
19+
type Status struct {
20+
base.Status `json:",inline"`
21+
// This field is used to store the list of plans that have been created
22+
// for the API definition if a management context has been defined
23+
// to sync the API with an APIM instance
24+
Plans map[string]string `json:"plans,omitempty"`
25+
}

api/model/api/v4/zz_generated.deepcopy.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/model/application/status.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (C) 2015 The Gravitee team (http://gravitee.io)
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package application
16+
17+
import "github.com/gravitee-io/gravitee-kubernetes-operator/pkg/types/k8s/custom"
18+
19+
type Status struct {
20+
// The organization ID, if a management context has been defined to sync with an APIM instance
21+
OrgID string `json:"organizationId,omitempty"`
22+
// The environment ID, if a management context has been defined to sync with an APIM instance
23+
EnvID string `json:"environmentId,omitempty"`
24+
// The ID of the Application, if a management context has been defined to sync with an APIM instance
25+
ID string `json:"id,omitempty"`
26+
// The processing status of the Application.
27+
// The value is `Completed` if the sync with APIM succeeded, Failed otherwise.
28+
ProcessingStatus custom.ProcessingStatus `json:"processingStatus,omitempty"`
29+
// This is the object generation observed during the latest reconcile.
30+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
31+
}

api/model/application/zz_generated.deepcopy.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/model/refs/namespace.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,46 +20,31 @@ import (
2020
"k8s.io/apimachinery/pkg/types"
2121
)
2222

23-
var _ custom.ResourceRef = &NamespacedName{}
23+
var _ custom.ResourceRef = NamespacedName{}
2424

2525
type NamespacedName struct {
2626
Name string `json:"name"`
2727
Namespace string `json:"namespace,omitempty"`
2828
}
2929

30-
// SetNamespace implements custom.ResourceRef.
31-
func (n *NamespacedName) SetNamespace(ns string) {
32-
n.Namespace = ns
33-
}
34-
35-
// IsMissingNamespace implements custom.ResourceRef.
36-
func (n *NamespacedName) IsMissingNamespace() bool {
37-
return !n.HasNameSpace()
38-
}
39-
4030
// GetName implements custom.ResourceRef.
41-
func (n *NamespacedName) GetName() string {
31+
func (n NamespacedName) GetName() string {
4232
return n.Name
4333
}
4434

4535
// GetNamespace implements custom.ResourceRef.
46-
func (n *NamespacedName) GetNamespace() string {
36+
func (n NamespacedName) GetNamespace() string {
4737
return n.Namespace
4838
}
4939

50-
// HasNameSpace implements custom.ResourceRef.
51-
func (n *NamespacedName) HasNameSpace() bool {
52-
return n.Namespace != ""
53-
}
54-
5540
func NewNamespacedName(namespace, name string) NamespacedName {
5641
return NamespacedName{Namespace: namespace, Name: name}
5742
}
5843

59-
func (n *NamespacedName) NamespacedName() types.NamespacedName {
44+
func (n NamespacedName) NamespacedName() types.NamespacedName {
6045
return types.NamespacedName{Namespace: n.Namespace, Name: n.Name}
6146
}
6247

63-
func (n *NamespacedName) String() string {
48+
func (n NamespacedName) String() string {
6449
return n.Namespace + "/" + n.Name
6550
}

api/v1alpha1/apiv2definition_types.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,7 @@ type ApiDefinitionV2Spec struct {
5858

5959
// ApiDefinitionStatus defines the observed state of API Definition.
6060
type ApiDefinitionStatus struct {
61-
OrgID string `json:"organizationId,omitempty"`
62-
EnvID string `json:"environmentId,omitempty"`
63-
// The ID of the API definition in the Gravitee API Management instance (if an API context has been configured).
64-
ID string `json:"id,omitempty"`
65-
CrossID string `json:"crossId,omitempty"`
66-
// The processing status of the API definition.
67-
Status custom.ProcessingStatus `json:"processingStatus,omitempty"`
68-
// This field is kept for backward compatibility and shall be removed in future versions.
69-
// Use processingStatus instead.
70-
DeprecatedStatus custom.ProcessingStatus `json:"status,omitempty"`
71-
72-
// The state of the API. Can be either STARTED or STOPPED.
73-
State base.ApiState `json:"state,omitempty"`
74-
75-
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
76-
// This field is kept for backward compatibility and shall be removed in future versions.
77-
// Use observedGeneration instead.
78-
DeprecatedObservedGeneration int64 `json:"generation,omitempty"`
61+
base.Status `json:",inline"`
7962
}
8063

8164
var _ list.Item = &ApiDefinition{}
@@ -189,7 +172,7 @@ func (spec *ApiDefinitionV2Spec) Hash() string {
189172
}
190173

191174
func (s *ApiDefinitionStatus) SetProcessingStatus(status custom.ProcessingStatus) {
192-
s.Status = status
175+
s.ProcessingStatus = status
193176
}
194177

195178
func (s *ApiDefinitionStatus) SetObservedGeneration(g int64) {

api/v1alpha1/apiv4definition_types.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,7 @@ type ApiV4DefinitionSpec struct {
4040

4141
// ApiV4DefinitionStatus defines the observed state of API Definition.
4242
type ApiV4DefinitionStatus struct {
43-
// The organisation ID, if a management context has been defined to sync the API with an APIM instance
44-
OrgID string `json:"organizationId,omitempty"`
45-
// The environment ID, if a management context has been defined to sync the API with an APIM instance
46-
EnvID string `json:"environmentId,omitempty"`
47-
// The ID of the API definition if a management context has been defined to sync the API with an APIM instance
48-
ID string `json:"id,omitempty"`
49-
// The Cross ID of the API definition if a management context has been defined to sync the API with an APIM instance
50-
CrossID string `json:"crossId,omitempty"`
51-
52-
// The processing status of the API definition.
53-
Status custom.ProcessingStatus `json:"processingStatus,omitempty"`
54-
55-
// The state of the API. Can be either STARTED or STOPPED.
56-
State string `json:"state,omitempty"`
57-
58-
// This field is used to store the list of plans that have been created
59-
// for the API definition if a management context has been defined
60-
// to sync the API with an APIM instance
61-
Plans map[string]string `json:"plans,omitempty"`
62-
// Last generation of the CRD resource
63-
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
43+
v4.Status `json:",inline"`
6444
}
6545

6646
var _ custom.ApiDefinition = &ApiV4Definition{}
@@ -231,7 +211,7 @@ func (spec *ApiV4DefinitionSpec) GetManagementContext() *refs.NamespacedName {
231211
}
232212

233213
func (s *ApiV4DefinitionStatus) SetProcessingStatus(status custom.ProcessingStatus) {
234-
s.Status = status
214+
s.ProcessingStatus = status
235215
}
236216

237217
func (s *ApiV4DefinitionStatus) SetObservedGeneration(g int64) {

api/v1alpha1/application_types.go

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,11 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20-
"fmt"
21-
2220
"github.com/gravitee-io/gravitee-kubernetes-operator/api/model/application"
2321
"github.com/gravitee-io/gravitee-kubernetes-operator/api/model/refs"
24-
"github.com/gravitee-io/gravitee-kubernetes-operator/internal/hash"
25-
"github.com/gravitee-io/gravitee-kubernetes-operator/pkg/types/k8s/custom"
2622
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27-
"sigs.k8s.io/controller-runtime/pkg/client"
2823
)
2924

30-
var _ custom.ContextAwareResource = &Application{}
31-
var _ custom.Spec = &ApplicationSpec{}
32-
var _ custom.Status = &ApplicationStatus{}
33-
3425
// Application is the main resource handled by the Kubernetes Operator
3526
// +kubebuilder:object:generate=true
3627
type ApplicationSpec struct {
@@ -41,14 +32,7 @@ type ApplicationSpec struct {
4132

4233
// ApplicationStatus defines the observed state of Application.
4334
type ApplicationStatus struct {
44-
OrgID string `json:"organizationId,omitempty"`
45-
EnvID string `json:"environmentId,omitempty"`
46-
// The ID of the Application in the Gravitee API Management instance (if an API context has been configured).
47-
ID string `json:"id,omitempty"`
48-
// The processing status of the Application.
49-
Status custom.ProcessingStatus `json:"processingStatus,omitempty"`
50-
51-
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
35+
application.Status `json:",inline"`
5236
}
5337

5438
// +kubebuilder:object:root=true
@@ -65,16 +49,6 @@ type Application struct {
6549
Status ApplicationStatus `json:"status,omitempty"`
6650
}
6751

68-
// GetSpec implements custom.Resource.
69-
func (app *Application) GetSpec() custom.Spec {
70-
return &app.Spec
71-
}
72-
73-
// GetStatus implements custom.Resource.
74-
func (app *Application) GetStatus() custom.Status {
75-
return &app.Status
76-
}
77-
7852
// +kubebuilder:object:root=true
7953
type ApplicationList struct {
8054
metav1.TypeMeta `json:",inline"`
@@ -89,53 +63,3 @@ func (app *Application) IsBeingDeleted() bool {
8963
func init() {
9064
SchemeBuilder.Register(&Application{}, &ApplicationList{})
9165
}
92-
93-
func (app *Application) ContextRef() custom.ResourceRef {
94-
return app.Spec.Context
95-
}
96-
97-
func (app *Application) HasContext() bool {
98-
return app.Spec.Context != nil
99-
}
100-
101-
func (app *Application) ID() string {
102-
return app.Status.ID
103-
}
104-
105-
func (app *Application) DeepCopyResource() custom.Resource {
106-
return app.DeepCopy()
107-
}
108-
109-
func (spec *ApplicationSpec) Hash() string {
110-
return hash.Calculate(spec)
111-
}
112-
113-
func (s *ApplicationStatus) DeepCopyFrom(obj client.Object) error {
114-
switch t := obj.(type) {
115-
case *Application:
116-
t.Status.DeepCopyInto(s)
117-
default:
118-
return fmt.Errorf("unknown type %T", t)
119-
}
120-
121-
return nil
122-
}
123-
124-
func (s *ApplicationStatus) DeepCopyTo(api client.Object) error {
125-
switch t := api.(type) {
126-
case *Application:
127-
s.DeepCopyInto(&t.Status)
128-
default:
129-
return fmt.Errorf("unknown type %T", t)
130-
}
131-
132-
return nil
133-
}
134-
135-
func (s *ApplicationStatus) SetObservedGeneration(g int64) {
136-
s.ObservedGeneration = g
137-
}
138-
139-
func (s *ApplicationStatus) SetProcessingStatus(status custom.ProcessingStatus) {
140-
s.Status = status
141-
}

0 commit comments

Comments
 (0)