Skip to content

Commit

Permalink
Merge pull request #65 from Kuadrant/gh-60
Browse files Browse the repository at this point in the history
fix nil checks
  • Loading branch information
maleck13 authored Apr 3, 2024
2 parents bb699a6 + 5e239e3 commit 1deaa27
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions internal/provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,28 @@ func (p *Route53DNSProvider) EnsureManagedZone(zone *v1alpha1.ManagedZone) (prov
if err != nil {
log.Log.Error(err, "failed to update hosted zone comment")
}
if getResp.HostedZone == nil {
err = fmt.Errorf("aws zone issue. No hosted zone info in response")
log.Log.Error(err, "unexpected response")
return managedZoneOutput, err
}
if getResp.HostedZone.Id == nil {
err = fmt.Errorf("aws zone issue. No hosted zone id in response")
return managedZoneOutput, err
}

managedZoneOutput.ID = *getResp.HostedZone.Id
managedZoneOutput.RecordCount = *getResp.HostedZone.ResourceRecordSetCount
managedZoneOutput.NameServers = getResp.DelegationSet.NameServers
if getResp.HostedZone.ResourceRecordSetCount != nil {
managedZoneOutput.RecordCount = *getResp.HostedZone.ResourceRecordSetCount
}

managedZoneOutput.NameServers = []*string{}
if getResp.DelegationSet != nil {
managedZoneOutput.NameServers = getResp.DelegationSet.NameServers
}

return managedZoneOutput, nil
}

//ToDo callerRef must be unique, but this can cause duplicates if the status can't be written back during a
//reconciliation that successfully created a new hosted zone i.e. the object has been modified; please apply your
//changes to the latest version and try again
Expand All @@ -191,9 +205,23 @@ func (p *Route53DNSProvider) EnsureManagedZone(zone *v1alpha1.ManagedZone) (prov
log.Log.Error(err, "failed to create hosted zone")
return managedZoneOutput, err
}
if createResp.HostedZone == nil {
err = fmt.Errorf("aws zone creation issue. No hosted zone info in response")
log.Log.Error(err, "unexpected response")
return managedZoneOutput, err
}
if createResp.HostedZone.Id == nil {
err = fmt.Errorf("aws zone creation issue. No hosted zone id in response")
return managedZoneOutput, err
}
managedZoneOutput.ID = *createResp.HostedZone.Id
managedZoneOutput.RecordCount = *createResp.HostedZone.ResourceRecordSetCount
managedZoneOutput.NameServers = createResp.DelegationSet.NameServers

if createResp.HostedZone.ResourceRecordSetCount != nil {
managedZoneOutput.RecordCount = *createResp.HostedZone.ResourceRecordSetCount
}
if createResp.DelegationSet != nil {
managedZoneOutput.NameServers = createResp.DelegationSet.NameServers
}
return managedZoneOutput, nil
}

Expand Down

0 comments on commit 1deaa27

Please sign in to comment.