github.com/openebs/api@v1.12.0/pkg/internalapis/apis/cstor/cstorvolumeconfig.go (about)

     1  /*
     2  Copyright 2020 The OpenEBS 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 cstor
    18  
    19  import (
    20  	corev1 "k8s.io/api/core/v1"
    21  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    22  )
    23  
    24  // +genclient
    25  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    26  // +k8s:openapi-gen=true
    27  
    28  // CStorVolumeConfig describes a cstor volume claim resource created as
    29  // custom resource. CStorVolumeConfig is a request for creating cstor volume
    30  // related resources like deployment, svc etc.
    31  type CStorVolumeConfig struct {
    32  	metav1.TypeMeta   `json:",inline"`
    33  	metav1.ObjectMeta `json:"metadata,omitempty"`
    34  	// Spec defines a specification of a cstor volume claim required
    35  	// to provisione cstor volume resources
    36  	Spec CStorVolumeConfigSpec `json:"spec"`
    37  
    38  	// Publish contains info related to attachment of a volume to a node.
    39  	// i.e. NodeId etc.
    40  	Publish CStorVolumeConfigPublish `json:"publish,omitempty"`
    41  
    42  	// Status represents the current information/status for the cstor volume
    43  	// claim, populated by the controller.
    44  	Status         CStorVolumeConfigStatus `json:"status"`
    45  	VersionDetails VersionDetails          `json:"versionDetails"`
    46  }
    47  
    48  // CStorVolumeConfigSpec is the spec for a CStorVolumeConfig resource
    49  type CStorVolumeConfigSpec struct {
    50  	// Capacity represents the actual resources of the underlying
    51  	// cstor volume.
    52  	Capacity corev1.ResourceList `json:"capacity"`
    53  	// CStorVolumeRef has the information about where CstorVolumeClaim
    54  	// is created from.
    55  	CStorVolumeRef *corev1.ObjectReference `json:"cstorVolumeRef,omitempty"`
    56  	// CStorVolumeSource contains the source volumeName@snapShotname
    57  	// combaination.  This will be filled only if it is a clone creation.
    58  	CStorVolumeSource string `json:"cstorVolumeSource,omitempty"`
    59  	// Provision represents the initial volume configuration for the underlying
    60  	// cstor volume based on the persistent volume request by user. Provision
    61  	// properties are immutable
    62  	Provision VolumeProvision `json:"provision"`
    63  	// Policy contains volume specific required policies target and replicas
    64  	Policy CStorVolumePolicySpec `json:"policy"`
    65  }
    66  
    67  type VolumeProvision struct {
    68  	// Capacity represents initial capacity of volume replica required during
    69  	// volume clone operations to maintain some metadata info related to child
    70  	// resources like snapshot, cloned volumes.
    71  	Capacity corev1.ResourceList `json:"capacity"`
    72  	// ReplicaCount represents initial cstor volume replica count, its will not
    73  	// be updated later on based on scale up/down operations, only readonly
    74  	// operations and validations.
    75  	ReplicaCount int32 `json:"replicaCount"`
    76  }
    77  
    78  // CStorVolumeConfigPublish contains info related to attachment of a volume to a node.
    79  // i.e. NodeId etc.
    80  type CStorVolumeConfigPublish struct {
    81  	// NodeID contains publish info related to attachment of a volume to a node.
    82  	NodeID string `json:"nodeId,omitempty"`
    83  }
    84  
    85  // CStorVolumeConfigPhase represents the current phase of CStorVolumeConfig.
    86  type CStorVolumeConfigPhase string
    87  
    88  const (
    89  	//CStorVolumeConfigPhasePending indicates that the cvc is still waiting for
    90  	//the cstorvolume to be created and bound
    91  	CStorVolumeConfigPhasePending CStorVolumeConfigPhase = "Pending"
    92  
    93  	//CStorVolumeConfigPhaseBound indiacates that the cstorvolume has been
    94  	//provisioned and bound to the cstor volume claim
    95  	CStorVolumeConfigPhaseBound CStorVolumeConfigPhase = "Bound"
    96  
    97  	//CStorVolumeConfigPhaseFailed indiacates that the cstorvolume provisioning
    98  	//has failed
    99  	CStorVolumeConfigPhaseFailed CStorVolumeConfigPhase = "Failed"
   100  )
   101  
   102  // CStorVolumeConfigStatus is for handling status of CstorVolume Claim.
   103  // defines the observed state of CStorVolumeConfig
   104  type CStorVolumeConfigStatus struct {
   105  	// Phase represents the current phase of CStorVolumeConfig.
   106  	Phase CStorVolumeConfigPhase `json:"phase"`
   107  
   108  	// PoolInfo represents current pool names where volume replicas exists
   109  	PoolInfo []string `json:"poolInfo"`
   110  
   111  	// Capacity the actual resources of the underlying volume.
   112  	Capacity corev1.ResourceList `json:"capacity,omitempty"`
   113  
   114  	Conditions []CStorVolumeConfigCondition `json:"condition,omitempty"`
   115  }
   116  
   117  // CStorVolumeConfigCondition contains details about state of cstor volume
   118  type CStorVolumeConfigCondition struct {
   119  	// Current Condition of cstor volume claim. If underlying persistent volume is being
   120  	// resized then the Condition will be set to 'ResizeStarted' etc
   121  	Type CStorVolumeConfigConditionType `json:"type"`
   122  	// Last time we probed the condition.
   123  	// +optional
   124  	LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"`
   125  	// Last time the condition transitioned from one status to another.
   126  	// +optional
   127  	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
   128  	// Reason is a brief CamelCase string that describes any failure
   129  	Reason string `json:"reason"`
   130  	// Human-readable message indicating details about last transition.
   131  	Message string `json:"message"`
   132  }
   133  
   134  // CStorVolumeConfigConditionType is a valid value of CstorVolumeConfigCondition.Type
   135  type CStorVolumeConfigConditionType string
   136  
   137  // These constants are CVC condition types related to resize operation.
   138  const (
   139  	// CStorVolumeConfigResizePending ...
   140  	CStorVolumeConfigResizing CStorVolumeConfigConditionType = "Resizing"
   141  	// CStorVolumeConfigResizeFailed ...
   142  	CStorVolumeConfigResizeFailed CStorVolumeConfigConditionType = "VolumeResizeFailed"
   143  	// CStorVolumeConfigResizeSuccess ...
   144  	CStorVolumeConfigResizeSuccess CStorVolumeConfigConditionType = "VolumeResizeSuccessful"
   145  	// CStorVolumeConfigResizePending ...
   146  	CStorVolumeConfigResizePending CStorVolumeConfigConditionType = "VolumeResizePending"
   147  )
   148  
   149  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   150  // +k8s:openapi-gen=true
   151  
   152  // CStorVolumeConfigList is a list of CStorVolumeConfig resources
   153  type CStorVolumeConfigList struct {
   154  	metav1.TypeMeta `json:",inline"`
   155  	metav1.ListMeta `json:"metadata"`
   156  
   157  	Items []CStorVolumeConfig `json:"items"`
   158  }