| 365 | } |
| 366 | |
| 367 | func (_ *migrationsComponent) findSpecFor(ctx *cu.Context, obj *unstructured.Unstructured) map[string]interface{} { |
| 368 | gvk := obj.GetObjectKind().GroupVersionKind() |
| 369 | switch fmt.Sprintf("%s/%s", gvk.Group, gvk.Kind) { |
| 370 | case "/Pod": |
| 371 | return obj.UnstructuredContent()["spec"].(map[string]interface{}) |
| 372 | case "apps/Deployment": |
| 373 | spec := obj.UnstructuredContent()["spec"].(map[string]interface{}) |
| 374 | template := spec["template"].(map[string]interface{}) |
| 375 | return template["spec"].(map[string]interface{}) |
| 376 | case "argoproj.io/Rollout": |
| 377 | spec := obj.UnstructuredContent()["spec"].(map[string]interface{}) |
| 378 | if spec["workloadRef"] != nil { |
| 379 | workloadRef := spec["workloadRef"].(map[string]interface{}) |
| 380 | workloadKind := workloadRef["kind"].(string) |
| 381 | if workloadKind == "Deployment" { |
| 382 | deployment := &unstructured.Unstructured{} |
| 383 | deployment.SetAPIVersion(workloadRef["apiVersion"].(string)) |
| 384 | deployment.SetKind(workloadKind) |
| 385 | err := ctx.Client.Get(ctx, types.NamespacedName{Name: workloadRef["name"].(string), Namespace: obj.GetNamespace()}, deployment) |
| 386 | if err != nil { |
| 387 | return nil |
| 388 | } |
| 389 | deploymentSpec := deployment.UnstructuredContent()["spec"].(map[string]interface{}) |
| 390 | deploymentTemplate := deploymentSpec["template"].(map[string]interface{}) |
| 391 | return deploymentTemplate["spec"].(map[string]interface{}) |
| 392 | } else { |
| 393 | // TODO handle other WorkloadRef types |
| 394 | return nil |
| 395 | } |
| 396 | } |
| 397 | template := spec["template"].(map[string]interface{}) |
| 398 | return template["spec"].(map[string]interface{}) |
| 399 | default: |
| 400 | return nil |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | func (comp *migrationsComponent) findOwnerSpec(ctx *cu.Context, obj *unstructured.Unstructured) (map[string]interface{}, error) { |
| 405 | owners, err := comp.findOwners(ctx, obj) |