github.com/kyma-project/kyma-environment-broker@v0.0.1/common/orchestration/dto.go (about) 1 package orchestration 2 3 import ( 4 "bytes" 5 "fmt" 6 "strconv" 7 "time" 8 9 "github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema" 10 ) 11 12 // Parameters hold the attributes of orchestration create (upgrade) requests. 13 type Parameters struct { 14 Targets TargetSpec `json:"targets"` 15 Strategy StrategySpec `json:"strategy,omitempty"` 16 DryRun bool `json:"dryRun,omitempty"` 17 Kubernetes *KubernetesParameters `json:"kubernetes,omitempty"` 18 // upgrade kyma specific parameters 19 Kyma *KymaParameters `json:"kyma,omitempty"` 20 RetryOperation RetryOperationParameters `json:"retryoperation,omitempty"` 21 // customer notification 22 Notification bool `json:"notification,omitempty"` 23 } 24 25 type RetryOperationParameters struct { 26 RetryOperations []string `json:"retryoperations,omitempty"` 27 Immediate stringBoolean `json:"immediate,omitempty"` 28 } 29 30 type KubernetesParameters struct { 31 KubernetesVersion string `json:"kubernetesVersion"` 32 MachineImage string `json:"machineImage"` 33 MachineImageVersion string `json:"machineImageVersion"` 34 } 35 36 // KymaParameters hold the attributes of kyma upgrade specific orchestration create requests. 37 type KymaParameters struct { 38 Version string `json:"version,omitempty"` 39 } 40 41 const ( 42 // StateParam parameter used in list orchestrations / operations queries to filter by state 43 StateParam = "state" 44 ) 45 46 // Orchestration states 47 const ( 48 Pending = "pending" 49 InProgress = "in progress" 50 Canceling = "canceling" 51 Retrying = "retrying" // to signal a retry sign before marking it to pending 52 Canceled = "canceled" 53 Succeeded = "succeeded" 54 Failed = "failed" 55 ) 56 57 // ListParameters hold attributes of list orchestrations / operations queries. 58 type ListParameters struct { 59 Page int 60 PageSize int 61 States []string 62 } 63 64 // TargetAll all SKRs provisioned successfully and not deprovisioning 65 const TargetAll = "all" 66 67 // RuntimeTarget captures a specification of SKR targets to resolve for an orchestration. 68 // When a RuntimeTarget defines multiple fields, all should match to any given runtime to be selected (i.e. the terms are AND-ed). 69 type RuntimeTarget struct { 70 // Valid values: "all" 71 Target string `json:"target,omitempty"` 72 // Regex pattern to match against the runtime's GlobalAccount field. E.g. CA50125541TID000000000741207136, CA.* 73 GlobalAccount string `json:"globalAccount,omitempty"` 74 // Regex pattern to match against the runtime's SubAccount field. E.g. 0d20e315-d0b4-48a2-9512-49bc8eb03cd1 75 SubAccount string `json:"subAccount,omitempty"` 76 // Regex pattern to match against the shoot cluster's Region field (not SCP platform-region). E.g. "europe|eu-" 77 Region string `json:"region,omitempty"` 78 // RuntimeID is used to indicate a specific runtime 79 RuntimeID string `json:"runtimeID,omitempty"` 80 // PlanName is used to match runtimes with the same plan 81 PlanName string `json:"planName,omitempty"` 82 // Shoot is used to indicate a sepcific runtime by shoot name 83 Shoot string `json:"shoot,omitempty"` 84 // InstanceID is used to identify an instance by it's instance ID 85 InstanceID string `json:"instanceID,omitempty"` 86 } 87 88 type Type string 89 90 const ( 91 UpgradeKymaOrchestration Type = "upgradeKyma" 92 UpgradeClusterOrchestration Type = "upgradeCluster" 93 ) 94 95 type StrategyType string 96 97 const ( 98 ParallelStrategy StrategyType = "parallel" 99 ) 100 101 type ScheduleType string 102 103 const ( 104 Immediate ScheduleType = "immediate" 105 Now ScheduleType = "now" 106 MaintenanceWindow ScheduleType = "maintenanceWindow" 107 ) 108 109 // ParallelStrategySpec defines parameters for the parallel orchestration strategy 110 type ParallelStrategySpec struct { 111 Workers int `json:"workers"` 112 } 113 114 // StrategySpec is the strategy part common for all orchestration trigger/status API 115 type StrategySpec struct { 116 Type StrategyType `json:"type"` 117 Schedule string `json:"schedule,omitempty"` 118 ScheduleTime time.Time 119 MaintenanceWindow bool `json:"maintenanceWindow,omitempty"` 120 Parallel ParallelStrategySpec `json:"parallel,omitempty"` 121 } 122 123 // TargetSpec is the targets part common for all orchestration trigger/status API 124 type TargetSpec struct { 125 Include []RuntimeTarget `json:"include"` 126 Exclude []RuntimeTarget `json:"exclude,omitempty"` 127 } 128 129 type StatusResponse struct { 130 OrchestrationID string `json:"orchestrationID"` 131 Type Type `json:"type"` 132 State string `json:"state"` 133 Description string `json:"description"` 134 CreatedAt time.Time `json:"createdAt"` 135 UpdatedAt time.Time `json:"updatedAt"` 136 Parameters Parameters `json:"parameters"` 137 OperationStats map[string]int `json:"operationStats,omitempty"` 138 } 139 140 type OperationResponse struct { 141 OperationID string `json:"operationID"` 142 RuntimeID string `json:"runtimeID"` 143 GlobalAccountID string `json:"globalAccountID"` 144 SubAccountID string `json:"subAccountID"` 145 OrchestrationID string `json:"orchestrationID"` 146 ServicePlanID string `json:"servicePlanID"` 147 ServicePlanName string `json:"servicePlanName"` 148 DryRun bool `json:"dryRun"` 149 ShootName string `json:"shootName"` 150 MaintenanceWindowBegin time.Time `json:"maintenanceWindowBegin"` 151 MaintenanceWindowEnd time.Time `json:"maintenanceWindowEnd"` 152 State string `json:"state"` 153 Description string `json:"description"` 154 } 155 156 type OperationResponseList struct { 157 Data []OperationResponse `json:"data"` 158 Count int `json:"count"` 159 TotalCount int `json:"totalCount"` 160 } 161 162 type OperationDetailResponse struct { 163 OperationResponse 164 165 KymaConfig *gqlschema.KymaConfigInput `json:"kymaConfig,omitempty"` 166 ClusterConfig *gqlschema.GardenerConfigInput `json:"clusterConfig,omitempty"` 167 } 168 169 type StatusResponseList struct { 170 Data []StatusResponse `json:"data"` 171 Count int `json:"count"` 172 TotalCount int `json:"totalCount"` 173 } 174 175 type UpgradeResponse struct { 176 OrchestrationID string `json:"orchestrationID"` 177 } 178 179 type RetryResponse struct { 180 OrchestrationID string `json:"orchestrationID"` 181 RetryShoots []string `json:"retryShoots"` 182 OldOperations []string `json:"oldOperations"` 183 InvalidOperations []string `json:"invalidOperations"` 184 Msg string `json:"msg"` 185 } 186 187 type MaintenancePolicyMatch struct { 188 GlobalAccountID string `json:"globalAccountID"` 189 Plan string `json:"plan"` 190 Region string `json:"region"` 191 } 192 193 type MaintenancePolicyEntry struct { 194 Days []string `json:"days"` 195 TimeBegin string `json:"timeBegin"` 196 TimeEnd string `json:"timeEnd"` 197 } 198 199 type MaintenancePolicyRule struct { 200 Match MaintenancePolicyMatch `json:"match"` 201 MaintenancePolicyEntry `json:""` 202 } 203 204 type MaintenancePolicy struct { 205 Rules []MaintenancePolicyRule `json:"rules"` 206 Default MaintenancePolicyEntry `json:"default"` 207 } 208 209 type stringBoolean bool 210 211 func (sb *stringBoolean) UnmarshalJSON(data []byte) error { 212 unqotedBool := bytes.Trim(data, `"`) 213 v, err := strconv.ParseBool(string(unqotedBool)) 214 if err != nil { 215 return fmt.Errorf("while unmarshaling stringBoolean: %w", err) 216 } 217 *sb = stringBoolean(v) 218 return nil 219 }