github.com/kyma-project/kyma-environment-broker@v0.0.1/common/runtime/model.go (about) 1 package runtime 2 3 import ( 4 "time" 5 6 "github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema" 7 ) 8 9 type State string 10 11 const ( 12 // StateSucceeded means that the last operation of the runtime has succeeded. 13 StateSucceeded State = "succeeded" 14 // StateFailed means that the last operation is one of provision, deprovivion, suspension, unsuspension, which has failed. 15 StateFailed State = "failed" 16 // StateError means the runtime is in a recoverable error state, due to the last upgrade/update operation has failed. 17 StateError State = "error" 18 // StateProvisioning means that the runtime provisioning (or unsuspension) is in progress (by the last runtime operation). 19 StateProvisioning State = "provisioning" 20 // StateDeprovisioning means that the runtime deprovisioning (or suspension) is in progress (by the last runtime operation). 21 StateDeprovisioning State = "deprovisioning" 22 // StateDeprovisioned means that the runtime deprovisioning has finished removing the instance. 23 // In case the instance has already been deleted, KEB will try best effort to reconstruct at least partial information regarding deprovisioned instances from residual operations. 24 StateDeprovisioned State = "deprovisioned" 25 // StateDeprovisionIncomplete means that the runtime deprovisioning has finished removing the instance but certain steps have not finished and the instance should be requeued for repeated deprovisioning. 26 StateDeprovisionIncomplete State = "deprovisionincomplete" 27 // StateUpgrading means that kyma upgrade or cluster upgrade operation is in progress. 28 StateUpgrading State = "upgrading" 29 // StateUpdating means the runtime configuration is being updated (i.e. OIDC is reconfigured). 30 StateUpdating State = "updating" 31 // StateSuspended means that the trial runtime is suspended (i.e. deprovisioned). 32 StateSuspended State = "suspended" 33 // AllState is a virtual state only used as query parameter in ListParameters to indicate "include all runtimes, which are excluded by default without state filters". 34 AllState State = "all" 35 ) 36 37 type RuntimeDTO struct { 38 InstanceID string `json:"instanceID"` 39 RuntimeID string `json:"runtimeID"` 40 GlobalAccountID string `json:"globalAccountID"` 41 SubscriptionGlobalAccountID string `json:"subscriptionGlobalAccountID"` 42 SubAccountID string `json:"subAccountID"` 43 ProviderRegion string `json:"region"` 44 SubAccountRegion string `json:"subAccountRegion"` 45 ShootName string `json:"shootName"` 46 ServiceClassID string `json:"serviceClassID"` 47 ServiceClassName string `json:"serviceClassName"` 48 ServicePlanID string `json:"servicePlanID"` 49 ServicePlanName string `json:"servicePlanName"` 50 Provider string `json:"provider"` 51 Status RuntimeStatus `json:"status"` 52 UserID string `json:"userID"` 53 AVSInternalEvaluationID int64 `json:"avsInternalEvaluationID"` 54 KymaVersion string `json:"kymaVersion,omitempty"` 55 KymaConfig *gqlschema.KymaConfigInput `json:"kymaConfig,omitempty"` 56 ClusterConfig *gqlschema.GardenerConfigInput `json:"clusterConfig,omitempty"` 57 } 58 59 type RuntimeStatus struct { 60 CreatedAt time.Time `json:"createdAt"` 61 ModifiedAt time.Time `json:"modifiedAt"` 62 ExpiredAt *time.Time `json:"expiredAt,omitempty"` 63 DeletedAt *time.Time `json:"deletedAt,omitempty"` 64 State State `json:"state"` 65 Provisioning *Operation `json:"provisioning,omitempty"` 66 Deprovisioning *Operation `json:"deprovisioning,omitempty"` 67 UpgradingKyma *OperationsData `json:"upgradingKyma,omitempty"` 68 UpgradingCluster *OperationsData `json:"upgradingCluster,omitempty"` 69 Update *OperationsData `json:"update,omitempty"` 70 Suspension *OperationsData `json:"suspension,omitempty"` 71 Unsuspension *OperationsData `json:"unsuspension,omitempty"` 72 } 73 74 type OperationType string 75 76 const ( 77 Provision OperationType = "provision" 78 Deprovision OperationType = "deprovision" 79 UpgradeKyma OperationType = "kyma upgrade" 80 UpgradeCluster OperationType = "cluster upgrade" 81 Update OperationType = "update" 82 Suspension OperationType = "suspension" 83 Unsuspension OperationType = "unsuspension" 84 ) 85 86 type OperationsData struct { 87 Data []Operation `json:"data"` 88 TotalCount int `json:"totalCount"` 89 Count int `json:"count"` 90 } 91 92 type Operation struct { 93 State string `json:"state"` 94 Type OperationType `json:"type,omitempty"` 95 Description string `json:"description"` 96 CreatedAt time.Time `json:"createdAt"` 97 UpdatedAt time.Time `json:"updatedAt"` 98 OperationID string `json:"operationID"` 99 OrchestrationID string `json:"orchestrationID,omitempty"` 100 FinishedStages []string `json:"finishedStages"` 101 ExecutedButNotCompletedSteps []string `json:"executedButNotCompletedSteps,omitempty"` 102 RuntimeVersion string `json:"runtimeVersion"` 103 } 104 105 type RuntimesPage struct { 106 Data []RuntimeDTO `json:"data"` 107 Count int `json:"count"` 108 TotalCount int `json:"totalCount"` 109 } 110 111 const ( 112 GlobalAccountIDParam = "account" 113 SubAccountIDParam = "subaccount" 114 InstanceIDParam = "instance_id" 115 RuntimeIDParam = "runtime_id" 116 RegionParam = "region" 117 ShootParam = "shoot" 118 PlanParam = "plan" 119 StateParam = "state" 120 OperationDetailParam = "op_detail" 121 KymaConfigParam = "kyma_config" 122 ClusterConfigParam = "cluster_config" 123 ExpiredParam = "expired" 124 ) 125 126 type OperationDetail string 127 128 const ( 129 LastOperation OperationDetail = "last" 130 AllOperation OperationDetail = "all" 131 ) 132 133 type ListParameters struct { 134 // Page specifies the offset for the runtime results in the total count of matching runtimes 135 Page int 136 // PageSize specifies the count of matching runtimes returned in a response 137 PageSize int 138 // OperationDetail specifies whether the server should respond with all operations, or only the last operation. If not set, the server by default sends all operations 139 OperationDetail OperationDetail 140 // KymaConfig specifies whether kyma configuration details should be included in the response for each runtime 141 KymaConfig bool 142 // ClusterConfig specifies whether Gardener cluster configuration details should be included in the response for each runtime 143 ClusterConfig bool 144 // GlobalAccountIDs parameter filters runtimes by specified global account IDs 145 GlobalAccountIDs []string 146 // SubAccountIDs parameter filters runtimes by specified subaccount IDs 147 SubAccountIDs []string 148 // InstanceIDs parameter filters runtimes by specified instance IDs 149 InstanceIDs []string 150 // RuntimeIDs parameter filters runtimes by specified instance IDs 151 RuntimeIDs []string 152 // Regions parameter filters runtimes by specified provider regions 153 Regions []string 154 // Shoots parameter filters runtimes by specified shoot cluster names 155 Shoots []string 156 // Plans parameter filters runtimes by specified service plans 157 Plans []string 158 // States parameter filters runtimes by specified runtime states. See type State for possible values 159 States []State 160 // Expired parameter filters runtimes to show only expired ones. 161 Expired bool 162 // Events parameter fetches tracing events per instance 163 Events string 164 } 165 166 func (rt RuntimeDTO) LastOperation() Operation { 167 op := Operation{} 168 169 if rt.Status.Provisioning != nil { 170 op = *rt.Status.Provisioning 171 op.Type = Provision 172 } 173 // Take the first cluster upgrade operation, assuming that Data is sorted by CreatedAt DESC. 174 if rt.Status.UpgradingCluster != nil && rt.Status.UpgradingCluster.Count > 0 { 175 op = rt.Status.UpgradingCluster.Data[0] 176 op.Type = UpgradeCluster 177 } 178 // Take the first upgrade operation, assuming that Data is sorted by CreatedAt DESC. 179 if rt.Status.UpgradingKyma != nil && rt.Status.UpgradingKyma.Count > 0 && rt.Status.UpgradingKyma.Data[0].CreatedAt.After(op.CreatedAt) { 180 op = rt.Status.UpgradingKyma.Data[0] 181 op.Type = UpgradeKyma 182 } 183 184 // Take the first unsuspension operation, assuming that Data is sorted by CreatedAt DESC. 185 if rt.Status.Unsuspension != nil && rt.Status.Unsuspension.Count > 0 && rt.Status.Unsuspension.Data[0].CreatedAt.After(op.CreatedAt) { 186 op = rt.Status.Unsuspension.Data[0] 187 op.Type = Unsuspension 188 } 189 190 // Take the first suspension operation, assuming that Data is sorted by CreatedAt DESC. 191 if rt.Status.Suspension != nil && rt.Status.Suspension.Count > 0 && rt.Status.Suspension.Data[0].CreatedAt.After(op.CreatedAt) { 192 op = rt.Status.Suspension.Data[0] 193 op.Type = Suspension 194 } 195 196 if rt.Status.Deprovisioning != nil && rt.Status.Deprovisioning.CreatedAt.After(op.CreatedAt) { 197 op = *rt.Status.Deprovisioning 198 op.Type = Deprovision 199 } 200 201 // Take the first update operation, assuming that Data is sorted by CreatedAt DESC. 202 if rt.Status.Update != nil && rt.Status.Update.Count > 0 && rt.Status.Update.Data[0].CreatedAt.After(op.CreatedAt) { 203 op = rt.Status.Update.Data[0] 204 op.Type = Update 205 } 206 207 return op 208 }