github.com/codeready-toolchain/api@v0.0.0-20240507023248-73662d6db2c5/api/v1alpha1/space_types.go (about)

     1  package v1alpha1
     2  
     3  import (
     4  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     5  )
     6  
     7  const (
     8  	// SpaceCreatorLabelKey is used to label the Space with the ID of its creator (Dev Sandbox UserSignup or AppStudio Workspace)
     9  	SpaceCreatorLabelKey = LabelKeyPrefix + "creator"
    10  
    11  	// ParentSpaceLabelKey is used to label the Space with the name of the parent space
    12  	// from which the creation was requested
    13  	ParentSpaceLabelKey = LabelKeyPrefix + "parent-space"
    14  )
    15  
    16  // These are valid status condition reasons of a Space
    17  const (
    18  	// Status condition reasons
    19  	SpaceUnableToCreateNSTemplateSetReason = "UnableToCreateNSTemplateSet"
    20  	SpaceUnableToUpdateNSTemplateSetReason = "UnableToUpdateNSTemplateSet"
    21  	SpaceProvisioningReason                = provisioningReason
    22  	SpaceProvisioningPendingReason         = "ProvisioningPending"
    23  	SpaceProvisioningFailedReason          = "UnableToProvision"
    24  	SpaceProvisionedReason                 = provisionedReason
    25  	SpaceTerminatingReason                 = terminatingReason
    26  	SpaceTerminatingFailedReason           = terminatingFailedReason
    27  	SpaceUpdatingReason                    = updatingReason
    28  	SpaceRetargetingReason                 = "Retargeting"
    29  	SpaceRetargetingFailedReason           = "UnableToRetarget"
    30  
    31  	// SpaceStateLabelKey is used for setting the actual/expected state of Spaces (pending, or empty).
    32  	// The main purpose of the label is easy selecting the Spaces based on the state - eg. get all Spaces on the waiting list (state=pending).
    33  	SpaceStateLabelKey = StateLabelKey
    34  	// SpaceStateLabelValuePending is used for identifying that the Space is waiting for assigning an available cluster
    35  	SpaceStateLabelValuePending = StateLabelValuePending
    36  	// SpaceStateLabelValueClusterAssigned is used for identifying that the Space has an assigned cluster
    37  	SpaceStateLabelValueClusterAssigned = "cluster-assigned"
    38  )
    39  
    40  // SpaceSpec defines the desired state of Space
    41  // +k8s:openapi-gen=true
    42  type SpaceSpec struct {
    43  
    44  	// TargetCluster The cluster in which this Space is going to be provisioned
    45  	// If not set then the target cluster will be picked automatically
    46  	// +optional
    47  	TargetCluster string `json:"targetCluster,omitempty"`
    48  
    49  	// TargetClusterRoles one or more label keys that define a set of clusters
    50  	// where the Space can be provisioned.
    51  	// The target cluster has to match ALL the roles defined in this field in order for the space to be provisioned there.
    52  	// It can be used as an alternative to targetCluster field, which has precedence in case both roles and name are provided.
    53  	// +optional
    54  	// +listType=atomic
    55  	TargetClusterRoles []string `json:"targetClusterRoles,omitempty"`
    56  
    57  	// TierName is introduced to retain the name of the tier
    58  	// for which this Space is provisioned
    59  	// If not set then the tier name will be set automatically
    60  	// +optional
    61  	TierName string `json:"tierName,omitempty"`
    62  
    63  	// ParentSpace holds the name of the context (Space) from which this space was created (requested),
    64  	// enabling hierarchy relationships between different Spaces.
    65  	//
    66  	// Keeping this association brings two main benefits:
    67  	// 1. SpaceBindings are inherited from the parent Space
    68  	// 2. Ability to easily monitor quota for the requested sub-spaces
    69  	// +optional
    70  	ParentSpace string `json:"parentSpace,omitempty"`
    71  
    72  	// DisableInheritance indicates whether or not SpaceBindings from the parent-spaces are
    73  	// automatically inherited to all sub-spaces in the tree.
    74  	//
    75  	// Set to True to disable SpaceBinding inheritance from the parent-spaces.
    76  	// Default is False.
    77  	// +optional
    78  	DisableInheritance bool `json:"disableInheritance,omitempty"`
    79  }
    80  
    81  // SpaceStatus defines the observed state of Space
    82  // +k8s:openapi-gen=true
    83  type SpaceStatus struct {
    84  
    85  	// TargetCluster The cluster in which this Space is currently provisioned
    86  	// Can be empty if provisioning did not start or failed
    87  	// To be used to de-provision the NSTemplateSet if the Spec.TargetCluster is either changed or removed
    88  	// +optional
    89  	TargetCluster string `json:"targetCluster,omitempty"`
    90  
    91  	// ProvisionedNamespaces is a list of Namespaces that were provisioned for the Space.
    92  	// +optional
    93  	// +listType=atomic
    94  	ProvisionedNamespaces []SpaceNamespace `json:"provisionedNamespaces,omitempty"`
    95  
    96  	// Conditions is an array of current Space conditions
    97  	// Supported condition types: ConditionReady
    98  	// +optional
    99  	// +patchMergeKey=type
   100  	// +patchStrategy=merge
   101  	// +listType=map
   102  	// +listMapKey=type
   103  	Conditions []Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
   104  }
   105  
   106  // +kubebuilder:object:root=true
   107  // +kubebuilder:subresource:status
   108  // Space is the Schema for the spaces API
   109  // +k8s:openapi-gen=true
   110  // +kubebuilder:resource:scope=Namespaced
   111  // +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=`.spec.targetCluster`
   112  // +kubebuilder:printcolumn:name="Tier",type="string",JSONPath=`.spec.tierName`
   113  // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=`.status.conditions[?(@.type=="Ready")].status`
   114  // +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=`.status.conditions[?(@.type=="Ready")].reason`
   115  // +kubebuilder:validation:XPreserveUnknownFields
   116  // +operator-sdk:gen-csv:customresourcedefinitions.displayName="Space"
   117  type Space struct {
   118  	metav1.TypeMeta   `json:",inline"`
   119  	metav1.ObjectMeta `json:"metadata,omitempty"`
   120  
   121  	Spec   SpaceSpec   `json:"spec,omitempty"`
   122  	Status SpaceStatus `json:"status,omitempty"`
   123  }
   124  
   125  //+kubebuilder:object:root=true
   126  
   127  // SpaceList contains a list of Space
   128  type SpaceList struct {
   129  	metav1.TypeMeta `json:",inline"`
   130  	metav1.ListMeta `json:"metadata,omitempty"`
   131  	Items           []Space `json:"items"`
   132  }
   133  
   134  func init() {
   135  	SchemeBuilder.Register(&Space{}, &SpaceList{})
   136  }