Skip to content

Commit d99e51b

Browse files
authored
implement accessrequest controller (#24)
* implement accessrequest controller * accessrequest controller now also adds profile label * accessrequest controller now also adds cluster reference * move general openmcp constants into own api package
1 parent 26438f0 commit d99e51b

39 files changed

+931
-120
lines changed

Taskfile.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ includes:
77
excludes: [] # put task names in here which are overwritten in this file
88
vars:
99
NESTED_MODULES: api
10-
API_DIRS: '{{.ROOT_DIR}}/api/provider/v1alpha1/... {{.ROOT_DIR}}/api/clusters/v1alpha1/...'
10+
API_DIRS: '{{.ROOT_DIR}}/api/...'
1111
MANIFEST_OUT: '{{.ROOT_DIR}}/api/crds/manifests'
12-
CODE_DIRS: '{{.ROOT_DIR}}/cmd/... {{.ROOT_DIR}}/internal/... {{.ROOT_DIR}}/api/provider/v1alpha1/... {{.ROOT_DIR}}/api/clusters/v1alpha1/...'
12+
CODE_DIRS: '{{.ROOT_DIR}}/cmd/... {{.ROOT_DIR}}/internal/... {{.ROOT_DIR}}/api/...'
1313
COMPONENTS: 'openmcp-operator'
1414
REPO_URL: 'https://github.com/openmcp-project/openmcp-operator'
1515
GENERATE_DOCS_INDEX: "true"

api/clusters/v1alpha1/accessrequest_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77

88
type AccessRequestSpec struct {
99
// ClusterRef is the reference to the Cluster for which access is requested.
10-
// Exactly one of clusterRef or requestRef must be set.
10+
// If set, requestRef will be ignored.
1111
// This value is immutable.
1212
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="clusterRef is immutable"
1313
// +optional
1414
ClusterRef *NamespacedObjectReference `json:"clusterRef,omitempty"`
1515

1616
// RequestRef is the reference to the ClusterRequest for whose Cluster access is requested.
17-
// Exactly one of clusterRef or requestRef must be set.
17+
// Is ignored if clusterRef is set.
1818
// This value is immutable.
1919
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="requestRef is immutable"
2020
// +optional

api/clusters/v1alpha1/clusterrequest_types.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type ClusterRequestSpec struct {
1111
Purpose string `json:"purpose"`
1212
}
1313

14-
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.clusterRef) || has(self.clusterRef)", message="clusterRef may not be removed once set"
14+
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.cluster) || has(self.cluster)", message="cluster may not be removed once set"
1515
type ClusterRequestStatus struct {
1616
CommonStatus `json:",inline"`
1717

@@ -23,8 +23,8 @@ type ClusterRequestStatus struct {
2323
// Cluster is the reference to the Cluster that was returned as a result of a granted request.
2424
// 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.
2525
// +optional
26-
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="clusterRef is immutable"
27-
Cluster *NamespacedObjectReference `json:"clusterRef,omitempty"`
26+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="cluster is immutable"
27+
Cluster *NamespacedObjectReference `json:"cluster,omitempty"`
2828
}
2929

3030
type RequestPhase string
@@ -49,6 +49,8 @@ func (p RequestPhase) IsPending() bool {
4949
// +kubebuilder:selectablefield:JSONPath=".status.phase"
5050
// +kubebuilder:printcolumn:JSONPath=".spec.purpose",name="Purpose",type=string
5151
// +kubebuilder:printcolumn:JSONPath=".status.phase",name="Phase",type=string
52+
// +kubebuilder:printcolumn:JSONPath=".status.cluster.name",name="Cluster",type=string
53+
// +kubebuilder:printcolumn:JSONPath=".status.cluster.namespace",name="Cluster-NS",type=string
5254

5355
// ClusterRequest is the Schema for the clusters API
5456
type ClusterRequest struct {

api/clusters/v1alpha1/constants.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,24 @@ const (
5656
)
5757

5858
const (
59-
// ClusterLabel can be used on CRDs to indicate onto which cluster they should be deployed.
60-
ClusterLabel = "openmcp.cloud/cluster"
61-
// OperationAnnotation is used to trigger specific operations on resources.
62-
OperationAnnotation = "openmcp.cloud/operation"
63-
// OperationAnnotationValueIgnore is used to ignore the resource.
64-
OperationAnnotationValueIgnore = "ignore"
65-
// OperationAnnotationValueReconcile is used to trigger a reconcile on the resource.
66-
OperationAnnotationValueReconcile = "reconcile"
67-
6859
// K8sVersionAnnotation can be used to display the k8s version of the cluster.
69-
K8sVersionAnnotation = "clusters.openmcp.cloud/k8sversion"
60+
K8sVersionAnnotation = GroupName + "/k8sversion"
7061
// ProviderInfoAnnotation can be used to display provider-specific information about the cluster.
71-
ProviderInfoAnnotation = "clusters.openmcp.cloud/providerinfo"
62+
ProviderInfoAnnotation = GroupName + "/providerinfo"
7263
// ProfileNameAnnotation can be used to display the actual name (not the hash) of the cluster profile.
73-
ProfileNameAnnotation = "clusters.openmcp.cloud/profile"
64+
ProfileNameAnnotation = GroupName + "/profile"
7465
// EnvironmentAnnotation can be used to display the environment of the cluster.
75-
EnvironmentAnnotation = "clusters.openmcp.cloud/environment"
66+
EnvironmentAnnotation = GroupName + "/environment"
7667
// ProviderAnnotation can be used to display the provider of the cluster.
77-
ProviderAnnotation = "clusters.openmcp.cloud/provider"
68+
ProviderAnnotation = GroupName + "/provider"
7869

7970
// DeleteWithoutRequestsLabel marks that the corresponding cluster can be deleted if the scheduler removes the last request pointing to it.
8071
// Its value must be "true" for the label to take effect.
81-
DeleteWithoutRequestsLabel = "clusters.openmcp.cloud/delete-without-requests"
72+
DeleteWithoutRequestsLabel = GroupName + "/delete-without-requests"
73+
// ProviderLabel is used to indicate the provider that is responsible for an AccessRequest.
74+
ProviderLabel = "provider." + GroupName
75+
// ProfileLabel is used to make the profile information easily accessible for the ClusterProviders.
76+
ProfileLabel = "profile." + GroupName
8277
)
8378

8479
const (

api/clusters/v1alpha1/constants/reasons.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const (
55
ReasonOnboardingClusterInteractionProblem = "OnboardingClusterInteractionProblem"
66
// ReasonPlatformClusterInteractionProblem is used when the platform cluster cannot be reached.
77
ReasonPlatformClusterInteractionProblem = "PlatformClusterInteractionProblem"
8+
// ReasonInvalidReference means that a reference points to a non-existing or otherwise invalid object.
9+
ReasonInvalidReference = "InvalidReference"
810
// ReasonConfigurationProblem indicates that something is configured incorrectly.
911
ReasonConfigurationProblem = "ConfigurationProblem"
1012
// ReasonInternalError indicates that something went wrong internally.

api/clusters/v1alpha1/groupversion_info.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ package v1alpha1
55
import (
66
"k8s.io/apimachinery/pkg/runtime/schema"
77
"sigs.k8s.io/controller-runtime/pkg/scheme"
8+
9+
apiconst "github.com/openmcp-project/openmcp-operator/api/constants"
810
)
911

10-
const GroupName = "clusters.openmcp.cloud"
12+
const GroupName = "clusters." + apiconst.OpenMCPGroupName
1113

1214
var (
1315
// GroupVersion is group version used to register these objects

api/constants/constants.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package constants
2+
3+
const (
4+
// OpenMCPGroupName is the base API group name for OpenMCP.
5+
OpenMCPGroupName = "openmcp.cloud"
6+
7+
// ClusterLabel can be used on CRDs to indicate onto which cluster they should be deployed.
8+
ClusterLabel = OpenMCPGroupName + "/cluster"
9+
10+
// OperationAnnotation is used to trigger specific operations on resources.
11+
OperationAnnotation = OpenMCPGroupName + "/operation"
12+
// OperationAnnotationValueIgnore is used to ignore the resource.
13+
OperationAnnotationValueIgnore = "ignore"
14+
// OperationAnnotationValueReconcile is used to trigger a reconcile on the resource.
15+
OperationAnnotationValueReconcile = "reconcile"
16+
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ spec:
5050
clusterRef:
5151
description: |-
5252
ClusterRef is the reference to the Cluster for which access is requested.
53-
Exactly one of clusterRef or requestRef must be set.
53+
If set, requestRef will be ignored.
5454
This value is immutable.
5555
properties:
5656
name:
@@ -135,7 +135,7 @@ spec:
135135
requestRef:
136136
description: |-
137137
RequestRef is the reference to the ClusterRequest for whose Cluster access is requested.
138-
Exactly one of clusterRef or requestRef must be set.
138+
Is ignored if clusterRef is set.
139139
This value is immutable.
140140
properties:
141141
name:

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ spec:
2626
- jsonPath: .status.phase
2727
name: Phase
2828
type: string
29+
- jsonPath: .status.cluster.name
30+
name: Cluster
31+
type: string
32+
- jsonPath: .status.cluster.namespace
33+
name: Cluster-NS
34+
type: string
2935
name: v1alpha1
3036
schema:
3137
openAPIV3Schema:
@@ -62,7 +68,7 @@ spec:
6268
rule: self == oldSelf
6369
status:
6470
properties:
65-
clusterRef:
71+
cluster:
6672
description: |-
6773
Cluster is the reference to the Cluster that was returned as a result of a granted request.
6874
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.
@@ -79,7 +85,7 @@ spec:
7985
- namespace
8086
type: object
8187
x-kubernetes-validations:
82-
- message: clusterRef is immutable
88+
- message: cluster is immutable
8389
rule: self == oldSelf
8490
conditions:
8591
description: Conditions contains the conditions.
@@ -147,8 +153,8 @@ spec:
147153
- phase
148154
type: object
149155
x-kubernetes-validations:
150-
- message: clusterRef may not be removed once set
151-
rule: '!has(oldSelf.clusterRef) || has(self.clusterRef)'
156+
- message: cluster may not be removed once set
157+
rule: '!has(oldSelf.cluster) || has(self.cluster)'
152158
type: object
153159
selectableFields:
154160
- jsonPath: .spec.purpose

cmd/openmcp-operator/app/init.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"sigs.k8s.io/yaml"
1111

1212
clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
13+
apiconst "github.com/openmcp-project/openmcp-operator/api/constants"
1314
"github.com/openmcp-project/openmcp-operator/api/crds"
1415
"github.com/openmcp-project/openmcp-operator/api/install"
1516
)
@@ -75,12 +76,12 @@ func (o *InitOptions) Run(ctx context.Context) error {
7576
log.Info("Environment", "value", o.Environment)
7677

7778
// apply CRDs
78-
crdManager := crdutil.NewCRDManager(clustersv1alpha1.ClusterLabel, crds.CRDs)
79+
crdManager := crdutil.NewCRDManager(apiconst.ClusterLabel, crds.CRDs)
7980

8081
crdManager.AddCRDLabelToClusterMapping(clustersv1alpha1.PURPOSE_ONBOARDING, o.Clusters.Onboarding)
8182
crdManager.AddCRDLabelToClusterMapping(clustersv1alpha1.PURPOSE_PLATFORM, o.Clusters.Platform)
8283

83-
if err := crdManager.CreateOrUpdateCRDs(ctx, nil); err != nil {
84+
if err := crdManager.CreateOrUpdateCRDs(ctx, &log); err != nil {
8485
return fmt.Errorf("error creating/updating CRDs: %w", err)
8586
}
8687

0 commit comments

Comments
 (0)