Skip to content

Commit b419ca7

Browse files
Merge pull request #1293 from rabi/bmhHash
Reset deployment status when provisioned BMH hash changes
2 parents 88ac3fb + 601909a commit b419ca7

File tree

6 files changed

+43
-12
lines changed

6 files changed

+43
-12
lines changed

apis/bases/dataplane.openstack.org_openstackdataplanenodesets.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,8 @@ spec:
937937
type: object
938938
ctlplaneSearchDomain:
939939
type: string
940+
deployedBmhHash:
941+
type: string
940942
deployedConfigHash:
941943
type: string
942944
deployedVersion:

apis/dataplane/v1beta1/openstackdataplanenodeset_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ type OpenStackDataPlaneNodeSetStatus struct {
154154

155155
// DeployedVersion
156156
DeployedVersion string `json:"deployedVersion,omitempty"`
157+
158+
//DeployedBmhHash - Hash of BMHs deployed
159+
DeployedBmhHash string `json:"deployedBmhHash,omitempty"`
157160
}
158161

159162
// +kubebuilder:object:root=true

bindata/crds/crds.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18127,6 +18127,8 @@ spec:
1812718127
type: object
1812818128
ctlplaneSearchDomain:
1812918129
type: string
18130+
deployedBmhHash:
18131+
type: string
1813018132
deployedConfigHash:
1813118133
type: string
1813218134
deployedVersion:

config/crd/bases/dataplane.openstack.org_openstackdataplanenodesets.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,8 @@ spec:
937937
type: object
938938
ctlplaneSearchDomain:
939939
type: string
940+
deployedBmhHash:
941+
type: string
940942
deployedConfigHash:
941943
type: string
942944
deployedVersion:

controllers/dataplane/openstackdataplanenodeset_controller.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,22 +371,22 @@ func (r *OpenStackDataPlaneNodeSetReconciler) Reconcile(ctx context.Context, req
371371
return ctrl.Result{}, err
372372
}
373373
containerImages := dataplaneutil.GetContainerImages(version)
374-
374+
provResult := deployment.ProvisionResult{}
375375
// Reconcile BaremetalSet if required
376376
if !instance.Spec.PreProvisioned {
377377
// Reset the NodeSetBareMetalProvisionReadyCondition to unknown
378378
instance.Status.Conditions.MarkUnknown(dataplanev1.NodeSetBareMetalProvisionReadyCondition,
379379
condition.InitReason, condition.InitReason)
380380

381-
isReady, err := deployment.DeployBaremetalSet(ctx, helper, instance,
381+
provResult, err := deployment.DeployBaremetalSet(ctx, helper, instance,
382382
allIPSets, dnsDetails.ServerAddresses, containerImages)
383-
if err != nil || !isReady {
383+
if err != nil || !provResult.IsProvisioned {
384384
return ctrl.Result{}, err
385385
}
386386
}
387387

388388
isDeploymentReady, isDeploymentRunning, isDeploymentFailed, failedDeployment, err := checkDeployment(
389-
ctx, helper, instance, generationChanged)
389+
ctx, helper, instance, generationChanged, provResult.BmhRefHash)
390390
if !isDeploymentFailed && err != nil {
391391
instance.Status.Conditions.MarkFalse(
392392
condition.DeploymentReadyCondition,
@@ -430,6 +430,7 @@ func (r *OpenStackDataPlaneNodeSetReconciler) Reconcile(ctx context.Context, req
430430
Log.Info("Set NodeSet DeploymentReadyCondition true")
431431
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition,
432432
condition.DeploymentReadyMessage)
433+
instance.Status.DeployedBmhHash = provResult.BmhRefHash
433434
} else if isDeploymentRunning {
434435
Log.Info("Deployment still running...", "instance", instance)
435436
Log.Info("Set NodeSet DeploymentReadyCondition false")
@@ -465,7 +466,7 @@ func (r *OpenStackDataPlaneNodeSetReconciler) Reconcile(ctx context.Context, req
465466

466467
func checkDeployment(ctx context.Context, helper *helper.Helper,
467468
instance *dataplanev1.OpenStackDataPlaneNodeSet,
468-
generationChanged bool,
469+
generationChanged bool, bmhRefHash string,
469470
) (bool, bool, bool, string, error) {
470471
// Get all completed deployments
471472
var failedDeployment string
@@ -524,8 +525,9 @@ func checkDeployment(ctx context.Context, helper *helper.Helper,
524525
// generation metadata has changed (i.e generation metatdata won't change when
525526
// fields are removed from the CRD during an update that would not require a new
526527
// deployment to run) asssume nodeset has changed requiring new deployment.
527-
if deployment.Status.NodeSetHashes[instance.Name] != instance.Status.ConfigHash &&
528-
generationChanged {
528+
if (deployment.Status.NodeSetHashes[instance.Name] != instance.Status.ConfigHash &&
529+
generationChanged) ||
530+
(!instance.Spec.PreProvisioned && instance.Status.DeployedBmhHash != bmhRefHash) {
529531
continue
530532
}
531533
isDeploymentReady = true
@@ -794,6 +796,5 @@ func (r *OpenStackDataPlaneNodeSetReconciler) GetSpecConfigHash(instance *datapl
794796
if err != nil {
795797
return "", err
796798
}
797-
798799
return configHash, nil
799800
}

pkg/dataplane/baremetal.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,25 @@ import (
2929
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
3030
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
3131
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
32+
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
3233
utils "github.com/openstack-k8s-operators/lib-common/modules/common/util"
3334
baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1"
3435
openstackv1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
3536
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"
3637
)
3738

39+
type ProvisionResult struct {
40+
IsProvisioned bool
41+
BmhRefHash string
42+
}
43+
3844
// DeployBaremetalSet Deploy OpenStackBaremetalSet
3945
func DeployBaremetalSet(
4046
ctx context.Context, helper *helper.Helper, instance *dataplanev1.OpenStackDataPlaneNodeSet,
4147
ipSets map[string]infranetworkv1.IPSet,
4248
dnsAddresses []string,
4349
containerImages openstackv1.ContainerImages,
44-
) (bool, error) {
50+
) (ProvisionResult, error) {
4551
baremetalSet := &baremetalv1.OpenStackBaremetalSet{
4652
ObjectMeta: metav1.ObjectMeta{
4753
Name: instance.Name,
@@ -109,7 +115,7 @@ func DeployBaremetalSet(
109115
condition.ErrorReason, condition.SeverityError,
110116
dataplanev1.NodeSetBaremetalProvisionErrorMessage,
111117
err.Error())
112-
return false, err
118+
return ProvisionResult{}, err
113119
}
114120

115121
// Check if baremetalSet is ready
@@ -119,10 +125,25 @@ func DeployBaremetalSet(
119125
dataplanev1.NodeSetBareMetalProvisionReadyCondition,
120126
condition.RequestedReason, condition.SeverityInfo,
121127
dataplanev1.NodeSetBaremetalProvisionReadyWaitingMessage)
122-
return false, nil
128+
return ProvisionResult{}, nil
129+
}
130+
131+
bmhRefHash, err := getBMHRefHash(baremetalSet)
132+
if err != nil {
133+
return ProvisionResult{}, err
123134
}
135+
124136
instance.Status.Conditions.MarkTrue(
125137
dataplanev1.NodeSetBareMetalProvisionReadyCondition,
126138
dataplanev1.NodeSetBaremetalProvisionReadyMessage)
127-
return true, nil
139+
return ProvisionResult{IsProvisioned: true, BmhRefHash: bmhRefHash}, nil
140+
}
141+
142+
func getBMHRefHash(bmSet *baremetalv1.OpenStackBaremetalSet) (string, error) {
143+
bmhRefHash, err := util.ObjectHash(bmSet.Status.BaremetalHosts)
144+
if err != nil {
145+
return "", err
146+
}
147+
return bmhRefHash, nil
148+
128149
}

0 commit comments

Comments
 (0)