|
| 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 | +// OCMRoleProfile defines the permission level for the OCM role |
| 28 | +type OCMRoleProfile string |
| 29 | + |
| 30 | +const ( |
| 31 | + // OCMRoleProfileStandard provides standard OCM permissions |
| 32 | + OCMRoleProfileStandard OCMRoleProfile = "Standard" |
| 33 | + |
| 34 | + // OCMRoleProfileAdmin provides admin OCM permissions |
| 35 | + OCMRoleProfileAdmin OCMRoleProfile = "Admin" |
| 36 | + |
| 37 | + // OCMRoleProfileNoConsole provides minimal OCM permissions (cannot use console.redhat.com) |
| 38 | + OCMRoleProfileNoConsole OCMRoleProfile = "NoConsole" |
| 39 | +) |
| 40 | + |
| 41 | +const ( |
| 42 | + // OCMRoleConfigReadyCondition condition reports on the successful reconciliation of OCMRoleConfig. |
| 43 | + OCMRoleConfigReadyCondition = "OCMRoleConfigReady" |
| 44 | + |
| 45 | + // OCMRoleConfigDeletionFailedReason used to report failures while deleting OCMRoleConfig. |
| 46 | + OCMRoleConfigDeletionFailedReason = "DeletionFailed" |
| 47 | + |
| 48 | + // OCMRoleConfigReconciliationFailedReason used to report reconciliation failures. |
| 49 | + OCMRoleConfigReconciliationFailedReason = "ReconciliationFailed" |
| 50 | + |
| 51 | + // OCMRoleConfigDeletionStarted used to indicate that the deletion of OCMRoleConfig has started. |
| 52 | + OCMRoleConfigDeletionStarted = "DeletionStarted" |
| 53 | + |
| 54 | + // OCMRoleConfigCreatedReason used to indicate that the OCMRoleConfig has been created. |
| 55 | + OCMRoleConfigCreatedReason = "Created" |
| 56 | + |
| 57 | + // OCMRoleConfigLinkedReason used to indicate that the OCM role has been linked to the organization. |
| 58 | + OCMRoleConfigLinkedReason = "Linked" |
| 59 | +) |
| 60 | + |
| 61 | +// OCMRoleConfigSpec defines the desired state of OCMRoleConfig |
| 62 | +type OCMRoleConfigSpec 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:=32 |
| 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 OCMRoleProfile `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:default="/" |
| 85 | + Path string `json:"path,omitempty"` |
| 86 | + |
| 87 | + // ManagedPolicies indicates whether to use AWS-managed policies (true) or customer-managed policies (false). |
| 88 | + // +optional |
| 89 | + // +kubebuilder:default=false |
| 90 | + ManagedPolicies bool `json:"managedPolicies,omitempty"` |
| 91 | + |
| 92 | + // IdentityRef is a reference to an identity to be used when reconciling the OCM Role Config. |
| 93 | + // If no identity is specified, the default identity for this controller will be used. |
| 94 | + // +optional |
| 95 | + IdentityRef *infrav1.AWSIdentityReference `json:"identityRef,omitempty"` |
| 96 | + |
| 97 | + // CredentialsSecretRef references a secret with necessary credentials to connect to the OCM API. |
| 98 | + // +optional |
| 99 | + CredentialsSecretRef *corev1.LocalObjectReference `json:"credentialsSecretRef,omitempty"` |
| 100 | +} |
| 101 | + |
| 102 | +// OCMRoleConfigStatus defines the observed state of OCMRoleConfig |
| 103 | +type OCMRoleConfigStatus struct { |
| 104 | + // RoleARN is the ARN of the created OCM role. |
| 105 | + RoleARN string `json:"roleARN,omitempty"` |
| 106 | + |
| 107 | + // OrganizationID is the OCM organization ID that this role is linked to. |
| 108 | + OrganizationID string `json:"organizationID,omitempty"` |
| 109 | + |
| 110 | + // Linked indicates whether the role has been successfully linked to the OCM organization. |
| 111 | + Linked bool `json:"linked,omitempty"` |
| 112 | + |
| 113 | + // Conditions specifies the OCMRoleConfig conditions |
| 114 | + Conditions clusterv1beta1.Conditions `json:"conditions,omitempty"` |
| 115 | +} |
| 116 | + |
| 117 | +// OCMRoleConfig is the Schema for the ocmroleconfigs API |
| 118 | +// +kubebuilder:object:root=true |
| 119 | +// +kubebuilder:resource:path=ocmroleconfigs,scope=Cluster,categories=cluster-api,shortName=ocmrole |
| 120 | +// +kubebuilder:storageversion |
| 121 | +// +kubebuilder:subresource:status |
| 122 | +type OCMRoleConfig struct { |
| 123 | + metav1.TypeMeta `json:",inline"` |
| 124 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 125 | + |
| 126 | + Spec OCMRoleConfigSpec `json:"spec,omitempty"` |
| 127 | + Status OCMRoleConfigStatus `json:"status,omitempty"` |
| 128 | +} |
| 129 | + |
| 130 | +// OCMRoleConfigList contains a list of OCMRoleConfig |
| 131 | +// +kubebuilder:object:root=true |
| 132 | +type OCMRoleConfigList struct { |
| 133 | + metav1.TypeMeta `json:",inline"` |
| 134 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 135 | + Items []OCMRoleConfig `json:"items"` |
| 136 | +} |
| 137 | + |
| 138 | +// SetConditions sets the conditions of the OCMRoleConfig. |
| 139 | +func (r *OCMRoleConfig) SetConditions(conditions clusterv1beta1.Conditions) { |
| 140 | + r.Status.Conditions = conditions |
| 141 | +} |
| 142 | + |
| 143 | +// GetConditions returns the observations of the operational state of the OCMRoleConfig resource. |
| 144 | +func (r *OCMRoleConfig) GetConditions() clusterv1beta1.Conditions { |
| 145 | + return r.Status.Conditions |
| 146 | +} |
| 147 | + |
| 148 | +func init() { |
| 149 | + SchemeBuilder.Register(&OCMRoleConfig{}, &OCMRoleConfigList{}) |
| 150 | +} |
0 commit comments