Skip to content

Commit

Permalink
fix: Reconcile common instance types even if URL does not change.
Browse files Browse the repository at this point in the history
The previous code would not reconcile common instance types resources
when they were loaded from a URL. User could change existing resources
in cluster, and the operator would not revert the change.

Signed-off-by: Andrej Krejcir <[email protected]>
  • Loading branch information
akrejcir committed Aug 6, 2024
1 parent 75d625d commit 8589145
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions internal/operands/common-instancetypes/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,23 +242,25 @@ func (c *CommonInstancetypes) reconcileRemovedResources(request *common.Request)
func (c *CommonInstancetypes) reconcileFromURL(request *common.Request) ([]common.ReconcileResult, error) {
// TODO - In the future we should handle cases where the URL remains the same but the provided resources change.
//nolint:staticcheck
if c.resourceURL != "" && c.resourceURL == *request.Instance.Spec.CommonInstancetypes.URL {
request.Logger.Info(fmt.Sprintf("Skipping reconcile of common-instancetypes from URL %s, force with a restart of the service.", *request.Instance.Spec.CommonInstancetypes.URL))
return nil, nil
}
if c.resourceURL == "" || c.resourceURL != *request.Instance.Spec.CommonInstancetypes.URL {
// Cache the URL, so we don't have to load it on every reconciliation.
//nolint:staticcheck
c.resourceURL = *request.Instance.Spec.CommonInstancetypes.URL

// Cache the URL so we can check if it changes with future reconcile attempts above
//nolint:staticcheck
c.resourceURL = *request.Instance.Spec.CommonInstancetypes.URL
request.Logger.Info(fmt.Sprintf("Reconciling common-instancetypes from URL %s", c.resourceURL))
var err error
c.virtualMachineClusterInstancetypes, c.virtualMachineClusterPreferences, err = c.FetchResourcesFromURL(c.resourceURL)
if err != nil {
return nil, err
request.Logger.Info(fmt.Sprintf("Reading common-instancetypes from URL %s", c.resourceURL))

var err error
c.virtualMachineClusterInstancetypes, c.virtualMachineClusterPreferences, err = c.FetchResourcesFromURL(c.resourceURL)
if err != nil {
return nil, err
}
} else {
request.Logger.Info(fmt.Sprintf("Skipping reading common-instancetypes from URL %s. Using cached resources. Force with a restart of the service.", *request.Instance.Spec.CommonInstancetypes.URL))
}

request.Logger.Info(fmt.Sprintf("Reconciling common-instancetypes from URL %s", c.resourceURL))
// Remove any resources no longer provided by the URL, this should only happen when switching from the internal bundle to external URL for now.
if err = c.reconcileRemovedResources(request); err != nil {
if err := c.reconcileRemovedResources(request); err != nil {
return nil, err
}

Expand Down

0 comments on commit 8589145

Please sign in to comment.