From 64700dcf6016a180c25f5e6fe63ccb4fe373e17a Mon Sep 17 00:00:00 2001 From: Alper Rifat Ulucinar Date: Wed, 29 May 2024 18:47:02 +0300 Subject: [PATCH] Add eks/v1beta2.ExternalNameIfClusterActive value extractor Signed-off-by: Alper Rifat Ulucinar --- apis/eks/v1beta1/reference.go | 4 ++++ apis/eks/v1beta2/reference.go | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 apis/eks/v1beta2/reference.go diff --git a/apis/eks/v1beta1/reference.go b/apis/eks/v1beta1/reference.go index 97105fe388..31f8e5591c 100644 --- a/apis/eks/v1beta1/reference.go +++ b/apis/eks/v1beta1/reference.go @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2024 The Crossplane Authors +// +// SPDX-License-Identifier: CC0-1.0 + package v1beta1 import ( diff --git a/apis/eks/v1beta2/reference.go b/apis/eks/v1beta2/reference.go new file mode 100644 index 0000000000..f0e388cb29 --- /dev/null +++ b/apis/eks/v1beta2/reference.go @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: 2024 The Crossplane Authors +// +// SPDX-License-Identifier: CC0-1.0 + +package v1beta2 + +import ( + "github.com/crossplane/crossplane-runtime/pkg/reference" + xpresource "github.com/crossplane/crossplane-runtime/pkg/resource" + "k8s.io/utils/ptr" +) + +// ExternalNameIfClusterActive returns the external name only if the EKS cluster +// is in ACTIVE state. +func ExternalNameIfClusterActive() reference.ExtractValueFn { + return func(mr xpresource.Managed) string { + cl, ok := mr.(*Cluster) + if !ok { + return "" + } + if ptr.Deref(cl.Status.AtProvider.Status, "") != "ACTIVE" { + return "" + } + return reference.ExternalName()(mr) + } +}