Skip to content

Commit 3a9771c

Browse files
committed
rebase changes
Signed-off-by: Bharath Nallapeta <nr.bharath97@gmail.com>
1 parent 34ebf5f commit 3a9771c

23 files changed

+272
-290
lines changed

.golangci.yml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ linters:
9393
- pkg: sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha1
9494
alias: infrav1alpha1
9595
- pkg: sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1
96+
alias: infrav1beta1
97+
- pkg: sigs.k8s.io/cluster-api-provider-openstack/api/v1beta2
9698
alias: infrav1
9799
- pkg: sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors
98100
alias: capoerrors
@@ -105,14 +107,8 @@ linters:
105107
alias: clusterv1
106108
- pkg: sigs.k8s.io/cluster-api/api/core/v1beta1
107109
alias: clusterv1beta1
108-
- pkg: sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions
109-
alias: v1beta1conditions
110-
- pkg: sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions/v1beta2
111-
alias: deprecatedv1beta2conditions
112-
- pkg: sigs.k8s.io/cluster-api/util/conditions/deprecated/v1beta1
113-
alias: deprecatedv1beta1conditions
114-
- pkg: sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch
115-
alias: v1beta1patch
110+
- pkg: sigs.k8s.io/cluster-api/util/conditions
111+
alias: conditions
116112
- pkg: sigs.k8s.io/cluster-api/api/ipam/v1beta2
117113
alias: ipamv1
118114
# CABPK
@@ -183,18 +179,6 @@ linters:
183179
- linters:
184180
- staticcheck
185181
text: 'SA1019: "sigs.k8s.io/cluster-api/api/core/v1beta1" is deprecated: This package is deprecated and is going to be removed when support for v1beta1 will be dropped.'
186-
- linters:
187-
- staticcheck
188-
text: 'SA1019: "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions" is deprecated: This package is deprecated and is going to be removed when support for v1beta1 will be dropped. Please see https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more details.'
189-
- linters:
190-
- staticcheck
191-
text: 'SA1019: .*.Status.Ready is deprecated: This field is deprecated and will be removed in a future API version. Use status.conditions to determine the ready state of the *'
192-
- linters:
193-
- staticcheck
194-
text: 'SA1019: .*.Status.FailureReason is deprecated: This field is deprecated and will be removed in a future API version. Use status.conditions to report failures.'
195-
- linters:
196-
- staticcheck
197-
text: 'SA1019: .*.Status.FailureMessage is deprecated: This field is deprecated and will be removed in a future API version. Use status.conditions to report failures.'
198182
paths:
199183
- zz_generated.*\.go$
200184
- third_party$

api/v1beta2/conditions_consts.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ const (
6666
FloatingAddressFromPoolErrorReason = "FloatingIPError"
6767
// UnableToFindFloatingIPNetworkReason is used when the floating ip network is not found.
6868
UnableToFindFloatingIPNetworkReason = "UnableToFindFloatingIPNetwork"
69+
// PortCreateFailedReason used when creating a port failed.
70+
PortCreateFailedReason = "PortCreateFailed"
71+
)
72+
73+
const (
74+
// OpenStackAuthenticationSucceeded reports on the current status of the OpenStack credentials.
75+
OpenStackAuthenticationSucceeded string = "OpenStackAuthenticationSucceeded"
76+
77+
// OpenStackAuthenticationFailedReason is used when the controller fails to authenticate with OpenStack.
78+
OpenStackAuthenticationFailedReason = "OpenStackAuthenticationFailed"
6979
)
7080

7181
const (

config/crd/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ labels:
22
- pairs:
33
# Mapping from CAPI contract to CAPO API versions.
44
cluster.x-k8s.io/v1beta1: v1beta1
5+
cluster.x-k8s.io/v1beta2: v1beta2
56

67
# This kustomization.yaml is not intended to be run by itself,
78
# since it depends on service name and namespace that are out of this kustomize package.

controllers/openstackcluster_controller.go

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ import (
2828
corev1 "k8s.io/api/core/v1"
2929
"k8s.io/apimachinery/pkg/api/equality"
3030
apierrors "k8s.io/apimachinery/pkg/api/errors"
31-
"k8s.io/apimachinery/pkg/api/meta"
3231
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3332
kerrors "k8s.io/apimachinery/pkg/util/errors"
3433
"k8s.io/client-go/tools/record"
3534
"k8s.io/utils/ptr"
3635
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3736
"sigs.k8s.io/cluster-api/util"
3837
"sigs.k8s.io/cluster-api/util/annotations"
38+
"sigs.k8s.io/cluster-api/util/conditions"
3939
"sigs.k8s.io/cluster-api/util/collections"
4040
"sigs.k8s.io/cluster-api/util/patch"
4141
"sigs.k8s.io/cluster-api/util/predicates"
@@ -123,10 +123,19 @@ func (r *OpenStackClusterReconciler) Reconcile(ctx context.Context, req ctrl.Req
123123

124124
clientScope, err := r.ScopeFactory.NewClientScopeFromObject(ctx, r.Client, r.CaCertificates, log, openStackCluster)
125125
if err != nil {
126-
v1beta1conditions.MarkFalse(openStackCluster, infrav1.OpenStackAuthenticationSucceeded, infrav1.OpenStackAuthenticationFailedReason, clusterv1beta1.ConditionSeverityError, "Failed to create OpenStack client scope: %v", err)
126+
conditions.Set(openStackCluster, metav1.Condition{
127+
Type: infrav1.OpenStackAuthenticationSucceeded,
128+
Status: metav1.ConditionFalse,
129+
Reason: infrav1.OpenStackAuthenticationFailedReason,
130+
Message: fmt.Sprintf("Failed to create OpenStack client scope: %v", err),
131+
})
127132
return reconcile.Result{}, err
128133
}
129-
v1beta1conditions.MarkTrue(openStackCluster, infrav1.OpenStackAuthenticationSucceeded)
134+
conditions.Set(openStackCluster, metav1.Condition{
135+
Type: infrav1.OpenStackAuthenticationSucceeded,
136+
Status: metav1.ConditionTrue,
137+
Reason: infrav1.ReadyConditionReason,
138+
})
130139
scope := scope.NewWithLogger(clientScope, log)
131140

132141
// Handle deleted clusters
@@ -369,11 +378,11 @@ func (r *OpenStackClusterReconciler) reconcileNormal(ctx context.Context, scope
369378
// Set the Ready condition to True when infrastructure is ready.
370379
// This condition surfaces into Cluster's status.conditions[InfrastructureReady].
371380
// It reflects the current operational state of the cluster infrastructure.
372-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
381+
conditions.Set(openStackCluster, metav1.Condition{
373382
Type: clusterv1.ReadyCondition,
374383
Status: metav1.ConditionTrue,
375384
Reason: infrav1.ReadyConditionReason,
376-
ObservedGeneration: openStackCluster.Generation,
385+
377386
})
378387

379388
scope.Logger().Info("Reconciled Cluster created successfully")
@@ -744,39 +753,39 @@ func reconcileNetworkComponents(scope *scope.WithLogger, cluster *clusterv1.Clus
744753

745754
err = networkingService.ReconcileSecurityGroups(openStackCluster, clusterResourceName)
746755
if err != nil {
747-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
756+
conditions.Set(openStackCluster, metav1.Condition{
748757
Type: infrav1.SecurityGroupsReadyCondition,
749758
Status: metav1.ConditionFalse,
750759
Reason: infrav1.SecurityGroupReconcileFailedReason,
751760
Message: fmt.Sprintf("Failed to reconcile security groups: %v", err),
752-
ObservedGeneration: openStackCluster.Generation,
761+
753762
})
754763
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to reconcile security groups: %w", err))
755764
return fmt.Errorf("failed to reconcile security groups: %w", err)
756765
}
757-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
766+
conditions.Set(openStackCluster, metav1.Condition{
758767
Type: infrav1.SecurityGroupsReadyCondition,
759768
Status: metav1.ConditionTrue,
760769
Reason: infrav1.ReadyConditionReason,
761-
ObservedGeneration: openStackCluster.Generation,
770+
762771
})
763772

764773
err = reconcileControlPlaneEndpoint(scope, networkingService, openStackCluster, clusterResourceName)
765774
if err != nil {
766-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
775+
conditions.Set(openStackCluster, metav1.Condition{
767776
Type: infrav1.APIEndpointReadyCondition,
768777
Status: metav1.ConditionFalse,
769778
Reason: infrav1.APIEndpointConfigFailedReason,
770779
Message: fmt.Sprintf("Failed to reconcile control plane endpoint: %v", err),
771-
ObservedGeneration: openStackCluster.Generation,
780+
772781
})
773782
return err
774783
}
775-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
784+
conditions.Set(openStackCluster, metav1.Condition{
776785
Type: infrav1.APIEndpointReadyCondition,
777786
Status: metav1.ConditionTrue,
778787
Reason: infrav1.ReadyConditionReason,
779-
ObservedGeneration: openStackCluster.Generation,
788+
780789
})
781790

782791
return nil
@@ -795,12 +804,12 @@ func reconcilePreExistingNetworkComponents(scope *scope.WithLogger, networkingSe
795804
if openStackCluster.Spec.Network != nil {
796805
network, err := networkingService.GetNetworkByParam(openStackCluster.Spec.Network)
797806
if err != nil {
798-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
807+
conditions.Set(openStackCluster, metav1.Condition{
799808
Type: infrav1.NetworkReadyCondition,
800809
Status: metav1.ConditionFalse,
801810
Reason: infrav1.OpenStackErrorReason,
802811
Message: fmt.Sprintf("Failed to find network: %v", err),
803-
ObservedGeneration: openStackCluster.Generation,
812+
804813
})
805814
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to find network: %w", err))
806815
return fmt.Errorf("error fetching cluster network: %w", err)
@@ -810,12 +819,12 @@ func reconcilePreExistingNetworkComponents(scope *scope.WithLogger, networkingSe
810819

811820
subnets, err := getClusterSubnets(networkingService, openStackCluster)
812821
if err != nil {
813-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
822+
conditions.Set(openStackCluster, metav1.Condition{
814823
Type: infrav1.NetworkReadyCondition,
815824
Status: metav1.ConditionFalse,
816825
Reason: infrav1.OpenStackErrorReason,
817826
Message: fmt.Sprintf("Failed to get cluster subnets: %v", err),
818-
ObservedGeneration: openStackCluster.Generation,
827+
819828
})
820829
return err
821830
}
@@ -832,12 +841,12 @@ func reconcilePreExistingNetworkComponents(scope *scope.WithLogger, networkingSe
832841
}
833842
}
834843
if err := utils.ValidateSubnets(capoSubnets); err != nil {
835-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
844+
conditions.Set(openStackCluster, metav1.Condition{
836845
Type: infrav1.NetworkReadyCondition,
837846
Status: metav1.ConditionFalse,
838847
Reason: infrav1.OpenStackErrorReason,
839848
Message: fmt.Sprintf("Failed to validate subnets: %v", err),
840-
ObservedGeneration: openStackCluster.Generation,
849+
841850
})
842851
return err
843852
}
@@ -849,34 +858,34 @@ func reconcilePreExistingNetworkComponents(scope *scope.WithLogger, networkingSe
849858
if openStackCluster.Status.Network.ID == "" && len(subnets) > 0 {
850859
network, err := networkingService.GetNetworkByID(subnets[0].NetworkID)
851860
if err != nil {
852-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
861+
conditions.Set(openStackCluster, metav1.Condition{
853862
Type: infrav1.NetworkReadyCondition,
854863
Status: metav1.ConditionFalse,
855864
Reason: infrav1.OpenStackErrorReason,
856865
Message: fmt.Sprintf("Failed to get network by ID: %v", err),
857-
ObservedGeneration: openStackCluster.Generation,
866+
858867
})
859868
return err
860869
}
861870
setClusterNetwork(openStackCluster, network)
862871
}
863872

864-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
873+
conditions.Set(openStackCluster, metav1.Condition{
865874
Type: infrav1.NetworkReadyCondition,
866875
Status: metav1.ConditionTrue,
867876
Reason: infrav1.ReadyConditionReason,
868-
ObservedGeneration: openStackCluster.Generation,
877+
869878
})
870879

871880
if openStackCluster.Spec.Router != nil {
872881
router, err := networkingService.GetRouterByParam(openStackCluster.Spec.Router)
873882
if err != nil {
874-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
883+
conditions.Set(openStackCluster, metav1.Condition{
875884
Type: infrav1.RouterReadyCondition,
876885
Status: metav1.ConditionFalse,
877886
Reason: infrav1.OpenStackErrorReason,
878887
Message: fmt.Sprintf("Failed to find router: %v", err),
879-
ObservedGeneration: openStackCluster.Generation,
888+
880889
})
881890
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to find router: %w", err))
882891
return fmt.Errorf("error fetching cluster router: %w", err)
@@ -895,11 +904,11 @@ func reconcilePreExistingNetworkComponents(scope *scope.WithLogger, networkingSe
895904
Tags: router.Tags,
896905
IPs: routerIPs,
897906
}
898-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
907+
conditions.Set(openStackCluster, metav1.Condition{
899908
Type: infrav1.RouterReadyCondition,
900909
Status: metav1.ConditionTrue,
901910
Reason: infrav1.ReadyConditionReason,
902-
ObservedGeneration: openStackCluster.Generation,
911+
903912
})
904913
}
905914

@@ -911,52 +920,52 @@ func reconcilePreExistingNetworkComponents(scope *scope.WithLogger, networkingSe
911920
func reconcileProvisionedNetworkComponents(networkingService *networking.Service, openStackCluster *infrav1.OpenStackCluster, clusterResourceName string) error {
912921
err := networkingService.ReconcileNetwork(openStackCluster, clusterResourceName)
913922
if err != nil {
914-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
923+
conditions.Set(openStackCluster, metav1.Condition{
915924
Type: infrav1.NetworkReadyCondition,
916925
Status: metav1.ConditionFalse,
917926
Reason: infrav1.NetworkReconcileFailedReason,
918927
Message: fmt.Sprintf("Failed to reconcile network: %v", err),
919-
ObservedGeneration: openStackCluster.Generation,
928+
920929
})
921930
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to reconcile network: %w", err))
922931
return fmt.Errorf("failed to reconcile network: %w", err)
923932
}
924933
err = networkingService.ReconcileSubnet(openStackCluster, clusterResourceName)
925934
if err != nil {
926-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
935+
conditions.Set(openStackCluster, metav1.Condition{
927936
Type: infrav1.NetworkReadyCondition,
928937
Status: metav1.ConditionFalse,
929938
Reason: infrav1.SubnetReconcileFailedReason,
930939
Message: fmt.Sprintf("Failed to reconcile subnets: %v", err),
931-
ObservedGeneration: openStackCluster.Generation,
940+
932941
})
933942
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to reconcile subnets: %w", err))
934943
return fmt.Errorf("failed to reconcile subnets: %w", err)
935944
}
936-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
945+
conditions.Set(openStackCluster, metav1.Condition{
937946
Type: infrav1.NetworkReadyCondition,
938947
Status: metav1.ConditionTrue,
939948
Reason: infrav1.ReadyConditionReason,
940-
ObservedGeneration: openStackCluster.Generation,
949+
941950
})
942951

943952
err = networkingService.ReconcileRouter(openStackCluster, clusterResourceName)
944953
if err != nil {
945-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
954+
conditions.Set(openStackCluster, metav1.Condition{
946955
Type: infrav1.RouterReadyCondition,
947956
Status: metav1.ConditionFalse,
948957
Reason: infrav1.RouterReconcileFailedReason,
949958
Message: fmt.Sprintf("Failed to reconcile router: %v", err),
950-
ObservedGeneration: openStackCluster.Generation,
959+
951960
})
952961
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to reconcile router: %w", err))
953962
return fmt.Errorf("failed to reconcile router: %w", err)
954963
}
955-
meta.SetStatusCondition(&openStackCluster.Status.Conditions, metav1.Condition{
964+
conditions.Set(openStackCluster, metav1.Condition{
956965
Type: infrav1.RouterReadyCondition,
957966
Status: metav1.ConditionTrue,
958967
Reason: infrav1.ReadyConditionReason,
959-
ObservedGeneration: openStackCluster.Generation,
968+
960969
})
961970

962971
return nil
@@ -1085,12 +1094,12 @@ func (r *OpenStackClusterReconciler) SetupWithManager(ctx context.Context, mgr c
10851094

10861095
func handleUpdateOSCError(openstackCluster *infrav1.OpenStackCluster, message error) {
10871096
// Set the Ready condition to False for errors
1088-
meta.SetStatusCondition(&openstackCluster.Status.Conditions, metav1.Condition{
1097+
conditions.Set(openstackCluster, metav1.Condition{
10891098
Type: clusterv1.ReadyCondition,
10901099
Status: metav1.ConditionFalse,
10911100
Reason: infrav1.OpenStackErrorReason,
10921101
Message: message.Error(),
1093-
ObservedGeneration: openstackCluster.Generation,
1102+
10941103
})
10951104
}
10961105

0 commit comments

Comments
 (0)