@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "fmt"
2222 "reflect"
23+ "sigs.k8s.io/cluster-api/util/conditions"
2324 "strconv"
2425
2526 "github.com/oracle/cluster-api-provider-oci/cloud/services/vcn"
@@ -108,6 +109,7 @@ func NewClusterScope(params ClusterScopeParams) (*ClusterScope, error) {
108109
109110// PatchObject persists the cluster configuration and status.
110111func (s * ClusterScope ) PatchObject (ctx context.Context ) error {
112+ conditions .SetSummary (s .OCICluster )
111113 return s .patchHelper .Patch (ctx , s .OCICluster )
112114}
113115
@@ -137,23 +139,29 @@ func (s *ClusterScope) IsResourceCreatedByClusterAPI(resourceFreeFormTags map[st
137139// in case of single AD regions, the failure domain will be fault domain, in case of multi Ad regions, it will
138140// be AD
139141func (s * ClusterScope ) setFailureDomains (ctx context.Context ) error {
140- req := identity.ListAvailabilityDomainsRequest {CompartmentId : common .String (s .GetCompartmentId ())}
142+ reqAd := identity.ListAvailabilityDomainsRequest {CompartmentId : common .String (s .GetCompartmentId ())}
141143
142- resp , err := s .IdentityClient .ListAvailabilityDomains (ctx , req )
144+ respAd , err := s .IdentityClient .ListAvailabilityDomains (ctx , reqAd )
143145 if err != nil {
144146 s .Logger .Error (err , "failed to list identity domains" )
145147 return err
146148 }
147149
148- numOfAds := len (resp .Items )
150+ // build the AD list for cluster
151+ err = s .setAvailabiltyDomainStatus (ctx , respAd .Items )
152+ if err != nil {
153+ return err
154+ }
155+
156+ numOfAds := len (respAd .Items )
149157 if numOfAds != 1 && numOfAds != 3 {
150158 err := errors .New (fmt .Sprintf ("invalid number of Availability Domains, should be either 1 or 3, but got %d" , numOfAds ))
151159 s .Logger .Error (err , "invalid number of Availability Domains" )
152160 return err
153161 }
154162
155163 if numOfAds == 3 {
156- for i , ad := range resp .Items {
164+ for i , ad := range respAd .Items {
157165 s .SetFailureDomain (strconv .Itoa (i + 1 ), clusterv1.FailureDomainSpec {
158166 ControlPlane : true ,
159167 Attributes : map [string ]string {AvailabilityDomain : * ad .Name },
@@ -162,7 +170,7 @@ func (s *ClusterScope) setFailureDomains(ctx context.Context) error {
162170 } else {
163171 req := identity.ListFaultDomainsRequest {
164172 CompartmentId : common .String (s .GetCompartmentId ()),
165- AvailabilityDomain : resp .Items [0 ].Name ,
173+ AvailabilityDomain : respAd .Items [0 ].Name ,
166174 }
167175 resp , err := s .IdentityClient .ListFaultDomains (ctx , req )
168176 if err != nil {
@@ -191,6 +199,38 @@ func (s *ClusterScope) SetFailureDomain(id string, spec clusterv1.FailureDomainS
191199 s .OCICluster .Status .FailureDomains [id ] = spec
192200}
193201
202+ // setAvailabiltyDomainStatus builds the OCIAvailabilityDomain list and sets the OCICluster's status with this list
203+ // so that other parts of the provider have access to ADs and FDs without having to make multiple calls to identity.
204+ func (s * ClusterScope ) setAvailabiltyDomainStatus (ctx context.Context , ads []identity.AvailabilityDomain ) error {
205+ clusterAds := make (map [string ]infrastructurev1beta1.OCIAvailabilityDomain )
206+ for _ , ad := range ads {
207+ reqFd := identity.ListFaultDomainsRequest {
208+ CompartmentId : common .String (s .GetCompartmentId ()),
209+ AvailabilityDomain : ad .Name ,
210+ }
211+ respFd , err := s .IdentityClient .ListFaultDomains (ctx , reqFd )
212+ if err != nil {
213+ s .Logger .Error (err , "failed to list fault domains" )
214+ return err
215+ }
216+
217+ var faultDomains []string
218+ for _ , fd := range respFd .Items {
219+ faultDomains = append (faultDomains , * fd .Name )
220+ }
221+
222+ adName := * ad .Name
223+ clusterAds [adName ] = infrastructurev1beta1.OCIAvailabilityDomain {
224+ Name : adName ,
225+ FaultDomains : faultDomains ,
226+ }
227+ }
228+
229+ s .OCICluster .Status .AvailabilityDomains = clusterAds
230+
231+ return nil
232+ }
233+
194234func (s * ClusterScope ) IsTagsEqual (freeFromTags map [string ]string , definedTags map [string ]map [string ]interface {}) bool {
195235 if reflect .DeepEqual (freeFromTags , s .GetFreeFormTags ()) && reflect .DeepEqual (definedTags , s .GetDefinedTags ()) {
196236 return true
0 commit comments