Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.3.x][OSPK8-672] fix provisionserver localImageUrl update #790

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions controllers/openstackprovisionserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"net/url"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -209,30 +208,11 @@ func (r *OpenStackProvisionServerReconciler) Reconcile(ctx context.Context, req
cond.Type = shared.ProvisionServerCondTypeProvisioning
cond.Reason = shared.OpenStackProvisionServerCondReasonProvisioning
cond.Message = "Provisioning of OpenStackProvisionServer in progress"
instance.Status.LocalImageURL = ""

// Provision IP Discovery Agent sets status' ProvisionIP
if instance.Status.ProvisionIP != "" {

// Get the current LocalImageURL IP (if any)
curURL, err := url.Parse(instance.Status.LocalImageURL)

if err != nil {
cond.Type = shared.ProvisionServerCondTypeError
cond.Reason = shared.OpenStackProvisionServerCondReasonLocalImageURLParseError
cond.Message = fmt.Sprintf("Failed to parse existing LocalImageURL: %s", instance.Status.LocalImageURL)
err = common.WrapErrorForObject(cond.Message, instance, err)

return ctrl.Result{}, err
}

// FIXME: changing the imageURL on the spec updates the pod, but doesn't update the LocalImageURL
// If the current LocalImageURL is empty, or its embedded IP does not equal the ProvisionIP, the update the LocalImageURL
if instance.Status.LocalImageURL == "" || curURL.Hostname() != instance.Status.ProvisionIP {
// Update status with LocalImageURL, given ProvisionIP status value
instance.Status.LocalImageURL = r.getLocalImageURL(instance)
common.LogForObject(r, fmt.Sprintf("OpenStackProvisionServer LocalImageURL changed: %s", instance.Status.LocalImageURL), instance)
}

// Now check the associated pod's status
podList, err := r.Kclient.CoreV1().Pods(instance.Namespace).List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("deployment=%s-provisionserver-deployment", instance.Name),
Expand All @@ -255,9 +235,7 @@ func (r *OpenStackProvisionServerReconciler) Reconcile(ctx context.Context, req
cond.Type = shared.ProvisionServerCondTypeWaiting
cond.Reason = shared.OpenStackProvisionServerCondReasonListError
cond.Message = "Pod not yet available"
err = common.WrapErrorForObject(cond.Message, instance, err)

return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, err
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
}

// There should only be one pod. If there is more than one, we have other problems...
Expand All @@ -266,6 +244,13 @@ func (r *OpenStackProvisionServerReconciler) Reconcile(ctx context.Context, req
cond.Type = shared.ProvisionServerCondTypeProvisioned
cond.Reason = shared.OpenStackProvisionServerCondReasonProvisioned
cond.Message = "OpenStackProvisionServer has been provisioned"

// Only set the localImageURL if the pod has finished init
instance.Status.LocalImageURL = r.getLocalImageURL(instance)
if instance.Status.LocalImageURL != currentStatus.LocalImageURL {
common.LogForObject(r, fmt.Sprintf("OpenStackProvisionServer LocalImageURL changed: %s", instance.Status.LocalImageURL), instance)
}

break
}
}
Expand Down Expand Up @@ -380,6 +365,9 @@ func (r *OpenStackProvisionServerReconciler) deploymentCreateOrUpdate(
replicas := int32(1)

deployment.Spec.Replicas = &replicas
deployment.Spec.Strategy = appsv1.DeploymentStrategy{
Type: appsv1.RecreateDeploymentStrategyType,
}
deployment.Spec.Template.Spec = corev1.PodSpec{
ServiceAccountName: provisionserver.ServiceAccount,
HostNetwork: true,
Expand Down