|
| 1 | +/* |
| 2 | + Copyright (c) 2022, 2023 Oracle and/or its affiliates. |
| 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 | + https://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 v1beta1 |
| 18 | + |
| 19 | +import ( |
| 20 | + corev1 "k8s.io/api/core/v1" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 23 | +) |
| 24 | + |
| 25 | +type PrincipalType string |
| 26 | + |
| 27 | +const ( |
| 28 | + // UserPrincipal represents a user principal. |
| 29 | + UserPrincipal PrincipalType = "UserPrincipal" |
| 30 | +) |
| 31 | + |
| 32 | +// OCIClusterIdentitySpec defines the parameters that are used to create an OCIClusterIdentity. |
| 33 | +type OCIClusterIdentitySpec struct { |
| 34 | + // Type is the type of OCI Principal used. |
| 35 | + // UserPrincipal is the only supported value |
| 36 | + Type PrincipalType `json:"type"` |
| 37 | + |
| 38 | + // PrincipalSecret is a secret reference which contains the authentication credentials for the principal. |
| 39 | + // +optional |
| 40 | + PrincipalSecret corev1.SecretReference `json:"principalSecret,omitempty"` |
| 41 | + |
| 42 | + // AllowedNamespaces is used to identify the namespaces the clusters are allowed to use the identity from. |
| 43 | + // Namespaces can be selected either using an array of namespaces or with label selector. |
| 44 | + // An empty allowedNamespaces object indicates that OCIClusters can use this identity from any namespace. |
| 45 | + // If this object is nil, no namespaces will be allowed (default behaviour, if this field is not provided) |
| 46 | + // A namespace should be either in the NamespaceList or match with Selector to use the identity. |
| 47 | + // |
| 48 | + // +optional |
| 49 | + // +nullable |
| 50 | + AllowedNamespaces *AllowedNamespaces `json:"allowedNamespaces"` |
| 51 | +} |
| 52 | + |
| 53 | +// AllowedNamespaces defines the namespaces the clusters are allowed to use the identity from |
| 54 | +type AllowedNamespaces struct { |
| 55 | + // A nil or empty list indicates that OCICluster cannot use the identity from any namespace. |
| 56 | + // NamespaceList takes precedence over the Selector. |
| 57 | + // +optional |
| 58 | + // +nullable |
| 59 | + NamespaceList []string `json:"list"` |
| 60 | + |
| 61 | + // Selector is a selector of namespaces that OCICluster can |
| 62 | + // use this Identity from. This is a standard Kubernetes LabelSelector, |
| 63 | + // a label query over a set of resources. The result of matchLabels and |
| 64 | + // matchExpressions are ANDed. |
| 65 | + // |
| 66 | + // A nil or empty selector indicates that OCICluster cannot use this |
| 67 | + // OCIClusterIdentity from any namespace. |
| 68 | + // +optional |
| 69 | + Selector *metav1.LabelSelector `json:"selector"` |
| 70 | +} |
| 71 | + |
| 72 | +// OCIClusterIdentityStatus defines the observed state of OCIClusterIdentity. |
| 73 | +type OCIClusterIdentityStatus struct { |
| 74 | + // Conditions defines current service state of the OCIClusterIdentity. |
| 75 | + // +optional |
| 76 | + Conditions clusterv1.Conditions `json:"conditions,omitempty"` |
| 77 | +} |
| 78 | + |
| 79 | +//+kubebuilder:object:root=true |
| 80 | +//+kubebuilder:subresource:status |
| 81 | + |
| 82 | +// OCIClusterIdentity is the Schema for the OCI Cluster Identity API |
| 83 | +type OCIClusterIdentity struct { |
| 84 | + metav1.TypeMeta `json:",inline"` |
| 85 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 86 | + Spec OCIClusterIdentitySpec `json:"spec,omitempty"` |
| 87 | + Status OCIClusterIdentityStatus `json:"status,omitempty"` |
| 88 | +} |
| 89 | + |
| 90 | +// +kubebuilder:object:root=true |
| 91 | + |
| 92 | +// OCIClusterIdentityList contains a list of OCIClusterIdentity. |
| 93 | +type OCIClusterIdentityList struct { |
| 94 | + metav1.TypeMeta `json:",inline"` |
| 95 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 96 | + Items []OCIClusterIdentity `json:"items"` |
| 97 | +} |
| 98 | + |
| 99 | +func init() { |
| 100 | + SchemeBuilder.Register(&OCIClusterIdentity{}, &OCIClusterIdentityList{}) |
| 101 | +} |
0 commit comments