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

     1  package v1alpha1
     2  
     3  import (
     4  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     5  )
     6  
     7  // These are valid conditions of an Idler
     8  const (
     9  	// IdlerTriggeredNotificationCreated is used to track the status of the notification send to a user
    10  	// when the idler is active for the very first time in user's namespace
    11  	IdlerTriggeredNotificationCreated ConditionType = "IdlerTriggeredNotificationCreated"
    12  
    13  	// Status condition reasons
    14  	IdlerUnableToEnsureIdlingReason                = "UnableToEnsureIdling"
    15  	IdlerRunningReason                             = "Running"
    16  	IdlerTriggeredReason                           = "IdlerRunningFirstTime"
    17  	IdlerTriggeredNotificationCreationFailedReason = "UnableToCreateIdlerNotification"
    18  	IdlerNoDeactivationReason                      = "NoDeactivation"
    19  )
    20  
    21  // NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.
    22  
    23  // IdlerSpec defines the desired state of Idler
    24  // +k8s:openapi-gen=true
    25  type IdlerSpec struct {
    26  	// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
    27  	// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
    28  
    29  	// TimeoutSeconds is the number of seconds before the running pods will be deleted
    30  	TimeoutSeconds int32 `json:"timeoutSeconds"`
    31  }
    32  
    33  // IdlerStatus defines the observed state of Idler
    34  // +k8s:openapi-gen=true
    35  type IdlerStatus struct {
    36  	// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
    37  	// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
    38  
    39  	// Pods is an array of tracked pods
    40  	// +optional
    41  	// +patchMergeKey=name
    42  	// +patchStrategy=merge
    43  	// +listType=map
    44  	// +listMapKey=name
    45  	Pods []Pod `json:"pods,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
    46  
    47  	// Conditions is an array of current Idler conditions
    48  	// Supported condition types: ConditionReady
    49  	// +optional
    50  	// +patchMergeKey=type
    51  	// +patchStrategy=merge
    52  	// +listType=map
    53  	// +listMapKey=type
    54  	Conditions []Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
    55  }
    56  
    57  type Pod struct {
    58  	Name      string      `json:"name"`
    59  	StartTime metav1.Time `json:"startTime"`
    60  }
    61  
    62  //+kubebuilder:object:root=true
    63  //+kubebuilder:subresource:status
    64  
    65  // Idler enables automatic idling of payloads in a user namespaces
    66  // where the name of the Idler matches the name of the corresponding namespace.
    67  // For example an Idler with "foo" name will be managing pods in namespace "foo".
    68  // +k8s:openapi-gen=true
    69  // +kubebuilder:subresource:status
    70  // +kubebuilder:resource:scope=Cluster
    71  // +kubebuilder:printcolumn:name="Timeout",type="integer",JSONPath=`.spec.timeoutSeconds`
    72  // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=`.status.conditions[?(@.type=="Ready")].status`
    73  // +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=`.status.conditions[?(@.type=="Ready")].reason`
    74  // +kubebuilder:validation:XPreserveUnknownFields
    75  // +operator-sdk:gen-csv:customresourcedefinitions.displayName="Idler"
    76  type Idler struct {
    77  	metav1.TypeMeta   `json:",inline"`
    78  	metav1.ObjectMeta `json:"metadata,omitempty"`
    79  
    80  	Spec   IdlerSpec   `json:"spec,omitempty"`
    81  	Status IdlerStatus `json:"status,omitempty"`
    82  }
    83  
    84  //+kubebuilder:object:root=true
    85  
    86  // IdlerList contains a list of Idlers
    87  type IdlerList struct {
    88  	metav1.TypeMeta `json:",inline"`
    89  	metav1.ListMeta `json:"metadata,omitempty"`
    90  	Items           []Idler `json:"items"`
    91  }
    92  
    93  func init() {
    94  	SchemeBuilder.Register(&Idler{}, &IdlerList{})
    95  }