Skip to content

Commit 3511902

Browse files
refactor: use common Status (#86)
* chore: update hack submodule * refactor(api): embed common status struct * refactor(controller): fix errors * feat: use `commonapi.ObjectReference` * feat(controller): use `commonapi.ObjectReference` * delete shared_types.go * chore: run `task generate` * release v0.9.0 * remove unused constants * fix: double import
1 parent 9a4f2ed commit 3511902

23 files changed

+314
-490
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.8.3-dev
1+
v0.9.0

api/clusters/v1alpha1/accessrequest_types.go

Lines changed: 18 additions & 9 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 (
@@ -20,14 +22,14 @@ type AccessRequestSpec struct {
2022
// This value is immutable.
2123
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="clusterRef is immutable"
2224
// +optional
23-
ClusterRef *NamespacedObjectReference `json:"clusterRef,omitempty"`
25+
ClusterRef *commonapi.ObjectReference `json:"clusterRef,omitempty"`
2426

2527
// RequestRef is the reference to the ClusterRequest for whose Cluster access is requested.
2628
// Is ignored if clusterRef is set.
2729
// This value is immutable.
2830
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="requestRef is immutable"
2931
// +optional
30-
RequestRef *NamespacedObjectReference `json:"requestRef,omitempty"`
32+
RequestRef *commonapi.ObjectReference `json:"requestRef,omitempty"`
3133

3234
// Permissions are the requested permissions.
3335
Permissions []PermissionsRequest `json:"permissions"`
@@ -46,15 +48,22 @@ 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.
57-
SecretRef *NamespacedObjectReference `json:"secretRef,omitempty"`
54+
SecretRef *commonapi.ObjectReference `json:"secretRef,omitempty"`
55+
}
56+
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
5867
}
5968

6069
// +kubebuilder:object:root=true

api/clusters/v1alpha1/cluster_types.go

Lines changed: 10 additions & 13 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
@@ -18,7 +20,7 @@ type ClusterSpec struct {
1820
// ClusterConfigs allows to reference any amount of provider-specific cluster configuration objects.
1921
// The k8s resource kind that is referenced by this depends on the provider (which is defined by the profile).
2022
// +optional
21-
ClusterConfigs []ObjectReference `json:"clusterConfigs,omitempty"`
23+
ClusterConfigs []commonapi.ObjectReference `json:"clusterConfigs,omitempty"`
2224

2325
// Kubernetes configuration for the cluster.
2426
Kubernetes K8sConfiguration `json:"kubernetes,omitempty"`
@@ -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/clusterprofile_types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ 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
// ClusterProfileSpec defines the desired state of Provider.
810
type ClusterProfileSpec struct {
911
// ProviderRef is a reference to the ClusterProvider
10-
ProviderRef ObjectReference `json:"providerRef"`
12+
ProviderRef commonapi.ObjectReference `json:"providerRef"`
1113

1214
// ProviderConfigRef is a reference to the provider-specific configuration.
13-
ProviderConfigRef ObjectReference `json:"providerConfigRef"`
15+
ProviderConfigRef commonapi.ObjectReference `json:"providerConfigRef"`
1416

1517
// SupportedVersions are the supported Kubernetes versions.
1618
SupportedVersions []SupportedK8sVersion `json:"supportedVersions"`

api/clusters/v1alpha1/clusterrequest_types.go

Lines changed: 10 additions & 15 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,32 +22,25 @@ 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.
3229
// +optional
3330
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="cluster is immutable"
34-
Cluster *NamespacedObjectReference `json:"cluster,omitempty"`
31+
Cluster *commonapi.ObjectReference `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 & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,28 @@ const (
1313
PURPOSE_MCP = "mcp"
1414
)
1515

16-
const (
17-
// CONDITION_UNKNOWN represents an unknown status for the condition.
18-
CONDITION_UNKNOWN ConditionStatus = "Unknown"
19-
// CONDITION_TRUE marks the condition as true.
20-
CONDITION_TRUE ConditionStatus = "True"
21-
// CONDITION_FALSE marks the condition as false.
22-
CONDITION_FALSE ConditionStatus = "False"
23-
)
24-
2516
const (
2617
// PHASE_UNKNOWN represents an unknown phase for the cluster.
27-
PHASE_UNKNOWN ClusterPhase = "Unknown"
18+
PHASE_UNKNOWN string = "Unknown"
2819
// PHASE_PROGRESSING indicates that the cluster is being created or updated.
29-
PHASE_PROGRESSING ClusterPhase = "Progressing"
20+
PHASE_PROGRESSING string = "Progressing"
3021
// PHASE_SUCCEEDED indicates that the cluster is ready.
31-
PHASE_SUCCEEDED ClusterPhase = "Succeeded"
22+
PHASE_SUCCEEDED string = "Succeeded"
3223
// PHASE_FAILED indicates that an error occurred while creating or updating the cluster.
33-
PHASE_FAILED ClusterPhase = "Failed"
24+
PHASE_FAILED string = "Failed"
3425
// PHASE_DELETING indicates that the cluster is being deleted.
35-
PHASE_DELETING ClusterPhase = "Deleting"
26+
PHASE_DELETING string = "Deleting"
3627
// PHASE_DELETION_FAILED indicates that an error occurred while deleting the cluster.
37-
PHASE_DELETION_FAILED ClusterPhase = "DeletionFailed"
28+
PHASE_DELETION_FAILED string = "DeletionFailed"
3829
)
3930

4031
const (
4132
// REQUEST_PENDING indicates that the request has neither been granted nor denied yet.
42-
REQUEST_PENDING RequestPhase = "Pending"
33+
REQUEST_PENDING string = "Pending"
4334
// REQUEST_GRANTED indicates that the request has been granted.
44-
REQUEST_GRANTED RequestPhase = "Granted"
35+
REQUEST_GRANTED string = "Granted"
4536
// REQUEST_DENIED indicates that the request has been denied.
46-
REQUEST_DENIED RequestPhase = "Denied"
37+
REQUEST_DENIED string = "Denied"
4738
)
4839

4940
type Tenancy string

api/clusters/v1alpha1/shared_types.go

Lines changed: 0 additions & 138 deletions
This file was deleted.

0 commit comments

Comments
 (0)