@@ -12,13 +12,13 @@ import (
1212 "gopkg.in/yaml.v2"
1313 corev1 "k8s.io/api/core/v1"
1414 apierrors "k8s.io/apimachinery/pkg/api/errors"
15+ "k8s.io/apimachinery/pkg/api/meta"
1516 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1617 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1718 "k8s.io/apimachinery/pkg/runtime"
1819 utilerrors "k8s.io/apimachinery/pkg/util/errors"
1920 "k8s.io/apimachinery/pkg/util/wait"
20- "k8s.io/utils/ptr"
21- clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
21+ clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2222 utilkubeconfig "sigs.k8s.io/cluster-api/util/kubeconfig"
2323 "sigs.k8s.io/controller-runtime/pkg/client"
2424
@@ -234,15 +234,16 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
234234 }
235235 }
236236 for _ , capiCluster := range capiClusters {
237- if ! capiCluster .Status .InfrastructureReady {
237+ infraReadyCond := meta .FindStatusCondition (capiCluster .Status .Conditions , clusterv1 .ClusterInfrastructureReadyCondition )
238+ if infraReadyCond == nil || infraReadyCond .Status != metav1 .ConditionTrue {
238239 return false , nil
239240 }
240241 }
241242 return true , nil
242243 }); err != nil {
243244 // Attempt to find and report falsy conditions in infra cluster if any.
244245 if len (capiClusters ) > 0 {
245- warnIfFalsyInfraConditions (ctx , capiClusters [0 ].Spec .InfrastructureRef , cl )
246+ warnIfFalsyInfraConditions (ctx , capiClusters [0 ].Spec .InfrastructureRef , capiutils . Namespace , cl )
246247 }
247248 if wait .Interrupted (err ) {
248249 return fileList , fmt .Errorf ("infrastructure was not ready within %v" , networkTimeout )
@@ -375,7 +376,7 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
375376 // Attempt to find and report falsy conditions in infra machines if any.
376377 for _ , machine := range capiMachines {
377378 if machine != nil {
378- warnIfFalsyInfraConditions (ctx , & machine .Spec .InfrastructureRef , cl )
379+ warnIfFalsyInfraConditions (ctx , machine .Spec .InfrastructureRef , capiutils . Namespace , cl )
379380 }
380381 }
381382 if wait .Interrupted (err ) {
@@ -640,10 +641,6 @@ func checkMachineReady(machine *clusterv1.Machine, requirePublicIP bool) (bool,
640641 machine .Status .Phase != string (clusterv1 .MachinePhaseRunning ) {
641642 logrus .Debugf ("Machine %s has not yet provisioned: %s" , machine .Name , machine .Status .Phase )
642643 return false , nil
643- } else if machine .Status .Phase == string (clusterv1 .MachinePhaseFailed ) {
644- //TODO: We need to update this to use non deprecated field
645- msg := ptr .Deref (machine .Status .FailureMessage , "machine.Status.FailureMessage was not set" ) //nolint:staticcheck
646- return false , fmt .Errorf ("machine %s failed to provision: %s" , machine .Name , msg )
647644 }
648645 logrus .Debugf ("Machine %s has status: %s" , machine .Name , machine .Status .Phase )
649646 return hasRequiredIP (machine , requirePublicIP ), nil
@@ -673,12 +670,12 @@ func hasRequiredIP(machine *clusterv1.Machine, requirePublicIP bool) bool {
673670// in a provider-agnostic way from the "status.condition" field, which should be present in all providers.
674671// https://cluster-api.sigs.k8s.io/developer/providers/contracts/infra-cluster#infracluster-conditions
675672// https://cluster-api.sigs.k8s.io/developer/providers/contracts/infra-machine#inframachine-conditions
676- func gatherInfraConditions (ctx context.Context , objRef * corev1. ObjectReference , cl client.Client ) (clusterv1.Conditions , error ) {
673+ func gatherInfraConditions (ctx context.Context , objRef clusterv1. ContractVersionedObjectReference , namespace string , cl client.Client ) (clusterv1.Conditions , error ) {
677674 unstructuredObj := & unstructured.Unstructured {}
678- unstructuredObj .SetGroupVersionKind (objRef .GroupVersionKind ( ))
675+ unstructuredObj .SetGroupVersionKind (objRef .GroupKind (). WithVersion ( "" ))
679676
680677 if err := cl .Get (ctx , client.ObjectKey {
681- Namespace : objRef . Namespace ,
678+ Namespace : namespace ,
682679 Name : objRef .Name ,
683680 }, unstructuredObj ); err != nil {
684681 return nil , err
@@ -700,12 +697,11 @@ func gatherInfraConditions(ctx context.Context, objRef *corev1.ObjectReference,
700697
701698// warnIfFalsyInfraConditions logs warning messages for any conditions that are not "True"
702699// in the infra cluster or machine status.
703- func warnIfFalsyInfraConditions (ctx context.Context , objRef * corev1.ObjectReference , cl client.Client ) {
704- apiVersion , kind := objRef .GroupVersionKind ().ToAPIVersionAndKind ()
705- objInfo := fmt .Sprintf ("apiVersion=%s, kind=%s, namespace=%s, name=%s" , apiVersion , kind , objRef .Namespace , objRef .Name )
700+ func warnIfFalsyInfraConditions (ctx context.Context , objRef clusterv1.ContractVersionedObjectReference , namespace string , cl client.Client ) {
701+ objInfo := fmt .Sprintf ("apiGroup=%s, kind=%s, namespace=%s, name=%s" , objRef .APIGroup , objRef .Kind , namespace , objRef .Name )
706702
707703 logrus .Infof ("Gathering conditions for %s" , objInfo )
708- conditions , err := gatherInfraConditions (ctx , objRef , cl )
704+ conditions , err := gatherInfraConditions (ctx , objRef , namespace , cl )
709705 if err != nil {
710706 logrus .Warnf ("Failed to gather conditions: %s" , err .Error ())
711707 return
0 commit comments