@@ -179,3 +179,67 @@ func (d *FailureDomains) Set(obj *unstructured.Unstructured, values clusterv1.Fa
179179 }
180180 return nil
181181}
182+
183+ // ControlPlaneEndpoint provides a helper struct for working with ControlPlaneEndpoint
184+ // in an InfrastructureCluster object.
185+ type ControlPlaneEndpoint struct {
186+ path Path
187+ }
188+
189+ // Path returns the path to the ControlPlaneEndpoint in an InfrastructureCluster object.
190+ func (c * ControlPlaneEndpoint ) Path () Path {
191+ return c .path
192+ }
193+
194+ // Get gets the ControlPlaneEndpoint value.
195+ func (c * ControlPlaneEndpoint ) Get (obj * unstructured.Unstructured ) (* clusterv1.APIEndpoint , error ) {
196+ controlPlaneEndpointMap , ok , err := unstructured .NestedMap (obj .UnstructuredContent (), c .path ... )
197+ if err != nil {
198+ return nil , errors .Wrapf (err , "failed to get %s from object" , "." + strings .Join (c .path , "." ))
199+ }
200+ if ! ok {
201+ return nil , errors .Wrapf (ErrFieldNotFound , "path %s" , "." + strings .Join (c .path , "." ))
202+ }
203+
204+ endpoint := & clusterv1.APIEndpoint {}
205+ s , err := json .Marshal (controlPlaneEndpointMap )
206+ if err != nil {
207+ return nil , errors .Wrapf (err , "failed to marshal field at %s to json" , "." + strings .Join (c .path , "." ))
208+ }
209+ if err := json .Unmarshal (s , & endpoint ); err != nil {
210+ return nil , errors .Wrapf (err , "failed to unmarshal field at %s to json" , "." + strings .Join (c .path , "." ))
211+ }
212+
213+ return endpoint , nil
214+ }
215+
216+ // Set sets the ControlPlaneEndpoint value.
217+ func (c * ControlPlaneEndpoint ) Set (obj * unstructured.Unstructured , value clusterv1.APIEndpoint ) error {
218+ controlPlaneEndpointMap := make (map [string ]interface {})
219+ s , err := json .Marshal (value )
220+ if err != nil {
221+ return errors .Wrapf (err , "failed to marshal supplied values to json for path %s" , "." + strings .Join (c .path , "." ))
222+ }
223+ if err := json .Unmarshal (s , & controlPlaneEndpointMap ); err != nil {
224+ return errors .Wrapf (err , "failed to unmarshal supplied values to json for path %s" , "." + strings .Join (c .path , "." ))
225+ }
226+
227+ if err := unstructured .SetNestedField (obj .UnstructuredContent (), controlPlaneEndpointMap , c .path ... ); err != nil {
228+ return errors .Wrapf (err , "failed to set path %s of object %v" , "." + strings .Join (c .path , "." ), obj .GroupVersionKind ())
229+ }
230+ return nil
231+ }
232+
233+ // host provides access to the host field in the ControlPlaneEndpoint in an InfrastructureCluster object.
234+ func (c * ControlPlaneEndpoint ) host () * String {
235+ return & String {
236+ path : c .path .Append ("host" ),
237+ }
238+ }
239+
240+ // port provides access to the port field in the ControlPlaneEndpoint in an InfrastructureCluster object.
241+ func (c * ControlPlaneEndpoint ) port () * Int64 {
242+ return & Int64 {
243+ path : c .path .Append ("port" ),
244+ }
245+ }
0 commit comments