@@ -11,7 +11,9 @@ import (
1111 "sync"
1212
1313 "github.com/akamai/AkamaiOPEN-edgegrid-golang/v8/pkg/dns"
14+ "github.com/go-logr/logr"
1415 "github.com/linode/linodego"
16+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1517 "sigs.k8s.io/cluster-api/api/core/v1beta2"
1618 kutil "sigs.k8s.io/cluster-api/util"
1719
@@ -300,7 +302,16 @@ func removeElement(stringList []string, elemToRemove string) []string {
300302 return stringList
301303}
302304
303- func processLinodeMachine (ctx context.Context , cscope * scope.ClusterScope , machine v1alpha2.LinodeMachine , dnsTTLSec int , subdomain string ) ([]DNSOptions , error ) {
305+ func isCapiMachineReady (capiMachine * v1beta2.Machine ) bool {
306+ for _ , condition := range capiMachine .Status .Conditions {
307+ if condition .Type == v1beta2 .ReadyCondition {
308+ return condition .Status == metav1 .ConditionTrue
309+ }
310+ }
311+ return false
312+ }
313+
314+ func processLinodeMachine (ctx context.Context , cscope * scope.ClusterScope , machine v1alpha2.LinodeMachine , dnsTTLSec int , subdomain string , firstMachine bool ) ([]DNSOptions , error ) {
304315 // Look up the corresponding CAPI machine, see if it is marked for deletion
305316 capiMachine , err := kutil .GetOwnerMachine (ctx , cscope .Client , machine .ObjectMeta )
306317 if err != nil {
@@ -312,6 +323,14 @@ func processLinodeMachine(ctx context.Context, cscope *scope.ClusterScope, machi
312323 return nil , nil
313324 }
314325
326+ if ! firstMachine && ! isCapiMachineReady (capiMachine ) {
327+ // always process the first linodeMachine, and add its IP to the DNS entries.
328+ // For other linodeMachine, only process them if the CAPI machine is ready
329+ logger := logr .FromContextOrDiscard (ctx )
330+ logger .Info ("skipping DNS entry creation for LinodeMachine as the CAPI machine is not ready" , "LinodeMachine" , machine .Name )
331+ return nil , nil
332+ }
333+
315334 options := []DNSOptions {}
316335 for _ , IPs := range machine .Status .Addresses {
317336 recordType := linodego .RecordTypeA
@@ -340,8 +359,10 @@ func (d *DNSEntries) getDNSEntriesToEnsure(ctx context.Context, cscope *scope.Cl
340359 }
341360
342361 subDomain := getSubDomain (cscope )
362+ firstMachine := true
343363 for _ , eachMachine := range cscope .LinodeMachines .Items {
344- options , err := processLinodeMachine (ctx , cscope , eachMachine , dnsTTLSec , subDomain )
364+ options , err := processLinodeMachine (ctx , cscope , eachMachine , dnsTTLSec , subDomain , firstMachine )
365+ firstMachine = false
345366 if err != nil {
346367 return nil , fmt .Errorf ("failed to process LinodeMachine %s: %w" , eachMachine .Name , err )
347368 }
0 commit comments