|
| 1 | +/* |
| 2 | +Copyright 2026 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1beta2 |
| 18 | + |
| 19 | +import ( |
| 20 | + corev1 "k8s.io/api/core/v1" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | + |
| 23 | + infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" |
| 24 | + clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" |
| 25 | +) |
| 26 | + |
| 27 | +// ROSAOCMRoleProfile defines the permission level for the OCM role |
| 28 | +type ROSAOCMRoleProfile string |
| 29 | + |
| 30 | +const ( |
| 31 | + // ROSAOCMRoleProfileStandard provides standard OCM permissions |
| 32 | + ROSAOCMRoleProfileStandard ROSAOCMRoleProfile = "Standard" |
| 33 | + |
| 34 | + // ROSAOCMRoleProfileAdmin provides admin OCM permissions |
| 35 | + ROSAOCMRoleProfileAdmin ROSAOCMRoleProfile = "Admin" |
| 36 | + |
| 37 | + // ROSAOCMRoleProfileNoConsole provides minimal OCM permissions (cannot use console.redhat.com) |
| 38 | + ROSAOCMRoleProfileNoConsole ROSAOCMRoleProfile = "NoConsole" |
| 39 | +) |
| 40 | + |
| 41 | +const ( |
| 42 | + // ROSAOCMRoleConfigReadyCondition condition reports on the successful reconciliation of ROSAOCMRoleConfig. |
| 43 | + ROSAOCMRoleConfigReadyCondition = "ROSAOCMRoleConfigReady" |
| 44 | + |
| 45 | + // ROSAOCMRoleConfigDeletionFailedReason used to report failures while deleting ROSAOCMRoleConfig. |
| 46 | + ROSAOCMRoleConfigDeletionFailedReason = "DeletionFailed" |
| 47 | + |
| 48 | + // ROSAOCMRoleConfigReconciliationFailedReason used to report reconciliation failures. |
| 49 | + ROSAOCMRoleConfigReconciliationFailedReason = "ReconciliationFailed" |
| 50 | + |
| 51 | + // ROSAOCMRoleConfigDeletionStarted used to indicate that the deletion of ROSAOCMRoleConfig has started. |
| 52 | + ROSAOCMRoleConfigDeletionStarted = "DeletionStarted" |
| 53 | + |
| 54 | + // ROSAOCMRoleConfigCreatedReason used to indicate that the ROSAOCMRoleConfig has been created. |
| 55 | + ROSAOCMRoleConfigCreatedReason = "Created" |
| 56 | + |
| 57 | + // ROSAOCMRoleConfigLinkedReason used to indicate that the OCM role has been linked to the organization. |
| 58 | + ROSAOCMRoleConfigLinkedReason = "Linked" |
| 59 | +) |
| 60 | + |
| 61 | +// ROSAOCMRoleConfigSpec defines the desired state of ROSAOCMRoleConfig |
| 62 | +type ROSAOCMRoleConfigSpec struct { |
| 63 | + // RolePrefix is the user-defined prefix for the OCM role name. |
| 64 | + // The final role name will be: {RolePrefix}-OCM-Role-{ExternalID} |
| 65 | + // where ExternalID is the organization's external identifier from OCM. |
| 66 | + // +kubebuilder:validation:Required |
| 67 | + // +kubebuilder:validation:MaxLength:=4 |
| 68 | + // +kubebuilder:validation:Pattern:=`^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$` |
| 69 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf", message="rolePrefix is immutable" |
| 70 | + RolePrefix string `json:"rolePrefix"` |
| 71 | + |
| 72 | + // Profile defines the permission level for the OCM role. |
| 73 | + // +kubebuilder:validation:Enum=Standard;Admin;NoConsole |
| 74 | + // +kubebuilder:default=Standard |
| 75 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf", message="profile is immutable" |
| 76 | + Profile ROSAOCMRoleProfile `json:"profile"` |
| 77 | + |
| 78 | + // PermissionsBoundaryARN is the ARN of the policy that is used to set the permissions boundary for the OCM role. |
| 79 | + // +optional |
| 80 | + PermissionsBoundaryARN string `json:"permissionsBoundaryARN,omitempty"` |
| 81 | + |
| 82 | + // Path is the IAM path for the OCM role. |
| 83 | + // +optional |
| 84 | + // +kubebuilder:validation:Pattern=`^\/.*$` |
| 85 | + Path string `json:"path,omitempty"` |
| 86 | + |
| 87 | + // IdentityRef is a reference to an identity to be used when reconciling the OCM Role Config. |
| 88 | + // If no identity is specified, the default identity for this controller will be used. |
| 89 | + // +optional |
| 90 | + IdentityRef *infrav1.AWSIdentityReference `json:"identityRef,omitempty"` |
| 91 | + |
| 92 | + // CredentialsSecretRef references a secret with necessary credentials to connect to the OCM API. |
| 93 | + // +optional |
| 94 | + CredentialsSecretRef *corev1.LocalObjectReference `json:"credentialsSecretRef,omitempty"` |
| 95 | +} |
| 96 | + |
| 97 | +// ROSAOCMRoleConfigStatus defines the observed state of ROSAOCMRoleConfig |
| 98 | +type ROSAOCMRoleConfigStatus struct { |
| 99 | + // RoleARN is the ARN of the created OCM role. |
| 100 | + RoleARN string `json:"roleARN,omitempty"` |
| 101 | + |
| 102 | + // OrganizationID is the OCM organization ID that this role is linked to. |
| 103 | + OrganizationID string `json:"organizationID,omitempty"` |
| 104 | + |
| 105 | + // Conditions specifies the ROSAOCMRoleConfig conditions |
| 106 | + Conditions clusterv1beta1.Conditions `json:"conditions,omitempty"` |
| 107 | +} |
| 108 | + |
| 109 | +// ROSAOCMRoleConfig is the Schema for the rosaocmroleconfigs API |
| 110 | +// +kubebuilder:object:root=true |
| 111 | +// +kubebuilder:resource:path=rosaocmroleconfigs,scope=Cluster,categories=cluster-api,shortName=rosaocmrole |
| 112 | +// +kubebuilder:storageversion |
| 113 | +// +kubebuilder:subresource:status |
| 114 | +type ROSAOCMRoleConfig struct { |
| 115 | + metav1.TypeMeta `json:",inline"` |
| 116 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 117 | + |
| 118 | + Spec ROSAOCMRoleConfigSpec `json:"spec,omitempty"` |
| 119 | + Status ROSAOCMRoleConfigStatus `json:"status,omitempty"` |
| 120 | +} |
| 121 | + |
| 122 | +// ROSAOCMRoleConfigList contains a list of ROSAOCMRoleConfig |
| 123 | +// +kubebuilder:object:root=true |
| 124 | +type ROSAOCMRoleConfigList struct { |
| 125 | + metav1.TypeMeta `json:",inline"` |
| 126 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 127 | + Items []ROSAOCMRoleConfig `json:"items"` |
| 128 | +} |
| 129 | + |
| 130 | +// SetConditions sets the conditions of the ROSAOCMRoleConfig. |
| 131 | +func (r *ROSAOCMRoleConfig) SetConditions(conditions clusterv1beta1.Conditions) { |
| 132 | + r.Status.Conditions = conditions |
| 133 | +} |
| 134 | + |
| 135 | +// GetConditions returns the observations of the operational state of the ROSAOCMRoleConfig resource. |
| 136 | +func (r *ROSAOCMRoleConfig) GetConditions() clusterv1beta1.Conditions { |
| 137 | + return r.Status.Conditions |
| 138 | +} |
| 139 | + |
| 140 | +func init() { |
| 141 | + SchemeBuilder.Register(&ROSAOCMRoleConfig{}, &ROSAOCMRoleConfigList{}) |
| 142 | +} |
0 commit comments