github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/fixture/fixture.go (about) 1 package fixture 2 3 import ( 4 "fmt" 5 "time" 6 7 reconcilerApi "github.com/kyma-incubator/reconciler/pkg/keb" 8 "github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema" 9 "github.com/kyma-project/kyma-environment-broker/common/gardener" 10 "github.com/kyma-project/kyma-environment-broker/common/orchestration" 11 "github.com/kyma-project/kyma-environment-broker/internal" 12 "github.com/kyma-project/kyma-environment-broker/internal/ptr" 13 "github.com/pivotal-cf/brokerapi/v8/domain" 14 ) 15 16 const ( 17 ServiceId = "47c9dcbf-ff30-448e-ab36-d3bad66ba281" 18 ServiceName = "kymaruntime" 19 PlanId = "4deee563-e5ec-4731-b9b1-53b42d855f0c" 20 TrialPlan = "7d55d31d-35ae-4438-bf13-6ffdfa107d9f" 21 PlanName = "azure" 22 GlobalAccountId = "e8f7ec0a-0cd6-41f0-905d-5d1efa9fb6c4" 23 SubscriptionGlobalAccountID = "" 24 Region = "westeurope" 25 ServiceManagerUsername = "u" 26 ServiceManagerPassword = "p" 27 ServiceManagerURL = "https://service-manager.local" 28 InstanceDashboardURL = "https://dashboard.local" 29 XSUAADataXSAppName = "XSApp" 30 KymaVersion = "1.19.0" 31 MonitoringUsername = "username" 32 MonitoringPassword = "password" 33 ) 34 35 type SimpleInputCreator struct { 36 Overrides map[string][]*gqlschema.ConfigEntryInput 37 Labels map[string]string 38 EnabledComponents []string 39 ShootName *string 40 ShootDomain string 41 shootDnsProviders gardener.DNSProvidersData 42 CloudProvider internal.CloudProvider 43 RuntimeID string 44 Config *internal.ConfigForPlan 45 } 46 47 func FixServiceManagerEntryDTO() *internal.ServiceManagerEntryDTO { 48 return &internal.ServiceManagerEntryDTO{ 49 Credentials: internal.ServiceManagerCredentials{ 50 BasicAuth: internal.ServiceManagerBasicAuth{ 51 Username: ServiceManagerUsername, 52 Password: ServiceManagerPassword, 53 }, 54 }, 55 URL: ServiceManagerURL, 56 } 57 } 58 59 func FixERSContext(id string) internal.ERSContext { 60 var ( 61 tenantID = fmt.Sprintf("Tenant-%s", id) 62 subAccountId = fmt.Sprintf("SA-%s", id) 63 userID = fmt.Sprintf("User-%s", id) 64 licenseType = "" 65 ) 66 67 return internal.ERSContext{ 68 TenantID: tenantID, 69 SubAccountID: subAccountId, 70 GlobalAccountID: GlobalAccountId, 71 Active: ptr.Bool(true), 72 UserID: userID, 73 LicenseType: &licenseType, 74 } 75 } 76 77 func FixProvisioningParametersDTO() internal.ProvisioningParametersDTO { 78 trialCloudProvider := internal.Azure 79 80 return internal.ProvisioningParametersDTO{ 81 Name: "cluster-test", 82 VolumeSizeGb: ptr.Integer(50), 83 MachineType: ptr.String("Standard_D8_v3"), 84 Region: ptr.String(Region), 85 Purpose: ptr.String("Purpose"), 86 LicenceType: ptr.String("LicenceType"), 87 Zones: []string{"1"}, 88 AutoScalerParameters: internal.AutoScalerParameters{ 89 AutoScalerMin: ptr.Integer(3), 90 AutoScalerMax: ptr.Integer(10), 91 MaxSurge: ptr.Integer(4), 92 MaxUnavailable: ptr.Integer(1), 93 }, 94 KymaVersion: KymaVersion, 95 Provider: &trialCloudProvider, 96 } 97 } 98 99 func FixProvisioningParameters(id string) internal.ProvisioningParameters { 100 return internal.ProvisioningParameters{ 101 PlanID: PlanId, 102 ServiceID: ServiceId, 103 ErsContext: FixERSContext(id), 104 Parameters: FixProvisioningParametersDTO(), 105 PlatformRegion: Region, 106 } 107 } 108 109 func FixInstanceDetails(id string) internal.InstanceDetails { 110 var ( 111 runtimeId = fmt.Sprintf("runtime-%s", id) 112 subAccountId = fmt.Sprintf("SA-%s", id) 113 shootName = fmt.Sprintf("Shoot-%s", id) 114 shootDomain = fmt.Sprintf("shoot-%s.domain.com", id) 115 ) 116 117 monitoringData := internal.MonitoringData{ 118 Username: MonitoringUsername, 119 Password: MonitoringPassword, 120 } 121 122 return internal.InstanceDetails{ 123 Avs: internal.AvsLifecycleData{}, 124 EventHub: internal.EventHub{Deleted: false}, 125 SubAccountID: subAccountId, 126 RuntimeID: runtimeId, 127 ShootName: shootName, 128 ShootDomain: shootDomain, 129 ShootDNSProviders: FixDNSProvidersConfig(), 130 Monitoring: monitoringData, 131 KymaResourceNamespace: "kyma-system", 132 KymaResourceName: runtimeId, 133 } 134 } 135 136 func FixInstance(id string) internal.Instance { 137 var ( 138 runtimeId = fmt.Sprintf("runtime-%s", id) 139 subAccountId = fmt.Sprintf("SA-%s", id) 140 ) 141 142 return internal.Instance{ 143 InstanceID: id, 144 RuntimeID: runtimeId, 145 GlobalAccountID: GlobalAccountId, 146 SubscriptionGlobalAccountID: SubscriptionGlobalAccountID, 147 SubAccountID: subAccountId, 148 ServiceID: ServiceId, 149 ServiceName: ServiceName, 150 ServicePlanID: PlanId, 151 ServicePlanName: PlanName, 152 DashboardURL: InstanceDashboardURL, 153 Parameters: FixProvisioningParameters(id), 154 ProviderRegion: Region, 155 Provider: internal.Azure, 156 InstanceDetails: FixInstanceDetails(id), 157 CreatedAt: time.Now(), 158 UpdatedAt: time.Now().Add(time.Minute * 5), 159 Version: 0, 160 } 161 } 162 163 func FixOperation(id, instanceId string, opType internal.OperationType) internal.Operation { 164 var ( 165 description = fmt.Sprintf("Description for operation %s", id) 166 orchestrationId = fmt.Sprintf("Orchestration-%s", id) 167 ) 168 169 return internal.Operation{ 170 InstanceDetails: FixInstanceDetails(instanceId), 171 ID: id, 172 Type: opType, 173 Version: 0, 174 CreatedAt: time.Now(), 175 UpdatedAt: time.Now().Add(time.Hour * 48), 176 InstanceID: instanceId, 177 ProvisionerOperationID: "", 178 State: domain.Succeeded, 179 Description: description, 180 ProvisioningParameters: FixProvisioningParameters(id), 181 OrchestrationID: orchestrationId, 182 FinishedStages: []string{"prepare", "check_provisioning"}, 183 } 184 } 185 186 func FixInputCreator(provider internal.CloudProvider) *SimpleInputCreator { 187 return &SimpleInputCreator{ 188 Overrides: make(map[string][]*gqlschema.ConfigEntryInput, 0), 189 Labels: make(map[string]string), 190 EnabledComponents: []string{"istio-configuration"}, 191 ShootName: ptr.String("ShootName"), 192 CloudProvider: provider, 193 } 194 } 195 196 func FixProvisioningOperation(operationId, instanceId string) internal.Operation { 197 o := FixOperation(operationId, instanceId, internal.OperationTypeProvision) 198 o.RuntimeVersion = internal.RuntimeVersionData{ 199 Version: KymaVersion, 200 Origin: internal.Defaults, 201 } 202 o.InputCreator = FixInputCreator(internal.Azure) 203 o.DashboardURL = "https://console.kyma.org" 204 return o 205 } 206 207 func FixUpdatingOperation(operationId, instanceId string) internal.UpdatingOperation { 208 o := FixOperation(operationId, instanceId, internal.OperationTypeUpdate) 209 o.InputCreator = FixInputCreator(internal.Azure) 210 o.UpdatingParameters = internal.UpdatingParametersDTO{ 211 OIDC: &internal.OIDCConfigDTO{ 212 ClientID: "clinet-id-oidc", 213 GroupsClaim: "groups", 214 IssuerURL: "issuer-url", 215 SigningAlgs: []string{"signingAlgs"}, 216 UsernameClaim: "sub", 217 UsernamePrefix: "", 218 }, 219 } 220 return internal.UpdatingOperation{ 221 Operation: o, 222 } 223 } 224 225 func FixProvisioningOperationWithProvider(operationId, instanceId string, provider internal.CloudProvider) internal.Operation { 226 o := FixOperation(operationId, instanceId, internal.OperationTypeProvision) 227 o.RuntimeVersion = internal.RuntimeVersionData{ 228 Version: KymaVersion, 229 Origin: internal.Defaults, 230 } 231 o.InputCreator = FixInputCreator(provider) 232 o.DashboardURL = "https://console.kyma.org" 233 return o 234 } 235 236 func FixDeprovisioningOperation(operationId, instanceId string) internal.DeprovisioningOperation { 237 return internal.DeprovisioningOperation{ 238 Operation: FixDeprovisioningOperationAsOperation(operationId, instanceId), 239 } 240 } 241 242 func FixDeprovisioningOperationAsOperation(operationId, instanceId string) internal.Operation { 243 o := FixOperation(operationId, instanceId, internal.OperationTypeDeprovision) 244 o.Temporary = false 245 return o 246 } 247 248 func FixSuspensionOperationAsOperation(operationId, instanceId string) internal.Operation { 249 o := FixOperation(operationId, instanceId, internal.OperationTypeDeprovision) 250 o.Temporary = true 251 o.ProvisioningParameters.PlanID = TrialPlan 252 return o 253 } 254 255 func FixRuntime(id string) orchestration.Runtime { 256 var ( 257 instanceId = fmt.Sprintf("Instance-%s", id) 258 subAccountId = fmt.Sprintf("SA-%s", id) 259 ) 260 261 return orchestration.Runtime{ 262 InstanceID: instanceId, 263 RuntimeID: id, 264 GlobalAccountID: GlobalAccountId, 265 SubAccountID: subAccountId, 266 ShootName: "ShootName", 267 MaintenanceWindowBegin: time.Now().Truncate(time.Millisecond).Add(time.Hour), 268 MaintenanceWindowEnd: time.Now().Truncate(time.Millisecond).Add(time.Minute).Add(time.Hour), 269 } 270 } 271 272 func FixRuntimeOperation(operationId string) orchestration.RuntimeOperation { 273 return orchestration.RuntimeOperation{ 274 Runtime: FixRuntime(operationId), 275 ID: operationId, 276 DryRun: false, 277 } 278 } 279 280 func FixUpgradeKymaOperation(operationId, instanceId string) internal.UpgradeKymaOperation { 281 o := FixOperation(operationId, instanceId, internal.OperationTypeUpgradeKyma) 282 o.RuntimeID = operationId 283 o.RuntimeOperation = FixRuntimeOperation(operationId) 284 o.InputCreator = FixInputCreator(internal.Azure) 285 o.RuntimeVersion = internal.RuntimeVersionData{ 286 Version: KymaVersion, 287 Origin: internal.Defaults, 288 } 289 o.Type = internal.OperationTypeUpgradeKyma 290 return internal.UpgradeKymaOperation{ 291 Operation: o, 292 } 293 } 294 295 func FixUpgradeClusterOperation(operationId, instanceId string) internal.UpgradeClusterOperation { 296 o := FixOperation(operationId, instanceId, internal.OperationTypeUpgradeCluster) 297 o.RuntimeOperation = FixRuntimeOperation(operationId) 298 o.InputCreator = FixInputCreator(internal.Azure) 299 return internal.UpgradeClusterOperation{ 300 Operation: o, 301 } 302 } 303 304 func FixOrchestration(id string) internal.Orchestration { 305 return internal.Orchestration{ 306 OrchestrationID: id, 307 State: orchestration.Succeeded, 308 Description: "", 309 CreatedAt: time.Now(), 310 UpdatedAt: time.Now().Add(time.Hour * 1), 311 Parameters: orchestration.Parameters{}, 312 } 313 } 314 315 func FixOIDCConfigDTO() internal.OIDCConfigDTO { 316 return internal.OIDCConfigDTO{ 317 ClientID: "9bd05ed7-a930-44e6-8c79-e6defeb7dec9", 318 GroupsClaim: "groups", 319 IssuerURL: "https://kymatest.accounts400.ondemand.com", 320 SigningAlgs: []string{"RS256"}, 321 UsernameClaim: "sub", 322 UsernamePrefix: "-", 323 } 324 } 325 326 func FixDNSProvidersConfig() gardener.DNSProvidersData { 327 return gardener.DNSProvidersData{ 328 Providers: []gardener.DNSProviderData{ 329 { 330 DomainsInclude: []string{"devtest.kyma.ondemand.com"}, 331 Primary: true, 332 SecretName: "aws_dns_domain_secrets_test_incustom", 333 Type: "route53_type_test", 334 }, 335 }, 336 } 337 } 338 339 func FixRuntimeState(id, runtimeID, operationID string) internal.RuntimeState { 340 disabled := false 341 return internal.RuntimeState{ 342 ID: id, 343 CreatedAt: time.Now(), 344 RuntimeID: runtimeID, 345 OperationID: operationID, 346 KymaConfig: gqlschema.KymaConfigInput{}, 347 ClusterConfig: gqlschema.GardenerConfigInput{ 348 ShootNetworkingFilterDisabled: &disabled, 349 }, 350 ClusterSetup: nil, 351 } 352 } 353 354 func FixClusterSetup(runtimeID string) reconcilerApi.Cluster { 355 return reconcilerApi.Cluster{ 356 Kubeconfig: "sample-kubeconfig", 357 KymaConfig: reconcilerApi.KymaConfig{ 358 Administrators: nil, 359 Components: nil, 360 Profile: "", 361 Version: "2.0.0", 362 }, 363 Metadata: reconcilerApi.Metadata{}, 364 RuntimeID: runtimeID, 365 RuntimeInput: reconcilerApi.RuntimeInput{}, 366 } 367 } 368 369 // SimpleInputCreator implements ProvisionerInputCreator interface 370 func (c *SimpleInputCreator) SetProvisioningParameters(params internal.ProvisioningParameters) internal.ProvisionerInputCreator { 371 return c 372 } 373 374 func (c *SimpleInputCreator) SetShootName(name string) internal.ProvisionerInputCreator { 375 c.ShootName = &name 376 return c 377 } 378 379 func (c *SimpleInputCreator) SetShootDomain(name string) internal.ProvisionerInputCreator { 380 c.ShootDomain = name 381 return c 382 } 383 384 func (c *SimpleInputCreator) SetShootDNSProviders(providers gardener.DNSProvidersData) internal.ProvisionerInputCreator { 385 c.shootDnsProviders = providers 386 return c 387 } 388 389 func (c *SimpleInputCreator) SetLabel(key, val string) internal.ProvisionerInputCreator { 390 c.Labels[key] = val 391 return c 392 } 393 394 func (c *SimpleInputCreator) SetKubeconfig(_ string) internal.ProvisionerInputCreator { 395 return c 396 } 397 398 func (c *SimpleInputCreator) SetClusterName(_ string) internal.ProvisionerInputCreator { 399 return c 400 } 401 402 func (c *SimpleInputCreator) SetInstanceID(kcfg string) internal.ProvisionerInputCreator { 403 return c 404 } 405 406 func (c *SimpleInputCreator) SetRuntimeID(runtimeID string) internal.ProvisionerInputCreator { 407 c.RuntimeID = runtimeID 408 return c 409 } 410 411 func (c *SimpleInputCreator) SetOverrides(component string, overrides []*gqlschema.ConfigEntryInput) internal.ProvisionerInputCreator { 412 return c 413 } 414 415 func (c *SimpleInputCreator) SetOIDCLastValues(oidcConfig gqlschema.OIDCConfigInput) internal.ProvisionerInputCreator { 416 return c 417 } 418 419 func (c *SimpleInputCreator) AppendOverrides(component string, overrides []*gqlschema.ConfigEntryInput) internal.ProvisionerInputCreator { 420 c.Overrides[component] = append(c.Overrides[component], overrides...) 421 return c 422 } 423 424 func (c *SimpleInputCreator) AppendGlobalOverrides(overrides []*gqlschema.ConfigEntryInput) internal.ProvisionerInputCreator { 425 return c 426 } 427 428 func (c *SimpleInputCreator) CreateClusterConfiguration() (reconcilerApi.Cluster, error) { 429 return reconcilerApi.Cluster{ 430 RuntimeID: c.RuntimeID, 431 Kubeconfig: "sample-kubeconfig", 432 }, nil 433 } 434 435 func (c *SimpleInputCreator) CreateProvisionClusterInput() (gqlschema.ProvisionRuntimeInput, error) { 436 return gqlschema.ProvisionRuntimeInput{}, nil 437 } 438 439 func (c *SimpleInputCreator) CreateProvisionRuntimeInput() (gqlschema.ProvisionRuntimeInput, error) { 440 return gqlschema.ProvisionRuntimeInput{}, nil 441 } 442 443 func (c *SimpleInputCreator) CreateUpgradeRuntimeInput() (gqlschema.UpgradeRuntimeInput, error) { 444 return gqlschema.UpgradeRuntimeInput{}, nil 445 } 446 447 func (c *SimpleInputCreator) CreateUpgradeShootInput() (gqlschema.UpgradeShootInput, error) { 448 return gqlschema.UpgradeShootInput{}, nil 449 } 450 451 func (c *SimpleInputCreator) EnableOptionalComponent(name string) internal.ProvisionerInputCreator { 452 c.EnabledComponents = append(c.EnabledComponents, name) 453 return c 454 } 455 456 func (c *SimpleInputCreator) DisableOptionalComponent(name string) internal.ProvisionerInputCreator { 457 for i, cmp := range c.EnabledComponents { 458 if cmp == name { 459 c.EnabledComponents = append(c.EnabledComponents[:i], c.EnabledComponents[i+1:]...) 460 } 461 } 462 return c 463 } 464 465 func (c *SimpleInputCreator) Provider() internal.CloudProvider { 466 return c.CloudProvider 467 } 468 469 func (c *SimpleInputCreator) Configuration() *internal.ConfigForPlan { 470 return c.Config 471 }