Skip to content

Commit 95fc985

Browse files
committed
fix: broken build
1 parent 77c079a commit 95fc985

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

internal/contract/controlplane.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ func ControlPlane() *ControlPlaneContract {
4444
return controlPlane
4545
}
4646

47+
// ControlPlaneEndpoint provides access to ControlPlaneEndpoint in an ControlPlane object.
48+
func (c *ControlPlaneContract) ControlPlaneEndpoint() *ControlPlaneEndpoint {
49+
return &ControlPlaneEndpoint{
50+
path: []string{"spec", "controlPlaneEndpoint"},
51+
}
52+
}
53+
4754
// MachineTemplate provides access to MachineTemplate in a ControlPlane object, if any.
4855
// NOTE: When working with unstructured there is no way to understand if the ControlPlane provider
4956
// do support a field in the type definition from the fact that a field is not set in a given instance.

internal/contract/infrastructure_cluster.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)