From b96b96ee5f51c385fbd2f61f6486bb4b3297d528 Mon Sep 17 00:00:00 2001 From: fabriziopandini Date: Tue, 5 Nov 2024 11:47:00 +0100 Subject: [PATCH] More comments --- internal/contract/types.go | 11 ++++++++--- .../controllers/cluster/cluster_controller_phases.go | 4 +--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/contract/types.go b/internal/contract/types.go index c2bc4d26cc1a..fa0b9d000ddf 100644 --- a/internal/contract/types.go +++ b/internal/contract/types.go @@ -107,12 +107,14 @@ type Int32 struct { paths []Path } -// Path returns the path to the int64 value. +// Path returns the path to the int32 value. func (i *Int32) Path() []Path { return i.paths } -// Get gets the int64 value. +// Get gets the int32 value. +// If more than one path is defined, path are checked in order and the first value reported is used +// (e.g. in case when we are reading from a preferred location first, and then from one or more fallback locations). func (i *Int32) Get(obj *unstructured.Unstructured) (*int32, error) { paths := []string{} for _, path := range i.paths { @@ -130,7 +132,10 @@ func (i *Int32) Get(obj *unstructured.Unstructured) (*int32, error) { return nil, errors.Wrapf(ErrFieldNotFound, "path %s", strings.Join(paths, ", ")) } -// Set sets the int64 value in the path. +// Set sets the int32 value in the path. +// If more than one path is defined, only the first path will be set. +// (the first path is considered the preferred location). +// Note: Cluster API should never Set values on external objects owner by providers; however this method is useful for writing tests. func (i *Int32) Set(obj *unstructured.Unstructured, value int64) error { if err := unstructured.SetNestedField(obj.UnstructuredContent(), value, i.paths[0]...); err != nil { return errors.Wrapf(err, "failed to set path %s of object %v", "."+strings.Join(i.paths[0], "."), obj.GroupVersionKind()) diff --git a/internal/controllers/cluster/cluster_controller_phases.go b/internal/controllers/cluster/cluster_controller_phases.go index ee7d1d612be1..f7e9fca144b7 100644 --- a/internal/controllers/cluster/cluster_controller_phases.go +++ b/internal/controllers/cluster/cluster_controller_phases.go @@ -151,9 +151,7 @@ func (r *Reconciler) reconcileInfrastructure(ctx context.Context, s *scope) (ctr // If the infrastructure ref is not set, no-op. if s.cluster.Spec.InfrastructureRef == nil { // if the cluster is not deleted, and the cluster is not using a ClusterClass, mark the infrastructure as ready to unblock other provisioning workflows. - // NOTE: if the cluster is not deleted and it is using a ClusterClass, the infrastructure will be set as soon as the topology is reconciled; in this - // case we should wait for the field to be se (and not unblock other provisioning workflows). - if s.cluster.DeletionTimestamp.IsZero() && cluster.Spec.Topology == nil { + if s.cluster.DeletionTimestamp.IsZero() { cluster.Status.InfrastructureReady = true conditions.MarkTrue(cluster, clusterv1.InfrastructureReadyCondition) }