Skip to content

Commit f03ace0

Browse files
Merge pull request #1258 from rabi/OSPRH-12709
Don't set BaremetalHosts in the nodeset spec
2 parents 3fc524e + 93afb71 commit f03ace0

File tree

8 files changed

+18
-107
lines changed

8 files changed

+18
-107
lines changed

apis/bases/dataplane.openstack.org_openstackdataplanenodesets.yaml

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,61 +51,22 @@ spec:
5151
- metadata
5252
- disabled
5353
type: string
54-
baremetalHosts:
55-
additionalProperties:
56-
properties:
57-
bmhLabelSelector:
58-
additionalProperties:
59-
type: string
60-
type: object
61-
ctlPlaneIP:
62-
type: string
63-
networkData:
64-
properties:
65-
name:
66-
type: string
67-
namespace:
68-
type: string
69-
type: object
70-
x-kubernetes-map-type: atomic
71-
userData:
72-
properties:
73-
name:
74-
type: string
75-
namespace:
76-
type: string
77-
type: object
78-
x-kubernetes-map-type: atomic
79-
type: object
80-
type: object
8154
bmhLabelSelector:
8255
additionalProperties:
8356
type: string
8457
type: object
8558
bmhNamespace:
8659
default: openshift-machine-api
8760
type: string
88-
bootstrapDns:
89-
items:
90-
type: string
91-
type: array
9261
cloudUserName:
9362
default: cloud-admin
9463
type: string
95-
ctlplaneGateway:
96-
type: string
9764
ctlplaneInterface:
9865
type: string
9966
ctlplaneNetmask:
10067
type: string
101-
ctlplaneVlan:
102-
type: integer
10368
deploymentSSHSecret:
10469
type: string
105-
dnsSearchDomains:
106-
items:
107-
type: string
108-
type: array
10970
domainName:
11071
type: string
11172
hardwareReqs:

apis/dataplane/v1beta1/openstackdataplanenodeset_types.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
type OpenStackDataPlaneNodeSetSpec struct {
3838
// +kubebuilder:validation:Optional
3939
// BaremetalSetTemplate Template for BaremetalSet for the NodeSet
40-
BaremetalSetTemplate baremetalv1.OpenStackBaremetalSetSpec `json:"baremetalSetTemplate,omitempty"`
40+
BaremetalSetTemplate baremetalv1.OpenStackBaremetalSetTemplateSpec `json:"baremetalSetTemplate,omitempty"`
4141

4242
// +kubebuilder:validation:Required
4343
// NodeTemplate - node attributes specific to nodes defined by this resource. These
@@ -188,9 +188,8 @@ func (instance *OpenStackDataPlaneNodeSet) InitConditions() {
188188
condition.UnknownCondition(condition.ServiceAccountReadyCondition, condition.InitReason, condition.ServiceAccountReadyInitMessage),
189189
)
190190

191-
// Only set Baremetal related conditions if we have baremetal hosts included in the
192-
// baremetalSetTemplate.
193-
if len(instance.Spec.BaremetalSetTemplate.BaremetalHosts) > 0 {
191+
// Only set Baremetal related conditions if required
192+
if !instance.Spec.PreProvisioned && len(instance.Spec.Nodes) > 0 {
194193
cl = append(cl, *condition.UnknownCondition(NodeSetBareMetalProvisionReadyCondition, condition.InitReason, condition.InitReason))
195194
}
196195

apis/dataplane/v1beta1/openstackdataplanenodeset_webhook.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/go-playground/validator/v10"
2626
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
27-
baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1"
2827
apierrors "k8s.io/apimachinery/pkg/api/errors"
2928
"k8s.io/apimachinery/pkg/runtime"
3029
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -79,6 +78,7 @@ func (spec *OpenStackDataPlaneNodeSetSpec) Default() {
7978
node.HostName = strings.Join([]string{nodeName, domain}, ".")
8079
}
8180
}
81+
8282
spec.Nodes[nodeName] = *node.DeepCopy()
8383
}
8484

@@ -87,15 +87,6 @@ func (spec *OpenStackDataPlaneNodeSetSpec) Default() {
8787
if spec.BaremetalSetTemplate.DeploymentSSHSecret == "" {
8888
spec.BaremetalSetTemplate.DeploymentSSHSecret = spec.NodeTemplate.AnsibleSSHPrivateKeySecret
8989
}
90-
nodeSetHostMap := make(map[string]baremetalv1.InstanceSpec)
91-
for _, node := range spec.Nodes {
92-
instanceSpec := baremetalv1.InstanceSpec{}
93-
instanceSpec.BmhLabelSelector = node.BmhLabelSelector
94-
instanceSpec.UserData = node.UserData
95-
instanceSpec.NetworkData = node.NetworkData
96-
nodeSetHostMap[node.HostName] = instanceSpec
97-
}
98-
spec.BaremetalSetTemplate.BaremetalHosts = nodeSetHostMap
9990
} else if spec.NodeTemplate.Ansible.AnsibleUser == "" {
10091
spec.NodeTemplate.Ansible.AnsibleUser = "cloud-admin"
10192
}
@@ -220,9 +211,9 @@ func (r *OpenStackDataPlaneNodeSetSpec) ValidateUpdate(oldSpec *OpenStackDataPla
220211
// If the BaremetalSetTemplate is changed, we will offload the parsing of these details
221212
// to the openstack-baremetal-operator webhook to avoid duplicating logic.
222213
if !reflect.DeepEqual(r.BaremetalSetTemplate, oldSpec.BaremetalSetTemplate) {
223-
224214
// Call openstack-baremetal-operator webhook Validate() to parse changes
225-
err := r.BaremetalSetTemplate.Validate(oldSpec.BaremetalSetTemplate)
215+
err := r.BaremetalSetTemplate.ValidateTemplate(
216+
len(oldSpec.Nodes), oldSpec.BaremetalSetTemplate)
226217
if err != nil {
227218
errors = append(errors, field.Forbidden(
228219
field.NewPath("spec.baremetalSetTemplate"),

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,61 +51,22 @@ spec:
5151
- metadata
5252
- disabled
5353
type: string
54-
baremetalHosts:
55-
additionalProperties:
56-
properties:
57-
bmhLabelSelector:
58-
additionalProperties:
59-
type: string
60-
type: object
61-
ctlPlaneIP:
62-
type: string
63-
networkData:
64-
properties:
65-
name:
66-
type: string
67-
namespace:
68-
type: string
69-
type: object
70-
x-kubernetes-map-type: atomic
71-
userData:
72-
properties:
73-
name:
74-
type: string
75-
namespace:
76-
type: string
77-
type: object
78-
x-kubernetes-map-type: atomic
79-
type: object
80-
type: object
8154
bmhLabelSelector:
8255
additionalProperties:
8356
type: string
8457
type: object
8558
bmhNamespace:
8659
default: openshift-machine-api
8760
type: string
88-
bootstrapDns:
89-
items:
90-
type: string
91-
type: array
9261
cloudUserName:
9362
default: cloud-admin
9463
type: string
95-
ctlplaneGateway:
96-
type: string
9764
ctlplaneInterface:
9865
type: string
9966
ctlplaneNetmask:
10067
type: string
101-
ctlplaneVlan:
102-
type: integer
10368
deploymentSSHSecret:
10469
type: string
105-
dnsSearchDomains:
106-
items:
107-
type: string
108-
type: array
10970
domainName:
11071
type: string
11172
hardwareReqs:

hack/crd-schema-checker.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ set -euxo pipefail
33

44
CHECKER=$INSTALL_DIR/crd-schema-checker
55

6-
DISABLED_VALIDATORS=NoMaps # TODO: https://issues.redhat.com/browse/OSPRH-12254
6+
# (TODO) Remove NoFieldRemoval after this PR merges
7+
DISABLED_VALIDATORS=NoMaps,NoFieldRemoval # TODO: https://issues.redhat.com/browse/OSPRH-12254
78

89
CHECKER_ARGS=""
910
if [[ ${DISABLED_VALIDATORS:+x} ]]; then
10-
CHECKER_ARGS="$CHECKER_ARGS --disabled-validators $DISABLED_VALIDATORS"
11+
CHECKER_ARGS="$CHECKER_ARGS "
12+
for check in ${DISABLED_VALIDATORS//,/ }; do
13+
CHECKER_ARGS+=" --disabled-validators $check"
14+
done
1115
fi
1216

1317
TMP_DIR=$(mktemp -d)

pkg/dataplane/baremetal.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,12 @@ func DeployBaremetalSet(
4949
},
5050
}
5151

52-
if instance.Spec.BaremetalSetTemplate.BaremetalHosts == nil {
53-
return false, fmt.Errorf("no baremetal hosts set in baremetalSetTemplate")
54-
}
5552
utils.LogForObject(helper, "Reconciling BaremetalSet", instance)
5653
_, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), baremetalSet, func() error {
5754
ownerLabels := labels.GetLabels(instance, labels.GetGroupLabel(NodeSetLabel), map[string]string{})
5855
baremetalSet.Labels = utils.MergeStringMaps(baremetalSet.GetLabels(), ownerLabels)
59-
60-
instance.Spec.BaremetalSetTemplate.DeepCopyInto(&baremetalSet.Spec)
56+
baremetalSet.Spec.BaremetalHosts = make(map[string]baremetalv1.InstanceSpec)
57+
instance.Spec.BaremetalSetTemplate.DeepCopyInto(&baremetalSet.Spec.OpenStackBaremetalSetTemplateSpec)
6158
// Set Images
6259
if containerImages.OsContainerImage != nil && instance.Spec.BaremetalSetTemplate.OSContainerImageURL == "" {
6360
baremetalSet.Spec.OSContainerImageURL = *containerImages.OsContainerImage
@@ -72,11 +69,14 @@ func DeployBaremetalSet(
7269
for _, node := range instance.Spec.Nodes {
7370
hostName := node.HostName
7471
ipSet, ok := ipSets[hostName]
75-
instanceSpec := baremetalSet.Spec.BaremetalHosts[hostName]
7672
if !ok {
7773
err := fmt.Errorf("no IPSet found for host: %s", hostName)
7874
return err
7975
}
76+
instanceSpec := baremetalv1.InstanceSpec{}
77+
instanceSpec.BmhLabelSelector = node.BmhLabelSelector
78+
instanceSpec.UserData = node.UserData
79+
instanceSpec.NetworkData = node.NetworkData
8080
for _, res := range ipSet.Status.Reservation {
8181
if strings.ToLower(string(res.Network)) == dataplanev1.CtlPlaneNetwork {
8282
_, ipNet, err := net.ParseCIDR(res.Cidr)

tests/functional/dataplane/openstackdataplanenodeset_controller_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ var _ = Describe("Dataplane NodeSet Test", func() {
331331
"telemetry"}
332332

333333
Expect(dataplaneNodeSetInstance.Spec.Services).Should(Equal(services))
334-
Expect(dataplaneNodeSetInstance.Spec.BaremetalSetTemplate.BaremetalHosts).Should(BeEmpty())
335334
})
336335

337336
It("should have input not ready and unknown Conditions initialized", func() {
@@ -432,7 +431,6 @@ var _ = Describe("Dataplane NodeSet Test", func() {
432431
"global-service"}
433432

434433
Expect(dataplaneNodeSetInstance.Spec.Services).Should(Equal(services))
435-
Expect(dataplaneNodeSetInstance.Spec.BaremetalSetTemplate.BaremetalHosts).Should(BeEmpty())
436434
})
437435

438436
It("should have input not ready and unknown Conditions initialized", func() {
@@ -846,7 +844,6 @@ var _ = Describe("Dataplane NodeSet Test", func() {
846844
"telemetry"}
847845

848846
Expect(dataplaneNodeSetInstance.Spec.Services).Should(Equal(services))
849-
Expect(dataplaneNodeSetInstance.Spec.BaremetalSetTemplate.BaremetalHosts).Should(BeEmpty())
850847
})
851848
It("should have input not ready and unknown Conditions initialized", func() {
852849
th.ExpectCondition(

tests/functional/dataplane/openstackdataplanenodeset_webhook_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ var _ = Describe("DataplaneNodeSet Webhook", func() {
4141
"hostName": "compute-0"},
4242
}
4343
nodeSetSpec["baremetalSetTemplate"] = map[string]interface{}{
44-
"cloudUserName": "test-user",
4544
"bmhLabelSelector": map[string]string{
4645
"app": "test-openstack",
4746
},
@@ -52,7 +51,6 @@ var _ = Describe("DataplaneNodeSet Webhook", func() {
5251
It("Should block changes to the BmhLabelSelector object in baremetalSetTemplate spec", func() {
5352
Eventually(func(_ Gomega) string {
5453
instance := GetDataplaneNodeSet(dataplaneNodeSetName)
55-
instance.Spec.BaremetalSetTemplate.CloudUserName = "new-user"
5654
instance.Spec.BaremetalSetTemplate.BmhLabelSelector = map[string]string{
5755
"app": "openstack1",
5856
}

0 commit comments

Comments
 (0)