github.com/openebs/api@v1.12.0/pkg/internalapis/apis/cstor/cstorpoolinstance.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  	"k8s.io/apimachinery/pkg/api/resource"
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  )
    24  
    25  // +genclient
    26  // +genclient:noStatus
    27  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    28  // +k8s:openapi-gen=true
    29  // +resource:path=cstorpoolinstance
    30  
    31  // CStorPoolInstance describes a cstor pool instance resource.
    32  type CStorPoolInstance struct {
    33  	metav1.TypeMeta   `json:",inline"`
    34  	metav1.ObjectMeta `json:"metadata,omitempty"`
    35  	// Spec is the specification of the cstorpoolinstance resource.
    36  	Spec CStorPoolInstanceSpec `json:"spec"`
    37  	// Status is the possible statuses of the cstorpoolinstance resource.
    38  	Status CStorPoolInstanceStatus `json:"status"`
    39  	// VersionDetails is the openebs version.
    40  	VersionDetails VersionDetails `json:"versionDetails"`
    41  }
    42  
    43  // CStorPoolInstanceSpec is the spec listing fields for a CStorPoolInstance resource.
    44  type CStorPoolInstanceSpec struct {
    45  	// HostName is the name of kubernetes node where the pool
    46  	// should be created.
    47  	HostName string `json:"hostName"`
    48  	// NodeSelector is the labels that will be used to select
    49  	// a node for pool provisioning.
    50  	// Required field
    51  	NodeSelector map[string]string `json:"nodeSelector"`
    52  	// PoolConfig is the default pool config that applies to the
    53  	// pool on node.
    54  	PoolConfig PoolConfig `json:"poolConfig"`
    55  	// DataRaidGroups is the raid group configuration for the given pool.
    56  	DataRaidGroups []RaidGroup `json:"dataRaidGroups"`
    57  	// WriteCacheRaidGroups is the write cache raid group.
    58  	WriteCacheRaidGroups []RaidGroup `json:"writeCacheRaidGroups"`
    59  }
    60  
    61  // CStorPoolInstancePhase is the phase for CStorPoolInstance resource.
    62  type CStorPoolInstancePhase string
    63  
    64  // Status written onto CStorPool and CStorVolumeReplica objects.
    65  // Resetting state to either Init or CreateFailed need to be done with care,
    66  // as, label clear and pool creation depends on this state.
    67  const (
    68  	// CStorPoolStatusEmpty ensures the create operation is to be done, if import fails.
    69  	CStorPoolStatusEmpty CStorPoolInstancePhase = ""
    70  	// CStorPoolStatusOnline signifies that the pool is online.
    71  	CStorPoolStatusOnline CStorPoolInstancePhase = "ONLINE"
    72  	// CStorPoolStatusOffline signifies that the pool is offline.
    73  	CStorPoolStatusOffline CStorPoolInstancePhase = "OFFLINE"
    74  	// CStorPoolStatusDegraded signifies that the pool is degraded.
    75  	CStorPoolStatusDegraded CStorPoolInstancePhase = "DEGRADED"
    76  	// CStorPoolStatusFaulted signifies that the pool is faulted.
    77  	CStorPoolStatusFaulted CStorPoolInstancePhase = "FAULTED"
    78  	// CStorPoolStatusRemoved signifies that the pool is removed.
    79  	CStorPoolStatusRemoved CStorPoolInstancePhase = "REMOVED"
    80  	// CStorPoolStatusUnavail signifies that the pool is not available.
    81  	CStorPoolStatusUnavail CStorPoolInstancePhase = "UNAVAIL"
    82  	// CStorPoolStatusError signifies that the pool status could not be fetched.
    83  	CStorPoolStatusError CStorPoolInstancePhase = "Error"
    84  	// CStorPoolStatusDeletionFailed ensures the resource deletion has failed.
    85  	CStorPoolStatusDeletionFailed CStorPoolInstancePhase = "DeletionFailed"
    86  	// CStorPoolStatusInvalid ensures invalid resource.
    87  	CStorPoolStatusInvalid CStorPoolInstancePhase = "Invalid"
    88  	// CStorPoolStatusErrorDuplicate ensures error due to duplicate resource.
    89  	CStorPoolStatusErrorDuplicate CStorPoolInstancePhase = "ErrorDuplicate"
    90  	// CStorPoolStatusPending ensures pending task for cstorpool.
    91  	CStorPoolStatusPending CStorPoolInstancePhase = "Pending"
    92  	// CStorPoolStatusInit is initial state of CSP, before pool creation.
    93  	CStorPoolStatusInit CStorPoolInstancePhase = "Init"
    94  	// CStorPoolStatusCreateFailed is state when pool creation failed
    95  	CStorPoolStatusCreateFailed CStorPoolInstancePhase = "PoolCreationFailed"
    96  )
    97  
    98  // CStorPoolInstanceStatus is for handling status of pool.
    99  type CStorPoolInstanceStatus struct {
   100  	// Current state of CSPI with details.
   101  	Conditions []CStorPoolInstanceCondition `json:"conditions,omitempty"`
   102  	//  The phase of a CStorPool is a simple, high-level summary of the pool state on the
   103  	//  node.
   104  	Phase CStorPoolInstancePhase `json:"phase"`
   105  	// Capacity describes the capacity details of a cstor pool
   106  	Capacity CStorPoolInstanceCapacity `json:"capacity"`
   107  	//ReadOnly if pool is readOnly or not
   108  	ReadOnly bool `json:"readOnly"`
   109  	// ProvisionedReplicas describes the total count of Volume Replicas
   110  	// present in the cstor pool
   111  	ProvisionedReplicas int32 `json:"provisionedReplicas"`
   112  	// HealthyReplicas describes the total count of healthy Volume Replicas
   113  	// in the cstor pool
   114  	HealthyReplicas int32 `json:"healthyReplicas"`
   115  }
   116  
   117  // CStorPoolInstanceCapacity stores the pool capacity related attributes.
   118  type CStorPoolInstanceCapacity struct {
   119  	// Amount of physical data (and its metadata) written to pool
   120  	// after applying compression, etc..,
   121  	Used resource.Quantity `json:"used"`
   122  	// Amount of usable space in the pool after excluding
   123  	// the storage used for metadata and raid parity
   124  	Free resource.Quantity `json:"free"`
   125  	// Sum of usable capacity in all the data raidgroups
   126  	Total resource.Quantity `json:"total"`
   127  	// ZFSCapacityAttributes contains advanced information about pool capacity details
   128  	ZFS ZFSCapacityAttributes `json:"zfs"`
   129  }
   130  
   131  // ZFSCapacityAttributes stores the advanced information about pool capacity related
   132  // attributes
   133  type ZFSCapacityAttributes struct {
   134  	// LogicalUsed is the amount of space that is "logically" consumed
   135  	// by this pool and all its descendents. The logical space ignores
   136  	// the effect of the compression and copies properties, giving a
   137  	// quantity closer to the amount of data that applications see.
   138  	// However, it does include space consumed by metadata.
   139  	// NOTE: Used and LogicalUsed can vary depends on the pool properties
   140  	LogicalUsed resource.Quantity `json:"logicalUsed"`
   141  }
   142  
   143  type CStorPoolInstanceConditionType string
   144  
   145  const (
   146  	// CSPIPoolExpansion condition will be available when user triggers
   147  	// pool expansion by adding blockdevice/raidgroup (or) when underlying
   148  	// disk got expanded
   149  	CSPIPoolExpansion CStorPoolInstanceConditionType = "PoolExpansion"
   150  	// CSPIDiskReplacement condition will be available when user triggers
   151  	// disk replacement by replacing the blockdevice
   152  	CSPIDiskReplacement CStorPoolInstanceConditionType = "DiskReplacement"
   153  	// CSPIDiskUnavailable condition will be available when one (or) more
   154  	// disks were unavailable
   155  	CSPIDiskUnavailable CStorPoolInstanceConditionType = "DiskUnavailable"
   156  	// CSPIPoolLost condition will be available when unable to import the pool
   157  	CSPIPoolLost CStorPoolInstanceConditionType = "PoolLost"
   158  )
   159  
   160  // CSPIConditionType describes the state of a CSPI at a certain point.
   161  type CStorPoolInstanceCondition struct {
   162  	// Type of CSPC condition.
   163  	Type CSPCConditionType `json:"type"`
   164  	// Status of the condition, one of True, False, Unknown.
   165  	Status corev1.ConditionStatus `json:"status"`
   166  	// The last time this condition was updated.
   167  	LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
   168  	// Last time the condition transitioned from one status to another.
   169  	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
   170  	// The reason for the condition's last transition.
   171  	Reason string `json:"reason,omitempty"`
   172  	// A human readable message indicating details about the transition.
   173  	Message string `json:"message,omitempty"`
   174  }
   175  
   176  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   177  // +resource:path=cstorpoolinstance
   178  
   179  // CStorPoolInstanceList is a list of CStorPoolInstance resources
   180  type CStorPoolInstanceList struct {
   181  	metav1.TypeMeta `json:",inline"`
   182  	metav1.ListMeta `json:"metadata"`
   183  	Items           []CStorPoolInstance `json:"items"`
   184  }