(ctx context.Context, cli client.Reader, synthesizedComp *SynthesizedComponent, obj client.Object, objName, key string, optional *bool, resolve func(obj client.Object) (*corev1.EnvVar, *corev1.EnvVar))
| 405 | } |
| 406 | |
| 407 | func resolveNativeObjectKey(ctx context.Context, cli client.Reader, synthesizedComp *SynthesizedComponent, |
| 408 | obj client.Object, objName, key string, optional *bool, resolve func(obj client.Object) (*corev1.EnvVar, *corev1.EnvVar)) (*corev1.EnvVar, *corev1.EnvVar, error) { |
| 409 | kind := obj.GetObjectKind().GroupVersionKind().Kind |
| 410 | _optional := func() bool { |
| 411 | return optional != nil && *optional |
| 412 | } |
| 413 | if len(objName) == 0 || len(key) == 0 { |
| 414 | if _optional() { |
| 415 | return nil, nil, nil |
| 416 | } |
| 417 | return nil, nil, fmt.Errorf("the name of %s object is empty when resolving vars", kind) |
| 418 | } |
| 419 | |
| 420 | objKey := types.NamespacedName{Namespace: synthesizedComp.Namespace, Name: objName} |
| 421 | if err := cli.Get(ctx, objKey, obj, inDataContext()); err != nil { |
| 422 | if apierrors.IsNotFound(err) && _optional() { |
| 423 | return nil, nil, nil |
| 424 | } |
| 425 | return nil, nil, fmt.Errorf("resolving vars from %s object %s error: %s", kind, objName, err.Error()) |
| 426 | } |
| 427 | |
| 428 | if v1, v2 := resolve(obj); v1 != nil || v2 != nil { |
| 429 | return v1, v2, nil |
| 430 | } |
| 431 | if _optional() { |
| 432 | return nil, nil, nil |
| 433 | } |
| 434 | return nil, nil, fmt.Errorf("the required var is not found in %s object %s", kind, objName) |
| 435 | } |
| 436 | |
| 437 | func resolveHostNetworkVarRef(ctx context.Context, cli client.Reader, synthesizedComp *SynthesizedComponent, |
| 438 | defineKey string, selector appsv1.HostNetworkVarSelector, ext ...any) ([]corev1.EnvVar, []corev1.EnvVar, error) { |
no test coverage detected
searching dependent graphs…