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) + } +}