@@ -77,20 +77,6 @@ type OnboardingController struct {
7777 testNetworkClient * gophercloud.ServiceClient
7878}
7979
80- func getHypervisorAddress (node * corev1.Node ) string {
81- for _ , addr := range node .Status .Addresses {
82- if addr .Address == "" {
83- continue
84- }
85-
86- if addr .Type == corev1 .NodeHostName {
87- return addr .Address
88- }
89- }
90-
91- return ""
92- }
93-
9480// +kubebuilder:rbac:groups=kvm.cloud.sap,resources=hypervisors,verbs=get;list;watch;patch
9581func (r * OnboardingController ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
9682 log := logger .FromContext (ctx ).WithName (req .Name )
@@ -144,24 +130,14 @@ func (r *OnboardingController) Reconcile(ctx context.Context, req ctrl.Request)
144130 return ctrl.Result {}, r .Status ().Update (ctx , hv )
145131 }
146132
147- // TODO: cleanup node retrieval
148- node := & corev1.Node {}
149- if err := r .Get (ctx , types.NamespacedName {Name : hv .Name }, node ); err != nil {
150- if k8sclient .IgnoreNotFound (err ) == nil {
151- // Node not found, could be deleted
152- return ctrl.Result {}, nil
153- }
154- return ctrl.Result {}, err
155- }
156-
157133 switch status .Reason {
158134 case ConditionReasonInitial :
159135 return ctrl.Result {}, r .initialOnboarding (ctx , hv , computeHost )
160136 case ConditionReasonTesting :
161137 if hv .Spec .SkipTests {
162- return r .completeOnboarding (ctx , computeHost , node , hv )
138+ return r .completeOnboarding (ctx , computeHost , hv )
163139 } else {
164- return r .smokeTest (ctx , node , hv , computeHost )
140+ return r .smokeTest (ctx , hv , computeHost )
165141 }
166142 default :
167143 // Nothing to be done
@@ -170,16 +146,7 @@ func (r *OnboardingController) Reconcile(ctx context.Context, req ctrl.Request)
170146}
171147
172148func (r * OnboardingController ) initialOnboarding (ctx context.Context , hv * kvmv1.Hypervisor , host string ) error {
173- node := & corev1.Node {}
174- if err := r .Get (ctx , types.NamespacedName {Name : hv .Name }, node ); err != nil {
175- if k8sclient .IgnoreNotFound (err ) == nil {
176- // Node not found, could be deleted
177- return nil
178- }
179- return err
180- }
181-
182- zone , found := node .Labels [corev1 .LabelTopologyZone ]
149+ zone , found := hv .Labels [corev1 .LabelTopologyZone ]
183150 if ! found || zone == "" {
184151 return fmt .Errorf ("cannot find availability-zone label %v on node" , corev1 .LabelTopologyZone )
185152 }
@@ -193,11 +160,9 @@ func (r *OnboardingController) initialOnboarding(ctx context.Context, hv *kvmv1.
193160 return fmt .Errorf ("failed to agg to availability-zone aggregate %w" , err )
194161 }
195162
196- if _ , found := node .Labels [corev1 .LabelTopologyZone ]; found {
197- err = addToAggregate (ctx , r .computeClient , aggs , host , testAggregateName , "" )
198- if err != nil {
199- return fmt .Errorf ("failed to agg to test aggregate %w" , err )
200- }
163+ err = addToAggregate (ctx , r .computeClient , aggs , host , testAggregateName , "" )
164+ if err != nil {
165+ return fmt .Errorf ("failed to agg to test aggregate %w" , err )
201166 }
202167
203168 // The service may be forced down previously due to an HA event,
@@ -220,10 +185,10 @@ func (r *OnboardingController) initialOnboarding(ctx context.Context, hv *kvmv1.
220185 return r .Status ().Update (ctx , hv )
221186}
222187
223- func (r * OnboardingController ) smokeTest (ctx context.Context , node * corev1. Node , hv * kvmv1.Hypervisor , host string ) (ctrl.Result , error ) {
188+ func (r * OnboardingController ) smokeTest (ctx context.Context , hv * kvmv1.Hypervisor , host string ) (ctrl.Result , error ) {
224189 log := logger .FromContext (ctx )
225- zone := node .Labels [corev1 .LabelTopologyZone ]
226- server , err := r .createOrGetTestServer (ctx , zone , host , node .UID )
190+ zone := hv .Labels [corev1 .LabelTopologyZone ]
191+ server , err := r .createOrGetTestServer (ctx , zone , host , hv .UID )
227192 if err != nil {
228193 return ctrl.Result {}, fmt .Errorf ("failed to create or get test instance %w" , err )
229194 }
@@ -288,13 +253,13 @@ func (r *OnboardingController) smokeTest(ctx context.Context, node *corev1.Node,
288253 return ctrl.Result {RequeueAfter : defaultWaitTime }, nil
289254 }
290255
291- return r .completeOnboarding (ctx , host , node , hv )
256+ return r .completeOnboarding (ctx , host , hv )
292257 default :
293258 return ctrl.Result {RequeueAfter : defaultWaitTime }, nil
294259 }
295260}
296261
297- func (r * OnboardingController ) completeOnboarding (ctx context.Context , host string , node * corev1. Node , hv * kvmv1.Hypervisor ) (ctrl.Result , error ) {
262+ func (r * OnboardingController ) completeOnboarding (ctx context.Context , host string , hv * kvmv1.Hypervisor ) (ctrl.Result , error ) {
298263 log := logger .FromContext (ctx )
299264
300265 serverPrefix := fmt .Sprintf ("%v-%v" , testPrefixName , host )
@@ -331,7 +296,7 @@ func (r *OnboardingController) completeOnboarding(ctx context.Context, host stri
331296 }
332297 log .Info ("removed from test-aggregate" , "name" , testAggregateName )
333298
334- err = enableInstanceHA (node )
299+ err = enableInstanceHA (hv )
335300 log .Info ("enabled instance-ha" )
336301 if err != nil {
337302 return ctrl.Result {}, err
@@ -356,12 +321,7 @@ func (r *OnboardingController) completeOnboarding(ctx context.Context, host stri
356321}
357322
358323func (r * OnboardingController ) ensureNovaProperties (ctx context.Context , hv * kvmv1.Hypervisor ) error {
359- node := & corev1.Node {}
360- if err := r .Get (ctx , types.NamespacedName {Name : hv .Name }, node ); err != nil {
361- return k8sclient .IgnoreNotFound (err )
362- }
363-
364- hypervisorAddress := getHypervisorAddress (node )
324+ hypervisorAddress := hv .Labels [corev1 .LabelHostname ]
365325 if hypervisorAddress == "" {
366326 return errRequeue
367327 }
0 commit comments