Skip to content

Commit

Permalink
WIP Don't set BaremetalHosts in the nodeset spec
Browse files Browse the repository at this point in the history
This is also probably required before we can change the
BaremetalSetTemplate field.

Jira: https://issues.redhat.com/browse/OSPRH-12709

Signed-off-by: rabi <ramishra@redhat.com>
  • Loading branch information
rabi committed Jan 13, 2025
1 parent 800f323 commit 85a2563
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
5 changes: 2 additions & 3 deletions apis/dataplane/v1beta1/openstackdataplanenodeset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ func (instance *OpenStackDataPlaneNodeSet) InitConditions() {
condition.UnknownCondition(condition.ServiceAccountReadyCondition, condition.InitReason, condition.ServiceAccountReadyInitMessage),
)

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

Expand Down
13 changes: 2 additions & 11 deletions apis/dataplane/v1beta1/openstackdataplanenodeset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/go-playground/validator/v10"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -70,6 +69,7 @@ func (r *OpenStackDataPlaneNodeSet) Default() {
// Default - set defaults for this OpenStackDataPlaneNodeSet Spec
func (spec *OpenStackDataPlaneNodeSetSpec) Default() {
domain := spec.BaremetalSetTemplate.DomainName
spec.BaremetalSetTemplate.BaremetalHosts = nil
for nodeName, node := range spec.Nodes {
if node.HostName == "" {
node.HostName = nodeName
Expand All @@ -79,6 +79,7 @@ func (spec *OpenStackDataPlaneNodeSetSpec) Default() {
node.HostName = strings.Join([]string{nodeName, domain}, ".")
}
}

spec.Nodes[nodeName] = *node.DeepCopy()
}

Expand All @@ -87,15 +88,6 @@ func (spec *OpenStackDataPlaneNodeSetSpec) Default() {
if spec.BaremetalSetTemplate.DeploymentSSHSecret == "" {
spec.BaremetalSetTemplate.DeploymentSSHSecret = spec.NodeTemplate.AnsibleSSHPrivateKeySecret
}
nodeSetHostMap := make(map[string]baremetalv1.InstanceSpec)
for _, node := range spec.Nodes {
instanceSpec := baremetalv1.InstanceSpec{}
instanceSpec.BmhLabelSelector = node.BmhLabelSelector
instanceSpec.UserData = node.UserData
instanceSpec.NetworkData = node.NetworkData
nodeSetHostMap[node.HostName] = instanceSpec
}
spec.BaremetalSetTemplate.BaremetalHosts = nodeSetHostMap
} else if spec.NodeTemplate.Ansible.AnsibleUser == "" {
spec.NodeTemplate.Ansible.AnsibleUser = "cloud-admin"
}
Expand Down Expand Up @@ -220,7 +212,6 @@ func (r *OpenStackDataPlaneNodeSetSpec) ValidateUpdate(oldSpec *OpenStackDataPla
// If the BaremetalSetTemplate is changed, we will offload the parsing of these details
// to the openstack-baremetal-operator webhook to avoid duplicating logic.
if !reflect.DeepEqual(r.BaremetalSetTemplate, oldSpec.BaremetalSetTemplate) {

// Call openstack-baremetal-operator webhook Validate() to parse changes
err := r.BaremetalSetTemplate.Validate(oldSpec.BaremetalSetTemplate)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions hack/crd-schema-checker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ set -euxo pipefail

CHECKER=$INSTALL_DIR/crd-schema-checker

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

CHECKER_ARGS=""
if [[ ${DISABLED_VALIDATORS:+x} ]]; then
CHECKER_ARGS="$CHECKER_ARGS --disabled-validators $DISABLED_VALIDATORS"
CHECKER_ARGS="$CHECKER_ARGS "
for check in ${DISABLED_VALIDATORS//,/ }; do
CHECKER_ARGS+=" --disabled-validators $check"
done
fi

TMP_DIR=$(mktemp -d)
Expand Down
8 changes: 4 additions & 4 deletions pkg/dataplane/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ func DeployBaremetalSet(
},
}

if instance.Spec.BaremetalSetTemplate.BaremetalHosts == nil {
return false, fmt.Errorf("no baremetal hosts set in baremetalSetTemplate")
}
utils.LogForObject(helper, "Reconciling BaremetalSet", instance)
_, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), baremetalSet, func() error {
ownerLabels := labels.GetLabels(instance, labels.GetGroupLabel(NodeSetLabel), map[string]string{})
Expand All @@ -72,11 +69,14 @@ func DeployBaremetalSet(
for _, node := range instance.Spec.Nodes {
hostName := node.HostName
ipSet, ok := ipSets[hostName]
instanceSpec := baremetalSet.Spec.BaremetalHosts[hostName]
if !ok {
err := fmt.Errorf("no IPSet found for host: %s", hostName)
return err
}
instanceSpec := baremetalv1.InstanceSpec{}
instanceSpec.BmhLabelSelector = node.BmhLabelSelector
instanceSpec.UserData = node.UserData
instanceSpec.NetworkData = node.NetworkData
for _, res := range ipSet.Status.Reservation {
if strings.ToLower(string(res.Network)) == dataplanev1.CtlPlaneNetwork {
_, ipNet, err := net.ParseCIDR(res.Cidr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ var _ = Describe("Dataplane NodeSet Test", func() {
"nova",
"telemetry"}

Expect(dataplaneNodeSetInstance.Spec.BaremetalSetTemplate.BaremetalHosts).Should(BeEmpty())
Expect(dataplaneNodeSetInstance.Spec.Services).Should(Equal(services))
Expect(dataplaneNodeSetInstance.Spec.BaremetalSetTemplate.BaremetalHosts).Should(BeEmpty())
})

It("should have input not ready and unknown Conditions initialized", func() {
Expand Down Expand Up @@ -448,8 +448,8 @@ var _ = Describe("Dataplane NodeSet Test", func() {
"telemetry",
"global-service"}

Expect(dataplaneNodeSetInstance.Spec.BaremetalSetTemplate.BaremetalHosts).Should(BeEmpty())
Expect(dataplaneNodeSetInstance.Spec.Services).Should(Equal(services))
Expect(dataplaneNodeSetInstance.Spec.BaremetalSetTemplate.BaremetalHosts).Should(BeEmpty())
})

It("should have input not ready and unknown Conditions initialized", func() {
Expand Down Expand Up @@ -870,8 +870,8 @@ var _ = Describe("Dataplane NodeSet Test", func() {
"nova",
"telemetry"}

Expect(dataplaneNodeSetInstance.Spec.BaremetalSetTemplate.BaremetalHosts).Should(BeEmpty())
Expect(dataplaneNodeSetInstance.Spec.Services).Should(Equal(services))
Expect(dataplaneNodeSetInstance.Spec.BaremetalSetTemplate.BaremetalHosts).Should(BeEmpty())
})
It("should have input not ready and unknown Conditions initialized", func() {
th.ExpectCondition(
Expand Down

0 comments on commit 85a2563

Please sign in to comment.