Skip to content

Commit a2045d5

Browse files
refactor(api): embed common status struct
1 parent 5db07cf commit a2045d5

10 files changed

+186
-135
lines changed

api/clusters/v1alpha1/accessrequest_types.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package v1alpha1
33
import (
44
rbacv1 "k8s.io/api/rbac/v1"
55
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
7+
commonapi "github.com/openmcp-project/openmcp-operator/api/common"
68
)
79

810
const (
@@ -46,17 +48,24 @@ type PermissionsRequest struct {
4648

4749
// AccessRequestStatus defines the observed state of AccessRequest
4850
type AccessRequestStatus struct {
49-
CommonStatus `json:",inline"`
50-
51-
// Phase is the current phase of the request.
52-
// +kubebuilder:default=Pending
53-
// +kubebuilder:validation:Enum=Pending;Granted;Denied
54-
Phase RequestPhase `json:"phase"`
51+
commonapi.Status `json:",inline"`
5552

5653
// SecretRef holds the reference to the secret that contains the actual credentials.
5754
SecretRef *NamespacedObjectReference `json:"secretRef,omitempty"`
5855
}
5956

57+
func (ars AccessRequestStatus) IsGranted() bool {
58+
return ars.Phase == REQUEST_GRANTED
59+
}
60+
61+
func (ars AccessRequestStatus) IsDenied() bool {
62+
return ars.Phase == REQUEST_DENIED
63+
}
64+
65+
func (ars AccessRequestStatus) IsPending() bool {
66+
return ars.Phase == "" || ars.Phase == REQUEST_PENDING
67+
}
68+
6069
// +kubebuilder:object:root=true
6170
// +kubebuilder:subresource:status
6271
// +kubebuilder:resource:shortName=ar;areq

api/clusters/v1alpha1/cluster_types.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
88
"k8s.io/apimachinery/pkg/runtime"
99
"k8s.io/apimachinery/pkg/util/sets"
10+
11+
commonapi "github.com/openmcp-project/openmcp-operator/api/common"
1012
)
1113

1214
// ClusterSpec defines the desired state of Cluster
@@ -39,10 +41,7 @@ type K8sConfiguration struct {
3941

4042
// ClusterStatus defines the observed state of Cluster
4143
type ClusterStatus struct {
42-
CommonStatus `json:",inline"`
43-
44-
// Phase is the current phase of the cluster.
45-
Phase ClusterPhase `json:"phase"`
44+
commonapi.Status `json:",inline"`
4645

4746
// APIServer is the API server endpoint of the cluster.
4847
// +optional
@@ -54,21 +53,19 @@ type ClusterStatus struct {
5453
ProviderStatus *runtime.RawExtension `json:"providerStatus,omitempty"`
5554
}
5655

57-
type ClusterPhase string
58-
5956
const (
6057
// CLUSTER_PHASE_UNKNOWN represents an unknown status for the cluster.
61-
CLUSTER_PHASE_UNKNOWN ClusterPhase = "Unknown"
58+
CLUSTER_PHASE_UNKNOWN string = "Unknown"
6259
// CLUSTER_PHASE_READY represents a cluster that is ready.
63-
CLUSTER_PHASE_READY ClusterPhase = "Ready"
60+
CLUSTER_PHASE_READY string = "Ready"
6461
// CLUSTER_PHASE_NOT_READY represents a cluster that is not ready.
65-
CLUSTER_PHASE_NOT_READY ClusterPhase = "Not Ready"
62+
CLUSTER_PHASE_NOT_READY string = "Not Ready"
6663
// CLUSTER_PHASE_ERROR represents a cluster that could not be reconciled successfully.
67-
CLUSTER_PHASE_ERROR ClusterPhase = "Error"
64+
CLUSTER_PHASE_ERROR string = "Error"
6865
// CLUSTER_PHASE_DELETING represents a cluster that is being deleted.
69-
CLUSTER_PHASE_DELETING ClusterPhase = "In Deletion"
66+
CLUSTER_PHASE_DELETING string = "In Deletion"
7067
// CLUSTER_PHASE_DELETING_ERROR represents a cluster that could not be reconciled successfully while being in deletion.
71-
CLUSTER_PHASE_DELETING_ERROR ClusterPhase = "Error In Deletion"
68+
CLUSTER_PHASE_DELETING_ERROR string = "Error In Deletion"
7269
)
7370

7471
// +kubebuilder:object:root=true

api/clusters/v1alpha1/clusterrequest_types.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package v1alpha1
22

33
import (
44
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
6+
commonapi "github.com/openmcp-project/openmcp-operator/api/common"
57
)
68

79
const (
@@ -20,12 +22,7 @@ type ClusterRequestSpec struct {
2022

2123
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.cluster) || has(self.cluster)", message="cluster may not be removed once set"
2224
type ClusterRequestStatus struct {
23-
CommonStatus `json:",inline"`
24-
25-
// Phase is the current phase of the request.
26-
// +kubebuilder:default=Pending
27-
// +kubebuilder:validation:Enum=Pending;Granted;Denied
28-
Phase RequestPhase `json:"phase"`
25+
commonapi.Status `json:",inline"`
2926

3027
// Cluster is the reference to the Cluster that was returned as a result of a granted request.
3128
// Note that this information needs to be recoverable in case this status is lost, e.g. by adding a back reference in form of a finalizer to the Cluster resource.
@@ -34,18 +31,16 @@ type ClusterRequestStatus struct {
3431
Cluster *NamespacedObjectReference `json:"cluster,omitempty"`
3532
}
3633

37-
type RequestPhase string
38-
39-
func (p RequestPhase) IsGranted() bool {
40-
return p == REQUEST_GRANTED
34+
func (crs ClusterRequestStatus) IsGranted() bool {
35+
return crs.Phase == REQUEST_GRANTED
4136
}
4237

43-
func (p RequestPhase) IsDenied() bool {
44-
return p == REQUEST_DENIED
38+
func (crs ClusterRequestStatus) IsDenied() bool {
39+
return crs.Phase == REQUEST_DENIED
4540
}
4641

47-
func (p RequestPhase) IsPending() bool {
48-
return p == "" || p == REQUEST_PENDING
42+
func (crs ClusterRequestStatus) IsPending() bool {
43+
return crs.Phase == "" || crs.Phase == REQUEST_PENDING
4944
}
5045

5146
// +kubebuilder:object:root=true

api/clusters/v1alpha1/constants.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@ const (
2424

2525
const (
2626
// PHASE_UNKNOWN represents an unknown phase for the cluster.
27-
PHASE_UNKNOWN ClusterPhase = "Unknown"
27+
PHASE_UNKNOWN string = "Unknown"
2828
// PHASE_PROGRESSING indicates that the cluster is being created or updated.
29-
PHASE_PROGRESSING ClusterPhase = "Progressing"
29+
PHASE_PROGRESSING string = "Progressing"
3030
// PHASE_SUCCEEDED indicates that the cluster is ready.
31-
PHASE_SUCCEEDED ClusterPhase = "Succeeded"
31+
PHASE_SUCCEEDED string = "Succeeded"
3232
// PHASE_FAILED indicates that an error occurred while creating or updating the cluster.
33-
PHASE_FAILED ClusterPhase = "Failed"
33+
PHASE_FAILED string = "Failed"
3434
// PHASE_DELETING indicates that the cluster is being deleted.
35-
PHASE_DELETING ClusterPhase = "Deleting"
35+
PHASE_DELETING string = "Deleting"
3636
// PHASE_DELETION_FAILED indicates that an error occurred while deleting the cluster.
37-
PHASE_DELETION_FAILED ClusterPhase = "DeletionFailed"
37+
PHASE_DELETION_FAILED string = "DeletionFailed"
3838
)
3939

4040
const (
4141
// REQUEST_PENDING indicates that the request has neither been granted nor denied yet.
42-
REQUEST_PENDING RequestPhase = "Pending"
42+
REQUEST_PENDING string = "Pending"
4343
// REQUEST_GRANTED indicates that the request has been granted.
44-
REQUEST_GRANTED RequestPhase = "Granted"
44+
REQUEST_GRANTED string = "Granted"
4545
// REQUEST_DENIED indicates that the request has been denied.
46-
REQUEST_DENIED RequestPhase = "Denied"
46+
REQUEST_DENIED string = "Denied"
4747
)
4848

4949
type Tenancy string

api/clusters/v1alpha1/zz_generated.deepcopy.go

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

api/common/status_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const (
1111
StatusPhaseTerminating = "Terminating"
1212
)
1313

14+
// +kubebuilder:object:generate=true
15+
1416
// Status represents the status of an openMCP resource.
1517
type Status struct {
1618
// ObservedGeneration is the generation of this resource that was last reconciled by the controller.

api/common/zz_generated.deepcopy.go

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

api/crds/manifests/clusters.openmcp.cloud_accessrequests.yaml

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -166,62 +166,67 @@ spec:
166166
conditions:
167167
description: Conditions contains the conditions.
168168
items:
169+
description: Condition contains details for one aspect of the current
170+
state of this API Resource.
169171
properties:
170172
lastTransitionTime:
171-
description: LastTransitionTime specifies the time when this
172-
condition's status last changed.
173+
description: |-
174+
lastTransitionTime is the last time the condition transitioned from one status to another.
175+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
173176
format: date-time
174177
type: string
175178
message:
176179
description: |-
177-
Message contains further details regarding the condition.
178-
It is meant for human users, Reason should be used for programmatic evaluation instead.
179-
It is optional, but should be filled at least when Status is not "True".
180+
message is a human readable message indicating details about the transition.
181+
This may be an empty string.
182+
maxLength: 32768
180183
type: string
184+
observedGeneration:
185+
description: |-
186+
observedGeneration represents the .metadata.generation that the condition was set based upon.
187+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
188+
with respect to the current state of the instance.
189+
format: int64
190+
minimum: 0
191+
type: integer
181192
reason:
182193
description: |-
183-
Reason is expected to contain a CamelCased string that provides further information regarding the condition.
184-
It should have a fixed value set (like an enum) to be machine-readable. The value set depends on the condition type.
185-
It is optional, but should be filled at least when Status is not "True".
194+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
195+
Producers of specific condition types may define expected values and meanings for this field,
196+
and whether the values are considered a guaranteed API.
197+
The value should be a CamelCase string.
198+
This field may not be empty.
199+
maxLength: 1024
200+
minLength: 1
201+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
186202
type: string
187203
status:
188-
description: Status is the status of the condition.
204+
description: status of the condition, one of True, False, Unknown.
205+
enum:
206+
- "True"
207+
- "False"
208+
- Unknown
189209
type: string
190210
type:
191-
description: |-
192-
Type is the type of the condition.
193-
Must be unique within the resource.
211+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
212+
maxLength: 316
213+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
194214
type: string
195215
required:
216+
- lastTransitionTime
217+
- message
218+
- reason
196219
- status
197220
- type
198221
type: object
199222
type: array
200-
lastReconcileTime:
201-
description: LastReconcileTime is the time when the resource was last
202-
reconciled by the controller.
203-
format: date-time
204-
type: string
205-
message:
206-
description: Message contains further details in a human-readable
207-
format.
208-
type: string
209223
observedGeneration:
210224
description: ObservedGeneration is the generation of this resource
211225
that was last reconciled by the controller.
212226
format: int64
213227
type: integer
214228
phase:
215-
default: Pending
216-
description: Phase is the current phase of the request.
217-
enum:
218-
- Pending
219-
- Granted
220-
- Denied
221-
type: string
222-
reason:
223-
description: Reason is expected to contain a CamelCased string that
224-
provides further information in a machine-readable format.
229+
description: Phase is the current phase of the resource.
225230
type: string
226231
secretRef:
227232
description: SecretRef holds the reference to the secret that contains
@@ -239,7 +244,6 @@ spec:
239244
- namespace
240245
type: object
241246
required:
242-
- lastReconcileTime
243247
- observedGeneration
244248
- phase
245249
type: object

0 commit comments

Comments
 (0)