Skip to content

Commit 7266349

Browse files
authored
set ignition endpoint at AgentClusterInstall creation (openshift#49)
1 parent 22297e7 commit 7266349

File tree

1 file changed

+26
-48
lines changed

1 file changed

+26
-48
lines changed

controllers/agentcluster_controller.go

+26-48
Original file line numberDiff line numberDiff line change
@@ -93,59 +93,20 @@ func (r *AgentClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
9393
return ctrl.Result{}, err
9494
}
9595

96-
aciCreated, err := r.ensureAgentClusterInstall(ctx, log, clusterDeployment)
96+
err = r.ensureAgentClusterInstall(ctx, log, clusterDeployment, agentCluster)
9797
if err != nil {
9898
return ctrl.Result{}, err
9999
}
100-
if aciCreated {
101-
// If we just created the ACI, requeue with a fresh copy of the ClusterDeployment
102-
return ctrl.Result{Requeue: true}, nil
103-
}
104100

105101
if !agentCluster.Spec.ControlPlaneEndpoint.IsValid() {
106102
log.Info("Waiting for agentCluster controlPlaneEndpoint")
107103
return ctrl.Result{RequeueAfter: agentClusterDependenciesWaitTime}, nil
108104
}
109-
err = r.updateAgentClusterInstall(ctx, log, agentCluster, clusterDeployment)
110-
if err != nil {
111-
return ctrl.Result{}, err
112-
}
113105

114106
// If the agentCluster has references a ClusterDeployment, sync from its status
115107
return r.updateClusterStatus(ctx, log, agentCluster)
116108
}
117109

118-
func (r *AgentClusterReconciler) updateAgentClusterInstall(ctx context.Context, log logrus.FieldLogger, agentCluster *capiproviderv1alpha1.AgentCluster, clusterDeployment *hivev1.ClusterDeployment) error {
119-
agentClusterInstall := &hiveext.AgentClusterInstall{}
120-
err := r.Get(ctx, types.NamespacedName{Namespace: agentCluster.Status.ClusterDeploymentRef.Namespace, Name: clusterDeployment.Spec.ClusterInstallRef.Name}, agentClusterInstall)
121-
if err != nil {
122-
log.WithError(err).Error("Failed to get AgentClusterInstall")
123-
return err
124-
}
125-
126-
if agentClusterInstall.Spec.IgnitionEndpoint == nil && agentCluster.Spec.IgnitionEndpoint != nil {
127-
log.Info("Updating ignition endpoint")
128-
url := agentCluster.Spec.IgnitionEndpoint.Url
129-
agentClusterInstall.Spec.IgnitionEndpoint = &hiveext.IgnitionEndpoint{
130-
// Currently assume something like https://1.2.3.4:555/ignition, otherwise this will fail
131-
// TODO: Replace with something more robust
132-
Url: url[0:strings.LastIndex(url, "/")],
133-
}
134-
if agentCluster.Spec.IgnitionEndpoint.CaCertificateReference != nil {
135-
agentClusterInstall.Spec.IgnitionEndpoint.CaCertificateReference = &hiveext.CaCertificateReference{
136-
Namespace: agentCluster.Spec.IgnitionEndpoint.CaCertificateReference.Namespace,
137-
Name: agentCluster.Spec.IgnitionEndpoint.CaCertificateReference.Name,
138-
}
139-
}
140-
if err = r.Client.Update(ctx, agentClusterInstall); err != nil {
141-
log.WithError(err).Error("Failed to update agentClusterInstall")
142-
return err
143-
}
144-
}
145-
146-
return nil
147-
}
148-
149110
func getNestedStringObject(log logrus.FieldLogger, obj *unstructured.Unstructured, baseFieldName string, fields ...string) (string, bool, error) {
150111
value, ok, err := unstructured.NestedString(obj.UnstructuredContent(), fields...)
151112
if err != nil {
@@ -285,26 +246,26 @@ func (r *AgentClusterReconciler) createClusterDeployment(ctx context.Context, lo
285246
return ctrl.Result{}, nil
286247
}
287248

288-
func (r *AgentClusterReconciler) ensureAgentClusterInstall(ctx context.Context, log logrus.FieldLogger, clusterDeployment *hivev1.ClusterDeployment) (bool, error) {
249+
func (r *AgentClusterReconciler) ensureAgentClusterInstall(ctx context.Context, log logrus.FieldLogger, clusterDeployment *hivev1.ClusterDeployment, agentCluster *capiproviderv1alpha1.AgentCluster) error {
289250
log.Info("Setting AgentClusterInstall")
290251
agentClusterInstall := &hiveext.AgentClusterInstall{}
291252
if err := r.Get(ctx, types.NamespacedName{Namespace: clusterDeployment.Namespace, Name: clusterDeployment.Name}, agentClusterInstall); err != nil {
292253
if apierrors.IsNotFound(err) {
293-
err = r.createAgentClusterInstall(ctx, log, clusterDeployment)
254+
err = r.createAgentClusterInstall(ctx, log, clusterDeployment, agentCluster)
294255
if err != nil {
295256
log.WithError(err).Error("failed to create AgentClusterInstall")
296-
return false, err
257+
return err
297258
}
298-
return true, nil
259+
return nil
299260
} else {
300-
log.WithError(err).Error("Failed to get AgentClusterInstall")
301-
return false, err
261+
log.WithError(err).Error("failed to get AgentClusterInstall")
262+
return err
302263
}
303264
}
304-
return false, nil
265+
return nil
305266
}
306267

307-
func (r *AgentClusterReconciler) createAgentClusterInstall(ctx context.Context, log logrus.FieldLogger, clusterDeployment *hivev1.ClusterDeployment) error {
268+
func (r *AgentClusterReconciler) createAgentClusterInstall(ctx context.Context, log logrus.FieldLogger, clusterDeployment *hivev1.ClusterDeployment, agentCluster *capiproviderv1alpha1.AgentCluster) error {
308269
log.Infof("Creating AgentClusterInstall for clusterDeployment: %s %s", clusterDeployment.Namespace, clusterDeployment.Name)
309270
agentClusterInstall := &hiveext.AgentClusterInstall{
310271
ObjectMeta: metav1.ObjectMeta{
@@ -318,6 +279,23 @@ func (r *AgentClusterReconciler) createAgentClusterInstall(ctx context.Context,
318279
},
319280
},
320281
}
282+
283+
// IgnitionEndpoint can only be set at AgentClusterInstall create time
284+
if agentCluster.Spec.IgnitionEndpoint != nil {
285+
url := agentCluster.Spec.IgnitionEndpoint.Url
286+
agentClusterInstall.Spec.IgnitionEndpoint = &hiveext.IgnitionEndpoint{
287+
// Currently assume something like https://1.2.3.4:555/ignition, otherwise this will fail
288+
// TODO: Replace with something more robust
289+
Url: url[0:strings.LastIndex(url, "/")],
290+
}
291+
if agentCluster.Spec.IgnitionEndpoint.CaCertificateReference != nil {
292+
agentClusterInstall.Spec.IgnitionEndpoint.CaCertificateReference = &hiveext.CaCertificateReference{
293+
Namespace: agentCluster.Spec.IgnitionEndpoint.CaCertificateReference.Namespace,
294+
Name: agentCluster.Spec.IgnitionEndpoint.CaCertificateReference.Name,
295+
}
296+
}
297+
}
298+
321299
return r.Client.Create(ctx, agentClusterInstall)
322300
}
323301

0 commit comments

Comments
 (0)